I was attempting to plot a series of sequential plots from a netCDF file of results from a modestly modified version of the upwelling test case using roms_jview.m (in Matlab 2009b). The plots come up exactly as I would expect, but after creating N plots (where N isn't all that large, and is cumulative within a session), Matlab would complain of too many files open and refuse to continue its otherwise cordial collaboration with me.
The fail appears to occur at line 2 of nc_varget_tmw.m :
Code: Select all
varid=netcdf.inqVarid(ncid,varname);
which rather often does not execute for some reason, leaving the current call of nc_varget_tmw hanging and the file referred to by the existing ncid unclosed.
An apparent fix is substituting
Code: Select all
try
varid=netcdf.inqVarid(ncid,varname);
catch
netcdf.close(ncid);
end
I'm a bit worried that the problem I'm encountering is not really in Matlab, but something weird in my netCDF files, but note that the same netCDF file is being examined each time. Without the try-catch statement, the code often opens the file numerous times before successfully assigning a varid and moving on through the rest of the code. Then it cycles through a few successes and starts a new sequence of orphaned ncid's...
Any thoughts, reactions, recommendations would be greatly appreciated.
Cheers,
EB