Skip to content

Thoemi09/h5

 
 

Repository files navigation

build

h5

h5 is a high-level C++ interface to the hdf5 library, which

  • Provides write and read functions for various STL container types.
  • Provides a generic array_interface to store and load multi-dimensional arrays
  • Takes an RAII approach to manage the reference counting.
  • Comes with Python bindings.

A reference documentation based on Doxygen is provided at triqs.github.io/h5.

Simple Example

Storing and loading a vector of string and a vector of doubles

#include <h5/h5.hpp>
#include <string>
#include <vector>

int main(){

  {
    // Open file in write mode
    h5::file file("vec.h5", 'w');

    std::vector<std::string> vecs = {"a", "b"};
    std::vector<double> vecd      = {1.0, 2.0};

    h5::write(file, "vecs", vecs);
    h5::write(file, "vecd", vecd);

  } // Close file

  {
    // Open file in read mode
    h5::file file("vec.h5", 'r');

    std::vector<std::string> vecs;
    std::vector<double> vecd;

    h5::read(file, "vecs", vecs);
    h5::read(file, "vecd", vecd);

  } // Close file
}

This example will generate an hdf5 file vec.h5 with two datasets

$ h5dump vec.h5

HDF5 "vec.h5" {
GROUP "/" {
   DATASET "vecd" {
      DATATYPE  H5T_IEEE_F64LE
      DATASPACE  SIMPLE { ( 2 ) / ( 2 ) }
      DATA {
      (0): 1, 2
      }
   }
   DATASET "vecs" {
      DATATYPE  H5T_STRING {
         STRSIZE 2;
         STRPAD H5T_STR_NULLTERM;
         CSET H5T_CSET_UTF8;
         CTYPE H5T_C_S1;
      }
      DATASPACE  SIMPLE { ( 2 ) / ( 2 ) }
      DATA {
      (0): "a", "b"
      }
   }
}
}

For further examples we refer the users to our tests.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 69.2%
  • Python 17.7%
  • CMake 12.6%
  • Shell 0.5%