File: ncCheck.cpp

package info (click to toggle)
netcdf-cxx 4.3.1-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,456 kB
  • sloc: cpp: 8,506; sh: 4,548; ansic: 4,251; xml: 173; makefile: 145
file content (94 lines) | stat: -rw-r--r-- 4,337 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <cstring>
#include "netcdf.h"
#include <ncException.h>
using namespace std;
using namespace netCDF::exceptions;

//  C++ API for netCDF4.
namespace netCDF
{
  // function checks error code and if necessary throws appropriate exception.
  void ncCheck(int retCode, const char* file, int line){
    if (retCode==NC_NOERR)
      return;

    const char* msg = 0;
    if (NC_ISSYSERR(retCode)){
      msg = std::strerror(retCode);
      msg = msg ? msg : "Unknown system error";
    }else{
      msg = nc_strerror(retCode);
    }

    switch(retCode) {
    case NC_EBADID          : throw NcBadId(msg,file,line);
    case NC_ENFILE          : throw NcNFile(msg,file,line);
    case NC_EEXIST          : throw NcExist(msg,file,line);
    case NC_EINVAL          : throw NcInvalidArg(msg,file,line);
    case NC_EPERM           : throw NcInvalidWrite(msg,file,line);
    case NC_ENOTINDEFINE    : throw NcNotInDefineMode(msg,file,line);
    case NC_EINDEFINE       : throw NcInDefineMode(msg,file,line);
    case NC_EINVALCOORDS    : throw NcInvalidCoords(msg,file,line);
    case NC_EMAXDIMS        : throw NcMaxDims(msg,file,line);
    case NC_ENAMEINUSE      : throw NcNameInUse(msg,file,line);
    case NC_ENOTATT         : throw NcNotAtt(msg,file,line);
    case NC_EMAXATTS        : throw NcMaxAtts(msg,file,line);
    case NC_EBADTYPE        : throw NcBadType(msg,file,line);
    case NC_EBADDIM         : throw NcBadDim(msg,file,line);
    case NC_EUNLIMPOS       : throw NcUnlimPos(msg,file,line);
    case NC_EMAXVARS        : throw NcMaxVars(msg,file,line);
    case NC_ENOTVAR         : throw NcNotVar(msg,file,line);
    case NC_EGLOBAL         : throw NcGlobal(msg,file,line);
    case NC_ENOTNC          : throw NcNotNCF(msg,file,line);
    case NC_ESTS            : throw NcSts(msg,file,line);
    case NC_EMAXNAME        : throw NcMaxName(msg,file,line);
    case NC_EUNLIMIT        : throw NcUnlimit(msg,file,line);
    case NC_ENORECVARS      : throw NcNoRecVars(msg,file,line);
    case NC_ECHAR           : throw NcChar(msg,file,line);
    case NC_EEDGE           : throw NcEdge(msg,file,line);
    case NC_ESTRIDE         : throw NcStride(msg,file,line);
    case NC_EBADNAME        : throw NcBadName(msg,file,line);
    case NC_ERANGE          : throw NcRange(msg,file,line);
    case NC_ENOMEM          : throw NcNoMem(msg,file,line);
    case NC_EVARSIZE        : throw NcVarSize(msg,file,line);
    case NC_EDIMSIZE        : throw NcDimSize(msg,file,line);
    case NC_ETRUNC          : throw NcTrunc(msg,file,line);

      // The following are specific netCDF4 errors.
    case NC_EHDFERR         : throw NcHdfErr(msg,file,line);
    case NC_ECANTREAD       : throw NcCantRead(msg,file,line);
    case NC_ECANTWRITE      : throw NcCantWrite(msg,file,line);
    case NC_ECANTCREATE     : throw NcCantCreate(msg,file,line);
    case NC_EFILEMETA       : throw NcFileMeta(msg,file,line);
    case NC_EDIMMETA        : throw NcDimMeta(msg,file,line);
    case NC_EATTMETA        : throw NcAttMeta(msg,file,line);
    case NC_EVARMETA        : throw NcVarMeta(msg,file,line);
    case NC_ENOCOMPOUND     : throw NcNoCompound(msg,file,line);
    case NC_EATTEXISTS      : throw NcAttExists(msg,file,line);
    case NC_ENOTNC4         : throw NcNotNc4(msg,file,line);
    case NC_ESTRICTNC3      : throw NcStrictNc3(msg,file,line);
    case NC_EBADGRPID       : throw NcBadGroupId(msg,file,line);
    case NC_EBADTYPID       : throw NcBadTypeId(msg,file,line);                       // netcdf.h file inconsistent with documentation!!
    case NC_EBADFIELD       : throw NcBadFieldId(msg,file,line);                     // netcdf.h file inconsistent with documentation!!
      //  case NC_EUNKNAME        : throw NcUnkownName("Cannot find the field id.",file,line);   // netcdf.h file inconsistent with documentation!!

    case NC_ENOGRP          : throw NcEnoGrp(msg,file,line);
    case NC_ELATEDEF        : throw NcElateDef(msg,file,line);

    default:
      throw NcException(retCode, msg, file, line);
    }
  }

  void ncCheckDefineMode(int ncid)
  {
    int status = nc_redef(ncid);
    if (status != NC_EINDEFINE) ncCheck(status, __FILE__, __LINE__);
  }

  void ncCheckDataMode(int ncid)
  {
    int status = nc_enddef(ncid);
    if (status != NC_ENOTINDEFINE) ncCheck(status, __FILE__, __LINE__);
  }
}