Skip to content
Snippets Groups Projects
read_Climatology.m 3.17 KiB
Newer Older
function read_Climatology(hMainFig)
% read_Climatology(hMainFig)
% Function to read climatology and store result to tsg structure
%
% Input
% -----
% type    ............ String describing climatology (annual,sesonal or
%                      monthly)
%
% Output
% ------
% none    ............ but update tsg structure with setappdata
jacques.grelet_ird.fr's avatar
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
%
% Get data
% -----------------------
tsg = getappdata( hMainFig, 'tsg_data' );
% get last selected climatology
% -----------------------------
s = get(findobj('Tag', 'TAG_UIMENU_CLIMATO_MAIN'), 'Userdata');

jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
% 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
% -------------------------------------------------------------------------
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
if strcmp( tsg.levitus.type, 'none') || ~strcmp(tsg.levitus.type, s.type) ...
    || ~strcmp(lev_version, tsg.levitus.version) 

  % construct the filename and read file
  % ------------------------------------
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
  file = which([lower(lev_version) '_' s.type  '_surf.nc']);

  % open netcdf climatology file
  % ----------------------------
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
  levitus = read_file_woa(file);
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
  % check if the new climatology format is used:
  % before V1.0RC5, structure was levitus.WOA01_TIME
  % after  V1.0RC5, structure is levitus.WOA_TIME and works with new 
  % WOA01_*_surf.nc & WOA05_*_surf.nc files
  % ----------------------------------------------------------------
  if ~isfield(levitus, 'WOA_TIME')
    errordlg({'NetCDF climatology file :', file, ...
      'is wrong type or obsolete. Internal structure as changed',...
      'Download new one from',...
      ['ftp://ftp.ifremer.fr/ifremer/ird/us191/oceano/lib/matlab/woa05_' s.type '_surf.nc']},...
      'NetCDF climatology file error');
  end
  
  % update tsg.levitus.version
  % --------------------------
  tsg.levitus.version = lev_version;
  
  % 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
    
    % show dialog box with help to get climatology file
    % -------------------------------------------------
    errordlg({'NetCDF climatology file :', file, ...
      'not present in you path',...
      'Check your matlab path or download it from',...
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
      ['ftp://ftp.ifremer.fr/ifremer/ird/us191/oceano/lib/matlab/woa05_' s.type '_surf.nc']},...
    % init tsg.levitus state
    % ----------------------
    tsg.levitus.data = [];
    tsg.levitus.type = 'none';
    
% save tsg structure
% ------------------
setappdata( hMainFig, 'tsg_data', tsg );