TECA
The Toolkit for Extreme Climate Analysis
teca_netcdf_util Namespace Reference

Codes dealing with NetCDF I/O calls. More...

Classes

class  cpp_tt
 A traits class mapping to C++ from netcdf. More...
 
class  cpp_tt< NC_BYTE >
 
class  cpp_tt< NC_DOUBLE >
 
class  cpp_tt< NC_FLOAT >
 
class  cpp_tt< NC_INT >
 
class  cpp_tt< NC_INT64 >
 
class  cpp_tt< NC_SHORT >
 
class  cpp_tt< NC_UBYTE >
 
class  cpp_tt< NC_UINT >
 
class  cpp_tt< NC_UINT64 >
 
class  cpp_tt< NC_USHORT >
 
class  netcdf_handle
 A RAII class for managing NETCDF files. The file is kept open while the object exists. More...
 
class  netcdf_tt
 A traits class mapping to netcdf from C++. More...
 
class  netcdf_tt< char >
 
class  netcdf_tt< double >
 
class  netcdf_tt< float >
 
class  netcdf_tt< int >
 
class  netcdf_tt< long >
 
class  netcdf_tt< long long >
 
class  netcdf_tt< short int >
 
class  netcdf_tt< unsigned char >
 
class  netcdf_tt< unsigned int >
 
class  netcdf_tt< unsigned long >
 
class  netcdf_tt< unsigned long long >
 
class  netcdf_tt< unsigned short int >
 
class  read_variable
 Function that reads and returns a variable from the named file. More...
 
class  read_variable_and_attributes
 Functional that reads and returns a variable from the named file. More...
 

Functions

void crtrim (char *s, long n)
 
std::mutex & get_netcdf_mutex ()
 
TECA_EXPORT int read_attribute (netcdf_handle &fh, int var_id, const std::string &att_name, teca_metadata &atts)
 
TECA_EXPORT int read_attribute (netcdf_handle &fh, int var_id, int att_id, teca_metadata &atts)
 
TECA_EXPORT int read_variable_attributes (netcdf_handle &fh, int var_id, const std::string &x_variable, const std::string &y_variable, const std::string &z_variable, const std::string &t_variable, int clamp_dimensions_of_one, std::string &name, teca_metadata &atts)
 
TECA_EXPORT int read_variable_attributes (netcdf_handle &fh, int var_id, std::string &name, teca_metadata &atts)
 
TECA_EXPORT int read_variable_attributes (netcdf_handle &fh, const std::string &name, const std::string &x_variable, const std::string &y_variable, const std::string &z_variable, const std::string &t_variable, int clamp_dimensions_of_one, teca_metadata &atts)
 
TECA_EXPORT int read_variable_attributes (netcdf_handle &fh, const std::string &var_name, teca_metadata &atts)
 
TECA_EXPORT int write_variable_attributes (netcdf_handle &fh, int var_id, teca_metadata &array_atts)
 

Detailed Description

Codes dealing with NetCDF I/O calls.

Function Documentation

◆ crtrim()

void teca_netcdf_util::crtrim ( char *  s,
long  n 
)

To deal with fortran fixed length strings which are not properly nulll terminated.

◆ get_netcdf_mutex()

std::mutex& teca_netcdf_util::get_netcdf_mutex ( )

NetCDF 3 is not threadsafe. The HDF5 C-API can be compiled to be threadsafe, but it is usually not. NetCDF uses HDF5-HL API to access HDF5, but HDF5-HL API is not threadsafe without the –enable-unsupported flag. For all those reasons it's best for the time being to protect all NetCDF I/O.

◆ read_attribute() [1/2]

TECA_EXPORT int teca_netcdf_util::read_attribute ( netcdf_handle fh,
int  var_id,
const std::string &  att_name,
teca_metadata atts 
)

Read the specified variable attribute by name. Its value is stored in the metadata object return is non-zero if an error occurred.

◆ read_attribute() [2/2]

TECA_EXPORT int teca_netcdf_util::read_attribute ( netcdf_handle fh,
int  var_id,
int  att_id,
teca_metadata atts 
)

Read the specified variable attribute by id. Its value is stored in the metadata object return is non-zero if an error occurred.

◆ read_variable_attributes() [1/4]

TECA_EXPORT int teca_netcdf_util::read_variable_attributes ( netcdf_handle fh,
const std::string &  name,
const std::string &  x_variable,
const std::string &  y_variable,
const std::string &  z_variable,
const std::string &  t_variable,
int  clamp_dimensions_of_one,
teca_metadata atts 
)

Read the specified variable's dimensions, and it's associated NetCDF attributes into the metadata object. See CF Attributes for details of attributes returned. returns non-zero if an error occurred.

◆ read_variable_attributes() [2/4]

TECA_EXPORT int teca_netcdf_util::read_variable_attributes ( netcdf_handle fh,
const std::string &  var_name,
teca_metadata atts 
)

Read the specified variable's dimensions, and it's associated NetCDF attributes into the metadata object. See CF Attributes for details of attributes returned. returns non-zero if an error occurred.

◆ read_variable_attributes() [3/4]

TECA_EXPORT int teca_netcdf_util::read_variable_attributes ( netcdf_handle fh,
int  var_id,
const std::string &  x_variable,
const std::string &  y_variable,
const std::string &  z_variable,
const std::string &  t_variable,
int  clamp_dimensions_of_one,
std::string &  name,
teca_metadata atts 
)

Read the specified variable's name, dimensions, and it's associated NetCDF attributes into the metadata object. Additionally the following key/value pairs are added and useful for subsequent I/O and processing

CF Attributes

Key Description
cf_id The NetCDF variable id that can be used to read the
variable.
cf_dims A vector of the NetCDF dimension lengths (i.e. the
variable's shape).
cf_dim_names A vector of the names of the NetCDF dimensions.
cf_type_code The NetCDF type code.
type_code The teca_variant_array::code type code.
centering The mesh centering, point_centering or no_centering
have_mesh_dim Flags indicating the presence of the x,y,z, and t
mesh dimensions
mesh_dim_active Flags indicating if the x,y,z, and t dimension is
active.

In order for centering and have_mesh_dim flags to be set, the x_variable, y_variable, z_variable, and t_variable must be specified.

If dimension is 1 and clamp_dimensions_of_one is set then the dimension is marked as inactive.

returns non-zero if an error occurred.

◆ read_variable_attributes() [4/4]

TECA_EXPORT int teca_netcdf_util::read_variable_attributes ( netcdf_handle fh,
int  var_id,
std::string &  name,
teca_metadata atts 
)

Read the specified variable's name, dimensions, and it's associated NetCDF attributes into the metadata object. See CF Attributes for details of attributes returned. returns non-zero if an error occurred.

◆ write_variable_attributes()

TECA_EXPORT int teca_netcdf_util::write_variable_attributes ( netcdf_handle fh,
int  var_id,
teca_metadata array_atts 
)

Write the attributes in array_atts to the variable identified by var_id the name is used in error messages. Returns zero of successful.