├── TODO ├── examples ├── kita │ ├── README.md │ ├── Makefile │ └── kita.cpp ├── mpi │ ├── README.md │ ├── collective.cpp │ ├── independent.cpp │ └── throughput.cpp ├── datatypes │ ├── README.md │ ├── Makefile │ ├── two-bit.cpp │ ├── n-bit.hpp │ ├── two-bit.hpp │ └── n-bit.cpp ├── custom_pipeline │ ├── pipeline.cpp │ └── Makefile ├── csv │ ├── struct.h │ ├── Makefile │ ├── generated.h │ ├── LICENSE.txt │ └── csv2hdf5.cpp ├── stl │ ├── utils.hpp │ ├── Makefile │ ├── struct.h │ ├── vector.cpp │ └── generated.h ├── multi-tu │ ├── utils.hpp │ ├── main.cpp │ ├── tu-01.cpp │ ├── tu-02.cpp │ ├── Makefile │ ├── struct.h │ └── tu-02.h ├── attributes │ ├── utils.hpp │ ├── Makefile │ ├── struct.h │ └── generated.h ├── packet-table │ ├── utils.hpp │ ├── Makefile │ ├── struct.h │ ├── generated.h │ └── packettable.cpp ├── half-float │ ├── open-exr │ │ ├── utils.hpp │ │ ├── Makefile │ │ ├── half-float.cpp │ │ └── README.md │ └── christian-rau │ │ ├── utils.hpp │ │ ├── Makefile │ │ ├── README.md │ │ ├── LICENSE.txt │ │ └── half-float.cpp ├── sparse │ ├── Makefile │ └── arma.cpp ├── string │ ├── Makefile │ └── string.cpp ├── compound │ ├── utils.hpp │ ├── Makefile │ ├── struct.h │ └── struct.cpp ├── transform │ ├── Makefile │ └── transform.cpp ├── groups │ ├── Makefile │ ├── README.md │ └── groups.cpp ├── raw_memory │ ├── Makefile │ └── raw.cpp ├── optimized │ ├── Makefile │ └── optimized.cpp ├── container │ ├── Makefile │ ├── README.md │ └── container.cpp ├── datasets │ ├── Makefile │ ├── datasets.cpp │ └── README.md ├── utf │ ├── Makefile │ └── utf.cpp ├── reference │ ├── Makefile │ └── reference.cpp ├── basics │ └── Makefile ├── linalg │ ├── Makefile │ ├── dlib.cpp │ ├── itpp.cpp │ ├── blitz.cpp │ ├── arma.cpp │ ├── ublas.cpp │ ├── blaze.cpp │ └── eigen3.cpp └── Makefile ├── CONTRIBUTORS ├── h5cpp ├── H5Dscatter.hpp ├── H5Adelete.hpp ├── all ├── io ├── H5Aopen.hpp ├── H5Fopen.hpp ├── core ├── H5Ialgorithm.hpp ├── H5Mdlib.hpp ├── H5Acreate.hpp ├── H5Pdapl.hpp ├── H5Dopen.hpp ├── H5Dgather.hpp ├── H5Zpipeline_basic.hpp ├── H5Fcreate.hpp ├── H5Mitpp.hpp ├── H5Mublas.hpp ├── H5misc.hpp ├── H5Mblaze.hpp ├── H5Mstl.hpp ├── H5Marma.hpp └── H5Zall.hpp ├── cmake └── config.cmake.in ├── h5cpp.pc ├── configure ├── CHANGES ├── LICENSE.HALF-FLOAT ├── .gitignore ├── COPYRIGHT ├── LICENSE.CSV ├── Makefile ├── LICENSE.H5CPP ├── LICENSE.HDF5_LBNL ├── INSTALL └── LICENSE.LLVM /TODO: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/kita/README.md: -------------------------------------------------------------------------------- 1 | ## MPI examples 2 | 3 | 4 | -------------------------------------------------------------------------------- /examples/mpi/README.md: -------------------------------------------------------------------------------- 1 | ## MPI examples 2 | 3 | 4 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Steven Varga - author 2 | Gerd Heber - collaborator from HDFGroup 3 | Gilles Filippini - debian packaging: sponsor and collaborator 4 | -------------------------------------------------------------------------------- /examples/datatypes/README.md: -------------------------------------------------------------------------------- 1 | #custom datatype support 2 | 3 | The examples outline how to interact with H5CPP and inherently HDF5 type system. 4 | 5 | 6 | -------------------------------------------------------------------------------- /h5cpp/H5Dscatter.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 - 2021 vargaconsulting, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #ifndef H5CPP_DSCATTER_HPP 6 | #define H5CPP_DSCATTER_HPP 7 | #endif -------------------------------------------------------------------------------- /cmake/config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | get_filename_component(CURRENT_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) 3 | 4 | include(${CURRENT_CMAKE_DIR}/h5cpp-config-version.cmake) 5 | 6 | include(${CURRENT_CMAKE_DIR}/h5cpp-targets.cmake) 7 | -------------------------------------------------------------------------------- /h5cpp/H5Adelete.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #ifndef H5CPP_ADELETE_HPP 6 | #define H5CPP_ADELETE_HPP 7 | 8 | #endif 9 | 10 | -------------------------------------------------------------------------------- /h5cpp/all: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #ifndef H5CPP_ALL_H 6 | #define H5CPP_ALL_H 7 | #include "core" 8 | #include "io" 9 | #endif 10 | 11 | -------------------------------------------------------------------------------- /h5cpp.pc: -------------------------------------------------------------------------------- 1 | 2 | Name: h5cpp 3 | Description: C++17 template library for major linear algebra systems and the STL 4 | URL: h5cpp.ca 5 | Version: 1.10.4.5-1 6 | Requires: hdf5 7 | Cflags: -I/usr/include/h5cpp -std=c++17 8 | Libs: -lhdf5 -lz -ldl -lm 9 | 10 | -------------------------------------------------------------------------------- /examples/custom_pipeline/pipeline.cpp: -------------------------------------------------------------------------------- 1 | #include "h5cpp/all" 2 | 3 | int main() { 4 | std::vector v(100, 2.); 5 | auto fd = h5::create("test.h5", H5F_ACC_TRUNC); 6 | //FIXME: reference count problems... 7 | h5::write(fd, "dataset", v, h5::chunk{2}, h5::high_throughput); 8 | } 9 | -------------------------------------------------------------------------------- /examples/csv/struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #ifndef CSV2H5_H 7 | #define CSV2H5_H 8 | 9 | constexpr int STR_ARRAY_SIZE = 20; 10 | /*define C++ representation as POD struct*/ 11 | struct input_t { 12 | long MasterRecordNumber; 13 | unsigned int Hour; 14 | double Latitude; 15 | double Longitude; 16 | char ReportedLocation[STR_ARRAY_SIZE]; 17 | }; 18 | #endif 19 | -------------------------------------------------------------------------------- /examples/stl/utils.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include "struct.h" 6 | #include 7 | 8 | namespace h5 { namespace utils { 9 | // template specialization 10 | template <> inline std::vector get_test_data( size_t n ){ 11 | std::vector vec (n); 12 | for(int i=0; i 4 | */ 5 | 6 | #include "struct.h" 7 | #include 8 | 9 | namespace h5 { namespace utils { 10 | // template specialization 11 | template <> inline std::vector get_test_data( size_t n ){ 12 | std::vector vec (n); 13 | for(int i=0; i 4 | */ 5 | 6 | #include "struct.h" 7 | #include 8 | 9 | namespace h5 { namespace utils { 10 | // template specialization 11 | template <> inline std::vector get_test_data( size_t n ){ 12 | std::vector vec (n); 13 | for(int i=0; i/dev/null 2>&1 || 7 | { 8 | echo "error: cmake (version 3.10 or later) must be present to configure and install h5cpp" 9 | echo "" 10 | echo "cmake might be available as a package for your system," 11 | echo "or can be downloaded from http://cmake.org" 12 | ABORT=yes 13 | } 14 | } 15 | 16 | check_cmake 17 | 18 | test "$ABORT" = yes && exit -1 19 | 20 | rm -f CMakeCache.txt 21 | cmake $@ . 22 | 23 | -------------------------------------------------------------------------------- /examples/packet-table/utils.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #include "struct.h" 7 | #include 8 | 9 | namespace h5 { namespace utils { 10 | // template specialization 11 | template <> inline std::vector get_test_data( size_t n ){ 12 | std::vector vec (n); 13 | for(int i=0; i 4 | */ 5 | 6 | #include 7 | 8 | namespace h5 { namespace utils { 9 | 10 | template <> inline std::vector get_test_data( size_t n ){ 11 | std::random_device rd; 12 | std::mt19937 eng(rd()); 13 | std::uniform_real_distribution distr(-1e2, 1e2); 14 | 15 | std::vector vec (n); 16 | for(int i=0; i 4 | */ 5 | 6 | #ifndef H5CPP_IO_H 7 | #define H5CPP_IO_H 8 | 9 | #include "H5Fcreate.hpp" 10 | #include "H5Fopen.hpp" 11 | 12 | #include "H5Dcreate.hpp" 13 | #include "H5Dopen.hpp" 14 | #include "H5Rall.hpp" 15 | #include "H5Dwrite.hpp" 16 | #include "H5Dread.hpp" 17 | #include "H5Dappend.hpp" 18 | 19 | #include "H5Acreate.hpp" 20 | #include "H5Aopen.hpp" 21 | #include "H5Awrite.hpp" 22 | #include "H5Aread.hpp" 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /examples/sparse/Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | # 6 | apps = arma 7 | 8 | CXXFLAGS = -Wno-deprecated -Wall 9 | LIBS = -lhdf5 -lz -ldl -lm 10 | 11 | test: clean $(apps) 12 | @./arma 13 | 14 | all: $(apps) 15 | 16 | arma: arma.cpp 17 | $(CXX) $^ $(LIBS) -o $@ 18 | 19 | clean: 20 | @$(RM) *.o *.prof *.h5 $(apps) 21 | 22 | dist-clean: clean 23 | .PHONY: test 24 | 25 | -------------------------------------------------------------------------------- /examples/half-float/christian-rau/utils.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #include 7 | 8 | namespace h5 { namespace utils { 9 | using namespace half_float::literal; 10 | using half_float::half; 11 | template <> inline std::vector get_test_data( size_t n ){ 12 | std::random_device rd; 13 | std::mt19937 eng(rd()); 14 | std::uniform_real_distribution distr(-1e2, 1e2); 15 | 16 | std::vector vec (n); 17 | for(int i=0; i 4 | # _________________________________________________________ 5 | 6 | CXXFLAGS = -std=c++17 -I/usr/include 7 | LIBS = -lhdf5 -lz -ldl -lm 8 | 9 | apps = string 10 | 11 | test: string 12 | ./string 13 | 14 | 15 | %.o : $(SRC_DIR)/%.cpp 16 | $(CXX) -$(INCLUDES) -o $@ $(CPPFLAGS) $(CXXFLAGS) -c $^ 17 | 18 | string: string.o 19 | $(CXX) $^ $(LIBS) -o $@ 20 | 21 | clean: 22 | @$(RM) *.o *.h5 $(apps) 23 | 24 | dist-clean: clean 25 | .PHONY: test 26 | 27 | -------------------------------------------------------------------------------- /examples/compound/utils.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include "struct.h" 6 | #include 7 | 8 | namespace h5::utils { 9 | // template specialization 10 | template <> inline std::vector get_test_data( size_t n ){ 11 | std::vector vec (n); 12 | for(int i=0; i inline std::vector get_test_data( size_t n ){ 17 | std::vector vec (n); 18 | for(int i=0; i 4 | # _________________________________________________________ 5 | 6 | apps = transform 7 | CXXFLAGS = -std=c++17 8 | LIBS = -lhdf5 -lz -ldl -lm 9 | test: $(apps) 10 | @./transform 11 | 12 | %.o : $(SRC_DIR)/%.cpp 13 | $(CXX) -$(INCLUDES) -o $@ $(CPPFLAGS) $(CXXFLAGS) -c $^ 14 | 15 | all: $(apps) 16 | 17 | transform: transform.o 18 | $(CXX) $^ $(LIBS) -o $@ 19 | 20 | clean: 21 | @$(RM) *.o *.prof *.h5 $(apps) 22 | 23 | dist-clean: clean 24 | .PHONY: test 25 | 26 | -------------------------------------------------------------------------------- /examples/groups/Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | apps = groups 6 | 7 | CXXFLAGS = -std=c++17 -Wno-deprecated 8 | LIBS = -lhdf5 -lz -ldl -lm 9 | 10 | test: $(apps) 11 | @./groups 12 | 13 | %.o : $(SRC_DIR)/%.cpp 14 | $(CXX) -$(INCLUDES) -o $@ $(CPPFLAGS) $(CXXFLAGS) -c $^ 15 | 16 | all: $(apps) 17 | 18 | groups: groups.o 19 | $(CXX) $^ $(LIBS) -o $@ 20 | 21 | clean: 22 | @$(RM) *.o *.prof *.h5 $(apps) 23 | 24 | dist-clean: clean 25 | .PHONY: test 26 | 27 | -------------------------------------------------------------------------------- /examples/raw_memory/Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | apps = raw 6 | CXXFLAGS = -std=c++17 7 | LIBS = -lhdf5 -lz -ldl -lm 8 | 9 | test: $(apps) 10 | @./raw 11 | h5dump -d dataset raw.h5 12 | 13 | %.o : $(SRC_DIR)/%.cpp 14 | $(CXX) -$(INCLUDES) -o $@ $(CPPFLAGS) $(CXXFLAGS) -c $^ 15 | 16 | all: $(apps) 17 | 18 | raw: raw.o 19 | $(CXX) $^ $(LIBS) -o $@ 20 | 21 | clean: 22 | @$(RM) *.o *.prof *.h5 $(apps) 23 | 24 | dist-clean: clean 25 | .PHONY: test 26 | 27 | -------------------------------------------------------------------------------- /examples/optimized/Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | apps = optimized 6 | CXXFLAGS = -std=c++17 -Wno-deprecated 7 | LIBS = -lhdf5 -lz -ldl -lm 8 | 9 | test: $(apps) 10 | @./$(apps) 11 | 12 | %.o : $(SRC_DIR)/%.cpp 13 | $(CXX) -$(INCLUDES) -o $@ $(CPPFLAGS) $(CXXFLAGS) -c $^ 14 | 15 | all: $(apps) 16 | 17 | optimized: optimized.o 18 | $(CXX) $^ $(LIBS) -o $@ 19 | 20 | clean: 21 | @$(RM) *.o *.prof *.h5 $(apps) 22 | 23 | dist-clean: clean 24 | 25 | .PHONY: test 26 | 27 | -------------------------------------------------------------------------------- /examples/container/Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | apps = datasets 6 | 7 | CXXFLAGS = -std=c++17 -Wno-deprecated 8 | LIBS = -lhdf5 -lz -ldl -lm 9 | 10 | test: $(apps) 11 | @./datasets 12 | 13 | %.o : $(SRC_DIR)/%.cpp 14 | $(CXX) -$(INCLUDES) -o $@ $(CPPFLAGS) $(CXXFLAGS) -c $^ 15 | 16 | all: $(apps) 17 | 18 | datasets: datasets.o 19 | $(CXX) $^ $(LIBS) -o $@ 20 | 21 | clean: 22 | @$(RM) *.o *.prof *.h5 $(apps) 23 | 24 | dist-clean: clean 25 | 26 | .PHONY: test 27 | 28 | -------------------------------------------------------------------------------- /examples/datasets/Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | 6 | apps = datasets 7 | 8 | CXXFLAGS = -std=c++17 -Wno-deprecated 9 | LIBS = -lhdf5 -lz -ldl -lm 10 | 11 | test: $(apps) 12 | @./datasets 13 | 14 | %.o : $(SRC_DIR)/%.cpp 15 | $(CXX) -$(INCLUDES) -o $@ $(CPPFLAGS) $(CXXFLAGS) -c $^ 16 | 17 | all: $(apps) 18 | 19 | datasets: datasets.o 20 | $(CXX) $^ $(LIBS) -o $@ 21 | 22 | clean: 23 | @$(RM) *.o *.prof *.h5 $(apps) 24 | 25 | dist-clean: clean 26 | 27 | .PHONY: test 28 | 29 | -------------------------------------------------------------------------------- /examples/kita/Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | apps = kita 6 | CXX=mpic++ 7 | CXXFLAGS = -std=c++17 -Wno-deprecated 8 | LIBS = -lrestvol -lcurl -lyajl -lhdf5 -lz -ldl -lm 9 | 10 | test: $(apps) 11 | @./kita 12 | 13 | %.o : $(SRC_DIR)/%.cpp 14 | $(CXX) -$(INCLUDES) -o $@ $(CPPFLAGS) $(CXXFLAGS) -c $^ 15 | 16 | all: $(apps) 17 | 18 | kita: kita.o 19 | $(CXX) $^ $(LIBS) -o $@ 20 | 21 | clean: 22 | @$(RM) *.o *.prof *.h5 $(apps) 23 | 24 | dist-clean: clean 25 | 26 | .PHONY: test 27 | 28 | -------------------------------------------------------------------------------- /examples/utf/Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | 6 | apps = utf 7 | CXXFLAGS = -std=c++17 8 | LIBS = -lhdf5 -lz -ldl -lm 9 | INCLUDES = -I/usr/local/include -I/usr/include 10 | 11 | test: $(apps) 12 | @./utf 13 | 14 | %.o : $(SRC_DIR)/%.cpp 15 | $(CXX) -$(INCLUDES) -o $@ $(CPPFLAGS) $(CXXFLAGS) -c $^ 16 | 17 | all: $(apps) 18 | 19 | utf: utf.o 20 | $(CXX) $^ $(LIBS) -o $@ 21 | 22 | clean: 23 | @$(RM) *.o *.prof *.h5 $(apps) generated.h 24 | 25 | dist-clean: clean 26 | .PHONY: test 27 | 28 | -------------------------------------------------------------------------------- /examples/half-float/christian-rau/Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | 6 | CXXFLAGS = -std=c++17 7 | LIBS = -lhdf5 -lz -ldl -lm 8 | INCLUDES = -I/usr/local/include -I/usr/include -I./ 9 | 10 | test: half-float 11 | ./half-float 12 | 13 | half-float.o : half-float.cpp 14 | $(CXX) $(INCLUDES) -o half-float.o $(CXXFLAGS) -c half-float.cpp 15 | 16 | half-float: half-float.o 17 | $(CXX) $^ $(LIBS) -o $@ 18 | 19 | clean: 20 | @$(RM) *.o *.h5 half-float 21 | 22 | dist-clean: clean 23 | .PHONY: test 24 | 25 | -------------------------------------------------------------------------------- /examples/reference/Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2021 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | 6 | CXXFLAGS = -std=c++17 7 | LIBS = -lhdf5 -lz -ldl -lm 8 | INCLUDES = -I/usr/local/include -I/usr/include 9 | 10 | test: reference 11 | ./reference 12 | h5dump ref.h5 13 | 14 | reference.o : reference.cpp 15 | $(CXX) $(INCLUDES) -o reference.o $(CXXFLAGS) -c reference.cpp 16 | 17 | reference: reference.o 18 | $(CXX) $^ $(LIBS) -o $@ 19 | 20 | clean: 21 | @$(RM) *.o *.h5 $(apps) reference 22 | 23 | dist-clean: clean 24 | .PHONY: test 25 | 26 | 27 | -------------------------------------------------------------------------------- /examples/basics/Makefile: -------------------------------------------------------------------------------- 1 | # _____________________________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _____________________________________________________________________________ 5 | 6 | apps = basics 7 | 8 | CXXFLAGS = -std=c++17 -Wall 9 | LIBS = -lhdf5 -lz -ldl -lm 10 | 11 | test: $(apps) 12 | @./basics 13 | #h5dump -pH 004.h5 14 | 15 | %.o : $(SRC_DIR)/%.cpp 16 | $(CXX) -$(INCLUDES) -o $@ $(CPPFLAGS) $(CXXFLAGS) -c $^ 17 | 18 | all: $(apps) 19 | 20 | basics: basics.o 21 | $(CXX) $^ $(LIBS) -o $@ 22 | 23 | clean: 24 | @$(RM) *.o *.prof *.h5 $(apps) 25 | 26 | dist-clean: clean 27 | 28 | .PHONY: test 29 | 30 | -------------------------------------------------------------------------------- /examples/custom_pipeline/Makefile: -------------------------------------------------------------------------------- 1 | # _____________________________________________________________________________ 2 | # Copyright (c) 2018-2021 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _____________________________________________________________________________ 5 | 6 | apps = pipeline 7 | 8 | CXXFLAGS = -std=c++17 -Wno-deprecated 9 | LIBS = -lhdf5 -lz -ldl -lm 10 | 11 | test: $(apps) 12 | @./pipeline 13 | #h5dump -pH 004.h5 14 | 15 | %.o : $(SRC_DIR)/%.cpp 16 | $(CXX) -$(INCLUDES) -o $@ $(CPPFLAGS) $(CXXFLAGS) -c $^ 17 | 18 | all: $(apps) 19 | 20 | pipeline: pipeline.o 21 | $(CXX) $^ $(LIBS) -o $@ 22 | 23 | clean: 24 | @$(RM) *.o *.prof *.h5 $(apps) 25 | 26 | dist-clean: clean 27 | 28 | .PHONY: test 29 | 30 | -------------------------------------------------------------------------------- /examples/multi-tu/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include 6 | // this TU only needs to know of h5::fd_t 7 | // no `sandwitching` between and needed 8 | #include 9 | 10 | 11 | 12 | // of course the function prototype definitions needs to be here, preferably factored out: 13 | 14 | void test_01( const h5::fd_t& fd ); 15 | void test_02( const h5::fd_t& fd ); 16 | void test_03( const h5::fd_t& fd ); 17 | void test_04( const h5::fd_t& fd ); 18 | 19 | 20 | int main(){ 21 | 22 | 23 | h5::fd_t fd = h5::create("example.h5",H5F_ACC_TRUNC); 24 | 25 | test_01( fd ); 26 | test_02( fd ); 27 | test_03( fd ); 28 | test_04( fd ); 29 | } 30 | -------------------------------------------------------------------------------- /examples/half-float/open-exr/Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | 6 | CXXFLAGS = -std=c++17 -DWITH_OPENEXR_HALF `pkg-config --cflags IlmBase` 7 | LIBS = -lhdf5 -lz -ldl -lm `pkg-config --libs IlmBase` 8 | INCLUDES = -I/usr/local/include -I/usr/include -I./ 9 | 10 | test: half-float 11 | ./half-float 12 | 13 | half-float.o : half-float.cpp 14 | $(CXX) $(INCLUDES) -o half-float.o $(CXXFLAGS) -c half-float.cpp 15 | 16 | half-float: half-float.o 17 | $(CXX) $^ $(LIBS) -o $@ 18 | 19 | clean: 20 | @$(RM) *.o *.h5 half-float 21 | 22 | dist-clean: clean 23 | .PHONY: test 24 | 25 | -------------------------------------------------------------------------------- /examples/csv/Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | 6 | CXXFLAGS = -std=c++17 7 | LIBS = -lhdf5 -lz -ldl -lm -lpthread 8 | INCLUDES = -I/usr/local/include -I/usr/include -I./ 9 | 10 | test: csv2hdf5 11 | ./csv2hdf5 12 | 13 | generated.h: csv2hdf5.cpp 14 | h5cpp csv2hdf5.cpp -- $(CXXFLAGS) $(INCLUDES) -Dgenerated.h 15 | 16 | csv2hdf5.o : csv2hdf5.cpp generated.h 17 | $(CXX) $(INCLUDES) -o csv2hdf5.o $(CXXFLAGS) -c csv2hdf5.cpp 18 | 19 | csv2hdf5: csv2hdf5.o 20 | $(CXX) $^ $(LIBS) -o $@ 21 | 22 | clean: 23 | @$(RM) *.o *.h5 csv2hdf5 24 | 25 | dist-clean: clean 26 | @$(RM) generated.h 27 | .PHONY: test 28 | 29 | -------------------------------------------------------------------------------- /h5cpp/H5Aopen.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #ifndef H5CPP_AOPEN_HPP 6 | #define H5CPP_AOPEN_HPP 7 | namespace h5 { 8 | template 9 | inline typename std::enable_if::value, 10 | h5::at_t>::type open(const HID_T& parent, const std::string& path, const h5::acpl_t& acpl = h5::default_acpl ){ 11 | 12 | H5CPP_CHECK_PROP( acpl, h5::error::io::attribute::open, "invalid attribute creation property" ); 13 | hid_t attr = H5I_UNINIT; 14 | H5CPP_CHECK_NZ(( 15 | attr = H5Aopen( static_cast(parent), path.c_str(), static_cast(acpl))), 16 | h5::error::io::attribute::open, "can't open attribute..." ); 17 | return h5::at_t{attr}; 18 | } 19 | } 20 | #endif 21 | 22 | -------------------------------------------------------------------------------- /examples/datatypes/Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | 6 | CXXFLAGS = -std=c++17 7 | LIBS = -lhdf5 -lz -ldl -lm 8 | INCLUDES = -I/usr/local/include -I/usr/include -I/usr/include/eigen3 -I./ 9 | test: two-bit n-bit 10 | ./n-bit 11 | 12 | two-bit.o : two-bit.cpp 13 | $(CXX) $(INCLUDES) -o two-bit.o $(CXXFLAGS) -c two-bit.cpp 14 | 15 | two-bit: two-bit.o 16 | $(CXX) $^ $(LIBS) -o $@ 17 | 18 | n-bit.o : n-bit.cpp 19 | $(CXX) $(INCLUDES) -o n-bit.o $(CXXFLAGS) -c n-bit.cpp 20 | 21 | n-bit: n-bit.o 22 | $(CXX) $^ $(LIBS) -o $@ 23 | 24 | clean: 25 | @$(RM) *.o *.h5 n-bit two-bit 26 | 27 | dist-clean: clean 28 | .PHONY: test 29 | 30 | -------------------------------------------------------------------------------- /CHANGES: -------------------------------------------------------------------------------- 1 | 2020 jan 06 added half float support 2 | 2020 jan 04 fixed clang compile problem for version 6.0 3 | added distclean target to example make files to reset generated header files 4 | 2019 oct 20 std::tuple creates multiple objects 5 | 2019 oct 20 added README-s to examples 6 | 2019 oct 09 fixed property list version related problems, added some missing properties 7 | 2019 jun 19 kita support 8 | 2019 jun 16 MPI support 9 | 2019 jun 15 cmake in addition to unix make 10 | 2019 feb 04 extended and improved packet table 11 | 2019 jan 23 moved h5cpp compiler to separate project; experimental high throughput pipeline 12 | 2018 dec 23 attributes with operators and h5cpp compiler assisted reflection 13 | 2018 jul 11 LLVM based compile time reflection: h5cpp tool 14 | 2018 may 13 property lists added 15 | 2018 feb 28 Linalg libraries: ETL, dlib, blaze, blitz++, it++, boost, eigen3 16 | 2017 dec 08 Project Started 17 | -------------------------------------------------------------------------------- /examples/stl/Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | 6 | CXXFLAGS = -std=c++17 -I/usr/local/include 7 | LIBS = -lhdf5 -lz -ldl -lm 8 | 9 | apps = vector 10 | 11 | test: vector 12 | ./vector 13 | # STL container examples uses generated.h from `../compound` example, where h5cpp compiler 14 | # automatically produces this file, containing the type descriptors. 15 | # 16 | 17 | generated.h: struct.h 18 | h5cpp vector.cpp -- $(CXXFLAGS) -Dgenerated.h 19 | 20 | vector.o : vector.cpp generated.h 21 | $(CXX) $(INCLUDES) -o vector.o $(CXXFLAGS) -c vector.cpp 22 | 23 | vector: vector.o 24 | $(CXX) $^ $(LIBS) -o $@ 25 | 26 | clean: 27 | @$(RM) *.o *.h5 $(apps) 28 | 29 | dist-clean: clean 30 | @$(RM) generated.h 31 | 32 | .PHONY: test 33 | 34 | -------------------------------------------------------------------------------- /examples/linalg/Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | # 6 | apps = arma eigen3 blaze itpp ublas dlib 7 | 8 | CXXFLAGS = -std=c++17 -Wno-deprecated -Wall 9 | LIBS = -lhdf5 -lz -ldl -lm 10 | INCLUDES=/usr/include/eigen3 11 | 12 | test: $(apps) 13 | $(foreach app, $(apps), ./$(app) ) 14 | 15 | all: $(apps) 16 | 17 | arma: arma.cpp 18 | $(CXX) $^ $(LIBS) $(CXXFLAGS) -o $@ 19 | 20 | blaze: blaze.cpp 21 | $(CXX) $^ $(LIBS) $(CXXFLAGS) -o $@ 22 | 23 | itpp: itpp.cpp 24 | $(CXX) $^ $(LIBS) $(CXXFLAGS) -litpp -o $@ 25 | 26 | eigen3: eigen3.cpp 27 | $(CXX) $(CXXFLAGS) -I/usr/include/eigen3 $^ $(LIBS) -o $@ 28 | 29 | ublas: ublas.cpp 30 | $(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@ 31 | 32 | dlib: dlib.cpp 33 | $(CXX) $(CXXFLAGS) $^ $(LIBS) -ldlib -o $@ 34 | 35 | clean: 36 | @$(RM) *.o *.prof *.h5 $(apps) 37 | 38 | dist-clean: clean 39 | .PHONY: test 40 | 41 | -------------------------------------------------------------------------------- /examples/half-float/christian-rau/README.md: -------------------------------------------------------------------------------- 1 | half float support 2 | -------------------- 3 | 4 | Obtain Chistian Rau's half float implementation [from this link](http://half.sourceforge.net/) 5 | 6 | The IEEE 754 standard specifies a binary16 as having the following format: 7 | - Sign bit: 1 bit 8 | - Exponent width: 5 bits 9 | - Significand precision: 11 bits (10 explicitly stored) 10 | 11 | The format is laid out as follows: 12 | `[1 bit sign | 5 bit exponent | 10 bit mantissa]` the exponent encoded using an offset-binary representation, with the zero offset being 15. 13 | 14 | **compiler assisted reflection:** not available, as half is not a POD type, but standard layout, keep tuned... 15 | 16 | ```bash 17 | HDF5 "example.h5" { 18 | GROUP "/" { 19 | DATASET "type" { 20 | DATATYPE 16-bit little-endian floating-point 21 | DATASPACE SIMPLE { ( 20 ) / ( 20 ) } 22 | DATA { 23 | (0): 55.7812, 89.375, 90.125, -29.3906, -90.3125, -48.4688, -1.17871, 24 | (7): 55.1875, -21.6719, 12.7578, -63.7188, 9.22656, 50.625, 37.0938, 25 | (14): -81.8125, -32.7812, 89.5, -28.3906, -44.125, -41.125 26 | } 27 | } 28 | } 29 | } 30 | ``` 31 | -------------------------------------------------------------------------------- /examples/transform/transform.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include 6 | #include 7 | 8 | 9 | // see: https://support.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-SetTypeConvCb 10 | H5T_conv_ret_t handler( H5T_conv_except_t except_type, hid_t src_id, hid_t dst_id, void *src_buf, void *dst_buf, void *op_data){ 11 | return H5T_CONV_HANDLED; 12 | } 13 | 14 | int main(){ 15 | { // CREATE - WRITE 16 | h5::fd_t fd = h5::create("arma.h5",H5F_ACC_TRUNC); 17 | arma::mat M(4,7); M.ones(); // create a matrix 18 | 19 | h5::write(fd,"transform", M, 20 | // data transform provides linear transformation from character descriptions 21 | // linear operators {*,/,+,-} allowed on x variable: 22 | h5::data_transform{"2*x+5"} ); 23 | } 24 | { // READ back, pass conversion handler -- if internal conversion fails, and a 25 | // data transform expression 26 | auto m = h5::read("arma.h5","transform", 27 | h5::type_conv_cb{ {handler, nullptr} } | h5::data_transform{"x/2 + 1"}); 28 | m.print(); 29 | } 30 | 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /examples/utf/utf.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | void test_case(const h5::fd_t fd, const std::string& path ){ 12 | arma::mat M = arma::ones(5,6); 13 | h5::ds_t ds = h5::write(fd, path, M); 14 | ds[path.data()] = path ; 15 | } 16 | 17 | int main(){ 18 | { 19 | h5::fd_t fd = h5::create("こんにちは世界.h5", H5F_ACC_TRUNC, h5::default_fcpl, 20 | h5::libver_bounds({H5F_LIBVER_V18, H5F_LIBVER_V18}) ); 21 | std::string utf8 [] = { 22 | "hello world", "مرحبا بالعالم", "Բարեւ աշխարհ", "Здравей свят","Прывітанне Сусвет","မင်္ဂလာပါကမ္ဘာလောက","你好,世界", 23 | "Γειά σου Κόσμε","હેલ્લો વિશ્વ","Helló Világ","こんにちは世界","안녕 세상","سلام دنیا","העלא וועלט"}; 24 | for( auto name : utf8 ) 25 | test_case(fd, name); 26 | } 27 | { 28 | try { 29 | h5::fd_t fd = h5::open("こんにちは世界.h5", H5F_ACC_RDWR); 30 | auto m = h5::read(fd, "مرحبا بالعالم" ); 31 | } catch( const h5::error::any& err ){ 32 | std::cerr << "ERROR:" << err.what(); 33 | } 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /LICENSE.HALF-FLOAT: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2012-2019 Christian Rau 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/half-float/christian-rau/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2012-2019 Christian Rau 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/datatypes/two-bit.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include // include this before custom type definition 11 | #include "two-bit.hpp" 12 | #include // IO operators become aware of your custom type 13 | 14 | int main(){ 15 | namespace nm = bitstring; 16 | 17 | h5::fd_t fd = h5::create("example.h5",H5F_ACC_TRUNC); 18 | // prints out type info, eases on debugging 19 | std::cout << h5::dt_t() << std::endl; 20 | 21 | std::vector vec = {0xff,0x0f,0xf0,0x00,0b0001'1011}; 22 | 23 | /* H5CPP operators are aware of your dataype, will do the right thing 24 | */ 25 | h5::write(fd,"data", vec); // single shot write 26 | auto data = h5::read>(fd, "data"); 27 | 28 | for( int i=0; i 4 | # _________________________________________________________ 5 | CXXFLAGS = -std=c++17 6 | LIBS = -lhdf5 -lz -ldl -lm 7 | INCLUDES = -I/usr/local/include -I/usr/include 8 | 9 | test: struct 10 | ./struct 11 | 12 | # compiler assisted introspection will scan TU translation unit, which is the 13 | # collection of files you're compiling into an object, generates desired output 14 | # from topologically ordered dependency graph. 15 | # currently POD structs, arrays and integral types are supported, in arbitrary deep 16 | # embedding 17 | # 18 | # with -Dmyfile.h specifies the generated output, which must be sandwiched between 19 | # and 20 | generated.h: struct.h 21 | h5cpp struct.cpp -- $(CXXFLAGS) $(INCLUDES) -Dgenerated.h 22 | 23 | struct.o : struct.cpp generated.h 24 | $(CXX) $(INCLUDES) -o struct.o $(CXXFLAGS) -c struct.cpp 25 | 26 | struct: struct.o 27 | $(CXX) $^ $(LIBS) -o $@ 28 | 29 | clean: 30 | @$(RM) *.o *.h5 $(apps) struct 31 | 32 | dist-clean: clean 33 | @$(RM) generated.h 34 | .PHONY: test 35 | 36 | -------------------------------------------------------------------------------- /examples/Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | 6 | DIRS = attributes basics compound csv datatypes half-float/christian-rau \ 7 | multi-tu optimized packet-table raw_memory stl string transform utf 8 | #to yank: groups kita mpi sparse 9 | #basics compound packet-table raw_memory linalg transform multi-tu stl utf 10 | 11 | BUILDDIRS = $(DIRS:%=build-%) 12 | CLEANDIRS = $(DIRS:%=clean-%) 13 | DISTCLEANDIRS = $(DIRS:%=dist-clean-%) 14 | TESTDIRS = $(DIRS:%=test-%) 15 | 16 | all: $(BUILDDIRS) 17 | $(DIRS): $(BUILDDIRS) 18 | $(BUILDDIRS): 19 | $(MAKE) -C $(@:build-%=%) 20 | 21 | install: 22 | 23 | test: $(TESTDIRS) all 24 | $(TESTDIRS): 25 | $(MAKE) -C $(@:test-%=%) test 26 | 27 | clean: $(CLEANDIRS) 28 | $(CLEANDIRS): 29 | $(MAKE) -C $(@:clean-%=%) clean 30 | 31 | dist-clean: $(DISTCLEANDIRS) 32 | $(DISTCLEANDIRS): 33 | $(MAKE) -C $(@:dist-clean-%=%) dist-clean 34 | 35 | .PHONY: subdirs $(DIRS) 36 | .PHONY: subdirs $(BUILDDIRS) 37 | .PHONY: subdirs $(TESTDIRS) 38 | .PHONY: subdirs $(CLEANDIRS) 39 | .PHONY: all install clean tests 40 | -------------------------------------------------------------------------------- /examples/string/string.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include 6 | #include 7 | 8 | #include 9 | // USE: h5dump example.h5 10 | // some recent version of hdfview fails with variable length strings on my platform 11 | int main(){ 12 | //RAII will close resource, noo need H5Fclose( any_longer ); 13 | h5::fd_t fd = h5::create("example.h5",H5F_ACC_TRUNC); 14 | { 15 | std::vector vec = h5::utils::get_test_data(20); 16 | std::vector vec2(10, 1); // h5::utils::get_test_data(20); 17 | h5::write(fd, "/strings.txt", vec); 18 | } 19 | { 20 | std::cout << "\nsingle shot entire dataset:\n"; 21 | auto vec = h5::read>(fd, "strings.txt"); 22 | for( auto i : vec ) 23 | std::cout << i <<"\n"; 24 | } 25 | 26 | { 27 | std::cout << "\npartial IO start = 3, stride/every=2, count=5 :\n"; 28 | std::cout << "will read in 5 strings, every second starting from third position:\n"; 29 | auto vec = h5::read>(fd, "strings.txt", h5::offset{2}, h5::count{5}, h5::stride{2}); 30 | for( auto i : vec ) 31 | std::cout << i <<"\n"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | # ALL RIGHTS RESERVED. 3 | # _________________________________________________________________________________ 4 | # NOTICE: All information contained herein is, and remains the property of Varga 5 | # Consulting and its suppliers, if any. The intellectual and technical concepts 6 | # contained herein are proprietary to Varga Consulting and its suppliers and may be 7 | # covered by Canadian and Foreign Patents, patents in process, and are protected 8 | # by trade secret or copyright law. Dissemination of this information or reproduc- 9 | # tion of this material is strictly forbidden unless prior written permission is 10 | # obtained from Varga Consulting. 11 | # 12 | # Copyright © <2018> Varga Consulting, Toronto, On info@vargaconsulting.ca 13 | # _________________________________________________________________________________ 14 | 15 | *.[oa] 16 | **/*.h5 17 | **/*.pcap 18 | **/*.aux 19 | **/*.prof 20 | docs/docs/site 21 | data/ 22 | **/.ycm_extra_conf.py 23 | 24 | build 25 | CMakeLists.txt.user* 26 | *~ 27 | *.swp 28 | *.d 29 | *.slo 30 | *.lo 31 | *.o 32 | *.obj 33 | *.gch 34 | *.pch 35 | *.so 36 | *.dylib 37 | *.dll 38 | *.mod 39 | *.smod 40 | *.lai 41 | *.la 42 | *.a 43 | *.lib 44 | *.exe 45 | *.out 46 | *.app 47 | -------------------------------------------------------------------------------- /examples/multi-tu/tu-01.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include 6 | #include 7 | #include "struct.h" 8 | #include 9 | // generated file must be sandwiched between core and io 10 | // to satisfy template dependencies in 11 | #include "tu-01.h" 12 | #include 13 | #include "utils.hpp" 14 | 15 | #define CHUNK_SIZE 5 16 | #define NROWS 4*CHUNK_SIZE 17 | #define NCOLS 1*CHUNK_SIZE 18 | 19 | void test_01( const h5::fd_t& fd ){// LINARG:=[armaidllo|eigen3|blaze|blitz|it++|dlib|ublas] supported 20 | 21 | arma::imat M(NROWS,NCOLS); // define a linalg object 22 | h5::write(fd, "/linalg/armadillo",M); // save it somewhere, partial and full read|write and append supported 23 | } 24 | 25 | void test_02( const h5::fd_t& fd ){// create a Matrix of STRUCT with chunked and GZIP compressed properties ready for partial read|write 26 | 27 | // upto 7 dimensions/extents are supported 28 | h5::create(fd, "/orm/chunked_2D", 29 | h5::current_dims{NROWS,NCOLS}, h5::chunk{1,CHUNK_SIZE} | h5::gzip{8} ); 30 | h5::create(fd, "/orm/typecheck", h5::max_dims{H5S_UNLIMITED} ); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /examples/csv/generated.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #ifndef H5CPP_GUARD_GCBLl 6 | #define H5CPP_GUARD_GCBLl 7 | 8 | namespace h5{ 9 | //template specialization of input_t to create HDF5 COMPOUND type 10 | template<> hid_t inline register_struct(){ 11 | hsize_t at_00_[] ={20}; hid_t at_00 = H5Tarray_create(H5T_NATIVE_CHAR,1,at_00_); 12 | 13 | hid_t ct_00 = H5Tcreate(H5T_COMPOUND, sizeof (input_t)); 14 | H5Tinsert(ct_00, "MasterRecordNumber", HOFFSET(input_t,MasterRecordNumber),H5T_NATIVE_LONG); 15 | H5Tinsert(ct_00, "Hour", HOFFSET(input_t,Hour),H5T_NATIVE_UINT); 16 | H5Tinsert(ct_00, "Latitude", HOFFSET(input_t,Latitude),H5T_NATIVE_DOUBLE); 17 | H5Tinsert(ct_00, "Longitude", HOFFSET(input_t,Longitude),H5T_NATIVE_DOUBLE); 18 | H5Tinsert(ct_00, "ReportedLocation", HOFFSET(input_t,ReportedLocation),at_00); 19 | 20 | //closing all hid_t allocations to prevent resource leakage 21 | H5Tclose(at_00); 22 | 23 | //if not used with h5cpp framework, but as a standalone code generator then 24 | //the returned 'hid_t ct_00' must be closed: H5Tclose(ct_00); 25 | return ct_00; 26 | }; 27 | } 28 | H5CPP_REGISTER_STRUCT(input_t); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /h5cpp/H5Fopen.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #ifndef H5CPP_FOPEN_HPP 6 | #define H5CPP_FOPEN_HPP 7 | 8 | /** 9 | * @namespace h5 10 | * @brief public namespace 11 | */ 12 | namespace h5{ 13 | /** @ingroup file-io 14 | * opens an existing HDF5 file, the returned h5::fd_t descriptor automatically closes backed resource when leaving code block 15 | * The h5::fd_t is a thin hid_t size object with std::unique_ptr like properties. 16 | * \par_file_path \par_fopn_flags \par_fapl \returns_fd 17 | * \sa_h5cpp \sa_hdf5 \sa_stl 18 | * @code 19 | * { 20 | * h5::fd_t fd = h5::open("example.h5", H5F_ACC_RDWR); // open an hdf5 file 21 | * ... // do some work 22 | * } // underlying hid_t is closed when leaving code block 23 | * @endcode 24 | */ 25 | inline h5::fd_t open(const std::string& path, unsigned flags, const h5::fapl_t& fapl = h5::default_fapl ){ 26 | H5CPP_CHECK_PROP( fapl, h5::error::io::file::create, "invalid file access property list" ); 27 | 28 | hid_t fd; 29 | H5CPP_CHECK_NZ( (fd = H5Fopen(path.data(), flags, static_cast(fapl))), 30 | h5::error::io::file::open, h5::error::msg::open_file ); 31 | return h5::fd_t{fd}; 32 | } 33 | } 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /examples/half-float/open-exr/half-float.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | // OpenEXR doesn't use namespace!!! 12 | #include 13 | #include 14 | #include "utils.hpp" 15 | 16 | int main(){ 17 | 18 | h5::fd_t fd = h5::create("example.h5",H5F_ACC_TRUNC); 19 | { 20 | std::cout <<"Floating point formats: \n"; 21 | std::cout << h5::dt_t() << std::endl; 22 | std::cout << h5::dt_t() << std::endl; 23 | std::cout << h5::dt_t() << std::endl; 24 | std::cout << h5::dt_t() << std::endl; 25 | std::cout <<"Half Float numerical limits: "; 26 | std::cout << "[min] " << std::numeric_limits::min() <<" [max] " << std::numeric_limits::max() << std::endl; 27 | std::cout << std::endl; 28 | } 29 | { 30 | std::vector vec = h5::utils::get_test_data(20); 31 | h5::write(fd,"data", vec); 32 | auto data = h5::read>(fd, "data"); 33 | 34 | for( int i=0; i<20; i++ ) 35 | std::cout << "[" << i << ": " << vec[i] << " " < 4 | # _____________________________________________________________________________ 5 | 6 | apps = attributes 7 | CXXFLAGS = -std=c++17 8 | LIBS = -lhdf5 -lz -ldl -lm 9 | INCLUDES = -I/usr/local/include -I/usr/include 10 | 11 | test: $(apps) 12 | @./attributes 13 | #h5dump -pH 001.h5 14 | 15 | %.o : $(SRC_DIR)/%.cpp 16 | $(CXX) -$(INCLUDES) -o $@ $(CPPFLAGS) $(CXXFLAGS) -c $^ 17 | 18 | all: $(apps) 19 | 20 | # compiler assisted introspection will scan TU translation unit, which is the 21 | # collection of files you're compiling into an object, generates desired output 22 | # from topologically ordered dependency graph. 23 | # currently POD structs, arrays and integral types are supported, in arbitrary deep 24 | # embedding 25 | # 26 | # with -Dmyfile.h specifies the generated output, which must be sandwiched between 27 | # and 28 | generated.h: struct.h 29 | h5cpp attributes.cpp -- $(CXXFLAGS) -Dgenerated.h 30 | 31 | attributes.o : attributes.cpp generated.h 32 | $(CXX) -o attributes.o $(CXXFLAGS) -c attributes.cpp 33 | 34 | attributes: attributes.o 35 | $(CXX) $^ $(LIBS) -o $@ 36 | 37 | clean: 38 | @$(RM) *.o *.prof *.h5 $(apps) 39 | 40 | dist-clean: clean 41 | @$(RM) generated.h 42 | .PHONY: test 43 | 44 | -------------------------------------------------------------------------------- /examples/groups/README.md: -------------------------------------------------------------------------------- 1 | ## Groups[^1] 2 | 3 | An HDF5 group is a structure containing zero or more HDF5 objects. A group has two parts: 4 | 5 | 1. A group header, which contains a group name and a list of group attributes. 6 | 2. A group symbol table, which is a list of the HDF5 objects that belong to the group. 7 | 8 | ```cpp 9 | parent ::= fd_t | gr_t; 10 | 11 | [open] 12 | h5::gr_t gopen(parent, const std::string& path [, const h5::gapl_t& gapl]); 13 | 14 | [create] 15 | h5::gr_t gcreate(const L& parent, const std::string& path, 16 | [, h5::lcpl_t lcpl] [, h5::gcpl_t gcpl] [, h5::gapl_t gapl]); 17 | ``` 18 | 19 | **Example:** adding attributes to a group 20 | ```cpp 21 | auto gr = h5::gopen(fd, "/mygroup"); 22 | std::initializer_list list = {1,2,3,4,5}; 23 | h5::awrite(gr, std::make_tuple( 24 | "temperature", 42.0, 25 | "unit", "C", 26 | "vector of ints", std::vector({1,2,3,4,5}), 27 | "initializer list", list, 28 | "strings", std::initializer_list({"first", "second", "third","..."}) 29 | )); 30 | ``` 31 | 32 | ### Examples: 33 | The examples are to demonstrate how to use HDF5 groups as well as how to add attributes to them 34 | 35 | * creating groups with an `h5::fd_t` file handle and `h5::gr_t` group handle as parents 36 | * error handling: 37 | * catching specific `h5::error::io::group::create` 38 | * using umbrella exception `h5::error::any` 39 | * how to open a group and add complex set of attributes with a single call 40 | 41 | [^1]: Lifted from HDF5 CAPI documentation 42 | 43 | -------------------------------------------------------------------------------- /examples/linalg/dlib.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | template using Matrix = dlib::matrix; 12 | /* DLIB fails from stock install 2018 july 11 13 | * /usr/include/dlib/matrix/matrix.h:1608:38: error: ISO C++17 does not allow dynamic exception specifications 14 | */ 15 | int main(){ 16 | { // CREATE - WRITE 17 | Matrix M(2,3); // create a matrix 18 | h5::fd_t fd = h5::create("linalg.h5",H5F_ACC_TRUNC); // and a file 19 | h5::ds_t ds = h5::create(fd,"create then write" 20 | ,h5::current_dims{10,20} 21 | ,h5::max_dims{10,H5S_UNLIMITED} 22 | ,h5::chunk{2,3} | h5::fill_value{3} | h5::gzip{9} 23 | ); 24 | h5::write( ds, M, h5::offset{2,2}, h5::stride{1,3} ); 25 | } 26 | 27 | { // CREATE - READ: we're reading back the dataset created in the very first step 28 | // note that data is only data, can be reshaped, cast to any format and content be modified through filtering 29 | auto fd = h5::open("linalg.h5", H5F_ACC_RDWR, // you can have multiple fd open with H5F_ACC_RDONLY, but single write 30 | h5::fclose_degree_strong | h5::sec2); // and able to set various properties 31 | } 32 | { // READ: 33 | Matrix M = h5::read>("linalg.h5","create then write"); // read entire dataset back with a single read 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /h5cpp/core: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include 6 | 7 | #ifdef H5CPP_HAVE_KITA 8 | #include 9 | #endif 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #ifdef H5CPP_WITH_GLOG 28 | #include 29 | #endif 30 | 31 | #ifndef H5CPP_CORE_H 32 | #define H5CPP_CORE_H 33 | #include "H5config.hpp" 34 | #include "compat.hpp" /* */ 35 | #include "H5Eall.hpp" /* all methods throwing exceptions must be included after */ 36 | #include "H5misc.hpp" 37 | 38 | #include "H5meta.hpp" 39 | #include "H5Tmeta.hpp" 40 | #include "H5Mstl.hpp" 41 | 42 | #include "H5Sall.hpp" 43 | #include "H5Marma.hpp" 44 | #include "H5Mdlib.hpp" 45 | #include "H5Meigen.hpp" 46 | #include "H5Mblaze.hpp" 47 | #include "H5Mitpp.hpp" 48 | #include "H5Mublas.hpp" 49 | 50 | #include "H5Iall.hpp" /* base hid_t type definitions */ 51 | #include "H5Tall.hpp" 52 | #include "H5Zall.hpp" 53 | #include "H5Pall.hpp" 54 | #include "H5Zpipeline.hpp" 55 | #include "H5Zpipeline_basic.hpp" 56 | #include "H5Pdapl.hpp" 57 | 58 | #include "H5Ialgorithm.hpp" 59 | #include "H5capi.hpp" 60 | #include "H5cout.hpp" 61 | #endif 62 | -------------------------------------------------------------------------------- /examples/packet-table/Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | 6 | CXXFLAGS = -std=c++17 -I/usr/local/include -I/usr/include/eigen3 7 | LIBS = -lhdf5 -lhdf5_hl -lz -ldl -lm -lblas -llapack 8 | 9 | test: packettable 10 | ./packettable 11 | h5dump -pH example.h5 12 | 13 | # compiler assisted introspection will scan TU translation unit, which is the 14 | # collection of files you're compiling into an object, generates desired output 15 | # from topologically ordered dependency graph. 16 | # currently POD structs, arrays and integral types are supported, in arbitrary deep 17 | # embedding 18 | # 19 | # with -Dmyfile.h specifies the generated output, which must be sandwiched between 20 | # and 21 | generated.h: struct.h 22 | h5cpp packettable.cpp -- $(CXXFLAGS) -Dgenerated.h 23 | 24 | packettable.o : packettable.cpp generated.h 25 | $(CXX) -I/usr/include/eigen3 -o packettable.o $(CXXFLAGS) -c packettable.cpp 26 | 27 | packettable: packettable.o 28 | $(CXX) $^ $(LIBS) -o $@ 29 | 30 | packet_batches.o : packet_batches.cpp 31 | $(CXX) -o packet_batches.o $(CXXFLAGS) -c packet_batches.cpp 32 | 33 | packet_batches: packet_batches.o 34 | $(CXX) $^ $(LIBS) -larmadillo -o $@ 35 | 36 | 37 | clean: 38 | @$(RM) *.o *.h5 $(apps) packettable packet_batches 39 | 40 | dist-clean: clean 41 | @$(RM) generated.h 42 | .PHONY: test 43 | 44 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | H5CPP may be used for any purpose, including commercial purposes, at absolutely 3 | no cost. It is distributed under the terms of the MIT license reproduced here. 4 | 5 | Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 6 | Author: Varga, Steven 7 | ------------------------------------------------------------------------------- 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy of 10 | this software and associated documentation files (the "Software"), to deal in 11 | the Software without restriction, including without limitation the rights to 12 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 13 | of the Software, and to permit persons to whom the Software is furnished to do 14 | so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 21 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 22 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 23 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 24 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | 26 | -------------------------------------------------------------------------------- /LICENSE.CSV: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, ben-strasser 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of fast-cpp-csv-parser nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /examples/csv/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, ben-strasser 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of fast-cpp-csv-parser nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /examples/half-float/christian-rau/half-float.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "half.hpp" // this should be obtained from http://half.sourceforge.net/ 11 | #include 12 | #include "utils.hpp" 13 | 14 | #define CHUNK_SIZE 5 15 | #define NROWS 4*CHUNK_SIZE 16 | #define NCOLS 1*CHUNK_SIZE 17 | 18 | int main(){ 19 | using half_float::half; 20 | using namespace half_float::literal; 21 | 22 | h5::fd_t fd = h5::create("example.h5",H5F_ACC_TRUNC); 23 | { 24 | std::cout <<"Floating point formats: \n"; 25 | std::cout << h5::dt_t() << std::endl; 26 | std::cout << h5::dt_t() << std::endl; 27 | std::cout << h5::dt_t() << std::endl; 28 | std::cout << h5::dt_t() << std::endl; 29 | std::cout <<"Half Float numerical limits: "; 30 | 31 | std::cout << "[min] " << std::numeric_limits::min() <<" [max] " << std::numeric_limits::max() << std::endl; 32 | std::cout << std::endl; 33 | } 34 | { 35 | std::vector vec = h5::utils::get_test_data(20); 36 | h5::write(fd,"data", vec); 37 | auto data = h5::read>(fd, "data"); 38 | 39 | for( int i=0; i<20; i++ ) 40 | std::cout << "[" << i << ": " << vec[i] << " " < 4 | */ 5 | 6 | #ifndef H5CPPI_ALGORITHM_HPP 7 | #define H5CPPI_ALGORITHM_HPP 8 | 9 | namespace h5 { namespace impl { 10 | inline static herr_t iterate_callback( ::hid_t gid, const char *name, const H5L_info_t *info, void *op_data){ 11 | // this must not throw error, CAPI has to clean up 12 | try { 13 | std::vector *data = static_cast* >(op_data); 14 | data->push_back( std::string(name) ); 15 | } catch ( ... ){ 16 | return -1; 17 | } 18 | return 0; 19 | } 20 | 21 | }} 22 | 23 | namespace h5 { 24 | inline std::vector ls(const h5::fd_t& fd, const std::string& directory ){ 25 | hid_t group_id; 26 | H5CPP_CHECK_NZ( 27 | (group_id = H5Gopen( static_cast(fd), directory.c_str(), H5P_DEFAULT )), std::runtime_error, h5::error::msg::open_group ); 28 | std::vector files; 29 | H5CPP_CHECK_NZ( H5Literate( group_id, H5_INDEX_NAME, H5_ITER_INC, 0, &impl::iterate_callback, &files ), std::runtime_error, h5::error::msg::list_directory ); 30 | H5CPP_CHECK_NZ( H5Gclose(group_id), std::runtime_error, h5::error::msg::close_group); 31 | return files; 32 | } 33 | //FIXME: to be implemented 34 | inline std::vector bfs(const h5::fd_t& fd, const std::string& directory ){ 35 | std::vector files; 36 | return files; 37 | } 38 | inline std::vector dfs(const h5::fd_t& fd, const std::string& directory ){ 39 | std::vector files; 40 | return files; 41 | } 42 | } 43 | #endif 44 | 45 | -------------------------------------------------------------------------------- /examples/multi-tu/tu-02.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include 6 | #include 7 | #include "struct.h" 8 | #include 9 | // generated file must be sandwiched between core and io 10 | // to satisfy template dependencies in 11 | #include "tu-02.h" 12 | // multiple inclusion is on purpose to test 13 | // include guards in generated file: tu_02.h 14 | #include "tu-02.h" 15 | #include 16 | #include "utils.hpp" 17 | 18 | #define CHUNK_SIZE 5 19 | #define NROWS 4*CHUNK_SIZE 20 | #define NCOLS 1*CHUNK_SIZE 21 | 22 | 23 | void test_03( const h5::fd_t& fd ){ // creates + writes entire object tree 24 | 25 | std::vector vec = h5::utils::get_test_data(20); 26 | h5::write(fd, "orm/partial/vector one_shot", vec ); 27 | // dimensions and other properties specified additional argument 28 | h5::write(fd, "orm/partial/vector custom_dims", vec, 29 | h5::max_dims{H5S_UNLIMITED}, h5::gzip{9} | h5::chunk{20} ); 30 | // you don't need to remember order, compiler will do it for you without runtime penalty: 31 | h5::write(fd, "orm/partial/vector custom_dims different_order", vec, 32 | h5::chunk{20} | h5::gzip{9}, 33 | h5::max_dims{H5S_UNLIMITED}, h5::offset{3} ); 34 | } 35 | 36 | void test_04( const h5::fd_t& fd ){ // read entire dataset back 37 | 38 | using T = std::vector; 39 | std::cerr<< "reading data: \n"; 40 | auto data = h5::read(fd,"/orm/partial/vector one_shot"); 41 | std::cerr <<"reading back data previously written:\n\t"; 42 | for( auto r:data ) 43 | std::cerr << r.idx <<" "; 44 | 45 | std::cerr << std::endl; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /examples/groups/groups.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include 6 | #include 7 | 8 | 9 | int main() { 10 | 11 | auto fd = h5::create("001.h5", H5F_ACC_TRUNC); 12 | { // create intermediate groups 13 | // NOTICE: const static h5::lcpl_t lcpl = h5::char_encoding{H5T_CSET_UTF8} | h5::create_intermediate_group{1}; 14 | // the default h5::default_lcpl will create immediate path and the encoding is set to utf8 15 | h5::gr_t gr = h5::gcreate(fd, "my-group/sub/path"); 16 | 17 | h5::lcpl_t lcpl = h5::create_intermediate_group{1}; 18 | h5::gcreate(fd, "/mygroup", lcpl); // passing lcpl type explicitly 19 | } 20 | { // exceptions 21 | h5::mute(); // mute CAPI error handler 22 | try { // this group already exists, will throw `h5::error::io::group::create` exception 23 | h5::gcreate(fd, "/mygroup", h5::dont_create_path); 24 | }catch ( const h5::error::io::group::create& e){ 25 | std::cout << e.what() <<"\n"; 26 | } 27 | 28 | // catching all exceptions 29 | try { // this group already exists, will throw `h5::error::io::group::create` exception 30 | h5::gcreate(fd, "/mygroup", h5::dont_create_path); 31 | }catch ( const h5::error::any& e){ 32 | std::cout << e.what() <<"\n"; 33 | } 34 | h5::unmute(); // re-enable CAPI error handling 35 | } 36 | { // opening a group and adding attributes 37 | auto gr = h5::gopen(fd, "/mygroup"); 38 | std::initializer_list list = {1,2,3,4,5}; 39 | h5::awrite(gr, std::make_tuple( 40 | "temperature", 42.0, 41 | "unit", "C", 42 | "vector of ints", std::vector({1,2,3,4,5}), 43 | "initializer list", list, 44 | "strings", std::initializer_list({"first", "second", "third","..."}) 45 | )); 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /examples/multi-tu/Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | # 6 | # you must include the path to LLVM version specific files conveniently installed: 7 | # -I/usr/local/h5cpp-llvm 8 | CXXFLAGS = -std=c++17 9 | LIBS = -lhdf5 -lz -ldl -lm 10 | INCLUDES = -I/usr/local/include -I/usr/include 11 | 12 | test: app 13 | ./app 14 | 15 | # compiler assisted introspection will scan TU translation unit, which is the 16 | # collection of files you're compiling into an object, generates desired output 17 | # from topologically ordered dependency graph. 18 | # currently POD structs, arrays and integral types are supported, in arbitrary deep 19 | # embedding 20 | # 21 | # with -Dmyfile.h specifies the generated output, which must be sandwiched between 22 | # and 23 | 24 | # invoke `h5cpp` compiler separately for any given TU translation unit 25 | # to produce tu_0?.h header file which must be included exactly once in each given TU. 26 | tu-01.h: struct.h 27 | h5cpp tu-01.cpp -- $(CXXFLAGS) $(INCLUDES) -Dtu-01.h 28 | tu-02.h: struct.h 29 | h5cpp tu-02.cpp -- $(CXXFLAGS) $(INCLUDES) -Dtu-02.h 30 | 31 | # for simplicity let's use explicit rules to compile TU-s into object files 32 | tu-01.o : tu-01.cpp tu-01.h 33 | $(CXX) $(INCLUDES) -o tu-01.o $(CXXFLAGS) -c tu-01.cpp 34 | 35 | tu-02.o : tu-02.cpp tu-02.h 36 | $(CXX) $(INCLUDES) -o tu-02.o $(CXXFLAGS) -c tu-02.cpp 37 | 38 | main.o : main.cpp 39 | $(CXX) -o main.o $(CXXFLAGS) -c main.cpp 40 | 41 | app: tu-01.o tu-02.o main.o 42 | $(CXX) $^ $(LIBS) -o $@ 43 | 44 | clean: 45 | @$(RM) *.o *.h5 app 46 | 47 | dist-clean: clean 48 | @$(RM) tu-01.h tu-02.h 49 | 50 | .PHONY: test 51 | 52 | -------------------------------------------------------------------------------- /examples/sparse/arma.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | int main(){ 11 | 12 | h5::fd_t fd = h5::create("example.h5",H5F_ACC_TRUNC); 13 | 14 | std::random_device rd; 15 | std::mt19937 gen(rd()); 16 | std::uniform_int_distribution<> dist(40, 45); 17 | 18 | arma::SpMatM(20,40); 19 | for(int i = 0, j=dist(gen); i(gr); 43 | std::cout<<"is dense: " << h5::exp::linalg::is_dense::value <<"\n"; 44 | std::cout<<"is continuous: " << h5::exp::is_contigious::value <<"\n"; 45 | std::cout<<"rank: " << h5::exp::rank::value << "\n"; 46 | std::cout<<"rank: " << h5::exp::rank>::value << "\n"; 47 | 48 | //std::cout << values <<"\n"; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /h5cpp/H5Mdlib.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #ifndef H5CPP_DLIB_HPP 6 | #define H5CPP_DLIB_HPP 7 | 8 | #if defined(DLIB_MATRIx_HEADER) || defined(H5CPP_USE_DLIB) 9 | namespace h5 { namespace dlib { 10 | // dlib template: 11 | // const dlib::matrix, dlib::row_major_layout>& 12 | template using rowmat = ::dlib::matrix, 14 | ::dlib::row_major_layout>; 15 | template ::type> 16 | using is_supported = std::integral_constant>::value>; 17 | }} 18 | namespace h5 { namespace impl { 19 | // 1.) object -> H5T_xxx 20 | template struct decay>{ typedef T type; }; 21 | 22 | // get read access to datastaore 23 | template ::type> inline 24 | typename std::enable_if< h5::dlib::is_supported::value, 25 | const T*>::type data(const Object& ref ){ 26 | return &ref(0,0); 27 | } 28 | // read write access 29 | template ::type> inline 30 | typename std::enable_if< h5::dlib::is_supported::value, 31 | T*>::type data( Object& ref ){ 32 | return &ref(0,0); 33 | } 34 | template struct rank> : public std::integral_constant{}; 35 | 36 | 37 | 38 | template 39 | inline std::array size( const dlib::rowmat& ref ){ 40 | return { (hsize_t)ref.nc(),(hsize_t)ref.nr()}; 41 | } 42 | 43 | 44 | 45 | template struct get> { 46 | static inline h5::dlib::rowmat ctor( std::array dims ){ 47 | return h5::dlib::rowmat( dims[1], dims[0] ); 48 | }}; 49 | }} 50 | #endif 51 | #endif 52 | -------------------------------------------------------------------------------- /examples/container/README.md: -------------------------------------------------------------------------------- 1 | ## File[^1] 2 |
3 | ![Object](../pix/FF-IH_FileObject.gif) 4 |
5 | 6 | 7 | 8 | HDF5 files are organized in a hierarchical structure, with two primary structures: groups and datasets. 9 | 10 | * HDF5 group: a grouping structure containing instances of zero or more groups or datasets, together with supporting metadata. 11 | * HDF5 dataset: a multidimensional array of data elements, together with supporting metadata. 12 | 13 | 14 | Working with groups and group members is similar in many ways to working with directories and files in UNIX. As with UNIX directories and files, objects in an HDF5 file are often described by giving their full (or absolute) path names. 15 |
16 | ![File](../pix/FF-IH_FileGroup.gif) 17 |
18 | 19 | `/` signifies the root group. `/foo` signifies a member of the root group called foo. `/foo/zoo` signifies a member of the group foo, which in turn is a member of the root group. Any HDF5 group or dataset may have an associated attribute list. An HDF5 attribute is a user-defined HDF5 structure that provides extra information about an HDF5 object. 20 | 21 | For those who are interested, this section takes a look at the low-level elements of the file as the file is written to disk (or other storage media) and the relation of those low-level elements to the higher level elements with which users typically are more familiar. The HDF5 API generally exposes only the high-level elements to the user; the low-level elements are often hidden. The rest of this Introduction does not assume an understanding of this material. 22 | 23 | The format of an HDF5 file on disk encompasses several key ideas of the HDF4 and AIO file formats as well as addressing some shortcomings therein. The new format is more self-describing than the HDF4 format and is more uniformly applied to data objects in the file. 24 | 25 | 26 | [^1]: Lifted from HDF5 CAPI documentation 27 | 28 | -------------------------------------------------------------------------------- /examples/datatypes/n-bit.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | // do your thing, usually this would be in a separate header file 7 | namespace bitstring { 8 | struct n_bit { // wrapper to aid C++ template mechanism, zero runtime cost 9 | // allow conversion: auto value = static_cast( n_bit_type ); 10 | explicit operator unsigned char() const { 11 | return value; 12 | } 13 | explicit operator unsigned int() const { 14 | return value; 15 | } 16 | n_bit() = default; 17 | n_bit( unsigned char value_ ) : value(value_){} 18 | unsigned char value; 19 | }; 20 | } 21 | 22 | // BEGIN H5CPP SPECIFIC CUSTOM TYPE DEFINITION 23 | namespace h5::impl::detail { 24 | template <> struct hid_t : public dt_p { 25 | using parent = dt_p; // h5cpp needs the following typedefs 26 | using dt_p::hid_t; 27 | //using parent::hid_t; --> this style of inheriting ctor will not work with clang :( 28 | using hidtype = bitstring::n_bit; 29 | 30 | // opaque doesn't care of byte order, also since you are using single byte 31 | // it is not relevant 32 | hid_t() : parent( H5Tcopy( H5T_NATIVE_UCHAR) ) { 33 | H5Tset_precision(handle, 2); 34 | hid_t id = static_cast( *this ); 35 | } 36 | }; 37 | } 38 | namespace h5 { 39 | template <> struct name { 40 | static constexpr char const * value = "bitstring::n_bit"; 41 | }; 42 | } 43 | // END H5CPP SPECIFIC TYPE DEFINEITION 44 | 45 | 46 | // SERVICE ROUTINES 47 | std::ostream& operator<<(std::ostream& os, const bitstring::n_bit& data){ 48 | os << data.value; 49 | return os; 50 | } 51 | 52 | std::ostream& operator<<(std::ostream& os, const 53 | Eigen::Matrix& M){ 54 | for( size_t i=0; i( M(i,j)) <<" "; 56 | os< 4 | */ 5 | 6 | #include "csv.h" 7 | // data structure include file: `struct.h` must precede 'generated.h' as the latter contains dependencies 8 | // from previous 9 | #include "struct.h" 10 | 11 | #include // has handle + type descriptors 12 | // sandwiched: as `h5cpp/io` depends on `henerated.h` which needs `h5cpp/core` 13 | #include "generated.h" // uses type descriptors 14 | #include // uses generated.h + core 15 | 16 | int main(){ 17 | 18 | // create HDF5 container 19 | h5::fd_t fd = h5::create("output.h5",H5F_ACC_TRUNC); 20 | // create dataset 21 | // chunk size is unrealistically small, usually you would set this such that ~= 1MB or an ethernet jumbo frame size 22 | h5::ds_t ds = h5::create(fd, "simple approach/dataset.csv", 23 | h5::max_dims{H5S_UNLIMITED}, h5::chunk{10} | h5::gzip{9} ); 24 | // `h5::ds_t` handle is seamlessly cast to `h5::pt_t` packet table handle, this could have been done in single step 25 | // but we need `h5::ds_t` handle to add attributes 26 | h5::pt_t pt = ds; 27 | // attributes may be added to `h5::ds_t` handle 28 | ds["data set"] = "monroe-county-crash-data2003-to-2015.csv"; 29 | ds["cvs parser"] = "https://github.com/ben-strasser/fast-cpp-csv-parser"; // thank you! 30 | 31 | constexpr unsigned N_COLS = 5; 32 | io::CSVReader in("input.csv"); // number of cols may be less, than total columns in a row, we're to read only 5 33 | in.read_header(io::ignore_extra_column, "Master Record Number", "Hour", "Reported_Location","Latitude","Longitude"); 34 | input_t row; // buffer to read line by line 35 | char* ptr; // indirection, as `read_row` doesn't take array directly 36 | while(in.read_row(row.MasterRecordNumber, row.Hour, ptr, row.Latitude, row.Longitude)){ 37 | strncpy(row.ReportedLocation, ptr, STR_ARRAY_SIZE); // defined in struct.h 38 | h5::append(pt, row); 39 | std::cout << std::string(ptr) << "\n"; 40 | } 41 | // RAII closes all allocated resources 42 | } 43 | -------------------------------------------------------------------------------- /h5cpp/H5Acreate.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #ifndef H5CPP_ACREATE_HPP 6 | #define H5CPP_ACREATE_HPP 7 | namespace h5 { 8 | namespace impl { 9 | /*this template defines what HDF5 object types may have attributes */ 10 | template using is_valid_attr = 11 | std::integral_constant::value || 12 | std::is_same::value || std::is_same::value || 13 | std::is_same::value || std::is_same>::value>; 14 | /*template using is_valid_attr = 15 | std::integral_constant::value>;*/ 17 | } 18 | 19 | template 20 | inline typename std::enable_if::value, 21 | h5::at_t>::type create( const HID_T& parent, const std::string& path, args_t&&... args ){ 22 | try { 23 | h5::acpl_t default_acpl{ H5Pcreate(H5P_ATTRIBUTE_CREATE) }; 24 | const h5::acpl_t& acpl = arg::get(default_acpl, args...); 25 | 26 | H5CPP_CHECK_PROP( acpl, h5::error::property_list::misc, "invalid attribute create property" ); 27 | 28 | // and dimensions 29 | h5::current_dims_t current_dims_default{0}; // if no current dims_present 30 | // this mutable value will be referenced 31 | const h5::current_dims_t& current_dims = arg::get(current_dims_default, args...); 32 | // no partial IO or chunks 33 | h5::sp_t space = h5::create_simple( current_dims ); 34 | using element_t = typename impl::decay::type; 35 | h5::dt_t type; 36 | hid_t id = H5I_UNINIT; 37 | H5CPP_CHECK_NZ( (id = H5Acreate2( static_cast( parent ), path.c_str(), 38 | static_cast(type), static_cast( space ), static_cast( acpl ), H5P_DEFAULT )), 39 | h5::error::io::attribute::create, "couldn't create attribute"); 40 | return h5::at_t{id}; 41 | } catch( const std::runtime_error& err ) { 42 | throw h5::error::io::attribute::create( err.what() ); 43 | } 44 | } 45 | 46 | } 47 | #endif 48 | 49 | -------------------------------------------------------------------------------- /h5cpp/H5Pdapl.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #ifndef H5CPP_PDAPL_HPP 6 | #define H5CPP_PDAPL_HPP 7 | 8 | #define H5CPP_DAPL_HIGH_THROUGHPUT "h5cpp_dapl_highthroughput" 9 | 10 | namespace h5 { namespace impl { 11 | inline herr_t dapl_pipeline_close( const char *name, size_t size, void *ptr ){ 12 | delete *static_cast< impl::pipeline_t**>( ptr ); 13 | return 0; 14 | } 15 | inline ::herr_t dapl_pipeline_set(::hid_t dapl ) { 16 | //TODO: see why H5CPP pipeline crashes with 1.12.x 17 | #if H5_VERSION_LE(1,10,6) 18 | // ignore if already set 19 | if( H5Pexist(dapl, H5CPP_DAPL_HIGH_THROUGHPUT) ) return 0; 20 | using pipeline = impl::pipeline_t; 21 | pipeline* ptr = new pipeline(); 22 | return H5Pinsert2(dapl, H5CPP_DAPL_HIGH_THROUGHPUT, sizeof( pipeline* ), &ptr, 23 | nullptr, nullptr, nullptr, nullptr, nullptr, dapl_pipeline_close); 24 | #else 25 | return 0; 26 | #endif 27 | } 28 | }} 29 | 30 | namespace h5 { 31 | // DATA ACCESS PROPERTY LISTS 32 | #if H5_VERSION_GE(1,10,0) 33 | using efile_prefix = impl::dapl_call< impl::dapl_args,H5Pset_efile_prefix>; 34 | using virtual_view = impl::dapl_call< impl::dapl_args,H5Pset_virtual_view>; 35 | using virtual_printf_gap = impl::dapl_call< impl::dapl_args,H5Pset_virtual_printf_gap>; 36 | #endif 37 | using chunk_cache = impl::dapl_call< impl::dapl_args,H5Pset_chunk_cache>; 38 | //using num_threads = impl::dapl_call< impl::dapl_args,impl::dapl_threads>; 39 | namespace flag { 40 | using high_throughput = impl::dapl_call< impl::dapl_args,impl::dapl_pipeline_set>; 41 | } 42 | const static flag::high_throughput high_throughput; 43 | 44 | const static h5::dapl_t dapl = static_cast( H5Pcreate(H5P_DATASET_ACCESS) ); 45 | //const static h5::dapl_t default_dapl = high_throughput; 46 | const static h5::dapl_t default_dapl = static_cast( H5Pcreate(H5P_DATASET_ACCESS) ); 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /examples/datatypes/two-bit.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | // do your thing, usually this would be in a separate header file 6 | namespace bitstring { 7 | struct two_bit { // wrapper to aid C++ template mechanism, zero runtime cost 8 | // but you have to develop your own efficient two bit arithmetic 9 | // as well as in memory storage mechanism, this is a 4 x 2bit data block 10 | unsigned operator[]( int idx_ ) const { 11 | switch (idx_){ 12 | case 0: return (value & 0b0000'0011) >> 0; 13 | case 1: return (value & 0b0000'1100) >> 2; 14 | case 2: return (value & 0b0011'0000) >> 4; 15 | case 3: return (value & 0b1100'0000) >> 6; 16 | default: 17 | throw std::runtime_error("out of bound"); 18 | } 19 | } 20 | two_bit( unsigned char value_ ) : value(value_){ 21 | } 22 | two_bit() = default; 23 | unsigned char value; 24 | }; 25 | } 26 | 27 | // BEGIN H5CPP SPECIFIC CUSTOM TYPE DEFINITION 28 | namespace h5::impl::detail { 29 | template <> struct hid_t : public dt_p { 30 | using parent = dt_p; // h5cpp needs the following typedefs 31 | using dt_p::hid_t; // inheriting ctor 32 | //using parent::hid_t; --> this style of inheriting ctor will not work with clang :( 33 | using hidtype = bitstring::two_bit; 34 | 35 | // opaque doesn't care of byte order, also since you are using single byte 36 | // it is not relevant 37 | hid_t() : parent( H5Tcreate( H5T_OPAQUE, 1) ) { // 1 == single byte, i would pack it into 64 bit though 38 | H5Tset_tag(handle, "bitstring::two_bit"); 39 | hid_t id = static_cast( *this ); 40 | } 41 | }; 42 | } 43 | namespace h5 { 44 | template <> struct name { 45 | static constexpr char const * value = "bitstring::two_bit"; 46 | }; 47 | } 48 | // END H5CPP SPECIFIC TYPE DEFINEITION 49 | 50 | 51 | // SERVICE ROUTINES 52 | std::ostream& operator<<(std::ostream& os, const bitstring::two_bit& val){ 53 | os << val[3] << " " << val[2] << " " << val[1] <<" " << val[0]; 54 | return os; 55 | } 56 | -------------------------------------------------------------------------------- /examples/reference/reference.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | int main(){ 7 | h5::fd_t fd = h5::create("ref.h5", H5F_ACC_TRUNC); 8 | { 9 | h5::ds_t ds = h5::create(fd,"01", 10 | h5::current_dims{10,20}, h5::chunk{2,2} | h5::fill_value{1} ); 11 | 12 | h5::reference_t ref = h5::reference(fd, "01", h5::offset{2,2}, h5::count{4,4}); 13 | h5::write(fd, "single reference", ref); 14 | /* you can factor out `count` this way : h5::count count{2,2}; */ 15 | std::vector idx { 16 | // The HDF5 CAPI reqires fd + dataset name, instead of hid_t to ds: wishy-washy 17 | h5::reference(fd, "01", h5::offset{2,2}, h5::count{4,4}), 18 | h5::reference(fd, "01", h5::offset{4,8}, h5::count{1,1}), 19 | h5::reference(fd, "01", h5::offset{6,12}, h5::count{3,3}), 20 | h5::reference(fd, "01", h5::offset{8,16}, h5::count{2,1}) 21 | }; 22 | // datset shape can be controlled with dimensions, in this case is 2x2 23 | // and is not related to the selected regions!!! 24 | // data type is H5R_DATASET_REGION when dataspace is provided, otherwise OBJECT 25 | h5::write(fd, "index", idx, h5::current_dims{2,2}, h5::max_dims{H5S_UNLIMITED, 2}); 26 | } 27 | { // we going to update the regions referenced by the set of region-references 28 | // stored in "index" 29 | h5::ds_t ds = h5::open(fd, "index"); 30 | std::vector color(50, 9); 31 | // this is to read from selection 32 | for(auto& ref: h5::read>(ds)) 33 | h5::exp::write(ds, ref, color.data()); 34 | } 35 | 36 | { // we are reading back data from the regions, now they all must be 'color' value '9' 37 | h5::ds_t ds = h5::open(fd, "index"); 38 | // this is to read from selection 39 | for(auto& ref: h5::read>(ds)){ 40 | arma::fmat mat = h5::exp::read(ds, ref); 41 | std::cout << mat << "\n"; 42 | } 43 | } 44 | { // for verification 45 | std::cout << h5::read(fd, "01") << "\n\n"; 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /examples/attributes/struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #ifndef H5TEST_STRUCT_01 7 | #define H5TEST_STRUCT_01 8 | 9 | /* typedef is allowed */ 10 | typedef unsigned long long int MyUInt; 11 | 12 | namespace sn { 13 | namespace typecheck { 14 | struct Record { /*the types with direct mapping to HDF5*/ 15 | char _char; unsigned char _uchar; short _short; unsigned short _ushort; int _int; unsigned int _uint; 16 | long _long; unsigned long _ulong; long long int _llong; unsigned long long _ullong; 17 | float _float; double _double; long double _ldouble; 18 | bool _bool; 19 | // wide characters are not supported in HDF5 20 | // wchar_t _wchar; char16_t _wchar16; char32_t _wchar32; 21 | }; 22 | } 23 | namespace other { 24 | struct Record { // POD struct with nested namespace 25 | MyUInt idx; // typedef type 26 | MyUInt aa; // typedef type 27 | double field_02[3]; // const array mapped 28 | typecheck::Record field_03[4]; // 29 | }; 30 | } 31 | namespace example { 32 | struct Record { // POD struct with nested namespace 33 | MyUInt idx; // typedef type 34 | float field_02[7]; // const array mapped 35 | sn::other::Record field_03[5]; // embedded Record 36 | sn::other::Record field_04[5]; // must be optimized out, same as previous 37 | other::Record field_05[3][8]; // array of arrays 38 | }; 39 | } 40 | namespace not_supported_yet { 41 | // NON POD: not supported in phase 1 42 | // C++ Class -> PODstruct -> persistence[ HDF5 | ??? ] -> PODstruct -> C++ Class 43 | struct Container { 44 | double idx; // 45 | std::string field_05; // c++ object makes it non-POD 46 | std::vector field_02; // ditto 47 | }; 48 | } 49 | /* BEGIN IGNORED STRUCT */ 50 | // these structs are not referenced with h5::read|h5::write|h5::create operators 51 | // hence compiler should ignore them. 52 | struct IgnoredRecord { 53 | signed long int idx; 54 | float field_0n; 55 | }; 56 | /* END IGNORED STRUCTS */ 57 | } 58 | #endif 59 | -------------------------------------------------------------------------------- /examples/compound/struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #ifndef H5TEST_STRUCT_01 7 | #define H5TEST_STRUCT_01 8 | 9 | /* typedef is allowed */ 10 | typedef unsigned long long int MyUInt; 11 | 12 | namespace sn { 13 | namespace typecheck { 14 | struct Record { /*the types with direct mapping to HDF5*/ 15 | char _char; unsigned char _uchar; short _short; unsigned short _ushort; int _int; unsigned int _uint; 16 | long _long; unsigned long _ulong; long long int _llong; unsigned long long _ullong; 17 | float _float; double _double; long double _ldouble; 18 | bool _bool; 19 | // wide characters are not supported in HDF5 20 | // wchar_t _wchar; char16_t _wchar16; char32_t _wchar32; 21 | }; 22 | } 23 | namespace other { 24 | struct Record { // POD struct with nested namespace 25 | MyUInt idx; // typedef type 26 | MyUInt aa; // typedef type 27 | double field_02[3]; // const array mapped 28 | typecheck::Record field_03[4]; // 29 | }; 30 | } 31 | namespace example { 32 | struct Record { // POD struct with nested namespace 33 | MyUInt idx; // typedef type 34 | float field_02[7]; // const array mapped 35 | sn::other::Record field_03[5]; // embedded Record 36 | sn::other::Record field_04[5]; // must be optimized out, same as previous 37 | other::Record field_05[3][8]; // array of arrays 38 | }; 39 | } 40 | namespace not_supported_yet { 41 | // NON POD: not supported in phase 1 42 | // C++ Class -> PODstruct -> persistence[ HDF5 | ??? ] -> PODstruct -> C++ Class 43 | struct Container { 44 | double idx; // 45 | std::string field_05; // c++ object makes it non-POD 46 | std::vector field_02; // ditto 47 | }; 48 | } 49 | /* BEGIN IGNORED STRUCT */ 50 | // these structs are not referenced with h5::read|h5::write|h5::create operators 51 | // hence compiler should ignore them. 52 | struct IgnoredRecord { 53 | signed long int idx; 54 | float field_0n; 55 | }; 56 | /* END IGNORED STRUCTS */ 57 | } 58 | #endif 59 | -------------------------------------------------------------------------------- /examples/multi-tu/struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #ifndef H5TEST_STRUCT_01 7 | #define H5TEST_STRUCT_01 8 | 9 | /* typedef is allowed */ 10 | typedef unsigned long long int MyUInt; 11 | 12 | namespace sn { 13 | namespace typecheck { 14 | struct Record { /*the types with direct mapping to HDF5*/ 15 | char _char; unsigned char _uchar; short _short; unsigned short _ushort; int _int; unsigned int _uint; 16 | long _long; unsigned long _ulong; long long int _llong; unsigned long long _ullong; 17 | float _float; double _double; long double _ldouble; 18 | bool _bool; 19 | // wide characters are not supported in HDF5 20 | // wchar_t _wchar; char16_t _wchar16; char32_t _wchar32; 21 | }; 22 | } 23 | namespace other { 24 | struct Record { // POD struct with nested namespace 25 | MyUInt idx; // typedef type 26 | MyUInt aa; // typedef type 27 | double field_02[3]; // const array mapped 28 | typecheck::Record field_03[4]; // 29 | }; 30 | } 31 | namespace example { 32 | struct Record { // POD struct with nested namespace 33 | MyUInt idx; // typedef type 34 | float field_02[7]; // const array mapped 35 | sn::other::Record field_03[5]; // embedded Record 36 | sn::other::Record field_04[5]; // must be optimized out, same as previous 37 | other::Record field_05[3][8]; // array of arrays 38 | }; 39 | } 40 | namespace not_supported_yet { 41 | // NON POD: not supported in phase 1 42 | // C++ Class -> PODstruct -> persistence[ HDF5 | ??? ] -> PODstruct -> C++ Class 43 | struct Container { 44 | double idx; // 45 | std::string field_05; // c++ object makes it non-POD 46 | std::vector field_02; // ditto 47 | }; 48 | } 49 | /* BEGIN IGNORED STRUCT */ 50 | // these structs are not referenced with h5::read|h5::write|h5::create operators 51 | // hence compiler should ignore them. 52 | struct IgnoredRecord { 53 | signed long int idx; 54 | float field_0n; 55 | }; 56 | /* END IGNORED STRUCTS */ 57 | } 58 | #endif 59 | -------------------------------------------------------------------------------- /examples/packet-table/struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #ifndef H5TEST_STRUCT_01 7 | #define H5TEST_STRUCT_01 8 | 9 | /* typedef is allowed */ 10 | typedef unsigned long long int MyUInt; 11 | 12 | namespace sn { 13 | namespace typecheck { 14 | struct Record { /*the types with direct mapping to HDF5*/ 15 | char _char; unsigned char _uchar; short _short; unsigned short _ushort; int _int; unsigned int _uint; 16 | long _long; unsigned long _ulong; long long int _llong; unsigned long long _ullong; 17 | float _float; double _double; long double _ldouble; 18 | bool _bool; 19 | // wide characters are not supported in HDF5 20 | // wchar_t _wchar; char16_t _wchar16; char32_t _wchar32; 21 | }; 22 | } 23 | namespace other { 24 | struct Record { // POD struct with nested namespace 25 | MyUInt idx; // typedef type 26 | MyUInt aa; // typedef type 27 | double field_02[3]; // const array mapped 28 | typecheck::Record field_03[4]; // 29 | }; 30 | } 31 | namespace example { 32 | struct Record { // POD struct with nested namespace 33 | MyUInt idx; // typedef type 34 | float field_02[7]; // const array mapped 35 | sn::other::Record field_03[5]; // embedded Record 36 | sn::other::Record field_04[5]; // must be optimized out, same as previous 37 | other::Record field_05[3][8]; // array of arrays 38 | }; 39 | } 40 | namespace not_supported_yet { 41 | // NON POD: not supported in phase 1 42 | // C++ Class -> PODstruct -> persistence[ HDF5 | ??? ] -> PODstruct -> C++ Class 43 | struct Container { 44 | double idx; // 45 | std::string field_05; // c++ object makes it non-POD 46 | std::vector field_02; // ditto 47 | }; 48 | } 49 | /* BEGIN IGNORED STRUCT */ 50 | // these structs are not referenced with h5::read|h5::write|h5::create operators 51 | // hence compiler should ignore them. 52 | struct IgnoredRecord { 53 | signed long int idx; 54 | float field_0n; 55 | }; 56 | /* END IGNORED STRUCTS */ 57 | } 58 | #endif 59 | -------------------------------------------------------------------------------- /examples/stl/struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #ifndef H5TEST_STRUCT_01 7 | #define H5TEST_STRUCT_01 8 | 9 | #include 10 | 11 | /* typedef is allowed */ 12 | typedef unsigned long long int MyUInt; 13 | 14 | namespace sn { 15 | namespace typecheck { 16 | struct Record { /*the types with direct mapping to HDF5*/ 17 | char _char; unsigned char _uchar; short _short; unsigned short _ushort; int _int; unsigned int _uint; 18 | long _long; unsigned long _ulong; long long int _llong; unsigned long long _ullong; 19 | float _float; double _double; long double _ldouble; 20 | bool _bool; 21 | // wide characters are not supported in HDF5 22 | // wchar_t _wchar; char16_t _wchar16; char32_t _wchar32; 23 | }; 24 | } 25 | namespace other { 26 | struct Record { // POD struct with nested namespace 27 | MyUInt idx; // typedef type 28 | MyUInt aa; // typedef type 29 | double field_02[3]; // const array mapped 30 | typecheck::Record field_03[4]; // 31 | }; 32 | } 33 | namespace example { 34 | struct Record { // POD struct with nested namespace 35 | MyUInt idx; // typedef type 36 | float field_02[7]; // const array mapped 37 | sn::other::Record field_03[5]; // embedded Record 38 | sn::other::Record field_04[5]; // must be optimized out, same as previous 39 | other::Record field_05[3][8]; // array of arrays 40 | }; 41 | } 42 | namespace not_supported_yet { 43 | // NON POD: not supported in phase 1 44 | // C++ Class -> PODstruct -> persistence[ HDF5 | ??? ] -> PODstruct -> C++ Class 45 | struct Container { 46 | double idx; // 47 | std::string field_05; // c++ object makes it non-POD 48 | std::vector field_02; // ditto 49 | }; 50 | } 51 | /* BEGIN IGNORED STRUCT */ 52 | // these structs are not referenced with h5::read|h5::write|h5::create operators 53 | // hence compiler should ignore them. 54 | struct IgnoredRecord { 55 | signed long int idx; 56 | float field_0n; 57 | }; 58 | /* END IGNORED STRUCTS */ 59 | } 60 | #endif 61 | -------------------------------------------------------------------------------- /examples/container/container.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | constexpr auto filename = "001.h5"; 11 | 12 | int main() { 13 | 14 | auto fd = h5::create(filename, H5F_ACC_TRUNC); 15 | { // CREATE - WRITE 16 | arma::mat M(2,3); M.ones(); // create a matrix 17 | h5::ds_t ds = h5::create(fd,"create then write" 18 | ,h5::current_dims{10,20} 19 | ,h5::max_dims{10,H5S_UNLIMITED} 20 | ,h5::chunk{2,3} | h5::fill_value{3} | h5::gzip{9} 21 | ); 22 | h5::write( ds, M, h5::offset{2,2}, h5::stride{1,3} ); 23 | } 24 | { 25 | arma::vec V( {1.,2.,3.,4.,5.,6.,7.,8.}); // create a vector 26 | // simple one shot write that computes current dimensions and saves matrix 27 | h5::write( filename, "one shot create write", V); 28 | // what if you want to position a matrix inside a higher dimension with some added complexity? 29 | h5::write( filename, "arma vec inside matrix", V // object contains 'count' and rank being written 30 | ,h5::current_dims{40,50} // control file_space directly where you want to place vector 31 | ,h5::offset{5,0} // when no explicit current dimension given current dimension := offset .+ object_dim .* stride (hadamard product) 32 | ,h5::count{1,1} 33 | ,h5::stride{3,5} 34 | ,h5::block{2,4} 35 | ,h5::max_dims{40,H5S_UNLIMITED} // wouldn't it be nice to have unlimited dimension? if no explicit chunk is set, then the object dimension 36 | // is used as unit chunk 37 | ); 38 | } 39 | { // CREATE - READ: we're reading back the dataset created in the very first step 40 | // note that data is only data, can be reshaped, cast to any format and content be modified through filtering 41 | h5::ds_t ds = h5::create(fd,"dataset", h5::current_dims{3,2}, h5::fill_value(NAN)); // create dataset, default to NaN-s 42 | auto M = h5::read( fd,"dataset" ); // read data back as matrix 43 | M.print(); 44 | } 45 | { // READ: 46 | arma::mat M = h5::read(filename,"create then write"); // read entire dataset back with a single read 47 | M.print(); 48 | } 49 | 50 | 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # _________________________________________________________ 2 | # Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | # Author: Varga, Steven 4 | # _________________________________________________________ 5 | 6 | PREFIX = /usr/local 7 | 8 | VERSION = 1.10.4.6 9 | DEB = -1~exp1 10 | PROGRAM_NAME=libh5cpp-dev 11 | BIN_DIR = $(PREFIX)/bin 12 | INCLUDE_DIR = $(PREFIX)/include 13 | EXAMPLE_DIR = $(PREFIX)/share 14 | 15 | MAN_BASE_DIR = $(PREFIX)/man 16 | MAN_DIR = $(MAN_BASE_DIR)/man1 17 | MAN_EXT = 1 18 | 19 | 20 | INSTALL = install # install : UCB/GNU Install compatiable 21 | 22 | RM = rm -f 23 | MKDIR = mkdir -p 24 | 25 | CC ?= gcc 26 | COMPILER_OPTIONS = -Wall -O -g 27 | 28 | INSTALL_PROGRAM = $(INSTALL) -c -m 0755 29 | INSTALL_DATA = $(INSTALL) -c -m 0644 30 | INSTALL_EXAMPLE = $(INSTALL) -c -m 0755 31 | INSTALL_INCLUDE = $(INSTALL) -m 0755 32 | 33 | OBJECT_FILES = 34 | #fdupes.o md5/md5.o $(ADDITIONAL_OBJECTS) 35 | 36 | ##################################################################### 37 | # no need to modify anything beyond this point # 38 | ##################################################################### 39 | 40 | all: 41 | 42 | 43 | installdirs: 44 | test -d $(INCLUDE_DIR) || $(MKDIR) $(MAN_DIR) 45 | 46 | install: installdirs 47 | echo "******** $(INCLUDE_DIR) *******" 48 | $(INSTALL_INCLUDE) -d $(INCLUDE_DIR)/h5cpp 49 | find h5cpp -type f -exec install -Dm 755 "{}" "${INCLUDE_DIR}/{}" \; 50 | $(INSTALL_EXAMPLE) -d $(EXAMPLE_DIR)/h5cpp 51 | find examples -type f -exec install -Dm 644 "{}" "${EXAMPLE_DIR}/h5cpp/{}" \; 52 | 53 | tar-gz: 54 | tar --exclude='.[^/]*' --exclude-vcs-ignores -czvf ../libh5cpp_${VERSION}.orig.tar.gz ./ 55 | gpg --detach-sign --armor ../libh5cpp_${VERSION}.orig.tar.gz 56 | scp ../libh5cpp_${VERSION}.orig.tar.* osaka:h5cpp.org/download/ 57 | clean: 58 | @$(RM) h5cpp-* 59 | 60 | dist-debian-src: tar-gz 61 | debuild -i -us -uc -S 62 | 63 | dist-debian-bin: 64 | debuild -i -us -uc -b 65 | 66 | dist-debian-src-upload: dist-debian-src 67 | debsign -k 1B04044AF80190D78CFBE9A3B971AC62453B78AE ../libh5cpp_${VERSION}${DEB}_source.changes 68 | #dput mentors ../libh5cpp_${VERSION}${DEB}_source.changes 69 | 70 | dist-rpm: dist-debian 71 | sudo alien -r ../libh5cpp-dev_${VERSION}_all.deb 72 | 73 | -------------------------------------------------------------------------------- /examples/datasets/datasets.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include 6 | #include 7 | #include 8 | 9 | constexpr auto filename = "001.h5"; 10 | 11 | int main() { 12 | 13 | auto fd = h5::create(filename, H5F_ACC_TRUNC); 14 | { // CREATE - WRITE 15 | arma::mat M(2,3); M.ones(); // create a matrix 16 | h5::ds_t ds = h5::create(fd,"create then write" 17 | ,h5::current_dims{10,20} 18 | ,h5::max_dims{10,H5S_UNLIMITED} 19 | ,h5::chunk{2,3} | h5::fill_value{3} | h5::gzip{9} 20 | ); 21 | h5::write( ds, M, h5::offset{2,2}, h5::stride{1,3} ); 22 | } 23 | { 24 | arma::vec V( {1.,2.,3.,4.,5.,6.,7.,8.}); // create a vector 25 | // simple one shot write that computes current dimensions and saves matrix 26 | h5::write( filename, "one shot create write", V); 27 | // what if you want to position a matrix inside a higher dimension with some added complexity? 28 | 29 | /* FIXME: hyperblock selection 30 | h5::write( filename, "arma vec inside matrix", V // object contains 'count' and rank being written 31 | ,h5::current_dims{40,50} // control file_space directly where you want to place vector 32 | ,h5::offset{5,0} // when no explicit current dimension given current dimension := offset .+ object_dim .* stride (hadamard product) 33 | ,h5::count{1,1} 34 | ,h5::stride{3,5} 35 | ,h5::block{2,4} 36 | ,h5::max_dims{40,H5S_UNLIMITED} // wouldn't it be nice to have unlimited dimension? if no explicit chunk is set, then the object dimension 37 | // is used as unit chunk 38 | );*/ 39 | } 40 | { // CREATE - READ: we're reading back the dataset created in the very first step 41 | // note that data is only data, can be reshaped, cast to any format and content be modified through filtering 42 | h5::ds_t ds = h5::create(fd,"dataset", h5::current_dims{3,2}, h5::fill_value(NAN)); // create dataset, default to NaN-s 43 | auto M = h5::read( fd,"dataset" ); // read data back as matrix 44 | M.print(); 45 | } 46 | { // READ: 47 | arma::mat M = h5::read(filename,"create then write"); // read entire dataset back with a single read 48 | M.print(); 49 | } 50 | 51 | 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /h5cpp/H5Dopen.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #ifndef H5CPP_DOPEN_HPP 7 | #define H5CPP_DOPEN_HPP 8 | 9 | namespace h5{ 10 | /** \ingroup file-io 11 | 12 | * open an existing dataset/document within an valid HDF5 file, the returned handle automatically closed when leaving code block 13 | * \par_fd \par_dataset_path \par_dapl \returns_fd 14 | * \sa_h5cpp \sa_hdf5 \sa_stl 15 | * @code 16 | * { 17 | * h5::fd_t fd = h5::open("example.h5", H5F_ACC_RDWR); // open an hdf5 file in read-write mode 18 | * h5::ds_t ds = h5::open(fd,"dataset.txt") // obtain ds descriptor 19 | * ... // do some work 20 | * } // ds and fd closes automatically 21 | * @endcode 22 | */ 23 | inline h5::ds_t open(const h5::fd_t& fd, const std::string& path, const h5::dapl_t& dapl = h5::default_dapl ){ 24 | 25 | H5CPP_CHECK_PROP( dapl, h5::error::io::dataset::open, "invalid data access property" ); 26 | 27 | hid_t ds; 28 | H5CPP_CHECK_NZ(( 29 | ds = H5Dopen2( static_cast(fd), path.data(), static_cast(dapl) )), 30 | h5::error::io::dataset::open, h5::error::msg::open_dataset ); 31 | // custom h5cpp specific C++ high throughpout filter 32 | // is abstracted out and hidden under property list 33 | // see: H5Pdapl.hpp and H5Pchunk.hpp for details 34 | hid_t dcpl = H5Dget_create_plist( ds ); 35 | 36 | switch( H5Pget_layout(dcpl) ){ 37 | case H5D_LAYOUT_ERROR: break; 38 | case H5D_NLAYOUTS: break; 39 | case H5D_COMPACT: break; 40 | case H5D_CONTIGUOUS: break; 41 | case H5D_CHUNKED: 42 | if( H5Pexist(dapl, H5CPP_DAPL_HIGH_THROUGHPUT) ){ 43 | // grab pointer to uninitialized pipeline 44 | h5::impl::pipeline_t* ptr; 45 | H5Pget(dapl, H5CPP_DAPL_HIGH_THROUGHPUT, &ptr); 46 | hid_t type_id = H5Dget_type( static_cast<::hid_t>(ds) ); 47 | size_t element_size = H5Tget_size( type_id ); 48 | ptr->set_cache(dcpl, element_size); 49 | } 50 | break; 51 | case H5D_VIRTUAL: break; 52 | } 53 | 54 | h5::ds_t ds_{ds}; 55 | //FIXME: temporary carry dapl around 56 | ds_.dapl = static_cast( dapl ); 57 | return ds_; 58 | } 59 | } 60 | 61 | #endif 62 | 63 | -------------------------------------------------------------------------------- /LICENSE.H5CPP: -------------------------------------------------------------------------------- 1 | 2 | ------------------------------------------------------------------------------- 3 | H5CPP may be used for any purpose, including commercial purposes, at absolutely 4 | no cost. It is distributed under the terms of the MIT license reproduced here. 5 | 6 | Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 7 | Author: Varga, Steven 8 | ------------------------------------------------------------------------------- 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy of 11 | this software and associated documentation files (the "Software"), to deal in 12 | the Software without restriction, including without limitation the rights to 13 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 14 | of the Software, and to permit persons to whom the Software is furnished to do 15 | so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 22 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 23 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 24 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 25 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | 27 | 28 | 29 | LLVM: University of Illinois/NCSA Open Source License 30 | Copyright (c) 2003-2017 University of Illinois at Urbana-Champaign. All rights reserved. 31 | see: LICENCE.LLVM 32 | 33 | HDF5: HDF5 (Hierarchical Data Format 5) Software Library and Utilities 34 | Copyright (c) 2006, The HDF Group. 35 | 36 | NCSA HDF5 (Hierarchical Data Format 5) Software Library and Utilities 37 | Copyright (c) 1998-2006, The Board of Trustees of the University of Illinois. All rights reserved. 38 | see: LICENCE.HDF5 39 | 40 | HALF FLOAT: examples/half-float/christian-rau/half.hpp 41 | Copyright (c) 2012-2019 Christian Rau 42 | see: LICENSE.HALF-FLOAT 43 | 44 | CSV: examples/csv/csv.h 45 | Copyright (c) 2015, ben-strasser 46 | see: LICENSE.CSV 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /examples/linalg/itpp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | // 11 | template using Matrix = itpp::Mat; 12 | template using Colvec = itpp::Vec; 13 | 14 | int main(){ 15 | { // CREATE - WRITE 16 | Matrix M(2,3); // create a matrix 17 | h5::fd_t fd = h5::create("linalg.h5",H5F_ACC_TRUNC); // and a file 18 | h5::ds_t ds = h5::create(fd,"create then write" 19 | ,h5::current_dims{10,20} 20 | ,h5::max_dims{10,H5S_UNLIMITED} 21 | ,h5::chunk{2,3} | h5::fill_value{3} | h5::gzip{9} 22 | ); 23 | h5::write( ds, M, h5::offset{2,2}, h5::stride{1,3} ); 24 | } 25 | 26 | { 27 | Colvec V(8); // create a vector 28 | // simple one shot write that computes current dimensions and saves matrix 29 | h5::write( "linalg.h5", "one shot create write", V); 30 | // what if you want to position a matrix inside a higher dimension with some added complexity? 31 | h5::write( "linalg.h5", "arma vec inside matrix", V // object contains 'count' and rank being written 32 | ,h5::current_dims{40,50} // control file_space directly where you want to place vector 33 | ,h5::offset{5,0} // when no explicit current dimension given current dimension := offset .+ object_dim .* stride (hadamard product) 34 | ,h5::count{1,1}, h5::stride{3,5}, h5::block{2,4} 35 | ,h5::max_dims{40,H5S_UNLIMITED} // wouldn't it be nice to have unlimited dimension? if no explicit chunk is set, then the object dimension 36 | // is used as unit chunk 37 | ); 38 | } 39 | { // CREATE - READ: we're reading back the dataset created in the very first step 40 | // note that data is only data, can be reshaped, cast to any format and content be modified through filtering 41 | auto fd = h5::open("linalg.h5", H5F_ACC_RDWR, // you can have multiple fd open with H5F_ACC_RDONLY, but single write 42 | h5::fclose_degree_strong | h5::sec2); // and able to set various properties 43 | } 44 | { // READ: 45 | Matrix M = h5::read>("linalg.h5","create then write"); // read entire dataset back with a single read 46 | } 47 | } 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /examples/linalg/blitz.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | // 12 | 13 | template using Colvec = blitz::Array; 14 | template using Matrix = blitz::Array; 15 | template using Cube = blitz::Array; 16 | 17 | int main(){ 18 | { // CREATE - WRITE 19 | Matrix M(2,3); // create a matrix 20 | h5::fd_t fd = h5::create("linalg.h5",H5F_ACC_TRUNC); // and a file 21 | h5::ds_t ds = h5::create(fd,"create then write" 22 | ,h5::current_dims{10,20} 23 | ,h5::max_dims{10,H5S_UNLIMITED} 24 | ,h5::chunk{2,3} | h5::fill_value{3} | h5::gzip{9} 25 | ); 26 | h5::write( ds, M, h5::offset{2,2}, h5::stride{1,3} ); 27 | } 28 | 29 | { 30 | Colvec V(4); // create a vector 31 | // simple one shot write that computes current dimensions and saves matrix 32 | h5::write( "linalg.h5", "one shot create write", V); 33 | // what if you want to position a matrix inside a higher dimension with some added complexity? 34 | h5::write( "linalg.h5", "vector inside matrix", V // object contains 'count' and rank being written 35 | ,h5::current_dims{40,50} // control file_space directly where you want to place vector 36 | ,h5::offset{5,0} // when no explicit current dimension given current dimension := offset .+ object_dim .* stride (hadamard product) 37 | ,h5::stride{4,4}, h5::block{3,3} 38 | ,h5::max_dims{40,H5S_UNLIMITED} // wouldn't it be nice to have unlimited dimension? if no explicit chunk is set, then the object dimension 39 | // is used as unit chunk 40 | ); 41 | } 42 | { // CREATE - READ: we're reading back the dataset created in the very first step 43 | // note that data is only data, can be reshaped, cast to any format and content be modified through filtering 44 | auto fd = h5::open("linalg.h5", H5F_ACC_RDWR, // you can have multiple fd open with H5F_ACC_RDONLY, but single write 45 | h5::fclose_degree_strong | h5::sec2); // and able to set various properties 46 | } 47 | { // READ: 48 | Matrix M = h5::read>("linalg.h5","create then write"); // read entire dataset back with a single read 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /examples/half-float/open-exr/README.md: -------------------------------------------------------------------------------- 1 | Industrial Light and Magick - OpenEXR half float support 2 | ---------------------------------------------- 3 | 4 | Obtain OpenEXR half float implementation: [ilmbase-x.y.z.tar.gz](https://www.openexr.com/downloads.html) and untar into some directory, configure and install 5 | ``` 6 | tar -xzf ilmbase-2.3.0.tar.gz 7 | ./configure --prefix=/usr/local 8 | make -j4 && sudo make install 9 | ``` 10 | 11 | usage and caveats 12 | -------- 13 | `-D WITH_OPENXDR_HALF` activates the shim code, since the internal include guards are `_HALF_H` deemed to be inadequate, to make it even less cheerful OpenEXR half precision add-on is **not embedded in namespace**. As a workaround, there is an optional by default empty `OPENEXR_NAMESPACE` macro to control namespaces. In order to make this work **you must hack the OpenEXR library** and recompile it with **namespace added**. 14 | 15 | **compiler assisted reflection:** not available, as half is not a POD type 16 | 17 | *Contacting listed authors failed, posted on mailing list, waiting for their reply.* 18 | 19 | 20 | The IEEE 754 standard specifies a binary16 as having the following format: 21 | - Sign bit: 1 bit 22 | - Exponent width: 5 bits 23 | - Significand precision: 11 bits (10 explicitly stored) 24 | 25 | Layout: 26 | ``` 27 | 15 (msb) 28 | | 29 | | 14 10 30 | | | | 31 | | | | 9 0 (lsb) 32 | | | | | | 33 | X XXXXX XXXXXXXXXX 34 | ``` 35 | 36 | Examples: 37 | ``` 38 | 0 00000 0000000000 = 0.0 39 | 0 01110 0000000000 = 0.5 40 | 0 01111 0000000000 = 1.0 41 | 0 10000 0000000000 = 2.0 42 | 0 10000 1000000000 = 3.0 43 | 1 10101 1111000001 = -124.0625 44 | 0 11111 0000000000 = +infinity 45 | 1 11111 0000000000 = -infinity 46 | 0 11111 1000000000 = NAN 47 | 1 11111 1111111111 = NAN 48 | ``` 49 | 50 | 51 | 52 | The format is laid out as follows: 53 | `[1 bit sign | 5 bit exponent | 10 bit mantissa]` the exponent encoded using an offset-binary representation, with the zero offset being 15. 54 | 55 | ```bash 56 | HDF5 "example.h5" { 57 | GROUP "/" { 58 | DATASET "type" { 59 | DATATYPE 16-bit little-endian floating-point 60 | DATASPACE SIMPLE { ( 20 ) / ( 20 ) } 61 | DATA { 62 | (0): 55.7812, 89.375, 90.125, -29.3906, -90.3125, -48.4688, -1.17871, 63 | (7): 55.1875, -21.6719, 12.7578, -63.7188, 9.22656, 50.625, 37.0938, 64 | (14): -81.8125, -32.7812, 89.5, -28.3906, -44.125, -41.125 65 | } 66 | } 67 | } 68 | } 69 | ``` 70 | -------------------------------------------------------------------------------- /examples/linalg/arma.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include 6 | #include 7 | 8 | 9 | int main(){ 10 | { // CREATE - WRITE 11 | arma::mat M(2,3); M.ones(); // create a matrix 12 | h5::fd_t fd = h5::create("arma.h5",H5F_ACC_TRUNC); // and a file 13 | h5::ds_t ds = h5::create(fd,"create then write" 14 | ,h5::current_dims{10,20} 15 | ,h5::max_dims{10,H5S_UNLIMITED} 16 | ,h5::chunk{2,3} | h5::fill_value{3} | h5::gzip{9} 17 | ); 18 | h5::write( ds, M, h5::offset{2,2}, h5::stride{1,3} ); 19 | } 20 | { 21 | arma::vec V( {1.,2.,3.,4.,5.,6.,7.,8.}); // create a vector 22 | // simple one shot write that computes current dimensions and saves matrix 23 | h5::write( "arma.h5", "one shot create write", V); 24 | // what if you want to position a matrix inside a higher dimension with some added complexity? 25 | h5::write( "arma.h5", "arma vec inside matrix", V // object contains 'count' and rank being written 26 | ,h5::current_dims{40,50} // control file_space directly where you want to place vector 27 | ,h5::offset{5,0} // when no explicit current dimension given current dimension := offset .+ object_dim .* stride (hadamard product) 28 | ,h5::count{1,1} 29 | ,h5::stride{3,5} 30 | ,h5::block{2,4} 31 | ,h5::max_dims{40,H5S_UNLIMITED} // wouldn't it be nice to have unlimited dimension? if no explicit chunk is set, then the object dimension 32 | // is used as unit chunk 33 | ); 34 | } 35 | { // CREATE - READ: we're reading back the dataset created in the very first step 36 | // note that data is only data, can be reshaped, cast to any format and content be modified through filtering 37 | auto fd = h5::open("arma.h5", H5F_ACC_RDWR, // you can have multiple fd open with H5F_ACC_RDONLY, but single write 38 | h5::fclose_degree_strong | h5::sec2); // and able to set various properties 39 | h5::ds_t ds = h5::create(fd,"dataset", h5::current_dims{3,2}, h5::fill_value(NAN)); // create dataset, default to NaN-s 40 | auto M = h5::read( fd,"dataset" ); // read data back as matrix 41 | M.print(); 42 | } 43 | { // READ: 44 | arma::mat M = h5::read("arma.h5","create then write"); // read entire dataset back with a single read 45 | M.print(); 46 | } 47 | } 48 | 49 | 50 | -------------------------------------------------------------------------------- /h5cpp/H5Dgather.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 - 2021 vargaconsulting, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #ifndef H5CPP_DGATHER_HPP 6 | #define H5CPP_DGATHER_HPP 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace h5 { 14 | 15 | /** @brief gathers memory regions into a single set of pointers 16 | * Objects may be classified by whether the content resides in contiguous memory location, making convenient 17 | * to IO operation: only single call is needed; or scattered and we need a reliable mechanism to collect the 18 | * content.
19 | * `h5::gather` is a template mechanism to facilitate the latter process by finding and returning a set of 20 | * `element_t` type pointers to the actual content of an object. 21 | * @param ref arbitrary object with non-contiguous content 22 | * @param ptr element type pointer with the correct size respect to `ref` object 23 | * @return ptr the same `element_t` pointer passed to the call 24 | * @tparam T C++ type of dataset being written into HDF5 container 25 | */ 26 | template inline 27 | const E** gather(const T& ref, std::vector& ptrs) { 28 | std::cout <<"< +++++++++ >\n"; 29 | 30 | return ptrs.data(); 31 | } 32 | /** @brief gathers memory regions into a single set of pointers 33 | * Objects may be classified by whether the content resides in contiguous memory location, making convenient 34 | * to IO operation: only single call is needed; or scattered and we need a reliable mechanism to collect the 35 | * content.
36 | * `h5::gather` is a template mechanism to facilitate the latter process by finding and returning a set of 37 | * `element_t` type pointers to the actual content of an object. 38 | * @param ref arbitrary object with non-contiguous content 39 | * @param ptr element type pointer with the correct size respect to `ref` object 40 | * @return ptr the same `element_t` pointer passed to the call 41 | * @tparam T C++ type of dataset being written into HDF5 container 42 | */ 43 | template <> inline 44 | const char** gather>( const std::vector& ref, std::vector& ptrs){ 45 | for(auto& element: ref) 46 | ptrs.push_back(element.data()); 47 | return ptrs.data(); 48 | } 49 | } 50 | #endif -------------------------------------------------------------------------------- /examples/linalg/ublas.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | using namespace std; 13 | // 14 | template using Matrix = boost::numeric::ublas::matrix; 15 | template using Colvec = boost::numeric::ublas::vector; 16 | 17 | 18 | int main(){ 19 | { // CREATE - WRITE 20 | Matrix M(2,3); // create a matrix 21 | h5::fd_t fd = h5::create("linalg.h5",H5F_ACC_TRUNC); // and a file 22 | h5::ds_t ds = h5::create(fd,"create then write" 23 | ,h5::current_dims{10,20} 24 | ,h5::max_dims{10,H5S_UNLIMITED} 25 | ,h5::chunk{2,3} | h5::fill_value{3} | h5::gzip{9} 26 | ); 27 | h5::write( ds, M, h5::offset{2,2}, h5::stride{1,3} ); 28 | } 29 | 30 | { 31 | Colvec V(8); // create a vector 32 | // simple one shot write that computes current dimensions and saves matrix 33 | h5::write( "linalg.h5", "one shot create write", V); 34 | // what if you want to position a matrix inside a higher dimension with some added complexity? 35 | h5::write( "linalg.h5", "vector inside matrix", V // object contains 'count' and rank being written 36 | ,h5::current_dims{40,50} // control file_space directly where you want to place vector 37 | ,h5::offset{5,0} // when no explicit current dimension given current dimension := offset .+ object_dim .* stride (hadamard product) 38 | ,h5::count{1,1}, h5::stride{3,5}, h5::block{2,4} 39 | ,h5::max_dims{40,H5S_UNLIMITED} // wouldn't it be nice to have unlimited dimension? if no explicit chunk is set, then the object dimension 40 | // is used as unit chunk 41 | ); 42 | } 43 | { // CREATE - READ: we're reading back the dataset created in the very first step 44 | // note that data is only data, can be reshaped, cast to any format and content be modified through filtering 45 | auto fd = h5::open("linalg.h5", H5F_ACC_RDWR, // you can have multiple fd open with H5F_ACC_RDONLY, but single write 46 | h5::fclose_degree_strong | h5::sec2); // and able to set various properties 47 | } 48 | { // READ: 49 | Matrix M = h5::read>("linalg.h5","create then write"); // read entire dataset back with a single read 50 | } 51 | } 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /examples/linalg/blaze.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | // 12 | 13 | template using Matrix = blaze::DynamicMatrix; 14 | template using Colvec = blaze::DynamicVector; 15 | /* only DYNAMIC [MATRIX|VECTOR] are supported */ 16 | 17 | int main(){ 18 | { // CREATE - WRITE 19 | Matrix M(2,3); // create a matrix 20 | h5::fd_t fd = h5::create("linalg.h5",H5F_ACC_TRUNC); // and a file 21 | h5::ds_t ds = h5::create(fd,"create then write" 22 | ,h5::current_dims{10,20} 23 | ,h5::max_dims{10,H5S_UNLIMITED} 24 | ,h5::chunk{2,3} | h5::fill_value{3} | h5::gzip{9} 25 | ); 26 | h5::write( ds, M, h5::offset{2,2}, h5::stride{1,3} ); 27 | } 28 | 29 | { 30 | Colvec V( {1.,2.,3.,4.,5.,6.,7.,8.}); // create a vector 31 | // simple one shot write that computes current dimensions and saves matrix 32 | h5::write( "linalg.h5", "one shot create write", V); 33 | // what if you want to position a matrix inside a higher dimension with some added complexity? 34 | h5::write( "linalg.h5", "vector inside matrix", V // object contains 'count' and rank being written 35 | ,h5::count{1,1} // encodes rank and shape: 2x4 block 36 | ,h5::current_dims{40,50} // control file_space directly where you want to place vector 37 | ,h5::offset{5,0} // when no explicit current dimension given current dimension := offset .+ object_dim .* stride (hadamard product) 38 | ,h5::stride{3,5} // 39 | ,h5::block{2,4} // 40 | ,h5::max_dims{40,H5S_UNLIMITED} // wouldn't it be nice to have unlimited dimension? if no explicit chunk is set, then the object dimension 41 | // is used as unit chunk 42 | ); 43 | } 44 | { // CREATE - READ: we're reading back the dataset created in the very first step 45 | // note that data is only data, can be reshaped, cast to any format and content be modified through filtering 46 | auto fd = h5::open("linalg.h5", H5F_ACC_RDWR, // you can have multiple fd open with H5F_ACC_RDONLY, but single write 47 | h5::fclose_degree_strong | h5::sec2); // and able to set various properties 48 | } 49 | { // READ: 50 | Matrix M = h5::read>("linalg.h5","create then write"); // read entire dataset back with a single read 51 | } 52 | } 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /examples/compound/struct.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include 6 | #include 7 | #include "struct.h" 8 | #include 9 | // generated file must be sandwiched between core and io 10 | // to satisfy template dependencies in 11 | #include "generated.h" 12 | #include 13 | #include "utils.hpp" 14 | 15 | #define CHUNK_SIZE 5 16 | #define NROWS 4*CHUNK_SIZE 17 | #define NCOLS 1*CHUNK_SIZE 18 | 19 | int main(){ 20 | //RAII will close resource, noo need H5Fclose( any_longer ); 21 | h5::fd_t fd = h5::create("example.h5",H5F_ACC_TRUNC); 22 | 23 | {// LINARG:=[armaidllo|eigen3|blaze|blitz|it++|dlib|ublas] supported 24 | arma::imat M(NROWS,NCOLS); // define a linalg object 25 | h5::write(fd, "/linalg/armadillo",M); // save it somewhere, partial and full read|write and append supported 26 | } 27 | {// create a Matrix of STRUCT with chunked and GZIP compressed properties ready for partial read|write 28 | // upto 7 dimensions/extents are supported 29 | h5::create(fd, "/orm/chunked_2D", 30 | h5::current_dims{NROWS,NCOLS}, h5::chunk{1,CHUNK_SIZE} | h5::gzip{8} ); 31 | //FIXME: defaults to unit chunk, which may not the best setting, yet chunking is required for unlimted 32 | // should we have some plausable value: 1024 instead? 33 | h5::create(fd, "/orm/typecheck", h5::max_dims{H5S_UNLIMITED} ); 34 | } 35 | 36 | { // creates + writes entire object tree 37 | std::vector vec = h5::utils::get_test_data(20); 38 | h5::write(fd, "orm/partial/vector one_shot", vec ); 39 | // dimensions and other properties specified additional argument 40 | h5::write(fd, "orm/partial/vector custom_dims", vec, 41 | h5::max_dims{H5S_UNLIMITED}, h5::gzip{9} | h5::chunk{20} ); 42 | // you don't need to remember order, compiler will do it for you without runtime penalty: 43 | h5::write(fd, "orm/partial/vector custom_dims different_order", vec, 44 | h5::chunk{20} | h5::gzip{9}, 45 | h5::max_dims{H5S_UNLIMITED}, 46 | // how much to move from current location to next, stide[i] >= block[i] must hold 47 | // gap = block[i] - stride[i] 48 | h5::stride{6}, h5::block{4}, 49 | h5::current_dims{100}, h5::offset{2}); 50 | } 51 | 52 | { // read entire dataset back 53 | using T = std::vector; 54 | auto data = h5::read(fd,"/orm/partial/vector one_shot"); 55 | std::cerr <<"reading back data previously written:\n\t"; 56 | for( auto r:data ) 57 | std::cerr << r.idx <<" "; 58 | std::cerr << std::endl; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /examples/mpi/collective.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #pragma GCC diagnostic ignored "-Wnarrowing" 13 | // armadillo 14 | //./configure -DCMAKE_INSTALL_PREFIX=/usr/local -DDETECT_HDF5=OFF 15 | int main(int argc, char** argv) { 16 | 17 | // usual boiler place 18 | int size, rank, name_len; 19 | char processor_name[MPI_MAX_PROCESSOR_NAME]; 20 | MPI_Init(NULL, NULL); 21 | MPI_Info info = MPI_INFO_NULL; 22 | MPI_Comm comm = MPI_COMM_WORLD; 23 | 24 | MPI_Comm_size(MPI_COMM_WORLD, &size); 25 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); 26 | MPI_Get_processor_name(processor_name, &name_len); 27 | 28 | int nrows = 10; 29 | { // CREATE - WRITE 30 | std::vector v(nrows); 31 | std::fill(std::begin(v), std::end(v), rank + 2 ); 32 | // open file with MPIIO 33 | auto fd = h5::create("collective.h5", H5F_ACC_TRUNC, 34 | h5::fcpl, 35 | h5::mpiio({MPI_COMM_WORLD, info}) // pass the communicator and hints as usual 36 | ); 37 | // single write request is expanded to chunked write at compile time, setting up 38 | // required arguments. 39 | // Passed property lists, chunk and size descriptors may be interchanged, and or omitted 40 | h5::write( fd, "dataset", v, 41 | h5::chunk{nrows,1}, h5::current_dims{nrows,size}, h5::offset{0,rank}, h5::count{nrows,1}, 42 | h5::collective ); // this makes `collective IO` magic happen 43 | // RAII will close all descriptors when leaving code block 44 | } 45 | 46 | { // READ 47 | // open container with MPIIO enabled 48 | auto fd = h5::open("collective.h5", H5F_ACC_RDWR, h5::mpiio({MPI_COMM_WORLD, info})); 49 | // this is a single shot read, all memory reservations are inside the `read` operator, convenient 50 | // but suboptimal for loops. 51 | auto data = h5::read>(fd, "dataset", h5::offset{0,rank}, h5::count{nrows,1}, h5::collective); 52 | std::cout << "rank: " << rank <<" data: "; 53 | for( auto v : data) std::cout << v << " "; std::cout <<" "; 54 | 55 | // for high performance loops constructs please use: 56 | std::vector buffer(nrows); // pre-allocate buffer, see documentation for variety of 57 | // linear algebra, the STL or raw memory objects 58 | 59 | // make sure to open dataset outside of the loop 60 | auto ds = h5::open(fd, "dataset"); 61 | // this is as efficient as it gets 62 | h5::read(ds, buffer.data(), h5::offset{0,rank}, h5::count{nrows,1}, h5::collective); 63 | } 64 | 65 | MPI_Barrier(MPI_COMM_WORLD); 66 | MPI_Finalize(); 67 | } 68 | -------------------------------------------------------------------------------- /examples/mpi/independent.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #pragma GCC diagnostic ignored "-Wnarrowing" 13 | // armadillo 14 | //./configure -DCMAKE_INSTALL_PREFIX=/usr/local -DDETECT_HDF5=OFF 15 | int main(int argc, char** argv) { 16 | 17 | // usual boiler place 18 | int size, rank, name_len; 19 | char processor_name[MPI_MAX_PROCESSOR_NAME]; 20 | MPI_Init(NULL, NULL); 21 | MPI_Info info = MPI_INFO_NULL; 22 | MPI_Comm comm = MPI_COMM_WORLD; 23 | 24 | MPI_Comm_size(MPI_COMM_WORLD, &size); 25 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); 26 | MPI_Get_processor_name(processor_name, &name_len); 27 | 28 | int nrows = 10; 29 | { // CREATE - WRITE 30 | std::vector v(nrows); 31 | std::fill(std::begin(v), std::end(v), rank + 2 ); 32 | // open file with MPIIO 33 | auto fd = h5::create("collective.h5", H5F_ACC_TRUNC, 34 | h5::fcpl, 35 | h5::mpiio({MPI_COMM_WORLD, info}) // pass the communicator and hints as usual 36 | ); 37 | // single write request is expanded to chunked write at compile time, setting up 38 | // required arguments. 39 | // Passed property lists, chunk and size descriptors may be interchanged, and or omitted 40 | h5::write( fd, "dataset", v, 41 | h5::chunk{nrows,1}, h5::current_dims{nrows,size}, h5::offset{0,rank}, h5::count{nrows,1}, 42 | h5::independent ); // this makes `collective IO` magic happen 43 | // RAII will close all descriptors when leaving code block 44 | } 45 | 46 | { // READ 47 | // open container with MPIIO enabled 48 | auto fd = h5::open("collective.h5", H5F_ACC_RDWR, h5::mpiio({MPI_COMM_WORLD, info})); 49 | // this is a single shot read, all memory reservations are inside the `read` operator, convenient 50 | // but suboptimal for loops. 51 | auto data = h5::read>(fd, "dataset", h5::offset{0,rank}, h5::count{nrows,1}, h5::collective); 52 | std::cout << "rank: " << rank <<" data: "; 53 | for( auto v : data) std::cout << v << " "; std::cout <<" "; 54 | 55 | // for high performance loops constructs please use: 56 | std::vector buffer(nrows); // pre-allocate buffer, see documentation for variety of 57 | // linear algebra, the STL or raw memory objects 58 | 59 | // make sure to open dataset outside of the loop 60 | auto ds = h5::open(fd, "dataset"); 61 | // this is as efficient as it gets 62 | h5::read(ds, buffer.data(), h5::offset{0,rank}, h5::count{nrows,1}, h5::independent); 63 | } 64 | 65 | MPI_Barrier(MPI_COMM_WORLD); 66 | MPI_Finalize(); 67 | } 68 | -------------------------------------------------------------------------------- /LICENSE.HDF5_LBNL: -------------------------------------------------------------------------------- 1 | Copyright Notice and License Terms for 2 | HDF5 (Hierarchical Data Format 5) Software Library and Utilities 3 | ----------------------------------------------------------------------------- 4 | 5 | HDF5 (Hierarchical Data Format 5) 6 | Copyright (c) 2016, The Regents of the University of California, through 7 | Lawrence Berkeley National Laboratory (subject to receipt of any required 8 | approvals from the U.S. Dept. of Energy). 9 | 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | 1. Redistributions of source code must retain the above copyright notice, 16 | this list of conditions, and the following disclaimer. 17 | 18 | 2. Redistributions in binary form must reproduce the above copyright notice, 19 | this list of conditions, and the following disclaimer in the documentation 20 | and/or materials provided with the distribution. 21 | 22 | 3. Neither the name of the University of California, Lawrence Berkeley 23 | National Laboratory, U.S. Dept. of Energy nor the names of its contributors 24 | may be used to endorse or promote products derived from this software without 25 | specific prior written permission. 26 | 27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 28 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 31 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 37 | THE POSSIBILITY OF SUCH DAMAGE. 38 | 39 | You are under no obligation whatsoever to provide any bug fixes, patches, 40 | or upgrades to the features, functionality or performance of the source 41 | code ("Enhancements") to anyone; however, if you choose to make your 42 | Enhancements available either publicly, or directly to Lawrence Berkeley 43 | National Laboratory, without imposing a separate written license agreement 44 | for such Enhancements, then you hereby grant the following license: 45 | a non-exclusive, royalty-free perpetual license to install, use, modify, 46 | prepare derivative works, incorporate into other computer software, 47 | distribute, and sublicense such enhancements or derivative works thereof, 48 | in binary and source code form. 49 | 50 | -------------------------------------------------------------------------------- /h5cpp/H5Zpipeline_basic.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #ifndef H5CPP_PIPELINE_BASIC_HPP 6 | #define H5CPP_PIPELINE_BASIC_HPP 7 | 8 | 9 | inline void h5::impl::basic_pipeline_t::write_chunk_impl( const hsize_t* offset, size_t nbytes, const void* data ){ 10 | 11 | size_t length = nbytes; // filter may change this, think of compression 12 | void *in = chunk0, *out=chunk1, *tmp = chunk0; // invariant: out must point to data block written 13 | uint32_t mask = 0x0; // filter mask = 0x0 all filters applied 14 | switch( tail ){ // tail = index pointing to queue holding filters 15 | case 0: // no filters, ( if blocking ) -> data == chunk0 otherwise directly from container 16 | H5Dwrite_chunk( ds, dxpl, 0x0, offset, nbytes, data); 17 | break; 18 | case 1: // single filter 19 | length = filter[0](out, data, nbytes, flags[0], cd_size[0], cd_values[0] ) ; 20 | if( !length ) 21 | mask = 1 << 0; 22 | default: // more than one filter 23 | for(hsize_t j=1; j 1.10.4 30 | H5Dwrite_chunk(ds, dxpl, mask, offset, length, out); 31 | } 32 | } 33 | 34 | 35 | inline void h5::impl::basic_pipeline_t::read_chunk_impl( const hsize_t* offset, size_t nbytes, void* data){ 36 | size_t length = nbytes; // filter may changed this, think of compression 37 | void *in = chunk0, *out=chunk1, *tmp = chunk1; // invariant: out must point to data block written 38 | uint32_t filter_mask; 39 | // for(int i=0; i<9; i++) 40 | // std::cout << ((short*) in)[i] << " "; 41 | // std::cout<<"\n"; 42 | 43 | switch( tail ){ // tail = index pointing to queue holding filters 44 | case 0: // no filters, ( if blocking ) -> data == chunk0 otherwise directly from container 45 | H5Dread_chunk(ds, dxpl, offset, &filter_mask, chunk0); 46 | break; 47 | case 1: // single filter 48 | H5Dread_chunk(ds, dxpl, offset, &filter_mask, chunk1); 49 | length = filter[0](chunk0, chunk1, nbytes, flags[0], cd_size[0], cd_values[0] ); 50 | break; 51 | default: // more than one filter 52 | throw std::runtime_error("filters not implemented yet..."); 53 | if( tail % 2 ){ 54 | H5Dread_chunk(ds, dxpl, offset, &filter_mask, chunk0); 55 | for(int j=tail; j>0; j--){ // invariant: out == buffer holding final result 56 | tmp = in, in = out, out = tmp; 57 | length = filter[j](out,in,length, flags[j], cd_size[j], cd_values[j]); 58 | } 59 | } 60 | // direct write available from > 1.10.4 61 | } 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /examples/raw_memory/raw.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include 6 | #include 7 | #define values 0,1,2,3,4,5,6,7,8,9 8 | 9 | int main(){ 10 | h5::fd_t fd = h5::create("raw.h5",H5F_ACC_TRUNC); 11 | 12 | float af[] = {values}; 13 | double ad[] = {values}; 14 | double* ptr = static_cast( calloc(10,sizeof(double)) ); 15 | 16 | { // dataset create: 17 | auto ds_0 = h5::create(fd,"/type/short with inline dcpl", 18 | h5::current_dims{10,20}, h5::max_dims{10,H5S_UNLIMITED}, 19 | h5::create_path | h5::utf8, // optional lcpl with this default settings** 20 | h5::chunk{2,3} | h5::fill_value{42} | h5::fletcher32 | h5::shuffle | h5::nbit | h5::gzip{9}, // optional dcpl 21 | h5::default_dapl ); // optional dapl 22 | //** lcpl controls how path (or hdf5 name: links) created, `h5::create_path` makes sure that sub paths are created 23 | // h5::default_lcpl and h5::lcpl are predifined conveniently such that h5::defeult_lcpl ::= h5::create_path | h5::utf8 24 | 25 | h5::dcpl_t dcpl = h5::chunk{2,3} | h5::fill_value{42} | h5::fletcher32 | h5::shuffle | h5::nbit | h5::gzip{9}; 26 | // same as above, default values implicit, dcpl explicit 27 | auto ds_1 = h5::create(fd,"/type/short explicit dcpl", h5::current_dims{10,20}, h5::max_dims{10,H5S_UNLIMITED}, dcpl); 28 | // same as above, default values explicit 29 | auto ds_2 = h5::create(fd,"/type/short default dcpl lcpl", h5::current_dims{10,20}, h5::max_dims{10,H5S_UNLIMITED}, 30 | h5::default_lcpl, dcpl, h5::default_dapl); 31 | // if only max_dims specified, the current dims is set to max_dims or zero if the dimension is H5S_UNLIMITED 32 | // making it suitable storage for packet table 33 | auto ds_3 = h5::create(fd,"/type/short max_dims", h5::max_dims{10,H5S_UNLIMITED}, // [10 X 0] 34 | h5::chunk{10,1} | h5::gzip{9} ); 35 | // expandable dataset with compression and chunksize explicitly set 36 | h5::create(fd,"/types/string with chunk and compression", h5::max_dims{H5S_UNLIMITED}, h5::chunk{10} | h5::gzip{9} ); 37 | } 38 | { // create + write from 1D memory location into a 2D file space 39 | h5::write(fd,"dataset", ad, h5::count{1,10}); 40 | } 41 | 42 | { // read back to memory location: 2D file space -> 1D mem space from specified offset 43 | h5::read(fd,"dataset", ptr, h5::count{1,8}, h5::offset{0,2} ); 44 | 45 | std::cout<<"valued read: "; 46 | for(int i=0; i<10; i++) std::cout<< ptr[i] <<" "; 47 | std::cout<<"\n"; 48 | 49 | //if you want to change memory offset, manipulate the passed pointer 50 | h5::read(fd,"dataset", ptr+4, h5::count{1,3} ); 51 | } 52 | free( ptr ); 53 | 54 | 55 | } 56 | 57 | -------------------------------------------------------------------------------- /examples/stl/vector.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | 7 | /** @example vector.cpp 8 | * A description of the example file, causes the example file to show up in 9 | * Examples */ 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include "struct.h" 16 | #include 17 | // compound type descriptor must be sandwiched between core and io 18 | // to satisfy template dependencies in 19 | #include "generated.h" 20 | #include 21 | #include "utils.hpp" 22 | 23 | #define CHUNK_SIZE 5 24 | #define NROWS 4*CHUNK_SIZE 25 | #define NCOLS 1*CHUNK_SIZE 26 | 27 | int main(){ 28 | //RAII will close resource, noo need H5Fclose( any_longer ); 29 | h5::fd_t fd = h5::create("example.h5",H5F_ACC_TRUNC); 30 | { 31 | std::vector v(10, 1.0); 32 | h5::write(fd,"stl/vector/full.dat", v); // simplest example 33 | 34 | //An elaborate example to demonstrate how to use H5CPP when you know the details, but no time/budget 35 | //to code it. The performance must be on par with the best C implementation -- if not: shoot an email and I fix it 36 | h5::create(fd,"stl/vector/partial.dat", 37 | // arguments can be written any order without loss of performance thanks to compile time parsing 38 | h5::current_dims{21,10},h5::max_dims{H5S_UNLIMITED,10}, h5::chunk{1,10} | h5::gzip{9} ); 39 | 40 | // you have some memory region you liked to read/write from, and H5CPP doesn't know of your object + no time to 41 | // fiddle around you want it done: 42 | // SOLUTION: write/read from/to memory region, NOTE the type cast: h5::write( ... ); 43 | h5::write(fd,"stl/vector/partial.dat", v, h5::offset{2,3}, h5::count{2,5}); 44 | } 45 | 46 | { // creates + writes entire POD STRUCT tree 47 | std::vector vec = h5::utils::get_test_data(20); 48 | h5::write(fd, "orm/partial/vector one_shot", vec ); 49 | // dimensions and other properties specified additional argument 50 | h5::write(fd, "orm/partial/vector custom_dims", vec, 51 | h5::max_dims{H5S_UNLIMITED}, h5::gzip{9} | h5::chunk{20} ); 52 | // you don't need to remember order, compiler will do it for you without runtime penalty: 53 | h5::write(fd, "orm/partial/vector custom_dims different_order", vec, 54 | h5::chunk{20} | h5::gzip{9}, 55 | h5::block{2}, h5::max_dims{H5S_UNLIMITED}, h5::stride{4}, h5::current_dims{100}, h5::offset{3} ); 56 | } 57 | { // read entire dataset back 58 | using T = std::vector; 59 | auto data = h5::read(fd,"/orm/partial/vector one_shot"); 60 | std::cerr <<"reading back data previously written:\n\t"; 61 | for( auto r:data ) 62 | std::cerr << r.idx <<" "; 63 | std::cerr << std::endl; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /h5cpp/H5Fcreate.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #ifndef H5CPP_FCREATE_HPP 7 | #define H5CPP_FCREATE_HPP 8 | 9 | /** 10 | * @namespace h5 11 | * @brief public namespace 12 | */ 13 | /* 14 | */ 15 | namespace h5{ 16 | /** @ingroup file-io 17 | * @brief creates an HDF5 file with given set of properties and returns a managed h5::fd_t resource handle. Depending on 18 | * active [conversion policy](@ref link_conversion_policy) h5::fd_t may be passed 19 | * [implicitly,explicitly](http://en.cppreference.com/w/cpp/language/explicit) or not at all to 20 | * HDF5 CAPI calls. 21 | * 22 | * 23 | * \par_file_path \par_fcrt_flags \par_fcpl \par_fapl \returns_fd 24 | * \sa_h5cpp \sa_hdf5 \sa_stl 25 | * @code 26 | * { 27 | * auto fd = h5::create("example.h5", H5F_ACC_TRUNC ); // create file and save descriptor 28 | * H5Dcreate(fd, ... ); // CAPI call with implicit conversion 29 | * H5Dcreate(static_cast(fd), ...); // or explicit cast 30 | * 31 | * h5::fd_t fd_2 = h5::create("other.h5", // thin smart pointer like RAII support 32 | * H5F_ACC_EXCL | H5F_ACC_DEBUG, // CAPI arguments are implicitly converted 33 | * H5P_DEFAULT, H5P_DEFAULT ); // if enabled 34 | * } 35 | * { // DON'Ts: assign returned smart pointer to hid_t directly, becuase 36 | * // underlying handle gets assigned to, then the smart pointer closes backing 37 | * // resource as it goes out of scope: 38 | * // hid_t fd = h5::create("example.h5", H5_ACC_TRUNC); // fd is now invalid 39 | * // 40 | * // DOs: capture smart pointer only when you use it, then pass it to CAPI 41 | * // if it were an hid_t, or use static_cast<> to signal intent 42 | * auto fd = h5::create("example.h5", H5_ACC_TRUNC); // instead, do this 43 | * H5Dopen(fd, "mydataset", ... ); // if implicit cast enabled, or 44 | * H5Dcreate(static_cast(fd), ...); // when explicit cast enforced 45 | * hid_t capi_fd = static_cast( fd ); // also fine, intent is clear 46 | * } 47 | * @endcode 48 | */ 49 | inline h5::fd_t create( const std::string& path, unsigned flags, 50 | const h5::fcpl_t& fcpl=h5::default_fcpl, const h5::fapl_t& fapl=h5::default_fapl ) { 51 | H5CPP_CHECK_PROP( fcpl, h5::error::io::file::create, "invalid file control property list" ); 52 | H5CPP_CHECK_PROP( fapl, h5::error::io::file::create, "invalid file access property list" ); 53 | 54 | hid_t fd; 55 | H5CPP_CHECK_NZ( 56 | (fd = H5Fcreate(path.data(), flags, static_cast( fcpl ), static_cast( fapl ) )), 57 | h5::error::io::file::create, h5::error::msg::create_file); 58 | return fd_t{fd}; 59 | } 60 | } 61 | #endif 62 | 63 | -------------------------------------------------------------------------------- /examples/optimized/optimized.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include 6 | #include 7 | 8 | 9 | /* EXAMPLE: 10 | * to demonstrate how to factor out arguments for in-loop or lean + mean in-sub-routine data operations 11 | * using c+17 most operations are compiler time, and eliminated if not used. Arguments are stored on 12 | * stack and have minimal size often none. 13 | * By not specifying optional arguments you give the compiler to eliminate entire branches compile time 14 | * resulting in highly optimized final binary: the way an expert wrote the code using HDF5 CAPI. 15 | */ 16 | 17 | int main(){ 18 | // have a file descriptor read 19 | h5::fd_t fd = h5::create("optimized.h5",H5F_ACC_TRUNC); 20 | 21 | // create or use existing linalg objects, the memory is reserved on heap and 22 | // usually is a big chunk 23 | arma::mat M(10,1); M.zeros(); 24 | // create or open the dataset withing HDF5 container, with the right properties set 25 | h5::ds_t ds = h5::create(fd,"huge dataset" 26 | ,h5::current_dims{10,100} // the actual size of the dataspace created inside HDF5 27 | ,h5::max_dims{10,H5S_UNLIMITED} // if it can grow: use `append` or H5CAPI calls 28 | ,h5::chunk{10,10} // compression and partial IO requires chunk-ing, which is 29 | // reading data by small blocks at a time with internal caching mechanism 30 | // for handling edges and frequent read | write to same region 31 | // 32 | | h5::gzip{9} // compression comes at cost 33 | | h5::fill_value{0} ); 34 | 35 | 36 | // SUGGESTED: Notice that `count` is not specified, but created on 37 | // that stack along `offset`. These operations have minimal impact if any. 38 | for( hsize_t i=0; i < 4; i ++){ 39 | h5::read( ds, M, h5::offset{0,0} ); 40 | M[0,0] = i; // your science thing, using 80% of in-core available memory 41 | // this is where you swap out 42 | h5::write( ds, M, h5::offset{0,i} ); 43 | } 44 | 45 | 46 | /* EXTREME: 47 | * h5::offset, h5::count, ... are space optimized (H5CPP_MAX_RANK + 1) * sizeof(hsize_t) small objects 48 | * placed on the local stack (not on the heap) suitable for pass by value, or reference. In the following 49 | * section offset and count are factored out from the high performance loop to demonstrate how it can 50 | * be done, but in most cases this is an **overkill** and not the suggested way. 51 | * Use profiler to identify hot spots. See `profile` directory for examples. 52 | * */ 53 | h5::offset offset{0,0}; // must have the proper rank: this is rank 2 54 | h5::count count{10,1}; // describe the memory region of `M` matrix 55 | 56 | // ready for optimized loop: 57 | for( hsize_t i=10; i < 15; i ++){ 58 | offset[1] = i; // set new coordinates 59 | M[1,0] = i; // do your science thing 60 | h5::write( ds, M, offset, count ); 61 | } 62 | 63 | } 64 | 65 | 66 | -------------------------------------------------------------------------------- /h5cpp/H5Mitpp.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #ifndef H5CPP_ITPP_HPP 6 | #define H5CPP_ITPP_HPP 7 | 8 | 9 | #if defined(MAT_H) || defined(H5CPP_USE_ITPP_MATRIX) 10 | namespace h5 { namespace itpp { 11 | template using rowmat = ::itpp::Mat; 12 | template ::type> 13 | using is_supported = std::integral_constant>::value>; 14 | }} 15 | namespace h5 { namespace impl { 16 | // 1.) object -> H5T_xxx 17 | template struct decay>{ typedef T type; }; 18 | 19 | // get read access to datastaore 20 | template ::type> inline 21 | typename std::enable_if< h5::itpp::is_supported::value, 22 | const T*>::type data(const Object& ref ){ 23 | return ref._data(); 24 | } 25 | // read write access 26 | template ::type> inline 27 | typename std::enable_if< h5::itpp::is_supported::value, 28 | T*>::type data( Object& ref ){ 29 | return ref._data(); 30 | } 31 | template struct rank> : public std::integral_constant{}; 32 | template inline std::array size( const h5::itpp::rowmat& ref ){ return {(hsize_t)ref.cols(),(hsize_t)ref.rows()};} 33 | template struct get> { 34 | static inline h5::itpp::rowmat ctor( std::array dims ){ 35 | return h5::itpp::rowmat( dims[1], dims[0] ); 36 | }}; 37 | }} 38 | #endif 39 | 40 | #if defined(VEC_H) || defined(H5CPP_USE_ITPP_VECTOR) 41 | namespace h5 { namespace itpp { 42 | template using rowvec = ::itpp::Vec; 43 | template ::type> 44 | using is_supported_v = std::integral_constant>::value>; 45 | }} 46 | namespace h5 { namespace impl { 47 | template struct decay>{ typedef T type; }; 48 | template ::type> inline 49 | typename std::enable_if< h5::itpp::is_supported_v::value, 50 | const T*>::type data(const Object& ref ){ 51 | return ref._data(); 52 | } 53 | template ::type> inline 54 | typename std::enable_if< h5::itpp::is_supported_v::value, 55 | T*>::type data( Object& ref ){ 56 | return ref._data(); 57 | } 58 | template struct rank> : public std::integral_constant{}; 59 | template inline std::array size( const h5::itpp::rowvec& ref ){ return { (hsize_t)ref.size() };} 60 | template struct get> { 61 | static inline h5::itpp::rowvec ctor( std::array dims ){ 62 | return h5::itpp::rowvec( dims[0] ); 63 | }}; 64 | }} 65 | #endif 66 | #endif 67 | -------------------------------------------------------------------------------- /h5cpp/H5Mublas.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #ifndef H5CPP_UBLAS_HPP 6 | #define H5CPP_UBLAS_HPP 7 | 8 | #if defined(_BOOST_UBLAS_MATRIX_) || defined(H5CPP_USE_UBLAS_MATRIX) 9 | namespace h5 { namespace ublas { 10 | template using rowmat = ::boost::numeric::ublas::matrix; 11 | template ::type> 12 | using is_supportedm = std::integral_constant>::value>; 13 | }} 14 | namespace h5 { namespace impl { 15 | // 1.) object -> H5T_xxx 16 | template struct decay>{ typedef T type; }; 17 | // get read access to datastaore 18 | template ::type> inline 19 | typename std::enable_if< h5::ublas::is_supportedm::value, 20 | const T*>::type data(const Object& ref ){ 21 | return ref.data().begin(); 22 | } 23 | // read write access 24 | template ::type> inline 25 | typename std::enable_if< h5::ublas::is_supportedm::value, 26 | T*>::type data( Object& ref ){ 27 | return ref.data().begin(); 28 | } 29 | template struct rank> : public std::integral_constant{}; 30 | template inline std::array size( const h5::ublas::rowmat& ref ){ return {(hsize_t)ref.size2(),(hsize_t)ref.size1()};} 31 | template struct get> { 32 | static inline h5::ublas::rowmat ctor( std::array dims ){ 33 | return h5::ublas::rowmat( dims[1], dims[0] ); 34 | }}; 35 | }} 36 | #endif 37 | 38 | #if defined(_BOOST_UBLAS_VECTOR_) || defined(H5CPP_USE_UBLAS_VECTOR) 39 | namespace h5 { namespace ublas { 40 | template using rowvec = ::boost::numeric::ublas::vector; 41 | template ::type> 42 | using is_supportedv = std::integral_constant>::value>; 43 | }} 44 | namespace h5 { namespace impl { 45 | template struct decay>{ typedef T type; }; 46 | template ::type> inline 47 | typename std::enable_if< h5::ublas::is_supportedv::value, 48 | const T*>::type data(const Object& ref ){ 49 | return ref.data().begin(); 50 | } 51 | template ::type> inline 52 | typename std::enable_if< h5::ublas::is_supportedv::value, 53 | T*>::type data( Object& ref ){ 54 | return ref.data().begin(); 55 | } 56 | template struct rank> : public std::integral_constant{}; 57 | template inline std::array size( const h5::ublas::rowvec& ref ){ return { (hsize_t)ref.size() };} 58 | template struct get> { 59 | static inline h5::ublas::rowvec ctor( std::array dims ){ 60 | return h5::ublas::rowvec( dims[0] ); 61 | }}; 62 | }} 63 | #endif 64 | #endif 65 | -------------------------------------------------------------------------------- /h5cpp/H5misc.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #ifndef H5CPP_MISC_HPP 7 | #define H5CPP_MISC_HPP 8 | namespace h5{ 9 | using cx_double = std::complex; /**< scientific type */ 10 | using cx_float = std::complex; /**< scientific type */ 11 | } 12 | 13 | 14 | 15 | 16 | #define H5CPP_supported_elementary_types "supported elementary types ::= pod_struct | float | double | [signed](int8 | int16 | int32 | int64)" 17 | 18 | namespace h5::utils { 19 | template 20 | static constexpr bool is_supported = std::is_class::value | std::is_arithmetic::value; 21 | //static constexpr bool is_supported = std::is_pod::value && std::is_class::value | std::is_arithmetic::value; 22 | } 23 | 24 | 25 | 26 | 27 | namespace h5::utils { 28 | 29 | template inline std::vector get_test_data( size_t n, size_t min, size_t max){ 30 | std::random_device rd; 31 | std::default_random_engine rng(rd()); 32 | std::uniform_int_distribution<> dist(0,n); 33 | 34 | std::vector data; 35 | data.reserve(n); 36 | std::generate_n(std::back_inserter(data), n, [&]() { 37 | return dist(rng); 38 | }); 39 | return data; 40 | } 41 | // TODO: bang this so total memory alloc is same as 'n' 42 | template <> inline std::vector get_test_data( size_t n, size_t min, size_t max){ 43 | 44 | std::vector data; 45 | data.reserve(n); 46 | 47 | static const char alphabet[] = "abcdefghijklmnopqrstuvwxyz" 48 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 49 | std::random_device rd; 50 | std::default_random_engine rng(rd()); 51 | std::uniform_int_distribution<> dist(0,sizeof(alphabet)/sizeof(*alphabet)-2); 52 | std::uniform_int_distribution<> string_length(min, max); 53 | 54 | std::generate_n(std::back_inserter(data), data.capacity(), [&] { 55 | std::string str; 56 | size_t N = string_length(rng); 57 | str.reserve(N); 58 | std::generate_n(std::back_inserter(str), N, [&]() { 59 | return alphabet[dist(rng)]; 60 | }); 61 | return str; 62 | }); 63 | return data; 64 | } 65 | template inline std::vector get_test_data(size_t n){ 66 | return get_test_data(n); 67 | } 68 | template <> inline std::vector get_test_data( size_t n){ 69 | 70 | std::vector data; 71 | data.reserve(n); 72 | 73 | static const char alphabet[] = "abcdefghijklmnopqrstuvwxyz" 74 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 75 | std::random_device rd; 76 | std::default_random_engine rng(rd()); 77 | std::uniform_int_distribution<> dist(0,sizeof(alphabet)/sizeof(*alphabet)-2); 78 | std::uniform_int_distribution<> string_length(7, 17); 79 | 80 | std::generate_n(std::back_inserter(data), data.capacity(), [&] { 81 | std::string str; 82 | size_t N = string_length(rng); 83 | str.reserve(N); 84 | std::generate_n(std::back_inserter(str), N, [&]() { 85 | return alphabet[dist(rng)]; 86 | }); 87 | return str; 88 | }); 89 | return data; 90 | } 91 | 92 | } 93 | #endif 94 | 95 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | 2 | 3 | This distribution contains two packages: an c++17 template library for major linear algebra packages and a source code transformation tool that help you to generate HDF5 compound datatype descriptors from valid C/C++ include files. 4 | 5 | 1. download and install HDF5 v1.10.4 from https://www.hdfgroup.org/downloads/hdf5/source-code/ 6 | from the source tree execute.: 7 | ``` 8 | ./configure --prefix=/usr/local --enable-build-mode=production --enable-shared --enable-static --enable-optimization=high --with-default-api-version=v110 9 | make -j4 10 | sudo make install 11 | ``` 12 | NOTE: the system is often shipped with existing hdf5 installation, the supplied CMAKE will be looking in `/usr/local` first. 13 | 14 | 2. install libh5cpp-dev: 15 | a. copy and ship the content of h5cpp/* with your distribution 16 | b. `sudo make install` 17 | c. ./configure && make install 18 | 19 | 3. linear algebra packages better to install from sources, for performance consider using Intel MKL BLAS/LAPACK 20 | nevertheless here are few packages generally available on the system. For new project I recommend Armadillo C++ or Eigen3 21 | `sudo apt-get install -y libarmadillo-dev libitpp-dev libblitz0-dev libeigen3-dev libdlib-dev` 22 | 23 | 24 | For development on Ubuntu 18.04 based systems: 25 | ---------------- 26 | ``` 27 | sudo apt-get install -y build-essential fakeroot devscripts google-perftools kcachegrind doxygen doxygen-gui markdown libboost-program-options-dev libgtest-dev cmake gcc g++ 28 | sudo apt-get install -y libarmadillo-dev libitpp-dev libblitz0-dev libeigen3-dev libdlib-dev 29 | ``` 30 | 31 | You have to do some manual labor here: 32 | ``` 33 | cd /usr/src/gtest && sudo cmake ./ && sudo make install 34 | ``` 35 | 36 | To package the library check out the relevant branch, ie: debian, then run `make dist-deb` 37 | which in turn will run the cmake based configuration scripts, generates new make file and finally the 38 | installation package. 39 | 40 | 41 | On AWS EC2 with ubuntu 18.04 42 | ----------- 43 | 1. start an image us-east-1: ami-046842448f9e74e7d 44 | 2. connect to running instance with ssh 45 | 46 | HDF5 47 | ``` 48 | sudo apt update && sudo apt upgrade 49 | sudo apt install build-essential g++ gcc cmake 50 | cd ~/ && wget http://h5cpp.org/download/hdf5-1.10.6.tar.gz 51 | tar -xvzf hdf5-1.10.6.tar.gz && cd hdf5-1.10.6/ 52 | ./configure --prefix=/usr/local --enable-build-mode=production 53 | make -j4 && sudo make install 54 | ``` 55 | compiler: 56 | ``` 57 | cd ~/ && wget http://h5cpp.org/download/h5cpp_1.10.4-5_amd64.deb 58 | sudo apt install libllvm6.0 libclang-common-6.0-dev 59 | sudo dpkg -i h5cpp_1.10.4-5_amd64.deb 60 | ``` 61 | 62 | header only: 63 | ``` 64 | cd ~/ && wget http://h5cpp.org/download/h5cpp-dev_1.10.4-5_amd64.deb 65 | sudo dpkg -i h5cpp-dev_1.10.4-5_amd64.deb 66 | ``` 67 | 68 | cleanup: `cd ~/ && rm -rf h5cpp* hdf5*` 69 | 70 | running examples: 71 | ``` 72 | cp -R /usr/share/h5cpp/ ./ && cd h5cpp/examples 73 | ``` 74 | 75 | Running examples: 76 | ``` 77 | sudo apt install libarmadillo-dev 78 | cd ~/ && cp -R /usr/share/h5cpp/ ./ && cd h5cpp/examples 79 | ``` 80 | I am checking the examples as of now, and will get back to you if everything checks 81 | 82 | -------------------------------------------------------------------------------- /examples/linalg/eigen3.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #include 6 | #include // must include Eigen before 7 | #include 8 | 9 | using namespace std; 10 | // EIGEN3 templates are unusually complex, let's use our template definitions 11 | template using Matrix = Eigen::Matrix; 12 | template using Colvec = Eigen::Matrix; 13 | 14 | template using ArrayX1D = Eigen::Array; 15 | template using ArrayX3D = Eigen::Array; 16 | 17 | 18 | 19 | // only EIGEN::DYNAMIC [ARRAY|MATRIX|VECTOR] are supported 20 | // in other words Eigen::Matrix where S \in unsigned will not work, rather cast static allocation into Dynamic (heap memory) structure 21 | 22 | int main(){ 23 | { // CREATE - WRITE 24 | Matrix M(2,3); // create a matrix 25 | h5::fd_t fd = h5::create("linalg.h5",H5F_ACC_TRUNC); // and a file 26 | h5::ds_t ds = h5::create(fd,"create then write" 27 | ,h5::current_dims{10,20} 28 | ,h5::max_dims{10,H5S_UNLIMITED} 29 | ,h5::chunk{2,3} | h5::fill_value{3} | h5::gzip{9} 30 | ); 31 | h5::write( ds, M, h5::offset{2,2}, h5::stride{1,3} ); 32 | } 33 | 34 | { 35 | Colvec V(8); // create a vector 36 | // simple one shot write that computes current dimensions and saves matrix 37 | h5::write( "linalg.h5", "one shot create write", V); 38 | // what if you want to position a matrix inside a higher dimension with some added complexity? 39 | h5::write( "linalg.h5", "arma vec inside matrix", V // object contains 'count' and rank being written 40 | ,h5::current_dims{40,50} // control file_space directly where you want to place vector 41 | ,h5::offset{5,0} // when no explicit current dimension given current dimension := offset .+ object_dim .* stride (hadamard product) 42 | ,h5::count{1,1}, h5::stride{4,4}, h5::block{3,3} 43 | ,h5::max_dims{40,H5S_UNLIMITED} // wouldn't it be nice to have unlimited dimension? if no explicit chunk is set, then the object dimension 44 | // is used as unit chunk 45 | ); 46 | } 47 | 48 | { // CREATE - READ: we're reading back the dataset created in the very first step 49 | // note that data is only data, can be reshaped, cast to any format and content be modified through filtering 50 | auto fd = h5::open("linalg.h5", H5F_ACC_RDWR, // you can have multiple fd open with H5F_ACC_RDONLY, but single write 51 | h5::fclose_degree_strong | h5::sec2); // and able to set various properties 52 | } 53 | { // READ: 54 | Matrix M = h5::read>("linalg.h5","create then write"); // read entire dataset back with a single read 55 | std::cout << M << std::endl; 56 | } 57 | 58 | { // fixed/compile time length arrays/matrices upto size 4 59 | auto fd = h5::open("linalg.h5", H5F_ACC_RDWR); 60 | ArrayX1D x1d = ArrayX1D::Zero(10); 61 | h5::write(fd, "/x1d ", x1d); 62 | ArrayX3D x3d = ArrayX3D::Zero(10,3); // first dimension is fixed size 63 | h5::write(fd, "/x3d", x3d); 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /LICENSE.LLVM: -------------------------------------------------------------------------------- 1 | ============================================================================== 2 | LLVM Release License 3 | ============================================================================== 4 | University of Illinois/NCSA 5 | Open Source License 6 | 7 | Copyright (c) 2003-2017 University of Illinois at Urbana-Champaign. 8 | All rights reserved. 9 | 10 | Developed by: 11 | 12 | LLVM Team 13 | 14 | University of Illinois at Urbana-Champaign 15 | 16 | http://llvm.org 17 | 18 | Permission is hereby granted, free of charge, to any person obtaining a copy of 19 | this software and associated documentation files (the "Software"), to deal with 20 | the Software without restriction, including without limitation the rights to 21 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 22 | of the Software, and to permit persons to whom the Software is furnished to do 23 | so, subject to the following conditions: 24 | 25 | * Redistributions of source code must retain the above copyright notice, 26 | this list of conditions and the following disclaimers. 27 | 28 | * Redistributions in binary form must reproduce the above copyright notice, 29 | this list of conditions and the following disclaimers in the 30 | documentation and/or other materials provided with the distribution. 31 | 32 | * Neither the names of the LLVM Team, University of Illinois at 33 | Urbana-Champaign, nor the names of its contributors may be used to 34 | endorse or promote products derived from this Software without specific 35 | prior written permission. 36 | 37 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 38 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 39 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 40 | CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 41 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 42 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE 43 | SOFTWARE. 44 | 45 | ============================================================================== 46 | Copyrights and Licenses for Third Party Software Distributed with LLVM: 47 | ============================================================================== 48 | The LLVM software contains code written by third parties. Such software will 49 | have its own individual LICENSE.TXT file in the directory in which it appears. 50 | This file will describe the copyrights, license, and restrictions which apply 51 | to that code. 52 | 53 | The disclaimer of warranty in the University of Illinois Open Source License 54 | applies to all code in the LLVM Distribution, and nothing in any of the 55 | other licenses gives permission to use the names of the LLVM Team or the 56 | University of Illinois to endorse or promote products derived from this 57 | Software. 58 | 59 | The following pieces of software have additional or alternate copyrights, 60 | licenses, and/or restrictions: 61 | 62 | Program Directory 63 | ------- --------- 64 | Google Test llvm/utils/unittest/googletest 65 | OpenBSD regex llvm/lib/Support/{reg*, COPYRIGHT.regex} 66 | pyyaml tests llvm/test/YAMLParser/{*.data, LICENSE.TXT} 67 | ARM contributions llvm/lib/Target/ARM/LICENSE.TXT 68 | md5 contributions llvm/lib/Support/MD5.cpp llvm/include/llvm/Support/MD5.h 69 | -------------------------------------------------------------------------------- /examples/datatypes/n-bit.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include // include this before custom type definition 14 | #include "n-bit.hpp" 15 | #include // IO operators become aware of your custom type 16 | 17 | namespace ei { 18 | template 19 | using Matrix = Eigen::Matrix; 20 | } 21 | 22 | // in all cases when filtering used chunk must be set as well, no contiguous 23 | int main(){ 24 | namespace bs = bitstring; 25 | 26 | h5::fd_t fd = h5::create("example.h5",H5F_ACC_TRUNC); 27 | // prints out type info, eases on debugging 28 | std::cout << h5::dt_t() << std::endl; 29 | 30 | std::random_device rd; 31 | std::mt19937 random_int(rd()); 32 | std::uniform_int_distribution<> sample(0, 3); 33 | 34 | { 35 | // method 1: use C++ conversion CTOR to convert from fundamental type to your custom one 36 | // notice the armadillo can only hold arithmetic types, you have to do some forcing 37 | // also that colmajor, coordinates are swapped 38 | arma::Mat M(12,8); 39 | std::generate(M.begin(), M.end(), [&](){ return sample(random_int);} ); 40 | 41 | h5::ds_t ds = h5::create(fd, "arma", 42 | h5::current_dims{8,12,1}, h5::max_dims{8,12,H5S_UNLIMITED}, h5::chunk{4,3,1} | h5::nbit); 43 | // force conversion for zero copy: 44 | h5::write(fd,"arma", (bs::n_bit*)M.memptr(), h5::offset{0,0,0}, h5::count{8,12,1}); 45 | 46 | arma::Mat data(12,8); 47 | h5::read(fd, "arma", (bs::n_bit*)data.memptr(), h5::offset{0,0,0}, h5::count{8,12,1}); 48 | data.print(); 49 | std::cout <<"\n\n"; 50 | M.print(); 51 | } 52 | { 53 | // method 2: eigen allows native type handling 54 | ei::Matrix M(12,8); 55 | for(int i=0; i<12; i++) for( int j=0; j<8; j++) 56 | M(i,j) = static_cast( sample(random_int)); 57 | 58 | h5::ds_t ds = h5::create(fd, "eigen", // chunk must be used with nbit 59 | h5::current_dims{12,8}, h5::max_dims{12,H5S_UNLIMITED}, h5::chunk{3,4} | h5::nbit); 60 | h5::write(ds, h5::impl::data(M), h5::count{12,8}); 61 | 62 | ei::Matrix data(12,8); 63 | h5::read(fd, "eigen", data, h5::offset{0,0}); 64 | std::cout << data << std::endl < V(12*8); 68 | std::generate(V.begin(), V.end(), [&](){ 69 | return static_cast(sample(random_int)); 70 | }); 71 | 72 | h5::ds_t ds = h5::create(fd, "stl", // chunk must be used with nbit 73 | h5::current_dims{12,8}, h5::max_dims{12,H5S_UNLIMITED}, h5::chunk{3,4} | h5::nbit); 74 | // from typed memory pointer to different shape 75 | h5::write(ds, V.data(), h5::count{12,8}); // single shot write 76 | 77 | auto data = h5::read>(fd, "stl"); 78 | for( int i=0; i( data[i] ) << " "; 80 | std::cout << "\n\ncomputing difference ||saved - read|| expecting norm to be zero:\n"; 81 | for( int i=0; i 4 | */ 5 | #ifndef H5CPP_BLAZE_HPP 6 | #define H5CPP_BLAZE_HPP 7 | 8 | #if defined(_BLAZE_MATH_MODULE_H_) || defined(H5CPP_USE_BLAZE) 9 | namespace h5 { namespace blaze { 10 | template using rowvec = ::blaze::DynamicVector; 11 | template using colvec = ::blaze::DynamicVector; 12 | template using rowmat = ::blaze::DynamicMatrix; 13 | template using colmat = ::blaze::DynamicMatrix; 14 | 15 | // is_linalg_type := filter 16 | template ::type> using is_supported = 17 | std::integral_constant>::value || std::is_same>::value 18 | || std::is_same>::value || std::is_same>::value>; 19 | }} 20 | 21 | namespace h5 { namespace impl { 22 | // 1.) object -> H5T_xxx 23 | template struct decay>{ typedef T type; }; 24 | template struct decay>{ typedef T type; }; 25 | template struct decay>{ typedef T type; }; 26 | template struct decay>{ typedef T type; }; 27 | 28 | // get read access to datastaore 29 | template ::type> inline 30 | typename std::enable_if< h5::blaze::is_supported::value, 31 | const T*>::type data(const Object& ref ){ 32 | return ref.data(); 33 | } 34 | // read write access 35 | template ::type> inline 36 | typename std::enable_if< h5::blaze::is_supported::value, 37 | T*>::type data( Object& ref ){ 38 | return ref.data(); 39 | } 40 | // rank 41 | template struct rank> : public std::integral_constant{}; 42 | template struct rank> : public std::integral_constant{}; 43 | template struct rank> : public std::integral_constant{}; 44 | template struct rank> : public std::integral_constant{}; 45 | // determine rank and dimensions 46 | template inline std::array size( const h5::blaze::rowvec& ref ){ return {ref.size()};} 47 | template inline std::array size( const h5::blaze::colvec& ref ){ return {ref.size()};} 48 | template inline std::array size( const h5::blaze::rowmat& ref ){ return {ref.columns(),ref.rows()};} 49 | template inline std::array size( const h5::blaze::colmat& ref ){ return {ref.rows(),ref.columns()};} 50 | 51 | 52 | template struct get> { 53 | static inline h5::blaze::rowvec ctor( std::array dims ){ 54 | return h5::blaze::rowvec( dims[0] ); 55 | }}; 56 | template struct get> { 57 | static inline h5::blaze::colvec ctor( std::array dims ){ 58 | return h5::blaze::colvec( dims[0] ); 59 | }}; 60 | template struct get> { 61 | static inline h5::blaze::rowmat ctor( std::array dims ){ 62 | return h5::blaze::rowmat( dims[1], dims[0] ); 63 | }}; 64 | template struct get> { 65 | static inline h5::blaze::colmat ctor( std::array dims ){ 66 | return h5::blaze::colmat( dims[0], dims[1] ); 67 | }}; 68 | }} 69 | 70 | #endif 71 | #endif 72 | -------------------------------------------------------------------------------- /examples/mpi/throughput.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #pragma GCC diagnostic ignored "-Wnarrowing" 13 | // armadillo 14 | //./configure -DCMAKE_INSTALL_PREFIX=/usr/local -DDETECT_HDF5=OFF 15 | int main(int argc, char** argv) { 16 | int size, rank, name_len; 17 | char processor_name[MPI_MAX_PROCESSOR_NAME]; 18 | MPI_Init(NULL, NULL); 19 | MPI_Info info; 20 | MPI_Comm comm = MPI_COMM_WORLD; 21 | 22 | MPI_Comm_size(MPI_COMM_WORLD, &size); 23 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); 24 | MPI_Get_processor_name(processor_name, &name_len); 25 | 26 | MPI_Info_create(&info); 27 | //MPI_Info_set(info, "fs_pvfs2_stripe_size", "6"); 28 | //MPI_Info_set(info, "fs_pvfs2_stripe_width", "1024"); 29 | 30 | 31 | int nchunk = 1024*1024; 32 | int nrows = 10*nchunk; // 800MB per rank!! 33 | 34 | { // CREATE - WRITE 35 | std::vector v(nrows); 36 | std::fill(std::begin(v), std::end(v), rank + 2 ); 37 | size_t vsize =v.size() * sizeof(double); 38 | 39 | auto fd = h5::create("collective.h5", H5F_ACC_TRUNC, 40 | h5::fcpl, 41 | h5::mpiio({MPI_COMM_WORLD, info}) // pass the communicator and hints as usual 42 | ); 43 | h5::ds_t ds = h5::create(fd,"dataset" 44 | ,h5::max_dims{size,nrows}, h5::chunk{1,nchunk} | h5::alloc_time_early ); 45 | 46 | // make a copy of dxpl, so we can query if collective IO was successful 47 | h5::dxpl_t dxpl = h5::collective; 48 | 49 | // ACTUAL WRITE MEASUREMENT 50 | std::chrono::system_clock::time_point start = std::chrono::system_clock::now(); 51 | h5::write( ds, v, h5::current_dims{nrows,size}, 52 | h5::offset{rank,0}, h5::count{1,nrows}, dxpl ); 53 | std::chrono::system_clock::time_point stop = std::chrono::system_clock::now(); 54 | double running_time = 1e-6 * std::chrono::duration_cast(stop - start).count(); 55 | double MB_sec = (vsize / 1e6) / running_time; 56 | 57 | // COLLECTING RESULTS: 58 | std::vector throughput(size); 59 | MPI_Gather(&MB_sec, 1, MPI_DOUBLE, throughput.data(), 1, MPI_DOUBLE, 0, comm); 60 | if( rank == 0) 61 | std::cout << "\nWRITE: " << 62 | std::accumulate(throughput.begin(), throughput.end(), 0) <<" MB/s" < v(nrows); 69 | size_t vsize =v.size() * sizeof(double); 70 | auto fd = h5::open("collective.h5", H5F_ACC_RDWR, h5::mpiio({MPI_COMM_WORLD, info})); 71 | auto ds = h5::open(fd, "/dataset"); 72 | 73 | // make a copy of dxpl, so we can query if collective IO was successful 74 | h5::dxpl_t dxpl = h5::collective; 75 | 76 | // ACTUAL WRITE MEASUREMENT 77 | std::chrono::system_clock::time_point start = std::chrono::system_clock::now(); 78 | h5::read(ds, v.data(), h5::offset{rank,0}, h5::count{1,nrows}, dxpl); 79 | std::chrono::system_clock::time_point stop = std::chrono::system_clock::now(); 80 | 81 | double running_time = 1e-6 * std::chrono::duration_cast(stop - start).count(); 82 | double MB_sec = (vsize / 1e6) / running_time; 83 | 84 | // COLLECTING RESULTS: 85 | std::vector throughput(size); 86 | MPI_Gather(&MB_sec, 1, MPI_DOUBLE, throughput.data(), 1, MPI_DOUBLE, 0, comm); 87 | if( rank == 0) 88 | std::cout << "\nREAD: " << 89 | std::accumulate(throughput.begin(), throughput.end(), 0) <<" MB/s" < 3 | */ 4 | #ifndef H5CPP_GUARD_tERYg 5 | #define H5CPP_GUARD_tERYg 6 | 7 | namespace h5{ 8 | //template specialization of sn::example::Record to create HDF5 COMPOUND type 9 | template<> hid_t inline register_struct(){ 10 | hsize_t at_00_[] ={7}; hid_t at_00 = H5Tarray_create(H5T_NATIVE_FLOAT,1,at_00_); 11 | hsize_t at_01_[] ={3}; hid_t at_01 = H5Tarray_create(H5T_NATIVE_DOUBLE,1,at_01_); 12 | 13 | hid_t ct_00 = H5Tcreate(H5T_COMPOUND, sizeof (sn::typecheck::Record)); 14 | H5Tinsert(ct_00, "_char", HOFFSET(sn::typecheck::Record,_char),H5T_NATIVE_CHAR); 15 | H5Tinsert(ct_00, "_uchar", HOFFSET(sn::typecheck::Record,_uchar),H5T_NATIVE_UCHAR); 16 | H5Tinsert(ct_00, "_short", HOFFSET(sn::typecheck::Record,_short),H5T_NATIVE_SHORT); 17 | H5Tinsert(ct_00, "_ushort", HOFFSET(sn::typecheck::Record,_ushort),H5T_NATIVE_USHORT); 18 | H5Tinsert(ct_00, "_int", HOFFSET(sn::typecheck::Record,_int),H5T_NATIVE_INT); 19 | H5Tinsert(ct_00, "_uint", HOFFSET(sn::typecheck::Record,_uint),H5T_NATIVE_UINT); 20 | H5Tinsert(ct_00, "_long", HOFFSET(sn::typecheck::Record,_long),H5T_NATIVE_LONG); 21 | H5Tinsert(ct_00, "_ulong", HOFFSET(sn::typecheck::Record,_ulong),H5T_NATIVE_ULONG); 22 | H5Tinsert(ct_00, "_llong", HOFFSET(sn::typecheck::Record,_llong),H5T_NATIVE_LLONG); 23 | H5Tinsert(ct_00, "_ullong", HOFFSET(sn::typecheck::Record,_ullong),H5T_NATIVE_ULLONG); 24 | H5Tinsert(ct_00, "_float", HOFFSET(sn::typecheck::Record,_float),H5T_NATIVE_FLOAT); 25 | H5Tinsert(ct_00, "_double", HOFFSET(sn::typecheck::Record,_double),H5T_NATIVE_DOUBLE); 26 | H5Tinsert(ct_00, "_ldouble", HOFFSET(sn::typecheck::Record,_ldouble),H5T_NATIVE_LDOUBLE); 27 | H5Tinsert(ct_00, "_bool", HOFFSET(sn::typecheck::Record,_bool),H5T_NATIVE_HBOOL); 28 | hsize_t at_02_[] ={4}; hid_t at_02 = H5Tarray_create(ct_00,1,at_02_); 29 | 30 | hid_t ct_01 = H5Tcreate(H5T_COMPOUND, sizeof (sn::other::Record)); 31 | H5Tinsert(ct_01, "idx", HOFFSET(sn::other::Record,idx),H5T_NATIVE_ULLONG); 32 | H5Tinsert(ct_01, "aa", HOFFSET(sn::other::Record,aa),H5T_NATIVE_ULLONG); 33 | H5Tinsert(ct_01, "field_02", HOFFSET(sn::other::Record,field_02),at_01); 34 | H5Tinsert(ct_01, "field_03", HOFFSET(sn::other::Record,field_03),at_02); 35 | hsize_t at_03_[] ={5}; hid_t at_03 = H5Tarray_create(ct_01,1,at_03_); 36 | hsize_t at_04_[] ={8}; hid_t at_04 = H5Tarray_create(ct_01,1,at_04_); 37 | hsize_t at_05_[] ={3}; hid_t at_05 = H5Tarray_create(at_04,1,at_05_); 38 | 39 | hid_t ct_02 = H5Tcreate(H5T_COMPOUND, sizeof (sn::example::Record)); 40 | H5Tinsert(ct_02, "idx", HOFFSET(sn::example::Record,idx),H5T_NATIVE_ULLONG); 41 | H5Tinsert(ct_02, "field_02", HOFFSET(sn::example::Record,field_02),at_00); 42 | H5Tinsert(ct_02, "field_03", HOFFSET(sn::example::Record,field_03),at_03); 43 | H5Tinsert(ct_02, "field_04", HOFFSET(sn::example::Record,field_04),at_03); 44 | H5Tinsert(ct_02, "field_05", HOFFSET(sn::example::Record,field_05),at_05); 45 | 46 | //closing all hid_t allocations to prevent resource leakage 47 | H5Tclose(at_00); H5Tclose(at_01); H5Tclose(ct_00); H5Tclose(at_02); H5Tclose(ct_01); 48 | H5Tclose(at_03); H5Tclose(at_04); H5Tclose(at_05); 49 | 50 | //if not used with h5cpp framework, but as a standalone code generator then 51 | //the returned 'hid_t ct_02' must be closed: H5Tclose(ct_02); 52 | return ct_02; 53 | }; 54 | } 55 | H5CPP_REGISTER_STRUCT(sn::example::Record); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /examples/attributes/generated.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 vargaconsulting, Toronto,ON Canada 2 | * Author: Varga, Steven 3 | */ 4 | #ifndef H5CPP_GUARD_aioPh 5 | #define H5CPP_GUARD_aioPh 6 | 7 | namespace h5{ 8 | //template specialization of sn::example::Record to create HDF5 COMPOUND type 9 | template<> hid_t inline register_struct(){ 10 | hsize_t at_00_[] ={7}; hid_t at_00 = H5Tarray_create(H5T_NATIVE_FLOAT,1,at_00_); 11 | hsize_t at_01_[] ={3}; hid_t at_01 = H5Tarray_create(H5T_NATIVE_DOUBLE,1,at_01_); 12 | 13 | hid_t ct_00 = H5Tcreate(H5T_COMPOUND, sizeof (sn::typecheck::Record)); 14 | H5Tinsert(ct_00, "_char", HOFFSET(sn::typecheck::Record,_char),H5T_NATIVE_CHAR); 15 | H5Tinsert(ct_00, "_uchar", HOFFSET(sn::typecheck::Record,_uchar),H5T_NATIVE_UCHAR); 16 | H5Tinsert(ct_00, "_short", HOFFSET(sn::typecheck::Record,_short),H5T_NATIVE_SHORT); 17 | H5Tinsert(ct_00, "_ushort", HOFFSET(sn::typecheck::Record,_ushort),H5T_NATIVE_USHORT); 18 | H5Tinsert(ct_00, "_int", HOFFSET(sn::typecheck::Record,_int),H5T_NATIVE_INT); 19 | H5Tinsert(ct_00, "_uint", HOFFSET(sn::typecheck::Record,_uint),H5T_NATIVE_UINT); 20 | H5Tinsert(ct_00, "_long", HOFFSET(sn::typecheck::Record,_long),H5T_NATIVE_LONG); 21 | H5Tinsert(ct_00, "_ulong", HOFFSET(sn::typecheck::Record,_ulong),H5T_NATIVE_ULONG); 22 | H5Tinsert(ct_00, "_llong", HOFFSET(sn::typecheck::Record,_llong),H5T_NATIVE_LLONG); 23 | H5Tinsert(ct_00, "_ullong", HOFFSET(sn::typecheck::Record,_ullong),H5T_NATIVE_ULLONG); 24 | H5Tinsert(ct_00, "_float", HOFFSET(sn::typecheck::Record,_float),H5T_NATIVE_FLOAT); 25 | H5Tinsert(ct_00, "_double", HOFFSET(sn::typecheck::Record,_double),H5T_NATIVE_DOUBLE); 26 | H5Tinsert(ct_00, "_ldouble", HOFFSET(sn::typecheck::Record,_ldouble),H5T_NATIVE_LDOUBLE); 27 | H5Tinsert(ct_00, "_bool", HOFFSET(sn::typecheck::Record,_bool),H5T_NATIVE_HBOOL); 28 | hsize_t at_02_[] ={4}; hid_t at_02 = H5Tarray_create(ct_00,1,at_02_); 29 | 30 | hid_t ct_01 = H5Tcreate(H5T_COMPOUND, sizeof (sn::other::Record)); 31 | H5Tinsert(ct_01, "idx", HOFFSET(sn::other::Record,idx),H5T_NATIVE_ULLONG); 32 | H5Tinsert(ct_01, "aa", HOFFSET(sn::other::Record,aa),H5T_NATIVE_ULLONG); 33 | H5Tinsert(ct_01, "field_02", HOFFSET(sn::other::Record,field_02),at_01); 34 | H5Tinsert(ct_01, "field_03", HOFFSET(sn::other::Record,field_03),at_02); 35 | hsize_t at_03_[] ={5}; hid_t at_03 = H5Tarray_create(ct_01,1,at_03_); 36 | hsize_t at_04_[] ={8}; hid_t at_04 = H5Tarray_create(ct_01,1,at_04_); 37 | hsize_t at_05_[] ={3}; hid_t at_05 = H5Tarray_create(at_04,1,at_05_); 38 | 39 | hid_t ct_02 = H5Tcreate(H5T_COMPOUND, sizeof (sn::example::Record)); 40 | H5Tinsert(ct_02, "idx", HOFFSET(sn::example::Record,idx),H5T_NATIVE_ULLONG); 41 | H5Tinsert(ct_02, "field_02", HOFFSET(sn::example::Record,field_02),at_00); 42 | H5Tinsert(ct_02, "field_03", HOFFSET(sn::example::Record,field_03),at_03); 43 | H5Tinsert(ct_02, "field_04", HOFFSET(sn::example::Record,field_04),at_03); 44 | H5Tinsert(ct_02, "field_05", HOFFSET(sn::example::Record,field_05),at_05); 45 | 46 | //closing all hid_t allocations to prevent resource leakage 47 | H5Tclose(at_00); H5Tclose(at_01); H5Tclose(ct_00); H5Tclose(at_02); H5Tclose(ct_01); 48 | H5Tclose(at_03); H5Tclose(at_04); H5Tclose(at_05); 49 | 50 | //if not used with h5cpp framework, but as a standalone code generator then 51 | //the returned 'hid_t ct_02' must be closed: H5Tclose(ct_02); 52 | return ct_02; 53 | }; 54 | } 55 | H5CPP_REGISTER_STRUCT(sn::example::Record); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /examples/stl/generated.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #ifndef H5CPP_GUARD_iBJBS 6 | #define H5CPP_GUARD_iBJBS 7 | 8 | namespace h5{ 9 | //template specialization of sn::example::Record to create HDF5 COMPOUND type 10 | template<> hid_t inline register_struct(){ 11 | hsize_t at_00_[] ={7}; hid_t at_00 = H5Tarray_create(H5T_NATIVE_FLOAT,1,at_00_); 12 | hsize_t at_01_[] ={3}; hid_t at_01 = H5Tarray_create(H5T_NATIVE_DOUBLE,1,at_01_); 13 | 14 | hid_t ct_00 = H5Tcreate(H5T_COMPOUND, sizeof (sn::typecheck::Record)); 15 | H5Tinsert(ct_00, "_char", HOFFSET(sn::typecheck::Record,_char),H5T_NATIVE_CHAR); 16 | H5Tinsert(ct_00, "_uchar", HOFFSET(sn::typecheck::Record,_uchar),H5T_NATIVE_UCHAR); 17 | H5Tinsert(ct_00, "_short", HOFFSET(sn::typecheck::Record,_short),H5T_NATIVE_SHORT); 18 | H5Tinsert(ct_00, "_ushort", HOFFSET(sn::typecheck::Record,_ushort),H5T_NATIVE_USHORT); 19 | H5Tinsert(ct_00, "_int", HOFFSET(sn::typecheck::Record,_int),H5T_NATIVE_INT); 20 | H5Tinsert(ct_00, "_uint", HOFFSET(sn::typecheck::Record,_uint),H5T_NATIVE_UINT); 21 | H5Tinsert(ct_00, "_long", HOFFSET(sn::typecheck::Record,_long),H5T_NATIVE_LONG); 22 | H5Tinsert(ct_00, "_ulong", HOFFSET(sn::typecheck::Record,_ulong),H5T_NATIVE_ULONG); 23 | H5Tinsert(ct_00, "_llong", HOFFSET(sn::typecheck::Record,_llong),H5T_NATIVE_LLONG); 24 | H5Tinsert(ct_00, "_ullong", HOFFSET(sn::typecheck::Record,_ullong),H5T_NATIVE_ULLONG); 25 | H5Tinsert(ct_00, "_float", HOFFSET(sn::typecheck::Record,_float),H5T_NATIVE_FLOAT); 26 | H5Tinsert(ct_00, "_double", HOFFSET(sn::typecheck::Record,_double),H5T_NATIVE_DOUBLE); 27 | H5Tinsert(ct_00, "_ldouble", HOFFSET(sn::typecheck::Record,_ldouble),H5T_NATIVE_LDOUBLE); 28 | H5Tinsert(ct_00, "_bool", HOFFSET(sn::typecheck::Record,_bool),H5T_NATIVE_HBOOL); 29 | hsize_t at_02_[] ={4}; hid_t at_02 = H5Tarray_create(ct_00,1,at_02_); 30 | 31 | hid_t ct_01 = H5Tcreate(H5T_COMPOUND, sizeof (sn::other::Record)); 32 | H5Tinsert(ct_01, "idx", HOFFSET(sn::other::Record,idx),H5T_NATIVE_ULLONG); 33 | H5Tinsert(ct_01, "aa", HOFFSET(sn::other::Record,aa),H5T_NATIVE_ULLONG); 34 | H5Tinsert(ct_01, "field_02", HOFFSET(sn::other::Record,field_02),at_01); 35 | H5Tinsert(ct_01, "field_03", HOFFSET(sn::other::Record,field_03),at_02); 36 | hsize_t at_03_[] ={5}; hid_t at_03 = H5Tarray_create(ct_01,1,at_03_); 37 | hsize_t at_04_[] ={8}; hid_t at_04 = H5Tarray_create(ct_01,1,at_04_); 38 | hsize_t at_05_[] ={3}; hid_t at_05 = H5Tarray_create(at_04,1,at_05_); 39 | 40 | hid_t ct_02 = H5Tcreate(H5T_COMPOUND, sizeof (sn::example::Record)); 41 | H5Tinsert(ct_02, "idx", HOFFSET(sn::example::Record,idx),H5T_NATIVE_ULLONG); 42 | H5Tinsert(ct_02, "field_02", HOFFSET(sn::example::Record,field_02),at_00); 43 | H5Tinsert(ct_02, "field_03", HOFFSET(sn::example::Record,field_03),at_03); 44 | H5Tinsert(ct_02, "field_04", HOFFSET(sn::example::Record,field_04),at_03); 45 | H5Tinsert(ct_02, "field_05", HOFFSET(sn::example::Record,field_05),at_05); 46 | 47 | //closing all hid_t allocations to prevent resource leakage 48 | H5Tclose(at_00); H5Tclose(at_01); H5Tclose(ct_00); H5Tclose(at_02); H5Tclose(ct_01); 49 | H5Tclose(at_03); H5Tclose(at_04); H5Tclose(at_05); 50 | 51 | //if not used with h5cpp framework, but as a standalone code generator then 52 | //the returned 'hid_t ct_02' must be closed: H5Tclose(ct_02); 53 | return ct_02; 54 | }; 55 | } 56 | H5CPP_REGISTER_STRUCT(sn::example::Record); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /examples/packet-table/generated.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 vargaconsulting, Toronto,ON Canada 2 | * Author: Varga, Steven 3 | */ 4 | #ifndef H5CPP_GUARD_irGVX 5 | #define H5CPP_GUARD_irGVX 6 | 7 | namespace h5{ 8 | //template specialization of sn::example::Record to create HDF5 COMPOUND type 9 | template<> hid_t inline register_struct(){ 10 | hsize_t at_00_[] ={7}; hid_t at_00 = H5Tarray_create(H5T_NATIVE_FLOAT,1,at_00_); 11 | hsize_t at_01_[] ={3}; hid_t at_01 = H5Tarray_create(H5T_NATIVE_DOUBLE,1,at_01_); 12 | 13 | hid_t ct_00 = H5Tcreate(H5T_COMPOUND, sizeof (sn::typecheck::Record)); 14 | H5Tinsert(ct_00, "_char", HOFFSET(sn::typecheck::Record,_char),H5T_NATIVE_CHAR); 15 | H5Tinsert(ct_00, "_uchar", HOFFSET(sn::typecheck::Record,_uchar),H5T_NATIVE_UCHAR); 16 | H5Tinsert(ct_00, "_short", HOFFSET(sn::typecheck::Record,_short),H5T_NATIVE_SHORT); 17 | H5Tinsert(ct_00, "_ushort", HOFFSET(sn::typecheck::Record,_ushort),H5T_NATIVE_USHORT); 18 | H5Tinsert(ct_00, "_int", HOFFSET(sn::typecheck::Record,_int),H5T_NATIVE_INT); 19 | H5Tinsert(ct_00, "_uint", HOFFSET(sn::typecheck::Record,_uint),H5T_NATIVE_UINT); 20 | H5Tinsert(ct_00, "_long", HOFFSET(sn::typecheck::Record,_long),H5T_NATIVE_LONG); 21 | H5Tinsert(ct_00, "_ulong", HOFFSET(sn::typecheck::Record,_ulong),H5T_NATIVE_ULONG); 22 | H5Tinsert(ct_00, "_llong", HOFFSET(sn::typecheck::Record,_llong),H5T_NATIVE_LLONG); 23 | H5Tinsert(ct_00, "_ullong", HOFFSET(sn::typecheck::Record,_ullong),H5T_NATIVE_ULLONG); 24 | H5Tinsert(ct_00, "_float", HOFFSET(sn::typecheck::Record,_float),H5T_NATIVE_FLOAT); 25 | H5Tinsert(ct_00, "_double", HOFFSET(sn::typecheck::Record,_double),H5T_NATIVE_DOUBLE); 26 | H5Tinsert(ct_00, "_ldouble", HOFFSET(sn::typecheck::Record,_ldouble),H5T_NATIVE_LDOUBLE); 27 | H5Tinsert(ct_00, "_bool", HOFFSET(sn::typecheck::Record,_bool),H5T_NATIVE_HBOOL); 28 | hsize_t at_02_[] ={4}; hid_t at_02 = H5Tarray_create(ct_00,1,at_02_); 29 | 30 | hid_t ct_01 = H5Tcreate(H5T_COMPOUND, sizeof (sn::other::Record)); 31 | H5Tinsert(ct_01, "idx", HOFFSET(sn::other::Record,idx),H5T_NATIVE_ULLONG); 32 | H5Tinsert(ct_01, "aa", HOFFSET(sn::other::Record,aa),H5T_NATIVE_ULLONG); 33 | H5Tinsert(ct_01, "field_02", HOFFSET(sn::other::Record,field_02),at_01); 34 | H5Tinsert(ct_01, "field_03", HOFFSET(sn::other::Record,field_03),at_02); 35 | hsize_t at_03_[] ={5}; hid_t at_03 = H5Tarray_create(ct_01,1,at_03_); 36 | hsize_t at_04_[] ={8}; hid_t at_04 = H5Tarray_create(ct_01,1,at_04_); 37 | hsize_t at_05_[] ={3}; hid_t at_05 = H5Tarray_create(at_04,1,at_05_); 38 | 39 | hid_t ct_02 = H5Tcreate(H5T_COMPOUND, sizeof (sn::example::Record)); 40 | H5Tinsert(ct_02, "idx", HOFFSET(sn::example::Record,idx),H5T_NATIVE_ULLONG); 41 | H5Tinsert(ct_02, "field_02", HOFFSET(sn::example::Record,field_02),at_00); 42 | H5Tinsert(ct_02, "field_03", HOFFSET(sn::example::Record,field_03),at_03); 43 | H5Tinsert(ct_02, "field_04", HOFFSET(sn::example::Record,field_04),at_03); 44 | H5Tinsert(ct_02, "field_05", HOFFSET(sn::example::Record,field_05),at_05); 45 | 46 | //closing all hid_t allocations to prevent resource leakage 47 | H5Tclose(at_00); H5Tclose(at_01); H5Tclose(ct_00); H5Tclose(at_02); H5Tclose(ct_01); 48 | H5Tclose(at_03); H5Tclose(at_04); H5Tclose(at_05); 49 | 50 | //if not used with h5cpp framework, but as a standalone code generator then 51 | //the returned 'hid_t ct_02' must be closed: H5Tclose(ct_02); 52 | return ct_02; 53 | }; 54 | } 55 | H5CPP_REGISTER_STRUCT(sn::example::Record); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /h5cpp/H5Mstl.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #ifndef H5CPP_STL_HPP 7 | #define H5CPP_STL_HPP 8 | 9 | namespace h5 { namespace impl { 10 | /*STL: */ 11 | // 2.) filter is_xxx_type 12 | // 4.) write access 13 | // 5.) obtain dimensions of extents 14 | // 6.) ctor with right dimensions 15 | 16 | // 1.) object -> H5T_xxx 17 | template struct decay{ typedef T type; }; 18 | 19 | template struct decay{ typedef T type; }; 20 | template struct decay{ typedef T* type; }; 21 | template struct decay>{ typedef const T* type; }; 22 | template struct decay{ typedef T* type; }; 23 | template struct decay{ typedef T* type; }; 24 | 25 | template struct decay>{ typedef const T* type; }; 26 | template struct decay>{ typedef T* type; }; 27 | template struct decay>{ typedef T type; }; 28 | 29 | template struct decay>{ typedef const T* type; }; 30 | template struct decay>{ typedef T* type; }; 31 | template struct decay>{ typedef T type; }; 32 | 33 | // helpers 34 | template 35 | using is_scalar = std::integral_constant::value || std::is_pod::value || std::is_same::value>; 37 | template ::type> 38 | using is_rank01 = std::integral_constant>::value || 40 | std::is_same>::value >; 41 | 42 | template struct rank : public std::integral_constant{}; 43 | template<> struct rank: public std::integral_constant{}; 44 | template struct rank: public std::integral_constant{}; 45 | template struct rank>: public std::integral_constant{}; 46 | 47 | // 3.) read access 48 | template inline typename std::enable_if::value || std::is_pod::value, 49 | const T*>::type data( const T& ref ){ return &ref; } 50 | template inline typename std::enable_if< impl::is_scalar::value, 51 | const T*>::type data( const std::initializer_list& ref ){ return ref.begin(); } 52 | inline const char* const* data( const std::initializer_list& ref ){ return ref.begin(); } 53 | inline const char* data( const std::string& ref ){ return ref.c_str(); } 54 | template inline const T* data( const std::vector& ref ){ 55 | return ref.data(); 56 | } 57 | template inline T* data( std::vector& ref ){ 58 | return ref.data(); 59 | } 60 | // 4.) write access 61 | template inline typename std::enable_if::value, 62 | T*>::type data( T& ref ){ return &ref; } 63 | //template inline typename std::enable_if::value, 64 | // const T*>::type data( const T& ref ){ return &ref; } 65 | // 5.) obtain dimensions of extents 66 | template inline constexpr typename std::enable_if< impl::is_scalar::value, 67 | std::array>::type size( T value ){ return{}; } 68 | template inline typename std::enable_if< impl::is_rank01::value, 69 | std::array>::type size( const T& ref ){ return {ref.size()}; } 70 | // 6.) ctor with right dimensions 71 | template struct get { 72 | static inline T ctor( std::array::value> dims ){ 73 | return T(); }}; 74 | template 75 | struct get> { 76 | static inline std::vector ctor( std::array dims ){ 77 | return std::vector( dims[0] ); 78 | }}; 79 | }} 80 | #endif 81 | -------------------------------------------------------------------------------- /examples/datasets/README.md: -------------------------------------------------------------------------------- 1 | ## Datasets[^1] 2 | A dataset is stored in a file in two parts: a header and a data array. 3 | 4 | The header contains information that is needed to interpret the array portion of the dataset, as well as metadata (or pointers to metadata) that describes or annotates the dataset. Header information includes the name of the object, its dimensionality, its number-type, information about how the data itself is stored on disk, and other information used by the library to speed up access to the dataset or maintain the file's integrity. 5 | 6 | There are four essential classes of information in any header: name, datatype, dataspace, and storage layout: 7 | 8 | * **Name** A dataset name is a sequence of alphanumeric ASCII characters. 9 | * **Datatype** HDF5 allows one to define many different kinds of datatypes. There are two categories of datatypes: 10 | * atomic datatype: currently only **NATIVE** byte order supported on H5CPP 11 | * compound datatypes: see h5cpp compiler assisted reflection 12 | 13 | * **Dataspace** A dataset dataspace describes the dimensionality of the dataset. The dimensions of a dataset can be fixed (unchanging), or they may be unlimited, which means that they are extendible (i.e. they can grow larger). 14 | 15 | * **Storage layout** The HDF5 format makes it possible to store data in a variety of ways. The default storage layout format is contiguous, meaning that data is stored in the same linear way that it is organized in memory. Two other storage layout formats are currently defined for HDF5: compact, and chunked. 16 | * **Chunked storage** involves dividing the dataset into equal-sized "chunks" that are stored separately. Chunking **has three important benefits**. 17 | 1. It makes it possible to achieve good performance when accessing subsets of the datasets, even when the subset to be chosen is orthogonal to the normal storage order of the dataset. 18 | 2. It makes it possible to compress large datasets and still achieve good performance when accessing subsets of the dataset. 19 | 3. It makes it possible efficiently to extend the dimensions of a dataset in any direction. 20 | * **Compact storage is** used when the amount of data is small and can be stored directly in the object header. And is **NOT SUPPORTED by H5CPP** directly 21 | 22 | ### Dataspace 23 | Properties of a dataspace consist of the rank (number of dimensions) of the data array, the actual sizes of the dimensions of the array, and the maximum sizes of the dimensions of the array. For a fixed-dimension dataset, the actual size is the same as the maximum size of a dimension. When a dimension is unlimited, the maximum size is set to the value H5P_UNLIMITED. 24 | A dataspace can also describe portions of a dataset, making it possible to do partial I/O operations on selections. Selection is supported by the dataspace interface (H5S). Given an n-dimensional dataset, there are currently four ways to do partial selection: 25 | 26 | * Select a logically contiguous n-dimensional hyperslab. 27 | * Select a non-contiguous hyperslab consisting of elements or blocks of elements (hyperslabs) that are equally spaced. 28 | 29 | List to describe dimensions of a dataset: 30 | 31 | * `h5::current_dims{i,j,k,..}` - actual dimension `i,j,k \in {1 - max}` 32 | * `h5::max_dims{...}` - maximum dimension, use `H5S_UNLIMITED` for infinite 33 | * `h5::chunk{...}` - define block size, clever blocking arrangement increases throughout 34 | 35 | List how to select from datasets for read or write: 36 | 37 | * `h5::offset{...}` - start coordinates of data selection 38 | * `h5::stride{...}` - every `n` considered 39 | * `h5::block{...}` - every `m` block is considered 40 | * `h5::count{...}` - the amount of data 41 | 42 | **Note:** `h5::stride`, `h5::block` and scatter - gather operations doesn't work when `h5::high_throughput` set, due to performance reasons. 43 | 44 | 45 | 46 | 47 | 48 | 49 | [^1]: Lifted from HDF5 CAPI documentation 50 | 51 | -------------------------------------------------------------------------------- /examples/kita/kita.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | 6 | #define H5CPP_HAVE_KITA 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #pragma GCC diagnostic ignored "-Wnarrowing" 15 | // armadillo 16 | //./configure -DCMAKE_INSTALL_PREFIX=/usr/local -DDETECT_HDF5=OFF 17 | int main(int argc, char** argv) { 18 | int size, rank, name_len; 19 | char processor_name[MPI_MAX_PROCESSOR_NAME]; 20 | MPI_Init(NULL, NULL); 21 | MPI_Info info; 22 | MPI_Comm comm = MPI_COMM_WORLD; 23 | 24 | MPI_Comm_size(MPI_COMM_WORLD, &size); 25 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); 26 | MPI_Get_processor_name(processor_name, &name_len); 27 | 28 | MPI_Info_create(&info); 29 | int nchunk = 1024*1024; 30 | int nrows = 10*nchunk; // 800MB per rank!! 31 | 32 | char data_path[200]; 33 | sprintf(data_path, "dataset_%i", rank); 34 | 35 | //static_assert(false, "please update your credentials in `.hsds` matching with your kita lab settings... "); 36 | RVinit(); 37 | 38 | { // CREATE - WRITE 39 | std::vector v(nrows); 40 | std::fill(std::begin(v), std::end(v), rank + 2 ); 41 | size_t vsize =v.size() * sizeof(double); 42 | h5::fapl_t fapl = h5::kita{}; 43 | //static_assert(false, "please update PATH to your KITA account PATH"); 44 | if( rank == 0 ){ 45 | auto fd = h5::create("/home/steven/kita-io-test.h5", H5F_ACC_TRUNC, 46 | h5::fcpl, fapl ); 47 | } 48 | MPI_Barrier(MPI_COMM_WORLD); 49 | auto fd = h5::open("/home/steven/kita-io-test.h5",H5F_ACC_RDWR, fapl); 50 | h5::ds_t ds = h5::create(fd,data_path, 51 | h5::max_dims{size,nrows}, h5::chunk{1,nchunk} | h5::alloc_time_early ); 52 | 53 | // ACTUAL WRITE MEASUREMENT 54 | std::chrono::system_clock::time_point start = std::chrono::system_clock::now(); 55 | h5::write( ds, v, h5::current_dims{nrows,size}, 56 | h5::offset{rank,0}, h5::count{1,nrows} ); 57 | std::chrono::system_clock::time_point stop = std::chrono::system_clock::now(); 58 | double running_time = 1e-6 * std::chrono::duration_cast(stop - start).count(); 59 | double MB_sec = (vsize / 1e6) / running_time; 60 | 61 | // COLLECTING RESULTS: 62 | std::vector throughput(size); 63 | MPI_Gather(&MB_sec, 1, MPI_DOUBLE, throughput.data(), 1, MPI_DOUBLE, 0, comm); 64 | if( rank == 0) 65 | std::cout << "\nWRITE: " << 66 | std::accumulate(throughput.begin(), throughput.end(), 0) <<" MB/s" < v(nrows); 72 | size_t vsize =v.size() * sizeof(double); 73 | auto fd = h5::open("collective.h5", H5F_ACC_RDWR, h5::mpiio({MPI_COMM_WORLD, info})); 74 | auto ds = h5::open(fd, "/dataset"); 75 | 76 | // make a copy of dxpl, so we can query if collective IO was successful 77 | h5::dxpl_t dxpl = 5::collective; 78 | 79 | // ACTUAL WRITE MEASUREMENT 80 | std::chrono::system_clock::time_point start = std::chrono::system_clock::now(); 81 | h5::read(ds, v.data(), h5::offset{rank,0}, h5::count{1,nrows}, dxpl); 82 | std::chrono::system_clock::time_point stop = std::chrono::system_clock::now(); 83 | 84 | double running_time = 1e-6 * std::chrono::duration_cast(stop - start).count(); 85 | double MB_sec = (vsize / 1e6) / running_time; 86 | 87 | // COLLECTING RESULTS: 88 | std::vector throughput(size); 89 | MPI_Gather(&MB_sec, 1, MPI_DOUBLE, throughput.data(), 1, MPI_DOUBLE, 0, comm); 90 | if( rank == 0) 91 | std::cout << "\nREAD: " << 92 | std::accumulate(throughput.begin(), throughput.end(), 0) <<" MB/s" < 4 | */ 5 | #ifndef H5CPP_ARMA_HPP 6 | #define H5CPP_ARMA_HPP 7 | 8 | //#include "H5Tmeta.hpp" 9 | 10 | #if defined(ARMA_INCLUDES) || defined(H5CPP_USE_ARMADILLO) 11 | namespace h5 { namespace arma { 12 | template using rowvec = ::arma::Row; 13 | template using colvec = ::arma::Col; 14 | template using colmat = ::arma::Mat; 15 | template using cube = ::arma::Cube; 16 | 17 | // is_linalg_type := filter 18 | template ::type> using is_supported = 19 | std::integral_constant>::value || std::is_same>::value 20 | || std::is_same>::value || std::is_same>::value>; 21 | }} 22 | 23 | namespace h5::meta { 24 | template struct is_contiguous> : std::true_type {}; 25 | template struct is_contiguous> : std::true_type {}; 26 | template struct is_contiguous> : std::true_type {}; 27 | template struct is_contiguous> : std::true_type {}; 28 | } 29 | 30 | 31 | namespace h5 { namespace impl { 32 | // 1.) object -> H5T_xxx 33 | 34 | template struct decay>{ typedef T type; }; 35 | template struct decay>{ typedef T type; }; 36 | template struct decay>{ typedef T type; }; 37 | template struct decay>{ typedef T type; }; 38 | 39 | // get read access to datastaore 40 | template ::type> inline 41 | typename std::enable_if< h5::arma::is_supported::value, 42 | const T*>::type data( const Object& ref ){ 43 | return ref.memptr(); 44 | } 45 | 46 | // read write access 47 | template ::type> inline 48 | typename std::enable_if< h5::arma::is_supported::value, 49 | T*>::type data( Object& ref ){ 50 | return ref.memptr(); 51 | } 52 | 53 | // rank 54 | template struct rank> : public std::integral_constant{}; 55 | template struct rank> : public std::integral_constant{}; 56 | template struct rank> : public std::integral_constant{}; 57 | template struct rank> : public std::integral_constant{}; 58 | 59 | // determine rank and dimensions 60 | template inline std::array size( const h5::arma::rowvec& ref ){ return {ref.n_elem};} 61 | template inline std::array size( const h5::arma::colvec& ref ){ return {ref.n_elem};} 62 | template inline std::array size( const h5::arma::colmat& ref ){ return {ref.n_cols,ref.n_rows};} 63 | template inline std::array size( const h5::arma::cube& ref ){ return {ref.n_slices,ref.n_cols,ref.n_rows};} 64 | 65 | // CTOR-s 66 | template struct get> { 67 | static inline h5::arma::rowvec ctor( std::array dims ){ 68 | return h5::arma::rowvec( dims[0] ); 69 | }}; 70 | template struct get> { 71 | static inline h5::arma::colvec ctor( std::array dims ){ 72 | return h5::arma::colvec( dims[0] ); 73 | }}; 74 | template struct get> { 75 | static inline h5::arma::colmat ctor( std::array dims ){ 76 | return h5::arma::colmat( dims[0], dims[1] ); 77 | }}; 78 | template struct get> { 79 | static inline h5::arma::colmat ctor( std::array dims ){ 80 | return h5::arma::colmat( dims[2], dims[0], dims[1] ); 81 | }}; 82 | }} 83 | #endif 84 | #endif 85 | -------------------------------------------------------------------------------- /examples/packet-table/packettable.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Steven Varga, Toronto,ON Canada 3 | * Author: Varga, Steven 4 | */ 5 | #define ARMA_DONT_USE_WRAPPER 6 | #include 7 | #include // must include Eigen before 8 | 9 | #include 10 | #include "struct.h" 11 | #include 12 | // generated file must be sandwiched between core and io 13 | // to satisfy template dependencies in 14 | #include "generated.h" 15 | #include 16 | #include "utils.hpp" 17 | 18 | template using Matrix = Eigen::Matrix; 19 | 20 | int main(){ 21 | 22 | h5::fd_t fd = h5::create("example.h5",H5F_ACC_TRUNC); 23 | 24 | // SCALAR: integral 25 | // The motivation behind this example to allow 2D frames be recorded into a stream 26 | // 3x5 is the frame or image size, with 2 planes. 27 | try { // centrally used error handling 28 | std::vector stream(83); 29 | std::iota(std::begin(stream), std::end(stream), 1); 30 | // the leading dimension is extended once chunk is full, chunk is filled in row major order 31 | // zero copy writes directly to chunk buffer then pushed through filter chain if specified 32 | // works up to H5CPP_MAX_RANK default to 7 33 | // last chunk if partial filled with h5::fill_value( some_value ) 34 | h5::pt_t pt = h5::create(fd, "stream of integral 01", 35 | h5::max_dims{H5S_UNLIMITED,3,5}, h5::chunk{2,3,5} | h5::gzip{9} | h5::fill_value(3) ); 36 | for( auto record : stream ) 37 | h5::append(pt, record); 38 | //auto M = h5::read(fd,"stream of integral" ); 39 | } catch ( const h5::error::any& e ){ 40 | std::cerr << "ERROR:" << e.what(); 41 | } 42 | 43 | try { // centrally used error handling 44 | std::vector stream(83); 45 | std::iota(std::begin(stream), std::end(stream), 1); 46 | // the leading dimension is extended once chunk is full, chunk is filled in row major order 47 | // zero copy writes directly to chunk buffer then pushed through filter chain if specified 48 | // works up to H5CPP_MAX_RANK default to 7 49 | // last chunk if partial filled with h5::fill_value( some_value ) 50 | h5::pt_t pt = h5::create(fd, "stream of integral 02", 51 | h5::max_dims{H5S_UNLIMITED}, h5::chunk{6} | h5::gzip{9} | h5::fill_value(3) ); 52 | for( auto record : stream ) 53 | h5::append(pt, record); 54 | } catch ( const h5::error::any& e ){ 55 | std::cerr << "ERROR:" << e.what(); 56 | } 57 | 58 | 59 | // SCALAR: pod 60 | try { // 61 | std::vector stream = h5::utils::get_test_data(127); 62 | 63 | // implicit conversion from h5::ds_t to h5::pt_t makes it a breeze to create 64 | // packet_table from h5::open | h5::create calls, 65 | // The newly created h5::pt_t stateful container caches the incoming data until 66 | // bucket filled. IO operations are at h5::chunk boundaries 67 | // or when resource is released. Last partial chunk handled as expected. 68 | // 69 | // compiler assisted introspection generates boilerplate, developer 70 | // can focus on the idea, leaving boring details to machines 71 | h5::pt_t pt = h5::create(fd, "stream of struct", 72 | h5::max_dims{H5S_UNLIMITED,7}, h5::chunk{4,7} | h5::gzip{9} ); 73 | for( auto record : stream ) 74 | h5::append(pt, record); 75 | } catch ( const h5::error::any& e ){ 76 | std::cerr << "ERROR:" << e.what(); 77 | } 78 | 79 | { // packet table for a collection of matrices modelling a HD resolution of gray scale images 80 | size_t nrows = 2, ncols=256, nframes=100; 81 | h5::pt_t pt = h5::create(fd, "stream of matrices", 82 | h5::max_dims{H5S_UNLIMITED,nrows,ncols}, h5::chunk{1,nrows,ncols} ); 83 | Matrix M(nrows,ncols); 84 | int k=0; 85 | for( int i=0; i 4 | */ 5 | #ifndef H5CPP_ZALL_HPP 6 | #define H5CPP_ZALL_HPP 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace h5 { namespace impl { namespace filter { 13 | // TODO: figure something out to map c++ filters to C calls? 14 | template 15 | struct filter_t { 16 | htri_t can_apply(::hid_t dcpl, ::hid_t type, ::hid_t space){ 17 | return static_cast(this)->can_apply_impl(dcpl,type,space); 18 | } 19 | herr_t set_local(::hid_t dcpl, ::hid_t type, ::hid_t space){ 20 | return static_cast(this)->set_local_impl(dcpl,type,space); 21 | } 22 | size_t callback(unsigned int flags, size_t cd_nelmts, const unsigned int cd_values[], size_t nbytes, size_t *buf_size, void **buf){ 23 | return 0; 24 | } 25 | size_t apply( void* dst, const void* src, size_t size){ 26 | return static_cast(this)->apply(dst,src,size); 27 | } 28 | int version; 29 | unsigned id; 30 | unsigned encoder_present; 31 | unsigned decoder_present; 32 | std::string name; 33 | }; 34 | 35 | using call_t = size_t (*)(void* dst, const void* src, size_t size, unsigned flags, size_t n, const unsigned params[] ); 36 | inline size_t mock( void* dst, const void* src, size_t size, unsigned flags, size_t n, const unsigned params[] ){ 37 | memcpy(dst,src,size); 38 | return size; 39 | } 40 | inline size_t deflate( void* dst, const void* src, size_t size, unsigned flags, size_t n, const unsigned params[]){ 41 | memcpy(dst,src,size); 42 | return size; 43 | } 44 | inline size_t scaleoffset( void* dst, const void* src, size_t size, unsigned flags, size_t n, const unsigned params[]){ 45 | memcpy(dst,src,size); 46 | return size; 47 | } 48 | inline size_t gzip( void* dst, const void* src, size_t size, unsigned flags, size_t n, const unsigned params[]){ 49 | size_t nbytes = size; 50 | compress2( (unsigned char*)dst, &nbytes, (const unsigned char*)src, size, params[0]); 51 | return nbytes; 52 | } 53 | inline size_t szip( void* dst, const void* src, size_t size, unsigned flags, size_t n, const unsigned params[]){ 54 | memcpy(dst,src,size); 55 | return size; 56 | } 57 | inline size_t nbit( void* dst, const void* src, size_t size, unsigned flags, size_t n, const unsigned params[]){ 58 | memcpy(dst,src,size); 59 | return size; 60 | } 61 | inline size_t fletcher32( void* dst, const void* src, size_t size, unsigned flags, size_t n, const unsigned params[]){ 62 | memcpy(dst,src,size); 63 | return size; 64 | } 65 | 66 | inline size_t add( void* dst, const void* src, size_t size, unsigned flags, size_t n, const unsigned params[] ){ 67 | memcpy(dst,src,size); 68 | return size; 69 | } 70 | inline size_t shuffle( void* dst, const void* src, size_t size, unsigned flags, size_t n, const unsigned params[] ){ 71 | memcpy(dst,src,size); 72 | return size; 73 | } 74 | inline size_t jpeg( void* dst, const void* src, size_t size, unsigned flags, size_t n, const unsigned params[] ){ 75 | memcpy(dst,src,size); 76 | return size; 77 | } 78 | inline size_t disperse( void* dst, const void* src, size_t size, unsigned flags, size_t n, const unsigned params[] ){ 79 | memcpy(dst,src,size); 80 | return size; 81 | } 82 | inline size_t error( void* dst, const void* src, size_t size, unsigned flags, size_t n, const unsigned params[] ){ 83 | throw std::runtime_error("invalid filter"); 84 | return size; 85 | } 86 | inline call_t get_callback( H5Z_filter_t filter_id ){ 87 | 88 | switch( filter_id ){ 89 | case H5Z_FILTER_DEFLATE: return filter::gzip; 90 | case H5Z_FILTER_SHUFFLE: return filter::shuffle; 91 | case H5Z_FILTER_FLETCHER32: return filter::fletcher32; 92 | case H5Z_FILTER_SZIP: return filter::szip; 93 | case H5Z_FILTER_NBIT: return filter::nbit; 94 | case H5Z_FILTER_SCALEOFFSET: return filter::scaleoffset; 95 | default: 96 | return filter::error; 97 | } 98 | } 99 | 100 | 101 | }}} 102 | #endif 103 | --------------------------------------------------------------------------------