Skip to content
Snippets Groups Projects
diffTsgSample.m 1.42 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');
sample = getappdata( hTsgGUI, 'sample' );

[m, n] = size(sample.SSPS);

% time difference between 2 succesive TSG measurements
% ----------------------------------------------------
dt = tsg.DAYD(2) - tsg.DAYD(1);

% Loop on the samples
% -------------------
for i= 1 : m
    
    % Indice of the TSG measurement the closest to the sample
    % --------------------------------------------------------
    timeDiff  = abs(tsg.DAYD - sample.DAYD(i));
    
    [timeMin, indMin]  = min(timeDiff);

    if  timeDiff(indMin) < dt && ~isnan(tsg.ssps.smooth.val(indMin)) 
    
        sample.SSPS_SMOOTH(i)  = tsg.ssps.smooth.val(indMin);
        sample.SSPS_QC(i)      = 1;      
    else
        sample.SSPS_QC(i)      = 0;      
    end
end

% Salinity difference : Sample minus smoothed TSG
% -----------------------------------------------
indSample = find( sample.SSPS_QC == 1 );
sample.SSPS_DIF(indSample) = ...
                    sample.SSPS(indSample) - sample.SSPS_SMOOTH(indSample);  

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