项目作者: srbhp

项目描述 :
C++ Header only library for HDF5 input/output
高级语言: C++
项目地址: git://github.com/srbhp/h5stream.git
创建时间: 2020-07-23T11:27:32Z
项目社区:https://github.com/srbhp/h5stream

开源协议:

下载


h5stream

C++ Header only library for simple HDF5 input/output

How to use

Just include the h5stream.hpp into your your main file.

Compile

  1. g++ -lhdf5 -lhdf5_cpp -std=c++1z example.cpp

Example

Create File with a mode.

  • “tr”: Create file, truncate if exists, Default
  • “r”: Readonly, file must exist
  • “rw”: Read/write, file must exist
  • “x”: Create file, fail if exists
  1. h5stream::h5stream file("sample.h5", "tr");
  2. // or
  3. h5stream::h5stream file("sample.h5");

write and read std::vector

Create a vector and write it to the file

  1. std::vector<double> matrix { 1, 2, 3282, 932 };
  2. file.write<double>(matrix, "matrix");

write and read Metadata

Write Attributes( Metadata) to the to the same data space

  1. auto dspace = file.get_dataspace("matrix");
  2. dspace.write_atr<double>(1.2, "Units");

Read data from the file

  1. auto xx = file.read_vector<double>("matrix");
  2. //OR
  3. file.read<double>(xx, "matrix");

Read Attribute (Metadata)

  1. double x = 0;
  2. dspace.read_atr<double>(x, "Units");
  3. std::cout << "Attribute : " << x << std::endl;
  4. std::cout << "HDF file size (MB): " << file.file_size() << std::endl;