File: example1.cpp

package info (click to toggle)
netcdf-cxx 4.3.1-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,456 kB
  • sloc: cpp: 8,506; sh: 4,548; ansic: 4,251; xml: 173; makefile: 145
file content (42 lines) | stat: -rw-r--r-- 1,087 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <iomanip>
#include <netcdf>
using namespace std;
using namespace netCDF;
using namespace netCDF::exceptions;


int main()
{
try
  {
    cout<<"Opening file \"firstFile.cdf\" with NcFile::replace"<<endl;
    NcFile ncFile("firstFile.cdf",NcFile::replace);

    cout<<left<<setw(50)<<"Testing addGroup(\"groupName\")";
    NcGroup groupA(ncFile.addGroup("groupA"));
    NcGroup groupA0(ncFile.addGroup("groupA0"));
    NcGroup groupB(groupA.addGroup("groupB"));
    NcGroup groupC(groupA.addGroup("groupC"));

    cout <<left<<setw(50)<<"Number of groups in the top-level group is" << ncFile.getGroupCount() <<endl;

    // create two dimensions
    ncFile.addDim("dim1",11);
    ncFile.addDim("dim2");

    // create a variable
    NcVar var1  = ncFile.addVar("varA",ncByte,"dim1");

    // create another variable
    vector<string> stringArray(2);
    stringArray[0] = "dim1";
    stringArray[1] = "dim2";
    NcVar var2  = ncFile.addVar("varB",ncByte,stringArray);
  }
 catch (NcException& e)
   {
     cout << "unknown error"<<endl;
     e.what();
   }
}