https://github.com/srbhp/h5stream
C++ Header only library for HDF5 input/output
https://github.com/srbhp/h5stream
cpp hdf5
Last synced: about 1 month ago
JSON representation
C++ Header only library for HDF5 input/output
- Host: GitHub
- URL: https://github.com/srbhp/h5stream
- Owner: srbhp
- Created: 2020-07-23T11:27:32.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-01-05T21:20:06.000Z (over 2 years ago)
- Last Synced: 2025-12-28T23:27:17.707Z (6 months ago)
- Topics: cpp, hdf5
- Language: C++
- Homepage:
- Size: 1.8 MB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# [h5stream](https://github.com/srbhp/h5stream)
C++ Header only library for simple HDF5 input/output
## How to use
Just include the `h5stream.hpp` into your your main file.
### Compile
```
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
```
h5stream::h5stream file("sample.h5", "tr");
// or
h5stream::h5stream file("sample.h5");
```
#### write and read `std::vector`
Create a vector and write it to the file
```
std::vector matrix { 1, 2, 3282, 932 };
file.write(matrix, "matrix");
```
#### write and read Metadata
Write Attributes( Metadata) to the to the same data space
```
auto dspace = file.get_dataspace("matrix");
dspace.write_atr(1.2, "Units");
```
#### Read data from the file
```
auto xx = file.read_vector("matrix");
//OR
file.read(xx, "matrix");
```
#### Read Attribute (Metadata)
```
double x = 0;
dspace.read_atr(x, "Units");
std::cout << "Attribute : " << x << std::endl;
std::cout << "HDF file size (MB): " << file.file_size() << std::endl;
```