Skip to content
Snippets Groups Projects
Commit 0dcfa495 authored by Yves Gouriou's avatar Yves Gouriou
Browse files

Suppression de fichier de lecture de fichier texte :

Une seule routine readASCII.

Elimine l'ecriture en ASCII lors de l'ecriture en NETCDF
Utilise maintenant la fonction EXPORT
parent d1e17dea
No related branches found
No related tags found
No related merge requests found
% tsg_platform.csv: 14 members & 3 lines with data
% tsg_platform.csv: 14 members & 4 lines with data
% $Id$
%
id;PLATFORM_NAME;SHIP_CALL_SIGN;SHIP_MMSI;TSG_TYPE;TSG_NUMBER;TINT_TYPE;TINT_NUMBER;SAMPLING_PERIOD;SSPS_DEPH;SSPS_DEPH_MIN;SSPS_DEPH_MAX;SSTP_DEPH;SSTP_DEPH_MIN;SSTP_DEPH_MAX;DATE_TSG;endl
......@@ -6,3 +6,4 @@ char;char;char;char;char;char;char;char;integer;integer;integer;integer;integer;
#;PASTEUR;ELWT7;228288228;SBE21;3197;SBE38;;300;5;3;6;;;;;#
#;ANTEA;FNUR;228111000;SBE21;2725;NA;;30;3;3;3;3;3;3;;#
#;TOUCAN;FNAV;227278000;SBE21;2725;NA;;30;;;;;;;;#
#;COLIBRI;;;SBE21;;SBE38;;;;;;;;;;#
function [error] = readTsgDataTsg( hMainFig, filename)
% Function to read the TSG data. Should be a NetCDF file
%
% Input
% -----
% hMainFig ............ Handle to the main user interface
% filename ........... Data filename
%
% Output
% ------
% error .............. 1: OK - -1 : an error occured
%
% The data are store using setappdata - Variable name : 'tsg_data'
%
% Caution : replace the fill-value with NaN
% $Id: readTsgDataTxt.m 297 2008-03-20 16:33:37Z ygouriou $
% Get the data from the application GUI
% -------------------------------------
tsg = getappdata( hMainFig, 'tsg_data');
% Get the fieldnames of tsg structure
% -----------------------------------
tsgNames = fieldnames(tsg);
nbFieldNames = length( tsgNames );
% Display read file info on console
% ---------------------------------
fprintf('\nREAD_ASCII_FILE\n'); tic;
% Open the file
% -------------
fid = fopen( filename, 'r' );
% Check file
% -----------
if fid == -1
msg_error = ['TSG_GOSUD file_lecture : Open file error : ' filename];
warndlg( msg_error, 'ASCII error dialog');
sprintf('...cannot locate %s\n', filename);
error = -1;
return;
end
% Display more info about read file on console
% --------------------------------------------
fprintf('...reading %s : ', filename);
% Read the header till the header line has been read
% --------------------------------------------------
OK = 0;
while ~OK
% Read every line
% ---------------
line = fgetl( fid );
c = textscan( line, '%s');
switch char( c{1}(1) )
case '%HEADER'
% Read the header then quit the while loop
% ----------------------------------------
header = c{1}(2:end);
nHeader = length( header );
OK = 1;
otherwise
% Get the paramete Name (Delete '%')
% ----------------------------------
Para = char( strtok(c{1}(1), '%') );
% Read the parameter value
% ------------------------
ind = strmatch( Para, tsgNames);
if ~isempty( ind )
tsg.(Para) = char( c{1}(2) );
end
end
end
% Read the data in a cell
% -----------------------
cellData = textscan( fid, '%f' );
% Convert the data to double
% --------------------------
nCol = nHeader;
mLine = length( cellData{:} )/nCol;
data = NaN * ones( mLine, nCol );
ind = 0;
for i = 1:mLine
for j = 1:nCol
ind = ind + 1;
data(i,j) = cellData{1}(ind);
end
end
clear cellData
% Date (y m d h m s) in the first 6 elements in data
% --------------------------------------------------
tsg.DAYD = datenum(data(:,1), data(:,2),data(:,3),data(:,4),data(:,5),data(:,6));
% Loop over the header. Skip the 6 first elements
% -----------------------------------------------
for i = 7 : nHeader
% QC should be converted in int8
% ------------------------------
if ~isempty( strfind(char(header(i)), '_QC'))
tsg.(char(header(i))) = int8( data(:,i) );
else
tsg.(char(header(i))) = data(:,i);
end
end
% populate tsg.file structure
% ---------------------------
[tsg.file.pathstr, tsg.file.name, tsg.file.ext, tsg.file.versn] = ...
fileparts(filename);
%tsg.file.name = filename;
tsg.file.type = 'ASCII';
% Keep somme information for the log file
% ---------------------------------------
tsg.report.tsgfile = filename;
% Save the data in the application GUI
% ------------------------------------
setappdata( hMainFig, 'tsg_data', tsg );
% Perform somme automatic tests
% -----------------------------
automaticQC( hMainFig );
% Close the file
% --------------
fclose( fid );
% Clear the Workspace
% -------------------
clear data
% Display time to read file on console
% ------------------------------------
t = toc; fprintf('...done (%6.2f sec).\n\n',t);
% Everything OK
% -------------
error = 1;
end
function [error] = readTsgDataTxt( hMainFig, filename)
% Function to read the TSG data. Should be a NetCDF file
%
% Input
% -----
% hMainFig ............ Handle to the main user interface
% filename ........... Data filename
%
% Output
% ------
% error .............. 1: OK - -1 : an error occured
%
% The data are store using setappdata - Variable name : 'tsg_data'
%
%
% Caution : replace the fill-value with NaN
% $Id$
% Get the data from the application GUI
% -------------------------------------
tsg = getappdata( hMainFig, 'tsg_data');
% Display read file info on console
% ---------------------------------
fprintf('\nREAD_ASCII_FILE\n'); tic;
% Open the file
% -------------
fid = fopen( filename, 'r' );
% Check file
% -----------
if fid == -1
msg_error = ['TSG_GOSUD file_lecture : Open file error : ' filename];
warndlg( msg_error, 'ASCII error dialog');
sprintf('...cannot locate %s\n', filename);
error = -1;
return;
end
% Display more info about read file on console
% --------------------------------------------
fprintf('...reading %s : ', filename);
% Read the file
% -------------
tsgData = fscanf(fid, '%d/%d/%d %d:%d:%d %f %f %f %f %d %f %f', [13 Inf])';
% Every variable are put in a structure
% -------------------------------------
tsg.DAYD = datenum(tsgData(:,3), tsgData(:,2),tsgData(:,1), ...
tsgData(:,4),tsgData(:,5),tsgData(:,6));
% save original date
% ------------------
tsg.DATE = datestr( tsg.DAYD, 'yyyymmddHHMMSS' );
tsg.LATX = tsgData(:,7);
tsg.LONX = tsgData(:,8);
tsg.SSJT = tsgData(:,9);
tsg.SSPS = tsgData(:,10);
tsg.SSPS_QC = tsgData(:,11);
tsg.SSPS_ADJUSTED = tsgData(:,12);
tsg.SSPS_ADJUSTED_ERROR = tsgData(:,13);
tsg.SSJT_QC = tsg.SSPS_QC;
% populate tsg.file structure
% ---------------------------
[tsg.file.pathstr, tsg.file.name, tsg.file.ext, tsg.file.versn] = ...
fileparts(filename);
%tsg.file.name = filename;
tsg.file.type = 'ASCII';
% Keep somme information for the log file
% ---------------------------------------
tsg.report.tsgfile = filename;
% Save the data in the application GUI
% ------------------------------------
setappdata( hMainFig, 'tsg_data', tsg );
% Perform somme automatic tests
% -----------------------------
automaticQC( hMainFig );
% Close the file
% --------------
fclose( fid );
% Clear the Workspace
% -------------------
clear tsgdata
% Display time to read file on console
% ------------------------------------
t = toc; fprintf('...done (%6.2f sec).\n\n',t);
% Everything OK
% -------------
error = 1;
......@@ -16,8 +16,9 @@ switch nPlot
PARA,'','none','*',2);
end
% Plot Salinity bucket
% --------------------
% Plot PARA bucket
% -----------------------------
if ~isempty( tsg.([PARA '_SPL']) )
ind = find( tsg.([PARA '_SPL_TYPE']) == 1 );
if ~isempty(ind)
......
......@@ -94,6 +94,9 @@ tsg.SSPS_SPL_TYPE = [];
tsg.SSTP_SPL = [];
tsg.SSTP_SPL_QC = [];
tsg.SSTP_SPL_TYPE = [];
tsg.SSJT_SPL = [];
tsg.SSJT_SPL_QC = [];
tsg.SSJT_SPL_TYPE = [];
% -------------------------------------------------------------------------
%% Constants for the quality control procedure
......
......@@ -2893,19 +2893,6 @@ end
% ------------------
set( hInfoFileText, 'String', strcat(tsg.file.name, tsg.file.ext));
% Write a TXT file
% ----------------
fileName = strcat(tsg.file.name, '_w.txt');
error = writeTsgDataTxt(hMainFig, strcat(pathName, fileName));
% Check for TxT writing error - must to be rewriting
% --------------------------------------------------
if error == -1
warning('tsgqc:SaveMenuCallback', ...
'TxT writing error: %s %s', pathName, fileName);
return;
end
% enable Quality Control mode
% ---------------------------
hdl_pushtool = findobj('Tag', 'QC');
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment