Skip to content
Snippets Groups Projects
tsg_mergesample.m 4.95 KiB
Newer Older
function [] = tsg_mergesample( hTsgGUI )
Yves Gouriou's avatar
Yves Gouriou committed
% function [] = tsg_mergesample( hTsgGUI )
%
% Merge the 2 types of 'bucket' records, if they exists
%
% Input
Yves Gouriou's avatar
Yves Gouriou committed
% _WS ........ Water sample
% _EXT ....... External samples (ARGO, CTD, etc.)
%
% Ouptut
%

% Get bucket data in ASCII or NETCDF format. If the data does not exist
% getappdata return an empty matrix
% ---------------------------------------------------------------------
tsg  = getappdata( hTsgGUI, 'tsg_data');
% Create a structure with an NaN
% No other solution as I can't add a structure to an empty one
% ------------------------------------------------------------
sample = struct('DAYD',NaN ,        'LATX',NaN ,      'LONX',NaN , ...
                'SSPS',NaN ,        'SSPS_QC',NaN ,   'SSPS_DIF',NaN ,...
                'SSPS_SMOOTH',NaN , 'SSPS_TYPE', NaN, 'SSPS_INDICE', NaN);    
% Fill the structure sample with the bucket data.
% ------------------------------------------------
if ~isempty(tsg.SSPS_WS)

  sample.DAYD        = [sample.DAYD;        tsg.DAYD_WS];
  sample.LATX        = [sample.LATX;        tsg.LATX_WS];
  sample.LONX        = [sample.LONX;        tsg.LONX_WS];
  sample.SSPS        = [sample.SSPS;        tsg.SSPS_WS];
Yves Gouriou's avatar
Yves Gouriou committed
  if ~isempty(tsg.SSPS_WS_QC)
    sample.SSPS_QC   = [sample.SSPS_QC;     tsg.SSPS_WS_QC];
  else
    sample.SSPS_QC   = [sample.SSPS_QC;     ones(size(tsg.DAYD_WS))];
  end
Yves Gouriou's avatar
Yves Gouriou committed
  % Fill the structure with NaN. NaN is tested in diffTsgSample
  % -----------------------------------------------------------
  sample.SSPS_DIF    = [sample.SSPS_DIF;    NaN*ones(size(tsg.DAYD_WS))];
  sample.SSPS_SMOOTH = [sample.SSPS_SMOOTH; NaN*ones(size(tsg.DAYD_WS))];
  % INDICE is used to put back the QC once the validation procedure has
  % been applied
  % -------------------------------------------------------------------
  sample.SSPS_INDICE = [sample.SSPS_INDICE; [1:length(tsg.DAYD_WS)]'];
  
  % Used for the plots : WS are given a type 1
  % ------------------------------------------
Yves Gouriou's avatar
Yves Gouriou committed
  sample.SSPS_TYPE   = [sample.SSPS_TYPE;   ones(size(tsg.DAYD_WS))];
% Fill the structure sample with the external sample
% This measurements are of TYPE EXT
% --------------------------------------------------
if ~isempty(tsg.SSPS_EXT)

  sample.DAYD        = [sample.DAYD;        tsg.DAYD_EXT];
  sample.LATX        = [sample.LATX;        tsg.LATX_EXT];
  sample.LONX        = [sample.LONX;        tsg.LONX_EXT];
  sample.SSPS        = [sample.SSPS;        tsg.SSPS_EXT];
Yves Gouriou's avatar
Yves Gouriou committed
  if ~isempty(tsg.SSPS_EXT_QC)
    sample.SSPS_QC   = [sample.SSPS_QC;     tsg.SSPS_EXT_QC];
  else
    sample.SSPS_QC   = [sample.SSPS_QC;     ones(size(sample.DAYD_EXT))];
  end
Yves Gouriou's avatar
Yves Gouriou committed
  % Fill the following structures with NaN. NaN is test in diffTsgSample
  % --------------------------------------------------------------------
  sample.SSPS_DIF    = [sample.SSPS_DIF;    NaN*ones(size(tsg.DAYD_EXT))];
  sample.SSPS_SMOOTH = [sample.SSPS_SMOOTH; NaN*ones(size(tsg.DAYD_EXT))];
  
  % Used for the plots : EXT sample are given a type 2
  % --------------------------------------------------
  sample.SSPS_TYPE   = [sample.SSPS_TYPE;   2*ones(size(tsg.DAYD_EXT))];
  
  % INDICE is used to put back the QC once the validation procedure has
  % been applied
  % -------------------------------------------------------------------
  sample.SSPS_INDICE = [sample.SSPS_INDICE; [1:length(tsg.DAYD_EXT)]'];
% Eliminate the first element if NaN
% ----------------------------------
if isnan(sample.DAYD(1))
  sample.DAYD(1)        = [];
  sample.LATX(1)        = [];
  sample.LONX(1)        = [];
  sample.SSPS(1)        = [];
  sample.SSPS_QC(1)     = [];
  sample.SSPS_DIF(1)    = [];
  sample.SSPS_SMOOTH(1) = [];
  sample.SSPS_TYPE(1)   = [];
% Sort the struct sample - increasing time.
% -----------------------------------------
if ~isempty(sample)
  [sample.DAYD, iOrder] = sort(sample.DAYD);
  sample.LATX           = sample.LATX(iOrder);
  sample.LONX           = sample.LONX(iOrder);
  sample.SSPS           = sample.SSPS(iOrder);
  sample.SSPS_QC        = sample.SSPS_QC(iOrder);
  sample.SSPS_DIF       = sample.SSPS_DIF(iOrder);
  sample.SSPS_SMOOTH    = sample.SSPS_SMOOTH(iOrder);
  sample.SSPS_TYPE      = sample.SSPS_TYPE(iOrder);
  % ---------------------------------------------
  tsg.LATX_SPL           = sample.LATX;
  tsg.LONX_SPL           = sample.LONX;
  tsg.SSPS_SPL           = sample.SSPS;
  tsg.SSPS_SPL_QC        = sample.SSPS_QC;
  tsg.SSPS_SPL_DIF       = sample.SSPS_DIF;
  tsg.SSPS_SPL_SMOOTH    = sample.SSPS_SMOOTH;
  tsg.SSPS_SPL_TYPE      = sample.SSPS_TYPE;
% Update application data
% -----------------------
setappdata( hTsgGUI, 'tsg_data', tsg );