我在我的C++程序中使用了一些HDF5文件,我有一个关于H5Dopen函数的问题。可以在给定文件中获取hdf5数据集的维度吗?
hid_t file, dset;
herr_t status;
file = H5Fopen (filenameField, H5F_ACC_RDONLY, H5P_DEFAULT);
dset = H5Dopen (file, "/xField", H5P_DEFAULT);在我做下一行之前,我想要得到dset的尺寸。
status = H5Dread (dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &readBuf[0]);我只找到了H5Dget_storage_size,但它不适合我的情况。
有人知道怎么做吗?
发布于 2018-04-19 16:19:12
或者,这可以像这样完成(对于简单的数据空间,请参阅Simons answer,如有必要,请使用bool H5::DataSpace::isSimple() const进行检查):
#include "H5Cpp.h"
using namespace H5;
//[...]
DataSpace dataspace(RANK, dims);
//[...]
/*
* Get the number of dimensions in the dataspace.
*/
const int rank = dataspace.getSimpleExtentNdims();这一行在大多数情况下可能是多余的,因为整个任务可以在两行中完成:
/*
* Get the dimension size of each dimension in the dataspace and
* store the dimentionality in ndims.
*/
hsize_t dims_out[rank];
const int ndims = dataspace.getSimpleExtentDims( dims_out, NULL);可以作为H5::DataSpace实例的成员调用函数getSimpleExtentNdims()。
这些代码片段取自较新的HDF5 C++ reference manual的examples page (readdata.cpp)。
用h5c++编译所有的东西,它应该可以工作。
https://stackoverflow.com/questions/15786626
复制相似问题