获取HDF5数据集的维度
Get the dimensions of a HDF5 dataset
我在我的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
,但那不适合我的情况。
有人知道怎么做吗?
为此,您需要使用以H5S为前缀的dataspace函数。
HDF5参考手册是使用这些前缀组织的,因此它有助于理解。
如何获取数据集的维度
首先,您需要使用H5Dget_space
:
hid_t dspace = H5Dget_space(dset);
如果你的数据空间是简单的(即不是null或标量),那么你可以使用H5Sget_simple_extent_ndims
:
const int ndims = H5Sget_simple_extent_ndims(dspace);
和每个维度的大小使用H5Sget_simple_extent_dims
:
hsize_t dims[ndims];
H5Sget_simple_extent_dims(dspace, dims, NULL);
尺寸现在存储在dims
中
或者,可以这样做(如果是简单的数据空间,请参阅Simons的回答,必要时请使用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);
函数getSimpleExtentNdims()
可以作为H5::DataSpace
实例的成员调用。
这些代码片段取自最新的hdf5c++参考手册的示例页(readdata.cpp)。
用h5c++
编译所有内容,它应该可以工作。
相关文章:
- 如何实现高效的算法来计算大型数据集的多个不同值?
- HDF5Cpp 扩展复合数据集超板问题
- HDF5 简单读取数据集失败
- C++创建空 HDF5 文件而不是数据集的代码
- 用于创建 HDF5 数据集的 4 维 c++ 数组的动态内存分配
- 一个HDF5文件中有多少个数据集
- 计算用于CAFFE分类的HDF5数据集的平均值
- HDF5 重新缩放数据集最大维度
- 如何从C 中的HDF5文件中读取属性名称和数据集名称,在这里我不知道HDF5文件中存在什么属性
- Armadillo:在一个hdf5文件中保存多个数据集
- 使用 OpenMPI 创建 HDF5 文件和数据集
- 打开hdf5字符串数据集
- HDF5:将线性数组保存到三维数据集
- 将boost::multi_array写入hdf5数据集
- 如何用C++将字符串附加到HDF5数据集
- 在并行HDF5中创建可扩展数据集
- HDF5 c++:我需要得到组列表,数据集列表,属性列表在HDF5文件
- 获取HDF5数据集的维度
- 写一个逗号分隔的字符串属性到HDF5数据集c++
- 如何找出一个数据集的PredType在HDF5使用c++库