FV3 Bundle
ioda::NetcdfIO Class Reference

Implementation of IodaIO for netcdf. More...

#include <NetcdfIO.h>

Inheritance diagram for ioda::NetcdfIO:
[legend]
Collaboration diagram for ioda::NetcdfIO:
[legend]

Public Member Functions

 NetcdfIO (const std::string &FileName, const std::string &FileMode, const std::size_t &Nlocs, const std::size_t &Nobs, const std::size_t &Nrecs, const std::size_t &Nvars)
 
 ~NetcdfIO ()
 
void ReadVar (const std::string &VarName, int *VarData)
 Read data from netcdf file to memory. More...
 
void ReadVar (const std::string &VarName, float *VarData)
 
void ReadVar (const std::string &VarName, double *VarData)
 
void WriteVar (const std::string &VarName, int *VarData)
 Write data from memory to netcdf file. More...
 
void WriteVar (const std::string &VarName, float *VarData)
 
void WriteVar (const std::string &VarName, double *VarData)
 
void ReadDateTime (int *VarDate, int *VarTime)
 Read and format the date, time values. More...
 
- Public Member Functions inherited from ioda::IodaIO
virtual ~IodaIO ()=0
 
std::string fname () const
 
std::string fmode () const
 
std::size_t nlocs ()
 
std::size_t nobs ()
 
std::size_t nrecs ()
 
std::size_t nvars ()
 

Static Public Member Functions

static const std::string classname ()
 classname method for object counter More...
 

Private Member Functions

void print (std::ostream &os) const
 print method for stream output More...
 
void CheckNcCall (int, std::string &)
 check results of netcdf call More...
 

Private Attributes

int ncid_
 netcdf file id More...
 
int nlocs_id_
 This data member holds the netcdf id of the "nlocs" dimension in the opened netcdf file. More...
 
int nvars_id_
 This data member holds the netcdf id of the "nvars" dimension in the opened netcdf file. More...
 
int nobs_id_
 This data member holds the netcdf id of the "nobs" dimension in the opened netcdf file. More...
 
int nrecs_id_
 This data member holds the netcdf id of the "nrecs" dimension in the opened netcdf file. More...
 
int nchans_id_
 This data member holds the netcdf id of the "nchans" dimension in the opened netcdf file. More...
 
int nc_varid_
 This data member holds the netcdf id of the current dataset (variable) in the opened netcdf file. More...
 
bool have_nlocs_
 This data member is a flag that indicates the existence of the "nlocs" dimension in the opened netcdf file. More...
 
bool have_nvars_
 This data member is a flag that indicates the existence of the "nvars" dimension in the opened netcdf file. More...
 
bool have_nobs_
 This data member is a flag that indicates the existence of the "nobs" dimension in the opened netcdf file. More...
 
bool have_nrecs_
 This data member is a flag that indicates the existence of the "nrecs" dimension in the opened netcdf file. More...
 
bool have_nchans_
 This data member is a flag that indicates the existence of the "nchans" dimension in the opened netcdf file. More...
 
int nc_attid_
 This data member holds the netcdf id of the current attribute in the opened netcdf file. More...
 

Additional Inherited Members

- Protected Attributes inherited from ioda::IodaIO
std::string fname_
 file name More...
 
std::string fmode_
 file mode ("r" -> read, "w" -> overwrite, "W" -> create and write) More...
 
std::size_t nlocs_
 number of unique locations More...
 
std::size_t nobs_
 number of unique observations More...
 
std::size_t nrecs_
 number of unique records More...
 
std::size_t nvars_
 number of unique variables More...
 

Detailed Description

Implementation of IodaIO for netcdf.

The NetcdfIO class defines the constructor and methods for the abstract class IodaIO.

Author
Stephen Herbener (JCSDA)

Definition at line 36 of file NetcdfIO.h.

Constructor & Destructor Documentation

◆ NetcdfIO()

ioda::NetcdfIO::NetcdfIO ( const std::string &  FileName,
const std::string &  FileMode,
const std::size_t &  Nlocs,
const std::size_t &  Nobs,
const std::size_t &  Nrecs,
const std::size_t &  Nvars 
)

This constructor will open the netcdf file. If opening in read mode, the parameters nlocs, nobs, nrecs and nvars will be set by querying the size of dimensions of the same names in the input file. If opening in write mode, the parameters will be set from the same named arguements to this constructor.

Parameters
[in]FileNamePath to the netcdf file
[in]FileMode"r" for read, "w" for overwrite to an existing file and "W" for create and write to a new file.
[in]NlocsNumber of unique locations in the obs data.
[in]NobsNumber of unique observations in the obs data.
[in]NrecsNumber of unique records in the obs data. Records are atomic units that will remain intact when obs are distributed across muliple process elements. A single radiosonde sounding would be an example.
[in]NvarsNumber of unique varibles in the obs data.

Definition at line 47 of file NetcdfIO.cc.

◆ ~NetcdfIO()

ioda::NetcdfIO::~NetcdfIO ( )

Definition at line 149 of file NetcdfIO.cc.

Member Function Documentation

◆ CheckNcCall()

void ioda::NetcdfIO::CheckNcCall ( int  RetCode,
std::string &  ErrorMsg 
)
private

check results of netcdf call

This method will check the return code from a netcdf API call. Successful completion of the call is indicated by the return code being equal to NC_NOERR. If the call was not successful, then the error message is written to the OOPS log, and is also sent to the OOPS ABORT call (execution is aborted).

Parameters
[in]RetCodeReturn code from netcdf call
[in]ErrorMsgMessage for the OOPS error logger

Definition at line 378 of file NetcdfIO.cc.

Here is the caller graph for this function:

◆ classname()

static const std::string ioda::NetcdfIO::classname ( )
inlinestatic

classname method for object counter

This method is supplied for the ObjectCounter base class. It defines a name to identify an object of this class for reporting by OOPS.

Definition at line 46 of file NetcdfIO.h.

◆ print()

void ioda::NetcdfIO::print ( std::ostream &  os) const
private

print method for stream output

This method is supplied for the Printable base class. It defines how to print an object of this class in an output stream.

Definition at line 360 of file NetcdfIO.cc.

◆ ReadDateTime()

void ioda::NetcdfIO::ReadDateTime ( int *  VarDate,
int *  VarTime 
)
virtual

Read and format the date, time values.

This method will read in the date and time information (timestamp) from the netcdf file, and convert them into a convenient format for usage by the JEDI system. Currently, the netcdf files contain an attribute called "date_time" that holds the analysis time for the obs data in the format yyyymmddhh. For example April 15, 2018 at 00Z is recorded as 2018041500. The netcdf file also contains a time variable (float) which is the offset from the date_time value in hours. This method will convert the date time information to two integer vectors. The first is the date (yyyymmdd) and the second is the time (hhmmss). With the above date_time example combined with a time value of -3.5 (hours), the resulting date and time entries in the output vectors will be date = 20180414 and time = 233000.

Eventually, the yyyymmdd and hhmmss values can be recorded in the netcdf file as thier own datasets and this method could be removed.

Parameters
[out]VarDateDate portion of the timestamp values (yyyymmdd)
[out]VarTimeTime portion of the timestamp values (hhmmss)

Implements ioda::IodaIO.

Definition at line 296 of file NetcdfIO.cc.

Here is the call graph for this function:

◆ ReadVar() [1/3]

void ioda::NetcdfIO::ReadVar ( const std::string &  VarName,
int *  VarData 
)
virtual

Read data from netcdf file to memory.

The three ReadVar methods are the same with the exception of the datatype that is being read (integer, float, double). It is the caller's responsibility to allocate memory to hold the data being read. The caller then passes a pointer to that memory for the VarData argument.

Parameters
[in]VarNameName of dataset in the netcdf file
[out]VarDataPointer to memory that will receive the file data

Implements ioda::IodaIO.

Definition at line 169 of file NetcdfIO.cc.

Here is the call graph for this function:

◆ ReadVar() [2/3]

void ioda::NetcdfIO::ReadVar ( const std::string &  VarName,
float *  VarData 
)
virtual

Implements ioda::IodaIO.

Definition at line 183 of file NetcdfIO.cc.

Here is the call graph for this function:

◆ ReadVar() [3/3]

void ioda::NetcdfIO::ReadVar ( const std::string &  VarName,
double *  VarData 
)
virtual

Implements ioda::IodaIO.

Definition at line 197 of file NetcdfIO.cc.

Here is the call graph for this function:

◆ WriteVar() [1/3]

void ioda::NetcdfIO::WriteVar ( const std::string &  VarName,
int *  VarData 
)
virtual

Write data from memory to netcdf file.

The three WriteVar methods are the same with the exception of the datatype that is being written (integer, float, double). It is the caller's responsibility to allocate and assign memory to the data that are to be written. The caller then passes a pointer to that memory for the VarData argument.

Parameters
[in]VarNameName of dataset in the netcdf file
[in]VarDataPointer to memory that will be written into the file

Implements ioda::IodaIO.

Definition at line 223 of file NetcdfIO.cc.

Here is the call graph for this function:

◆ WriteVar() [2/3]

void ioda::NetcdfIO::WriteVar ( const std::string &  VarName,
float *  VarData 
)
virtual

Implements ioda::IodaIO.

Definition at line 240 of file NetcdfIO.cc.

Here is the call graph for this function:

◆ WriteVar() [3/3]

void ioda::NetcdfIO::WriteVar ( const std::string &  VarName,
double *  VarData 
)
virtual

Implements ioda::IodaIO.

Definition at line 257 of file NetcdfIO.cc.

Here is the call graph for this function:

Member Data Documentation

◆ have_nchans_

bool ioda::NetcdfIO::have_nchans_
private

This data member is a flag that indicates the existence of the "nchans" dimension in the opened netcdf file.

Definition at line 143 of file NetcdfIO.h.

◆ have_nlocs_

bool ioda::NetcdfIO::have_nlocs_
private

This data member is a flag that indicates the existence of the "nlocs" dimension in the opened netcdf file.

Definition at line 119 of file NetcdfIO.h.

◆ have_nobs_

bool ioda::NetcdfIO::have_nobs_
private

This data member is a flag that indicates the existence of the "nobs" dimension in the opened netcdf file.

Definition at line 131 of file NetcdfIO.h.

◆ have_nrecs_

bool ioda::NetcdfIO::have_nrecs_
private

This data member is a flag that indicates the existence of the "nrecs" dimension in the opened netcdf file.

Definition at line 137 of file NetcdfIO.h.

◆ have_nvars_

bool ioda::NetcdfIO::have_nvars_
private

This data member is a flag that indicates the existence of the "nvars" dimension in the opened netcdf file.

Definition at line 125 of file NetcdfIO.h.

◆ nc_attid_

int ioda::NetcdfIO::nc_attid_
private

This data member holds the netcdf id of the current attribute in the opened netcdf file.

Definition at line 149 of file NetcdfIO.h.

◆ nc_varid_

int ioda::NetcdfIO::nc_varid_
private

This data member holds the netcdf id of the current dataset (variable) in the opened netcdf file.

Definition at line 113 of file NetcdfIO.h.

◆ nchans_id_

int ioda::NetcdfIO::nchans_id_
private

This data member holds the netcdf id of the "nchans" dimension in the opened netcdf file.

Definition at line 107 of file NetcdfIO.h.

◆ ncid_

int ioda::NetcdfIO::ncid_
private

netcdf file id

This data member holds the file id of the open netcdf file. It gives access to the dimensions, attributes and variables in the netcdf file.

Definition at line 77 of file NetcdfIO.h.

◆ nlocs_id_

int ioda::NetcdfIO::nlocs_id_
private

This data member holds the netcdf id of the "nlocs" dimension in the opened netcdf file.

Definition at line 83 of file NetcdfIO.h.

◆ nobs_id_

int ioda::NetcdfIO::nobs_id_
private

This data member holds the netcdf id of the "nobs" dimension in the opened netcdf file.

Definition at line 95 of file NetcdfIO.h.

◆ nrecs_id_

int ioda::NetcdfIO::nrecs_id_
private

This data member holds the netcdf id of the "nrecs" dimension in the opened netcdf file.

Definition at line 101 of file NetcdfIO.h.

◆ nvars_id_

int ioda::NetcdfIO::nvars_id_
private

This data member holds the netcdf id of the "nvars" dimension in the opened netcdf file.

Definition at line 89 of file NetcdfIO.h.


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