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
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
* 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
});
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(),
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;
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<hid_t>(new hid_t, [](auto pointer) {
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;
- 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
{
// 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;
{
// 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<float>("root_float");
auto root_double = data_file.get_attribute<double>("root_double");
auto root_int = data_file.get_attribute<int>("root_int");
{
HDF5::File data_file(filename,
- mpi_communicator,
- HDF5::File::FileAccessMode::create);
+ HDF5::File::FileAccessMode::create,
+ mpi_communicator);
write_test<std::vector, float>(data_file,
dataset_dimensions,
{
HDF5::File data_file(filename,
- mpi_communicator,
- HDF5::File::FileAccessMode::open);
+ HDF5::File::FileAccessMode::open,
+ mpi_communicator);
read_test<std::vector, float>(data_file, mpi_communicator, pcout);
read_test<std::vector, double>(data_file, mpi_communicator, pcout);
{
HDF5::File data_file(filename,
- mpi_communicator,
- HDF5::File::FileAccessMode::create);
+ HDF5::File::FileAccessMode::create,
+ mpi_communicator);
write_test<float>(data_file, mpi_communicator, pcout);
write_test<double>(data_file, mpi_communicator, pcout);
{
HDF5::File data_file(filename,
- mpi_communicator,
- HDF5::File::FileAccessMode::open);
+ HDF5::File::FileAccessMode::open,
+ mpi_communicator);
read_test<float>(data_file, mpi_communicator, pcout);
read_test<double>(data_file, mpi_communicator, pcout);