NetCDF4 C++ API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Test_NcVarMetaCF.cpp

Test of class NcVarMetaCF.

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#include <iostream>
using std::cout;
using std::endl;
#include "netcdf4"
char const * const ncFileName = "Test_NcVarMetaCF.nc";
//-----------------------------------------------------------------------------
template< typename TNumeric >
void Fill (MetadataCFVariable<TNumeric> & meta)
{
meta.longName = "count of data";
meta.standardName = "data count";
meta.units = "frequency";
meta.validMin = 0;
meta.validMax = 100;
meta.fillValue = 0;
meta.encoding = "ASCII";
}
//-----------------------------------------------------------------------------
int main ()
{
cout << "Test of class NcVarMetaCF." << endl;
try
{
// create the file and add a dimension and a variable
cout << "Creating netCDF file: " << ncFileName << endl;
netcdf::NcDim ncDim = ncFile.AddDim( "record" );
netcdf::NcVar ncVar = ncFile.AddVar ( "data", netcdf::NcInt(), ncDim );
MetadataCFVariable<short> metadata1;
Fill( metadata1 );
cout << metadata1 << endl;
// write metadata for variable
cout << "Test writing metadata for variable" << endl;
NcVarMetaCF metaVar (ncVar);
metaVar << metadata1;
// read metadata for variable
cout << "Test reading metadata for variable:" << endl;
MetadataCFVariable<short> metadata2;
metaVar >> metadata2;
cout << metadata2 << endl;
// test equality
cout << "metadata1 == metadata2 ? "
<< ( metadata1 == metadata2 ? "true" : "false" )
<< endl;
}
catch (std::exception const & e)
{
cout << "Exception: " << e.what() << endl;
}
catch (...)
{
cout << "Error: unknown error." << endl;
}
cout << "\n all done!" << endl;
return 0;
}
//-----------------------------------------------------------------------------