function diffTsgSample(hTsgGUI, PARA)
%
% 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.([PARA '_QC']) <= probablyGoodCode );

if ~isempty( indTsg )

  [m, n] = size(tsg.([PARA '_SPL']));

  % Loop on the samples
  % -------------------
  for i= 1 : m

    % 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
    % -------------------------
    smooth = tsg_average(hTsgGUI, 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.([PARA '_SPL_SMOOTH'])(i)  = smooth;

    end
  end

  % Salinity difference : Sample minus smoothed TSG
  % -----------------------------------------------
  tsg.([PARA '_SPL_DIF']) = tsg.([PARA '_SPL']) - tsg.([PARA '_SPL_SMOOTH']);

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

end