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

Re: 970725: handle_error ? Is it implemented ?



>To: address@hidden
>From: Adrianos Lahanas <address@hidden>
>Subject: handle_error ? Is it implemented ?
>Organization: University of Cyprus
>Keywords: 199707250809.CAA24059

Hi Adrianos,

> I am a student at University of Cyprus. I tried to install
> the netCDF software provided by your Foundation. Actually
> the netcdf-3.3.1 version.
> 
> I installed it successfuly but some problems arise when I compile
> my programs. When the xlc compiler tries to link the objects
> it complains it can not find the function "handle_error".

The handle_error() function used in the examples in the documentation is
just to make the examples simpler.  Error handling can differ greatly in
applications, depending on whether the program is trying to hide the
netCDF layer from the user.

But there is a simple example of a handle_error() function in the User's
Guide section 5.2, documenting the nc_strerror() function:

#include <netcdf.h>
   ... 
void handle_error(int status) {
if (status != NC_NOERR) {
   fprintf(stderr, "%s\n", nc_strerror(status));
   exit(-1);
   }
}

You could just use this, if you want something simple.

I usually would like to know where the error came from (source file and
line number in the C source), and for this you could use something a
bit more complicated:

void
check_err(const int stat, const int line, const char *file) {
    if (stat != NC_NOERR) {
           (void) fprintf(stderr, "line %d of %s: %s\n", line, file, 
                          nc_strerror(stat));
        exit(1);
    }
}

which you would call like this, for example:

   status = nc_create("ctest0.nc", NC_CLOBBER, &ncid);
   check_err(status,__LINE__,__FILE__);

> Is it implemented in your 3.3.1 version ?
> I also tried to find it with the grep command but it doesn't find 
> anything.
> 
> Is it implemented in any other version of netcdf ?

The way errors are handled is left up to the application, since there is
such a wide variety of ways to do this (much like other Unix I/O
libraries, in which you must check the returned error status and handle
it).  So the only netCDF library support for error handling is the error
status returned by each function and the error strings returned by
nc_strerror().

--Russ

_____________________________________________________________________

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