Skip to content
Snippets Groups Projects
tsgqc.m 176 KiB
Newer Older
    % restacks the figure to the top of the screen
    % --------------------------------------------
    figure( hMainFig);
    set(hQCToggletool, 'state', 'on' );
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
%---------------------------------------------------------------------
% Callback function run when mouse pointer is moving on temperature plot
% draw corresponding measurement position on map
%---------------------------------------------------------------------
  function MouseMotion(src, evnt)
    % Test if the callback can be activated
    % -------------------------------------
    if strcmp( get( hMainFig, 'UserData'), 'ButtonMotionOn')
      % Retrieve named application data
      % -------------------------------
      tsg = getappdata( hMainFig, 'tsg_data');
      % Get current position of cusor and return its coordinates in
      % axes with handle h_axes
      % -----------------------------------------------------------
      a = get(hPlotAxes(1), 'CurrentPoint');
      x = a(2,1);
      y = a(2,2);
      % Get the Limits of axes 1
      % ------------------------
      limx = get(hPlotAxes(1), 'XLim');
      limy = get(hPlotAxes(1), 'YLim');
      % Code to Activate the PAN function when QC mode is active
      % A PAN zone is defined in the bottom (10%) of PlotAxes(1)
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
      % 2 callback are needed :
      %    1 - one to desactivate QC when Pan is set to on.
      %    2 - one to reactivate QC once the pan has been used.
      % ---------------------------------------------------------
      
      % if we are in QC mode
      % ---------------------
      if strcmp( get(hQCToggletool, 'state' ), 'on' );
        % Suppose that Y axes is increasing from the bottom to the top
        % ------------------------------------------------------------
        limy2 = limy(1) + (limy(2)-limy(1)) * 0.10;
        if  x > limx(1) && x < limx(2) &&  y <= limy2 && y >= limy(1)
          hPan = pan(hMainFig);
          set(hPan,'ActionPreCallback',  @preQcPanCallback);
          set(hPan,'ActionPostCallback', @postQcPanCallback);
          set(hPan,'Enable','on');
        else
          
        end % end of cursor test location
        
      end % end of QC mode test
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
      % Dynamically display data in uicontrol for valid data
      % ----------------------------------------------------
      if x > tsg.DAYD(1) && x < tsg.DAYD(end)
        
        % get index of cursor location
        % ----------------------------
        indCursor = find( tsg.DAYD > x, 1, 'first');
        
        % display informations of cursor location in text uicontrol
        % ---------------------------------------------------------
        set( hInfoDateText, 'String',...
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
          datestr(tsg.DAYD(indCursor),'dd/mm/yyyy   HH:MM'));
        if tsg.preference.positions_format_value == 1
          set( hInfoLatText,  'String', dd2dm(tsg.LATX(indCursor), 0) );
          set( hInfoLongText, 'String', ...
            dd2dm(mod(tsg.LONX(indCursor) + 180, 360) - 180, 1) );
          set( hInfoLatText,  'String', tsg.LATX(indCursor) );
          set( hInfoLongText, 'String', ...
            mod(tsg.LONX(indCursor) + 180, 360) - 180 );
        if ~isempty(tsg.SSPS)
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
          set( hInfoSSPSText, 'String', tsg.SSPS(indCursor) );
        end
        if ~isempty(tsg.SSJT)
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
          set( hInfoSSJTText, 'String', tsg.SSJT(indCursor) );
        if ~isempty(tsg.SSTP)
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
          set( hInfoSSTPText, 'String', tsg.SSTP(indCursor) );
        % Plot the position on the map if this one is active
        % --------------------------------------------------
        if strcmp( get(hMapFig, 'Visible'), 'on')
          % Select the map axes, we cannot use mline as line with an axes
          % in first parameter like:  m_line(hPlotAxes(4), ....)
          % ------------------------------------------------------------
          axes( hPlotAxes(4));
          % Look for a MARKER (Red point) on the ship track
          % -----------------------------------------------
          h = findobj( hPlotAxes(4), '-regexp','Tag', 'TAG_PLOT4_LINE_MARKER');
          if isempty( h )   % if no Marker
            if ~isnan( tsg.LONX(indCursor) )
              % Plot a Marker (Red point) on the ship track
              % -------------------------------------------
              hMarker = m_line(mod(tsg.LONX(indCursor(1)) + ...
                tsg.lonplus, tsg.lonmod) - tsg.lonplus,...
                tsg.LATX(indCursor(1)),...
                'Marker', 'o', 'MarkerSize', tsg.preference.map.ship.size, ...
                'Color', tsg.preference.map.ship.color, 'MarkerFaceColor', ...
                tsg.preference.map.ship.color);
              % Put a tag on the Marker - This tag allows to get the handle
              % of the Marker
              % -----------------------------------------------------------
              set( hMarker, 'TAG', 'TAG_PLOT4_LINE_MARKER' );
          else         % a marker exists
            if ~isnan( tsg.LONX(indCursor) )
              % Delete the Marker and redraw it
              % -------------------------------
              delete( h);
              hMarker = m_line(...
                tsg.LONX(indCursor), tsg.LATX(indCursor),...
                'Marker', 'o', 'MarkerSize', tsg.preference.map.ship.size, ...
                'Color', tsg.preference.map.ship.color,...
                'MarkerFaceColor', tsg.preference.map.ship.color);
              % Put a tag on the Marker - This tag allows to get the handle
              % of the Marker
              % -----------------------------------------------------------
              set( hMarker, 'TAG', 'TAG_PLOT4_LINE_MARKER' );
        
      else
        
        % if cursor is out of valid data, display blank
        % ---------------------------------------------
        set( hInfoDateText, 'String', '' );
        set( hInfoLatText,  'String', '' );
        set( hInfoLongText, 'String', '' );
        set( hInfoSSPSText, 'String', '' );
        set( hInfoSSTPText, 'String', '' );
        set( hInfoSSJTText, 'String', '' );
      
    end % end of BuntonMotionOn
    
  end % end of mouseMotion function

%% Map_OnMenuCallback
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
%---------------------------------------------------------------------
% Callback function run when the Map tool bar item is selected
%---------------------------------------------------------------------
  function Map_OnMenuCallback(src, evnt)
    % Desactivate Zoom and Pan toggle buttons
    % ---------------------------------------
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    set(hZoomInToggletool,  'state', 'off' );
    set(hZoomOutToggletool,  'state', 'off' );
    set(hPanToggletool,   'state', 'off' );
    % Make the earth map visible
    % --------------------------
    set(hMapFig, 'Visible', 'on' );
    erase_Line( hPlotAxes, 4 );
    plot_map( hMainFig, hPlotAxes)
    
    % De-activate keyPressFcn callback on main fig
    % --------------------------------------------
%% Map_OffMenuCallback
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
%---------------------------------------------------------------------
% Callback function run when the Map tool bar item is unselected
%---------------------------------------------------------------------
  function Map_OffMenuCallback(src, evnt)
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    % Make the earth map invisible
    % ----------------------------
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    set(hMapFig, 'Visible', 'off' );
    % Re-activate keyPressFcn callback on main fig
    % see Enabling user callbacks during zoom/pan on Undocumented Matlab
    % https://undocumentedmatlab.com/blog/enabling-user-callbacks-during-zoom-pan
    % This should work in both HG1 and HG2:
    % ------------------------------------------------------------------------
    %     hManager = uigetmodemanager(hMainFig);
    %     try
    %       set(hManager.WindowListenerHandles, 'Enable', 'off'); % HG1 (prior R2014b)
    %     catch
    %       [hManager.WindowListenerHandles.Enabled] = deal(false);  % HG2 (R2014b)
    %     end
    %    set(hMainFig, 'WindowKeyPressFcn', []);
    
    % comment this line to prevent warning
    %    set(hMainFig, 'KeyPressFcn', @keyPressFcnCallback);
%% Bottle_OnMenuCallback ................................ Correction Module
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
%---------------------------------------------------------------------
% Callback function run when the bootle push tool is selected
%---------------------------------------------------------------------
  function Bottle_OnMenuCallback(src, evnt)
    % Callback function run when the Bottle tool bar item is selected
    % Get the tsg structure
    % ---------------------
    tsg = getappdata(hMainFig, 'tsg_data');
    % Get the parameter we are working on (SSPS, SSJT, SSTP)
    % ------------------------------------------------------
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    SAMPLE = tsg.plot.sample;
    PARA = getParaCorModule( hMainFig );
    % Switch somme buttons
    % --------------------
    set( hQCToggletool,         'state',  'off' );
    set( hZoomInToggletool,     'state', 'off', 'enable', 'on' );
    set( hZoomOutToggletool,    'state', 'off', 'enable', 'on' );
    set( hPanToggletool,        'state',  'off' );
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    %     set( hMapToggletool,        'state',  'off' );
    set( hClimToggletool,       'state',  'off', 'enable', 'off');
    set( hCalToggletool,        'enable', 'off' );
    set( hInterpToggletool,     'enable', 'off' );
    set( hTimelimitToggletool,  'enable', 'on' );
    % Activate or desactivate uipanels
    % ---------------------------------
    set( hpDateLimit,           'Visible', 'on' );
    set( hbgCorMethod,          'Visible', 'on' );
    set( hCorPanel,             'Visible', 'on' );
    set( hbgParameter,          'Visible', 'off');
    set( hbgQc,                 'Visible', 'off');
    if ~isempty( tsg.([SAMPLE '_EXT']) )
      % Compute the sample-TSG differences
      % ----------------------------------
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
      diffTsgSample( hMainFig, PARA );
      tsg = getappdata( hMainFig, 'tsg_data');
      msgbox('No sample data file has been read', 'modal');
    % Plot in the 3 axes
    % ------------------
    plot_Correction( hMainFig, hPlotAxes, PARA );
    % Necessary to unzoom as the new plot keep in memory the preceding zoom
    % ---------------------------------------------------------------------
    zoom out;
    tsg.preference.map.border = ...
      str2double(tsg.preference.map.border_string(tsg.preference.map.border_value));
    setappdata( hMainFig, 'tsg_data', tsg );
    
    % Get the information on time limits of the time series
    % Write them in the uipanel
    % -----------------------------------------------------
    noNaN = tsg.DAYD(~isnan( tsg.DAYD ));
    set( hetDateMin, 'String', datestr(noNaN(1), 31));
    set( hetDateMax, 'String', datestr(noNaN(end), 31));

%% Bottle_OffMenuCallback ............................... Correction module
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
%---------------------------------------------------------------------
% Callback function run when the bootle push tool is selected
%---------------------------------------------------------------------
  function Bottle_OffMenuCallback(src, evnt)
    % If necessary toggle off some buttons
    % ------------------------------------
    set( hQCToggletool,        'state',  'off' );
    set( hZoomInToggletool,    'state',  'off' );
    set( hZoomOutToggletool,   'state',  'off' );
    set( hPanToggletool,       'state',  'off' );
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    %     set( hMapToggletool,       'state',  'off' );
    set( hClimToggletool,      'enable', 'on');
    set( hCalToggletool,       'enable', 'on'  );
    set( hInterpToggletool,    'enable', 'on' );
    set( hTimelimitToggletool, 'enable', 'off' );
    % Activate or Desactivate uipanel
    % --------------------------------
    set( hpDateLimit,          'Visible', 'off' );
    set( hCorPanel,            'Visible', 'off' );
    set( hbgCorMethod,         'Visible', 'off' );
    set( hbgParameter,         'Visible', 'on');
    % Desactivate Click Mouse on figure
    % ---------------------------------
    set( hMainFig, 'WindowButtonDownFcn', []);
    % Get tsg structure
    % -----------------
    tsg  = getappdata( hMainFig, 'tsg_data' );
    % Draw the 3 plots of the validation figure and unzoom as the new
    % plot keep in memory the preceding zoom
    % -----------------------------------------
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    plot_Validation( hMainFig, hPlotAxes, 1, tsg.plot.parameter{1} );
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    plot_Validation( hMainFig, hPlotAxes, 2, tsg.plot.parameter{2} );
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    plot_Validation( hMainFig, hPlotAxes, 3, tsg.plot.parameter{3} );
    tsg.preference.map.border = ...
      str2double(tsg.preference.map.border_string(tsg.preference.map.border_value));
    setappdata( hMainFig, 'tsg_data', tsg );
    
    % Set the pointer
    % ---------------
    set( hMainFig, 'Pointer', 'arrow');
%% cancelCorrectionCallback .................................... Correction Module
  function cancelCorrectionCallback(src, evnt, Limits)
    % Callback function run when the user want to cancel the
    % corrections made from comparison with bottles or ARGO data.
    % The deletion can be made for th whole time series or
    % between 2 dates.
    % Desactivate somme Toggle button
    % -------------------------------
    set( hZoomInToggletool,       'state', 'off' );
    set( hZoomOutToggletool,       'state', 'off' );
    set( hPanToggletool,        'state', 'off' );
    set( hQCToggletool,         'state', 'off' );
    set( hTimelimitToggletool,  'state', 'off' );
    % Get tsg application data
    % ------------------------
    tsg = getappdata(hMainFig, 'tsg_data');
    % Get parameter we are working on (SSPS, SSJT, SSTP)
    % or SSPS_CAL, SSJT_CAL, SSTP_CAL
    % -------------------------------------------------
    PARA = getParaCorModule( hMainFig );
    
    % The correction will be cancelled either for the entire
    % time series or within date limits
    % ------------------------------------------------------
    ind = 0;
    switch Limits
      
      % Get the indices of the whole time series
      % ----------------------------------------
      case 'total'
        
        ind = find( tsg.DAYD >= tsg.DAYD(1) &  tsg.DAYD <= tsg.DAYD(end) );
        
        %         ind = size(tsg.([PARA{1} '_ADJUSTED']));
        
        % Get the indices between 2 dates
        % --------------------------------
      case 'part'
        % Get the date limits used for the correction
        % -------------------------------------------
        dateMin = datenum(get( hetDateMin, 'String'), 'yyyy-mm-dd HH:MM:SS');
        dateMax = datenum(get( hetDateMax, 'String'), 'yyyy-mm-dd HH:MM:SS');
        % Find indices within date limits
        % --------------------------------
        if dateMax > dateMin
          ind = find( tsg.DAYD >= dateMin &  tsg.DAYD <= dateMax );
        end
      otherwise
        msgbox( 'cancelCorrectionCallback : error', 'cancelCorrectionCallback', 'error', 'modal');
    if ~isempty(ind) && ~isempty( tsg.([PARA{1} '_ADJUSTED']) )
      
      % Cancel the correction : set the ADJUSTED variable to NaN
      % and ADJUSTED_QC to 0 (Bytes)
      % --------------------------------------------------------
      tsg.([PARA{1} '_ADJUSTED'])(ind) = ...
        NaN*ones(size(tsg.([PARA{1} '_ADJUSTED'])(ind))) ;
      tsg.([PARA{1} '_ADJUSTED_QC'])(ind) = ...
        zeros*ones(size(tsg.([PARA{1} '_ADJUSTED_QC'])(ind))) ;
      tsg.([PARA{1} '_ADJUSTED_ERROR'])(ind) = ...
        NaN*ones(size(tsg.([PARA{1} '_ADJUSTED_ERROR'])(ind))) ;
      
    end
    % Save tsg data
    % -------------
    setappdata(hMainFig, 'tsg_data', tsg);
    % Plot in the 3 axes
    % ------------------
    plot_Correction( hMainFig, hPlotAxes, PARA );
%% gradientCorrectionCallback .................................... Correction Module
  function gradientCorrectionCallback(src, evnt)
    % Desactivate somme Toggle button
    % -------------------------------
    set( hZoomInToggletool,     'state', 'off' );
    set( hZoomOutToggletool,    'state', 'off' );
    set( hPanToggletool,        'state', 'off' );
    set( hQCToggletool,         'state', 'off' );
    set( hTimelimitToggletool,  'state', 'off' );
    % Get the time limits for the correction
    % --------------------------------------
    dateMin = datenum(get( hetDateMin, 'String'), 'yyyy-mm-dd HH:MM:SS');
    dateMax = datenum(get( hetDateMax, 'String'), 'yyyy-mm-dd HH:MM:SS');
    % Get tsg application data
    % ------------------------
    tsg    = getappdata(hMainFig, 'tsg_data');
    % Get parameter we are working on (SSPS, SSJT, SSTP)
    % or SSPS_CAL, SSJT_CAL, SSTP_CAL
    % -------------------------------------------------
    PARA = getParaCorModule( hMainFig );
    SAMPLE = tsg.plot.sample;
      % Compute the sample-TSG differences
      % ----------------------------------
      diffTsgSample( hMainFig, PARA );
      % Correction
      % ----------
      error = corTsgGradient(hMainFig, PARA, dateMin, dateMax);
          % Plot in the 3 axes
          % ------------------
          plot_Correction( hMainFig, hPlotAxes, PARA );
            msgbox( 'Date limits are not correct',...
              'Correction module', 'warn', 'modal');
          end
%% biasCorrectionCallback .................................... Correction Module
  function biasCorrectionCallback(src, evnt)
    % Desactivate somme Toggle button
    % -------------------------------
    set( hZoomInToggletool,     'state', 'off' );
    set( hZoomOutToggletool,    'state', 'off' );
    set( hPanToggletool,        'state', 'off' );
    set( hQCToggletool,         'state', 'off' );
    set( hTimelimitToggletool,  'state', 'off' );
    % Get the time limits for the correction A TESTER
    % -----------------------------------------------
    dateMin = datenum(get( hetDateMin, 'String'), 'yyyy-mm-dd HH:MM:SS');
    dateMax = datenum(get( hetDateMax, 'String'), 'yyyy-mm-dd HH:MM:SS');
    % Get tsg application data
    % ------------------------
    tsg    = getappdata(hMainFig, 'tsg_data');
    % Get parameter we are working on (SSPS, SSJT, SSTP)
    % or SSPS_CAL, SSJT_CAL, SSTP_CAL
    % -------------------------------------------------
    PARA = getParaCorModule( hMainFig );
    SAMPLE = tsg.plot.sample;
      % Compute the sample-TSG differences
      % ----------------------------------
      diffTsgSample( hMainFig, PARA );
      
    end
    
    % Correction
    % ----------
    error = corTsgBias(hMainFig, PARA, dateMin, dateMax);
        % Plot in the 3 axes
        % ------------------
        plot_Correction( hMainFig, hPlotAxes, PARA );
        msgbox( 'Date limits are not correct',...
          'Correction module', 'warn', 'modal');
        msgbox( {'corTsgBias : unknow error', sprintf('error = %d', error)});
%% linearCorrectionCallback .................................... Correction Module
  function linearCorrectionCallback(src, evnt)
    % Callback function run when
    % Desactivate somme Toggle button
    % -------------------------------
    set( hZoomInToggletool,     'state', 'off' );
    set( hZoomOutToggletool,    'state', 'off' );
    set( hPanToggletool,        'state', 'off' );
    set( hQCToggletool,         'state', 'off' );
    set( hTimelimitToggletool,  'state', 'off' );
    % Get the time limits for the correction A TESTER
    % -----------------------------------------------
    dateMin = datenum(get( hetDateMin, 'String'), 'yyyy-mm-dd HH:MM:SS');
    dateMax = datenum(get( hetDateMax, 'String'), 'yyyy-mm-dd HH:MM:SS');
    % Get tsg application data
    % ------------------------
    tsg    = getappdata(hMainFig, 'tsg_data');
    % Get parameter we are working on (SSPS, SSJT, SSTP)
    % or SSPS_CAL, SSJT_CAL, SSTP_CAL
    % -------------------------------------------------
    PARA = getParaCorModule( hMainFig );
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    SAMPLE = tsg.plot.sample;
    if ~isempty( tsg.([SAMPLE '_EXT']) )
      % Compute the sample-TSG differences
      % ----------------------------------
      diffTsgSample( hMainFig, PARA );
      % Correction
      % ----------
      error = corTsgLinear(hMainFig, PARA, dateMin, dateMax);
          % Plot in the 3 axes
          % ------------------
          plot_Correction( hMainFig, hPlotAxes, PARA );
        case -1
          msgbox( 'Date limits are not correct',...
            'Correction module', 'warn', 'modal');
      end
%% medianCorrectionCallback .................................... Correction Module
  function medianCorrectionCallback(src, evnt)
    % Callback function run when
    % Desactivate somme Toggle button
    % -------------------------------
    set( hZoomInToggletool,       'state', 'off' );
    set( hZoomOutToggletool,       'state', 'off' );
    set( hPanToggletool,        'state', 'off' );
    set( hQCToggletool,         'state', 'off' );
    set( hTimelimitToggletool,  'state', 'off' );
    % Get the time limits for the correction A TESTER
    % --------------------------------------
    dateMin = datenum(get( hetDateMin, 'String'), 'yyyy-mm-dd HH:MM:SS');
    dateMax = datenum(get( hetDateMax, 'String'), 'yyyy-mm-dd HH:MM:SS');
    % Get tsg application data
    % ------------------------
    tsg = getappdata(hMainFig, 'tsg_data');
    % Get parameter we are working on (SSPS, SSJT, SSTP)
    % or SSPS_CAL, SSJT_CAL, SSTP_CAL
    % -------------------------------------------------
    PARA = getParaCorModule( hMainFig );
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    SAMPLE = tsg.plot.sample;
    if ~isempty( tsg.([SAMPLE '_EXT']) )
      % Compute the sample-TSG differences
      % ----------------------------------
      diffTsgSample( hMainFig, PARA );
      % Correction
      % ----------
      error = corTsgMedian(hMainFig, PARA, dateMin, dateMax);
          % Plot in the 3 axes
          % ------------------
          plot_Correction( hMainFig, hPlotAxes, PARA );
        case -1
          
          % dateMax <= dateMin
          % ------------------
          msgbox( {'Function corTsgMedian'; ' '; ...
            'Date limits are not correct' },...
            'Correction Method', 'warn', 'modal');
          
        case -2
          
          % the date are not strictly increasing interp1 cannot be used
          % -----------------------------------------------------------
          msgbox( {'Function corTsgMedian'; ' '; ...
            'At least 2 samples have the same date';...
            'The soft cannot make the interpolation'},...
            'Correction Method', 'warn');
          
          msgbox( {'corTsgMedian : unknow error', sprintf('error = %d', error)});
%% PopupMenu Select Parameter
% POP_UP filled in with the function "initParameterChoice"
% ---------------------------
  function SelectParameter(src, evnt, nplot)
    % Callback function run when the ....
    % Get application data
    % --------------------
    tsg = getappdata( hMainFig, 'tsg_data');
    % Get the active string of the selected box
    % -----------------------------------------
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    val             = get( src, 'Value' );
    string_list     = get( src, 'String' );
    selected_string = string_list{val};
    % Get the default parameter
    % -------------------------
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    tsg.plot.parameter{nplot} =  selected_string;
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
      tsg.plot.sample = selected_string;
      if strcmp( tsg.plot.sample, 'SSJT' )
        tsg.plot.sample = 'SSTP';
    % Save application data
    % --------------------
    setappdata( hMainFig, 'tsg_data', tsg);
    % Disable the climatology
    % -----------------------
    plotClim = 0;
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    if strcmp( get(hClimToggletool, 'state'), 'on' )
      set( hClimToggletool, 'state', 'off' );
      plotClim = 1;
    end
    % Disable the climatology
    % -----------------------
    set( hClimToggletool, 'state', 'off' );
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    plot_Validation( hMainFig, hPlotAxes, 1, tsg.plot.parameter{1} );
    plot_Validation( hMainFig, hPlotAxes, 2, tsg.plot.parameter{2} );
    plot_Validation( hMainFig, hPlotAxes, 3, tsg.plot.parameter{3} );
    % Plot the climatology if it was already plotted
    % ----------------------------------------------
    if plotClim
      set( hClimToggletool, 'state', 'on' );
      plot_Climatology(hMainFig, hPlotAxes);
%% SelectTime_OnMenuCallback
%---------------------------
  function SelectTime_OnMenuCallback(src, evnt)
    % Callback function run when the ....
    % Desactivate Zoom and Pan functions.
    % ----------------------------------
    set( hZoomInToggletool, 'state', 'off' );
    set( hZoomOutToggletool, 'state', 'off' );
    set( hQCToggletool,   'state', 'off' );
    set( hPanToggletool,  'state', 'off' );
    % Create a pointer to select the time limits
    % ------------------------------------------
    selTimePointer = ones(16)+1;
    selTimePointer(1,:)       = 1; selTimePointer(16,:)      = 1;
    selTimePointer(:,1)       = 1; selTimePointer(:,16)      = 1;
    selTimePointer(1:4,8:9)   = 1; selTimePointer(13:16,8:9) = 1;
    selTimePointer(8:9,1:4)   = 1; selTimePointer(8:9,13:16) = 1;
    selTimePointer(5:12,5:12) = NaN; % Create a transparent region in the center
    % Activate clic mouse menu on second axes (salinity) for next rbbox
    % ----------------------------------------------------------------
    set(hMainFig,'WindowButtonDownFcn', @Time_SelectCallback);
    % change cursor
    % ---------------
    set( hMainFig, 'Pointer', 'custom',...
      'PointerShapeCData', selTimePointer, 'PointerShapeHotSpot',[9 9]);
    % ----------------------------------------------------------------------
    % nested function on mouse clic when Select Time toggle tool is selected
    % ----------------------------------------------------------------------
    function Time_SelectCallback(src, evnt)
      % disable ButtonMotion on main fig during select
      % prevent drawing to map
      % ----------------------------------------------
      set( hMainFig, 'WindowButtonMotionFcn', []);
      % Retrieve named application data
      % -------------------------------
      tsg = getappdata( hMainFig, 'tsg_data');
      % Selection of the data within the figure
      % ---------------------------------------
      point1    = get(gca,'CurrentPoint');    % button down detected
      finalRect = rbbox;                      % return figure units
      point2    = get(gca,'CurrentPoint');    % button up detected
      point1 = point1(1,1:2);                 % extract x and y
      point2 = point2(1,1:2);
      p1 = min(point1,point2);
      p2 = max(point1,point2);                % calculate locations
      % get index on selected zone - Only on X axes (time)
      % --------------------------------------------------
      ind = find(tsg.DAYD >= p1(1,1) & tsg.DAYD <= p2(1,1));
      % Write the date in the Editable uicontrol
      % ----------------------------------------
      set( hetDateMin, 'String', datestr(tsg.DAYD(ind(1)),   31));
      set( hetDateMax, 'String', datestr(tsg.DAYD(ind(end)), 31));
      % enable ButtonMotion on main fig after select QC area
      % ----------------------------------------------------
      set( hMainFig, 'WindowButtonMotionFcn', @MouseMotion);
    end
  end

%% SelectTime_OffMenuCallback
%----------------------------
  function SelectTime_OffMenuCallback(src, evnt)
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    % Callback function run when the ....
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    % Desactivate time limit buttons
    % ------------------------------
    set( hTimelimitToggletool, 'state', 'off');
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    set( hMainFig, 'WindowButtonDownFcn', []);
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    set( hMainFig, 'Pointer', 'arrow');
  end

%% Clim_OffMenuCallback
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
%------------------------------------------------------------------------
% Callback function run when the Levitus climatology toolbar is unselected
%------------------------------------------------------------------------
  function Clim_OffMenuCallback(src, evnt)
    % Get the tsg struct from the application GUI
    % -------------------------------------------
    tsg = getappdata( hMainFig, 'tsg_data');
    
    % set climato on map to none (disable)
    % ------------------------------------
    tsg.preference.map.climatology = 'none';
    
    % mask climato range uipanel on map
    set(findobj('tag', 'TAG_MAP_CLIMATO_UIPANEL'),'Visible', 'off');
    % resize map panel for axes
    set(findobj('tag', 'TAG_MAP_CLIMATO_AXES'),'Position',[0, 0, 1, 1])
    
    % Save tsg structure
    % ------------------
    setappdata( hMainFig, 'tsg_data', tsg);
    
    % Get lines handles from tag
    % --------------------------
    hLines = findobj('-regexp', 'Tag', 'TAG_LINE_CLIMATO_');
    % disable and check/uncheck climato menu on map
    set(findobj('tag', 'TAG_UIMENU_MAP_CLIMATOLOGY_WITH_PCOLOR'),...
      'enable', 'off', 'checked', 'off');
    set(findobj('tag', 'TAG_UIMENU_MAP_CLIMATOLOGY_WITH_CONTOURF'),...
      'enable', 'off', 'checked', 'off');
    set(findobj('tag', 'TAG_UIMENU_MAP_CLIMATOLOGY_WITH_NONE'),...
      'checked', 'on');
    
    % Delete climatology lines on axes
    % ---------------------------------
    delete(hLines);
    % Update the map (if visible)
    % ----------------------------
    if strcmp( get(hMapFig,'visible'), 'on') == 1
      erase_Line( hPlotAxes, 4 );
  end

%% Clim_OnMenuCallback
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
%------------------------------------------------------------------------
% Callback function run when the Levitus climatology toolbar is unselected
%------------------------------------------------------------------------
  function Clim_OnMenuCallback(src, evnt)
    % Test if the TSG and bucket files have been read
    % -----------------------------------------------
    if strcmp( get(hOpenMenu, 'UserData'), 'on' )
      % Read surface climatology (annual, seasonal or monthly)
      % ------------------------------------------------------
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
      if read_Climatology(hMainFig)
        
        % enable climato menu on map
        set(findobj('tag', 'TAG_UIMENU_MAP_CLIMATOLOGY_WITH_PCOLOR'),'enable', 'on');
        set(findobj('tag', 'TAG_UIMENU_MAP_CLIMATOLOGY_WITH_CONTOURF'),'enable', 'on');
        
        % find all climato on map submenu and set 'checked' property to 'off'
        % ------------------------------------------------------------
        hdl = findobj( '-regexp', 'tag', 'TAG_UIMENU_MAP_CLIMATOLOGY_WITH_');
        set(hdl, 'checked', 'off');
        
        % check menu with the previously selected climatology
        % ---------------------------------------------------
        switch tsg.preference.map.climatology
          case 'pcolor'
            set(findobj('tag', 'TAG_UIMENU_MAP_CLIMATOLOGY_WITH_PCOLOR'),'checked', 'on');
          case 'contourf'
            set(findobj('tag', 'TAG_UIMENU_MAP_CLIMATOLOGY_WITH_CONTOURF'),'checked', 'on');
          otherwise
            set(findobj('tag', 'TAG_UIMENU_MAP_CLIMATOLOGY_WITH_NONE'),'checked', 'on');
        end
        
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
        % plot climatology
        % ----------------
        plot_Climatology(hMainFig, hPlotAxes);
      end
    end
  end

%% ClimatoSelectMenuCallback
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
% -------------------------------------------------------------------
% Callback function run when climato submenu is selected
% -------------------------------------------------------------------
  function ClimatoSelectMenuCallback(src, evnt, climato, time)
    % find all climato submenu and set 'checked' property to 'off'
    % ------------------------------------------------------------
    hdl = findobj( '-regexp', 'tag', 'TAG_UIMENU_CLIMATO');
    set(hdl, 'checked', 'off');
    % set current climato submenu checked
    % -----------------------------------
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    set(src, 'checked', 'on');
    % memorize action on climatology menu for next use
    % ------------------------------------------------
    s.type = climato;
    s.time = time;
    set(hClimatoMenu, 'userdata', s);
    % check if climatology toggle button is set
    % -----------------------------------------
    if strcmp(get(hClimToggletool, 'state'), 'on')
      % clear last plotted climatology
      % ------------------------------
      Clim_OffMenuCallback;
      % Read surface climatology (annual, seasonal or monthly)
      % ------------------------------------------------------
      read_Climatology(hMainFig);
      % plot and read (eventually) new climatology
      % ------------------------------------------
      plot_Climatology(hMainFig, hPlotAxes);
  end

%% PreferencesMenuCallback
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
% -------------------------------------------------------------------
% Callback function run when Option/Preference is selected
% -------------------------------------------------------------------
  function PreferencesMenuCallback(src, evnt)
    oldmapres=tsg.preference.map.resolution;
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    % call preferences form function
    % ------------------------------
    if( preferencesForm(hMainFig) )
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
      % if form is validate, update plots only if plot exist
      % ----------------------------------------------------
      if ~isempty(findobj( '-regexp', 'Tag', ('TAG_PLOT\d_LINE_')))
        SelectParameter(pmhPara(1),[],1);
      end
      % Update the map (if visible) if ship speed QC has been applied
      % or map resolution has been changed
      % -------------------------------------------------------------
      if (strcmp( get(hMapFig,'visible'), 'on') == 1 & ...
          tsg.preference.map.resolution ~= oldmapres)
        erase_Line( hPlotAxes, 4 );
        plot_map( hMainFig, hPlotAxes);
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
%% HelpMenuCallback
% -------------------------------------------------------------------
% Callback function run when Help/Help is selected
% -------------------------------------------------------------------
  function HelpMenuCallback(src, evnt)
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    msgbox( 'Function Help not yet implemented', 'warn', 'modal');
  end

%% AboutMenuCallback
% -------------------------------------------------------------------
% Callback function run when Help/About is selected
% -------------------------------------------------------------------
  function AboutMenuCallback(src, evnt)
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    %splash('Thermo.jpg', 3000);
    aboutDialog(hMainFig, DEFAULT_PATH_FILE);
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
  end
%% Map menus
% -----------
  function mapResolutionCallback(src, evnt, resolution)
    % get the tsg structure
    % ---------------------