27static const int NLVL = 2;
 
   28static const int NLAT = 6;
 
   29static const int NLON = 12;
 
   30static const int NREC = 2;
 
   33static const float SAMPLE_PRESSURE = 900.0;
 
   34static const float SAMPLE_TEMP = 9.0;
 
   35static const float START_LAT = 25.0;
 
   36static const float START_LON = -125.0; 
 
   40static const int NC_ERR = 2;
 
   45   float lats[NLAT], lons[NLON];
 
   49   float pres_in[NLVL][NLAT][NLON];
 
   50   float temp_in[NLVL][NLAT][NLON];
 
   55     NcFile dataFile(
"pres_temp_4D.nc", NcFile::read);
 
   59   latVar = dataFile.
getVar(
"latitude");
 
   60   if(latVar.
isNull()) 
return NC_ERR;
 
   61   lonVar = dataFile.
getVar(
"longitude");
 
   62   if(lonVar.
isNull()) 
return NC_ERR;
 
   67   for (
int lat = 0; lat < NLAT; lat++)
 
   68       if (lats[lat] != START_LAT + 5. * lat)
 
   71   for (
int lon = 0; lon < NLON; lon++)
 
   72      if (lons[lon] != START_LON + 5. * lon)
 
   76   NcVar presVar, tempVar;
 
   77   presVar = dataFile.
getVar(
"pressure");
 
   78   if(presVar.
isNull()) 
return NC_ERR;
 
   79   tempVar = dataFile.
getVar(
"temperature");
 
   80   if(tempVar.
isNull()) 
return NC_ERR;
 
   82   vector<size_t> startp,countp;
 
   88   countp.push_back(NLVL);
 
   89   countp.push_back(NLAT);
 
   90   countp.push_back(NLON);
 
   91   for (
size_t rec = 0; rec < NREC; rec++)
 
   95     presVar.
getVar(startp,countp,pres_in);
 
   96     tempVar.
getVar(startp,countp,temp_in);
 
   99     for (
int lvl = 0; lvl < NLVL; lvl++)
 
  100       for (
int lat = 0; lat < NLAT; lat++)
 
  101     for (
int lon = 0; lon < NLON; lon++)
 
  103         if(pres_in[lvl][lat][lon] != (
float) (SAMPLE_PRESSURE + i)) 
return NC_ERR;
 
  104         if(temp_in[lvl][lat][lon] != (
float)(SAMPLE_TEMP + i++)) 
return NC_ERR;
 
  120      cout<<
"FAILURE**************************"<<endl;
 
Class represents a netCDF root group.
Class represents a netCDF variable.
void getVar(void *dataValues) const
This is an overloaded member function, provided for convenience.
bool isNull() const
Returns true if this object variable is not defined.
Base object is thrown if a netCDF exception is encountered.