首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取HDF5数据集的维度

获取HDF5数据集的维度
EN

Stack Overflow用户
提问于 2013-04-03 19:53:22
回答 1查看 9.4K关注 0票数 10

我在我的C++程序中使用了一些HDF5文件,我有一个关于H5Dopen函数的问题。可以在给定文件中获取hdf5数据集的维度吗?

代码语言:javascript
复制
hid_t file, dset;
herr_t status;
file = H5Fopen (filenameField, H5F_ACC_RDONLY, H5P_DEFAULT);
dset = H5Dopen (file, "/xField", H5P_DEFAULT);

在我做下一行之前,我想要得到dset的尺寸。

代码语言:javascript
复制
status = H5Dread (dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,  &readBuf[0]);

我只找到了H5Dget_storage_size,但它不适合我的情况。

有人知道怎么做吗?

EN

回答 1

Stack Overflow用户

发布于 2018-04-19 16:19:12

或者,这可以像这样完成(对于简单的数据空间,请参阅Simons answer,如有必要,请使用bool H5::DataSpace::isSimple() const进行检查):

代码语言:javascript
复制
  #include "H5Cpp.h"
  using namespace H5;
  //[...]
  DataSpace dataspace(RANK, dims);
  //[...]
  /*
   * Get the number of dimensions in the dataspace.
   */
  const int rank = dataspace.getSimpleExtentNdims();

这一行在大多数情况下可能是多余的,因为整个任务可以在两行中完成:

代码语言:javascript
复制
  /*
   * 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 manualexamples page (readdata.cpp)。

h5c++编译所有的东西,它应该可以工作。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15786626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档