NetCDF-C++
4.3.2
Toggle main menu visibility
Loading...
Searching...
No Matches
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 << e.what() << endl;
40
return
EXIT_FAILURE;
41
}
42
}
netCDF::NcFile
Class represents a netCDF root group.
Definition
ncFile.h:19
netCDF::NcFile::replace
@ replace
Create new file, even if already exists.
Definition
ncFile.h:26
netCDF::NcGroup
Class represents a netCDF group.
Definition
ncGroup.h:26
netCDF::NcVar
Class represents a netCDF variable.
Definition
ncVar.h:34
netCDF::exceptions::NcException
Base object is thrown if a netCDF exception is encountered.
Definition
ncException.h:24
netCDF::exceptions
Exception classes.
Definition
ncException.h:16
netCDF
C++ API for netCDF4.
Definition
ncAtt.h:10
netCDF::ncByte
NcByte ncByte
A global instance of the NcByte class within the netCDF namespace.
Definition
ncByte.cpp:7
Return to the Main Unidata NetCDF page.
Generated on
for NetCDF-C++. NetCDF is a
Unidata
library.