function [sample] = tsg_diffTsgSample(tsg, psal_smooth, sample) % % function [sample] = tsg_diffTsgSample(tsg, psal_smooth, sample, dt) % % Co-location of bucket and TSG measurements % Compute the bucket-TSG difference % % tsg ........... structure of TSG data % psal_smooth ... smooth TSG timeseries % sample ........ structure of samples % [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(psal_smooth(indMin)) sample.SSPS_SMOOTH(i) = psal_smooth(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);