36#include "AbstractHdf5Converter.hpp"
43herr_t op_func (hid_t loc_id,
45 const H5L_info_t *info,
49template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
51 const std::string& rFileBaseName,
53 const std::string& rSubdirectoryName,
55 : mrH5Folder(rInputDirectory),
56 mFileBaseName(rFileBaseName),
59 mRelativeSubdirectory(rSubdirectoryName),
71template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
77 std::string time_info_filename;
81 if (mDatasetNames[mOpenDatasetIndex]==
"Data")
83 time_info_filename = mFileBaseName +
"_times.info";
87 time_info_filename = mDatasetNames[mOpenDatasetIndex] +
"_times.info";
89 out_stream p_file = mpOutputFileHandler->OpenOutputFile(time_info_filename);
91 std::vector<double> time_values = mpReader->GetUnlimitedDimensionValues();
92 unsigned num_timesteps = time_values.size();
93 double first_timestep = time_values.front();
94 double last_timestep = time_values.back();
96 double timestep = num_timesteps > 1 ? time_values[1] - time_values[0] :
DOUBLE_UNSET;
98 *p_file <<
"Number of timesteps " << num_timesteps << std::endl;
99 *p_file <<
"timestep " << timestep << std::endl;
100 *p_file <<
"First timestep " << first_timestep << std::endl;
101 *p_file <<
"Last timestep " << last_timestep << std::endl;
108template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
111 delete mpOutputFileHandler;
114template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
117 return mRelativeSubdirectory;
120template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
124 if (mDatasetNames.size() == mOpenDatasetIndex+1u)
132 mOpenDatasetIndex = 0u;
140 mpReader.reset(
new Hdf5DataReader(mrH5Folder, mFileBaseName, mDatasetNames[mOpenDatasetIndex]));
143 std::vector<std::string> variable_names = mpReader->GetVariableNames();
144 mNumVariables = variable_names.size();
146 if (mpReader->GetNumberOfRows() != mpMesh->GetNumNodes())
148 delete mpOutputFileHandler;
149 EXCEPTION(
"Mesh and HDF5 file have a different number of nodes");
156template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
158 const std::string& rFileName)
163 std::string file_name = rH5Folder.
GetAbsolutePath() + rFileName +
".h5";
164 hid_t file = H5Fopen(file_name.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
169 H5Literate(file, H5_INDEX_NAME, H5_ITER_NATIVE,
nullptr, op_func, &mDatasetNames);
174 std::string ending =
"_Unlimited";
177 std::vector<std::string>::iterator iter;
178 for (iter = mDatasetNames.begin(); iter != mDatasetNames.end(); )
184 if ((*(iter) ==
"Time") ||
185 ((iter->length() > ending.length()) &&
186 (0 == iter->compare(iter->length() - ending.length(), ending.length(), ending))))
188 iter = mDatasetNames.erase(iter);
206herr_t op_func (hid_t loc_id,
const char *name,
207 const H5L_info_t *info,
210 std::vector<std::string>* p_dataset_names =
static_cast<std::vector< std::string > *
>(operator_data);
218 H5Oget_info_by_name (loc_id, name, &infobuf, H5P_DEFAULT);
219 switch (infobuf.type)
224 case H5O_TYPE_DATASET:
225 p_dataset_names->push_back(name);
const double DOUBLE_UNSET
#define EXCEPTION(message)
const unsigned UNSIGNED_UNSET
std::string mFileBaseName
std::string GetSubdirectory()
OutputFileHandler * mpOutputFileHandler
AbstractHdf5Converter(const FileFinder &rInputDirectory, const std::string &rFileBaseName, AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > *pMesh, const std::string &rSubdirectoryName, unsigned precision)
const FileFinder & mrH5Folder
bool MoveOntoNextDataset()
std::string mRelativeSubdirectory
void GenerateListOfDatasets(const FileFinder &rH5Folder, const std::string &rFileName)
static std::string GetProvenanceString()
std::string GetAbsolutePath() const