本文整理汇总了C++中NcVar::putRec方法的典型用法代码示例。如果您正苦于以下问题:C++ NcVar::putRec方法的具体用法?C++ NcVar::putRec怎么用?C++ NcVar::putRec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NcVar
的用法示例。
在下文中一共展示了NcVar::putRec方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testExamples
//.........这里部分代码省略.........
// Return this code to the OS in case of failure.
#define NC_ERR 2
// We will write latitude and longitude fields.
float lats[NLAT],lons[NLON];
// Program variables to hold the data we will write out. We will
// only need enough space to hold one timestep of data; one record.
float pres_out[NLVL][NLAT][NLON];
float temp_out[NLVL][NLAT][NLON];
int i=0; //used in the data generation loop
// create some pretend data. If this wasn't an example program, we
// would have some real data to write for example, model output.
for (int lat = 0; lat < NLAT; lat++)
lats[lat] = START_LAT + 5. * lat;
for (int lon = 0; lon < NLON; lon++)
lons[lon] = START_LON + 5. * lon;
for (int lvl = 0; lvl < NLVL; lvl++)
for (int lat = 0; lat < NLAT; lat++)
for (int lon = 0; lon < NLON; lon++)
{
pres_out[lvl][lat][lon] = SAMPLE_PRESSURE + i;
temp_out[lvl][lat][lon] = SAMPLE_TEMP + i++;
}
try
{
// Create the file.
NcFile test(FILE_NAME, NcFile::Replace);
// Define the dimensions. NetCDF will hand back an ncDim object for
// each.
NcDim* lvlDim = test.addDim(LVL_NAME, NLVL);
NcDim* latDim = test.addDim(LAT_NAME, NLAT);
NcDim* lonDim = test.addDim(LON_NAME, NLON);
NcDim* recDim = test.addDim(REC_NAME); //adds an unlimited dimension
// Define the coordinate variables.
NcVar* latVar = test.addVar(LAT_NAME, ncFloat, latDim);
NcVar* lonVar = test.addVar(LON_NAME, ncFloat, lonDim);
// Define units attributes for coordinate vars. This attaches a
// text attribute to each of the coordinate variables, containing
// the units.
latVar->addAtt(UNITS,ncChar, DEGREES_NORTH);
lonVar->addAtt(UNITS,ncChar, DEGREES_EAST);
// Define the netCDF variables for the pressure and temperature
// data.
NcVar* pressVar = test.addVar(PRES_NAME, ncFloat, recDim, lvlDim,
latDim, lonDim);
NcVar* tempVar = test.addVar(TEMP_NAME, ncFloat, recDim, lvlDim,
latDim, lonDim);
// Define units attributes for coordinate vars. This attaches a
// text attribute to each of the coordinate variables, containing
// the units.
pressVar->addAtt(UNITS,ncChar, PRES_UNITS);
tempVar->addAtt(UNITS,ncChar ,TEMP_UNITS);
// Write the coordinate variable data to the file.
latVar->put(lats, NLAT);
lonVar->put(lons, NLON);
// Write the pretend data. This will write our surface pressure and
// surface temperature data. The arrays only hold one timestep
// worth of data. We will just rewrite the same data for each
// timestep. In a real application, the data would change between
// timesteps.
for (int rec = 0; rec < NREC; rec++)
{
pressVar->putRec(&pres_out[0][0][0], rec);
tempVar->putRec(&temp_out[0][0][0], rec);
}
//NcValues * pressVals = pressVar->getValues();
//pressVals->print(cout);
// The file is automatically closed by the destructor. This frees
// up any internal netCDF resources associated with the file, and
// flushes any buffers.
cout << "*** SUCCESS writing example file " << FILE_NAME << "!" << endl;
}
catch(NcException e)
{
e.what();
return 1;
}
return 0;
}