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

Detailed Description

Specialized functions to read/write a std::array from/to HDF5.

The following code writes a std::array to an HDF5 file, reads the same array and outputs it to stdout:

#include <h5/h5.hpp>
#include <iostream>
#include <array>
int main() {
// create file in read/write mode
h5::file file("array.h5", 'w');
// write array
h5::write(file, "myarray", std::array { 1, 2, 3, 4 , 5 });
// read into array
std::array<int, 5> arr;
h5::read(file, "myarray", arr);
// output array
for (auto x : arr) std::cout << x << 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
3
4
5

Contents of array.h5:

HDF5 "array.h5" {
GROUP "/" {
DATASET "myarray" {
DATATYPE H5T_STD_I32LE
DATASPACE SIMPLE { ( 5 ) / ( 5 ) }
DATA {
(0): 1, 2, 3, 4, 5
}
}
}
}

Functions

template<typename T , size_t N>
void h5::h5_read (group g, std::string name, std::array< T, N > &a)
 Read a std::array from an HDF5 dataset/subgroup.
 
template<typename T , size_t N>
void h5::h5_write (group g, std::string const &name, std::array< T, N > const &a)
 Write a std::array to an HDF5 dataset/subgroup.
 

Function Documentation

◆ h5_read()

template<typename T , size_t N>
void h5::h5_read ( group g,
std::string name,
std::array< T, N > & a )

#include <h5/stl/array.hpp>

Read a std::array from an HDF5 dataset/subgroup.

Template Parameters
TValue type of the std::array.
NSize of the std::array.
Parameters
gh5::group containing the dataset/subgroup.
nameName of the dataset/subgroup from which the std::array is read.
astd::array to read into.

Definition at line 84 of file array.hpp.

◆ h5_write()

template<typename T , size_t N>
void h5::h5_write ( group g,
std::string const & name,
std::array< T, N > const & a )

#include <h5/stl/array.hpp>

Write a std::array to an HDF5 dataset/subgroup.

Template Parameters
TValue type of the std::array.
NSize of the std::array.
Parameters
gh5::group in which the dataset/subgroup is created.
nameName of the dataset/subgroup to which the std::array is written.
astd::array to be written.

Definition at line 52 of file array.hpp.