Skip to content
Snippets Groups Projects
diffTsgSample.m 2.33 KiB
Newer Older
function diffTsgSample(hMainFig, PARA)
%
% Co-location of sample and TSG measurements
% Compute the sample-TSG difference
%

% Get the tsg and sample structures from the application
% ------------------------------------------------------
tsg    = getappdata( hMainFig, 'tsg_data');
% Get PROBABLY_GOOD code
% ----------------------
probablyGoodCode = get(tsg.qc.hash, 'PROBABLY_GOOD', 'code');
missingValueCode = get(tsg.qc.hash, 'MISSING_VALUE', 'code');

% IF PARA = 'SSJT' use 'SSTP' to get the samples
% ----------------------------------------------
SAMPLE = PARA;
if strcmp( SAMPLE, 'SSJT')
  SAMPLE = 'SSTP';
end

% Consider only tsg data with NO_CONTROL, GOOD and PROBABLY_GOOD code
% -------------------------------------------------------------------
indTsg = find( tsg.([PARA '_QC']) < missingValueCode );
if ~isempty( indTsg )

  [m, n] = size(tsg.([SAMPLE '_EXT']));

  % Loop on the samples
  % -------------------
  for i= 1 : m
    % Compute the differences between the sample and the time serie
    % -------------------------------------------------------------
    timeDiff  = abs(tsg.DAYD - tsg.DAYD_EXT(i));

    % Compute the indice of the TSG measurement the closest to the sample
    % taking into account the TSG quality code
    % -------------------------------------------------------------------
    [timeMin, indMin]  = min(timeDiff(indTsg));
    indMin             = indTsg( indMin );

    % Keep the smooth TSG value
    % -------------------------
    smooth = tsg_average(hMainFig, PARA, indMin);
    if  timeDiff(indMin) < tsg.cst.TSG_WS_TIMEDIFF && ~isnan(smooth)
      % The smooth TSG time series (tsg_moveaverage) is
      % no more computed : too long
      % We now computed a smooth value only at the position of the sample
      % -----------------------------------------------------------------
      %tsg.([PARA '_SPL_SMOOTH'])(i)  = tsg.ssps_smooth(indMin);
      tsg.EXT_SMOOTH(i)  = smooth;
    else
      tsg.EXT_SMOOTH(i)  = NaN;
    end
  end

  % Salinity difference : Sample minus smoothed TSG
  % -----------------------------------------------
  tsg.EXT_DIF = tsg.([SAMPLE '_EXT']) - tsg.EXT_SMOOTH';
  % update the sample structures in the application
  % ------------------------------------------------
  setappdata( hMainFig, 'tsg_data', tsg );