2007 Unidata NetCDF Workshop for Developers and Data Providers > NetCDF APIs
5.3 The C++ API
The C++ library provided the first object-oriented API for netCDF.
Strengths
- Object-oriented interface
- Fairly well documented: Users Guide is complete and up-to-date.
- Type safety: better than the C interface.
- Less code than an equivalent C program, and it's object-oriented.
- Short argument lists, because there are no IDs for variables,
dimensions, or attributes.
- Easier memory management, because space for blocks of data is allocated
by the library.
- Hides "define mode", so no calls are needed to enter or leave
define mode for changing the schema of a netCDF file (adding
variables, dimensions, or attributes).
Other Characteristics
- Implemented as a thin layer on top of C library
- Showing its age: written before C++ standards for templates,
exceptions, and namespaces
- Student updating the C++ interface for netCDF-4 this summer
- No garbage collection: you have to delete blocks of data and
NcAtt objects (attributes) allocated by the library when done with them.
- Less tested than C, Fortran, and Java interfaces.
- No ncgen support: ncgen cannot (yet) generate any C++ code.
- Not used in other Unidata libraries or applications.
- Old-fashioned error handling: no C++ Exceptions are used, so need to check
return status from method calls and use an is_valid() method to
determine if constructors failed.
- Because "define mode" is
hidden by the interface, you may not be aware of inefficiencies when you are
changing the schema.
Examples
Annotated examples of complete C++ netCDF programs are available from
the program examples page.
2007 Unidata NetCDF Workshop for Developers and Data Providers > NetCDF APIs