Skip to content
Snippets Groups Projects
Commit 481bd1d1 authored by jacques.grelet_ird.fr's avatar jacques.grelet_ird.fr
Browse files

add try catch and errordlg if file not found

parent cab858a5
No related branches found
No related tags found
No related merge requests found
......@@ -18,12 +18,11 @@ end
% check file validity
% -------------------
self.nc_id = netcdf.open(self.file, self.mode);
if self.nc_id == -1
error(['netcdf:netcdf', ...
'The specified data file ''%s'' does not exist\n' ...
'or is not in the directory which is on the MATLAB path'],...
self.file);
try
self.nc_id = netcdf.open(self.file, self.mode);
catch me
errordlg(me.message, 'Read NetCDF file error');
error(me.identifier, me.message);
end
% update waitbar title with Tex mode disable
......@@ -136,10 +135,10 @@ for id = 0:nvars-1
% -------------------------------------
try
s.data__ = netcdf.getVar(self.nc_id, id);
% under Matlab R2011b, getVar thrown an error when all _EXT dimensions
% are 0. In that case, set data to empty
% ------------------------------------------------------------------
% under Matlab R2011b, getVar thrown an error when all _EXT dimensions
% are 0. In that case, set data to empty
% ------------------------------------------------------------------
catch ME
fprintf('Notice: netcdf_native:read: %s set to empty\n', varName);
% fprintf('Notice: netcdf_native:read: %s: %s\n', varName, ME.message);
......@@ -186,34 +185,34 @@ for id = 0:nvars-1
end
end
% % if var is char and as vertical alignment, transpose it
% % ------------------------------------------------------
% % if xtype == self.NC_CHAR && (size(s.data__, 1) ~= 1)
% % s.data__ = s.data__';
% % end
%
% % add internal dimension__ member
% % Because MATLAB uses FORTRAN-style ordering, however, the order of
% % the dimension IDs is reversed relative to what would be obtained
% % from the C API
% % ----------------------------
% if length(dimids) > 1
% s.data__ = permute(s.data__, fliplr(1:length(dimids)));
% dimids = fliplr(dimids);
% end
% % if var is char and as vertical alignment, transpose it
% % ------------------------------------------------------
% % if xtype == self.NC_CHAR && (size(s.data__, 1) ~= 1)
% % s.data__ = s.data__';
% % end
%
% % add internal dimension__ member
% % Because MATLAB uses FORTRAN-style ordering, however, the order of
% % the dimension IDs is reversed relative to what would be obtained
% % from the C API
% % ----------------------------
% if length(dimids) > 1
% s.data__ = permute(s.data__, fliplr(1:length(dimids)));
% dimids = fliplr(dimids);
% end
% if var is char and as vertical alignment, transpose it
% ------------------------------------------------------
if xtype == self.NC_CHAR && (size(s.data__', 1) == 1)
s.data__ = s.data__';
% Because MATLAB uses FORTRAN-style indexing, we need to transpose
% N-D array (k,i,j,...) to (i,j,k,...) however, the order of
% the dimension IDs is reversed relative to what would be obtained
% from the C API
% If s.data__ is a vector, NetCDF API return vertical vector,
% do nothing, it's OK
% -----------------------------------------------------------------
% Because MATLAB uses FORTRAN-style indexing, we need to transpose
% N-D array (k,i,j,...) to (i,j,k,...) however, the order of
% the dimension IDs is reversed relative to what would be obtained
% from the C API
% If s.data__ is a vector, NetCDF API return vertical vector,
% do nothing, it's OK
% -----------------------------------------------------------------
elseif length(dimids) > 1
s.data__ = permute(s.data__, fliplr(1:length(dimids)));
dimids = fliplr(dimids);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment