### Installing the Library Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/users_guide/installing.rst Install the compiled h5cpp library to the system using the 'make install' command. The default installation prefix is /usr/local. ```bash $ make install ``` -------------------------------- ### Install h5cpp Source: https://github.com/ess-dmsc/h5cpp/blob/master/README.md Install the built h5cpp library to the system using 'make install'. This typically requires superuser privileges. ```bash sudo make install ``` -------------------------------- ### Add Examples as Dependencies Source: https://github.com/ess-dmsc/h5cpp/blob/master/examples/mpi/CMakeLists.txt Specifies that the 'examples' target depends on 'writer_simple' and 'writer_extend'. This ensures these executables are built before 'examples'. ```cmake add_dependencies(examples writer_simple writer_extend ) ``` -------------------------------- ### Build Examples with Make Source: https://github.com/ess-dmsc/h5cpp/blob/master/examples/Readme.md After configuring with CMake, use Make to compile the h5cpp examples. This command assumes you are in the build directory created in the previous step. ```bash $ make ``` -------------------------------- ### Get Node Function Example Source: https://github.com/ess-dmsc/h5cpp/wiki/Meeting-minutes Demonstrates how to use the get_node function with relative paths and custom separators. ```cpp node::Node get_node(const node:Node &base,const Paths &path, std::string separator = ".."); node::Dataset base = .... node::Group base = root.create_group("../../../data"); node::Node n = get_node(base,"../../sample"); node::Node n = get_node(base,"#&/#&/sample", "#&"); ``` -------------------------------- ### Aggregate Example Targets and Include Subdirectories Source: https://github.com/ess-dmsc/h5cpp/blob/master/examples/CMakeLists.txt Creates a custom target 'examples' that depends on several example executables. It also conditionally adds subdirectories for attributes, SWMR, and MPI examples based on build configurations. ```cmake add_custom_target(examples) add_dependencies(examples basic_files selecting_datasets std_vector_io complex_io writing_image append_scalar_data append_vector_data ) # # build this only for new versions of HDF5 # add_subdirectory(attributes) if (H5CPP_SWMR_ENABLED) add_subdirectory(swmr) endif () if (H5CPP_MPI_ENABLED) add_subdirectory(mpi) endif () ``` -------------------------------- ### Setup and Build h5cpp Source: https://github.com/ess-dmsc/h5cpp/blob/master/build_with_meson.md Use these commands to set up the build directory and compile the h5cpp project using Meson and Ninja. ```bash $ meson setup builddir $ cd builddir $ ninja all ``` -------------------------------- ### Complete C++ HDF5 Read/Write Example Source: https://github.com/ess-dmsc/h5cpp/wiki/R-\-W-Interface-examples A full example demonstrating the creation of an HDF5 file, a group, a dataset, writing data to it, and printing the dataset. This illustrates the core R/W operations. ```C++ #include #include #include "hdf5" int main() { hdf5::File hdf5File("some_file_name.h5"); hdf5::Group someGroup(hdf5File, "name_of_group"); std::vector dimensions = {2, 2}; hdf5::DataSet someDataSet(someGroup, "name_of_data_set", dimensions); std::vector someData = {1, 2, 3, 4}; someDataSet({{0, 1}, {0, 1}}) = someData; std::cout << someDataSet << std::endl; return 0; } ``` -------------------------------- ### Example Project Structure Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/users_guide/using.rst A typical project structure for an application using h5cpp. ```text h5cpp_test/ main.cpp CMakeLists.txt ``` -------------------------------- ### Installing h5cpp Package Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/users_guide/installing.rst Install the h5cpp library version 0.8.0 and its associated debug, documentation, and development packages using apt-get. ```bash $ apt-get install libh5cpp0.8.0 libh5cpp0.8.0-dbg libh5cpp0.8.0-doc libh5cpp0.8.0-dev ``` -------------------------------- ### Install h5cpp Utility Headers Source: https://github.com/ess-dmsc/h5cpp/blob/master/src/h5cpp/utilities/CMakeLists.txt Installs the header files for the h5cpp utilities module to the system's include directory. ```cmake set(dir ${CMAKE_CURRENT_SOURCE_DIR}) set(SOURCES ) set(HEADERS ${dir}/array_adapter.hpp ) install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/h5cpp/utilities) set(h5cpp_headers ${h5cpp_headers} ${HEADERS} PARENT_SCOPE) set(h5cpp_sources ${h5cpp_sources} ${SOURCES} PARENT_SCOPE) ``` -------------------------------- ### Default Meson Build Steps Source: https://github.com/ess-dmsc/h5cpp/blob/master/build-with-meson.md Standard procedure to set up and build the library using Meson. Ensure you are in the project's root directory before starting. ```bash mkdir builddir meson setup builddir cd builddir ninja ``` -------------------------------- ### Configure and Install Pkg-Config File Source: https://github.com/ess-dmsc/h5cpp/blob/master/src/h5cpp/CMakeLists.txt Conditionally configures and installs the h5cpp.pc file if H5CPP_CONAN is not set to DISABLE. It generates link flags and compile flags based on target properties. ```cmake if(${H5CPP_CONAN} MATCHES "DISABLE") get_target_property(LIBRARIES h5cpp INTERFACE_LINK_LIBRARIES) get_target_property(DEFINITIONS h5cpp INTERFACE_COMPILE_DEFINITIONS) get_target_property(INCLUDE_DIRS h5cpp INTERFACE_INCLUDE_DIRECTORIES) foreach(LIB ${LIBRARIES}) GET_LIBRARY_NAME("${LIB}") endforeach() foreach(LIB ${HDF5_LIBRARIES}) GET_LIBRARY_NAME("${LIB}") endforeach() list(REMOVE_DUPLICATES PKG_CONFIG_LIBS) list(REMOVE_DUPLICATES PKG_CONFIG_LIBDIRS) if(${CMAKE_VERSION} VERSION_LESS "3.13.0") message("Please consider to switch to CMake 3.13.0") else() target_link_directories(h5cpp PUBLIC ${PKG_CONFIG_LIBDIRS}) endif() set(PKG_CONFIG_LINKFLAGS) foreach(DIR ${PKG_CONFIG_LIBDIRS}) set(PKG_CONFIG_LINKFLAGS "${PKG_CONFIG_LINKFLAGS} -L${DIR}") endforeach() foreach(LIB ${PKG_CONFIG_LIBS}) set(PKG_CONFIG_LINKFLAGS "${PKG_CONFIG_LINKFLAGS} -l${LIB}") endforeach() set(PKG_CONFIG_CFLAGS) foreach(DEF ${DEFINITIONS}) if(NOT (DEF MATCHES ".*NOTFOUND")) set(PKG_CONFIG_CFLAGS "${PKG_CONFIG_CFLAGS} -D${DEF}") endif() endforeach() foreach(INCDIR ${INCLUDE_DIRS}) if(NOT (INCDIR MATCHES "\\$<.*\"")) set(PKG_CONFIG_CFLAGS "${PKG_CONFIG_CFLAGS} -I${INCDIR}") endif() endforeach() message("Link libraries: ${PKG_CONFIG_LIBS}") message("Library paths: ${PKG_CONFIG_LINKFLAGS}") configure_file(h5cpp.pc.in h5cpp.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/h5cpp.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT development) endif() ``` -------------------------------- ### Install h5cpp to Alternate Directory Source: https://github.com/ess-dmsc/h5cpp/blob/master/README.md Use this CMake option to specify a custom installation prefix for the h5cpp library. ```bash cmake -DCMAKE_INSTALL_PREFIX=/home/user1/some/path .. ``` -------------------------------- ### Install Headers Source: https://github.com/ess-dmsc/h5cpp/blob/master/src/h5cpp/contrib/nexus/CMakeLists.txt Installs the header files for the Nexus contrib module to the appropriate include directory. ```cmake install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/h5cpp/contrib/nexus) ``` -------------------------------- ### Create HDF5 File, Group, and Dataset Source: https://github.com/ess-dmsc/h5cpp/blob/master/README.md Example demonstrating how to create an HDF5 file, a group within it, and a dataset to store a vector of integers. ```cpp using namespace hdf5; // create a file file::File f = file::create("writing_vector.h5",file::AccessFlags::Truncate); // create a group node::Group root_group = f.root(); node::Group my_group = root_group.create_group("my_group"); // create a dataset using data_type = std::vector; data_type data{1,2,3,4}; node::Dataset dataset = my_group.create_dataset("data", datatype::create(), dataspace::create(data)); // write to dataset dataset.write(data); ``` -------------------------------- ### Install h5cpp Dataspace Headers Source: https://github.com/ess-dmsc/h5cpp/blob/master/src/h5cpp/dataspace/CMakeLists.txt Installs the header files for the h5cpp dataspace module to the system's include directory. This makes the module's API accessible to other projects. ```cmake install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/h5cpp/dataspace) ``` -------------------------------- ### Install H5CPP File Module Headers Source: https://github.com/ess-dmsc/h5cpp/blob/master/src/h5cpp/file/CMakeLists.txt Installs the header files to the specified include directory for the H5CPP file module. This makes the headers available for external projects. ```cmake install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/h5cpp/file) ``` -------------------------------- ### Install STL Headers Source: https://github.com/ess-dmsc/h5cpp/blob/master/src/h5cpp/contrib/stl/CMakeLists.txt Installs the defined STL header files to the specified destination directory for the h5cpp package. ```cmake install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/h5cpp/contrib/stl) ``` -------------------------------- ### Configure Client Program with Alternate Install Directory Source: https://github.com/ess-dmsc/h5cpp/blob/master/README.md When using an alternate install directory for h5cpp, point your client program's CMake build to the custom h5cpp directory. ```bash cmake -Dh5cpp_DIR=/home/user1/some/path/lib/cmake/h5cpp-0.8.0 path/to/your/source ``` -------------------------------- ### Install Conan Package Manager Source: https://github.com/ess-dmsc/h5cpp/blob/master/README.md Install the Conan package manager using pip, which is a recommended way to manage h5cpp dependencies. ```bash pip install conan ``` -------------------------------- ### Basic CMake Configuration for h5cpp Examples Source: https://github.com/ess-dmsc/h5cpp/blob/master/examples/CMakeLists.txt Sets up the minimum CMake version, project name, and finds the h5cpp package. It also conditionally includes MPI support and sets the C++ standard based on H5CPP_BOOST_ENABLED. ```cmake cmake_minimum_required(VERSION 3.0.0) project(h5cpp-examples LANGUAGES CXX C) get_directory_property(IS_TOP_LEVEL PARENT_DIRECTORY) if (NOT IS_TOP_LEVEL) find_package(h5cpp REQUIRED) if (H5CPP_MPI_ENABLED) find_package(MPI REQUIRED) include_directories(SYSTEM ${MPI_C_INCLUDE_PATH}) include_directories(SYSTEM ${MPI_INCLUDE_PATH}) endif () endif() if (NOT H5CPP_BOOST_ENABLED) set(CMAKE_CXX_STANDARD 17) else() set(CMAKE_CXX_STANDARD 11) endif() ``` -------------------------------- ### Define Executable Target for Selecting Datasets Example Source: https://github.com/ess-dmsc/h5cpp/blob/master/examples/CMakeLists.txt Creates an executable target named 'selecting_datasets' from 'selecting_datasets.cpp' and links it with the h5cpp library. ```cmake add_executable(selecting_datasets selecting_datasets.cpp) target_link_libraries(selecting_datasets PRIVATE h5cpp::h5cpp) ``` -------------------------------- ### Configuring Build with CMake Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/users_guide/installing.rst Configure the build using CMake, specifying the build type as Release. Ensure all dependencies are installed in standard locations. ```bash $ cmake -DCMAKE_BUILD_TYPE=Release ../h5cpp ``` -------------------------------- ### Configure Build with CMake Source: https://github.com/ess-dmsc/h5cpp/blob/master/examples/Readme.md Use CMake to configure the build process for the h5cpp examples. Ensure you replace `` with the actual path to your h5cpp CMake package configuration file. ```bash $ mkdir examples_build $ cd examples_build $ cmake -DCMAKE_BUILD_TYPE=Release -Dh5cpp_DIR= ../examples ``` -------------------------------- ### Meson Build with MPI Support Source: https://github.com/ess-dmsc/h5cpp/blob/master/build-with-meson.md Enables MPI support during the Meson setup phase by passing the '-Dwith-mpi=true' option. This is necessary for projects requiring MPI functionality. ```bash meson setup -Dwith-mpi=true builddir ``` -------------------------------- ### Define Executable Target for Basic Files Example Source: https://github.com/ess-dmsc/h5cpp/blob/master/examples/CMakeLists.txt Creates an executable target named 'basic_files' from 'basic_files.cpp' and links it with the h5cpp library. ```cmake add_executable(basic_files basic_files.cpp) target_link_libraries(basic_files PRIVATE h5cpp::h5cpp) ``` -------------------------------- ### Building the Project with CMake Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/users_guide/using.rst Commands to build the h5cpp project using CMake. Ensure you set the h5cpp_DIR variable to the correct installation path. ```bash h5cpp_test:$ mkdir build h5cpp_test:$ cd build h5cpp_test:$ cmake -Dh5cpp_DIR=/lib/cmake/h5cpp-0.8.0 ../ h5cpp_test:$ make ``` -------------------------------- ### Define Executable Target for Reading Dataset Example Source: https://github.com/ess-dmsc/h5cpp/blob/master/examples/CMakeLists.txt Creates an executable target named 'read_dataset' from 'read_dataset.cpp' and links it with the h5cpp library. ```cmake add_executable(read_dataset read_dataset.cpp) target_link_libraries(read_dataset PRIVATE h5cpp::h5cpp) ``` -------------------------------- ### Build h5cpp with CMake and Make (Linux) Source: https://github.com/ess-dmsc/h5cpp/blob/master/README.md Standard build process for h5cpp on Linux using Git, CMake, and Make. Assumes dependencies are managed by Conan or installed manually. ```bash git clone https://github.com/ess-dmsc/h5cpp.git cd h5cpp mkdir build cd build cmake .. make ``` -------------------------------- ### Using IO Object Read/Write Methods Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/design/source/concepts.md Illustrates the usage of the 'read()' and 'write()' methods on an 'io_object' instance. This example shows how to read a scalar value (double) and write a container (std::vector). ```cpp io_object object = ...; double temperature; object.read(temperature); std::vector velocity; object = ...; object.write(velocity); ``` -------------------------------- ### H5CPP Datatype Source and Header Files Source: https://github.com/ess-dmsc/h5cpp/blob/master/src/h5cpp/datatype/CMakeLists.txt Defines the source and header files for the H5CPP datatype library and sets up installation rules. ```cmake set(dir ${CMAKE_CURRENT_SOURCE_DIR}) set(SOURCES ${dir}/array.cpp ${dir}/compound.cpp ${dir}/datatype.cpp ${dir}/float.cpp ${dir}/integer.cpp ${dir}/string.cpp ${dir}/types.cpp ${dir}/enum.cpp ) set(HEADERS ${dir}/datatype.hpp ${dir}/factory.hpp ${dir}/float.hpp ${dir}/integer.hpp ${dir}/type_trait.hpp ${dir}/types.hpp ${dir}/compound.hpp ${dir}/string.hpp ${dir}/array.hpp ${dir}/enum.hpp ) install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/h5cpp/datatype) set(h5cpp_headers ${h5cpp_headers} ${HEADERS} PARENT_SCOPE) set(h5cpp_sources ${h5cpp_sources} ${SOURCES} PARENT_SCOPE) ``` -------------------------------- ### H5CPP Filter CMakeLists.txt Configuration Source: https://github.com/ess-dmsc/h5cpp/blob/master/src/h5cpp/filter/CMakeLists.txt Defines source and header files for the H5CPP filter library and sets installation paths. ```cmake set(dir ${CMAKE_CURRENT_SOURCE_DIR}) set(SOURCES ${dir}/deflate.cpp ${dir}/filter.cpp ${dir}/fletcher32.cpp ${dir}/nbit.cpp ${dir}/scaleoffset.cpp ${dir}/shuffle.cpp ${dir}/szip.cpp ${dir}/external_filter.cpp ) set(HEADERS ${dir}/filter.hpp ${dir}/types.hpp ${dir}/deflate.hpp ${dir}/fletcher32.hpp ${dir}/nbit.hpp ${dir}/scaleoffset.hpp ${dir}/shuffle.hpp ${dir}/szip.hpp ${dir}/external_filter.hpp ) install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/h5cpp/filter) set(h5cpp_headers ${h5cpp_headers} ${HEADERS} PARENT_SCOPE) set(h5cpp_sources ${h5cpp_sources} ${SOURCES} PARENT_SCOPE) ``` -------------------------------- ### Define Executable Target for Writing Image Example Source: https://github.com/ess-dmsc/h5cpp/blob/master/examples/CMakeLists.txt Creates an executable target named 'writing_image' from 'writing_image.cpp' and 'rgbpixel.cpp', linking it with the h5cpp library. ```cmake add_executable(writing_image writing_image.cpp rgbpixel.cpp) target_link_libraries(writing_image PRIVATE h5cpp::h5cpp) ``` -------------------------------- ### Define Executable Target for Complex IO Example Source: https://github.com/ess-dmsc/h5cpp/blob/master/examples/CMakeLists.txt Creates an executable target named 'complex_io' from 'complex_io.cpp' and links it with the h5cpp library. ```cmake add_executable(complex_io complex_io.cpp) target_link_libraries(complex_io PRIVATE h5cpp::h5cpp) ``` -------------------------------- ### Define Executable Target for Standard Vector IO Example Source: https://github.com/ess-dmsc/h5cpp/blob/master/examples/CMakeLists.txt Creates an executable target named 'std_vector_io' from 'std_vector_io.cpp' and links it with the h5cpp library. ```cmake add_executable(std_vector_io std_vector_io.cpp) target_link_libraries(std_vector_io PRIVATE h5cpp::h5cpp) ``` -------------------------------- ### Define Executable Target for Writing Vector List Example Source: https://github.com/ess-dmsc/h5cpp/blob/master/examples/CMakeLists.txt Creates an executable target named 'write_vector_list' from 'write_vector_list.cpp' and links it with the h5cpp library. ```cmake add_executable(write_vector_list write_vector_list.cpp) target_link_libraries(write_vector_list PRIVATE h5cpp::h5cpp) ``` -------------------------------- ### Create HDF5 file with custom property lists Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/users_guide/files.rst Create an HDF5 file with custom file creation and access property lists, for example, to enable SWMR features. Ensure you link against HDF5 1.10.0 or higher. ```cpp property::FileCreationList fcpl; //can use the default here property::FileAccessList fapl; //we need to set the appropriate version flags fapl.library_version_bounds(property::LibVersion::Latest, property::LibVersion::Latest); file::File f = file::create("swmr_file.h5", file::AccessFlags::Truncate, fcpl,fapl); ``` -------------------------------- ### Constructing id_t from hid_t Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/design/source/design/ids.md Provides examples of constructing an id_t object from a raw HDF5 hid_t value, including a case with prior error checking. ```cpp id_t id(H5Tcopy(H5T_NATIVE_DOUBLE)); ``` ```cpp hid_t id_plain = H5Tcopy(H5T_NATIVE_DOUBLE); if(id_plain < 0) { //do some error management here } id_t id(std::move(id_plain)); ``` -------------------------------- ### Define Executable Target for Writing Single Vector Example Source: https://github.com/ess-dmsc/h5cpp/blob/master/examples/CMakeLists.txt Creates an executable target named 'write_single_vector' from 'write_single_vector.cpp' and links it with the h5cpp library. ```cmake add_executable(write_single_vector write_single_vector.cpp) target_link_libraries(write_single_vector PRIVATE h5cpp::h5cpp) ``` -------------------------------- ### Dataset Stream IO - Writing Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/users_guide/datasets.rst Example of using `dataset_stream_t` to write data sequentially to a dataset along a specified dimension, similar to standard C++ output streams. ```cpp h5::dataset_t dataset = group["temperatures"]; //create a new stream along the first dimension of a dataset h5::dataset_stream_t stream(dataset,0); while(measurement_running) { double temperature = read_temperature(); stream<apply(space,selection.first); ``` -------------------------------- ### Basic C++ Main File Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/users_guide/using.rst A simple C++ program demonstrating the inclusion of h5cpp headers and basic usage. ```cpp #include #include int main() { auto type = hdf5::datatype::TypeTrait::create(); std::cout< ``` -------------------------------- ### Read and Write Entire Dataset Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/users_guide/datasets.rst Demonstrates reading from and writing to an entire dataset using the `read` and `write` methods. Assumes the dataset is already created and accessible. ```cpp dataset_t dset = group["temperatures"]; std::vector temperatures; dset.read(temperatures); //or for writing dset.write(temperatures) ``` -------------------------------- ### Opening an HDF5 File Source: https://github.com/ess-dmsc/h5cpp/wiki/R-\-W-Interface-examples Demonstrates the basic syntax for opening an HDF5 file. Additional parameters like read-only or SWMR mode would require an extended interface, possibly using a parameter library. ```C++ hdf5::File hdf5File("some_file_name.h5"); ``` -------------------------------- ### Creating an HDF5 Dataset Source: https://github.com/ess-dmsc/h5cpp/wiki/R-\-W-Interface-examples Illustrates the creation of a dataset with a specified data type and dimensions. The library should provide sensible defaults for parameters like cache and chunk size if not explicitly set. ```C++ hdf5::DataSet someDataSet(someGroup, "name_of_data_set", dimensions); ``` -------------------------------- ### Run h5cpp Tests Source: https://github.com/ess-dmsc/h5cpp/blob/master/build_with_meson.md Execute this command after building to run the tests for the h5cpp project. ```bash $ ninja test ``` -------------------------------- ### Define STL Headers in CMake Source: https://github.com/ess-dmsc/h5cpp/blob/master/src/h5cpp/contrib/stl/CMakeLists.txt Sets the list of header files for the h5cpp STL contribution. These headers are typically installed to the include directory. ```cmake set(HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/array.hpp ${CMAKE_CURRENT_SOURCE_DIR}/complex.hpp ${CMAKE_CURRENT_SOURCE_DIR}/stl.hpp ${CMAKE_CURRENT_SOURCE_DIR}/string.hpp ${CMAKE_CURRENT_SOURCE_DIR}/vector.hpp) ``` -------------------------------- ### Define Executable Target for Appending Vector Data Example Source: https://github.com/ess-dmsc/h5cpp/blob/master/examples/CMakeLists.txt Creates an executable target named 'append_vector_data' from 'append_vector_data.cpp' and links it with the h5cpp library. ```cmake add_executable(append_vector_data append_vector_data.cpp) target_link_libraries(append_vector_data PRIVATE h5cpp::h5cpp) ``` -------------------------------- ### Construct Simple Dataspace from General Dataspace Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/users_guide/dataspace.rst Create a new dataspace::Simple instance by copying from a general dataspace::Dataspace reference. This utilizes the conversion copy constructor. ```cpp using namespace hdf5; dataspace::Dataspace &general_dataspace = ...; dataspace::Simple simple_dataspace(general_dataspace); ``` -------------------------------- ### Define Executable Target for Appending Scalar Data Example Source: https://github.com/ess-dmsc/h5cpp/blob/master/examples/CMakeLists.txt Creates an executable target named 'append_scalar_data' from 'append_scalar_data.cpp' and links it with the h5cpp library. ```cmake add_executable(append_scalar_data append_scalar_data.cpp) target_link_libraries(append_scalar_data PRIVATE h5cpp::h5cpp) ``` -------------------------------- ### Building the Library Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/users_guide/installing.rst Compile the h5cpp library using make after configuring with CMake. This command is typically used on Linux systems where make is the default build system. ```bash $ make ``` -------------------------------- ### HDF5 C API for Dataset Creation Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/design/source/design/property_lists.md Illustrates the C API function for creating a dataset, highlighting the use of various property list IDs as arguments. ```c hid_t H5Dcreate(hid_t loc_id, const char *name, hid_t dtype_id, hid_t space_id, hid_t lcpl_id, hid_t dcpl_id, hid_t dapl_id) ``` -------------------------------- ### HDF5 C-API Object Leak Example Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/design/source/design/ids.md Illustrates a common resource leak scenario in the HDF5 C-API where an object is not closed if an error occurs. ```cpp int dosomething(...) { hid_t group = H5Gopen(...); if(error) { return 1; } H5Gclose(group); } ``` -------------------------------- ### Configuring and Copying Source Files Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/design/CMakeLists.txt This snippet iterates through the defined SOURCES and uses `configure_file` to copy them, potentially performing variable substitution if placeholders are present. This ensures that source files are correctly placed and configured for the build. ```cmake foreach(SRC ${SOURCES}) configure_file(${SRC} ${SRC} COPYONLY) endforeach() ``` -------------------------------- ### Get Root Group from HDF5 File Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/users_guide/files.rst Obtains the root group of an HDF5 file instance, which is necessary for accessing the object tree in the C++ API. ```cpp hdf5::file::File f = .... ; hdf5::node::Group root_group = f.root(); ``` -------------------------------- ### HDF5 C++ Wrapper for Dataset Creation Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/design/source/design/property_lists.md Demonstrates a type-safe C++ wrapper for dataset creation, using distinct property list types for compile-time checking. ```c++ id_t create_dataset(const id_t &location, const path_t &path, const datatype::datatype_t &dtype, const dataspace::dataspace_t &dspace, const property_list::link_create_t &lcpl, const property_list::dataset_create_t &dcpl, const property_list::dataset_access_t &dapl) ``` -------------------------------- ### Define Executable and Link Libraries Source: https://github.com/ess-dmsc/h5cpp/blob/master/test/utilities/CMakeLists.txt Defines the 'utilities_test' executable and links it against the 'h5cpp' library, HDF5, and Catch2 testing framework. This is essential for building the test suite. ```cmake add_executable(utilities_test array_adapter_test.cpp) target_link_libraries( utilities_test PRIVATE h5cpp hdf5::hdf5 Catch2::Catch2 Catch2::Catch2WithMain ) ``` -------------------------------- ### Add Executable for Attribute Iteration Source: https://github.com/ess-dmsc/h5cpp/blob/master/examples/attributes/CMakeLists.txt Defines an executable target named 'attribute_iteration' and links it against the h5cpp library. This setup is for projects that involve iterating over HDF5 attributes. ```cmake add_executable(attribute_iteration attribute_iteration.cpp) target_link_libraries(attribute_iteration PRIVATE h5cpp::h5cpp) ``` -------------------------------- ### Apply Selection using SelectionManager Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/users_guide/dataspace_selections.rst Demonstrates how to apply a hyperslab selection to an existing dataspace using the SelectionManager interface. Ensure you have a Dataspace object and a Hyperslab defined. ```cpp dataspace::Dataspace file_space = dataset.dataspace(); dataspace::Hyperslab slab(...); file_space.selection(dataspace::SelectionOperation::Set,slab); ``` -------------------------------- ### Create a new HDF5 file Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/users_guide/files.rst Use `hdf5::file::create` to create a new HDF5 file. By default, this function throws an exception if the file already exists. ```cpp #include #include using namespace hdf5; using namespace fs = boost::filesystem; int main() { //creating a new file fs::path file_path("data.h5"); file::File f1 = file::create(file_path); //do something with the file } ``` -------------------------------- ### Create an Extensible Simple Dataspace with Bounded Maximum Dimensions Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/users_guide/dataspace.rst Create a simple dataspace that can be extended up to a specified maximum size in each dimension. Initial dimensions are smaller than maximum. ```cpp using namespace hdf5; dataspace::Simple space({2,3},{10,10}); space.current_dimensions(); // {2,3} space.maximum_dimensions(); // {10,10} ``` -------------------------------- ### Define h5cpp Dataspace Sources and Headers Source: https://github.com/ess-dmsc/h5cpp/blob/master/src/h5cpp/dataspace/CMakeLists.txt Defines the list of C++ source files and header files for the h5cpp dataspace module. These lists are used for compilation and installation. ```cmake set(dir ${CMAKE_CURRENT_SOURCE_DIR}) set(SOURCES ${dir}/hyperslab.cpp ${dir}/dataspace.cpp ${dir}/scalar.cpp ${dir}/selection.cpp ${dir}/selection_manager.cpp ${dir}/simple.cpp ${dir}/type.cpp ${dir}/view.cpp ${dir}/points.cpp ${dir}/pool.cpp ) set(HEADERS ${dir}/hyperslab.hpp ${dir}/dataspace.hpp ${dir}/scalar.hpp ${dir}/selection_manager.hpp ${dir}/selection.hpp ${dir}/simple.hpp ${dir}/type.hpp ${dir}/type_trait.hpp ${dir}/view.hpp ${dir}/points.hpp ${dir}/pool.hpp ) ``` -------------------------------- ### Create Executable and Link Libraries Source: https://github.com/ess-dmsc/h5cpp/blob/master/test/attribute/CMakeLists.txt Builds the 'attribute_test' executable from the defined sources and links it with required libraries. This includes the h5cpp library, HDF5, and the Catch2 testing framework. ```cmake add_executable(attribute_test ${test_sources}) target_link_libraries( attribute_test PRIVATE h5cpp hdf5::hdf5 Catch2::Catch2 Catch2::Catch2WithMain ) ``` -------------------------------- ### SWMR Executable Definitions Source: https://github.com/ess-dmsc/h5cpp/blob/master/examples/swmr/CMakeLists.txt Defines the SWMR write and read executables, specifying their source files and linking against the h5cpp library. This setup is used for building SWMR-enabled applications. ```cmake set(SWMR_SOURCES swmr_environment.cpp swmr_builder.cpp) add_executable(swmr_write swmr_write.cpp ${SWMR_SOURCES}) target_link_libraries(swmr_write PRIVATE h5cpp::h5cpp) add_executable(swmr_read swmr_reader.cpp ${SWMR_SOURCES}) target_link_libraries(swmr_read PRIVATE h5cpp::h5cpp) add_dependencies(examples swmr_write swmr_read ) ``` -------------------------------- ### Node Constructor from Link Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/design/source/design/group.md Illustrates the potential constructors for a node_t class that would allow implicit conversion from link_t objects. This facilitates easier navigation and object creation from links. ```cpp class node_t { public: node_t(const link::link_t &l); node_t(link::link_t &&l); } ``` -------------------------------- ### Type Naming Conflict Example Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/design/source/coding_style.md Illustrates a potential naming conflict when a type name and a variable name are identical, highlighting the rationale for using suffixes like '_t' to differentiate them. ```cpp id id; ``` -------------------------------- ### hdf5::file::create Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/api_reference/namespace_file.rst Creates a new HDF5 file with specified access and creation properties. ```APIDOC ## hdf5::file::create ### Description Creates a new HDF5 file at the specified path with the given access flags and property lists. ### Signature `hdf5::file::create(const fs::path &, AccessFlags, const property::FileCreationList &, const property::FileAccessList &)` ### Parameters * **path** (const fs::path &) - The path where the HDF5 file will be created. * **flags** (AccessFlags) - The access flags to apply to the file. * **create_plist** (const property::FileCreationList &) - The file creation property list. * **access_plist** (const property::FileAccessList &) - The file access property list. ``` -------------------------------- ### Including Project Subdirectories Source: https://github.com/ess-dmsc/h5cpp/blob/master/test/CMakeLists.txt Adds various subdirectories to the CMake build process, enabling the compilation of different modules like 'examples', 'error', 'core', etc. This modularizes the project structure. ```cmake include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory(examples) add_subdirectory(error) add_subdirectory(core) add_subdirectory(property) add_subdirectory(datatype) add_subdirectory(dataspace) add_subdirectory(attribute) add_subdirectory(filter) add_subdirectory(node) add_subdirectory(file) add_subdirectory(utilities) ``` -------------------------------- ### Extending Dataset Write with Constructor Subclassing Source: https://github.com/ess-dmsc/h5cpp/wiki/Allowing-for-subclassing-of-hdf5::node::Dataset-and-hdf5::node::Group Demonstrates how to extend the Dataset's write functionality by subclassing and overriding the write method when a constructor is available. This allows for self-contained extra actions. ```c++ std::vector someData = getSomeData(); MyDataset cDataSet = MyDataset(*someGroup, "some_name", ...); cDataSet.write(someData); ``` ```c++ class MyDataset : public Dataset { public: MyDataset(const Group *parent, std::string name, ...) : Dataset(parent, name, ...) {} template void write(const T &data) const { Dataset::write(data); //Do extra stuff //Do extra stuff } }; ``` -------------------------------- ### Find and Report Unresolvable External Links Recursively Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/design/source/design/group.md Recursively traverse all links starting from the root group to find external links that cannot be resolved. Prints the targets of unresolvable links to standard output. ```cpp std::vector invalid_ext_links; group::group_t root_group = file.root_group(); std::copy_if(root_group.links.begin_recursive(), root_group.links.end_recursive(), std::back_inserter(invalid_ext_links), [](const auto &l) { return (l.type() == link::link_t::type_t::EXTERNAL) && (l.status() == link::status_t::NOT_RESOLVABLE); }); for(const auto &l: invalid_ext_links) std::cout<<"Cannot resolve: "< #include ``` -------------------------------- ### Create and Populate Point Selection with push_back Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/design/source/design/dataspace.md Creates a dataspace::point_t object and populates it with coordinates using the push_back member function. This is an alternative to using initializer lists. ```cpp dataspace::point_t points(3); points.push_back({1,2,3}); points.push_back({4,5,5}); points.push_back({4,3,4}); ``` -------------------------------- ### CMakeLists.txt for h5cpp Error Tests Source: https://github.com/ess-dmsc/h5cpp/blob/master/test/error/CMakeLists.txt Configures the build for h5cpp error tests. Includes source files, links libraries like h5cpp and Catch2, and discovers tests. ```cmake set(test_sources descriptor_test.cpp h5c_error_test.cpp error_test.cpp) add_executable(error_test ${test_sources}) target_link_libraries( error_test PRIVATE h5cpp hdf5::hdf5 Catch2::Catch2 Catch2::Catch2WithMain ) catch_discover_tests(error_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) ``` -------------------------------- ### Write Data to C-style Array using ArrayAdapter Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/advanced/c_arrays.rst Create an instance of ArrayAdapter on the fly to write data from a C-style array to an HDF5 dataset. The memory for the C-style array must be managed externally. ```cpp using DoubleArrayAdapter = ArrayAdapter; Dataset dataset(...); double *data; data = new double[1024]; dataset.write(DoubleArrayAdapter(data,1024)); ``` -------------------------------- ### Indentation and Namespace Handling Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/design/source/coding_style.md Demonstrates the use of 4 spaces for indentation and the rule of not indenting nested namespaces. This ensures consistent code structure. ```cpp namespace first{ namespace second{ //no indentation required here void function(int arg) { //add here some code } } // end of namespace second } // end of namespace first ``` -------------------------------- ### Reading and Writing Data with Operators Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/design/source/concepts.md Demonstrates the intended usage of overloaded operators for reading and writing data, mimicking Python's h5py package. ```cpp io_object object = ....; double temperature = object; //reading data (conversion) object = ....; object = std::vector{...}; // writing data (assignment) ``` -------------------------------- ### Create Dataspace Test Executable Source: https://github.com/ess-dmsc/h5cpp/blob/master/test/dataspace/CMakeLists.txt Builds the dataspace test executable using the defined source files. ```cmake add_executable(dataspace_test ${test_sources}) ``` -------------------------------- ### hdf5::file::open Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/api_reference/namespace_file.rst Opens an existing HDF5 file with specified access flags and access property list. ```APIDOC ## hdf5::file::open ### Description Opens an existing HDF5 file at the specified path with the given access flags and access property list. ### Signature `hdf5::file::open(const fs::path &, AccessFlags, const property::FileAccessList &)` ### Parameters * **path** (const fs::path &) - The path to the HDF5 file to open. * **flags** (AccessFlags) - The access flags to apply to the file. * **access_plist** (const property::FileAccessList &) - The file access property list. ``` -------------------------------- ### Container Adapter for Datasets - Reading Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/users_guide/datasets.rst Shows how to use `container_adapter_t` to iterate over a dataset along a specified dimension, simplifying access to multidimensional data. Each element read is processed. ```cpp using frame_t = std::vector; h5::dataset_t d = group["detector_data"]; //container adapter for dataset d along the first dimension container_adapter_t frames(d,0); frame_t frame; for(auto slab: frames) { //process the frame slab.read(frame); } ``` -------------------------------- ### Define Test Executable Sources Source: https://github.com/ess-dmsc/h5cpp/blob/master/test/property/CMakeLists.txt Lists all source files for the properties_test executable. ```cmake set(test_sources utilities.cpp property_class_test.cpp property_list_test.cpp creation_order_test.cpp object_creation_test.cpp dataset_creation_test.cpp type_creation_test.cpp group_creation_test.cpp file_creation_test.cpp link_access_test.cpp chunk_cache_parameters_test.cpp dataset_access_test.cpp datatype_access_test.cpp group_access_test.cpp string_creation_test.cpp attribute_creation_test.cpp link_creation_test.cpp dataset_transfer_test.cpp file_access_test.cpp file_mount_test.cpp object_copy_test.cpp) add_executable(properties_test ${test_sources}) ``` -------------------------------- ### CMakeLists.txt Configuration for h5cpp Source: https://github.com/ess-dmsc/h5cpp/blob/master/doc/source/users_guide/using.rst This CMakeLists.txt file is sufficient to build a C++ program using h5cpp. It finds the h5cpp package and links the executable against it. ```cmake cmake_minimum_required(VERSION 3.5.0) project(h5cpp_test LANGUAGES C CXX VERSION 0.8.0) set(CMAKE_CXX_STANDARD 11) find_package(h5cpp REQUIRED) add_executable(h5cpp_test main.cpp) target_link_libraries(h5cpp_test h5cpp::h5cpp) ``` -------------------------------- ### Define Test Source Files Source: https://github.com/ess-dmsc/h5cpp/blob/master/test/core/CMakeLists.txt Lists all the C++ source files that will be compiled for the core test executable. ```cmake set(test_sources ObjectHandleDefault.cpp object_handle_test.cpp file_object_handle_test.cpp datatype_object_handle_test.cpp dataspace_object_handle_test.cpp group_object_handle_test.cpp dataset_object_handle_test.cpp attribute_object_handle_test.cpp property_objects_handle_test.cpp error_objects_handle_test.cpp fixed_length_string_test.cpp test_environment.cpp iteration_index_test.cpp iteration_order_test.cpp object_id_test.cpp iterator_test.cpp path_test.cpp version_test.cpp) add_executable(core_test ${test_sources}) ```