Newer
Older
% levitus = read_file_woa(file)
% Read WOA01 Levitus T-S-O2, Stddev & nb_obs Netcdf file in memory

jacques.grelet_ird.fr
committed
%

jacques.grelet_ird.fr
committed
% check for file existence
% ------------------------
filesfound = checkforfiles( file );
if filesfound == 0;
warning(['Couldn''t find ', file]);
levitus = -1;
return;
end
% il existe un "bug" dans netcdf ligne 409, ncitem retourne une
% erreur dans la variable result

jacques.grelet_ird.fr
committed
% open file in read mode
% ----------------------
nc = netcdf(which(file), 'nowrite');
% Initialise la waitbar de chargement du fichier netCDF

jacques.grelet_ird.fr
committed
% -----------------------------------------------------
%wb = waitbar(0,'');

jacques.grelet_ird.fr
committed
% We cannot change title property to 'none' (default set as 'tex') inside
% waitbar function (line 81), see
% http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/115725
% -----------------------------------------------------------------------
% hchild = get(wb,'children');
% htitle = get(hchild,'title');
% set(htitle,'Interpreter','None');

jacques.grelet_ird.fr
committed
% ('none' as opposed to 'latex') to leave underscores as underscores
set(0,'DefaulttextInterpreter','none')

jacques.grelet_ird.fr
committed
% update waitbar title with Tex mode disable
% ------------------------------------------
wb = waitbar(0, ['Loading file: ' file ' Please wait...']);

jacques.grelet_ird.fr
committed
% loop for every variable
% -----------------------
for i = 1:length(var(nc))
% first initialize the dimensions of the data array, this is due to a bug
% (?) in netcdf toolbox, with an array [1,1,n,m], netcdf operator (:)
% return only [n,m]. This is true for surface climatology file !!!!!
% -------------------------------------------------------------------

jacques.grelet_ird.fr
committed
data = zeros(size(nc{i}));
% return current variable (object)
% --------------------------------
nv = nc{i};

jacques.grelet_ird.fr
committed
% use autonan mode on this variable (object), remplace fillValue with NaN
% -----------------------------------------------------------------------
nv = autonan(nv, true);
% then fill with values, we use a temporary object data, because nv
% is an netcdf object, see line 75
% -----------------------------------------------------------------
data(:) = nv(:);
% other Matlab way to replace fillValue by NaN
% --------------------------------------------
% if ~isempty(fillval(nc{i}))
% data(data == fillval(nc{i})) = NaN;
% end

jacques.grelet_ird.fr
committed
% assign dynamically variable in structure levitus
% ------------------------------------------------
% be carreful !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
% don't use data(:) ...
% whem data dimensions are [1,1,m,n]
% [m,n] = data(:)
% [1,1,m,n] = data
% ------------------------------------------------
levitus.(name(nv)) = data;

jacques.grelet_ird.fr
committed
% moves the waitbar cursor
% ------------------------
waitbar( i/length(nv), wb);

jacques.grelet_ird.fr
committed

jacques.grelet_ird.fr
committed
% close waitbar
% -------------

jacques.grelet_ird.fr
committed
% close netcdf file
% -----------------
close(nc);
%----------------------------------------------------------------------
%----------------------------------------------------------------------
function filesfound = checkforfiles( file )
if exist(file,'file');
filesfound = 1;
else
filesfound = 0;
end