Newer
Older
function ok = tsg_preferences(hTsgGUI, app_name, DEFAULT_PATH_FILE)
% tsg_preferences(S1,S2) returns structure tsg saved in S1.mat file
% and with S2 internal version number.
% If S1.mat dosn't exist, call tsg_initialisation to create it in
% prefdir directory
%
% Input
% -----
% hTsgGUI ............ Handle to the main user interface
% app_name ............ application name
%
% Output
% ------
% global variable VERSION, update revision number when tsg structure change
% -------------------------------------------------------------------------

jacques.grelet_ird.fr
committed
% Initialize loading preference file waitbar
% ------------------------------------------
wb = waitbar(0, 'Loading preference file. Please wait...');
% display waitbar
% ---------------
waitbar( 1/10, wb, 'loading structure tsg' );
% Construct config file path
% --------------------------
config_file = [prefdir, filesep, app_name, '.mat'];
% Open config file
% ----------------
% read preference mat file
% ------------------------
fid = fopen( config_file, 'r' );
% test fopen return value
% -----------------------

jacques.grelet_ird.fr
committed
% --------------------------
case -1

jacques.grelet_ird.fr
committed
% create new tsg structure and save it to appdata
% -----------------------------------------------

jacques.grelet_ird.fr
committed
preference = new_config;
% file exist and is open, fid > 2
% -------------------------------

jacques.grelet_ird.fr
committed
% Pointer set to watch during loading preference file
% ---------------------------------------------------
set( hTsgGUI, 'Pointer', 'watch' );

jacques.grelet_ird.fr
committed

jacques.grelet_ird.fr
committed
% if file exist, load preference struct to workspace
% --------------------------------------------------
load( config_file, 'preference' );

jacques.grelet_ird.fr
committed

jacques.grelet_ird.fr
committed
% display warning
% ---------------
warning('tsgqc_GUI:tsg_preferences', ...
'Can''t load preference file ''%s''', config_file);

jacques.grelet_ird.fr
committed
% quit program
% ------------
ok = false;
return

jacques.grelet_ird.fr
committed

jacques.grelet_ird.fr
committed
% If there no field version or wrong version, initialize
% -------------------------------------------------------
if ~(exist('preference','var') && ...
isfield( preference, 'char_version') && ...
strcmp(preference.char_version, CHAR_VERSION))

jacques.grelet_ird.fr
committed
% call new config private function
% --------------------------------

jacques.grelet_ird.fr
committed

jacques.grelet_ird.fr
committed
end

jacques.grelet_ird.fr
committed
% add preference struct to tsg struct
% -----------------------------------
tsg.preference = preference;
% Save structure tsg
% ------------------
setappdata( hTsgGUI, 'tsg_data', tsg);
% update structure tsg with derived value
% ---------------------------------------
updateTsgStructWithSmoothVars(hTsgGUI)

jacques.grelet_ird.fr
committed
% call default tsg_initialisation
% -------------------------------
tsg_initialisation(hTsgGUI);

jacques.grelet_ird.fr
committed
% display waitbar
% ---------------
waitbar( 1/2, wb, 'loading structure tsg' );
% Close waitbar
% -------------
close(wb)
% cursor back to normal
% ---------------------
set(hTsgGUI,'Pointer','arrow');
ok = true;
return
% ----------------------------------------------------------------------

jacques.grelet_ird.fr
committed
% nested function new_config
% generate a new preference structure with default values
% ----------------------------------------------------------------------

jacques.grelet_ird.fr
committed
% add tsg.preference to default values
% -------------------------------------
preference.version = VERSION;
preference.char_version = CHAR_VERSION;
preference.levitus_version = {'WOA01','WOA05','ISAS13'};
preference.levitus_value = 2; % WOA05
preference.levitus_depth_string = {'0','10'};
preference.levitus_depth_value = 1;
preference.coeff_type_string = {'use A-D', 'use G-J'};
preference.coeff_type_value = 2;

jacques.grelet_ird.fr
committed
preference.map_resolution_string = {'low','medium','intermediate','high'};
preference.map_resolution = 1;
preference.plot_connected_string = {'none', '-', '--', ':', '-.'};
preference.plot_connected_value = 1; % 0, line not connected
% QC test
preference.flow_min_string = {'1'};
preference.press_min_string = {'1'};
Yves Gouriou
committed
preference.ship_speed_min_string = {'1'};
preference.ssps_min_string = {'0'};
preference.ssps_max_string = {'50'};
preference.ssjt_min_string = {'-3'};
preference.ssjt_max_string = {'40'};
preference.sstp_min_string = {'-3'};
preference.sstp_max_string = {'40'};

jacques.grelet_ird.fr
committed
% according with tsg_netcdf.xls file
% change version number or delete tsgqc.mat
% -----------------------------------------
preference.date_format_variable = 'yyyymmddHHMMSS';
preference.date_format_attribute = 'yyyymmddHHMMSS';
preference.positions_format_string = {'DDMM.SS', '+-DD.CCCC'};
preference.positions_format_value = 1;

jacques.grelet_ird.fr
committed
% use in tsg-average by tsg.cst.TSG_DT_SMOOTH
% this value in in minute
% ---------------------------------------------
preference.dt_smooth = '60';
% Salinity, in 1 hour interval, should not depart the average for more
% than SAL_STD_MAX standard deviation
% -------------------------------------
preference.ssps_stdmax = '0.1';
% Maximum time difference between tsg data and water sample used to
% compute the difference : 5 minutes.
% ------------------------------------
preference.ws_timediff = '5';
% save preference struct to 'prefdir.mat' file
% ---------------------------------------------
save(config_file, 'preference');

jacques.grelet_ird.fr
committed