Hi Heiko, Sorry to have taken so long to respond to your email ... > when opening a netcdf-file with the (old) cpp interface of netcdf, e.g. > new NcFile(filename, NcFile::ReadOnly) > it is not possible to catch any error, e.g. "No such file or directory". > > The problem is that NcFile::NcFile internally sets > > NcError err(NcError::silent_nonfatal); // constructor must not fail > > but when the NcFile constructor finishes, the destructor of NcError is > called, which will reset the NcError. Right, that's why the documentation recommends using the is_valid() member function after an attempted open to determine whether it succeeded or failed: The constructor will not fail, but in the case of a bad path name, improper permissions, or if the file already exists and you have specified FileMode as New, no netCDF file will be created or opened. If the constructor fails to create or open a netCDF file, a subsequent call to the is_valid() member function will return False. This would be handled better with Exceptions (as the new netCDF-4 C++ API does) but Exceptions weren't in the C++ standard back when this was written. The new C++ netCDF-4 API is documented here: http://www.unidata.ucar.edu/netcdf/docs/cxx4/ It currently can read any kind of netCDF file, but can only create netCDF-4 files. A little work is needed in the constructors to support creating classic format, 64-bit offset, and netCDF-4 classic model files ... --Russ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: ZES-283112 Department: Support netCDF Priority: High Status: Closed
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.