/src/netcdf-c/libdispatch/derror.c
| Line | Count | Source | 
| 1 |  | /** \file | 
| 2 |  | Error messages and library version. | 
| 3 |  |  | 
| 4 |  | These functions return the library version, and error messages. | 
| 5 |  |  | 
| 6 |  | Copyright 2018 University Corporation for Atmospheric | 
| 7 |  | Research/Unidata. See COPYRIGHT file for more info. | 
| 8 |  | */ | 
| 9 |  |  | 
| 10 |  | #include "config.h" | 
| 11 |  | #include "ncdispatch.h" | 
| 12 |  | #ifdef USE_PNETCDF | 
| 13 |  | #include <pnetcdf.h>  /* for ncmpi_strerror() */ | 
| 14 |  | #endif | 
| 15 |  |  | 
| 16 |  | /** @internal The version string for the library, used by | 
| 17 |  |  * nc_inq_libvers(). */ | 
| 18 |  | static const char nc_libvers[] = PACKAGE_VERSION " of "__DATE__" "__TIME__" $"; | 
| 19 |  |  | 
| 20 |  | /** | 
| 21 |  | Return the library version. | 
| 22 |  |  | 
| 23 |  | \returns short string that contains the version information for the | 
| 24 |  | library. | 
| 25 |  |  */ | 
| 26 |  | const char * | 
| 27 |  | nc_inq_libvers(void) | 
| 28 | 0 | { | 
| 29 | 0 |    return nc_libvers; | 
| 30 | 0 | } | 
| 31 |  |  | 
| 32 |  | /*! NetCDF Error Handling | 
| 33 |  |  | 
| 34 |  | \addtogroup error NetCDF Error Handling | 
| 35 |  |  | 
| 36 |  | NetCDF functions return a non-zero status codes on error. | 
| 37 |  |  | 
| 38 |  | Each netCDF function returns an integer status value. If the returned | 
| 39 |  | status value indicates an error, you may handle it in any way desired, | 
| 40 |  | from printing an associated error message and exiting to ignoring the | 
| 41 |  | error indication and proceeding (not recommended!). For simplicity, | 
| 42 |  | the examples in this guide check the error status and call a separate | 
| 43 |  | function, handle_err(), to handle any errors. One possible definition | 
| 44 |  | of handle_err() can be found within the documentation of | 
| 45 |  | nc_strerror(). | 
| 46 |  |  | 
| 47 |  | The nc_strerror() function is available to convert a returned integer | 
| 48 |  | error status into an error message string. | 
| 49 |  |  | 
| 50 |  | Occasionally, low-level I/O errors may occur in a layer below the | 
| 51 |  | netCDF library. For example, if a write operation causes you to exceed | 
| 52 |  | disk quotas or to attempt to write to a device that is no longer | 
| 53 |  | available, you may get an error from a layer below the netCDF library, | 
| 54 |  | but the resulting write error will still be reflected in the returned | 
| 55 |  | status value. | 
| 56 |  |  | 
| 57 |  | */ | 
| 58 |  |  | 
| 59 |  | /** \{ */ | 
| 60 |  |  | 
| 61 |  | /*! Given an error number, return an error message. | 
| 62 |  |  | 
| 63 |  | This function returns a static reference to an error message string | 
| 64 |  | corresponding to an integer netCDF error status or to a system error | 
| 65 |  | number, presumably returned by a previous call to some other netCDF | 
| 66 |  | function. The error codes are defined in netcdf.h. | 
| 67 |  |  | 
| 68 |  | \param ncerr1 error number | 
| 69 |  |  | 
| 70 |  | \returns short string containing error message. | 
| 71 |  |  | 
| 72 |  | Here is an example of a simple error handling function that uses | 
| 73 |  | nc_strerror() to print the error message corresponding to the netCDF | 
| 74 |  | error status returned from any netCDF function call and then exit: | 
| 75 |  |  | 
| 76 |  | \code | 
| 77 |  |      #include <netcdf.h> | 
| 78 |  |         ... | 
| 79 |  |      void handle_error(int status) { | 
| 80 |  |      if (status != NC_NOERR) { | 
| 81 |  |         fprintf(stderr, "%s\n", nc_strerror(status)); | 
| 82 |  |         exit(-1); | 
| 83 |  |         } | 
| 84 |  |      } | 
| 85 |  | \endcode | 
| 86 |  | */ | 
| 87 |  | const char *nc_strerror(int ncerr1) | 
| 88 | 0 | { | 
| 89 |  |    /* System error? */ | 
| 90 | 0 |    if(NC_ISSYSERR(ncerr1)) | 
| 91 | 0 |    { | 
| 92 | 0 |       const char *cp = (const char *) strerror(ncerr1); | 
| 93 | 0 |       if(cp == NULL) | 
| 94 | 0 |    return "Unknown Error"; | 
| 95 | 0 |       return cp; | 
| 96 | 0 |    } | 
| 97 |  |  | 
| 98 |  |    /* If we're here, this is a netcdf error code. */ | 
| 99 | 0 |    switch(ncerr1) | 
| 100 | 0 |    { | 
| 101 | 0 |       case NC_NOERR: | 
| 102 | 0 |    return "No error"; | 
| 103 | 0 |       case NC_EBADID: | 
| 104 | 0 |    return "NetCDF: Not a valid ID"; | 
| 105 | 0 |       case NC_ENFILE: | 
| 106 | 0 |    return "NetCDF: Too many files open"; | 
| 107 | 0 |       case NC_EEXIST: | 
| 108 | 0 |    return "NetCDF: File exists && NC_NOCLOBBER"; | 
| 109 | 0 |       case NC_EINVAL: | 
| 110 | 0 |    return "NetCDF: Invalid argument"; | 
| 111 | 0 |       case NC_EPERM: | 
| 112 | 0 |    return "NetCDF: Write to read only"; | 
| 113 | 0 |       case NC_ENOTINDEFINE: | 
| 114 | 0 |    return "NetCDF: Operation not allowed in data mode"; | 
| 115 | 0 |       case NC_EINDEFINE: | 
| 116 | 0 |    return "NetCDF: Operation not allowed in define mode"; | 
| 117 | 0 |       case NC_EINVALCOORDS: | 
| 118 | 0 |    return "NetCDF: Index exceeds dimension bound"; | 
| 119 | 0 |       case NC_EMAXDIMS: | 
| 120 | 0 |    return "NetCDF: NC_MAX_DIMS exceeded"; /* not enforced after 4.5.0 */ | 
| 121 | 0 |       case NC_ENAMEINUSE: | 
| 122 | 0 |    return "NetCDF: String match to name in use"; | 
| 123 | 0 |       case NC_ENOTATT: | 
| 124 | 0 |    return "NetCDF: Attribute not found"; | 
| 125 | 0 |       case NC_EMAXATTS: | 
| 126 | 0 |    return "NetCDF: NC_MAX_ATTRS exceeded"; /* not enforced after 4.5.0 */ | 
| 127 | 0 |       case NC_EBADTYPE: | 
| 128 | 0 |    return "NetCDF: Not a valid data type or _FillValue type mismatch"; | 
| 129 | 0 |       case NC_EBADDIM: | 
| 130 | 0 |    return "NetCDF: Invalid dimension ID or name"; | 
| 131 | 0 |       case NC_EUNLIMPOS: | 
| 132 | 0 |    return "NetCDF: NC_UNLIMITED in the wrong index"; | 
| 133 | 0 |       case NC_EMAXVARS:  return "NetCDF: NC_MAX_VARS exceeded"; /* not enforced after 4.5.0 */ | 
| 134 | 0 |       case NC_ENOTVAR: | 
| 135 | 0 |    return "NetCDF: Variable not found"; | 
| 136 | 0 |       case NC_EGLOBAL: | 
| 137 | 0 |    return "NetCDF: Action prohibited on NC_GLOBAL varid"; | 
| 138 | 0 |       case NC_ENOTNC: | 
| 139 | 0 |    return "NetCDF: Unknown file format"; | 
| 140 | 0 |       case NC_ESTS: | 
| 141 | 0 |    return "NetCDF: In Fortran, string too short"; | 
| 142 | 0 |       case NC_EMAXNAME: | 
| 143 | 0 |    return "NetCDF: NC_MAX_NAME exceeded"; | 
| 144 | 0 |       case NC_EUNLIMIT: | 
| 145 | 0 |    return "NetCDF: NC_UNLIMITED size already in use"; | 
| 146 | 0 |       case NC_ENORECVARS: | 
| 147 | 0 |    return "NetCDF: nc_rec op when there are no record vars"; | 
| 148 | 0 |       case NC_ECHAR: | 
| 149 | 0 |    return "NetCDF: Attempt to convert between text & numbers"; | 
| 150 | 0 |       case NC_EEDGE: | 
| 151 | 0 |    return "NetCDF: Start+count exceeds dimension bound"; | 
| 152 | 0 |       case NC_ESTRIDE: | 
| 153 | 0 |    return "NetCDF: Illegal stride"; | 
| 154 | 0 |       case NC_EBADNAME: | 
| 155 | 0 |    return "NetCDF: Name contains illegal characters"; | 
| 156 | 0 |       case NC_ERANGE: | 
| 157 | 0 |    return "NetCDF: Numeric conversion not representable"; | 
| 158 | 0 |       case NC_ENOMEM: | 
| 159 | 0 |    return "NetCDF: Memory allocation (malloc) failure"; | 
| 160 | 0 |       case NC_EVARSIZE: | 
| 161 | 0 |    return "NetCDF: One or more variable sizes violate format constraints"; | 
| 162 | 0 |       case NC_EDIMSIZE: | 
| 163 | 0 |    return "NetCDF: Invalid dimension size"; | 
| 164 | 0 |       case NC_ETRUNC: | 
| 165 | 0 |    return "NetCDF: File likely truncated or possibly corrupted"; | 
| 166 | 0 |       case NC_EAXISTYPE: | 
| 167 | 0 |    return "NetCDF: Illegal axis type"; | 
| 168 | 0 |       case NC_EDAP: | 
| 169 | 0 |    return "NetCDF: DAP failure"; | 
| 170 | 0 |       case NC_ECURL: | 
| 171 | 0 |    return "NetCDF: libcurl failure"; | 
| 172 | 0 |       case NC_EIO: | 
| 173 | 0 |    return "NetCDF: I/O failure"; | 
| 174 | 0 |       case NC_ENODATA: | 
| 175 | 0 |    return "NetCDF: Variable has no data"; | 
| 176 | 0 |       case NC_EDAPSVC: | 
| 177 | 0 |    return "NetCDF: DAP server error"; | 
| 178 | 0 |       case NC_EDAS: | 
| 179 | 0 |    return "NetCDF: Malformed or inaccessible DAP DAS"; | 
| 180 | 0 |       case NC_EDDS: | 
| 181 | 0 |    return "NetCDF: Malformed or inaccessible DAP2 DDS or DAP4 DMR response"; | 
| 182 | 0 |       case NC_EDATADDS: | 
| 183 | 0 |    return "NetCDF: Malformed or inaccessible DAP2 DATADDS or DAP4 DAP response"; | 
| 184 | 0 |       case NC_EDAPURL: | 
| 185 | 0 |    return "NetCDF: Malformed URL"; | 
| 186 | 0 |       case NC_EDAPCONSTRAINT: | 
| 187 | 0 |    return "NetCDF: Malformed or unexpected Constraint"; | 
| 188 | 0 |       case NC_ETRANSLATION: | 
| 189 | 0 |    return "NetCDF: Untranslatable construct"; | 
| 190 | 0 |       case NC_EACCESS: | 
| 191 | 0 |    return "NetCDF: Access failure"; | 
| 192 | 0 |       case NC_EAUTH: | 
| 193 | 0 |    return "NetCDF: Authorization failure"; | 
| 194 | 0 |       case NC_ENOTFOUND: | 
| 195 | 0 |    return "NetCDF: file not found"; | 
| 196 | 0 |       case NC_ECANTREMOVE: | 
| 197 | 0 |    return "NetCDF: cannot delete file"; | 
| 198 | 0 |       case NC_EINTERNAL: | 
| 199 | 0 |    return "NetCDF: internal library error; Please contact Unidata support"; | 
| 200 | 0 |       case NC_EPNETCDF: | 
| 201 | 0 |    return "NetCDF: PnetCDF error"; | 
| 202 | 0 |       case NC_EHDFERR: | 
| 203 | 0 |    return "NetCDF: HDF error"; | 
| 204 | 0 |       case NC_ECANTREAD: | 
| 205 | 0 |    return "NetCDF: Can't read file"; | 
| 206 | 0 |       case NC_ECANTWRITE: | 
| 207 | 0 |    return "NetCDF: Can't write file"; | 
| 208 | 0 |       case NC_ECANTCREATE: | 
| 209 | 0 |    return "NetCDF: Can't create file"; | 
| 210 | 0 |       case NC_EFILEMETA: | 
| 211 | 0 |    return "NetCDF: Can't add HDF5 file metadata"; | 
| 212 | 0 |       case NC_EDIMMETA: | 
| 213 | 0 |    return "NetCDF: Can't define dimensional metadata"; | 
| 214 | 0 |       case NC_EATTMETA: | 
| 215 | 0 |    return "NetCDF: Can't open HDF5 attribute"; | 
| 216 | 0 |       case NC_EVARMETA: | 
| 217 | 0 |    return "NetCDF: Problem with variable metadata."; | 
| 218 | 0 |       case NC_ENOCOMPOUND: | 
| 219 | 0 |    return "NetCDF: Can't create HDF5 compound type"; | 
| 220 | 0 |       case NC_EATTEXISTS: | 
| 221 | 0 |    return "NetCDF: Attempt to create attribute that already exists"; | 
| 222 | 0 |       case NC_ENOTNC4: | 
| 223 | 0 |    return "NetCDF: Attempting netcdf-4 operation on netcdf-3 file"; | 
| 224 | 0 |       case NC_ESTRICTNC3: | 
| 225 | 0 |    return "NetCDF: Attempting netcdf-4 operation on strict nc3 netcdf-4 file"; | 
| 226 | 0 |       case NC_ENOTNC3: | 
| 227 | 0 |    return "NetCDF: Attempting netcdf-3 operation on netcdf-4 file"; | 
| 228 | 0 |       case NC_ENOPAR: | 
| 229 | 0 |    return "NetCDF: Parallel operation on file opened for non-parallel access"; | 
| 230 | 0 |       case NC_EPARINIT: | 
| 231 | 0 |    return "NetCDF: Error initializing for parallel access"; | 
| 232 | 0 |       case NC_EBADGRPID: | 
| 233 | 0 |    return "NetCDF: Bad group ID"; | 
| 234 | 0 |       case NC_EBADTYPID: | 
| 235 | 0 |    return "NetCDF: Bad type ID"; | 
| 236 | 0 |       case NC_ETYPDEFINED: | 
| 237 | 0 |    return "NetCDF: Type has already been defined and may not be edited"; | 
| 238 | 0 |       case NC_EBADFIELD: | 
| 239 | 0 |    return "NetCDF: Bad field ID"; | 
| 240 | 0 |       case NC_EBADCLASS: | 
| 241 | 0 |    return "NetCDF: Bad class"; | 
| 242 | 0 |       case NC_EMAPTYPE: | 
| 243 | 0 |    return "NetCDF: Mapped access for atomic types only"; | 
| 244 | 0 |       case NC_ELATEFILL: | 
| 245 | 0 |    return "NetCDF: Attempt to define fill value when data already exists."; | 
| 246 | 0 |       case NC_ELATEDEF: | 
| 247 | 0 |    return "NetCDF: Attempt to define var properties, like deflate, after enddef."; | 
| 248 | 0 |       case NC_EDIMSCALE: | 
| 249 | 0 |    return "NetCDF: Problem with HDF5 dimscales."; | 
| 250 | 0 |       case NC_ENOGRP: | 
| 251 | 0 |    return "NetCDF: No group found."; | 
| 252 | 0 |       case NC_ESTORAGE: | 
| 253 | 0 |    return "NetCDF: Cannot specify both contiguous and chunking."; | 
| 254 | 0 |       case NC_EBADCHUNK: | 
| 255 | 0 |    return "NetCDF: Bad chunk sizes."; | 
| 256 | 0 |       case NC_ENOTBUILT: | 
| 257 | 0 |    return "NetCDF: Attempt to use feature that was not turned on " | 
| 258 | 0 |       "when netCDF was built."; | 
| 259 | 0 |       case NC_EDISKLESS: | 
| 260 | 0 |    return "NetCDF: Error in using diskless access"; | 
| 261 | 0 |       case NC_EFILTER: | 
| 262 | 0 |    return "NetCDF: Filter error: bad id or parameters or duplicate filter"; | 
| 263 | 0 |       case NC_ENOFILTER: | 
| 264 | 0 |    return "NetCDF: Filter error: undefined filter encountered"; | 
| 265 | 0 |       case NC_ECANTEXTEND: | 
| 266 | 0 |   return "NetCDF: Attempt to extend dataset during NC_INDEPENDENT I/O operation. Use nc_var_par_access to set mode NC_COLLECTIVE before extending variable."; | 
| 267 | 0 |       case NC_EMPI: return "NetCDF: MPI operation failed."; | 
| 268 | 0 |       case NC_ERCFILE: | 
| 269 | 0 |   return "NetCDF: RC File Failure."; | 
| 270 | 0 |       case NC_ENULLPAD: | 
| 271 | 0 |        return "NetCDF: File fails strict Null-Byte Header check."; | 
| 272 | 0 |       case NC_EINMEMORY: | 
| 273 | 0 |        return "NetCDF: In-memory File operation failed."; | 
| 274 | 0 |       case NC_ENCZARR: | 
| 275 | 0 |    return "NetCDF: NCZarr error"; | 
| 276 | 0 |       case NC_ES3: | 
| 277 | 0 |    return "NetCDF: S3 error"; | 
| 278 | 0 |       case NC_EEMPTY: | 
| 279 | 0 |    return "NetCDF: Attempt to read empty NCZarr map key"; | 
| 280 | 0 |       case NC_EOBJECT: | 
| 281 | 0 |    return "NetCDF: Some object exists when it should not"; | 
| 282 | 0 |       case NC_ENOOBJECT: | 
| 283 | 0 |    return "NetCDF: Some object not found"; | 
| 284 | 0 |       case NC_EPLUGIN: | 
| 285 | 0 |    return "NetCDF: Unclassified failure in accessing a dynamically loaded plugin"; | 
| 286 | 0 |      default: | 
| 287 |  | #ifdef USE_PNETCDF | 
| 288 |  |         /* The behavior of ncmpi_strerror here is to return | 
| 289 |  |            NULL, not a string.  This causes problems in (at least) | 
| 290 |  |            the fortran interface. */ | 
| 291 |  |         return (ncmpi_strerror(ncerr1) ? | 
| 292 |  |                 ncmpi_strerror(ncerr1) : | 
| 293 |  |                 "Unknown Error"); | 
| 294 |  | #else | 
| 295 | 0 |    return "Unknown Error"; | 
| 296 | 0 | #endif | 
| 297 | 0 |    } | 
| 298 | 0 | } | 
| 299 |  |  | 
| 300 |  | /** \} */ |