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 % ------ % boolean % % $Id$ % global variable VERSION, update revision number when tsg structure change % ------------------------------------------------------------------------- global VERSION CHAR_VERSION DATE_VERSION DEBUGGING % Initialize loading preference file waitbar % ------------------------------------------ wb = waitbar(0, 'Loading preference file. Please wait...'); % display waitbar % --------------- waitbar( 1/10, wb, 'loading tsg structure' ); % Construct config file path % -------------------------- config_file = [prefdir, filesep, app_name, '.mat']; % Debug % ----- if DEBUGGING fprintf(1, 'Load configuration file is %s\n', config_file); end % Open config file % ---------------- % read preference mat file % ------------------------ fid = fopen( config_file, 'r' ); % test fopen return value % ----------------------- switch fid % preference file is missing % -------------------------- case -1 % create new tsg structure and save it to appdata % ----------------------------------------------- preference = new_config; % file exist and is open, fid > 2 % ------------------------------- otherwise % Pointer set to watch during loading preference file % --------------------------------------------------- set( hTsgGUI, 'Pointer', 'watch' ); try % if file exist, load preference struct to workspace % -------------------------------------------------- load( config_file, 'preference' ); catch % display warning % --------------- warning('tsgqc_GUI:tsg_preferences', ... 'Can''t load preference file ''%s''', config_file); % quit program % ------------ ok = false; return end % If there no field version or wrong version, initialize % ------------------------------------------------------- if ~(exist('preference','var') && ... isfield( preference, 'char_version') && ... strcmp(preference.char_version, CHAR_VERSION)) % call new config private function % -------------------------------- preference = new_config; if DEBUGGING fprintf(1, 'Version mismatch, restore a new default configuration file\n'); end end end % add preference struct to tsg struct % ----------------------------------- tsg.preference = preference; % map.border could be set to zero when zoom is active % --------------------------------------------------- tsg.preference.map.border = ... str2double(tsg.preference.map.border_string(tsg.preference.map.border_value)); % save structure tsg % ------------------ setappdata( hTsgGUI, 'tsg_data', tsg); % call default tsg_initialisation % ------------------------------- tsg_initialisation(hTsgGUI); % debug % ------ if DEBUGGING disp(tsg.preference) disp(tsg.preference.map) end % display waitbar % --------------- waitbar( 1/2, wb, 'loading structure tsg' ); % Close waitbar % ------------- close(wb) % cursor back to normal % --------------------- set(hTsgGUI,'Pointer','arrow'); ok = true; return % ---------------------------------------------------------------------- % nested function new_config % generate a new preference structure with default values % ---------------------------------------------------------------------- function preference = new_config % add tsg.preference to default values % ------------------------------------- preference.version = VERSION; preference.char_version = CHAR_VERSION; preference.date_version = DATE_VERSION; preference.autoload = 'off'; preference.fileExtension = ({'*.lbv';'*.nc';'*.arg';'*.ast';'*.btl';'*.ora';... '*.sdf';'*.spl'; '*.transmit*'; '*.tsgqc';'*.xml';'*.cnv'}); % Climatology preference.levitus_version = {'WOA05','WOA13','ISAS13','ISAS15'}; preference.levitus_value = 3; % ISAS13 as default preference.levitus_depth_string = {'5','10'}; preference.levitus_depth_value = 2; preference.coeff_type_string = {'use A-D', 'use G-J'}; preference.coeff_type_value = 2; % Plot preference.map.resolution_string = {'low','medium','intermediate','high'}; preference.map.resolution = 1; preference.map.patch_string = {'off', 'on'}; preference.map.patch_value = 1; preference.map.border_string = {'0','1','2','5','10','15'}; preference.map.border_value = 4; preference.map.border = 5; % default preference.map.climatology = 'none'; preference.map.climato.SSTP.min = 0; preference.map.climato.SSTP.max = 32; preference.map.climato.SSTP.step = 1; preference.map.climato.SSPS.min = 30; preference.map.climato.SSPS.max = 37; preference.map.climato.SSPS.step = .2; preference.map.track.size = 1; preference.map.track.size_index = 1; preference.map.track.color = 'b'; preference.map.track.color_index = 3; preference.map.ship.size = 5; preference.map.ship.size_index = 2; preference.map.ship.color = 'r'; preference.map.ship.color_index = 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'}; 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'}; % 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 = {sprintf('DD%cMM.SS',char(176)), '+-DD.CCCC'}; preference.positions_format_value = 1; % 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'; % Number of QC history levels for UNDO function % --------------------------------------------- preference.qc_history_size = '10'; % save preference struct to 'prefdir.mat' file % --------------------------------------------- save(config_file, 'preference'); end end