Newer
Older
% Check for .TSG writing error - must to be rewriting
% Because of the 'return' - These line must be at the end
% --------------------------------------------------------
warning('tsgqc:SaveMenuCallback', ...
'TSG no ouput: %s %s', pathName, fileName);
return;
end
end
%% ExportSampleCallback
% -------------------------------------------------------------------
% Callback function run when the Export menu item is selected
% -------------------------------------------------------------------
function ExportSampleCallback(src, evnt)
% Retrieve named application data
% -------------------------------
tsg = getappdata( hMainFig, 'tsg_data');
% Desactivate MouseMotion 'off'
% ----------------------------
set( hMainFig, 'WindowButtonMotionFcn', []);
% Open standard dialog box for saving files
% -----------------------------------------
gael.alory_legos.obs-mip.fr
committed
[fileName, pathName, filterindex] = uiputfile('*.spl', ...
'Save file name', strcat(tsg.file.name, '.spl'));
% if user press cancel button, all var are set to zero
% ----------------------------------------------------
if filterindex == 0
% Pointer set to watch during reading and plotting
% ------------------------------------------------
set( hMainFig, 'Pointer', 'watch' );
gael.alory_legos.obs-mip.fr
committed
% Write a .SPL (ascii) file
% --------------------------
error = writeAsciiSample(hMainFig, strcat(pathName, fileName));
% Pointer reset to arrow
% ----------------------
set( hMainFig, 'Pointer', 'arrow' );
% enable Quality Control mode
% ---------------------------
hdl_pushtool = findobj('Tag', 'QC');
set(hdl_pushtool, 'Enable', 'on');
% Set MouseMotion 'on'
% --------------------
set( hMainFig, 'WindowButtonMotionFcn', @MouseMotion);
% Check for .TSG writing error - must to be rewriting
% Because of the 'return' - These line must be at the end
% --------------------------------------------------------
if error == -1
warning('tsgqc:SaveMenuCallback', ...
'TSG no ouput: %s %s', pathName, fileName);
return;
end
% -----------------------------------------------------------------------
% Callback function run when the Edit/Undo menu item is selected (Ctrl+Z)
% -----------------------------------------------------------------------
function UndoMenuCallback(src, evnt)
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
if (tsg.qc_history_pointer > 0)
% Get the parameter (SSPS, SSJT or SSTP)
% --------------------------------------
PARA = getParaCorModule( hMainFig );
if (tsg.qc_history_pointer == tsg.qc_history_size)
tsg.qc_history_state = circshift(tsg.qc_history_state,[0 -1]);
tsg.qc_history_pointer = tsg.qc_history_pointer - 1;
end
% Back to previous QC flags
% -------------------------
tsg.qc_history_state(:,tsg.qc_history_pointer+1) = tsg.([PARA{1} '_QC']);
tsg.([PARA{1} '_QC']) = tsg.qc_history_state(:,tsg.qc_history_pointer);
tsg.qc_history_pointer = tsg.qc_history_pointer - 1;
% Allow redo
% ----------
tsg.qc_redo_possible = tsg.qc_redo_possible + 1;
% Save the modifications
% ----------------------
setappdata( hMainFig, 'tsg_data', tsg);
% 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);
end
% As soon as a modification took place the data should be saved
% -------------------------------------------------------------
set( hSaveMenu, 'UserData', 'on' );
else
msgbox('Undo not possible', 'modal');

jacques.grelet_ird.fr
committed
end
end
% -----------------------------------------------------------------------
% Callback function run when the Edit/Redo menu item is selected (Ctrl+R)
% -----------------------------------------------------------------------
function RedoMenuCallback(src, evnt)
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
if (tsg.qc_redo_possible >0)
% Get the parameter (SSPS, SSJT or SSTP)
% --------------------------------------
PARA = getParaCorModule( hMainFig );
% Forward to undone QC flags
% --------------------------
tsg.qc_history_pointer = tsg.qc_history_pointer + 1;
tsg.([PARA{1} '_QC']) = tsg.qc_history_state(:,tsg.qc_history_pointer+1);
% Reduce number of possible redo
% ------------------------------
tsg.qc_redo_possible = tsg.qc_redo_possible-1;
% Save the modifications
% ----------------------
setappdata( hMainFig, 'tsg_data', tsg);
% 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);
end
% As soon as a modification took place the data should be saved
% -------------------------------------------------------------
set( hSaveMenu, 'UserData', 'on' );
else
msgbox('Redo not possible', 'modal');
end
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
%% This function is called after to duplicate QC from upper plot to middle
% plot
% -----------------------------------------------------------------------
function duplicateQc(src, evnt)
% Get the data from the application GUI
% -------------------------------------
tsg = getappdata( hMainFig, 'tsg_data');
source = tsg.plot.parameter{1};
dest = tsg.plot.parameter{2};
valid = {'SSPS', 'SSTP'};
if any(strcmp(valid, source)) && any(strcmp(valid, dest))
% duplicate QC from parameter 1 to 2
% ----------------------------------
tsg.([dest '_QC']) = tsg.([source '_QC']);
% Save tsg structure first for plot_Validation
% ---------------------------------------------
setappdata( hMainFig, 'tsg_data', tsg);
% plot with QC on middle plot
% ---------------------------
plot_Validation( hMainFig, hPlotAxes, 2, tsg.plot.parameter{2} );
else
msgbox( 'Duplication QC code only on SSPS or SSTP variable',...
'Choose the correct variable first', 'warn', 'modal');
end
end
%% KeyPressFcnCallback
% -----------------------------------------------------------------------
% Callback function run when key is pressed
% -----------------------------------------------------------------------

jacques.grelet_ird.fr
committed
% MATLAB generates repeated KeyPressFcn events, desactivate callback
% ------------------------------------------------------------------

jacques.grelet_ird.fr
committed
% check if key is pressed
% -----------------------
if ~isempty(evnt.Key)

jacques.grelet_ird.fr
committed
% test key, shift or control
% --------------------------
switch evnt.Key

jacques.grelet_ird.fr
committed
case 'shift'

jacques.grelet_ird.fr
committed
% get current pointer shape
% -------------------------

jacques.grelet_ird.fr
committed
% save current cursor shape
% -------------------------
setappdata( hMainFig, 'tsg_pointer', pointerShape);

jacques.grelet_ird.fr
committed
% set cursor to fullcross or reset to normal arrow
% ------------------------------------------------
set(src, 'pointer', 'crosshair');
case 'alt'

jacques.grelet_ird.fr
committed
% Get current position of cusor and return its coordinates in
% axes
% -----------------------------------------------------------
a = get(hPlotAxes(1), 'CurrentPoint');
x = a(2,1);

jacques.grelet_ird.fr
committed
% Test if cursor is inside data interval
% -------------------------------------
if x > tsg.DAYD(1) && x < tsg.DAYD(end)

jacques.grelet_ird.fr
committed
% loop over 3 subplot and draw vertical lines
% -------------------------------------------
for iplot = 1:3
% axes( hPlotAxes(iplot));

jacques.grelet_ird.fr
committed
limy = get(hPlotAxes(iplot), 'YLim');
line(hPlotAxes(iplot), [x x], limy,...
'color', 'k', 'tag', 'VERTICAL_TAG_LINE');
% to immediately display changes to object data, call
% the drawnow function instead of setting EraseMode to 'xor'.
% since R2014
drawnow;

jacques.grelet_ird.fr
committed
end
end

jacques.grelet_ird.fr
committed
end % end of switch

jacques.grelet_ird.fr
committed
%% KeyReleaseFcnCallback
% -----------------------------------------------------------------------
% Callback function run when key is release
% -----------------------------------------------------------------------

jacques.grelet_ird.fr
committed
% check if key is pressed
% -----------------------
if ~isempty(evnt.Key)

jacques.grelet_ird.fr
committed
% test key, shift or control
% --------------------------
switch evnt.Key

jacques.grelet_ird.fr
committed
case 'shift'

jacques.grelet_ird.fr
committed
% get stored cursor shape
% -----------------------
pointerShape = getappdata( hMainFig, 'tsg_pointer');

jacques.grelet_ird.fr
committed
% if pointer equal to fullcrosshair, oups, error, reset to arrow
% ---------------------------------------------------------------
if strcmp(pointerShape, 'fullcrosshair')
pointerShape = 'arrow';

jacques.grelet_ird.fr
committed
end

jacques.grelet_ird.fr
committed
% set pointer
% -----------
case 'alt'

jacques.grelet_ird.fr
committed
% find vertical lines and delete them
% -----------------------------------
hdl_lines = findobj( 'Tag', 'VERTICAL_TAG_LINE' );
delete(hdl_lines);

jacques.grelet_ird.fr
committed
end % end of switch

jacques.grelet_ird.fr
committed
end % end of if
% Re-activate callback
% --------------------

jacques.grelet_ird.fr
committed
end
%% QuitMapCallback
% -----------------------------------------------------------------
% Callback function run when the Quit Map Figure item is selected
% -----------------------------------------------------------------
function QuitMapCallback(src, evnt)
% Make the earth map invisible
% ----------------------------
set(hMapToggletool, 'state', 'off' );
% -----------------------------------------------------------------
% Callback function run when the Quit menu item is selected
% -----------------------------------------------------------------
function QuitMenuCallback(src, evnt)
% Get the data from the application GUI
% -------------------------------------
tsg = getappdata(hMainFig, 'tsg_data');
% in case of bad initialisation, the user could close the windows
% ---------------------------------------------------------------
try
% save config mat file in prefdir
% -------------------------------
config_file = [prefdir, filesep, tsgqcname, '.mat'];
% save preference mat file
% ------------------------
if exist('tsg', 'var') && isfield( tsg, 'preference')
preference = tsg.preference;
save( config_file, 'preference');
end
% If the data have been modified and not save, the program
% ask to save the data
% --------------------------------------------------------
if strcmp( get( hSaveMenu, 'UserData' ), 'on')
selection = ...
questdlg('The file has been modified. Do you want to save it ?',...
'Save before Quit?',...
'Yes', 'No', 'Yes');
if strcmp(selection, 'Yes')
% call File/Save Menu Callback before before quit
% -----------------------------------------------
SaveMenuCallback;
% quit program
% ------------
quitProgram(DEFAULT_PATH_FILE, hMainFig, hMapFig);
selection = ...
questdlg(['Quit ' get(hMainFig, 'Name') '?'],...
['Quit ' get(hMainFig, 'Name') '?'],...
'Yes', 'No', 'Yes');
if strcmp(selection, 'No')
return;
else
quitProgram(DEFAULT_PATH_FILE, hMainFig, hMapFig);
end
% catch error during close windows
% --------------------------------
catch
% display message to console and quit program
% -------------------------------------------
fprintf('abnormal program termination during close user request\n');
quitProgram(DEFAULT_PATH_FILE, hMainFig);

jacques.grelet_ird.fr
committed
end % end of QuitMenuCallback
function quitProgram(DEFAULT_PATH_FILE, varargin)
% close all windows
% -----------------
for ii=1:size(varargin,2)
delete(varargin{ii});
end
% reset userdata property of root Matalab object (0) for next use
% ---------------------------------------------------------------
set(0, 'userdata', []);
% reset Matlab search path to default
% addpath isn't mandatory and failed with compiled applications
% --------------------------------------------------------------
if (~isdeployed)
rmpath( [DEFAULT_PATH_FILE filesep 'tsg_util'] );
rmpath( [DEFAULT_PATH_FILE filesep 'tsg_data'] );
rmpath( [DEFAULT_PATH_FILE filesep 'tsg_io'] );
rmpath( [DEFAULT_PATH_FILE filesep 'tsg_icon'] );
rmpath( [DEFAULT_PATH_FILE filesep 'tsg_map'] );
end
% Refresh file system caches
% --------------------------
rehash;
% clear base workspace just before quit, this is the only method
% to clear NetCDF variables assign to base workspace with assignin
% ----------------------------------------------------------------
evalin('base','clear all');
end % end of quitProgram
end % end of tsgqc