NetCDF4 C++ API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
netcdf::NcFile Class Reference

Manages the opening, creating, and closing of netCDF files.
Represents the netCDF root group. More...

#include <NetCDF/cpp4/src/NcFile.h>

+ Inheritance diagram for netcdf::NcFile:

Detailed Description

Class represents a netCDF root group. The Ncfile class is the same as the NcGroup class with the additional functionality for opening and closing files.

Copyright:
Original C++ API developed by Lynton Appel.
Portions of this software were developed by the Unidata Program at the
University Corporation for Atmospheric Research.
Modifications: Copyright 2013 Colorado State University. All rights reserved.
Organization:
Natural Resource Ecology Laboratory
Colorado State University, Fort Collins, CO 80523 USA
www.nrel.colostate.edu
Project:
IRC <www.nrel.colostate.edu/projects/irc/>
Author
Tom Hilinski tom.h.nosp@m.ilin.nosp@m.ski@c.nosp@m.olos.nosp@m.tate..nosp@m.edu
Date
2013Jan
Examples:
Test_AttVectors.cpp, Test_CreateFileNc3.cpp, Test_NcChar.cpp, Test_NcFileMetaCF.cpp, Test_NcString.cpp, Test_NcVarMetaCF.cpp, and Test_Parallel.cpp.

Public Types

enum  FileMode { ReadOnly, Write, Replace, New }
 
enum  FileFormat { Classic, Offset64Bits, NetCDF4, NetCDF4Classic }
 
- Public Types inherited from netcdf::NcGroup
enum  GroupLocation {
  ChildrenGrps, ParentsGrps, ChildrenOfChildrenGrps, AllChildrenGrps,
  ParentsAndCurrentGrps, AllGrps
}
 options for selecting groups (used for returned set of NcGroup objects) More...
 
enum  Location {
  Current, Parents, Children, ParentsAndCurrent,
  ChildrenAndCurrent, All
}
 options for selecting groups. More...
 
typedef std::map< std::string,
NcGroup
NcGroupMapUnique
 
typedef std::multimap
< std::string, NcGroup
NcGroupMap
 
typedef std::pair< std::string,
NcGroup
NcGroupPair
 
typedef std::set< NcGroupNcGroupSet
 
typedef std::multimap
< std::string, NcType
NcTypeMap
 
typedef std::pair< std::string,
NcType
NcTypePair
 
typedef std::set< NcTypeNcTypeSet
 
typedef std::multimap
< std::string, NcTypeUserDef
NcUserTypeMap
 
typedef std::multimap
< std::string, NcVar
NcVarMap
 
typedef std::pair< std::string,
NcVar
NcVarPair
 
typedef std::set< NcVarNcVarSet
 
typedef std::multimap
< std::string, NcDim
NcDimMap
 
typedef std::pair< std::string,
NcDim
NcDimPair
 
typedef std::set< NcDimNcDimSet
 
typedef std::multimap
< std::string, NcGroupAtt
NcGroupAttMap
 
typedef std::pair< std::string,
NcGroupAtt
NcGroupAttPair
 
typedef std::set< NcGroupAttNcGroupAttSet
 
- Public Types inherited from netcdf::NcItem
enum  { idGlobal = NC_GLOBAL }
 

Public Member Functions

 NcFile (MPI::Comm &mpiComm, MPI::Info &mpiInfo, std::string const fileName, FileMode const fileMode, size_t const *const bufrsizeptr=NULL, size_t const initialsize=0)
 Opens existing netCDF file for parallel MPI I/O; format is NetCDF4. Throws std::exception if failed. More...
 
 NcFile (std::string const fileName, FileMode const fileMode, FileFormat const fileFormat=NetCDF4, size_t const *const bufrsizeptr=NULL, size_t const initialsize=0)
 Opens existing netCDF file for non-parallel I/O. Throws std::exception if failed. More...
 
 NcFile (std::string const fileName, FileMode const fileMode=ReadOnly)
 Opens existing netCDF file for non-parallel I/O using the Classic format. Throws std::exception if failed. More...
 
bool IsParallel () const
 true if doing parallel IO. This version is parallel version. More...
 
MPI::Comm & Comm ()
 
MPI::Info & Info ()
 
FileFormat GetFormat ()
 get NetCDF file format More...
 
bool IsNetCDF3 ()
 true if file format is a NetCDF3 format More...
 
std::string GetFileName () const
 get copy of file name + path More...
 
FileMode GetFileMode () const
 
void Sync ()
 synchronize to disk More...
 
void ToDefineMode ()
 put NetCDF3 dataset into define mode More...
 
void ToDataMode ()
 put NetCDF3 dataset into data mode More...
 
void Close ()
 Close the netCDF file. For parallel-netCDF, this must be called before MPI::Finalize! More...
 
virtual ~NcFile ()
 
- Public Member Functions inherited from netcdf::NcGroup
 NcGroup ()
 null group More...
 
 NcGroup (int const useFileID, int const groupId, std::string const groupName)
 name of new group More...
 
 NcGroup (NcGroup const &rhs)
 
virtual ~NcGroup ()
 
bool operator< (NcGroup const &rhs) const
 
std::string GetName (bool fullName=false) const
 
NcGroup GetParentGroup () const
 
int GetGroupCount (NcGroup::GroupLocation location=ChildrenGrps) const
 
NcGroupMap GetGroups (NcGroup::GroupLocation location=ChildrenGrps) const
 
NcGroupSet GetGroups (std::string const name, NcGroup::GroupLocation location=ChildrenGrps) const
 
NcGroup GetGroup (std::string const name, NcGroup::GroupLocation location=ChildrenGrps) const
 
NcGroup AddGroup (std::string const name) const
 
bool IsRootGroup () const
 
int GetVarCount (NcGroup::Location location=Current) const
 
bool HaveVariable (std::string const name, NcGroup::Location const location=Current) const
 
NcVarMap GetVars (NcGroup::Location location=Current) const
 
NcVarSet GetVars (std::string const name, NcGroup::Location location=Current) const
 
NcVar GetVar (std::string const name, NcGroup::Location location=Current) const
 
NcVar AddVar (std::string const name, std::string const typeName) const
 Add a scalar variable of a specified type name. More...
 
NcVar AddVar (std::string const name, NcType const &ncType) const
 Add a scalar variable of a specifed type. More...
 
NcVar AddVar (std::string const name, std::string const typeName, std::string const dimName) const
 
NcVar AddVar (std::string const name, NcType const &ncType, const NcDim &ncDim) const
 
NcVar AddVar (std::string const name, std::string const typeName, const std::vector< std::string > &dimNames) const
 
NcVar AddVar (std::string const name, NcType const &ncType, const std::vector< NcDim > &ncDimVector) const
 
NcVar AddVar (NcVar const &var)
 
int GetAttCount (NcGroup::Location const location=Current) const
 
bool HaveAttribute (std::string const name, NcGroup::Location const location=Current) const
 
NcGroupAttMap GetAttributes (NcGroup::Location location=Current) const
 
NcGroupAttSet GetAttributes (std::string const name, NcGroup::Location location=Current) const
 
NcGroupAtt GetAtt (std::string const name, NcGroup::Location location=Current) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, size_t len, const unsigned char *dataValues) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, size_t len, const signed char *dataValues) const
 
NcGroupAtt PutAtt (std::string const name, char const aChar) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, short datumValue) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, size_t len, const short *dataValues) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, unsigned short datumValue) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, size_t len, const unsigned short *dataValues) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, int datumValue) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, size_t len, const int *dataValues) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, long datumValue) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, size_t len, const long *dataValues) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, unsigned int datumValue) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, size_t len, const unsigned int *dataValues) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, float datumValue) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, size_t len, const float *dataValues) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, double datumValue) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, size_t len, const double *dataValues) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, long long datumValue) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, size_t len, const long long *dataValues) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, unsigned long long datumValue) const
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, size_t len, const unsigned long long *dataValues) const
 
NcGroupAtt PutAtt (std::string const name, size_t len, const char **dataValues) const
 
NcGroupAtt PutAtt (std::string const name, std::string const &dataValues) const
 
NcGroupAtt PutAtt (std::string const name, std::vector< std::string > const &strVec)
 
NcGroupAtt PutAtt (std::string const name, NcType const &type, size_t len, const void *dataValues) const
 
NcGroupAtt PutAtt (NcGroupAtt const &att)
 
int GetDimCount (NcGroup::Location const location=Current) const
 
NcDimMap GetDims (NcGroup::Location const location=Current) const
 
NcDimSet GetDims (std::string const name, NcGroup::Location const location=Current) const
 
NcDim GetDim (std::string const name, NcGroup::Location const location=Current) const
 
NcDim AddDim (std::string const name, size_t const dimSize) const
 
NcDim AddDim (std::string const name) const
 
NcDim AddDim (NcDim const &dim) const
 
int GetTypeCount (NcGroup::Location location=Current) const
 
int GetTypeCount (NcType::ncType enumType, NcGroup::Location location=Current) const
 
NcTypeMap GetTypes (NcGroup::Location location=Current) const
 
NcTypeSet GetTypes (std::string const &name, NcGroup::Location location=Current) const
 
NcTypeSet GetTypes (NcType::ncType enumType, NcGroup::Location location=Current) const
 
NcTypeSet GetTypes (std::string const &name, NcType::ncType enumType, NcGroup::Location location=Current) const
 
NcType GetType (std::string const &name, NcGroup::Location location=Current) const
 
NcEnumType AddEnumType (std::string const name, NcEnumType::ncEnumType basetype) const
 
NcVlenType AddVlenType (std::string const name, NcType &basetype) const
 
NcOpaqueType AddOpaqueType (std::string const name, size_t size) const
 
NcCompoundType AddCompoundType (std::string const name, size_t size) const
 
NcGroupMapUnique GetCoordVars (Location location=Current) const
 
void GetCoordVar (std::string &coordVarName, NcDim &ncDim, NcVar &ncVar, NcGroup::Location location=Current) const
 
- Public Member Functions inherited from netcdf::NcItem
virtual ~NcItem ()=0
 
bool IsNull () const
 
std::string const & GetName () const
 
int GetID () const
 
int GetGroupID () const
 
int GetFileID () const
 
NcItemoperator= (NcItem const &rhs)
 
bool operator== (NcItem const &rhs) const
 
bool operator!= (NcItem const &rhs) const
 
bool operator< (NcItem const &rhs) const
 

Friends

class NcGroup
 

Additional Inherited Members

- Static Public Attributes inherited from netcdf::NcItem
static int const nullID = -999
 
- Protected Member Functions inherited from netcdf::NcGroup
virtual void Rename (std::string const &)
 
- Protected Member Functions inherited from netcdf::NcItem
 NcItem (bool const isNullObject=true)
 
 NcItem (int const useFileID, int const useID, int const useGroupID=NcItem::idGlobal, std::string const useName=std::string())
 
 NcItem (NcItem const &rhs)
 
void Copy (NcItem const &rhs)
 
- Protected Attributes inherited from netcdf::NcItem
bool nullObject
 
int myID
 object ID number More...
 
int groupID
 group ID number (can be unused) More...
 
int fileID
 netCDF file ID number More...
 
std::string myName
 optional name of object More...
 

Member Enumeration Documentation

Enumerator
Classic 

Classic format, classic data model.

Offset64Bits 

64-bit offset format, classic data model

NetCDF4 

(default) netCDF-4/HDF5 format, enhanced data model

NetCDF4Classic 

netCDF-4/HDF5 format, classic data model

Enumerator
ReadOnly 

File exists, open read-only.

Write 

File exists, open for read, write, append.

Replace 

Create new file, even if already exists.

New 

Create new file; fail if already exists.

Constructor & Destructor Documentation

netcdf::NcFile::NcFile ( MPI::Comm &  mpiComm,
MPI::Info &  mpiInfo,
std::string const  fileName,
FileMode const  fileMode,
size_t const *const  bufrsizeptr = NULL,
size_t const  initialsize = 0 
)
Todo:
initial file size
Parameters
mpiCommMPI world communicator
mpiInfoMPI world info
fileNameNetCDF file name + path
fileModefile mode
bufrsizeptrr/w buffer size
netcdf::NcFile::NcFile ( std::string const  fileName,
FileMode const  fileMode,
FileFormat const  fileFormat = NetCDF4,
size_t const *const  bufrsizeptr = NULL,
size_t const  initialsize = 0 
)
Todo:
initial file size
Parameters
fileNameNetCDF file name + path
fileModefile mode
fileFormatfile format
bufrsizeptrr/w buffer size
netcdf::NcFile::NcFile ( std::string const  fileName,
FileMode const  fileMode = ReadOnly 
)

file mode

Parameters
fileNameName of netCDF file
netcdf::NcFile::~NcFile ( )
virtual

Member Function Documentation

void netcdf::NcFile::Close ( )
MPI::Comm& netcdf::NcFile::Comm ( )
inline
FileMode netcdf::NcFile::GetFileMode ( ) const
inline
std::string netcdf::NcFile::GetFileName ( ) const
NcFile::FileFormat netcdf::NcFile::GetFormat ( )
MPI::Info& netcdf::NcFile::Info ( )
inline
bool netcdf::NcFile::IsNetCDF3 ( )
inline
bool netcdf::NcFile::IsParallel ( ) const
inline
void netcdf::NcFile::Sync ( )
void netcdf::NcFile::ToDataMode ( )
Examples:
Test_NcChar.cpp.
void netcdf::NcFile::ToDefineMode ( )

Friends And Related Function Documentation

friend class NcGroup
friend

The documentation for this class was generated from the following files: