Go to the previous, next section.
By default all netCDF library routines print an error message and exit when an error has occurred. If this error behavior is acceptable, you never need to check error returns, since any condition that would result in an error will print an explanatory message and exit. The examples in this guide assume the default error-handling behavior, so there is no checking of error returns.
Occasionally, low-level write errors may occur in the XDR library layer below the netCDF library. For example, if a write operation causes you to exceed disk quotas or to attempt to write to a device that is no longer available, you may get an error message from one of the XDR functions rather than from the netCDF library. If you get a message from the XDR layer, diagnose and correct whatever is causing the low-level write errors.
In the C interface, errors may be handled more flexibly by setting the
external integer ncopts
, declared in the file `netcdf.h'.
Two aspects of the error-handling behavior can be modified
independently: the suppression of error messages, and the fatality of
errors. The default behavior is specified by the assignment
ncopts = NC_VERBOSE | NC_FATAL;where
NC_VERBOSE
and NC_FATAL
are predefined constants
from the include file `netcdf.h'.
If you want error messages but do not wish errors to be fatal, turn off the fatal error flag with:
ncopts = NC_VERBOSE;If you want neither error messages nor fatal errors, turn off both flags with:
ncopts = 0;In either case, you should check the return value after each call to a netCDF function. The integer
-1
is returned whenever an error
occurs and NC_FATAL
is off, so you can detect error returns and
handle the errors appropriately. Another externally-defined integer,
ncerr
, contains a netCDF-specific error code that can be used
after an error has occurred to determine what the nature of the error
was. The names and descriptions of netCDF error codes are included in
the file `netcdf.h'.
In the FORTRAN interface, the error options described above can be accessed by using the routines NCPOPT and NCGOPT. The default error- handling behavior is equivalent to the statement
CALL NCPOPT(NCVERBOS+NCFATAL)where the values of NCVERBOS and NCFATAL are pre-defined constants from the FORTRAN include file `netcdf.inc'. If you want error messages, but do not wish errors to be fatal, turn off the fatal error flag with:
CALL NCPOPT(NCVERBOS)If you want neither error messages nor fatal errors, turn off both flags with:
CALL NCPOPT(0)To get the current value of the error options, use:
CALL NCGOPT(NCOPTS)
In either case, the integer return code (the last parameter in all of the FORTRAN subroutines and functions) contains the non-zero netCDF-specific error number that can be used to determine the nature of the error. Names and descriptions of netCDF error codes are included in the file `netcdf.inc'.
Go to the previous, next section.