HighFive 2.10.1
HighFive - Header-only C++ HDF5 interface
|
Documentation: https://bluebrain.github.io/HighFive/
HighFive is a modern header-only C++11 friendly interface for libhdf5.
HighFive supports STL vector/string, Boost::UBLAS, Boost::Multi-array and Xtensor. It handles C++ from/to HDF5 with automatic type mapping. HighFive does not require additional libraries (see dependencies).
It integrates nicely with other CMake projects by defining (and exporting) a HighFive target.
std::vector
and nested std::vector
from/to any dataset with basic typesstd::string
to/from variable length string datasetstd::byte
in C++17 mode (with -DCMAKE_CXX_STANDARD=17
or higher)Note: As of 2.8.0, one can use highfive/highfive.hpp
to include everything HighFive. Prior to 2.8.0 one would include highfive/H5File.hpp
.
Note: For advanced usecases the dataset can be created without immediately writing to it. This is common in MPI-IO related patterns, or when growing a dataset over the course of a simulation.
See select_partial_dataset_cpp11.cpp
See create_attribute_string_integer.cpp
See src/examples/ subdirectory for more info.
For several 'standard' use cases the highfive/H5Easy.hpp interface is available. It allows:
HIGHFIVE_USE_EIGEN
),HIGHFIVE_USE_XTENSOR
).HIGHFIVE_USE_OPENCV
).whereby the int
type of this example can be replaced by any of the above types. See easy_load_dump.cpp for more details.
Note: Classes such as H5Easy::File
are just short for the regular HighFive
classes (in this case HighFive::File
). They can thus be used interchangeably.
There's two common paths of integrating HighFive into a CMake based project. The first is to "vendor" HighFive, the second is to install HighFive as a normal C++ library. Due to how HighFive CMake code works, sometimes following the third Bailout Approach is needed.
In this approach the HighFive sources are included in a subdirectory of the project (typically as a git submodule), for example in third_party/HighFive
.
The projects CMakeLists.txt
add the following lines
Note: add_subdirectory(third_party/HighFive)
will search and "link" HDF5 and optional dependencies such as Boost.
Alternatively you can install HighFive once and use it in several projects via find_package()
. First one should clone the sources:
By default CMake will install systemwide, which is likely not appropriate. The instruction below allow users to select a custom path where HighFive will be installed, e.g. HIGHFIVE_INSTALL_PREFIX=${HOME}/third_party/HighFive
or some other location. The CMake invocations would be
This will install (i.e. copy) the headers to ${HIGHFIVE_INSTALL_PREFIX}/include
and some CMake files into an appropriate subfolder of ${HIGHFIVE_INSTALL_PREFIX}
.
The projects CMakeLists.txt
should add the following:
Note: If HighFive hasn't been installed in a default location, CMake needs to be told where to find it which can be done by adding -DCMAKE_PREFIX_PATH=${HIGHFIVE_INSTALL_PREFIX}
to the CMake command for building the project using HighFive. The variable CMAKE_PREFIX_PATH
is a semi-colon ;
separated list of directories.
Note: find_package(HighFive)
will search and "link" HDF5 and optional dependencies such as Boost.
Since both add_subdirectory
and find_package
will trigger finding HDF5 and other optional dependencies of HighFive as well as the target_link_libraries
code for "linking" with the dependencies, things can go wrong.
Fortunately, HighFive is a header only library and all that's needed is the headers. Preferably, the version obtained by installing HighFive, since those include H5Version.hpp
. Let's assume they've been copied to third_party/HighFive
. Then one could create a target:
One known case where this is required is when vendoring the optional dependencies of HighFive.
Do you have questions on how to use HighFive? Would you like to share an interesting example or discuss HighFive features? Head over to the Discussions forum and join the community.
For bugs and issues please use Issues.
The development of this software was supported by funding to the Blue Brain Project, a research center of the École polytechnique fédérale de Lausanne (EPFL), from the Swiss government's ETH Board of the Swiss Federal Institutes of Technology.
Copyright © 2015-2022 Blue Brain Project/EPFL
Boost Software License 1.0