Skip to content
Snippets Groups Projects
readArgoLocean.m 4.37 KiB
Newer Older
function [error] = readArgoLocean( hMainFig, filename)
% [error] = readArgoLocean( hMainFig, filename)
%
% Format :
% 1,6 Date du profil ARGO : YYYY-MM-DD HH:MI:SS
%  7  Longitude du profil ARGO 
%  8  Latitude du profil ARGO
%  9  Numero du profileur
% 10  Numero du cycle
% 11  Pression de la mesure ARGO (*)
Yves Gouriou's avatar
Yves Gouriou committed
% 12  Qualite de la pression
% 13  Salinite ARGO
% 14  Qualite de la salinite
% 15  Temperature ARGO
% 16  Qualite de la temperature
% 17  Difference temporelle moyenne entre la mesure ARGO et les mesures TSG (**) (***)
% 18  Distance moyenne entre les mesures TSG et le profil ARGO (***)
Yves Gouriou's avatar
Yves Gouriou committed
% 19  Nombre de salinites TSG
% 20  Moyenne des salinites TSG
% 21  Ecart-type des salinites TSG
% 22  Nombre de temperatures TSG
% 23  Moyenne des temperatures TSG
% 24  Ecart-type des temperatures TSG
% (*) : par defaut la pression la plus proche de 5 m comprise entre 0 et 10m et ayant une qualite de mesure de '1' ou '2'
% (**) : a moins de R km et a +/-J jours (par defaut R=50 km et J=5 jours)
% (***) : interviennent toutes les mesures et au moins la SSS ou la SST ont une qualite de '1' ou '2'

% Get the tsg structure from application GUI
% ------------------------------------------
tsg = getappdata( hMainFig, 'tsg_data');

% Get NO_CONTROL code value
% -------------------------

% Display read file info on console
% ---------------------------------
fprintf('\nREAD ARGO_LOCEAN FILE\n'); tic;

% Open the file
% -------------
fid = fopen( filename, 'r' );

% Check file
% -----------
if fid == -1
  msg_error = ['readArgoLocean file_lecture : Open file error : ' filename];
  warndlg( msg_error, 'ASCII error dialog');
  sprintf('...cannot locate %s\n', filename);
  error = -1;
  return;
end

% Read the file
% -------------
data = fscanf(fid,...
  '%d-%d-%d %d:%d:%d %f %f %d %d %f %d %f %d %f %d %f %f %d %f %f %d %f %f',...
  [24 Inf])';

% close the file
% --------------
fclose(fid)

% Every variable are put in a 'argo' structure
% --------------------------------------------
argo.DAYD_EXT  = datenum(data(:,1), data(:,2), data(:,3), data(:,4), ...
  data(:,5), data(:,6));

% Add, to the ARGO date, the time difference between ARGO and TSG
% ---------------------------------------------------------------
argo.DAYD_EXT =  argo.DAYD_EXT + data(:,17);

% Convert date in character. 
% ------------------------------------------------------
argo.DATE_EXT    = datestr( argo.DAYD_EXT, 'yyyymmddHHMMSS' );

argo.LONX_EXT    = data(:,  7);
argo.LATX_EXT    = data(:,  8);
argo.SSPS_EXT    = data(:, 13);
argo.SSTP_EXT    = data(:, 15);
argo.SSPS_EXT_QC = data(:, 14);
argo.SSTP_EXT_QC = data(:, 16);
% % pre-allocate and fill SSPS_WS_QC with 'NO_CONTROL' code value
% % -------------------------------------------------------------
% argo.SSPS_EXT_QC = castByteQC( NO_CONTROL, argo.SSPS_EXT );
% argo.SSTP_EXT_QC = castByteQC( NO_CONTROL, argo.SSTP_EXT );

% Create a string matrix for the type of data
% --------------------------------------------
[m, n] = size(data);
label = 'ARGO';
argo.SSPS_EXT_TYPE = label( ones(m,1), :);
argo.SSTP_EXT_TYPE = label( ones(m,1), :);

% No bottle number
% ----------------
label = '0';
argo.SSPS_EXT_BOTTLE = label( ones(m,1), :);

% No analysis date for ARGO floats
% ---------------------------------
label = '19500101000000';
argo.SSPS_EXT_ANALDATE = label( ones(length(argo.SSPS_EXT),1), :);

% keep data only within TSG data time-limit
% -----------------------------------------
ind = find( argo.DAYD_EXT < tsg.DAYD(1)-3 | argo.DAYD_EXT > tsg.DAYD(end)+3);

argo.DAYD_EXT(ind)            = [];
argo.DATE_EXT(ind,:)          = [];
argo.LATX_EXT(ind)            = [];
argo.LONX_EXT(ind)            = [];
argo.SSPS_EXT(ind)            = [];
argo.SSPS_EXT_QC(ind)         = [];
argo.SSPS_EXT_TYPE(ind,:)     = [];
argo.SSPS_EXT_BOTTLE(ind,:)   = [];
argo.SSPS_EXT_ANALDATE(ind,:) = [];
argo.SSTP_EXT(ind)            = [];
argo.SSTP_EXT_QC(ind)         = [];
argo.SSTP_EXT_TYPE(ind,:)     = [];

% Transfer the 'argo' structure to the 'tsg' structure
% ----------------------------------------------------
error = concatSample( hMainFig, argo );

if error
  tsg.report.extfile = filename;
end

% Display time to read file on console
% ------------------------------------
t = toc; fprintf('...done (%6.2f sec).\n\n',t);

end