Re: catching netcdf error codes [message #38719] |
Fri, 26 March 2004 13:53  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Benjamin Hornberger wrote:
> Hi all,
>
> I don't know how to catch a netcdf error code. I want to write a
> function is_netcdf() which checks if a file is a netcdf file. For
> that, I use the ncdf_open() function. If the file is not a netcdf
> file, then I will get an error which I want to catch. The error sais
> "%NCDF_OPEN: Unable to open the file "...". (NC_ERROR=-51)".
>
> If I now check !error_state.code, it is -1088 and not -51. Which
> variable holds the "nc_error", how can I get that?
>
> Thanks for your help,
> Benjamin
Dear Benjamin
we have already written such a routine.
You'll find it here
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _work/rb_lib
is_ncdf_file.pro
You need only to check the first three bytes of the file. If it is 'CDF'
then it is a netCDF file.
For further routines and licensing please have a look at
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
best regards
Reimar
|
|
|
Re: catching netcdf error codes [message #38721 is a reply to message #38719] |
Fri, 26 March 2004 13:17   |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
Benjamin Hornberger wrote:
> Hi all,
>
> I don't know how to catch a netcdf error code. I want to write a
> function is_netcdf() which checks if a file is a netcdf file. For
> that, I use the ncdf_open() function. If the file is not a netcdf
> file, then I will get an error which I want to catch. The error sais
> "%NCDF_OPEN: Unable to open the file "...". (NC_ERROR=-51)".
>
> If I now check !error_state.code, it is -1088 and not -51. Which
> variable holds the "nc_error", how can I get that?
I don't know if you can in IDL (you can in Fortran90 and C/C++). I would check the IDL
netcdf help (which I can't currently do and, as far as I can tell, the idlwave html docs
also don't have it?). Anyway, below is an incomplete list of the corresponding errors from
the netcdf library.
I say incomplete because of the following:
IDL> id=ncdf_open('blah')
% Loaded DLM: NCDF.
% NCDF_OPEN: Unable to open the file "blah". (NC_ERROR=-31)
% Execution halted at: $MAIN$
where there is no file named "blah". I don't see an error value of -31 in the list below.
Or -32 for that matter.
; #define NC_NOERR 0 /* No Error */
;
; #define NC_EBADID (-33) /* Not a netcdf id */
; #define NC_ENFILE (-34) /* Too many netcdfs open */
; #define NC_EEXIST (-35) /* netcdf file exists && NC_NOCLOBBER */
; #define NC_EINVAL (-36) /* Invalid Argument */
; #define NC_EPERM (-37) /* Write to read only */
; #define NC_ENOTINDEFINE (-38) /* Operation not allowed in data mode */
; #define NC_EINDEFINE (-39) /* Operation not allowed in define mode */
; #define NC_EINVALCOORDS (-40) /* Index exceeds dimension bound */
; #define NC_EMAXDIMS (-41) /* NC_MAX_DIMS exceeded */
; #define NC_ENAMEINUSE (-42) /* String match to name in use */
; #define NC_ENOTATT (-43) /* Attribute not found */
; #define NC_EMAXATTS (-44) /* NC_MAX_ATTRS exceeded */
; #define NC_EBADTYPE (-45) /* Not a netcdf data type */
; #define NC_EBADDIM (-46) /* Invalid dimension id or name */
; #define NC_EUNLIMPOS (-47) /* NC_UNLIMITED in the wrong index */
; #define NC_EMAXVARS (-48) /* NC_MAX_VARS exceeded */
; #define NC_ENOTVAR (-49) /* Variable not found */
; #define NC_EGLOBAL (-50) /* Action prohibited on NC_GLOBAL varid */
; #define NC_ENOTNC (-51) /* Not a netcdf file */
; #define NC_ESTS (-52) /* In Fortran, string too short */
; #define NC_EMAXNAME (-53) /* NC_MAX_NAME exceeded */
; #define NC_EUNLIMIT (-54) /* NC_UNLIMITED size already in use */
; #define NC_ENORECVARS (-55) /* nc_rec op when there are no record vars */
; #define NC_ECHAR (-56) /* Attempt to convert between text & numbers */
; #define NC_EEDGE (-57) /* Edge+start exceeds dimension bound */
; #define NC_ESTRIDE (-58) /* Illegal stride */
; #define NC_EBADNAME (-59) /* Attribute or variable name
; contains illegal characters */
; /* N.B. following must match value in ncx.h */
; #define NC_ERANGE (-60) /* Math result not representable */
; #define NC_ENOMEM (-61) /* Memory allocation (malloc) failure */
|
|
|
Re: catching netcdf error codes [message #38805 is a reply to message #38719] |
Sun, 28 March 2004 17:04  |
Mark Hadfield
Messages: 783 Registered: May 1995
|
Senior Member |
|
|
Reimar Bauer wrote:
> You need only to check the first three bytes of the file. If it is 'CDF'
> then it is a netCDF file.
Or possibly some other sort of file with 'CDF' in the first three bytes!
--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
|
|
|