一个HDF5文件中有多少个数据集
How many datasets in one hdf5 file
我正在使用MATLAB的函数H5Write将Double变量foo
写入称为saved_foos.h5
的HDF5文件。我有一个循环,可以在每次迭代中更改foo
,并且每次将其保存在同一HDF5文件中,但在另一个数据集中,该数据集是根据当前迭代次数命名的。
之后,我在带有H5Cpp
库的C 程序中读取了每个数据集(EAACH迭代(的数据,如下所示:
#include "H5Cpp.h"
using namespace H5;
double readDouble(std::string dir, std::string file, std::string s_dataset) {
if (!fexists((dir + file + std::string(".h5")).c_str())) {
throw std::runtime_error((std::string("File ") + dir + file + std::string(".h5 does not exist.")).c_str());
}
H5File file_h(dir + file + std::string(".h5"), H5F_ACC_RDONLY);
DataSet dataset = file_h.openDataSet(s_dataset);
DataSpace dataspace = dataset.getSpace();
int rank = dataspace.getSimpleExtentNdims();
hsize_t *dims_out = new hsize_t[rank];
dataspace.getSimpleExtentDims(dims_out, NULL);
if (rank>=2 && (dims_out[0] * dims_out[1] != 1)) {
throw std::runtime_error("Requested dataset is not a scalar double value.");
}
double data;
dataset.read(&data, PredType::NATIVE_DOUBLE);
delete dims_out;
return data;
}
但是如何确定在给定的HDF5文件中存储了多少个数据集?
遍历文件
似乎您要列出文件中的数据集。这是一个非常完整的示例,这是您问题的过度杀伤。为了帮助理解它,我将解释相关的代码会话:
C-API函数H5Literate
用于迭代组中的所有对象。
/*
* Use iterator to see the names of the objects in the file
* root directory.
*/
cout << endl << "Iterating over elements in the file" << endl;
herr_t idx = H5Literate(file->getId(), H5_INDEX_NAME, H5_ITER_INC, NULL, file_info, NULL);
cout << endl;
其中 file_info
是回调函数:
/*
* Operator function.
*/
herr_t
file_info(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *opdata)
{
hid_t group;
group = H5Gopen2(loc_id, name, H5P_DEFAULT);
cout << "Name : " << name << endl; // Display the group name.
H5Gclose(group);
return 0;
}
在您的情况下,其他迭代功能而不是H5Literate
可能更合适。请在这里找到。一个纯C-API示例,可以在此处找到遍历文件。
只获取数字
如果所有数据集都存储在根下,并且其名称的格式已知。有一个更简单的解决方案仅获取数据集数量:
hsize_t num_obj;
H5Gget_num_objs(file->getId(), &num_obj); // if success, num_obj will be assigned the number of objects in the group
相关文章:
- 如何实现高效的算法来计算大型数据集的多个不同值?
- HDF5Cpp 扩展复合数据集超板问题
- HDF5 简单读取数据集失败
- std::bad_alloc 在大数据集的 Dijkstra 计算期间
- C++中的多维数据集:从 std::vector 的 2D 数据到 std::vector 的 2D 网格的最干净方法?
- C++创建空 HDF5 文件而不是数据集的代码
- 跨线程共享数据集与拆分每个线程的数据
- 多维数据集ai中的ai_float是什么
- 适用于频繁更改的大型数据集的最佳数据结构
- 将数据集从 R 传递到C++(使用 .呼叫)
- 将数据集几乎平均分配给工作线程
- 我将 c++ 矢量数据集转换为 c 数组.我将相同的数据集传递到一个应该给出相同输出的函数中
- 使用 194 点海伦数据集训练 DLib 形状预测器
- 现代 OpenGL 多维数据集旋转未按预期工作
- 我可以通过命令行参数传递给C++程序多少数据?
- 数据集(和样本)何时在 boost::test 中销毁?
- 从数据集 Blob 字段中打开和编辑文件
- 用于创建 HDF5 数据集的 4 维 c++ 数组的动态内存分配
- OpenGL 第一个多维数据集渲染不起作用
- 一个HDF5文件中有多少个数据集