Skip to content

FileH5

A file handler for hdf5 files. The proper tool to write results of XDiag simulations to disk. Only provided for the C++ version as Julia already provides good tools handling hdf5 files.

Sources file_h5.hpp, file_h5.cpp


Constructors

FileH5(std::string filename, std::string iomode = "w");
Name Description Default
filename filename of the hdf5 file
iomode whether to read or write to file w

There are four possible values of iomode

  1. r: read-only mode
  2. w: secure write mode, new file is created if it does not exist
  3. w!: forced write mode, existing file will be overwritten
  4. a: append mode, new datasets in an existing file can be created

Methods

getindex / operator[]

Returns a handler to a value to be read or written from or to the hdf5 file.

hdf5::FileH5Handler operator[](std::string key);

Usage Example

std::string filename = XDIAG_DIRECTORY "/misc/data/hdf5/write.h5";
auto fl = FileH5(filename, "w!");

// Write output to the hdf5 file
fl["val"] = 12;
fl["test/to"] = 22;
fl["test/to2/group"] = 32;
fl["test/to3/group2/asdf"] = 42;

auto mat = arma::cx_mat(3, 5, arma::fill::randn);
fl["a/b/c/mat"] = mat;