TECA
The Toolkit for Extreme Climate Analysis
teca_netcdf_util.h File Reference
#include "teca_config.h"
#include "teca_mpi.h"
#include "teca_metadata.h"
#include "teca_cpu_thread_pool.h"
#include <mutex>
#include <string>
#include <netcdf.h>
Include dependency graph for teca_netcdf_util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

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

Namespaces

 teca_netcdf_util
 Codes dealing with NetCDF I/O calls.
 

Macros

#define NC_DISPATCH_FP(tc_, ...)
 macro to help with netcdf floating point data types More...
 
#define NC_DISPATCH(tc_, ...)
 macro to help with netcdf data types More...
 
#define NC_DISPATCH_CASE(cc_, tt_, ...)
 macro that executes code when the type code is matched. More...
 
#define DECLARE_NETCDF_TT(cpp_t_, nc_c_)
 
#define DECLARE_CPP_TT(cpp_t_, nc_c_)
 

Functions

void teca_netcdf_util::crtrim (char *s, long n)
 
std::mutex & teca_netcdf_util::get_netcdf_mutex ()
 
TECA_EXPORT int teca_netcdf_util::read_attribute (int parent_id, int var_id, const std::string &att_name, teca_metadata &atts)
 
TECA_EXPORT int teca_netcdf_util::read_attribute (int parent_id, int var_id, int att_id, teca_metadata &atts)
 
TECA_EXPORT int teca_netcdf_util::read_variable_attributes (netcdf_handle &fh, const std::string &parent_group, int var_id, const std::string &x_variable, const std::string &y_variable, const std::string &z_variable, const std::string &t_variable, const std::string &ensemble_dimension_name, int clamp_dimensions_of_one, std::string &name, teca_metadata &atts)
 
TECA_EXPORT int teca_netcdf_util::read_variable_attributes (netcdf_handle &fh, const std::string &parent_group, int var_id, std::string &name, teca_metadata &atts)
 
TECA_EXPORT int teca_netcdf_util::get_varid (netcdf_handle &fh, const std::string &var_name, int *parent_id, int *var_id)
 
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, const std::string &ensemble_dim_name, int clamp_dimensions_of_one, teca_metadata &atts)
 
TECA_EXPORT int teca_netcdf_util::read_variable_attributes (netcdf_handle &fh, const std::string &var_name, teca_metadata &atts)
 
TECA_EXPORT int teca_netcdf_util::write_variable_attributes (int parent_id, int var_id, teca_metadata &array_atts)
 

Macro Definition Documentation

◆ DECLARE_CPP_TT

#define DECLARE_CPP_TT (   cpp_t_,
  nc_c_ 
)
Value:
/** A traits class mapping to C++ from NetCDF, specialized for cpp_t_ */ \
template <> class cpp_tt<nc_c_> \
{ \
public: \
using type = cpp_t_; \
static const char *name() { return #cpp_t_; } \
};

◆ DECLARE_NETCDF_TT

#define DECLARE_NETCDF_TT (   cpp_t_,
  nc_c_ 
)
Value:
/** A traits class mapping to NetCDF from C++, specialized for cpp_t_ */ \
template <> class netcdf_tt<cpp_t_> \
{ \
public: \
enum { type_code = nc_c_ }; \
static const char *name() { return #nc_c_; } \
};

◆ NC_DISPATCH

#define NC_DISPATCH (   tc_,
  ... 
)
Value:
switch (tc_) \
{ \
NC_DISPATCH_CASE(NC_BYTE, char, __VA_ARGS__) \
NC_DISPATCH_CASE(NC_UBYTE, unsigned char, __VA_ARGS__) \
NC_DISPATCH_CASE(NC_CHAR, char, __VA_ARGS__) \
NC_DISPATCH_CASE(NC_SHORT, short int, __VA_ARGS__) \
NC_DISPATCH_CASE(NC_USHORT, unsigned short int, __VA_ARGS__) \
NC_DISPATCH_CASE(NC_INT, int, __VA_ARGS__) \
NC_DISPATCH_CASE(NC_UINT, unsigned int, __VA_ARGS__) \
NC_DISPATCH_CASE(NC_INT64, long long, __VA_ARGS__) \
NC_DISPATCH_CASE(NC_UINT64, unsigned long long, __VA_ARGS__) \
NC_DISPATCH_CASE(NC_FLOAT, float, __VA_ARGS__) \
NC_DISPATCH_CASE(NC_DOUBLE, double, __VA_ARGS__) \
default: \
TECA_ERROR("netcdf type code " << tc_ \
<< " is not supported") \
}

macro to help with netcdf data types

◆ NC_DISPATCH_CASE

#define NC_DISPATCH_CASE (   cc_,
  tt_,
  ... 
)
Value:
case cc_: \
{ \
using NC_NT = tt_; \
using NC_CTT = const teca_variant_array_impl<tt_>; \
using NC_PT = std::shared_ptr<teca_variant_array_impl<tt_>>; \
using NC_CPT = std::shared_ptr<const teca_variant_array_impl<tt_>>; \
using NC_SP = std::shared_ptr<tt_>; \
using NC_CSP = std::shared_ptr<const tt_>; \
__VA_ARGS__ \
break; \
}
The concrete implementation of our type agnostic container for contiguous arrays.
Definition: teca_variant_array_impl.h:380

macro that executes code when the type code is matched.

◆ NC_DISPATCH_FP

#define NC_DISPATCH_FP (   tc_,
  ... 
)
Value:
switch (tc_) \
{ \
NC_DISPATCH_CASE(NC_FLOAT, float, __VA_ARGS__) \
NC_DISPATCH_CASE(NC_DOUBLE, double, __VA_ARGS__) \
default: \
TECA_ERROR("netcdf type __VA_ARGS__ " << tc_ \
<< " is not a floating point type") \
}

macro to help with netcdf floating point data types