Coverage Report

Created: 2026-06-30 08:33

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