Skip to content
Snippets Groups Projects
tsgqc_GUI.m 75.4 KiB
Newer Older
  %----------------------------------------------------------------------
  % Callback function run when the pan toggle toolbar is released
  %----------------------------------------------------------------------
  function Pan_OffMenuCallback(hObject, eventdata)
    
    % turns interactive pan off
    % -------------------------
    pan off;
    
Yves Gouriou's avatar
Yves Gouriou committed
    % 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
 
    % Turns off the automatic adaptation of date ticks
    % ------------------------------------------------
    panAdaptiveDateTicks('off');
  %----------------------------------------------------------------------
  % Callback function run when the pan toggle toolbar is selected
  %----------------------------------------------------------------------
  function Pan_OnMenuCallback(hObject, eventdata)
    
    % cursor back to normal
    % ---------------------
    set(hMainFig,'Pointer','arrow');
    
    % Returns a pan mode object for the figure handle
    % -----------------------------------------------
    % Disallows a pan operation on the MAP axes objects
    % --------------------------------------------------
    setAllowAxesPan(hPan, hPlotAxes(4), false);
Yves Gouriou's avatar
Yves Gouriou committed

    % turns on interactive pan (same effect than pan on) but prevent
    % side effect on another figure
Yves Gouriou's avatar
Yves Gouriou committed
    % --------------------------------------------------------------
    set(hPan,'enable', 'on');
    
    % Turns on the automatic adaptation of date ticks
    % -----------------------------------------------
    panAdaptiveDateTicks('on');
    % Desactivate some toggle buttons
    % -------------------------------
    set( hQCToggletool,   'state', 'off' );
    set( hZoomToggletool, 'state', 'off' );
    set( hStartlimitToggletool, 'State', 'off' );
    set( hEndlimitToggletool,   'State', 'off' );
%% QC_OffMenuCallback .............................. Quality Control Module
  %----------------------------------------------------------------------
  % 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', []);
      
%     % No selection on uibuttongroup QC
%     % --------------------------------
%     set(hbgQc,'SelectedObject',[]);  
       
    % cursor back to normal
    % ---------------------
    set(hMainFig,'Pointer','arrow');
%% QC_OnMenuCallback ............................... Quality Control Module
  %----------------------------------------------------------------------
  % Callback function run when the QC toggle tool is pressed
  %----------------------------------------------------------------------
  function QC_OnMenuCallback(gcbo, eventdata)
    
    % Desactivate Zoom and Pan functions.
    % ----------------------------------
    set( hZoomToggletool,       'state', 'off' );
    set( hPanToggletool,        'state', 'off' );
    set( hStartlimitToggletool, 'State', 'off' );
    set( hEndlimitToggletool,   'State', 'off' );
Yves Gouriou's avatar
Yves Gouriou committed

    % Activate right clic context menu on first axes (salinity)
    % ---------------------------------------------------------
Yves Gouriou's avatar
Yves Gouriou committed
    set(hPlotAxes(1),'UIContextMenu', hQcCmenu);
    % Activate clic mouse menu on first axes (salinity) for next rbbox
    % ----------------------------------------------------------------
Yves Gouriou's avatar
Yves Gouriou committed
    set(hPlotAxes(1),'ButtonDownFcn', @QC_SelectCallback);
    % change cursor to crosshair aspect
    % ---------------------------------
    % -------------------------------------------------------------
    % nested function on mouse clic when QC toggle tool is selected
    % -------------------------------------------------------------
    function QC_SelectCallback(gcbo, eventdata)
      % disable ButtonMotion on main fig during select
      % ----------------------------------------------
      set( hMainFig, 'WindowButtonMotionFcn', []);
      % Retrieve named application data
      % -------------------------------
      sample = getappdata( hMainFig, 'sample');
      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
      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
          % --------------------------
          ind = find(sample.DAYD     > p1(1,1) & sample.DAYD     < p2(1,1) & ...
                     sample.SSPS_DIF > p1(1,2) & sample.SSPS_DIF < p2(1,2));

          % Keep the information on the indices of the selected zone
          % --------------------------------------------------------
          tsg.rbboxind = ind .* ones(size(ind));
          
          % Modifiy the QC
          % --------------
          sample.SSPS_QC(ind) = tsg.qc.active.Code;

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

          % plot selected data with selected code
          % --------------------------------------
Yves Gouriou's avatar
Yves Gouriou committed
          erase_Line( hPlotAxes, 1 );
          erase_Line( hPlotAxes, 2 );
          plot_Sample( hMainFig, hPlotAxes, 1, 'SSPS_DIF', [] );
          plot_Tsg(    hMainFig, hPlotAxes, 2, 'SSPS', 1, [] );
          plot_Sample( hMainFig, hPlotAxes, 2, 'SSPS', [] );

        else

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

          % Keep the information on the indices of the selected zone
          % --------------------------------------------------------
          tsg.rbboxind = ind .* ones(size(ind));
          
          % Modifiy the QC
          % --------------
          tsg.SSPS_QC(ind) = tsg.qc.active.Code;

          % put last SSPS_QC in queue (Undo/Redo)
          % -------------------------------------
          tsg.queue = push( tsg.queue, tsg.SSPS_QC);

          % store QC in queue object, for undo
          % ----------------------------------
          tsg.queue = push(tsg.queue, tsg.SSPS_QC);

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

          % plot selected data with selected code
          % --------------------------------------
Yves Gouriou's avatar
Yves Gouriou committed
          erase_Line( hPlotAxes, 1 );
          plot_Tsg(    hMainFig, hPlotAxes, 1, 'SSPS', 1, [] );
          plot_Sample( hMainFig, hPlotAxes, 1, 'SSPS', [] );

          % refresh QC statistic panel
          % --------------------------
          display_QC( 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' );
      % enable ButtonMotion on main fig after select QC area
      % ----------------------------------------------------
      set( hMainFig, 'WindowButtonMotionFcn', @MouseMotion);
%% Qc context menu selected ........................ Quality Control Module
  %-----------------------------------------------------------
  % 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');
    sample = getappdata( hMainFig, 'sample');
    % get key and some values in hashtable
    % ------------------------------------
    code  = get(tsg.qc.hash, key, 'code');
    color = get(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 ~isempty( tsg.rbboxind )

      if strcmp( get(hBottleToggletool, 'state'), 'on')
        sample.SSPS_QC(tsg.rbboxind) = tsg.qc.active.Code;
Yves Gouriou's avatar
Yves Gouriou committed
        % Save tsg.SSPS_QC and tsg.qc.active.Code 
        % in the application data
        % ----------------------------------------
        setappdata( hMainFig, 'sample', sample);
Yves Gouriou's avatar
Yves Gouriou committed
        setappdata( hMainFig, 'tsg_data', tsg );
        % Plot selected data with the new codes
        % --------------------------------------
Yves Gouriou's avatar
Yves Gouriou committed
        erase_Line( hPlotAxes, 1 );
        erase_Line( hPlotAxes, 2 );
        plot_Sample( hMainFig, hPlotAxes, 1, 'SSPS_DIF', [] );
        plot_Tsg(    hMainFig, hPlotAxes, 2, 'SSPS', 1, [] );
        plot_Sample( hMainFig, hPlotAxes, 2, 'SSPS', [] );
      else
        tsg.SSPS_QC(tsg.rbboxind) = tsg.qc.active.Code;
        % Save tsg.SSPS_QC in the application data
        % ----------------------------------------
        setappdata( hMainFig, 'tsg_data', tsg );
Yves Gouriou's avatar
Yves Gouriou committed
        
        % Plot the TSG data with new codes
        % --------------------------------
        erase_Line( hPlotAxes, 1 );
        plot_Tsg(    hMainFig, hPlotAxes, 1, 'SSPS', 1, [] );
        plot_Sample( hMainFig, hPlotAxes, 1, 'SSPS', [] );
    % 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 );
%% Radiobutton Quality Control ..................... Quality Control Module
  % ---------------------------------------------------------------
  % Callback to select CODE and COLOR QC from the RadioButton Group
  % ---------------------------------------------------------------
  function RadiobuttonQc(source, eventdata)
        
      % Retrieve Default Quality Code and Color
      % ---------------------------------------
      tsg = getappdata( hMainFig, 'tsg_data');
      % 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);
      
      % get key and some values in hashtable
      % ------------------------------------
      code  = get(tsg.qc.hash, key, 'code');
      color = get(tsg.qc.hash, key, 'color');
       
      % set active code and color from selected context menu
      % ----------------------------------------------------
      tsg.qc.active.Code  = code;
      tsg.qc.active.Color = color;

      setappdata( hMainFig, 'tsg_data', tsg );

  end

%% preQcPanCallback .................................Quality Control Module
function preQcPanCallback(obj, evd)
  
  set(hQCToggletool, 'state', 'off' );

end

%% postQcPanCallback ............................... Quality Control Module
function postQcPanCallback(obj, evd)
  
  set(hQCToggletool, 'state', 'on' );
  
  % 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
  
end

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

Yves Gouriou's avatar
Yves Gouriou committed
      % Get current position of cusor and return its coordinates in
      % axes with handle h_axes
      % -----------------------------------------------------------
Yves Gouriou's avatar
Yves Gouriou committed
      
      % Get the Limits of axes 1
      % ------------------------
      limx = get(hPlotAxes(1), 'XLim');
      limy = get(hPlotAxes(1), 'YLim');
Yves Gouriou's avatar
Yves Gouriou committed
      % Code to Activate the PAN function when QC mode is active
      % A PAN zone is defined in the bottom (10%) of PlotAxes(1)
Yves Gouriou's avatar
Yves Gouriou 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.
      % ---------------------------------------------------------
      qcState = get(hQCToggletool,   'state' );
      if strcmp(qcState, 'on' );
        
        % Suppose that Y axes is increasing from the bottom to the top
        % ------------------------------------------------------------
        limy2 = limy(1) + (limy(2)-limy(1)) * 0.10;
Yves Gouriou's avatar
Yves Gouriou committed

        if  x > limx(1) && x < limx(2) &&  y <= limy2 && y >= limy(1)
Yves Gouriou's avatar
Yves Gouriou committed
          hPan = pan(hMainFig);
          set(hPan,'ActionPreCallback',  @preQcPanCallback);
          set(hPan,'ActionPostCallback', @postQcPanCallback);
Yves Gouriou's avatar
Yves Gouriou committed
          set(hPan,'Enable','on');
        else
          pan off
        end
      end
      
      % Dynamically display data in uicontrol
      % -------------------------------------
Yves Gouriou's avatar
Yves Gouriou committed
      %if x > tsg.DAYD(1) && x < tsg.DAYD(end)
      if  x > limx(1) && x < limx(2)

Yves Gouriou's avatar
Yves Gouriou committed
        indCursor = find( tsg.DAYD > x);
        set( hInfoDateText, 'String',...
          datestr(tsg.DAYD(indCursor(1)),'dd/mm/yyyy   HH:MM'));
        set( hInfoLatText,  'String', dd2dm(tsg.LATX(indCursor(1)),0));
        set( hInfoLongText, 'String', dd2dm(tsg.LONX(indCursor(1)),1));
        set( hInfoSSPSText, 'String', tsg.SSPS(indCursor(1)));
        set( hInfoSSJTText, 'String', tsg.SSJT(indCursor(1)));
        if ~isempty(tsg.SSTP)
          set( hInfoSSTPText, 'String', tsg.SSTP(indCursor(1)));
        end

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

          % Select the map axes
          % -------------------
          axes( hPlotAxes(4));

          if isempty( get(hMapPanel, 'UserData'))
Yves Gouriou's avatar
Yves Gouriou committed
            hMarker = m_line( tsg.LONX(indCursor(1)), tsg.LATX(indCursor(1)),...
                              'Marker','o','MarkerSize',5, ...
                              'Color','r', 'MarkerFaceColor','r');
Yves Gouriou's avatar
Yves Gouriou committed
            set(hMapPanel, 'UserData', hMarker)
          else
            delete(get(hMapPanel, 'UserData'));
            hMarker = m_line( ...
Yves Gouriou's avatar
Yves Gouriou committed
                             tsg.LONX(indCursor(1)), tsg.LATX(indCursor(1)),...
                             'Marker','o','MarkerSize',5, ...
                             'Color','r', 'MarkerFaceColor','r');
Yves Gouriou's avatar
Yves Gouriou committed
            set(hMapPanel, 'UserData', hMarker);
  %---------------------------------------------------------------------
  % Callback function run when the Map tool bar item is unselected
  %---------------------------------------------------------------------
  function Map_OffMenuCallback(hObject, eventdata)
    
    %if ~isempty( get(hMapPanel, 'UserData'))
    %  delete(get(hMapPanel, 'UserData'));
    %end

    %hLines = findobj( hPlotAxes(4), 'Tag', 'TAG_AXES_MAP');
    %hLines = get( hPlotAxes(4), 'Children' );
    %if ~isempty( hLines )
    %  delete(hLines);
    %end
   % Make the earth map invisible
    % ----------------------------
    set(hMapPanel, 'Visible', 'off' ); 

  %---------------------------------------------------------------------
  % Callback function run when the Map tool bar item is selected
  %---------------------------------------------------------------------
  function Map_OnMenuCallback(hObject, eventdata)
     
    % Desactivate Zoom and Pan toggle buttons
    % may be change in the futur ...
    % ---------------------------------------
    set(hZoomToggletool,  'state', 'off' );
    set(hPanToggletool,  'state', 'off' );
    % Make the earth map visible
    % --------------------------
Yves Gouriou's avatar
Yves Gouriou committed
    erase_Line( hPlotAxes, 4 );
%% Bottle_OnMenuCallback ................................ Correction Module
  %---------------------------------------------------------------------
  % 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');
    
    % Desactivate the Climatology button
    % ----------------------------------
    set( hClimToggletool, 'Enable', 'off');
    % Switch somme buttons
    % --------------------
    set( hZoomToggletool, 'state', 'off' );
    set( hQCToggletool,   'state', 'off' );
    set( hPanToggletool,  'state', 'off' );
    % Activate some toolbar buttons
    % -----------------------------
    hdl_Toggletool = findobj('-regexp','Tag', 'CORRECT_');
    set(hdl_Toggletool, 'Enable', 'on');
    
    % Test if tsg and sample data have been loaded
    % --------------------------------------------
    if ~isempty( tsg.SSPS_WS ) || ~isempty( tsg.SSPS_EXT )
      
      % Compute the sample-TSG differences
      % ----------------------------------
      diffTsgSample( hMainFig );

      % plot Salinity Difference
      % ------------------------
      %plot_Sample( hMainFig, hPlotAxes );
Yves Gouriou's avatar
Yves Gouriou committed
      erase_Line( hPlotAxes, 1 )
      erase_Line( hPlotAxes, 2 )
      erase_Line( hPlotAxes, 3 )

      plot_Sample( hMainFig, hPlotAxes, 1, 'SSPS_DIF', [] );
      
      plot_Tsg(    hMainFig, hPlotAxes, 2, 'SSPS', 1, [] );
      plot_Sample( hMainFig, hPlotAxes, 2, 'SSPS', [] );
      
      plot_Tsg(    hMainFig, hPlotAxes, 3, 'SSPS', 0, 'k' );
      plot_Tsg(    hMainFig, hPlotAxes, 3, 'SSPS_ADJUSTED', 0, 'r' );
     
      axesCommonProp( hPlotAxes );

      % Get the information on time limits of the time series
      % Write them in the uipanel
      % -----------------------------------------------------
Yves Gouriou's avatar
Yves Gouriou committed
      noNaN = tsg.DAYD(~isnan( tsg.DAYD ));
      set( hetDateMin, 'String', datestr(noNaN(1), 31));
      set( hetDateMax, 'String', datestr(noNaN(end), 31)); 

      % Desactivate the corretion module
      % --------------------------------
      set( hBottleToggletool, 'state', 'off' );
      
      msgbox('Sample data not loaded in the program', 'modal');
%% Bottle_OffMenuCallback ............................... Correction module
  %---------------------------------------------------------------------
  % Callback function run when the bootle push tool is selected
  %---------------------------------------------------------------------
  function Bottle_OffMenuCallback(hObject, eventdata)
Yves Gouriou's avatar
Yves Gouriou committed
    % Transfert de la structure Sample  la structure 
    % RESTE A ECRIRE
    % -----------------------------------------------
    
    % Activate the Climatology button
    % -------------------------------
    set( hClimToggletool, 'Enable', 'on');
    
    % If necessary toggle off some buttons
    % ------------------------------------
    set( hZoomToggletool, 'state',  'off' );
    set( hQCToggletool,   'state',  'off' );
    set( hPanToggletool,  'state',  'off' );
    
    % Desactivate some toolbar buttons
    % --------------------------------
    hdl_Toggletool = findobj('-regexp','Tag', 'CORRECT_');

    set( hStartlimitToggletool, 'State', 'off' );
    set( hEndlimitToggletool,   'State', 'off' );

    % Desactivate Click Mouse on figure
    % ---------------------------------
    set( hMainFig, 'WindowButtonDownFcn', []);

    % Plot the SSS, SST and Velocity
    % ------------------------------
Yves Gouriou's avatar
Yves Gouriou committed
    erase_Line( hPlotAxes, 1 );
    erase_Line( hPlotAxes, 2 );
    erase_Line( hPlotAxes, 3 );
    
    plot_Tsg(    hMainFig, hPlotAxes, 1, 'SSPS', 1, [] );
    plot_Sample( hMainFig, hPlotAxes, 1, 'SSPS', [] );
    plot_Tsg(    hMainFig, hPlotAxes, 2, 'SSJT', 1, 'k' );
    plot_Tsg(    hMainFig, hPlotAxes, 3, 'SPDC', 1, 'k' );

    axesCommonProp( hPlotAxes );
%% SelectTime_OnMenuCallback ............................ Correction module
%----------------------------------------------------------------------
  function SelectTime_OnMenuCallback(hObject, eventdata)
    % Callback function run when the ....
            
    % Desactivate Zoom and Pan functions.
    % ----------------------------------
    set( hZoomToggletool, 'state', 'off' );
    set( hQCToggletool,   'state', 'off' );
    set( hPanToggletool,  'state', 'off' );
    
    % Create a pointer to select the time limits
    % ------------------------------------------
    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
    % Toggle the state of the Qc Togglebutton to 'on' or 'off'
    % ----------------------------------------------------
    if hObject == hEndlimitToggletool
      set( hStartlimitToggletool, 'State', 'off' );
    else
      set( hEndlimitToggletool,   'State', 'off' );
    end
    
    % Activate clic mouse menu on first axes (salinity) for next rbbox
    % DO NOT USE :
    % ButtonDownFcn -  the callback executes whenever you press a button
    % while the pointer is within the axes, but not over another graphics
    % object parented to the axes.
    % -------------------------------------------------------------------
    %set(hPlotAxes(1),'ButtonDownFcn', @Time_SelectCallback);
    set( hMainFig,'WindowButtonDownFcn', @Time_SelectCallback);  
 
    % change cursor to crosshair aspect
    % ---------------------------------
    set( hMainFig, 'Pointer', 'custom',...
         'PointerShapeCData', selTimePointer, 'PointerShapeHotSpot',[9 9]);
    % ----------------------------------------------------------------------
    % nested function on mouse clic when Select Time toggle tool is selected
    % ----------------------------------------------------------------------
    function Time_SelectCallback(gcbo, eventdata)

      % disable ButtonMotion on main fig during select
      % prevent drawing to map
      % ----------------------------------------------
      %set( hMainFig, 'WindowButtonMotionFcn', []);

Yves Gouriou's avatar
Yves Gouriou committed
      % Get the current mouse position on axe 2
      % ---------------------------------------
      a = get(hPlotAxes(2), 'CurrentPoint');

      % Write the date in the Editable uicontrol
      % ----------------------------------------
      if hObject == hEndlimitToggletool
        set( hetDateMax, 'String', datestr(x, 31));
      else
        set( hetDateMin, 'String', datestr(x, 31));
      end

      % Color of date limit in red if dateMax <=datMin
      % -------------------------------------------------------------------
      dateMin = datenum(get( hetDateMin, 'String'), 'yyyy-mm-dd HH:MM:SS');
      dateMax = datenum(get( hetDateMax, 'String'), 'yyyy-mm-dd HH:MM:SS');

      if dateMax <= dateMin
        set( hetDateMin, 'ForegroundColor','r');
        set( hetDateMax, 'ForegroundColor','r');
      else
        set( hetDateMin, 'ForegroundColor','k');
        set( hetDateMax, 'ForegroundColor','k');
      end

      % Enable ButtonMotion on main fig 
      % -------------------------------
      %set( hMainFig, 'WindowButtonMotionFcn', @MouseMotion);
      
    end
  end

%% SelectTime_OffMenuCallback ........................... Correction module
%--------------------------------------------------------------------------
  function SelectTime_OffMenuCallback(hObject, eventdata)
  % Callback function run when the ....

    % Desactivate time limit buttons
    % ------------------------------
    if hObject == hEndlimitToggletool
      set( hEndlimitToggletool, 'State', 'off');
    else
      set( hStartlimitToggletool, 'State', 'off');
    end
    
    set( hMainFig,'WindowButtonDownFcn', []);  
    
%% CorCancelCallback .................................... Correction Module
  function CorCancelCallback(hObject, eventdata)
    % Callback function run when ...
    % Desactivate somme Toggle button
    % -------------------------------
    set( hZoomToggletool,       'state', 'off' );
    set( hPanToggletool,        'state', 'off' );
    set( hQCToggletool,  'state', 'off' );
    set( hStartlimitToggletool, 'State', 'off' );
    set( hEndlimitToggletool,   'State', 'off' );

    tsg = getappdata(hMainFig, 'tsg_data');
    
Yves Gouriou's avatar
Yves Gouriou committed
    tsg.SSPS_ADJUSTED       = tsg.SSPS;
    tsg.SSPS_ADJUSTED_ERROR = NaN*ones(size(tsg.SSPS));
Yves Gouriou's avatar
Yves Gouriou committed
    tsg.SSPS_ADJUSTED_QC    = tsg.SSPS_QC;
    setappdata(hMainFig, 'tsg_data', tsg);
Yves Gouriou's avatar
Yves Gouriou committed
    % Reinitialise plot 1 and 3
    % -------------------------
Yves Gouriou's avatar
Yves Gouriou committed
    erase_Line( hPlotAxes, 1 )
    plot_Sample( hMainFig, hPlotAxes, 1, 'SSPS_DIF', [] );
    erase_Line( hPlotAxes, 3 )
    plot_Tsg( hMainFig, hPlotAxes, 3, 'SSPS', 0, 'k' );

%% CorLinearCallback .................................... Correction Module
  function CorLinearCallback(hObject, eventdata)
    % Callback function run when

    % Desactivate somme Toggle button
    % -------------------------------
    set( hZoomToggletool,       'state', 'off' );
    set( hPanToggletool,        'state', 'off' );
    set( hQCToggletool,  'state', 'off' );
    set( hStartlimitToggletool, 'State', 'off' );
    set( hEndlimitToggletool,   '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');
    % Compute the sample-TSG differences
    % ----------------------------------
    diffTsgSample( hMainFig );
    % Correction
    % ----------
    error = corTsgLinear(hMainFig, dateMin, dateMax);
Yves Gouriou's avatar
Yves Gouriou committed
        % Reinitialise plot 1 and 3
        % -------------------------
Yves Gouriou's avatar
Yves Gouriou committed
        erase_Line( hPlotAxes, 1 )
        erase_Line( hPlotAxes, 3 )
Yves Gouriou's avatar
Yves Gouriou committed
        plot_Sample( hMainFig, hPlotAxes, 1, 'SSPS_DIF', [] );
        
        % The order of ploting is important : RED before BLACK
        % For the time series section where no correction has been
        % made the black curve must be over the red one.
        % ----------------------------------------------------
        plot_Tsg( hMainFig, hPlotAxes, 3, 'SSPS_ADJUSTED', 0, 'r' );
        plot_Tsg( hMainFig, hPlotAxes, 3, 'SSPS', 0, 'k' );
        tsg = getappdata( hMainFig, 'tsg_data');

Yves Gouriou's avatar
Yves Gouriou committed
        % Plot the difference tsg.SSPS_ADJUSTED-tsg.SSPS on axe 1
        % Only for VALUE_CHANGED
        % -------------------------------------------------------
        VALUE_CHANGED = get(tsg.qc.hash, 'VALUE_CHANGED', 'code');
        ind = find( tsg.SSPS_ADJUSTED_QC == VALUE_CHANGED);

        % Plot the difference tsg.SSPS_ADJUSTED-tsg.SSPS on axe 1
        % -------------------------------------------------------
Yves Gouriou's avatar
Yves Gouriou committed
        axes( hPlotAxes(1) );
        line( tsg.DAYD(ind), tsg.SSPS_ADJUSTED(ind)-tsg.SSPS(ind),...
          'Tag', 'TAG_PLOT1_LINE_TSGDIF', 'Color', 'b');

        % Plot TSG + ERROR on axe 3
        % -------------------------
Yves Gouriou's avatar
Yves Gouriou committed
        errorPlus  = tsg.SSPS_ADJUSTED(ind) + tsg.SSPS_ADJUSTED_ERROR(ind);
        errorMinus = tsg.SSPS_ADJUSTED(ind) - tsg.SSPS_ADJUSTED_ERROR(ind);
        axes( hPlotAxes(3) );
Yves Gouriou's avatar
Yves Gouriou committed
        line( tsg.DAYD(ind), errorPlus(ind),...
          'Tag', 'TAG_PLOT3_LINE_TSGERROR_PLUS', 'Color', 'g');
Yves Gouriou's avatar
Yves Gouriou committed
        line( tsg.DAYD(ind), errorMinus(ind),...
          'Tag', 'TAG_PLOT3_LINE_TSGERROR_MINUS', 'Color', 'g');

      case -1
        msgbox( 'Date limits are not correct',...
          'Correction module', 'warn', 'modal');

  end

%% CorMedianCallback .................................... Correction Module
  function CorMedianCallback(hObject, eventdata)
    % Callback function run when

    % Desactivate somme Toggle button
    % -------------------------------
    set( hZoomToggletool,       'state', 'off' );
    set( hPanToggletool,        'state', 'off' );
    set( hQCToggletool,  'state', 'off' );
    set( hStartlimitToggletool, 'State', 'off' );
    set( hEndlimitToggletool,   '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');
    % Compute the sample-TSG differences
    % ----------------------------------
    diffTsgSample( hMainFig );
    error = corTsgMedian(hMainFig, dateMin, dateMax);
Yves Gouriou's avatar
Yves Gouriou committed
        % Reinitialise plot 1 and 3
        % -------------------------
Yves Gouriou's avatar
Yves Gouriou committed
        erase_Line( hPlotAxes, 1 )
        erase_Line( hPlotAxes, 3 )
        
        plot_Sample( hMainFig, hPlotAxes, 1, 'SSPS_DIF', [] );
        
        % The order of ploting is important : RED before BLACK
        % For the time series section where no correction has been
        % made the black curve must be over the red one.
        % ----------------------------------------------------
        plot_Tsg( hMainFig, hPlotAxes, 3, 'SSPS_ADJUSTED', 0, 'r' );
        plot_Tsg( hMainFig, hPlotAxes, 3, 'SSPS', 0, 'k' );
        tsg = getappdata( hMainFig, 'tsg_data');

Yves Gouriou's avatar
Yves Gouriou committed
        % Plot the difference tsg.SSPS_ADJUSTED-tsg.SSPS on axe 1
        % Only for VALUE_CHANGED
        % -------------------------------------------------------
Yves Gouriou's avatar
Yves Gouriou committed
        VALUE_CHANGED = get(tsg.qc.hash, 'VALUE_CHANGED', 'code');
        ind = find( tsg.SSPS_ADJUSTED_QC == VALUE_CHANGED);
        
        axes( hPlotAxes(1) );
        line( tsg.DAYD(ind), tsg.SSPS_ADJUSTED(ind)-tsg.SSPS(ind),...
                        'Tag', 'TAG_PLOT1_LINE_TSGDIF', 'LineStyle', 'none', 'Marker', '.', 'MarkerSize', 1, 'Color', 'b');

        % Plot TSG + ERROR on axe 3
        % -------------------------
Yves Gouriou's avatar
Yves Gouriou committed
        errorPlus  = tsg.SSPS_ADJUSTED(ind) + tsg.SSPS_ADJUSTED_ERROR(ind);
        errorMinus = tsg.SSPS_ADJUSTED(ind) - tsg.SSPS_ADJUSTED_ERROR(ind);
        axes( hPlotAxes(3) );
Yves Gouriou's avatar
Yves Gouriou committed
        line( tsg.DAYD(ind), errorPlus,...
          'Tag', 'TAG_PLOT3_LINE_TSGERROR_PLUS', 'Color', 'g');
Yves Gouriou's avatar
Yves Gouriou committed
        line( tsg.DAYD(ind), errorMinus,...
          'Tag', 'TAG_PLOT3_LINE_TSGERROR_MINUS', 'Color', 'g');

        msgbox( 'Date limits are not correct',...
          'Correction module', 'warn', 'modal');
%% Clim_OffMenuCallback
  %------------------------------------------------------------------------
  % Callback function run when the Levitus climatology toolbar is unselected
  %------------------------------------------------------------------------
  function Clim_OffMenuCallback(hObject, eventdata)
    % Get lines handles from tag
    % --------------------------
    hLines = findobj('-regexp', 'Tag', 'TAG_LINE_CLIMATO_');
    % ---------------------------------
    delete(hLines);
  %------------------------------------------------------------------------
  % Callback function run when the Levitus climatology toolbar is unselected
  %------------------------------------------------------------------------
  function Clim_OnMenuCallback(hObject, eventdata)
    % Test if the TSG and bucket files have been read
    % -----------------------------------------------
    if strcmp( get(hOpenMenu, 'UserData'), 'on' )
      
    end
  end

%% ClimatoSelectMenuCallback
  % -------------------------------------------------------------------
  % Callback function run when climato submenu is selected
  % -------------------------------------------------------------------
  function ClimatoSelectMenuCallback(hObject, eventdata, 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
    % -----------------------------------
    set(hObject, '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;
      % plot and read (eventually) new climatology
      % ------------------------------------------
      plot_Climatology(hMainFig, hPlotAxes);
%% PreferencesMenuCallback
  % -------------------------------------------------------------------
  % Callback function run when Option/Preference is selected
  % -------------------------------------------------------------------
  function PreferencesMenuCallback(hObject, eventdata)
    
    % Test if the preference menu is allready checked
    % -----------------------------------------------
    if strcmp( get(hObject, 'checked'), 'on' )
      
      % set preference autoload off (unchecked)
      % ---------------------------------------
      root.preference.autoload = 'off';
      
    else
      
      % set preference autoload on (checked)
      % ------------------------------------
      root.preference.autoload = 'on';
      
    end

     % set current option/preference submenu state
     % -------------------------------------------
     set(hObject, 'checked', root.preference.autoload);
     
    % store root struct to root UserData
    % ----------------------------------
    set(0, 'userdata', root);
    
  end

% -------------------------------------------------------------------
% Callback function run when the headerForm tool bar item is selected
% -------------------------------------------------------------------