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

Test of class NcFileMetaCF.

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#include <iostream>
using std::cout;
using std::endl;
#include "netcdf4"
char const * const ncFileName = "Test_NcFileMetaCF.nc";
//-----------------------------------------------------------------------------
void Fill (MetadataCFGlobal & meta)
{
meta.title = "data for title";
meta.institution = "data for institution";
meta.contact = "data for contact";
meta.copyright = "data for copyright";
meta.conventions = "data for conventions";
meta.references = "data for references";
meta.source = "data for source";
meta.comment = "data for comment";
meta.history = "data for history";
}
//-----------------------------------------------------------------------------
int main ()
{
cout << "Test of class NcFileMetaCF." << 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 );
MetadataCFGlobal metadata1;
Fill( metadata1 );
cout << metadata1 << endl;
// write metadata for variable
cout << "Test writing global metadata:" << endl;
NcFileMetaCF metaFile (ncFile);
metaFile << metadata1;
// read metadata for variable
cout << "Test reading global metadata:" << endl;
MetadataCFGlobal metadata2;
metaFile >> 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;
}
//-----------------------------------------------------------------------------