25#define FILE_NAME "pres_temp_4D.nc"
29constexpr int NDIMS = 4;
30constexpr int NLVL = 2;
31constexpr int NLAT = 6;
32constexpr int NLON = 12;
33constexpr int NREC = 2;
36constexpr auto LVL_NAME =
"level";
37constexpr auto LAT_NAME =
"latitude";
38constexpr auto LON_NAME =
"longitude";
39constexpr auto REC_NAME =
"time";
40constexpr auto PRES_NAME =
"pressure";
41constexpr auto TEMP_NAME =
"temperature";
42constexpr auto MAX_ATT_LEN = 80;
44constexpr float SAMPLE_PRESSURE = 900;
45constexpr float SAMPLE_TEMP = 9.0;
46constexpr float START_LAT = 25.0;
47constexpr float START_LON = -125.0;
50string UNITS =
"units";
51string DEGREES_EAST =
"degrees_east";
52string DEGREES_NORTH =
"degrees_north";
56string PRES_UNITS =
"hPa";
57string TEMP_UNITS =
"celsius";
58string LAT_UNITS =
"degrees_north";
59string LON_UNITS =
"degrees_east";
72 float pres_out[NLVL][NLAT][NLON];
73 float temp_out[NLVL][NLAT][NLON];
79 for (
int lat = 0; lat < NLAT; lat++) {
80 lats[lat] = START_LAT + 5.f *
static_cast<float>(lat);
82 for (
int lon = 0; lon < NLON; lon++) {
83 lons[lon] = START_LON + 5.f *
static_cast<float>(lon);
86 for (
int lvl = 0; lvl < NLVL; lvl++)
87 for (
int lat = 0; lat < NLAT; lat++)
88 for (
int lon = 0; lon < NLON; lon++)
90 pres_out[lvl][lat][lon] = SAMPLE_PRESSURE +
static_cast<float>(i);
91 temp_out[lvl][lat][lon] = SAMPLE_TEMP +
static_cast<float>(i++);
103 NcDim lvlDim = test.addDim(LVL_NAME, NLVL);
104 NcDim latDim = test.addDim(LAT_NAME, NLAT);
105 NcDim lonDim = test.addDim(LON_NAME, NLON);
106 NcDim recDim = test.addDim(REC_NAME);
115 latVar.
putAtt(UNITS, DEGREES_NORTH);
116 lonVar.
putAtt(UNITS, DEGREES_EAST);
120 vector<NcDim> dimVector;
121 dimVector.push_back(recDim);
122 dimVector.push_back(lvlDim);
123 dimVector.push_back(latDim);
124 dimVector.push_back(lonDim);
125 NcVar pressVar = test.addVar(PRES_NAME,
ncFloat, dimVector);
126 NcVar tempVar = test.addVar(TEMP_NAME,
ncFloat, dimVector);
131 pressVar.
putAtt(UNITS, PRES_UNITS);
132 tempVar.
putAtt(UNITS, TEMP_UNITS);
143 vector<size_t> startp,countp;
149 countp.push_back(NLVL);
150 countp.push_back(NLAT);
151 countp.push_back(NLON);
152 for (
size_t rec = 0; rec < NREC; rec++)
155 pressVar.
putVar(startp,countp,pres_out);
156 tempVar.
putVar(startp,countp,temp_out);
168 cout<<
"FAILURE**************************\n";
169 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.