Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "MOR_Hdf5MVInputFile.hpp"
00007
00008 #include "Epetra_Comm.h"
00009
00010 #include "EpetraExt_HDF5.h"
00011
00012 #include "Teuchos_TestForException.hpp"
00013 #include "Teuchos_Assert.hpp"
00014
00015 #include <stdexcept>
00016 #include <cstddef>
00017
00018 namespace MOR {
00019
00020 namespace Detail {
00021
00022 #ifdef HAVE_EPETRAEXT_HDF5
00023 void openReadOnlyAndCheckGroupName(
00024 EpetraExt::HDF5 &handle,
00025 const std::string &path,
00026 const std::string &groupName)
00027 {
00028 handle.Open(path, H5F_ACC_RDONLY);
00029
00030 TEUCHOS_TEST_FOR_EXCEPTION(!handle.IsOpen(),
00031 std::runtime_error,
00032 "Cannot open input file: " + path);
00033
00034 TEUCHOS_TEST_FOR_EXCEPTION(!handle.IsContained(groupName),
00035 std::runtime_error,
00036 "Cannot find source group name :" + groupName + " in file: " + path);
00037 }
00038 #endif
00039
00040 }
00041
00042
00043 Hdf5MVInputFile::Hdf5MVInputFile(const std::string &path,
00044 const std::string &groupName) :
00045 MultiVectorInputFile(path),
00046 groupName_(groupName)
00047 {
00048
00049 }
00050
00051 int Hdf5MVInputFile::readVectorCount(const Epetra_Comm &comm)
00052 {
00053 #ifdef HAVE_EPETRAEXT_HDF5
00054 EpetraExt::HDF5 hdf5Input(comm);
00055 Detail::openReadOnlyAndCheckGroupName(hdf5Input, this->path(), groupName_);
00056
00057 int result, dummy;
00058 hdf5Input.ReadMultiVectorProperties(groupName_, dummy, result);
00059
00060 hdf5Input.Close();
00061
00062 return result;
00063 #else
00064 throw std::logic_error("HDF5 support disabled");
00065 #endif
00066 }
00067
00068 Teuchos::RCP<Epetra_MultiVector> Hdf5MVInputFile::read(const Epetra_Map &map)
00069 {
00070 #ifdef HAVE_EPETRAEXT_HDF5
00071 EpetraExt::HDF5 hdf5Input(map.Comm());
00072 Detail::openReadOnlyAndCheckGroupName(hdf5Input, this->path(), groupName_);
00073
00074
00075
00076 Epetra_MultiVector *raw_result = NULL;
00077 hdf5Input.Read(groupName_, map, raw_result);
00078
00079
00080 Teuchos::RCP<Epetra_MultiVector> result = Teuchos::rcp(raw_result);
00081
00082 hdf5Input.Close();
00083
00084 TEUCHOS_TEST_FOR_EXCEPT(result.is_null());
00085 return result;
00086 #else
00087 throw std::logic_error("HDF5 support disabled");
00088 #endif
00089 }
00090
00091 }