NetCDF-C++ 4.3.2
Loading...
Searching...
No Matches
ncCheck.cpp
1#include <cstring>
2#include "netcdf.h"
3#include <ncException.h>
4using namespace std;
5using namespace netCDF::exceptions;
6
7// C++ API for netCDF4.
8namespace netCDF
9{
10 // function checks error code and if necessary throws appropriate exception.
11 void ncCheck(int retCode, const char* file, int line){
12 if (retCode==NC_NOERR)
13 return;
14
15 const char* msg = 0;
16 if (NC_ISSYSERR(retCode)){
17 msg = std::strerror(retCode);
18 msg = msg ? msg : "Unknown system error";
19 }else{
20 msg = nc_strerror(retCode);
21 }
22
23 switch(retCode) {
24 case NC_EBADID : throw NcBadId(msg,file,line);
25 case NC_ENFILE : throw NcNFile(msg,file,line);
26 case NC_EEXIST : throw NcExist(msg,file,line);
27 case NC_EINVAL : throw NcInvalidArg(msg,file,line);
28 case NC_EPERM : throw NcInvalidWrite(msg,file,line);
29 case NC_ENOTINDEFINE : throw NcNotInDefineMode(msg,file,line);
30 case NC_EINDEFINE : throw NcInDefineMode(msg,file,line);
31 case NC_EINVALCOORDS : throw NcInvalidCoords(msg,file,line);
32 case NC_EMAXDIMS : throw NcMaxDims(msg,file,line);
33 case NC_ENAMEINUSE : throw NcNameInUse(msg,file,line);
34 case NC_ENOTATT : throw NcNotAtt(msg,file,line);
35 case NC_EMAXATTS : throw NcMaxAtts(msg,file,line);
36 case NC_EBADTYPE : throw NcBadType(msg,file,line);
37 case NC_EBADDIM : throw NcBadDim(msg,file,line);
38 case NC_EUNLIMPOS : throw NcUnlimPos(msg,file,line);
39 case NC_EMAXVARS : throw NcMaxVars(msg,file,line);
40 case NC_ENOTVAR : throw NcNotVar(msg,file,line);
41 case NC_EGLOBAL : throw NcGlobal(msg,file,line);
42 case NC_ENOTNC : throw NcNotNCF(msg,file,line);
43 case NC_ESTS : throw NcSts(msg,file,line);
44 case NC_EMAXNAME : throw NcMaxName(msg,file,line);
45 case NC_EUNLIMIT : throw NcUnlimit(msg,file,line);
46 case NC_ENORECVARS : throw NcNoRecVars(msg,file,line);
47 case NC_ECHAR : throw NcChar(msg,file,line);
48 case NC_EEDGE : throw NcEdge(msg,file,line);
49 case NC_ESTRIDE : throw NcStride(msg,file,line);
50 case NC_EBADNAME : throw NcBadName(msg,file,line);
51 case NC_ERANGE : throw NcRange(msg,file,line);
52 case NC_ENOMEM : throw NcNoMem(msg,file,line);
53 case NC_EVARSIZE : throw NcVarSize(msg,file,line);
54 case NC_EDIMSIZE : throw NcDimSize(msg,file,line);
55 case NC_ETRUNC : throw NcTrunc(msg,file,line);
56
57 // The following are specific netCDF4 errors.
58 case NC_EHDFERR : throw NcHdfErr(msg,file,line);
59 case NC_ECANTREAD : throw NcCantRead(msg,file,line);
60 case NC_ECANTWRITE : throw NcCantWrite(msg,file,line);
61 case NC_ECANTCREATE : throw NcCantCreate(msg,file,line);
62 case NC_EFILEMETA : throw NcFileMeta(msg,file,line);
63 case NC_EDIMMETA : throw NcDimMeta(msg,file,line);
64 case NC_EATTMETA : throw NcAttMeta(msg,file,line);
65 case NC_EVARMETA : throw NcVarMeta(msg,file,line);
66 case NC_ENOCOMPOUND : throw NcNoCompound(msg,file,line);
67 case NC_EATTEXISTS : throw NcAttExists(msg,file,line);
68 case NC_ENOTNC4 : throw NcNotNc4(msg,file,line);
69 case NC_ESTRICTNC3 : throw NcStrictNc3(msg,file,line);
70 case NC_EBADGRPID : throw NcBadGroupId(msg,file,line);
71 case NC_EBADTYPID : throw NcBadTypeId(msg,file,line); // netcdf.h file inconsistent with documentation!!
72 case NC_EBADFIELD : throw NcBadFieldId(msg,file,line); // netcdf.h file inconsistent with documentation!!
73 // case NC_EUNKNAME : throw NcUnkownName("Cannot find the field id.",file,line); // netcdf.h file inconsistent with documentation!!
74
75 case NC_ENOGRP : throw NcEnoGrp(msg,file,line);
76 case NC_ELATEDEF : throw NcElateDef(msg,file,line);
77
78 default:
79 throw NcException(retCode, msg, file, line);
80 }
81 }
82
83 void ncCheckDefineMode(int ncid)
84 {
85 int status = nc_redef(ncid);
86 if (status != NC_EINDEFINE) ncCheck(status, __FILE__, __LINE__);
87 }
88
89 void ncCheckDataMode(int ncid)
90 {
91 int status = nc_enddef(ncid);
92 if (status != NC_ENOTINDEFINE) ncCheck(status, __FILE__, __LINE__);
93 }
94}
NcChar()
Constructor.
Definition ncChar.cpp:11
Thrown if attribute exists.
Thrown if attribute meta.
Thrown if an invalid dimension id or name.
Thrown if bad field id.
Thrown if bad group id.
Thrown if the specified netCDF ID does not refer to an open netCDF dataset.
Definition ncException.h:42
Thrown if attribute or variable name contains illegal characters.
Thrown if bad type id.
Thrown if not a valid netCDF data type.
Thrown if cannot create.
Thrown if cannot read.
Thrown if cannot write.
Thrown if invalid dimension size.
Thrown if edge+start exceeds dimension bound.
Thrown if an operation to set the chunking, endianness, fill of a NcVar object is issued after a call...
Thrown if cannot return a netCDF group.
Base object is thrown if a netCDF exception is encountered.
Definition ncException.h:24
Thrown if, having set NC_NOCLOBBER, the specified dataset already exists.
Definition ncException.h:56
Thrown if the action is prohibited on the NC_GLOBAL varid.
Thrown if an error was reported by the HDF5 layer.
Thrown if operation not allowed in defined mode.
Definition ncException.h:84
Thrown if not a netCDF id.
Definition ncException.h:63
Index exceeds dimension bound.
Definition ncException.h:97
Thrown if invalid argument.
Definition ncException.h:70
Thrown if Nc_MAX_ATTRS is exceeded.
Thrown if NC_MAX_DIMS is exceeded.
Thrown if NC_MAX_NAME is exceeded.
Thrown if NC_MAX_VARS is exceeded.
Thrown if too many netcdf files are open.
Definition ncException.h:49
Thrown if string match to name is in use.
Thrown if no compound.
Thrown if memory allocation (malloc) failure.
Thrown if nc_rec op when there are no record vars.
Thrown if attribute is not found.
Thrown if operation not allowed in data mode.
Definition ncException.h:77
Thrown if not a netCDF file.
Thrown if attempting netcdf-4 operation on netcdf-3 file.
Thrown if variable is not found.
Thrown if math result not representable.
Thrown if attempting netcdf-4 operation on strict nc3 netcdf-4 file.
Thrown if illegal stride.
Thrown if in FORTRAN, string is too short.
Thrown if file likely truncated or possibly corrupted.
Thrown if Nc_UNLIMITED is in the wrong index.
Thrown if NC_UNLIMITED size is already in use.
Thrown if variable meta.
Thrown if one or more variable sizes violate format constraints.
Exception classes.
Definition ncException.h:16
C++ API for netCDF4.
Definition ncAtt.h:10
void ncCheckDataMode(int ncid)
Function checks if the file (group) is in data mode.
Definition ncCheck.cpp:89
void ncCheckDefineMode(int ncid)
Function checks if the file (group) is in define mode.
Definition ncCheck.cpp:83
void ncCheck(int retCode, const char *file, int line)
Function checks error code and if necessary throws an exception.
Definition ncCheck.cpp:11

Return to the Main Unidata NetCDF page.
Generated on for NetCDF-C++. NetCDF is a Unidata library.