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

% Get the tsg and sample structures from the application
% ------------------------------------------------------
tsg    = getappdata( hTsgGUI, 'tsg_data');

% Get PROBABLY_GOOD code
% ----------------------
probablyGoodCode = get(tsg.qc.hash, 'PROBABLY_GOOD', 'code');

% Consider only tsg data with NO_CONTROL, GOOD and PROBABLY_GOOD code
% -------------------------------------------------------------------
indTsg = find( tsg.SSPS_QC <= probablyGoodCode );

[m, n] = size(tsg.SSPS_SPL);
% time difference between 2 successive TSG measurements
% Not use anymore. Now use a constant tsg.cst.TSG_WS_TIMEDIFF in the test
% -----------------------------------------------------------------------
% dt = min(diff(tsg.DAYD));
% Loop on the samples 
% -------------------
  
    % Compute the differences between the sample and the time serie
    % -------------------------------------------------------------
    timeDiff  = abs(tsg.DAYD - tsg.DAYD_SPL(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
    % -------------------------
    if  timeDiff(indMin) < tsg.cst.TSG_WS_TIMEDIFF && ...
        ~isnan(tsg.ssps_smooth(indMin))
      tsg.SSPS_SPL_SMOOTH(i)  = tsg.ssps_smooth(indMin);
    end
end

% Salinity difference : Sample minus smoothed TSG
% -----------------------------------------------
tsg.SSPS_SPL_DIF = tsg.SSPS_SPL - tsg.SSPS_SPL_SMOOTH;  

% update the sample structures in the application
% ------------------------------------------------
setappdata( hTsgGUI, 'tsg_data', tsg );