Skip to content
Snippets Groups Projects
tsgqc.m 133 KiB
Newer Older
        minSSPSQC(hMainFig)
      case 'SSPSmax'
        maxSSPSQC(hMainFig)
      case 'SSJTmin'
        minSSJTQC(hMainFig)
      case 'SSJTmax'
        maxSSJTQC(hMainFig)
      case 'SSTPmin'
        minSSTPQC(hMainFig)
      case 'SSTPmax'
        maxSSTPQC(hMainFig)
      otherwise
        msgbox('QCMenuCallback : erreur', 'QCMenuCallback','error', 'modal');
    end

    % --------------------------
    % refresh QC statistic panel
    % --------------------------
    display_QC( hMainFig );

    % ------------------
    % Refresh the plots
    %-------------------
    
    % Get the parameter displayed on plot number 1 : figure at the top
    % -----------------------------------------------------------------
    PARA = getParaCorModule( hMainFig );

    % Draw plot 1
    % -----------
    plot_Validation( hMainFig, hPlotAxes, 1, PARA{1} );

    % Update the map if already displayed
    % -----------------------------------
    if strcmp( get(hMapFig,'visible'), 'on') == 1
      erase_Line( hPlotAxes, 4 );
      plot_map( hMainFig, hPlotAxes);
    end

  end


%% QC_OnMenuCallback ............................... Quality Control Module
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
%----------------------------------------------------------------------
% Callback function run when the QC toggle tool is pressed
%----------------------------------------------------------------------
  function QC_OnMenuCallback(gcbo, eventdata)
    % Make the QC code uipanel visible
    % --------------------------------
    set( hbgQc,                'Visible' ,'on');
    set( hbgParameter,         'Visible', 'off');
    % Desactivate toggletools.
    % ------------------------
    set( hZoomInToggletool,    'state', 'off', 'enable', 'on' );
    set( hZoomOutToggletool,   'state', 'off', 'enable', 'on' );
    set( hPanToggletool,        'state', 'off' );
    set( hTimelimitToggletool,  'state', 'off' );
    set( hCalToggletool,        'state', 'off', 'enable', 'off'  );
    set( hInterpToggletool,     'state', 'off', 'enable', 'off' );
    % Retrieve named application data
    % -------------------------------
    tsg = getappdata( hMainFig, 'tsg_data');

    PARA = getParaCorModule( hMainFig );
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    SAMPLE = tsg.plot.sample;
    % refresh QC statistic panel
    % --------------------------
    display_QC( hMainFig );
    % Activate right clic context menu on first axes (salinity)
    % ---------------------------------------------------------
    set(hPlotAxes(1),'UIContextMenu', hQcCmenu);

    % Activate clic mouse menu on first axes (salinity) for next rbbox
    % ----------------------------------------------------------------
    set(hPlotAxes(1),'ButtonDownFcn', @QC_SelectCallback);
    % change cursor to crosshair aspect
    % ---------------------------------
    set( hMainFig, 'Pointer', 'crosshair');
    % -------------------------------------------------------------
    % nested function on mouse clic when QC toggle tool is selected
    % -------------------------------------------------------------
    function QC_SelectCallback(gcbo, eventdata)
      % disable ButtonMotion on main fig during select
      % prevent drawing to map
      % ----------------------------------------------
      set( hMainFig, 'WindowButtonMotionFcn', []);

      % 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

      % The following code is only executed if the left mouse button is clicked.
      % If the right mouse button is clicked, this code must not be
      % executed as the variable 'ind' will be emptied. And this variable
      % is used when the context menu (callback 'Qc') is called
      % -----------------------------------------------------------------
      if ~strcmp( get(gcf, 'SelectionType'), 'alt')

        % The QC is applied either on TSG data either on Sample data.
        % it depends if the Botte Toggle button has been cliked on
        % -----------------------------------------------------------
        if strcmp( get(hBottleToggletool, 'state'), 'on')

          % get index on selected zone
          % --------------------------
          if ~isempty(tsg.DAYD_EXT)
            ind = find(tsg.DAYD_EXT > p1(1) &  tsg.DAYD_EXT < p2(1) & ...
              tsg.EXT_DIF  > p1(2) &  tsg.EXT_DIF  < p2(2));

            % Keep the information on the indices of the selected zone
            % --------------------------------------------------------
            tsg.rbboxind = ind .* ones(size(ind));

            % Modifiy the QC
            % --------------
            tsg.([SAMPLE '_EXT_QC'])(ind) = tsg.qc.active.Code;

            % Save the modifications
            % ----------------------
            setappdata( hMainFig, 'tsg_data', tsg);

            % plot selected data with selected code
            % --------------------------------------
            plot_Correction( hMainFig, hPlotAxes, PARA);

        else

          % get index on selected zone
          % ---------------------------
          ind = find(tsg.DAYD   > p1(1,1) & tsg.DAYD   < p2(1,1) & ...
            tsg.(PARA{1}) > p1(1,2) & tsg.(PARA{1}) < p2(1,2));

          % Keep the information on the indices of the selected zone
          % --------------------------------------------------------
          tsg.rbboxind = ind .* ones(size(ind));
          % Modifiy the QC
          % --------------
          tsg.([PARA{1} '_QC'])(ind) = tsg.qc.active.Code;

          % put last SSPS_QC in queue (Undo/Redo)
          % -------------------------------------
          %tsg.queue = push( tsg.queue, tsg.([PARA '_QC']));

          % store QC in queue object, for undo
          % ----------------------------------
          %tsg.queue = push(tsg.queue, tsg.([PARA '_QC']));

          % Save the modifications
          % ----------------------
          setappdata( hMainFig, 'tsg_data', tsg);

jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
          % Draw plot 1 of the validation figure
          % ------------------------------------
          plot_Validation( hMainFig, hPlotAxes, 1, PARA{1} );

          % refresh QC statistic panel
          % --------------------------
          display_QC( hMainFig );
          % Update the map if already displayed
          % -----------------------------------
          if strcmp( get(hMapFig,'visible'), 'on') == 1
            erase_Line( hPlotAxes, 4 );
            plot_map( hMainFig, hPlotAxes);
          % enable undo menu
          % ----------------
          set(findobj('tag','UIMENU_UNDO'),'enable','on');
        end

        % As soon as a modification took place the data should be saved
        % -------------------------------------------------------------
        set( hSaveMenu, 'UserData', 'on' );

      end

      % enable ButtonMotion on main fig after select QC area
      % ----------------------------------------------------
      set( hMainFig, 'WindowButtonMotionFcn', @MouseMotion);

    end
  end

%% QC_OffMenuCallback .............................. Quality Control Module
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
%----------------------------------------------------------------------
% Callback function run when the QC toggle tool is released
%----------------------------------------------------------------------
  function QC_OffMenuCallback(gcbo, eventdata)

    % Desactive right clic menu on first axes (salinity)
    % ---------------------------------------------------
    set(hPlotAxes(1),'UIContextMenu', []);
    % Desactive clic mouse menu (zoom) on first axes (salinity)
    % ----------------------------------------------------------
    set(hPlotAxes(1),'ButtonDownFcn', []);
    % Uipanel visible or not
    % -----------------------
    set( hbgQc,        'Visible', 'off' );
    if strcmp( get(hBottleToggletool, 'state'), 'off' )
      set( hCalToggletool,        'state', 'off', 'enable', 'on' );
      set( hInterpToggletool,     'state', 'off', 'enable', 'on' );
    end

    % uibuttongroup uipanel used to choose a parameter is set to
    % on only if the Correction screen (bottle toggletool) is off
    % -----------------------------------------------------------
    if  strcmp( get( hBottleToggletool, 'state'), 'off')
      set( hbgParameter, 'Visible', 'on');
    end
    % cursor back to normal
    % ---------------------
    set(hMainFig,'Pointer','arrow');
  end

%% Qc context menu selected ........................ Quality Control Module
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
%-----------------------------------------------------------
% Callback function run when the QC context menu is selected
%
% Context menu used to attribute a QC to the TSG time series
%
%-----------------------------------------------------------
  function Qc(hObject, eventdata, key)

    % Retrieve Default Quality Code and Color
    % ---------------------------------------
    tsg = getappdata( hMainFig, 'tsg_data');
    % Get the parameter (SSPS, SSJT or SSTP)
    % --------------------------------------
    PARA = getParaCorModule( hMainFig );
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    SAMPLE = tsg.plot.sample;
    % get key and some values in hashtable
    % ------------------------------------
    code  = tsg.qc.hash.(key).code;
    color = tsg.qc.hash.(key).color;

    % set active code and color from selected context menu
    % ----------------------------------------------------
    tsg.qc.active.Code  = code;
    tsg.qc.active.Color = color;
    % Modify and plot the last selected tsg data
    % ------------------------------------------
    if isfield(tsg, 'rbboxind') && ~isempty( tsg.rbboxind )

      if strcmp( get(hBottleToggletool, 'state'), 'on')

        tsg.([SAMPLE '_EXT_QC'])(tsg.rbboxind) = tsg.qc.active.Code;
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
        % Save tsg.SSPS_QC and tsg.qc.active.Code
        % in the application data
        % ----------------------------------------
        setappdata( hMainFig, 'tsg_data', tsg );

        % Draw the 3 plots of the Correction figure
        % -----------------------------------------
        plot_Correction( hMainFig, hPlotAxes, PARA );

      else
        tsg.([PARA{1} '_QC'])(tsg.rbboxind) = tsg.qc.active.Code;
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
        % Save tsg.SSPS_QC in the application data before use 
        % inside plot_Validation
        % ---------------------------------------------------
        setappdata( hMainFig, 'tsg_data', tsg );
        % Draw plot 1 of the validation figure
        % ------------------------------------
        plot_Validation( hMainFig, hPlotAxes, 1, PARA{1} );
      end

    end

    % Update the radio button corresponding to the selected
    % QC context menu (rbg : RadioButtonGroup)
    % -----------------------------------------------------
    %     radioTag     = ['TAG_QC_RADIO_' key];        % Build the TAG of the CODE
    %     hbgChildren  = get(hbgQc,'Children');        % Get the handles of the rbg
    %     hbgTagCell   = get(hbgChildren, 'tag');      % get the TAG of the rbg
    %     ind          = strcmp(radioTag, hbgTagCell); % Compare the TAG
    %     hRadioButton = hbgChildren( ind == 1 );      % Get the handle of the button
    %     set(hbgQc, 'SelectedObject', hRadioButton);  % Make this button active
    setappdata( hMainFig, 'tsg_data', tsg );

  end

%% Radiobutton Quality Control ..................... Quality Control Module
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
% ---------------------------------------------------------------
% Callback to select CODE and COLOR QC from the RadioButton Group
% ---------------------------------------------------------------
  function RadiobuttonQc(source, eventdata)

jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    % Retrieve Default Quality Code and Color
    % ---------------------------------------
    tsg = getappdata( hMainFig, 'tsg_data');
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    % Retrieve the key from the active RadioButton
    % --------------------------------------------
    rbTag = get(eventdata.NewValue,'Tag');
    key = strrep(rbTag, 'TAG_QC_RADIO_', '');

    % store his handle to uibuttongroup userdata
    % ------------------------------------------
    set(hbgQc,'Userdata', eventdata.NewValue);

    % set active code and color from selected context menu
    % ----------------------------------------------------
    tsg.qc.active.Code  = tsg.qc.hash.(key).code;
    tsg.qc.active.Color = tsg.qc.hash.(key).color;
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    setappdata( hMainFig, 'tsg_data', tsg );

  end

%% preQcPanCallback .................................Quality Control Module
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
% ---------------------------------------------------------------
% Callback function ... to be completed
% ---------------------------------------------------------------
  function preQcPanCallback(obj, evd)

    set(hQCToggletool, 'state', 'off' );

  end

%% postQcPanCallback ............................... Quality Control Module
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
% ---------------------------------------------------------------
% Callback function ... to be completed
% ---------------------------------------------------------------
  function postQcPanCallback(obj, evd)
    % Set the right limit and interval to the 3 axes
    % ----------------------------------------------
    for iaxe = 1:3
      set(hPlotAxes(iaxe),'XTickMode','auto')
      datetick(hPlotAxes(iaxe),'x','keeplimits')
    end

    % Re-draw the map once the pan is off -  only valide in QC mode
    % -------------------------------------------------------------
    if strcmp( get(hMapFig, 'visible'), 'on') == 1
      erase_Line( hPlotAxes, 4 );
      plot_map( hMainFig, hPlotAxes);
    end
    % 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(hObject, eventdata)

    % 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'));
        set( hInfoLatText,  'String', dd2dm(tsg.LATX(indCursor), 0) );
        set( hInfoLongText, 'String', ...
          dd2dm(mod(tsg.LONX(indCursor) + 180, 360) - 180, 1) );
        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) );
        end

        % Plot the position on the map if this one is active
        % --------------------------------------------------
        if strcmp( get(hMapFig, 'Visible'), 'on')

          % Select the map axes
          % -------------------
          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', 5, ...
                'Color', 'r', 'MarkerFaceColor', 'r');
              % 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', 5, ...
                'Color', 'r', 'MarkerFaceColor', 'r');
              % Put a tag on the Marker - This tag allows to get the handle
              % of the Marker
              % -----------------------------------------------------------
              set( hMarker, 'TAG', 'TAG_PLOT4_LINE_MARKER' );
         end % end of map visible
        
      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(hObject, eventdata)
    % 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
    % --------------------------------------------
    set(hMainFig, 'KeyPressFcn', []);
%% 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(hObject, eventdata)
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
    % ---------------------------------------------
    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(hObject, eventdata)
    % 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
      % ----------------------------------
      errDif = diffTsgSample( hMainFig, PARA );
      
      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;
    % 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(hObject, eventdata)
    % 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
    % -----------------------------------------
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} );
    % Necessary to unzoom as the new plot keep in memory the preceding zoom
    % ---------------------------------------------------------------------
    zoom out;
    % Set the pointer
    % ---------------
    set( hMainFig, 'Pointer', 'arrow');

  end

%% OldCorCancelCallback .................................... Correction Module
  function OldCorCancelCallback(hObject, eventdata)
    % 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 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 );
Yves Gouriou's avatar
Yves Gouriou committed
    % To cancel the correction set the ADJUSTED variable
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
    % to []
    % --------------------------------------------------
    tsg.([PARA{1} '_ADJUSTED']) = [];
    tsg.([PARA{1} '_ADJUSTED_QC']) = [];
    tsg.([PARA{1} '_ADJUSTED_ERROR']) = [];

    % Save tsg data
    % -------------
    setappdata(hMainFig, 'tsg_data', tsg);

    % Plot in the 3 axes
    % ------------------
    plot_Correction( hMainFig, hPlotAxes, PARA );

  end
%% cancelCorrectionCallback .................................... Correction Module
  function cancelCorrectionCallback(hObject, eventdata, 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.
% $Id$

    % 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( 'CorCancelCallback : error', 'CorCancelCallback', 'error', modal);
    end

    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 );

  end

%% gradientCorrectionCallback .................................... Correction Module
  function gradientCorrectionCallback(hObject, eventdata)
    % 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
    % --------------------------------------
    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;

    if ~isempty( tsg.([SAMPLE '_EXT']) )

      % Compute the sample-TSG differences
      % ----------------------------------
      diffTsgSample( hMainFig, PARA );

      % Correction
      % ----------
      error = corTsgGradient(hMainFig, PARA, dateMin, dateMax);

      switch error

        case 1

          % Plot in the 3 axes
          % ------------------
          plot_Correction( hMainFig, hPlotAxes, PARA );

          if DateMax <= DateMin
            msgbox( 'Date limits are not correct',...
              'Correction module', 'warn', 'modal');
          end
%% biasCorrectionCallback .................................... Correction Module
  function biasCorrectionCallback(hObject, eventdata)
    % 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 );
    SAMPLE = tsg.plot.sample;

    if ~isempty( tsg.([SAMPLE '_EXT']) )

      % 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 );
        if DateMax <= DateMin
          msgbox( 'Date limits are not correct',...
            'Correction module', 'warn', 'modal');
        end
        
      otherwise
        msgbox( 'CorBiasCallback : Error different   or -1',' ', 'error');
%% linearCorrectionCallback .................................... Correction Module
  function linearCorrectionCallback(hObject, eventdata)
    % 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(hObject, eventdata)
    % 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
    % ------------------------