[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 20010516: ncopts, NC_FATAL and NC_VERBOSE



>From: Stephen Marshall <address@hidden>
>Subject: ncopts, NC_FATAL and NC_VERBOSE
>Organization: WSI Corporation
>Keywords: 200105161832.f4GIWtp16601 netCDF NC_FATAL NC_VERBOSE

Hi Steve,

> I have a question about error handling in the NetCDF library.
> 
> When I tried to retrieve a variable id by name from a NetCDF file,
> and the variable did not exist in the file, my program terminated
> with this error message.
> 
> ncvarid: ncid 3: Variable not found
> 
> I had error handling in my application, but that code was never executed.

This means that you are using the (relatively old) netCDF-2 interface
where termination with a message was the default error handling, and
where to change this, you had to set flag bits in the global variable
ncopts.  The netCDF-3 interface, changed the default, so that every
function call returns an error status, and you have to take further
action to produce an error message or take other action as the result
of an error.

> Tracing the problem through the code, I found the error was issued
> in the nc_advise() function.  The global variable ncopts was set with
> both the NC_VERBOSE and NC_FATAL flags turned on.  These
> settings caused, respectively, the error message to be generated and
> the program to terminate.
> 
> I would like to disable both these features so I could handle all these
> errors within my application.  It looks like I can do it my editing
> a line of code in the module v2i.c and recompiling,
> e.g. change
>     int ncopts = (NC_FATAL | NC_VERBOSE) ;
> to
>     int ncopts = 0;
> 
> My question is, are any side effects to turning off NC_FATAL and
> NC_VERBOSE other than their effects on the nc_advise function?
> Also can this be done with compile switches, or do I have to edit
> the source file?

Although you could change the default by recompiling the library, your
programs would no longer match the netCDF-2 documented interface so
might puzzle future maintainers.  The documented way to change the
error handling behavior when using the netCDF-2 interfaces is to reset
the value of ncopts:  

 http://www.unidata.ucar.edu/packages/netcdf/guide_6.html#SEC37

You should not even declare ncopts, because its
declaration as an external int is already made in the netcdf.h header
file you #include at the top of a file of code that uses netCDF.

--Russ

_____________________________________________________________________

Russ Rew                                         UCAR Unidata Program
address@hidden                     http://www.unidata.ucar.edu