NetCDF-C++ 4.3.1
example1.cpp
1#include <iostream>
2#include <iomanip>
3#include <netcdf>
4using namespace std;
5using namespace netCDF;
6using namespace netCDF::exceptions;
7
8
9int main()
10{
11try
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}
Class represents a netCDF root group.
Definition: ncFile.h:19
Class represents a netCDF group.
Definition: ncGroup.h:28
Class represents a netCDF variable.
Definition: ncVar.h:34
Base object is thrown if a netCDF exception is encountered.
Definition: ncException.h:24
Exception classes.
Definition: ncException.h:16
C++ API for netCDF4.
Definition: ncAtt.h:10

Return to the Main Unidata NetCDF page.
Generated on Wed Nov 10 2021 15:25:08 for NetCDF-C++. NetCDF is a Unidata library.