NetCDF-C++  4.3.1-developer
example1.cpp
1 #include <iostream>
2 #include <iomanip>
3 #include <netcdf>
4 using namespace std;
5 using namespace netCDF;
6 using namespace netCDF::exceptions;
7 
8 
9 int main()
10 {
11 try
12  {
13  cout<<"Opening file \"firstFile.cdf\" with NcFile::replace"<<endl;
14  NcFile ncFile("firstFile.cdf",NcFile::replace);
15 
16  cout<<left<<setw(50)<<"Testing addGroup(\"groupName\")";
17  NcGroup groupA(ncFile.addGroup("groupA"));
18  NcGroup groupA0(ncFile.addGroup("groupA0"));
19  NcGroup groupB(groupA.addGroup("groupB"));
20  NcGroup groupC(groupA.addGroup("groupC"));
21 
22  cout <<left<<setw(50)<<"Number of groups in the top-level group is" << ncFile.getGroupCount() <<endl;
23 
24  // create two dimensions
25  ncFile.addDim("dim1",11);
26  ncFile.addDim("dim2");
27 
28  // create a variable
29  NcVar var1 = ncFile.addVar("varA",ncByte,"dim1");
30 
31  // create another variable
32  vector<string> stringArray(2);
33  stringArray[0] = "dim1";
34  stringArray[1] = "dim2";
35  NcVar var2 = ncFile.addVar("varB",ncByte,stringArray);
36  }
37  catch (NcException& e)
38  {
39  cout << "unknown error"<<endl;
40  e.what();
41  }
42 }
C++ API for netCDF4.
Definition: ncAtt.h:9
Class represents a netCDF group.
Definition: ncGroup.h:27
int getGroupCount(NcGroup::GroupLocation location=ChildrenGrps) const
Gets the number of NcGroup objects.
Definition: ncGroup.cpp:147
Exception classes.
Definition: ncException.h:15
Base object is thrown if a netCDF exception is encountered.
Definition: ncException.h:24
Class represents a netCDF variable.
Definition: ncVar.h:33
Class represents a netCDF root group.
Definition: ncFile.h:18

Return to the Main Unidata NetCDF page.
Generated on Fri Nov 11 2016 15:28:29 for NetCDF-C++. NetCDF is a Unidata library.