Exemple #1
0
void
nc_advise(const char *routine_name, int err, const char *fmt,...)
{
	va_list args;

	if(NC_ISSYSERR(err))
		ncerr = NC_SYSERR;
	else
		ncerr = err;

	if( ncopts & NC_VERBOSE )
	{
		(void) fprintf(stderr,"%s: ", routine_name);
		va_start(args ,fmt);
		(void) vfprintf(stderr,fmt,args);
		va_end(args);
		if(err != NC_NOERR)
		{
			(void) fprintf(stderr,": %s",
				nc_strerror(err));
		}
		(void) fputc('\n',stderr);
		(void) fflush(stderr);	/* to ensure log files are current */
	}

	if( (ncopts & NC_FATAL) && err != NC_NOERR )
	{
		exit(ncopts);
	}
}
Exemple #2
0
/*
 * Test nc_open.
 * If in read-only section of tests,
 *    Try to open a non-existent netCDF file, check error return.
 *    Open a file that is not a netCDF file, check error return.
 *    Open a netCDF file with a bad mode argument, check error return.
 *    Open a netCDF file with NC_NOWRITE mode, try to write, check error.
 *    Try to open a netcdf twice, check whether returned netcdf ids different.
 * If in writable section of tests,
 *    Open a netCDF file with NC_WRITE mode, write something, close it.
 * On exit, any open netCDF files are closed.
 */
void
test_nc_open(void)
{
    int err;
    int ncid;
    int ncid2;

    /* Try to open a nonexistent file */
    err = nc_open("tooth-fairy.nc", NC_NOWRITE, &ncid);/* should fail */
    IF (err == NC_NOERR)
	error("nc_open of nonexistent file should have failed");
#ifndef USE_PARALLEL
    IF (! NC_ISSYSERR(err))
	error("nc_open of nonexistent file should have returned system error");
#endif

    /* Open a file that is not a netCDF file.  But need a portable
     * test that also works for cross-compiles ... */
    /* err = nc_open("nc_test.o", NC_NOWRITE, &ncid);/\* should fail *\/ */
    /* IF (err != NC_ENOTNC) */
    /* 	error("nc_open of non-netCDF file: status = %d", err); */

    /* Open a netCDF file in read-only mode, check that write fails */
    err = nc_open(testfile, NC_NOWRITE, &ncid);
    IF (err)
	error("nc_open: %s", nc_strerror(err));
    err = nc_redef(ncid);	/* should fail */
    IF (err != NC_EPERM)
	error("nc_redef of read-only file should fail");
    /* Opened OK, see if can open again and get a different netCDF ID */
    err = nc_open(testfile, NC_NOWRITE, &ncid2);
    IF (err)
	error("nc_open: %s", nc_strerror(err));
    else {
Exemple #3
0
/**
\ingroup error
 Given an error number, return an error message. 

This function returns a static reference to an error message string
corresponding to an integer netCDF error status or to a system error
number, presumably returned by a previous call to some other netCDF
function. The error codes are defined in netcdf.h.

\param ncerr1 error number

\returns short string containing error message.

\section Example

Here is an example of a simple error handling function that uses
nc_strerror to print the error message corresponding to the netCDF
error status returned from any netCDF function call and then exit:

\code
     #include <netcdf.h>
        ...
     void handle_error(int status) {
     if (status != NC_NOERR) {
        fprintf(stderr, "%s\n", nc_strerror(status));
        exit(-1);
        }
     }
\endcode
*/
const char *
nc_strerror(int ncerr1)
{
   /* System error? */
   if(NC_ISSYSERR(ncerr1))
   {
      const char *cp = (const char *) strerror(ncerr1);
      if(cp == NULL)
	 return "Unknown Error";
      return cp;
   }

   /* If we're here, this is a netcdf error code. */
   switch(ncerr1)
   {
      case NC_NOERR:
	 return "No error";
      case NC_EBADID:
	 return "NetCDF: Not a valid ID";
      case NC_ENFILE:
	 return "NetCDF: Too many files open";
      case NC_EEXIST:
	 return "NetCDF: File exists && NC_NOCLOBBER";
      case NC_EINVAL:
	 return "NetCDF: Invalid argument";
      case NC_EPERM:
	 return "NetCDF: Write to read only";
      case NC_ENOTINDEFINE:
	 return "NetCDF: Operation not allowed in data mode";
      case NC_EINDEFINE:
	 return "NetCDF: Operation not allowed in define mode";
      case NC_EINVALCOORDS:
	 return "NetCDF: Index exceeds dimension bound";
      case NC_EMAXDIMS:
	 return "NetCDF: NC_MAX_DIMS exceeded";
      case NC_ENAMEINUSE:
	 return "NetCDF: String match to name in use";
      case NC_ENOTATT:
	 return "NetCDF: Attribute not found";
      case NC_EMAXATTS:
	 return "NetCDF: NC_MAX_ATTRS exceeded";
      case NC_EBADTYPE:
	 return "NetCDF: Not a valid data type or _FillValue type mismatch";
      case NC_EBADDIM:
	 return "NetCDF: Invalid dimension ID or name";
      case NC_EUNLIMPOS:
	 return "NetCDF: NC_UNLIMITED in the wrong index";
      case NC_EMAXVARS:
	 return "NetCDF: NC_MAX_VARS exceeded";
      case NC_ENOTVAR:
	 return "NetCDF: Variable not found";
      case NC_EGLOBAL:
	 return "NetCDF: Action prohibited on NC_GLOBAL varid";
      case NC_ENOTNC:
	 return "NetCDF: Unknown file format";
      case NC_ESTS:
	 return "NetCDF: In Fortran, string too short";
      case NC_EMAXNAME:
	 return "NetCDF: NC_MAX_NAME exceeded";
      case NC_EUNLIMIT:
	 return "NetCDF: NC_UNLIMITED size already in use";
      case NC_ENORECVARS:
	 return "NetCDF: nc_rec op when there are no record vars";
      case NC_ECHAR:
	 return "NetCDF: Attempt to convert between text & numbers";
      case NC_EEDGE:
	 return "NetCDF: Start+count exceeds dimension bound";
      case NC_ESTRIDE:
	 return "NetCDF: Illegal stride";
      case NC_EBADNAME:
	 return "NetCDF: Name contains illegal characters";
      case NC_ERANGE:
	 return "NetCDF: Numeric conversion not representable";
      case NC_ENOMEM:
	 return "NetCDF: Memory allocation (malloc) failure";
      case NC_EVARSIZE:
	 return "NetCDF: One or more variable sizes violate format constraints";
      case NC_EDIMSIZE:
	 return "NetCDF: Invalid dimension size";
      case NC_ETRUNC:
	 return "NetCDF: File likely truncated or possibly corrupted";
      case NC_EAXISTYPE:
	 return "NetCDF: Illegal axis type";
      case NC_EDAP:
	 return "NetCDF: DAP failure";
      case NC_ECURL:
	 return "NetCDF: libcurl failure";
      case NC_EIO:
	 return "NetCDF: I/O failure";
      case NC_ENODATA:
	 return "NetCDF: Variable has no data in DAP request";
      case NC_EDAPSVC:
	 return "NetCDF: DAP server error";
      case NC_EDAS:
	 return "NetCDF: Malformed or inaccessible DAP DAS";
      case NC_EDDS:
	 return "NetCDF: Malformed or inaccessible DAP DDS";
      case NC_EDATADDS:
	 return "NetCDF: Malformed or inaccessible DAP DATADDS";
      case NC_EDAPURL:
	 return "NetCDF: Malformed URL";
      case NC_EDAPCONSTRAINT:
	 return "NetCDF: Malformed Constraint";
      case NC_ETRANSLATION:
	 return "NetCDF: Untranslatable construct";
      case NC_EHDFERR:
	 return "NetCDF: HDF error";
      case NC_ECANTREAD:
	 return "NetCDF: Can't read file";
      case NC_ECANTWRITE:
	 return "NetCDF: Can't write file";
      case NC_ECANTCREATE:
	 return "NetCDF: Can't create file";
      case NC_EFILEMETA:
	 return "NetCDF: Can't add HDF5 file metadata";
      case NC_EDIMMETA:      
	 return "NetCDF: Can't define dimensional metadata";
      case NC_EATTMETA:
	 return "NetCDF: Can't open HDF5 attribute";
      case NC_EVARMETA:
	 return "NetCDF: Problem with variable metadata.";
      case NC_ENOCOMPOUND:
	 return "NetCDF: Can't create HDF5 compound type";
      case NC_EATTEXISTS:
	 return "NetCDF: Attempt to create attribute that alread exists";
      case NC_ENOTNC4:
	 return "NetCDF: Attempting netcdf-4 operation on netcdf-3 file";
      case NC_ESTRICTNC3:
	 return "NetCDF: Attempting netcdf-4 operation on strict nc3 netcdf-4 file";
      case NC_ENOTNC3:
	 return "NetCDF: Attempting netcdf-3 operation on netcdf-4 file";
      case NC_ENOPAR:
	 return "NetCDF: Parallel operation on file opened for non-parallel access";
      case NC_EPARINIT:
	 return "NetCDF: Error initializing for parallel access";
      case NC_EBADGRPID:
	 return "NetCDF: Bad group ID";
      case NC_EBADTYPID:
	 return "NetCDF: Bad type ID";
      case NC_ETYPDEFINED:
	 return "NetCDF: Type has already been defined and may not be edited";
      case NC_EBADFIELD:
	 return "NetCDF: Bad field ID";
      case NC_EBADCLASS:
	 return "NetCDF: Bad class";
      case NC_EMAPTYPE:
	 return "NetCDF: Mapped access for atomic types only";
      case NC_ELATEFILL:
	 return "NetCDF: Attempt to define fill value when data already exists.";
      case NC_ELATEDEF:
	 return "NetCDF: Attempt to define var properties, like deflate, after enddef.";
      case NC_EDIMSCALE:
	 return "NetCDF: Probem with HDF5 dimscales.";
      case NC_ENOGRP:
	 return "NetCDF: No group found.";
      case NC_ESTORAGE:
	 return "NetCDF: Cannot specify both contiguous and chunking.";
      case NC_EBADCHUNK:
	 return "NetCDF: Bad chunk sizes.";
      case NC_ENOTBUILT:
	 return "NetCDF: Attempt to use feature that was not turned on "
	    "when netCDF was built.";
      case NC_EDISKLESS:
	 return "NetCDF: Error in using diskless access";
      default:
	 return "Unknown Error";
   }
}
Exemple #4
0
const char *
nc_strerror(int err)
{

#ifdef vms 
	if(err == EVMSERR)
	{
		return vms_strerror(err);
	}	
	/* else */
#endif /* vms */

	if(NC_ISSYSERR(err))
	{
		const char *cp = (const char *) strerror(err);
		if(cp == NULL)
			return unknown;
		/* else */
		return cp;
	}
	/* else */

	switch (err) {
	case NC_NOERR:
	    return "No error";
	case NC_EBADID:
	    return "NetCDF: Not a valid ID";
	case NC_ENFILE:
	    return "NetCDF: Too many files open";
	case NC_EEXIST:
	    return "NetCDF: File exists && NC_NOCLOBBER";
	case NC_EINVAL:
	    return "NetCDF: Invalid argument";
	case NC_EPERM:
	    return "NetCDF: Write to read only";
	case NC_ENOTINDEFINE:
	    return "NetCDF: Operation not allowed in data mode";
	case NC_EINDEFINE:
	    return "NetCDF: Operation not allowed in define mode";
	case NC_EINVALCOORDS:
	    return "NetCDF: Index exceeds dimension bound";
	case NC_EMAXDIMS:
	    return "NetCDF: NC_MAX_DIMS exceeded";
	case NC_ENAMEINUSE:
	    return "NetCDF: String match to name in use";
	case NC_ENOTATT:
	    return "NetCDF: Attribute not found";
	case NC_EMAXATTS:
	    return "NetCDF: NC_MAX_ATTRS exceeded";
	case NC_EBADTYPE:
	    return "NetCDF: Not a valid data type or _FillValue type mismatch";
	case NC_EBADDIM:
	    return "NetCDF: Invalid dimension ID or name";
	case NC_EUNLIMPOS:
	    return "NetCDF: NC_UNLIMITED in the wrong index";
	case NC_EMAXVARS:
	    return "NetCDF: NC_MAX_VARS exceeded";
	case NC_ENOTVAR:
	    return "NetCDF: Variable not found";
	case NC_EGLOBAL:
	    return "NetCDF: Action prohibited on NC_GLOBAL varid";
	case NC_ENOTNC:
	    return "NetCDF: Unknown file format";
	case NC_ESTS:
	    return "NetCDF: In Fortran, string too short";
	case NC_EMAXNAME:
	    return "NetCDF: NC_MAX_NAME exceeded";
	case NC_EUNLIMIT:
	    return "NetCDF: NC_UNLIMITED size already in use";
	case NC_ENORECVARS:
	    return "NetCDF: nc_rec op when there are no record vars";
	case NC_ECHAR:
	    return "NetCDF: Attempt to convert between text & numbers";
	case NC_EEDGE:
	    return "NetCDF: Start+count exceeds dimension bound";
	case NC_ESTRIDE:
	    return "NetCDF: Illegal stride";
	case NC_EBADNAME:
	    return "NetCDF: Name contains illegal characters";
	case NC_ERANGE:
	    return "NetCDF: Numeric conversion not representable";
	case NC_ENOMEM:
	    return "NetCDF: Memory allocation (malloc) failure";
	case NC_EVARSIZE:
	    return "NetCDF: One or more variable sizes violate format constraints";
	case NC_EDIMSIZE:
	    return "NetCDF: Invalid dimension size";
	case NC_ETRUNC:
	    return "NetCDF: File likely truncated or possibly corrupted";
	case NC_EAXISTYPE:
	    return "NetCDF: Illegal axis type";
	case NC_EDAP:
	    return "NetCDF: DAP failure";
	case NC_ECURL:
	    return "NetCDF: libcurl failure";
	case NC_EIO:
	    return "NetCDF: I/O failure";
	case NC_ENODATA:
	    return "NetCDF: Variable has no data in DAP request";
	case NC_EDAPSVC:
	    return "NetCDF: DAP server error";
	case NC_EDAS:
	    return "NetCDF: Malformed or inaccessible DAP DAS";
	case NC_EDDS:
	    return "NetCDF: Malformed or inaccessible DAP DDS";
	case NC_EDATADDS:
	    return "NetCDF: Malformed or inaccessible DAP DATADDS";
	case NC_EDAPURL:
	    return "NetCDF: Malformed DAP URL";
	case NC_EDAPCONSTRAINT:
	    return "NetCDF: Malformed DAP Constraint";
	}
	/* default */
	return unknown;
}
Exemple #5
0
const char *
nc_strerror(int err)
{

#ifdef vms 
	if(err == EVMSERR)
	{
		return vms_strerror(err);
	}	
	/* else */
#endif /* vms */

	if(NC_ISSYSERR(err))
	{
		const char *cp = (const char *) strerror(err);
		if(cp == NULL)
			return unknown;
		/* else */
		return cp;
	}
	/* else */

	switch (err) {
	case NC_NOERR:
	    return "No error";
	case NC_EBADID:
	    return "Not a netCDF id";
	case NC_ENFILE:
	    return "Too many netCDF files open";
	case NC_EEXIST:
	    return "netCDF file exists && NC_NOCLOBBER";
	case NC_EINVAL:
	    return "Invalid argument";
	case NC_EPERM:
	    return "Write to read only";
	case NC_ENOTINDEFINE:
	    return "Operation not allowed in data mode";
	case NC_EINDEFINE:
	    return "Operation not allowed in define mode";
	case NC_EINVALCOORDS:
	    return "Index exceeds dimension bound";
	case NC_EMAXDIMS:
	    return "NC_MAX_DIMS exceeded";
	case NC_ENAMEINUSE:
	    return "String match to name in use";
	case NC_ENOTATT:
	    return "Attribute not found";
	case NC_EMAXATTS:
	    return "NC_MAX_ATTRS exceeded";
	case NC_EBADTYPE:
	    return "Not a netCDF data type or _FillValue type mismatch";
	case NC_EBADDIM:
	    return "Invalid dimension id or name";
	case NC_EUNLIMPOS:
	    return "NC_UNLIMITED in the wrong index";
	case NC_EMAXVARS:
	    return "NC_MAX_VARS exceeded";
	case NC_ENOTVAR:
	    return "Variable not found";
	case NC_EGLOBAL:
	    return "Action prohibited on NC_GLOBAL varid";
	case NC_ENOTNC:
	    return "Not a netCDF file";
	case NC_ESTS:
	    return "In Fortran, string too short";
	case NC_EMAXNAME:
	    return "NC_MAX_NAME exceeded";
	case NC_EUNLIMIT:
	    return "NC_UNLIMITED size already in use";
	case NC_ENORECVARS:
	    return "nc_rec op when there are no record vars";
	case NC_ECHAR:
	    return "Attempt to convert between text & numbers";
	case NC_EEDGE:
	    return "Start+count exceeds dimension bound";
	case NC_ESTRIDE:
	    return "Illegal stride";
	case NC_EBADNAME:
	    return "Attribute or variable name contains illegal characters";
	case NC_ERANGE:
	    return "Numeric conversion not representable";
	case NC_ENOMEM:
	    return "Memory allocation (malloc) failure";
	case NC_EVARSIZE:
	    return "One or more variable sizes violate format constraints";
	case NC_EDIMSIZE:
	    return "Invalid dimension size";
	case NC_ETRUNC:
	    return "File likely truncated or possibly corrupted";
	}
	/* default */
	return unknown;
}