Skip to content

szarejkodariusz/SimpleHDF5

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HDF5 C++ Wrapper

A tiny, header-only C++17 wrapper around the HDF5 C++ API that makes common write/read flows painless: scalars, vectors, matrices, and compound datasets. It auto-creates group paths, keeps your data strongly typed, and stays out of your way.

Why this wrapper

  • Simple API for the 80% use case: save/read values, vectors, matrices, and compound records.
  • Strong typing with minimal boilerplate.
  • Header-only: just include HDF5.hpp.
  • Works with vanilla h5c++ or pkg-config.

Features

  • Save/read scalars, vectors, matrices, and compound datasets.
  • Supports int, unsigned int, unsigned short, std::size_t, long long, unsigned long long, char, unsigned char, bool, float, double, and std::string.
  • Variable-length string support for vectors and matrices.
  • Automatic group creation from dataset paths like "group/subgroup/data".
  • Clear error reporting via exceptions.

Requirements

  • HDF5 with C++ interface (libhdf5_cpp).
  • C++17 compiler.
  • pkg-config (optional, for automatic flags).

Quick start

#include <vector>
#include <string>
#include "HDF5.hpp"

int main()
{
    HDF5 file("data.h5", HDF5::OpenMode::TRUNC);

    int answer = 42;
    std::vector<double> samples{0.5, 1.5, 2.5};
    std::vector<std::size_t> dims{2, 3};
    std::vector<float> matrix{1, 2, 3, 4, 5, 6};

    file.saveValue("scalars/answer", answer);
    file.saveVector("vectors/samples", samples);
    file.saveMatrix("matrices/float", matrix, dims);

    return 0;
}

Build

make examples

Binaries land in bin/.

Run the examples

./bin/basic
./bin/compound

Tests

make tests
./bin/run_hdf5_tests

API at a glance

HDF5 file("data.h5", HDF5::OpenMode::TRUNC);

file.saveValue("path", value);
file.readValue("path", value_out);

file.saveVector("path", vector);
file.readVector("path", vector_out);

file.saveMatrix("path", vector_or_ptr, dims);
file.readMatrix("path", vector_out, dims_out);

file.saveCompound("path", names, vec1, vec2, ...);
file.readCompound("path", names, vec1_out, vec2_out, ...);

Open modes:

  • RDONLY, RDWR, TRUNC, EXCL, CREAT, SWMR_WRITE, SWMR_READ

Project layout

  • HDF5.hpp: single header with the full implementation.
  • examples/: minimal sample programs.
  • run_hdf5_tests.cpp: integration tests.
  • Makefile: build targets for examples and tests.

Notes

  • Datasets are created with fixed dimensions; pass the full dims you want to store.
  • For compound datasets, all vectors must be the same length and provide matching field names.

If you want a CMake build or extended type support, open an issue or send a PR.

About

A tiny, header-only C++17 wrapper around the HDF5 C++ API that makes common write/read flows painless: scalars, vectors, matrices, and compound datasets. It auto-creates group paths, keeps your data strongly typed, and stays out of your way.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors