【问题标题】:Can't write HDF5 file with vector bigger than 2^13无法写入向量大于 2^13 的 HDF5 文件
【发布时间】:2013-06-10 19:48:01
【问题描述】:

我正在使用 C++ 和 HDF5 来编写文件。但是遇到了问题。这是我使用的代码:

void fileRead::writeFile(string name, const vector<double>* data) {
int dimn = data->size();

hsize_t dim[1] = {data->size()}; //-> 2^13!!!

hid_t sid = H5Pcreate(H5P_DATASET_CREATE);
hid_t didProp = H5Screate_simple(1,dim,NULL);
H5Pset_layout(sid, H5D_COMPACT);

hid_t did = H5Dcreate(fid, name.c_str(),H5T_IEEE_F64LE, didProp, H5P_DEFAULT, sid,H5P_DEFAULT);
H5Dwrite (did, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &(data->at(0)));
H5Dclose(did);

H5Sclose(didProp);
H5Pclose(sid);
}

但这给了我这个错误信息:

HDF5-DIAG: Error detected in HDF5 (1.8.10) thread 0:   #000: /pub/devel/hdf5/hdf5-1.8.10-1/src/hdf5-1.8.10/src/H5D.c line 170 in H5Dcreate2(): unable to create dataset
    major: Dataset
    minor: Unable to initialize object   #001: /pub/devel/hdf5/hdf5-1.8.10-1/src/hdf5-1.8.10/src/H5Dint.c line 439 in H5D__create_named(): unable to create and link to dataset
    major: Dataset
    minor: Unable to initialize object   #002: /pub/devel/hdf5/hdf5-1.8.10-1/src/hdf5-1.8.10/src/H5L.c line 1638 in H5L_link_object(): unable to create new link to object
    major: Links
    minor: Unable to initialize object   #003: /pub/devel/hdf5/hdf5-1.8.10-1/src/hdf5-1.8.10/src/H5L.c line 1882 in H5L_create_real(): can't insert link
    major: Symbol table
    minor: Unable to insert object   #004: /pub/devel/hdf5/hdf5-1.8.10-1/src/hdf5-1.8.10/src/H5Gtraverse.c line 861 in H5G_traverse(): internal path traversal failed
    major: Symbol table
    minor: Object not found   #005: /pub/devel/hdf5/hdf5-1.8.10-1/src/hdf5-1.8.10/src/H5Gtraverse.c line 641 in H5G_traverse_real(): traversal operator failed
    major: Symbol table
    minor: Callback failed   #006: /pub/devel/hdf5/hdf5-1.8.10-1/src/hdf5-1.8.10/src/H5L.c line 1685 in H5L_link_cb(): unable to create object
    major: Object header
    minor: Unable to initialize object   #007: /pub/devel/hdf5/hdf5-1.8.10-1/src/hdf5-1.8.10/src/H5O.c line 3015 in H5O_obj_create(): unable to open object
    major: Object header
    minor: Can't open object   #008: /pub/devel/hdf5/hdf5-1.8.10-1/src/hdf5-1.8.10/src/H5Doh.c line 293 in H5O__dset_create(): unable to create dataset
    major: Dataset
    minor: Unable to initialize object   #009: /pub/devel/hdf5/hdf5-1.8.10-1/src/hdf5-1.8.10/src/H5Dint.c line 1044 in H5D__create(): unable to construct layout information
    major: Dataset
    minor: Unable to initialize object   #010: /pub/devel/hdf5/hdf5-1.8.10-1/src/hdf5-1.8.10/src/H5Dcompact.c line 212 in H5D__compact_construct(): compact dataset size is bigger than header message maximum size
    major: Dataset
    minor: Unable to initialize object HDF5-DIAG: Error detected in HDF5 (1.8.10) thread 0:   #000: /pub/devel/hdf5/hdf5-1.8.10-1/src/hdf5-1.8.10/src/H5D.c line 391 in H5Dclose(): not a dataset
    major: Invalid arguments to routine
    minor: Inappropriate type

所有向量大小 >= 2^13 (8192) 都会发生这种情况。这让我感到困惑,因为读入更大的文件没有问题,而且 2^13 仍然是一个相当小的数字,所以我的代码一定有问题。

任何帮助将不胜感激。 你的 马古_

【问题讨论】:

  • 不确定它是否会有所帮助:假设 double 的宽度为 8 个字节,那么您的“原始”数据大小为 8192*8 = 65536(即 64 KB),并且在 @987654321 @您可以阅读此评论:Verify data size is smaller than maximum header message size (64KB) minus other layout message fields.

标签: c++ hdf5


【解决方案1】:

来自H5Pset_layoutH5D_COMPACT 参数的文档:

将原始数据存储在文件中的数据集对象头中。这应该只 用于具有少量原始数据的数据集。原始数据大小 限制为 64K(65520 字节)。尝试使用原始数据创建数据集 大于此限制的数据将导致 H5Dcreate 调用失败。

所以如果你的双打是 8 个字节,那么你已经达到了这个限制。

您需要使用其他存储选项之一,连续或分块。

【讨论】:

  • 嗯,是的,这是有道理的。谢谢(molbfnilo 和 gx_)的答案。现在它确实起作用了(现在^^)
猜你喜欢
  • 2020-07-24
  • 1970-01-01
  • 1970-01-01
  • 2019-04-01
  • 2021-07-06
  • 2015-06-09
  • 2019-05-17
  • 2012-01-27
  • 2011-07-17
相关资源
最近更新 更多