本文整理汇总了C++中NcValues::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ NcValues::toString方法的具体用法?C++ NcValues::toString怎么用?C++ NcValues::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NcValues
的用法示例。
在下文中一共展示了NcValues::toString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testVar
int TestSuite::testVar()
{
try
{
string FILE_NAME = "tst_vars.nc";
int NDIMS = 4;
int NLAT = 6;
int NLON = 12;
// Names of things.
string LAT_NAME = "latitude";
string LON_NAME = "longitude";
int MAX_ATT_LEN = 80;
// These are used to construct some example data.
float START_LAT = 25.0;
float START_LON = -125.0;
string UNITS = "units";
string DEGREES_EAST = "degrees_east";
string DEGREES_NORTH = "degrees_north";
// For the units attributes.
string LAT_UNITS = "degrees_north";
string LON_UNITS = "degrees_east";
// 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];
// 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;
// Create the file.
NcFile test(FILE_NAME, NcFile::Replace);
// Define the dimensions. NetCDF will hand back an ncDim object for
// each.
NcDim* latDim = test.addDim(LAT_NAME, NLAT);
NcDim* lonDim = test.addDim(LON_NAME, NLON);
// 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,ncString, DEGREES_NORTH);
lonVar->addAtt(UNITS,ncString, DEGREES_EAST);
// Write the coordinate variable data to the file.
latVar->put(lats, NLAT);
lonVar->put(lons, NLON);
NcValues *latVals = latVar->getValues();
cout<<"toString returns lats: "<<latVals->toString()<<endl;
cout<<"toChar returns "<<latVals->toChar(1)<<endl;
cout<<"toShort returns "<<latVals->toShort(1)<<endl;
cout<<"toInt returns "<<latVals->toInt(1)<<endl;
cout<<"toLong returns "<<latVals->toLong(1)<<endl;
latVals->print(cout);
NcValues *lonVals = lonVar->getValues();
cout<<"toString returns lats: "<<lonVals->toString()<<endl;
lonVals->print(cout);
cout<<"no segmentation fault thus far"<<endl;
//test varaibles here
}
catch(NcException e)
{
e.what();
return 1;
}
try
{
cout<<"should test adding a variable with more than 5 dimensions here"<<endl;
// test creating a variable with more than 5 dimensions
}
catch (NcException e)
{
e.what();
return 1;
}
//.........这里部分代码省略.........