C++ Header only library for simple HDF5 input/output
Just include the h5stream.hpp
into your your main file.
g++ -lhdf5 -lhdf5_cpp -std=c++1z example.cpp
- "tr": Create file, truncate if exists, Default
- "r": Readonly, file must exist
- "rw": Read/write, file must exist
- "x": Create file, fail if exists
h5stream::h5stream file("sample.h5", "tr");
// or
h5stream::h5stream file("sample.h5");
Create a vector and write it to the file
std::vector<double> matrix { 1, 2, 3282, 932 };
file.write<double>(matrix, "matrix");
Write Attributes( Metadata) to the to the same data space
auto dspace = file.get_dataspace("matrix");
dspace.write_atr<double>(1.2, "Units");
auto xx = file.read_vector<double>("matrix");
//OR
file.read<double>(xx, "matrix");
double x = 0;
dspace.read_atr<double>(x, "Units");
std::cout << "Attribute : " << x << std::endl;
std::cout << "HDF file size (MB): " << file.file_size() << std::endl;