36 #include "AbstractHdf5Converter.hpp"
37 #include "Version.hpp"
43 herr_t op_func (hid_t loc_id,
45 #
if H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >=8
46 const H5L_info_t *info,
51 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
53 const std::string& rFileBaseName,
55 const std::string& rSubdirectoryName,
57 : mrH5Folder(rInputDirectory),
58 mFileBaseName(rFileBaseName),
61 mRelativeSubdirectory(rSubdirectoryName),
73 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
79 std::string time_info_filename;
83 if (mDatasetNames[mOpenDatasetIndex]==
"Data")
85 time_info_filename = mFileBaseName +
"_times.info";
89 time_info_filename = mDatasetNames[mOpenDatasetIndex] +
"_times.info";
91 out_stream p_file = mpOutputFileHandler->OpenOutputFile(time_info_filename);
93 std::vector<double> time_values = mpReader->GetUnlimitedDimensionValues();
94 unsigned num_timesteps = time_values.size();
95 double first_timestep = time_values.front();
96 double last_timestep = time_values.back();
98 double timestep = num_timesteps > 1 ? time_values[1] - time_values[0] :
DOUBLE_UNSET;
100 *p_file <<
"Number of timesteps " << num_timesteps << std::endl;
101 *p_file <<
"timestep " << timestep << std::endl;
102 *p_file <<
"First timestep " << first_timestep << std::endl;
103 *p_file <<
"Last timestep " << last_timestep << std::endl;
110 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
113 delete mpOutputFileHandler;
116 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
119 return mRelativeSubdirectory;
122 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
126 if (mDatasetNames.size() == mOpenDatasetIndex+1u)
134 mOpenDatasetIndex = 0u;
142 mpReader.reset(
new Hdf5DataReader(mrH5Folder, mFileBaseName, mDatasetNames[mOpenDatasetIndex]));
145 std::vector<std::string> variable_names = mpReader->GetVariableNames();
146 mNumVariables = variable_names.size();
148 if (mpReader->GetNumberOfRows() != mpMesh->GetNumNodes())
150 delete mpOutputFileHandler;
151 EXCEPTION(
"Mesh and HDF5 file have a different number of nodes");
158 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
160 const std::string& rFileName)
165 std::string file_name = rH5Folder.
GetAbsolutePath() + rFileName +
".h5";
166 hid_t file = H5Fopen(file_name.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
171 #if H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >=8
173 H5Literate(file, H5_INDEX_NAME, H5_ITER_NATIVE, NULL, op_func, &mDatasetNames);
176 H5Giterate(file,
"/", NULL, op_func, &mDatasetNames);
182 std::string ending =
"_Unlimited";
185 std::vector<std::string>::iterator iter;
186 for (iter = mDatasetNames.begin(); iter != mDatasetNames.end(); )
192 if ( (*(iter) ==
"Time") ||
193 ( ( iter->length() > ending.length() ) &&
194 ( 0 == iter->compare(iter->length() - ending.length(), ending.length(), ending) ) ) )
196 iter = mDatasetNames.erase(iter);
214 herr_t op_func (hid_t loc_id,
const char *name,
215 #
if H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >=8
216 const H5L_info_t *info,
220 std::vector<std::string>* p_dataset_names =
static_cast<std::vector< std::string > *
>(operator_data);
227 #if H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >=8
229 H5Oget_info_by_name (loc_id, name, &infobuf, H5P_DEFAULT);
230 switch (infobuf.type)
235 case H5O_TYPE_DATASET:
236 p_dataset_names->push_back(name);
243 H5Gget_objinfo (loc_id, name, 0, &statbuf);
244 switch (statbuf.type)
251 p_dataset_names->push_back(name);
std::string mFileBaseName
std::string mRelativeSubdirectory
std::string GetAbsolutePath() const
#define EXCEPTION(message)
OutputFileHandler * mpOutputFileHandler
const FileFinder & mrH5Folder
const double DOUBLE_UNSET
const unsigned UNSIGNED_UNSET
std::string GetSubdirectory()
AbstractHdf5Converter(const FileFinder &rInputDirectory, const std::string &rFileBaseName, AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > *pMesh, const std::string &rSubdirectoryName, unsigned precision)
bool MoveOntoNextDataset()
static std::string GetProvenanceString()
void GenerateListOfDatasets(const FileFinder &rH5Folder, const std::string &rFileName)