Commit 975536e3 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Enable flexibility in specifying dimensionality of light data description.

Previously, for HDF5 datasets, the number of dimensions in the light data
description had to match the number of dimensions in the heavy data file in
order to properly select a hyperslab. To support older files and be more
flexible, we now allow the number of dimensions to be different as long as
we are reading the entire dataset.
parent 0e3f8a56
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
/*****************************************************************************/ /*****************************************************************************/
#include <hdf5.h> #include <hdf5.h>
#include <numeric>
#include <sstream> #include <sstream>
#include "XdmfArray.hpp" #include "XdmfArray.hpp"
#include "XdmfArrayType.hpp" #include "XdmfArrayType.hpp"
...@@ -173,13 +174,35 @@ XdmfHDF5Controller::read(XdmfArray * const array, const int fapl) ...@@ -173,13 +174,35 @@ XdmfHDF5Controller::read(XdmfArray * const array, const int fapl)
mOpenFileUsage[mFilePath]++; mOpenFileUsage[mFilePath]++;
} }
} }
hid_t dataset = H5Dopen(hdf5Handle, mDataSetPath.c_str(), H5P_DEFAULT);
hid_t dataspace = H5Dget_space(dataset);
std::vector<hsize_t> start(mStart.begin(), mStart.end()); const hid_t dataset = H5Dopen(hdf5Handle, mDataSetPath.c_str(), H5P_DEFAULT);
std::vector<hsize_t> stride(mStride.begin(), mStride.end()); const hid_t dataspace = H5Dget_space(dataset);
std::vector<hsize_t> count(mDimensions.begin(), mDimensions.end());
const unsigned int dataspaceDims = H5Sget_simple_extent_ndims(dataspace);
const std::vector<hsize_t> count(mDimensions.begin(), mDimensions.end());
if(dataspaceDims != mDimensions.size()) {
// special case where the number of dimensions of the hdf5 dataset
// does not equal the number of dimensions in the light data
// description - in this case we cannot properly take a hyperslab
// selection, so we assume we are reading the entire dataset and
// check whether that is ok to do
const int numberValuesHDF5 = H5Sget_select_npoints(dataspace);
const int numberValuesXdmf =
std::accumulate(mDimensions.begin(),
mDimensions.end(),
1,
std::multiplies<unsigned int>());
if(numberValuesHDF5 != numberValuesXdmf) {
XdmfError::message(XdmfError::FATAL,
"Number of dimensions in light data description in "
"Xdmf does not match number of dimensions in hdf5 "
"file.");
}
}
else {
const std::vector<hsize_t> start(mStart.begin(), mStart.end());
const std::vector<hsize_t> stride(mStride.begin(), mStride.end());
status = H5Sselect_hyperslab(dataspace, status = H5Sselect_hyperslab(dataspace,
H5S_SELECT_SET, H5S_SELECT_SET,
...@@ -187,8 +210,9 @@ XdmfHDF5Controller::read(XdmfArray * const array, const int fapl) ...@@ -187,8 +210,9 @@ XdmfHDF5Controller::read(XdmfArray * const array, const int fapl)
&stride[0], &stride[0],
&count[0], &count[0],
NULL); NULL);
hssize_t numVals = H5Sget_select_npoints(dataspace); }
const hssize_t numVals = H5Sget_select_npoints(dataspace);
hid_t memspace = H5Screate_simple(mDimensions.size(), hid_t memspace = H5Screate_simple(mDimensions.size(),
&count[0], &count[0],
NULL); NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment