Theoretica
Scientific Computing
Loading...
Searching...
No Matches
hdf5.h File Reference

HDF5 file IO. More...

#include <hdf5.h>
#include <string>
#include <vector>
#include <unordered_map>
#include <stdexcept>
#include <cstring>
#include <sstream>
#include <algorithm>
#include "./error.h"
#include "../core/constants.h"
#include "../algebra/vec.h"
#include "../algebra/mat.h"

Go to the source code of this file.

Classes

class  theoretica::io::hdf5_node
 Represents a single node (group or dataset) in the HDF5 file hierarchy. More...
 
class  theoretica::io::hdf5_handle
 RAII wrapper for managing HDF5 C-style handles, allowing direct API usage. More...
 
class  theoretica::io::hdf5_file
 High-level interface for managing an HDF5 file, its structure, and operations. More...
 

Namespaces

namespace  theoretica
 Main namespace of the library which contains all functions and objects.
 
namespace  theoretica::io
 Input and output module.
 

Enumerations

enum class  theoretica::io::HDF5NodeType { theoretica::io::UNKNOWN , theoretica::io::GROUP , theoretica::io::DATASET }
 Type of node inside an HDF5 file. More...
 

Functions

template<typename Type >
hid_t theoretica::io::_internal::hdf5_type ()
 Helper template to map C++ types to HDF5 Native Types.
 
void theoretica::io::_internal::suppress_errors ()
 Suppress HDF5 error messages by setting a custom dummy error handler.
 
void theoretica::io::_internal::remove_link (const hdf5_handle &id, const std::string &path)
 Removes a link (dataset or group) if it exists at the given path.
 
std::string theoretica::io::to_string (const hdf5_node &node)
 Generates a string representation of the HDF5 tree structure.
 
std::ostream & theoretica::io::operator<< (std::ostream &os, const hdf5_node &node)
 Prints the HDF5 file tree to a stream.
 
hdf5_handle theoretica::io::hdf5_open (const std::string &filename, bool write=false)
 Open an HDF5 file with the given filename, returning a file handle.
 
bool theoretica::io::hdf5_is_valid (const hdf5_handle &handle)
 Check whether a given HDF5 handle is valid.
 
hdf5_node theoretica::io::hdf5_load (const hdf5_handle &id)
 Recursively loads the structure of an active HDF5 group or file.
 
void theoretica::io::hdf5_create_group (const hdf5_handle &id, const std::string &path)
 Create a new group at the given path under an already open HDF5 location.
 
void theoretica::io::hdf5_delete_group (const hdf5_handle &id, const std::string &path)
 Delete a group (link) at the given path under an already open HDF5 location.
 
template<typename Type >
Type theoretica::io::hdf5_read_attribute (const hdf5_handle &id, const std::string &path, const std::string &attr_name)
 Reads an attribute attached to a specific node.
 
void theoretica::io::hdf5_delete_attribute (const hdf5_handle &id, const std::string &path, const std::string &attr_name)
 Deletes an attribute attached to a specific node, if it exists.
 
template<typename Type >
void theoretica::io::hdf5_write_attribute (const hdf5_handle &id, const std::string &path, const std::string &attr_name, const Type &value)
 Writes or overwrites an attribute attached to a specific node.
 
template<typename Vector = vec<real>>
Vectortheoretica::io::hdf5_read_vec (const hdf5_handle &id, const std::string &path, Vector &v)
 Loads a 1D dataset array into a vector.
 
template<typename Vector = vec<real>>
Vector theoretica::io::hdf5_read_vec (const hdf5_handle &id, const std::string &path)
 Loads a 1D dataset array into a vector.
 
template<typename Vector >
void theoretica::io::hdf5_write_vec (const hdf5_handle &id, const std::string &path, const Vector &v)
 Writes a 1D vector to an HDF5 dataset, overwriting if it exists.
 
void theoretica::io::hdf5_delete_dataset (const hdf5_handle &id, const std::string &path)
 Deletes a dataset at the given path if it exists.
 
template<typename Matrix = mat<real>>
Matrix theoretica::io::hdf5_read_mat (const hdf5_handle &id, const std::string &path, Matrix &m)
 Loads a 2D dataset array into a matrix.
 
template<typename Matrix = mat<real>>
Matrix theoretica::io::hdf5_read_mat (const hdf5_handle &id, const std::string &path)
 Loads a 2D dataset array into a matrix.
 
template<typename Matrix >
void theoretica::io::hdf5_write_mat (const hdf5_handle &id, const std::string &path, const Matrix &m)
 Writes a 2D matrix to an HDF5 dataset, overwriting if it exists.
 

Detailed Description

HDF5 file IO.

Note
Because of its complexity and dependencies, this header is not included automatically in 'theoretica.h'.

Function Documentation

◆ hdf5_type()

template<typename Type >
hid_t theoretica::io::_internal::hdf5_type ( )
inline

Helper template to map C++ types to HDF5 Native Types.

Template Parameters
TypeThe C++ scalar type
Returns
The equivalent HDF5 hid_t native type

◆ remove_link()

void theoretica::io::_internal::remove_link ( const hdf5_handle id,
const std::string &  path 
)
inline

Removes a link (dataset or group) if it exists at the given path.

Parameters
idThe active file or group handle
pathThe path to check and remove