From: Daniel Garcia-Sanchez Date: Sat, 3 Apr 2021 19:15:01 +0000 (+0200) Subject: Write test hdf5_07 X-Git-Tag: v9.3.0-rc1~237^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73432255b11c55a5a4939d6cbe9382e3752fa223;p=dealii.git Write test hdf5_07 --- diff --git a/tests/base/hdf5_07.cc b/tests/base/hdf5_07.cc new file mode 100644 index 0000000000..fc97b56649 --- /dev/null +++ b/tests/base/hdf5_07.cc @@ -0,0 +1,131 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2015 - 2019 by the deal.II Authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + +// Test bool with parallel HDF5 +// This test is based on tests/base/hdf5_02.cc + +#include + +#include "../tests.h" + +// all include files you need here + +void +test() +{ + std::string filename = "test.h5"; + + MPI_Comm mpi_communicator = MPI_COMM_WORLD; + + // Write data + { + // Create file + HDF5::File data_file(filename, + HDF5::File::FileAccessMode::create, + mpi_communicator); + + // Create attributes attached to the root + data_file.set_attribute("root_true", true); + data_file.set_attribute("root_false", false); + + // Create attributes attached to a group + auto group = data_file.create_group("test_group"); + + group.set_attribute("group_true", true); + group.set_attribute("group_false", false); + + + + std::string dataset_name("test_dataset"); + + + const std::vector dataset_dimensions = {2, 5, 3}; + auto dataset = + group.template create_dataset(dataset_name, dataset_dimensions); + + + dataset.set_attribute("dataset_true", true); + dataset.set_attribute("dataset_false", false); + } + + // Read data + { + // Read attributes attached to the root + HDF5::File data_file(filename, + HDF5::File::FileAccessMode::open, + mpi_communicator); + auto root_true = data_file.get_attribute("root_true"); + auto root_false = data_file.get_attribute("root_false"); + deallog << "root_true:" << root_true << std::endl; + deallog << "root_false:" << root_false << std::endl; + + // Read attributes attached to a group + auto test_group = data_file.open_group("test_group"); + deallog << "group_name: " << test_group.get_name() << std::endl; + auto group_true = test_group.get_attribute("group_true"); + auto group_false = test_group.get_attribute("group_false"); + deallog << "group_true:" << group_true << std::endl; + deallog << "group_false:" << group_false << std::endl; + + // Read attributes attached to a dataset + auto test_dataset = test_group.open_dataset("test_dataset"); + deallog << "dataset_name: " << test_dataset.get_name() << std::endl; + auto dataset_true = test_dataset.get_attribute("dataset_true"); + auto dataset_false = test_dataset.get_attribute("dataset_false"); + deallog << "dataset_true:" << dataset_true << std::endl; + deallog << "dataset_false:" << dataset_false << std::endl; + } +} + + + +int +main(int argc, char **argv) +{ + initlog(); + + try + { + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + + test(); + } + catch (std::exception &exc) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +} diff --git a/tests/base/hdf5_07.with_hdf5=true.mpirun=1.output b/tests/base/hdf5_07.with_hdf5=true.mpirun=1.output new file mode 100644 index 0000000000..272c63d20e --- /dev/null +++ b/tests/base/hdf5_07.with_hdf5=true.mpirun=1.output @@ -0,0 +1,9 @@ + +DEAL::root_true:1 +DEAL::root_false:0 +DEAL::group_name: test_group +DEAL::group_true:1 +DEAL::group_false:0 +DEAL::dataset_name: test_dataset +DEAL::dataset_true:1 +DEAL::dataset_false:0 diff --git a/tests/base/hdf5_07.with_hdf5=true.mpirun=4.output b/tests/base/hdf5_07.with_hdf5=true.mpirun=4.output new file mode 100644 index 0000000000..272c63d20e --- /dev/null +++ b/tests/base/hdf5_07.with_hdf5=true.mpirun=4.output @@ -0,0 +1,9 @@ + +DEAL::root_true:1 +DEAL::root_false:0 +DEAL::group_name: test_group +DEAL::group_true:1 +DEAL::group_false:0 +DEAL::dataset_name: test_dataset +DEAL::dataset_true:1 +DEAL::dataset_false:0