1 | /** \file |
---|
2 | Error messages and library version. |
---|
3 | |
---|
4 | These functions return the library version, and error messages. |
---|
5 | |
---|
6 | Copyright 2010 University Corporation for Atmospheric |
---|
7 | Research/Unidata. See COPYRIGHT file for more info. |
---|
8 | */ |
---|
9 | |
---|
10 | #include "ncdispatch.h" |
---|
11 | |
---|
12 | /* Tell the user the version of netCDF. */ |
---|
13 | static const char nc_libvers[] = PACKAGE_VERSION " of "__DATE__" "__TIME__" $"; |
---|
14 | |
---|
15 | /** \defgroup lib_version Library Version |
---|
16 | |
---|
17 | */ |
---|
18 | |
---|
19 | /** |
---|
20 | \ingroup lib_version |
---|
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 | { |
---|
29 | return nc_libvers; |
---|
30 | } |
---|
31 | |
---|
32 | /** \defgroup error Error Handling |
---|
33 | NetCDF functions non-zero status codes on error. |
---|
34 | |
---|
35 | Each netCDF function returns an integer status value. If the returned |
---|
36 | status value indicates an error, you may handle it in any way desired, |
---|
37 | from printing an associated error message and exiting to ignoring the |
---|
38 | error indication and proceeding (not recommended!). For simplicity, |
---|
39 | the examples in this guide check the error status and call a separate |
---|
40 | function, handle_err(), to handle any errors. One possible definition |
---|
41 | of handle_err() can be found within the documentation of |
---|
42 | nc_strerror(). |
---|
43 | |
---|
44 | The nc_strerror() function is available to convert a returned integer |
---|
45 | error status into an error message string. |
---|
46 | |
---|
47 | Occasionally, low-level I/O errors may occur in a layer below the |
---|
48 | netCDF library. For example, if a write operation causes you to exceed |
---|
49 | disk quotas or to attempt to write to a device that is no longer |
---|
50 | available, you may get an error from a layer below the netCDF library, |
---|
51 | but the resulting write error will still be reflected in the returned |
---|
52 | status value. |
---|
53 | |
---|
54 | */ |
---|
55 | |
---|
56 | /** |
---|
57 | \ingroup error |
---|
58 | Given an error number, return an error message. |
---|
59 | |
---|
60 | This function returns a static reference to an error message string |
---|
61 | corresponding to an integer netCDF error status or to a system error |
---|
62 | number, presumably returned by a previous call to some other netCDF |
---|
63 | function. The error codes are defined in netcdf.h. |
---|
64 | |
---|
65 | \param ncerr1 error number |
---|
66 | |
---|
67 | \returns short string containing error message. |
---|
68 | |
---|
69 | \section Example |
---|
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 * |
---|
87 | nc_strerror(int ncerr1) |
---|
88 | { |
---|
89 | /* System error? */ |
---|
90 | if(NC_ISSYSERR(ncerr1)) |
---|
91 | { |
---|
92 | const char *cp = (const char *) strerror(ncerr1); |
---|
93 | if(cp == NULL) |
---|
94 | return "Unknown Error"; |
---|
95 | return cp; |
---|
96 | } |
---|
97 | |
---|
98 | /* If we're here, this is a netcdf error code. */ |
---|
99 | switch(ncerr1) |
---|
100 | { |
---|
101 | case NC_NOERR: |
---|
102 | return "No error"; |
---|
103 | case NC_EBADID: |
---|
104 | return "NetCDF: Not a valid ID"; |
---|
105 | case NC_ENFILE: |
---|
106 | return "NetCDF: Too many files open"; |
---|
107 | case NC_EEXIST: |
---|
108 | return "NetCDF: File exists && NC_NOCLOBBER"; |
---|
109 | case NC_EINVAL: |
---|
110 | return "NetCDF: Invalid argument"; |
---|
111 | case NC_EPERM: |
---|
112 | return "NetCDF: Write to read only"; |
---|
113 | case NC_ENOTINDEFINE: |
---|
114 | return "NetCDF: Operation not allowed in data mode"; |
---|
115 | case NC_EINDEFINE: |
---|
116 | return "NetCDF: Operation not allowed in define mode"; |
---|
117 | case NC_EINVALCOORDS: |
---|
118 | return "NetCDF: Index exceeds dimension bound"; |
---|
119 | case NC_EMAXDIMS: |
---|
120 | return "NetCDF: NC_MAX_DIMS exceeded"; |
---|
121 | case NC_ENAMEINUSE: |
---|
122 | return "NetCDF: String match to name in use"; |
---|
123 | case NC_ENOTATT: |
---|
124 | return "NetCDF: Attribute not found"; |
---|
125 | case NC_EMAXATTS: |
---|
126 | return "NetCDF: NC_MAX_ATTRS exceeded"; |
---|
127 | case NC_EBADTYPE: |
---|
128 | return "NetCDF: Not a valid data type or _FillValue type mismatch"; |
---|
129 | case NC_EBADDIM: |
---|
130 | return "NetCDF: Invalid dimension ID or name"; |
---|
131 | case NC_EUNLIMPOS: |
---|
132 | return "NetCDF: NC_UNLIMITED in the wrong index"; |
---|
133 | case NC_EMAXVARS: |
---|
134 | return "NetCDF: NC_MAX_VARS exceeded"; |
---|
135 | case NC_ENOTVAR: |
---|
136 | return "NetCDF: Variable not found"; |
---|
137 | case NC_EGLOBAL: |
---|
138 | return "NetCDF: Action prohibited on NC_GLOBAL varid"; |
---|
139 | case NC_ENOTNC: |
---|
140 | return "NetCDF: Unknown file format"; |
---|
141 | case NC_ESTS: |
---|
142 | return "NetCDF: In Fortran, string too short"; |
---|
143 | case NC_EMAXNAME: |
---|
144 | return "NetCDF: NC_MAX_NAME exceeded"; |
---|
145 | case NC_EUNLIMIT: |
---|
146 | return "NetCDF: NC_UNLIMITED size already in use"; |
---|
147 | case NC_ENORECVARS: |
---|
148 | return "NetCDF: nc_rec op when there are no record vars"; |
---|
149 | case NC_ECHAR: |
---|
150 | return "NetCDF: Attempt to convert between text & numbers"; |
---|
151 | case NC_EEDGE: |
---|
152 | return "NetCDF: Start+count exceeds dimension bound"; |
---|
153 | case NC_ESTRIDE: |
---|
154 | return "NetCDF: Illegal stride"; |
---|
155 | case NC_EBADNAME: |
---|
156 | return "NetCDF: Name contains illegal characters"; |
---|
157 | case NC_ERANGE: |
---|
158 | return "NetCDF: Numeric conversion not representable"; |
---|
159 | case NC_ENOMEM: |
---|
160 | return "NetCDF: Memory allocation (malloc) failure"; |
---|
161 | case NC_EVARSIZE: |
---|
162 | return "NetCDF: One or more variable sizes violate format constraints"; |
---|
163 | case NC_EDIMSIZE: |
---|
164 | return "NetCDF: Invalid dimension size"; |
---|
165 | case NC_ETRUNC: |
---|
166 | return "NetCDF: File likely truncated or possibly corrupted"; |
---|
167 | case NC_EAXISTYPE: |
---|
168 | return "NetCDF: Illegal axis type"; |
---|
169 | case NC_EDAP: |
---|
170 | return "NetCDF: DAP failure"; |
---|
171 | case NC_ECURL: |
---|
172 | return "NetCDF: libcurl failure"; |
---|
173 | case NC_EIO: |
---|
174 | return "NetCDF: I/O failure"; |
---|
175 | case NC_ENODATA: |
---|
176 | return "NetCDF: Variable has no data in DAP request"; |
---|
177 | case NC_EDAPSVC: |
---|
178 | return "NetCDF: DAP server error"; |
---|
179 | case NC_EDAS: |
---|
180 | return "NetCDF: Malformed or inaccessible DAP DAS"; |
---|
181 | case NC_EDDS: |
---|
182 | return "NetCDF: Malformed or inaccessible DAP DDS"; |
---|
183 | case NC_EDATADDS: |
---|
184 | return "NetCDF: Malformed or inaccessible DAP DATADDS"; |
---|
185 | case NC_EDAPURL: |
---|
186 | return "NetCDF: Malformed URL"; |
---|
187 | case NC_EDAPCONSTRAINT: |
---|
188 | return "NetCDF: Malformed Constraint"; |
---|
189 | case NC_ETRANSLATION: |
---|
190 | return "NetCDF: Untranslatable construct"; |
---|
191 | case NC_EHDFERR: |
---|
192 | return "NetCDF: HDF error"; |
---|
193 | case NC_ECANTREAD: |
---|
194 | return "NetCDF: Can't read file"; |
---|
195 | case NC_ECANTWRITE: |
---|
196 | return "NetCDF: Can't write file"; |
---|
197 | case NC_ECANTCREATE: |
---|
198 | return "NetCDF: Can't create file"; |
---|
199 | case NC_EFILEMETA: |
---|
200 | return "NetCDF: Can't add HDF5 file metadata"; |
---|
201 | case NC_EDIMMETA: |
---|
202 | return "NetCDF: Can't define dimensional metadata"; |
---|
203 | case NC_EATTMETA: |
---|
204 | return "NetCDF: Can't open HDF5 attribute"; |
---|
205 | case NC_EVARMETA: |
---|
206 | return "NetCDF: Problem with variable metadata."; |
---|
207 | case NC_ENOCOMPOUND: |
---|
208 | return "NetCDF: Can't create HDF5 compound type"; |
---|
209 | case NC_EATTEXISTS: |
---|
210 | return "NetCDF: Attempt to create attribute that alread exists"; |
---|
211 | case NC_ENOTNC4: |
---|
212 | return "NetCDF: Attempting netcdf-4 operation on netcdf-3 file"; |
---|
213 | case NC_ESTRICTNC3: |
---|
214 | return "NetCDF: Attempting netcdf-4 operation on strict nc3 netcdf-4 file"; |
---|
215 | case NC_ENOTNC3: |
---|
216 | return "NetCDF: Attempting netcdf-3 operation on netcdf-4 file"; |
---|
217 | case NC_ENOPAR: |
---|
218 | return "NetCDF: Parallel operation on file opened for non-parallel access"; |
---|
219 | case NC_EPARINIT: |
---|
220 | return "NetCDF: Error initializing for parallel access"; |
---|
221 | case NC_EBADGRPID: |
---|
222 | return "NetCDF: Bad group ID"; |
---|
223 | case NC_EBADTYPID: |
---|
224 | return "NetCDF: Bad type ID"; |
---|
225 | case NC_ETYPDEFINED: |
---|
226 | return "NetCDF: Type has already been defined and may not be edited"; |
---|
227 | case NC_EBADFIELD: |
---|
228 | return "NetCDF: Bad field ID"; |
---|
229 | case NC_EBADCLASS: |
---|
230 | return "NetCDF: Bad class"; |
---|
231 | case NC_EMAPTYPE: |
---|
232 | return "NetCDF: Mapped access for atomic types only"; |
---|
233 | case NC_ELATEFILL: |
---|
234 | return "NetCDF: Attempt to define fill value when data already exists."; |
---|
235 | case NC_ELATEDEF: |
---|
236 | return "NetCDF: Attempt to define var properties, like deflate, after enddef."; |
---|
237 | case NC_EDIMSCALE: |
---|
238 | return "NetCDF: Probem with HDF5 dimscales."; |
---|
239 | case NC_ENOGRP: |
---|
240 | return "NetCDF: No group found."; |
---|
241 | case NC_ESTORAGE: |
---|
242 | return "NetCDF: Cannot specify both contiguous and chunking."; |
---|
243 | case NC_EBADCHUNK: |
---|
244 | return "NetCDF: Bad chunk sizes."; |
---|
245 | case NC_ENOTBUILT: |
---|
246 | return "NetCDF: Attempt to use feature that was not turned on " |
---|
247 | "when netCDF was built."; |
---|
248 | case NC_EDISKLESS: |
---|
249 | return "NetCDF: Error in using diskless access"; |
---|
250 | default: |
---|
251 | return "Unknown Error"; |
---|
252 | } |
---|
253 | } |
---|
254 | |
---|
255 | |
---|