Newer
Older
% read_Climatology(hMainFig)

jacques.grelet_ird.fr
committed
% Function to read climatology and store result to tsg structure
%
% Input
% -----
% tsg ............ structure tsg

jacques.grelet_ird.fr
committed
% type ............ String describing climatology (annual,sesonal or
% monthly)
%
% Output
% ------
% none ............ but update tsg structure with setappdata

jacques.grelet_ird.fr
committed
%
% Caution:
% --------
% before V1.0RC5, structure was levitus.WOA01_TIME with DEPH = [0]
% after V1.0RC5, structure is levitus.WOA_TIME with DEPH = [0, 10] and
% works with new WOA01_*_surf.nc & WOA05_*_surf.nc files
%

jacques.grelet_ird.fr
committed
global DEFAULT_PATH_FILE
ftp_addr = 'ftp.ifremer.fr';
ftp_dir = 'ifremer/ird/us191/oceano/Climatology';
isRead = false;
% Get data
% -----------------------
tsg = getappdata( hMainFig, 'tsg_data' );

jacques.grelet_ird.fr
committed
% get last selected climatology
% -----------------------------
s = get(findobj('Tag', 'TAG_UIMENU_CLIMATO_MAIN'), 'Userdata');
% get selected levitus version in preferencesForm
% -----------------------------------------------
lev_version = tsg.preference.levitus_version{tsg.preference.levitus_value};
% tsg.levitus.type = 'none' or new select climatology is different, load file
% -------------------------------------------------------------------------
if strcmp( tsg.levitus.type, 'none') || ~strcmp(tsg.levitus.type, s.type) ...
|| ~strcmp(lev_version, tsg.levitus.version)
% construct the climatology filename and try to found it
% -------------------------------------------------------
theFile = [lower(lev_version) '_' s.type '_surf.nc'];
file = which(theFile);
% prepare full file ftp name
% --------------------------
ftp_all = sprintf('%s/%s/%s', ftp_addr, ftp_dir, lev_version);
ftpLink = strcat(ftp_all, '/', theFile);
% check for file existence
% ------------------------
if ~exist(file, 'file')
% show dialog box when climatology file are missing
% -------------------------------------------------
answer = questdlg({['NetCDF climatology file: ', theFile], ...
'is not present in you Matlab path.',...
'Do you want download it from ', ftp_all, '?'},...
['NetCDF ', lev_version, ' climatology file missing'],...
'Yes', 'No', 'Yes');
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
% memorize current dir
% --------------------
currentDir = pwd;
% handle user response
% --------------------
switch answer
case 'Yes'
% NetCDF files are automatically downloaded from ftp
% --------------------------------------------------
ftpobj = ftp(ftp_addr);
cd(ftpobj, ftp_dir);
if DEBUGGING
dir(ftpobj);
end
cd(ftpobj, lev_version);
cd(strcat(DEFAULT_PATH_FILE, filesep, 'tsg_climato'));
h = showinfowindow(hMainFig,...
{['Downloading NetCDF ', lev_version, ' files from : ', ftp_all],...
'Please wait ...'}, 'TSG-QC Climatology');
mget(ftpobj,'*.nc');
close(ftpobj);
close(h);
rehash;
cd(currentDir); % return back to current dir
file = which(theFile);
isRead = true;
case 'No'
% disable climatology toolbar
% ---------------------------
hdl = findobj( '-regexp', 'tag', 'PUSHTOOL_CLIM');
% change the state call automatically Clim_OffMenuCallback function
% -----------------------------------------------------------------
set( hdl, 'state', 'off' );
cd(currentDir); % return back to current dir
% display ftp download adress in hypertext link in Matlab command Window
% ----------------------------------------------------------------------
fprintf(1,'download from ftp directory: <a href="ftp://%s">ftp://%s</a>\n', ftp_all, ftp_all);
fprintf(1,'direct link: <a href="ftp://%s">ftp://%s</a>\n', ftpLink, ftpLink);
isRead = false;
return;
end

jacques.grelet_ird.fr
committed
% open netcdf climatology file
% ----------------------------
if DEBUGGING
fprintf(1, 'Read climatology file: %s\n', file);
end
% update tsg.levitus.version
% --------------------------
tsg.levitus.version = lev_version;

jacques.grelet_ird.fr
committed
% test for structure concordance
% ------------------------------
if isstruct(levitus)
% ok, save last climato state in tsg.levitus structure
% ----------------------------------------------------
tsg.levitus.type = s.type;
tsg.levitus.data = levitus;
else
% display ftp download adress in hypertext link in Matlab command Window
% ----------------------------------------------------------------------
fprintf(1,'download from ftp directory: <a href="%s">%s</a>\n', ftp, ftp);
fprintf(1,'direct link: <a href="%s">%s</a>\n', ftpLink, ftpLink);
% show error dialog box with help to get climatology file
% -------------------------------------------------------
errordlg({['NetCDF climatology file: ' theFile], ...
'is wrong type or obsolete. Internal structure as changed',...
'Download new one from: ',...
ftp,...
'see hypertext link in Matlab Command Window'},...
% init tsg.levitus state
% ----------------------
tsg.levitus.data = [];
tsg.levitus.type = 'none';
% disable climatology toolbar
hdl = findobj( '-regexp', 'tag', 'PUSHTOOL_CLIM');
set( hdl, 'state', 'off' );

jacques.grelet_ird.fr
committed
end
end

jacques.grelet_ird.fr
committed
if DEBUGGING
fprintf(1, 'Version: %s\n', tsg.levitus.version);
fprintf(1, 'Type: %s\n', tsg.levitus.type);
tsg.levitus.data
end
% save tsg structure
% ------------------
setappdata( hMainFig, 'tsg_data', tsg );