26#define FILE_NAME "sfc_pres_temp.nc"
30static const int NDIMS = 2;
31static const int NLAT = 6;
32static const int NLON = 12;
35string PRES_NAME =
"pressure";
36string TEMP_NAME =
"temperature";
37string UNITS =
"units";
38string DEGREES_EAST =
"degrees_east";
39string DEGREES_NORTH =
"degrees_north";
40string LAT_NAME =
"latitude";
41string LON_NAME =
"longitude";
44constexpr float SAMPLE_PRESSURE = 900;
45constexpr float SAMPLE_TEMP = 9.0;
46constexpr float START_LAT = 25.0;
47constexpr float 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.f*
static_cast<float>(lat);
69 for(
int lon = 0; lon < NLON; lon++) {
70 lons[lon] = START_LON + 5.f*
static_cast<float>(lon);
76 for (
int lat = 0; lat < NLAT; lat++)
77 for(
int lon = 0;lon < NLON; lon++)
79 presOut[lat][lon] = SAMPLE_PRESSURE +
static_cast<float>(lon * NLAT + lat);
80 tempOut[lat][lon] = SAMPLE_TEMP + .25f *
static_cast<float>(lon * NLAT +lat);
92 NcDim latDim = sfc.addDim(LAT_NAME, NLAT);
93 NcDim lonDim = sfc.addDim(LON_NAME, NLON);
114 lonVar.
putAtt(UNITS,DEGREES_EAST);
115 latVar.
putAtt(UNITS,DEGREES_NORTH);
119 dims.push_back(latDim);
120 dims.push_back(lonDim);
125 presVar.
putAtt(UNITS,
"hPa");
126 tempVar.
putAtt(UNITS,
"celsius");
143 cout<<
"FAILURE**************************\n";
144 cout << e.what() << endl;
Class represents a netCDF dimension.
Class represents a netCDF root group.
@ replace
Create new file, even if already exists.
Class represents a netCDF variable.
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...
void putVar(const void *dataValues) const
This is an overloaded member function, provided for convenience.
Base object is thrown if a netCDF exception is encountered.
NcFloat ncFloat
A global instance of the NcFloat class within the netCDF namespace.