ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ncutils::NCFile Class Reference

#include <ERF_NCInterface.H>

Inheritance diagram for ncutils::NCFile:
Collaboration diagram for ncutils::NCFile:

Public Member Functions

 ~NCFile ()
 
void close ()
 
- Public Member Functions inherited from ncutils::NCGroup
std::string name () const
 Name of this group. More...
 
std::string full_name () const
 Full name for this group. More...
 
int num_groups () const
 Number of sub-groups within this group. More...
 
int num_dimensions () const
 Number of dimensions in this group. More...
 
int num_variables () const
 Number of variables within this group. More...
 
int num_attributes () const
 Number of attributes within this group. More...
 
bool has_group (const std::string &) const
 Check if a group exists. More...
 
bool has_dim (const std::string &) const
 Check if a dimension exists by name. More...
 
bool has_var (const std::string &) const
 Check if a variable exists by name. More...
 
bool has_attr (const std::string &) const
 Check if an attribute exists. More...
 
NCGroup group (const std::string &) const
 
NCDim dim (const std::string &) const
 Get the dimension instance by name. More...
 
NCVar var (const std::string &) const
 Get the variable instance by name. More...
 
void def_dim (const std::string &, size_t len) const
 Define new dimension. More...
 
void def_array (const std::string &name, nc_type dtype, const std::vector< std::string > &) const
 Define an array. More...
 
void def_var (const std::string &name, const nc_type dtype, const std::vector< std::string > &dnames) const
 Define a variable (wrapper for def_array) More...
 
void put_attr (const std::string &name, const std::string &value) const
 
void put_attr (const std::string &name, const std::vector< double > &value) const
 
void put_attr (const std::string &name, const std::vector< float > &value) const
 
void put_attr (const std::string &name, const std::vector< int > &value) const
 
std::string get_attr (const std::string &name) const
 
void get_attr (const std::string &name, std::vector< double > &value) const
 
void get_attr (const std::string &name, std::vector< float > &value) const
 
void get_attr (const std::string &name, std::vector< int > &value) const
 
std::vector< NCGroupall_groups () const
 Return a list of all groups defined in this group. More...
 
std::vector< NCDimall_dims () const
 Return a list of all dimensions defined in this group. More...
 
std::vector< NCVarall_vars () const
 Return a list of all variables defined in this group. More...
 
void enter_def_mode () const
 Enter definition mode (not needed for NetCDF4 format) More...
 
void exit_def_mode () const
 Exit definition mode. More...
 

Static Public Member Functions

static NCFile create (const std::string &name, const int cmode=NC_CLOBBER|NC_NETCDF4)
 
static NCFile open (const std::string &name, const int cmode=NC_NOWRITE)
 
static NCFile create_par (const std::string &name, const int cmode=NC_CLOBBER|NC_NETCDF4|NC_MPIIO, MPI_Comm comm=MPI_COMM_WORLD, MPI_Info info=MPI_INFO_NULL)
 
static NCFile open_par (const std::string &name, const int cmode=NC_NOWRITE, MPI_Comm comm=MPI_COMM_WORLD, MPI_Info info=MPI_INFO_NULL)
 

Protected Member Functions

 NCFile (const int id)
 
- Protected Member Functions inherited from ncutils::NCGroup
 NCGroup (const int id)
 
 NCGroup (const int id, const NCGroup *)
 

Protected Attributes

bool is_open {false}
 

Additional Inherited Members

- Public Attributes inherited from ncutils::NCGroup
const int ncid
 Identifier used with NetCDF API calls. More...
 

Detailed Description

Representation of a NetCDF file

Provide wrappes to create and open file

Constructor & Destructor Documentation

◆ ~NCFile()

ncutils::NCFile::~NCFile ( )
697 {
698  if (is_open) check_nc_error(nc_close(ncid));
699 }
bool is_open
Definition: ERF_NCInterface.H:309
const int ncid
Identifier used with NetCDF API calls.
Definition: ERF_NCInterface.H:190

◆ NCFile()

ncutils::NCFile::NCFile ( const int  id)
inlineprotected
307 : NCGroup(id), is_open{true} {}
NCGroup(const int id)
Definition: ERF_NCInterface.H:276

Referenced by create(), create_par(), open(), and open_par().

Here is the caller graph for this function:

Member Function Documentation

◆ close()

void ncutils::NCFile::close ( )
702 {
703  is_open = false;
704  check_nc_error(nc_close(ncid));
705 }

◆ create()

NCFile ncutils::NCFile::create ( const std::string &  name,
const int  cmode = NC_CLOBBER | NC_NETCDF4 
)
static
668 {
669  int ncid;
670  check_nc_error(nc_create(name.data(), cmode, &ncid));
671  return NCFile(ncid);
672 }
NCFile(const int id)
Definition: ERF_NCInterface.H:307
std::string name() const
Name of this group.
Definition: ERF_NCInterface.cpp:442
Here is the call graph for this function:

◆ create_par()

NCFile ncutils::NCFile::create_par ( const std::string &  name,
const int  cmode = NC_CLOBBER | NC_NETCDF4 | NC_MPIIO,
MPI_Comm  comm = MPI_COMM_WORLD,
MPI_Info  info = MPI_INFO_NULL 
)
static
682 {
683  int ncid;
684  check_nc_error(nc_create_par(name.data(), cmode, comm, info, &ncid));
685  return NCFile(ncid);
686 }
Here is the call graph for this function:

◆ open()

NCFile ncutils::NCFile::open ( const std::string &  name,
const int  cmode = NC_NOWRITE 
)
static
675 {
676  int ncid;
677  check_nc_error(nc_open(name.data(), cmode, &ncid));
678  return NCFile(ncid);
679 }

Referenced by ReadNetCDFFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ open_par()

NCFile ncutils::NCFile::open_par ( const std::string &  name,
const int  cmode = NC_NOWRITE,
MPI_Comm  comm = MPI_COMM_WORLD,
MPI_Info  info = MPI_INFO_NULL 
)
static
690 {
691  int ncid;
692  check_nc_error(nc_open_par(name.data(), cmode, comm, info, &ncid));
693  return NCFile(ncid);
694 }
Here is the call graph for this function:

Member Data Documentation

◆ is_open

bool ncutils::NCFile::is_open {false}
protected

Referenced by close(), and ~NCFile().


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