TRIQS/h5 1.3.0
C++ interface to HDF5
Loading...
Searching...
No Matches
Arithmetic scalar types

Detailed Description

Specialized functions to read/write arithmetic scalar types from/to HDF5.

The following types are supported:

The following code writes a std::complex<double> to an HDF5 file, reads the same number and outputs it to stdout:

#include <h5/h5.hpp>
#include <complex>
#include <iostream>
int main() {
// create file in read/write mode
h5::file file("complex.h5", 'w');
// write complex number
std::complex<double> z { 1.0, 2.0 };
h5::write(file, "z", z);
// read into complex number
std::complex<double> z_rd;
h5::read(file, "z", z_rd);
// output complex number
std::cout << z_rd << std::endl;
}
A handle to an HDF5 file.
Definition file.hpp:43
T read(group g, std::string const &key)
Generic implementation for reading from an HDF5 dataset/subgroup.
Definition generic.hpp:73
void write(group g, std::string const &key, T const &x, auto const &...args)
Generic implementation for writing a variable to an HDF5 dataset/subgroup.
Definition generic.hpp:105
Includes all relevant h5 headers.

Output:

(1,2)

Contents of complex.h5:

HDF5 "complex.h5" {
GROUP "/" {
DATASET "z" {
DATATYPE H5T_IEEE_F64LE
DATASPACE SIMPLE { ( 2 ) / ( 2 ) }
DATA {
(0): 1, 2
}
ATTRIBUTE "__complex__" {
DATATYPE H5T_STRING {
STRSIZE H5T_VARIABLE;
STRPAD H5T_STR_NULLTERM;
CSET H5T_CSET_UTF8;
CTYPE H5T_C_S1;
}
DATASPACE SCALAR
DATA {
(0): "1"
}
}
}
}
}

Functions

template<typename T >
void h5::h5_read (group g, std::string const &name, T &x) H5_REQUIRES(std
 Read a scalar from an HDF5 dataset.
 
template<typename T >
void h5::h5_read_attribute (object obj, std::string const &name, T &x) H5_REQUIRES(std
 Read a scalar from an HDF5 attribute.
 
template<typename T >
void h5::h5_write (group g, std::string const &name, T const &x) H5_REQUIRES(std
 Write a scalar to an HDF5 dataset.
 
template<typename T >
void h5::h5_write_attribute (object obj, std::string const &name, T const &x) H5_REQUIRES(std
 Write a scalar to an HDF5 attribute.
 

Function Documentation

◆ h5_read()

template<typename T >
void h5::h5_read ( group g,
std::string const & name,
T & x )

#include <h5/scalar.hpp>

Read a scalar from an HDF5 dataset.

The scalar type needs to be either arithmetic, complex or of type h5::dcplx_t.

Template Parameters
TScalar type.
Parameters
gh5::group containing the dataset.
nameName of the dataset.
xScalar variable to be read into.

Definition at line 85 of file scalar.hpp.

◆ h5_read_attribute()

template<typename T >
void h5::h5_read_attribute ( object obj,
std::string const & name,
T & x )

#include <h5/scalar.hpp>

Read a scalar from an HDF5 attribute.

The scalar type needs to be either arithmetic or std::complex.

Template Parameters
TScalar type.
Parameters
objh5::object to which the attribute is attached.
nameName of the attribute.
xScalar variable to be read into.

Definition at line 140 of file scalar.hpp.

◆ h5_write()

template<typename T >
void h5::h5_write ( group g,
std::string const & name,
T const & x )

#include <h5/scalar.hpp>

Write a scalar to an HDF5 dataset.

The scalar type needs to be either arithmetic, complex or of type h5::dcplx_t.

Template Parameters
TScalar type.
Parameters
gh5::group in which the dataset is created.
nameName of the dataset.
xScalar value to be written.

Definition at line 70 of file scalar.hpp.

◆ h5_write_attribute()

template<typename T >
void h5::h5_write_attribute ( object obj,
std::string const & name,
T const & x )

#include <h5/scalar.hpp>

Write a scalar to an HDF5 attribute.

The scalar type needs to be either arithmetic or std::complex.

Template Parameters
TScalar type.
Parameters
objh5::object to which the attribute is attached.
nameName of the attribute.
xScalar value to be written.

Definition at line 125 of file scalar.hpp.