netcdfpp
Header-only NetCDF C++ wrapper
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Functions
netcdfpp.h File Reference

Header-only C++ wrapper for the NetCDF-C API. More...

#include <netcdf.h>
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <memory>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

Go to the source code of this file.

Classes

struct  netCDF::SystemType< I >
 
struct  netCDF::Type< T >
 
struct  netCDF::Type< long long >
 
struct  netCDF::Type< unsigned long long >
 
class  netCDF::Exception
 Exception thrown when a NetCDF-C call fails. More...
 
struct  netCDF::detail::Path
 
struct  netCDF::detail::ClassName< T >
 
struct  netCDF::detail::ClassName< Attribute >
 
struct  netCDF::detail::ClassName< Dimension >
 
struct  netCDF::detail::ClassName< File >
 
struct  netCDF::detail::ClassName< Group >
 
struct  netCDF::detail::ClassName< UserType >
 
struct  netCDF::detail::ClassName< Variable >
 
class  netCDF::detail::Object
 
class  netCDF::Maybe< T >
 Optional result returned by object lookup functions. More...
 
class  netCDF::Attribute
 NetCDF attribute attached to a group or variable. More...
 
class  netCDF::Dimension
 NetCDF dimension. More...
 
class  netCDF::Group
 NetCDF group, including the root group represented by File. More...
 
class  netCDF::File
 NetCDF file handle and root group. More...
 
class  netCDF::UserType
 NetCDF user-defined type. More...
 
struct  netCDF::UserType::CompoundField
 Compound field metadata. More...
 
struct  netCDF::VLenElement< T >
 RAII wrapper for one NetCDF variable-length value returned by the C API. More...
 
class  netCDF::Variable
 NetCDF variable. More...
 

Namespaces

namespace  netCDF
 
namespace  netCDF::testing
 
namespace  netCDF::detail
 

Macros

#define NETCDFPP_IMPL_TYPE(internal, lib)
 
#define NETCDFPP_IMPL_ATTRIBUTE_GET(type, name)
 
#define NETCDFPP_IMPL_ATTRIBUTE_SET(type, name)
 
#define NETCDFPP_IMPL_VARIABLE_READ(type, name)
 
#define NETCDFPP_IMPL_VARIABLE_WRITE(type, name)
 
#define NETCDFPP_IMPL_ALL(type, name)
 

Functions

template<typename T , typename Function >
netCDF::for_type (nc_type t, Function &&f)
 Calls a callable with a default value of the C++ type matching a NetCDF atomic type.
 
constexpr bool netCDF::detail::is_user_type (nc_type type)
 
template<typename T >
T * netCDF::detail::data_or_null (std::vector< T > &v)
 
template<typename T >
const T * netCDF::detail::data_or_null (const std::vector< T > &v)
 
std::vector< std::string > netCDF::detail::process_char_vector (std::vector< char * > &buf)
 
std::vector< std::string > netCDF::detail::process_char_vector (char **buf, std::size_t len)
 
std::vector< const char * > netCDF::detail::process_string_vector (const std::vector< std::string > &v)
 
template<>
Variable netCDF::Group::add_variable< std::string > (std::string name, const std::vector< int > &dims)
 
template<>
Variable netCDF::Group::add_variable< std::string > (std::string name, const std::vector< Dimension > &dims)
 
template<>
Variable netCDF::Group::add_variable< std::string > (std::string name, const std::vector< std::string > &dims)
 

Detailed Description

Header-only C++ wrapper for the NetCDF-C API.

The public API is in the netCDF namespace. Most operations forward to the NetCDF-C library and throw netCDF::Exception on NetCDF errors.

Macro Definition Documentation

◆ NETCDFPP_IMPL_ALL

#define NETCDFPP_IMPL_ALL (   type,
  name 
)
Value:
NETCDFPP_IMPL_ATTRIBUTE_SET(type, name) \
NETCDFPP_IMPL_VARIABLE_READ(type, name) \
NETCDFPP_IMPL_VARIABLE_WRITE(type, name)
#define NETCDFPP_IMPL_ATTRIBUTE_GET(type, name)
Definition netcdfpp.h:1933

◆ NETCDFPP_IMPL_ATTRIBUTE_GET

#define NETCDFPP_IMPL_ATTRIBUTE_GET (   type,
  name 
)
Value:
template<> \
inline int Attribute::get_internal(int ncid_p, int othid_p, const char* name_p, type* v) const { \
return nc_get_att##name(ncid_p, othid_p, name_p, v); \
}

◆ NETCDFPP_IMPL_ATTRIBUTE_SET

#define NETCDFPP_IMPL_ATTRIBUTE_SET (   type,
  name 
)
Value:
template<> \
inline int Attribute::set_internal(int ncid_p, int othid_p, const char* name_p, std::size_t len, const type* v) { \
return nc_put_att##name(ncid_p, othid_p, name_p, Type<type>::id, len, v); \
}

◆ NETCDFPP_IMPL_TYPE

#define NETCDFPP_IMPL_TYPE (   internal,
  lib 
)
Value:
template<> \
struct SystemType<lib> { \
using type = internal; \
}; \
template<> \
struct Type<internal> { \
static constexpr nc_type id = lib; \
static constexpr bool is_atomic = true; \
};

◆ NETCDFPP_IMPL_VARIABLE_READ

#define NETCDFPP_IMPL_VARIABLE_READ (   type,
  name 
)
Value:
template<> \
inline void Variable::read(type* v) const { \
check(nc_get_var##name(path->parent->id, path->id, v)); \
} \
template<> \
inline void Variable::read(type* v, const std::size_t* index) const { \
check(nc_get_var1##name(path->parent->id, path->id, index, v)); \
} \
template<> \
inline void Variable::read(type* v, const std::size_t* start, const std::size_t* count) const { \
check(nc_get_vara##name(path->parent->id, path->id, start, count, v)); \
} \
template<> \
inline void Variable::read(type* v, const std::size_t* start, const std::size_t* count, const std::ptrdiff_t* stride) const { \
check(nc_get_vars##name(path->parent->id, path->id, start, count, stride, v)); \
} \
template<> \
inline void Variable::read(type* v, const std::size_t* start, const std::size_t* count, const std::ptrdiff_t* stride, const std::ptrdiff_t* imap) const { \
check(nc_get_varm##name(path->parent->id, path->id, start, count, stride, imap, v)); \
}

◆ NETCDFPP_IMPL_VARIABLE_WRITE

#define NETCDFPP_IMPL_VARIABLE_WRITE (   type,
  name 
)
Value:
template<> \
inline void Variable::write(const type* v) { \
check(nc_put_var##name(path->parent->id, path->id, v)); \
} \
template<> \
inline void Variable::write(const type* v, const std::size_t* index) { \
check(nc_put_var1##name(path->parent->id, path->id, index, v)); \
} \
template<> \
inline void Variable::write(const type* v, const std::size_t* start, const std::size_t* count) { \
check(nc_put_vara##name(path->parent->id, path->id, start, count, v)); \
} \
template<> \
inline void Variable::write(const type* v, const std::size_t* start, const std::size_t* count, const std::ptrdiff_t* stride) { \
check(nc_put_vars##name(path->parent->id, path->id, start, count, stride, v)); \
} \
template<> \
inline void Variable::write(const type* v, const std::size_t* start, const std::size_t* count, const std::ptrdiff_t* stride, const std::ptrdiff_t* imap) { \
check(nc_put_varm##name(path->parent->id, path->id, start, count, stride, imap, v)); \
}