%
%   gliderCTD_DataViz.m
%
%   Purpose:  glider CTD data plots user interface
%
%   Requires:
%	gliderCTD_GeneratePlots.m
%	gliderCTD_2DPlots.m
%	gliderCTD_3DPlots.m
%	BATHYMETRY folder - contains bathymetry data
%	MATLAB folder - contains util, matutil, seawater, plots, strfun, opnml
%	CLIDER_CTD_DATA_LEVEL1 folder - contains Level 1 .mat files
%
%
%   Author:  William Stark
%            Marine Sciences Department
%            UNC-Chapel Hill
%
%   Created: 18 June 2012
%
%   Todo: Have tracks for individual legs instead of just all tracks.
%         Get some better bathymetry.
%         Move specification of leg endpoints to included .m file.
%         Individualize axes bounds per glider but NOT per leg.
%         Include legend for all legs TS plot.
%
%//////////////////////////////////////////////////////////////////////////


function varargout = gliderCTD_DataViz(varargin)
%       Description:  User interface for specifying and displaying 
%                     Slocum glider CTD data visualization plots.

% (Leave a blank line following the help.)


% global variables...
global mGliderIndex;
global mDeploymentNumber;
global mLegNumber;
global mPlotFlag_TS;
global mPlotFlag_TS_AllLegs;
% global mPlotFlag_TS_Chlorophyll;
global mPlotFlag_Temperature;
global mPlotFlag_Salinity;
global mPlotFlag_Density;
% global mPlotFlag_Chlorophyll;
global mPlotFlag_TemperatureProfile;
global mPlotFlag_SalinityProfile;
global mPlotFlag_DensityProfile;
% global mPlotFlag_ChlorophyllProfile;
global mPlotFlag_Temperature3D;
global mPlotFlag_Salinity3D;
global mPlotFlag_Density3D;
% global mPlotFlag_Chlorophyll3D;
global mPlotFlag_AllGliderTracks;

global mStrPelagiaD1Complete_DateRange;
global mStrPelagiaD1L1_DateRange;
global mStrPelagiaD1L2_DateRange;
global mStrPelagiaD1L3_DateRange;
global mStrPelagiaD2Complete_DateRange;
global mStrPelagiaD2L1_DateRange;
global mStrPelagiaD2L2_DateRange;
global mStrPelagiaD2L3_DateRange;
global mStrPelagiaD2L4_DateRange;
global mStrPelagiaD2L5_DateRange;
global mStrPelagiaD3Complete_DateRange;
global mStrPelagiaD3L1_DateRange;
global mStrPelagiaD3L2_DateRange;
global mStrPelagiaD3L3_DateRange;
global mStrPelagiaD3L4_DateRange;
global mStrPelagiaD3L5_DateRange;
global mStrPelagiaD3L6_DateRange;

global mStrRamsesD1Complete_DateRange;
global mStrRamsesD1L1_DateRange;
global mStrRamsesD1L2_DateRange;
global mStrRamsesD1L3_DateRange;
global mStrRamsesD1L4_DateRange;
global mStrRamsesD1L5_DateRange;
global mStrRamsesD2Complete_DateRange;
global mStrRamsesD2L1_DateRange;
global mStrRamsesD2L2_DateRange;
global mStrRamsesD2L3_DateRange;
global mStrRamsesD2L4_DateRange;
global mStrRamsesD3Complete_DateRange;
global mStrRamsesD3L1_DateRange;
global mStrRamsesD3L2_DateRange;
global mStrRamsesD3L3_DateRange;
global mStrRamsesD3L4_DateRange;

global mStrComplete_DateRange;
global mStrLeg1_DateRange;
global mStrLeg2_DateRange;
global mStrLeg3_DateRange;
global mStrLeg4_DateRange;
global mStrLeg5_DateRange;
global mStrLeg6_DateRange;

% initial values...
mGliderIndex = 1;
mDeploymentNumber = 1;
mLegNumber = 0;
mPlotFlag_TS = 0;
mPlotFlag_TS_AllLegs = 0;
% mPlotFlag_TS_Chlorophyll = 0;
mPlotFlag_Temperature = 0;
mPlotFlag_Salinity = 0;
mPlotFlag_Density = 0;
% mPlotFlag_Chlorophyll = 0;
mPlotFlag_TemperatureProfile = 0;
mPlotFlag_SalinityProfile = 0;
mPlotFlag_DensityProfile = 0;
% mPlotFlag_ChlorophyllProfile = 0;
mPlotFlag_Temperature3D = 0;
mPlotFlag_Salinity3D = 0;
mPlotFlag_Density3D = 0;
% mPlotFlag_Chlorophyll3D = 0;
mPlotFlag_AllGliderTracks = 0;

mStrPelagiaD1Complete_DateRange = '26-Jan-2012 01:57:14  to  14-Feb-2012 17:10:38';
mStrPelagiaD1L1_DateRange =       '26-Jan-2012 01:57:14  to  31-Jan-2012 12:00:00';
mStrPelagiaD1L2_DateRange =       '31-Jan-2012 12:00:01  to  08-Feb-2012 12:00:00';
mStrPelagiaD1L3_DateRange =       '08-Feb-2012 12:00:01  to  14-Feb-2012 17:10:38';

mStrPelagiaD2Complete_DateRange = '16-Feb-2012 13:47:27  to  08-Mar-2012 12:36:28';
mStrPelagiaD2L1_DateRange =       '16-Feb-2012 13:47:27  to  18-Feb-2012 10:30:00';
mStrPelagiaD2L2_DateRange =       '18-Feb-2012 10:30:01  to  20-Feb-2012 06:00:00';
mStrPelagiaD2L3_DateRange =       '20-Feb-2012 06:00:01  to  23-Feb-2012 05:30:00';
mStrPelagiaD2L4_DateRange =       '23-Feb-2012 05:30:01  to  29-Feb-2012 02:30:00';
mStrPelagiaD2L5_DateRange =       '29-Feb-2012 02:30:01  to  08-Mar-2012 12:36:28';

mStrPelagiaD3Complete_DateRange = '16-Mar-2012 12:58:45  to  04-Apr-2012 10:36:01';
mStrPelagiaD3L1_DateRange =       '16-Mar-2012 12:58:45  to  18-Mar-2012 21:40:00';
mStrPelagiaD3L2_DateRange =       '18-Mar-2012 21:40:01  to  22-Mar-2012 17:30:00';
mStrPelagiaD3L3_DateRange =       '22-Mar-2012 17:30:01  to  25-Mar-2012 14:00:00';
mStrPelagiaD3L4_DateRange =       '25-Mar-2012 14:00:01  to  28-Mar-2012 22:00:00';
mStrPelagiaD3L5_DateRange =       '28-Mar-2012 22:00:01  to  31-Mar-2012 19:00:00';
mStrPelagiaD3L6_DateRange =       '31-Mar-2012 19:00:01  to  04-Apr-2012 10:36:01';

mStrRamsesD1Complete_DateRange =  '26-Jan-2012 01:06:22  to  14-Feb-2012 12:35:11';
mStrRamsesD1L1_DateRange =        '26-Jan-2012 01:06:22  to  28-Jan-2012 20:00:00';
mStrRamsesD1L2_DateRange =        '28-Jan-2012 20:00:01  to  30-Jan-2012 03:00:00';
mStrRamsesD1L3_DateRange =        '30-Jan-2012 03:00:01  to  31-Jan-2012 14:00:00';
mStrRamsesD1L4_DateRange =        '31-Jan-2012 14:00:01  to  07-Feb-2012 10:30:00';
mStrRamsesD1L5_DateRange =        '07-Feb-2012 10:30:01  to  14-Feb-2012 12:35:11';

mStrRamsesD2Complete_DateRange =  '16-Feb-2012 01:29:39  to  12-Mar-2012 16:24:18';
mStrRamsesD2L1_DateRange =        '16-Feb-2012 01:29:39  to  28-Feb-2012 12:00:00';
mStrRamsesD2L2_DateRange =        '28-Feb-2012 12:00:01  to  04-Mar-2012 12:00:00';
mStrRamsesD2L3_DateRange =        '04-Mar-2012 12:00:01  to  07-Mar-2012 11:30:00';
mStrRamsesD2L4_DateRange =        '07-Mar-2012 11:30:01  to  12-Mar-2012 16:24:18';

mStrRamsesD3Complete_DateRange =  '16-Mar-2012 15:41:35  to  03-Apr-2012 19:24:45';
mStrRamsesD3L1_DateRange =        '16-Mar-2012 15:41:35  to  22-Mar-2012 12:00:00';
mStrRamsesD3L2_DateRange =        '22-Mar-2012 12:00:01  to  27-Mar-2012 03:00:00';
mStrRamsesD3L3_DateRange =        '27-Mar-2012 03:00:01  to  29-Mar-2012 02:00:00';
mStrRamsesD3L4_DateRange =        '29-Mar-2012 02:00:01  to  03-Apr-2012 19:24:45';

% initial date range label strings...
mStrComplete_DateRange = mStrPelagiaD1Complete_DateRange;
mStrLeg1_DateRange = mStrPelagiaD1L1_DateRange;
mStrLeg2_DateRange = mStrPelagiaD1L2_DateRange;
mStrLeg3_DateRange = mStrPelagiaD1L3_DateRange;
mStrLeg4_DateRange = '';
mStrLeg5_DateRange = '';
mStrLeg6_DateRange = '';



% BEGIN GUI Initialization /////////////////////////////////////////////////////////////////////

figureWidth = 790;
%figureHeight = 690;
figureHeight = 670;

titleTextPosFromLeft = 85;
titleTextPosFromBottom = 620;
titleTextWidth = 600;
titleTextHeight = 35;

gliderBGPosFromLeft = 20;
gliderBGPosFromBottom = 470;
gliderBGWidth = 200;
gliderBGHeight = 120;

deploymentBGPosFromLeft = 20;
deploymentBGPosFromBottom = 290;
deploymentBGWidth = 200;
deploymentBGHeight = 160;

legBGPosFromLeft = 250;
legBGPosFromBottom = 290;
legBGWidth = 500;
legBGHeight = 300;

plotsBGPosFromLeft = 20;
plotsBGPosFromBottom = 110;
plotsBGWidth = 730;
%plotsBGHeight = 190;
plotsBGHeight = 160;


% create figure...
guih = figure('MenuBar', 'none', 'Position', [10, 10, figureWidth, figureHeight]);

% add title text...
uicontrol(guih, 'Style', 'text', 'String', ' Slocum Glider CTD Data Visualization', 'FontSize', 16,...
          'FontWeight', 'bold', 'BackgroundColor', [0.8 0.8 0.8], 'Units', 'pixels',...
          'Position', [titleTextPosFromLeft titleTextPosFromBottom titleTextWidth titleTextHeight]);

% add button group to select glider...
bghGlider = uibuttongroup('Parent', guih, 'Title', 'Glider', 'FontSize', 14, 'FontWeight', 'bold',...
                          'Units', 'pixels', 'Position', [gliderBGPosFromLeft gliderBGPosFromBottom gliderBGWidth gliderBGHeight],...
                          'SelectionChangeFcn', @hGliderSelectionChanged);
rbhGlider_Pelagia = uicontrol(bghGlider, 'Style', 'radiobutton', 'String', 'Pelagia', 'FontSize', 14,...
                              'Units', 'pixels', 'Position', [30 60 120 30]);
rbhGlider_Ramses = uicontrol(bghGlider, 'Style', 'radiobutton', 'String', 'Ramses', 'FontSize', 14,...
                             'Units', 'pixels', 'Position', [30 20 120 30]);

% add button group to select deployment number...
bghDeployment = uibuttongroup('Parent', guih, 'Title', 'Deployment', 'FontSize', 14, 'FontWeight', 'bold',...
                              'Units', 'pixels', 'Position', [deploymentBGPosFromLeft deploymentBGPosFromBottom deploymentBGWidth deploymentBGHeight],...
                              'SelectionChangeFcn', @hDeploymentNumberSelectionChanged);                             
rbhDeployment_1 = uicontrol(bghDeployment, 'Style', 'radiobutton', 'String', '1', 'FontSize', 14,...
                            'Units', 'pixels', 'Position', [30 100 140 30]);
rbhDeployment_2 = uicontrol(bghDeployment, 'Style', 'radiobutton', 'String', '2', 'FontSize', 14,...
                           'Units', 'pixels', 'Position', [30 60 140 30]);
rbhDeployment_3 = uicontrol(bghDeployment, 'Style', 'radiobutton', 'String', '3', 'FontSize', 14,...
                           'Units', 'pixels', 'Position', [30 20 140 30]);
                         
% add button group to select leg number...
bghLeg = uibuttongroup('Parent', guih, 'Title', 'Leg', 'FontSize', 14, 'FontWeight', 'bold',...
                       'Units', 'pixels', 'Position', [legBGPosFromLeft legBGPosFromBottom legBGWidth legBGHeight],...
                       'SelectionChangeFcn', @hLegNumberSelectionChanged);
                   
rbhLeg_0 = uicontrol(bghLeg, 'Style', 'radiobutton', 'String', 'All', 'FontSize', 14,...
                     'Units', 'pixels', 'Position', [30 235 50 30]);
sthLeg_0 = uicontrol(bghLeg, 'Style', 'text', 'String', mStrComplete_DateRange, 'FontSize', 10,...
                     'Units', 'pixels', 'Position', [90 240 380 20]);

rbhLeg_1 = uicontrol(bghLeg, 'Style', 'radiobutton', 'String', '1', 'FontSize', 14,...
                     'Units', 'pixels', 'Position', [30 200 50 30]);
sthLeg_1 = uicontrol(bghLeg, 'Style', 'text', 'String', mStrLeg1_DateRange, 'FontSize', 10,...
                     'Units', 'pixels', 'Position', [90 205 380 20]);
                 
rbhLeg_2 = uicontrol(bghLeg, 'Style', 'radiobutton', 'String', '2', 'FontSize', 14,...
                    'Units', 'pixels', 'Position', [30 165 50 30]);
sthLeg_2 = uicontrol(bghLeg, 'Style', 'text', 'String', mStrLeg2_DateRange, 'FontSize', 10,...
                     'Units', 'pixels', 'Position', [90 170 380 20]);
                
rbhLeg_3 = uicontrol(bghLeg, 'Style', 'radiobutton', 'String', '3', 'FontSize', 14,...
                     'Units', 'pixels', 'Position', [30 130 50 30]);
sthLeg_3 = uicontrol(bghLeg, 'Style', 'text', 'String', mStrLeg3_DateRange, 'FontSize', 10,...
                     'Units', 'pixels', 'Position', [90 135 380 20]);
                 
rbhLeg_4 = uicontrol(bghLeg, 'Style', 'radiobutton', 'String', '4', 'FontSize', 14,...
                     'Units', 'pixels', 'Position', [30 95 50 30]);
sthLeg_4 = uicontrol(bghLeg, 'Style', 'text', 'String', mStrLeg4_DateRange, 'FontSize', 10,...
                     'Units', 'pixels', 'Position', [90 100 380 20]);

rbhLeg_5 = uicontrol(bghLeg, 'Style', 'radiobutton', 'String', '5', 'FontSize', 14,...
                     'Units', 'pixels', 'Position', [30 60 50 30]);
sthLeg_5 = uicontrol(bghLeg, 'Style', 'text', 'String', mStrLeg5_DateRange, 'FontSize', 10,...
                     'Units', 'pixels', 'Position', [90 65 380 20]);
                 
rbhLeg_6 = uicontrol(bghLeg, 'Style', 'radiobutton', 'String', '6', 'FontSize', 14,...
                     'Units', 'pixels', 'Position', [30 25 50 30]);
sthLeg_6 = uicontrol(bghLeg, 'Style', 'text', 'String', mStrLeg6_DateRange, 'FontSize', 10,...
                     'Units', 'pixels', 'Position', [90 30 380 20]);

                 
% initial visibility settings for leg radio buttons...
set(rbhLeg_0, 'Visible', 'on');
set(rbhLeg_1, 'Visible', 'on');
set(rbhLeg_2, 'Visible', 'on');
set(rbhLeg_3, 'Visible', 'on');
set(rbhLeg_4, 'Visible', 'off');
set(rbhLeg_5, 'Visible', 'off');
set(rbhLeg_6, 'Visible', 'off');



% add button group to select which data plots to display...
bghPlotType = uibuttongroup('Parent', guih, 'Title', 'Data Plots', 'FontSize', 14, 'FontWeight', 'bold',...
                            'Units', 'pixels', 'Position', [plotsBGPosFromLeft plotsBGPosFromBottom plotsBGWidth plotsBGHeight]);
cbhPlot_1 = uicontrol(bghPlotType, 'Style', 'checkbox', 'String', 'All Glider Tracks', 'FontSize', 10,...
                      'Units', 'pixels', 'Position', [30 90 160 30], 'Callback', @checkbox1_Callback);
cbhPlot_2 = uicontrol(bghPlotType, 'Style', 'checkbox', 'String', 'TS', 'FontSize', 10,...
                      'Units', 'pixels', 'Position', [30 55 160 30], 'Callback', @checkbox2_Callback);
cbhPlot_3 = uicontrol(bghPlotType, 'Style', 'checkbox', 'String', 'TS (all legs)', 'FontSize', 10,...
                      'Units', 'pixels', 'Position', [30 20 160 30], 'Callback', @checkbox3_Callback);
% cbhPlot_4 = uicontrol(bghPlotType, 'Style', 'checkbox', 'String', 'TS (with Chlorophyll)', 'FontSize', 10,...
%                       'Units', 'pixels', 'Position', [30 105 160 30], 'Callback', @checkbox4_Callback);
cbhPlot_5 = uicontrol(bghPlotType, 'Style', 'checkbox', 'String', 'Temperature', 'FontSize', 10,...
                      'Units', 'pixels', 'Position', [220 90 160 30], 'Callback', @checkbox5_Callback);                 
cbhPlot_6 = uicontrol(bghPlotType, 'Style', 'checkbox', 'String', 'Salinity', 'FontSize', 10,...
                      'Units', 'pixels', 'Position', [220 55 160 30], 'Callback', @checkbox6_Callback);
cbhPlot_7 = uicontrol(bghPlotType, 'Style', 'checkbox', 'String', 'Density', 'FontSize', 10,...
                      'Units', 'pixels', 'Position', [220 20 160 30], 'Callback', @checkbox7_Callback);
% cbhPlot_8 = uicontrol(bghPlotType, 'Style', 'checkbox', 'String', 'Chlorophyll', 'FontSize', 10,...
%                       'Units', 'pixels', 'Position', [220 105 160 30], 'Callback', @checkbox8_Callback);
cbhPlot_9 = uicontrol(bghPlotType, 'Style', 'checkbox', 'String', 'Temperature Profile', 'FontSize', 10,...
                      'Units', 'pixels', 'Position', [370 90 160 30], 'Callback', @checkbox9_Callback);
cbhPlot_10 = uicontrol(bghPlotType, 'Style', 'checkbox', 'String', 'Salinity Profile', 'FontSize', 10,...
                      'Units', 'pixels', 'Position', [370 55 160 30], 'Callback', @checkbox10_Callback);
cbhPlot_11 = uicontrol(bghPlotType, 'Style', 'checkbox', 'String', 'Density Profile', 'FontSize', 10,...
                      'Units', 'pixels', 'Position', [370 20 160 30], 'Callback', @checkbox11_Callback);
% cbhPlot_12 = uicontrol(bghPlotType, 'Style', 'checkbox', 'String', 'Chlorophyll Profile', 'FontSize', 10,...
%                        'Units', 'pixels', 'Position', [370 105 160 30], 'Callback', @checkbox12_Callback);
cbhPlot_13 = uicontrol(bghPlotType, 'Style', 'checkbox', 'String', '3D Temperature', 'FontSize', 10,...
                       'Units', 'pixels', 'Position', [560 90 160 30], 'Callback', @checkbox13_Callback);
cbhPlot_14 = uicontrol(bghPlotType, 'Style', 'checkbox', 'String', '3D Salinity', 'FontSize', 10,...
                       'Units', 'pixels', 'Position', [560 55 160 30], 'Callback', @checkbox14_Callback);
cbhPlot_15 = uicontrol(bghPlotType, 'Style', 'checkbox', 'String', '3D Density', 'FontSize', 10,...
                       'Units', 'pixels', 'Position', [560 20 160 30], 'Callback', @checkbox15_Callback);
% cbhPlot_16 = uicontrol(bghPlotType, 'Style', 'checkbox', 'String', '3D Chlorophyll', 'FontSize', 10,...
%                        'Units', 'pixels', 'Position', [560 105 160 30], 'Callback', @checkbox16_Callback);

                 
                 
% add push button to display plots                 
pbhGeneratePlots = uicontrol(guih, 'Style', 'pushbutton',...
                             'String', 'Generate Plots', 'FontSize', 14, 'FontWeight', 'bold',...
                             'Units', 'pixels', 'Position', [280 30 200 60],...
                             'Callback', @generatePlots_Callback);


% END GUI Initialization /////////////////////////////////////////////////////////////////////




% BEGIN GUI Callbacks ////////////////////////////////////////////////////////////////////////

    %/// CALLBACK - RADIO BUTTONS FOR GLIDER NAME //////////////////////////////////////
    %----------------------------------------------------------------------
    function hGliderSelectionChanged(hObject, eventdata)
    % callback called when the selected glider is changed
        selected = get(bghGlider, 'SelectedObject');
        radioButtonLabel = get(selected, 'String');
        
        if (strcmp(radioButtonLabel, 'Pelagia'))
            mGliderIndex = 1;
        else
            mGliderIndex = 2;
        end
        
        updateLegRadioButtons(mGliderIndex, mDeploymentNumber);
    end

    %/// CALLBACK - RADIO BUTTONS FOR DEPLOYMENT NUMBER //////////////////////////////////////
    %----------------------------------------------------------------------
    function hDeploymentNumberSelectionChanged(hObject, eventdata)
    % callback called when the selected deployment number is changed
        selected = get(bghDeployment, 'SelectedObject');
        radioButtonLabel = get(selected, 'String');
        
        if (strcmp(radioButtonLabel, '1'))
            mDeploymentNumber = 1;
        elseif (strcmp(radioButtonLabel, '2'))
            mDeploymentNumber = 2;
        else
            mDeploymentNumber = 3;
        end
        
        updateLegRadioButtons(mGliderIndex, mDeploymentNumber);
    end


    %/// CALLBACK - RADIO BUTTONS FOR LEG NUMBER //////////////////////////////////////
    %----------------------------------------------------------------------
    function hLegNumberSelectionChanged(hObject, eventdata)
    % callback called when the selected leg number is changed
        selected = get(bghLeg, 'SelectedObject');
        radioButtonLabel = get(selected, 'String');
        
        if (strcmp(radioButtonLabel, 'All'))
            mLegNumber = 0;
        elseif (strcmp(radioButtonLabel, '1'))
            mLegNumber = 1;
        elseif (strcmp(radioButtonLabel, '2'))
            mLegNumber = 2;
        elseif (strcmp(radioButtonLabel, '3'))
            mLegNumber = 3;
        elseif (strcmp(radioButtonLabel, '4'))
            mLegNumber = 4;
        elseif (strcmp(radioButtonLabel, '5'))
            mLegNumber = 5;
        else
            mLegNumber = 6;
        end
    end


    %/// CALLBACKS - CHECKBOXES FOR PLOT TYPES //////////////////////////////////////
    %----------------------------------------------------------------------
    function checkbox1_Callback(hObject, eventdata, handles)
        % callback called when the All Glider Tracks plot checkbox is checked
        if (get(hObject,'Value') == get(hObject,'Max'))
            mPlotFlag_AllGliderTracks = 1;
        else
            mPlotFlag_AllGliderTracks = 0;
        end
    end

    %----------------------------------------------------------------------
    function checkbox2_Callback(hObject, eventdata, handles)
        % callback called when the TS plot checkbox is checked
        if (get(hObject,'Value') == get(hObject,'Max'))
            mPlotFlag_TS = 1;
        else
            mPlotFlag_TS = 0;
        end
    end

    %----------------------------------------------------------------------
    function checkbox3_Callback(hObject, eventdata, handles)
        % callback called when the TS-All Legs plot checkbox is checked
        if (get(hObject,'Value') == get(hObject,'Max'))
            mPlotFlag_TS_AllLegs = 1;
        else
            mPlotFlag_TS_AllLegs = 0;
        end
    end

    %----------------------------------------------------------------------
    % function checkbox4_Callback(hObject, eventdata, handles)
    %     % callback called when the TS-Chlorophyll plot checkbox is checked
    %     if (get(hObject,'Value') == get(hObject,'Max'))
    %         mPlotFlag_TS_Chlorophyll = 1;
    %     else
    %         mPlotFlag_TS_Chlorophyll = 0;
    %     end
    % end

    %----------------------------------------------------------------------
    function checkbox5_Callback(hObject, eventdata, handles)
        % callback called when the temperature plot checkbox is checked
        if (get(hObject,'Value') == get(hObject,'Max'))
            mPlotFlag_Temperature = 1;
        else
            mPlotFlag_Temperature = 0;
        end
    end

    %----------------------------------------------------------------------
    function checkbox6_Callback(hObject, eventdata, handles)
        % callback called when the salinity plot checkbox is checked
        if (get(hObject,'Value') == get(hObject,'Max'))
            mPlotFlag_Salinity = 1;
        else
            mPlotFlag_Salinity = 0;
        end
    end

    %----------------------------------------------------------------------
    function checkbox7_Callback(hObject, eventdata, handles)
        % callback called when the density plot checkbox is checked
        if (get(hObject,'Value') == get(hObject,'Max'))
            mPlotFlag_Density = 1;
        else
            mPlotFlag_Density = 0;
        end
    end

    %----------------------------------------------------------------------
    % function checkbox8_Callback(hObject, eventdata, handles)
    %     % callback called when the chlorophyll plot checkbox is checked
    %     if (get(hObject,'Value') == get(hObject,'Max'))
    %         mPlotFlag_Chlorophyll = 1;
    %     else
    %         mPlotFlag_Chlorophyll = 0;
    %     end
    % end

    %----------------------------------------------------------------------
    function checkbox9_Callback(hObject, eventdata, handles)
        % callback called when the temperature profile plot checkbox is checked
        if (get(hObject,'Value') == get(hObject,'Max'))
            mPlotFlag_TemperatureProfile = 1;
        else
            mPlotFlag_TemperatureProfile = 0;
        end
    end

    %----------------------------------------------------------------------
    function checkbox10_Callback(hObject, eventdata, handles)
        % callback called when the salinity profile plot checkbox is checked
        if (get(hObject,'Value') == get(hObject,'Max'))
            mPlotFlag_SalinityProfile = 1;
        else
            mPlotFlag_SalinityProfile = 0;
        end
    end

    %----------------------------------------------------------------------
    function checkbox11_Callback(hObject, eventdata, handles)
        % callback called when the density profile plot checkbox is checked
        if (get(hObject,'Value') == get(hObject,'Max'))
            mPlotFlag_DensityProfile = 1;
        else
            mPlotFlag_DensityProfile = 0;
        end
    end

    %----------------------------------------------------------------------
    % function checkbox12_Callback(hObject, eventdata, handles)
    %     % callback called when the chlorophyll profile plot checkbox is checked
    %     if (get(hObject,'Value') == get(hObject,'Max'))
    %         mPlotFlag_ChlorophyllProfile = 1;
    %     else
    %         mPlotFlag_ChlorophyllProfile = 0;
    %     end
    % end

    %----------------------------------------------------------------------
    function checkbox13_Callback(hObject, eventdata, handles)
        % callback called when the 3D temperature plot checkbox is checked
        if (get(hObject,'Value') == get(hObject,'Max'))
            mPlotFlag_Temperature3D = 1;
        else
            mPlotFlag_Temperature3D = 0;
        end
    end

    %----------------------------------------------------------------------
    function checkbox14_Callback(hObject, eventdata, handles)
        % callback called when the 3D salinity plot checkbox is checked
        if (get(hObject,'Value') == get(hObject,'Max'))
            mPlotFlag_Salinity3D = 1;
        else
            mPlotFlag_Salinity3D = 0;
        end
    end

    %----------------------------------------------------------------------
    function checkbox15_Callback(hObject, eventdata, handles)
        % callback called when the 3D density plot checkbox is checked
        if (get(hObject,'Value') == get(hObject,'Max'))
            mPlotFlag_Density3D = 1;
        else
            mPlotFlag_Density3D = 0;
        end
    end

    %----------------------------------------------------------------------
    % function checkbox16_Callback(hObject, eventdata, handles)
    %     % callback called when the 3D chlorophyll plot checkbox is checked
    %     if (get(hObject,'Value') == get(hObject,'Max'))
    %         mPlotFlag_Chlorophyll3D = 1;
    %     else
    %         mPlotFlag_Chlorophyll3D = 0;
    %     end
    % end




    %----------------------------------------------------------------------
    function updateLegRadioButtons(mGliderIndex, mDeploymentNumber)
        
        switch mGliderIndex
            case 1  % Pelagia
                switch mDeploymentNumber
                    case 1  % Deployment 1
                        set(rbhLeg_0, 'Visible', 'on');
                        set(sthLeg_0, 'String', mStrPelagiaD1Complete_DateRange, 'Visible', 'on');                        
                        set(rbhLeg_1, 'Visible', 'on');
                        set(sthLeg_1, 'String', mStrPelagiaD1L1_DateRange, 'Visible', 'on');                        
                        set(rbhLeg_2, 'Visible', 'on');
                        set(sthLeg_2, 'String', mStrPelagiaD1L2_DateRange, 'Visible', 'on');                        
                        set(rbhLeg_3, 'Visible', 'on');
                        set(sthLeg_3, 'String', mStrPelagiaD1L3_DateRange, 'Visible', 'on');                        
                        set(rbhLeg_4, 'Visible', 'off');
                        set(sthLeg_4, 'Visible', 'off');
                        set(rbhLeg_5, 'Visible', 'off');
                        set(sthLeg_5, 'Visible', 'off');
                        set(rbhLeg_6, 'Visible', 'off');
                        set(sthLeg_6, 'Visible', 'off');
                    case 2  % Deployment 2
                        set(rbhLeg_0, 'Visible', 'on');
                        set(sthLeg_0, 'String', mStrPelagiaD2Complete_DateRange, 'Visible', 'on');                        
                        set(rbhLeg_1, 'Visible', 'on');
                        set(sthLeg_1, 'String', mStrPelagiaD2L1_DateRange, 'Visible', 'on');
                        set(rbhLeg_2, 'Visible', 'on');
                        set(sthLeg_2, 'String', mStrPelagiaD2L2_DateRange, 'Visible', 'on');
                        set(rbhLeg_3, 'Visible', 'on');
                        set(sthLeg_3, 'String', mStrPelagiaD2L3_DateRange, 'Visible', 'on');
                        set(rbhLeg_4, 'Visible', 'on');
                        set(sthLeg_4, 'String', mStrPelagiaD2L4_DateRange, 'Visible', 'on');
                        set(rbhLeg_5, 'Visible', 'on');
                        set(sthLeg_5, 'String', mStrPelagiaD2L5_DateRange, 'Visible', 'on');
                        set(rbhLeg_6, 'Visible', 'off');
                        set(sthLeg_6, 'Visible', 'off');
                    case 3  % Deployment 3
                        set(rbhLeg_0, 'Visible', 'on');
                        set(sthLeg_0, 'String', mStrPelagiaD3Complete_DateRange, 'Visible', 'on');                        
                        set(rbhLeg_1, 'Visible', 'on');
                        set(sthLeg_1, 'String', mStrPelagiaD3L1_DateRange, 'Visible', 'on');
                        set(rbhLeg_2, 'Visible', 'on');
                        set(sthLeg_2, 'String', mStrPelagiaD3L2_DateRange, 'Visible', 'on');
                        set(rbhLeg_3, 'Visible', 'on');
                        set(sthLeg_3, 'String', mStrPelagiaD3L3_DateRange, 'Visible', 'on');
                        set(rbhLeg_4, 'Visible', 'on');
                        set(sthLeg_4, 'String', mStrPelagiaD3L4_DateRange, 'Visible', 'on');
                        set(rbhLeg_5, 'Visible', 'on');
                        set(sthLeg_5, 'String', mStrPelagiaD3L5_DateRange, 'Visible', 'on');
                        set(rbhLeg_6, 'Visible', 'on');
                        set(sthLeg_6, 'String', mStrPelagiaD3L6_DateRange, 'Visible', 'on');
                end
            case 2  % Ramses
                switch mDeploymentNumber
                    case 1  % Deployment 1
                        set(rbhLeg_0, 'Visible', 'on');
                        set(sthLeg_0, 'String', mStrRamsesD1Complete_DateRange, 'Visible', 'on');                        
                        set(rbhLeg_1, 'Visible', 'on');
                        set(sthLeg_1, 'String', mStrRamsesD1L1_DateRange, 'Visible', 'on');
                        set(rbhLeg_2, 'Visible', 'on');
                        set(sthLeg_2, 'String', mStrRamsesD1L2_DateRange, 'Visible', 'on');
                        set(rbhLeg_3, 'Visible', 'on');
                        set(sthLeg_3, 'String', mStrRamsesD1L3_DateRange, 'Visible', 'on');
                        set(rbhLeg_4, 'Visible', 'on');
                        set(sthLeg_4, 'String', mStrRamsesD1L4_DateRange, 'Visible', 'on');
                        set(rbhLeg_5, 'Visible', 'on');
                        set(sthLeg_5, 'String', mStrRamsesD1L5_DateRange, 'Visible', 'on');
                        set(rbhLeg_6, 'Visible', 'off');
                        set(sthLeg_6, 'Visible', 'off');
                    case 2  % Deployment 2
                        set(rbhLeg_0, 'Visible', 'on');
                        set(sthLeg_0, 'String', mStrRamsesD2Complete_DateRange, 'Visible', 'on');               
                        set(rbhLeg_1, 'Visible', 'on');
                        set(sthLeg_1, 'String', mStrRamsesD2L1_DateRange, 'Visible', 'on');
                        set(rbhLeg_2, 'Visible', 'on');
                        set(sthLeg_2, 'String', mStrRamsesD2L2_DateRange, 'Visible', 'on');
                        set(rbhLeg_3, 'Visible', 'on');
                        set(sthLeg_3, 'String', mStrRamsesD2L3_DateRange, 'Visible', 'on');
                        set(rbhLeg_4, 'Visible', 'on');
                        set(sthLeg_4, 'String', mStrRamsesD2L4_DateRange, 'Visible', 'on');
                        set(rbhLeg_5, 'Visible', 'off');
                        set(sthLeg_5, 'Visible', 'off');
                        set(rbhLeg_6, 'Visible', 'off');
                        set(sthLeg_6, 'Visible', 'off');
                    case 3  % Deployment 3
                        set(rbhLeg_0, 'Visible', 'on');
                        set(sthLeg_0, 'String', mStrRamsesD3Complete_DateRange, 'Visible', 'on');               
                        set(rbhLeg_1, 'Visible', 'on');
                        set(sthLeg_1, 'String', mStrRamsesD3L1_DateRange, 'Visible', 'on');
                        set(rbhLeg_2, 'Visible', 'on');
                        set(sthLeg_2, 'String', mStrRamsesD3L2_DateRange, 'Visible', 'on');
                        set(rbhLeg_3, 'Visible', 'on');
                        set(sthLeg_3, 'String', mStrRamsesD3L3_DateRange, 'Visible', 'on');
                        set(rbhLeg_4, 'Visible', 'on');
                        set(sthLeg_4, 'String', mStrRamsesD3L4_DateRange, 'Visible', 'on');
                        set(rbhLeg_5, 'Visible', 'off');
                        set(sthLeg_5, 'Visible', 'off');
                        set(rbhLeg_6, 'Visible', 'off');
                        set(sthLeg_6, 'Visible', 'off');
                end
        end
    end


    %----------------------------------------------------------------------
    function generatePlots_Callback(hObject, eventdata, handles)
        % callback called when the Generate Plots button is clicked
        
        gliderCTD_GeneratePlots(mGliderIndex, mDeploymentNumber, mLegNumber,...
                                mPlotFlag_TS, mPlotFlag_TS_AllLegs,...
                                mPlotFlag_Temperature, mPlotFlag_Salinity, mPlotFlag_Density,...
                                mPlotFlag_TemperatureProfile,...
                                mPlotFlag_SalinityProfile, mPlotFlag_DensityProfile,...
                                mPlotFlag_Temperature3D,...
                                mPlotFlag_Salinity3D, mPlotFlag_Density3D,...
                                mPlotFlag_AllGliderTracks);
                           
    end

% END GUI Callbacks //////////////////////////////////////////////////////////////////////////


end