From: Daniel Garcia-Sanchez Date: Wed, 31 Oct 2018 15:57:44 +0000 (+0100) Subject: Reorder parameters X-Git-Tag: v9.1.0-rc1~453^2~15 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cdfc5f609d6b5291ad724b5de61eb34d9b2d020c;p=dealii.git Reorder parameters --- diff --git a/include/deal.II/base/hdf5.h b/include/deal.II/base/hdf5.h index 52c0ed048c..bed7681555 100644 --- a/include/deal.II/base/hdf5.h +++ b/include/deal.II/base/hdf5.h @@ -923,13 +923,13 @@ namespace HDF5 enum class GroupAccessMode { /** - * Creates a new group + * Opens an existing group */ - create, + open, /** - * Opens an existing group + * Creates a new group */ - open + create }; /** * This constructor creates or opens a group depending on the value of @@ -1021,29 +1021,22 @@ namespace HDF5 enum class FileAccessMode { /** - * Create file, truncate if exists + * Read/write, file must exist */ - create, + open, /** - * Read/write, file must exist + * Create file, truncate if exists */ - open + create }; - private: /** - * Delegation internal constructor. - * File(const std::string &, const MPI_Comm, const Mode); - * and - * File(const std::string &, const Mode) - * should be used to open or create HDF5 files. + * Creates or opens a hdf5 file for serial operations. This call does not + * require MPI support. It creates or opens a HDF5 file depending on the + * value of @p mode. */ - File(const std::string & name, - const bool mpi, - const MPI_Comm mpi_communicator, - const FileAccessMode mode); + File(const std::string &name, const FileAccessMode mode); - public: /** * Creates or opens an HDF5 file in parallel using MPI. This requires that * deal.ii and HDF5 were compiled with MPI support. It creates or opens a @@ -1052,16 +1045,21 @@ namespace HDF5 * a common value for the MPI communicator. */ File(const std::string & name, - const MPI_Comm mpi_communicator, - const FileAccessMode mode = FileAccessMode::create); + const FileAccessMode mode, + const MPI_Comm mpi_communicator); + private: /** - * Creates or opens a hdf5 file for serial operations. This call does not - * require MPI support. It creates or opens a HDF5 file depending on the - * value of @p mode. + * Delegation internal constructor. + * File(const std::string &, const MPI_Comm, const Mode); + * and + * File(const std::string &, const Mode) + * should be used to open or create HDF5 files. */ File(const std::string & name, - const FileAccessMode mode = FileAccessMode::create); + const FileAccessMode mode, + const bool mpi, + const MPI_Comm mpi_communicator); }; } // namespace HDF5 diff --git a/source/base/hdf5.cc b/source/base/hdf5.cc index 873f7cb0ae..17013e6b39 100644 --- a/source/base/hdf5.cc +++ b/source/base/hdf5.cc @@ -1461,6 +1461,11 @@ namespace HDF5 }); switch (mode) { + case (GroupAccessMode::open): + *hdf5_reference = + H5Gopen2(*(parentGroup.hdf5_reference), name.data(), H5P_DEFAULT); + Assert(*hdf5_reference >= 0, ExcMessage("Error at H5Gopen2")); + break; case (GroupAccessMode::create): *hdf5_reference = H5Gcreate2(*(parentGroup.hdf5_reference), name.data(), @@ -1469,11 +1474,6 @@ namespace HDF5 H5P_DEFAULT); Assert(*hdf5_reference >= 0, ExcMessage("Error at H5Gcreate2")); break; - case (GroupAccessMode::open): - *hdf5_reference = - H5Gopen2(*(parentGroup.hdf5_reference), name.data(), H5P_DEFAULT); - Assert(*hdf5_reference >= 0, ExcMessage("Error at H5Gopen2")); - break; default: Assert(false, ExcInternalError()); break; @@ -1533,10 +1533,26 @@ namespace HDF5 dataset.write(data); } + + + File::File(const std::string &name, const FileAccessMode mode) + : File(name, mode, false, MPI_COMM_NULL) + {} + + + + File::File(const std::string & name, + const FileAccessMode mode, + const MPI_Comm mpi_communicator) + : File(name, mode, true, mpi_communicator) + {} + + + File::File(const std::string & name, + const FileAccessMode mode, const bool mpi, - const MPI_Comm mpi_communicator, - const FileAccessMode mode) + const MPI_Comm mpi_communicator) : Group(name, mpi) { hdf5_reference = std::shared_ptr(new hid_t, [](auto pointer) { @@ -1569,15 +1585,15 @@ namespace HDF5 switch (mode) { + case (FileAccessMode::open): + *hdf5_reference = H5Fopen(name.data(), H5F_ACC_RDWR, plist); + Assert(*hdf5_reference >= 0, ExcMessage("Error at H5Fopen")); + break; case (FileAccessMode::create): *hdf5_reference = H5Fcreate(name.data(), H5F_ACC_TRUNC, H5P_DEFAULT, plist); Assert(*hdf5_reference >= 0, ExcMessage("Error at H5Fcreate")); break; - case (FileAccessMode::open): - *hdf5_reference = H5Fopen(name.data(), H5F_ACC_RDWR, plist); - Assert(*hdf5_reference >= 0, ExcMessage("Error at H5Fopen")); - break; default: Assert(false, ExcInternalError()); break; @@ -1595,20 +1611,6 @@ namespace HDF5 - File::File(const std::string & name, - const MPI_Comm mpi_communicator, - const FileAccessMode mode) - : File(name, true, mpi_communicator, mode) - {} - - - - File::File(const std::string &name, const FileAccessMode mode) - : File(name, false, MPI_COMM_NULL, mode) - {} - - - # ifndef DOXYGEN // instantiations of functions diff --git a/tests/base/hdf5_02.cc b/tests/base/hdf5_02.cc index dc4686dc0f..80df31b075 100644 --- a/tests/base/hdf5_02.cc +++ b/tests/base/hdf5_02.cc @@ -30,8 +30,8 @@ test() { // Create file HDF5::File data_file(filename, - MPI_COMM_WORLD, - HDF5::File::FileAccessMode::create); + HDF5::File::FileAccessMode::create, + MPI_COMM_WORLD); // Create attributes attached to the root const float root_float = 2.45681934e5; @@ -76,8 +76,8 @@ test() { // Read attributes attached to the root HDF5::File data_file(filename, - MPI_COMM_WORLD, - HDF5::File::FileAccessMode::open); + HDF5::File::FileAccessMode::open, + MPI_COMM_WORLD); auto root_float = data_file.get_attribute("root_float"); auto root_double = data_file.get_attribute("root_double"); auto root_int = data_file.get_attribute("root_int"); diff --git a/tests/base/hdf5_03.cc b/tests/base/hdf5_03.cc index a19402fd3f..25a5196c5f 100644 --- a/tests/base/hdf5_03.cc +++ b/tests/base/hdf5_03.cc @@ -770,8 +770,8 @@ main(int argc, char **argv) { HDF5::File data_file(filename, - mpi_communicator, - HDF5::File::FileAccessMode::create); + HDF5::File::FileAccessMode::create, + mpi_communicator); write_test(data_file, dataset_dimensions, @@ -844,8 +844,8 @@ main(int argc, char **argv) { HDF5::File data_file(filename, - mpi_communicator, - HDF5::File::FileAccessMode::open); + HDF5::File::FileAccessMode::open, + mpi_communicator); read_test(data_file, mpi_communicator, pcout); read_test(data_file, mpi_communicator, pcout); diff --git a/tests/base/hdf5_05.cc b/tests/base/hdf5_05.cc index 4aa0723995..76f3658a3d 100644 --- a/tests/base/hdf5_05.cc +++ b/tests/base/hdf5_05.cc @@ -1409,8 +1409,8 @@ main(int argc, char **argv) { HDF5::File data_file(filename, - mpi_communicator, - HDF5::File::FileAccessMode::create); + HDF5::File::FileAccessMode::create, + mpi_communicator); write_test(data_file, mpi_communicator, pcout); write_test(data_file, mpi_communicator, pcout); @@ -1423,8 +1423,8 @@ main(int argc, char **argv) { HDF5::File data_file(filename, - mpi_communicator, - HDF5::File::FileAccessMode::open); + HDF5::File::FileAccessMode::open, + mpi_communicator); read_test(data_file, mpi_communicator, pcout); read_test(data_file, mpi_communicator, pcout);