Class h5stream#

Class Documentation#

class h5stream#

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

How to use

 Just include the `h5stream.hpp` into your your main file.
How to Compile

 @code{.bash}
 g++ -lhdf5 -lhdf5_cpp -std=c++1z example.cpp
 @endcode
Example

Create a File with a mode.

   - "tr":   Create a file, truncate if it exists, Default
   - "r":    Readonly, the file must exist
   - "rw": Read/write, the file must exist
   - "x":   Create a file, fail if exists


   @verbatim

    Create a vector and write it to the file


    @verbatim
  • std::vector<double> matrix { 1, 2, 3282, 932 };

  • file.write<double>(matrix, “matrix”);

  • write and read Metadata

      Write Attributes( Metadata) to the to the same data space
    
    
      @verbatim
    
  • auto dspace = file.get_dataspace(“matrix”);

  • dspace.write_atr<double>(1.2, “Units”);

  • Read data from the file

   @verbatim
  • auto xx = file.read_vector<double>(“matrix”);

  • //OR

  • file.read<double>(xx, “matrix”);

  • Read Attribute (Metadata)

    *       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;
    *
    

Public Functions

h5stream() = default#
inline explicit h5stream(const std::string &fileName, const std::string &rw = std::string("tr"))#
inline void setFileName(const H5std_string &fileName, const std::string &rw = std::string("tr"))#

create and set the file name

“rw”: Read-write access. If the file is currently open for read-only access then it will be reopened. Absence of this flag implies read-only access.

“x”: Fail if file already exists. “r” and “tr” are mutually exclusive

“tr”: Truncate file, if it already exists, erasing all data previously stored in the file.: default

Parameters:
  • fileName

  • rw – : Possible values are “r”: read only,

template<typename T = double, template<typename...> class vec>
inline void write(const std::vector<vec<T>> &data, const H5std_string &datasetName)#
template<typename T = double, template<typename...> class vec = std::vector>
inline void write(const vec<T> &data, const H5std_string &datasetName)#
Parameters:
  • data

  • datasetName

template<typename T = double>
inline void write(const H5std_string &datasetName, const T *data, unsigned data_size)#
Template Parameters:

T – : Type of the array

Parameters:
  • data – : Array that needs to stored

  • dataname – : DataSet name

template<typename T = double, template<typename...> class vec = std::vector>
inline void read(vec<T> &data, const H5std_string &datasetName)#
Parameters:
  • data – : Array that needs to stored

  • dataname – : DataSet name

template<typename T = double, template<typename...> class vec>
inline void read(std::vector<vec<T>> &data, const H5std_string &datasetName)#

Read the data.

Parameters:
  • data – : Array of data

  • datasetName – : dataset name

inline void close()#

close the file

inline double fileSize() const#

Return the filesize in MB.

Returns:

inline dspace getDataspace(const H5std_string &dataset_name)#
Parameters:

dataset_name – : dataset name

Returns:

inline gspace getGroup(const H5std_string &dataset_name)#
Parameters:

dataset_name – : DataSet name

Returns:

inline auto createGroup(const H5std_string &group_name)#

Create a group name.

Parameters:

group_name – : Group name

Returns:

template<typename T>
inline void writeMetadata(const T &data, const H5std_string &label)#

Write Metadata.

Template Parameters:

T – : Type of the array

Parameters:
  • data – : Array that needs to stored

  • dataname – : DataSet name

template<typename T>
inline void readMetadata(T &data, const H5std_string &label)#
Template Parameters:

T – : Type of the array

Parameters:
  • data – : Array that needs to stored

  • dataname – : DataSet name

Public Members

H5std_string hdf5FileName#
H5::H5File hdf5File#

Friends

template<typename T>
inline friend h5stream &operator<<(h5stream &out, const h5str1<T> &struct1)#
template<typename T>
inline friend h5stream &operator>>(h5stream &out, const h5str1<T> &struct1)#