26 #define FILE_NAME "sfc_pres_temp.nc" 30 static const int NDIMS = 2;
31 static const int NLAT = 6;
32 static const int NLON = 12;
35 string PRES_NAME =
"pressure";
36 string TEMP_NAME =
"temperature";
37 string UNITS =
"units";
38 string DEGREES_EAST =
"degrees_east";
39 string DEGREES_NORTH =
"degrees_north";
40 string LAT_NAME =
"latitude";
41 string LON_NAME =
"longitude";
44 #define SAMPLE_PRESSURE 900 45 #define SAMPLE_TEMP 9.0 46 #define START_LAT 25.0 47 #define START_LON -125.0 55 float presOut[NLAT][NLON];
56 float tempOut[NLAT][NLON];
65 for(
int lat = 0;lat < NLAT; lat++)
66 lats[lat] = START_LAT + 5.*lat;
68 for(
int lon = 0; lon < NLON; lon++)
69 lons[lon] = START_LON + 5.*lon;
74 for (
int lat = 0; lat < NLAT; lat++)
75 for(
int lon = 0;lon < NLON; lon++)
77 presOut[lat][lon] = SAMPLE_PRESSURE + (lon * NLAT + lat);
78 tempOut[lat][lon] = SAMPLE_TEMP + .25 * (lon * NLAT +lat);
86 NcFile sfc(FILE_NAME, NcFile::replace);
90 NcDim latDim = sfc.addDim(LAT_NAME, NLAT);
91 NcDim lonDim = sfc.addDim(LON_NAME, NLON);
97 NcVar latVar = sfc.addVar(LAT_NAME, ncFloat, latDim);
98 NcVar lonVar = sfc.addVar(LON_NAME, ncFloat, lonDim);
112 lonVar.
putAtt(UNITS,DEGREES_EAST);
113 latVar.
putAtt(UNITS,DEGREES_NORTH);
117 dims.push_back(latDim);
118 dims.push_back(lonDim);
119 NcVar presVar = sfc.addVar(PRES_NAME, ncFloat, dims);
120 NcVar tempVar = sfc.addVar(TEMP_NAME, ncFloat, dims);
123 presVar.
putAtt(UNITS,
"hPa");
124 tempVar.
putAtt(UNITS,
"celsius");
NcVarAtt putAtt(const std::string &name, size_t len, const char **dataValues) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Class represents a netCDF dimension.
Base object is thrown if a netCDF exception is encountered.
void putVar(const void *dataValues) const
This is an overloaded member function, provided for convenience.
Class represents a netCDF variable.
Class represents a netCDF root group.