如何使用C ++接口读取HDF5文件中的属性

时间:2017-04-13 05:34:05

标签: hdf5

我有HDF5文件,其中的属性格式为

ATTRIBUTE "dtype" {
   DATATYPE  H5T_STRING {
         STRSIZE 8;
         STRPAD H5T_STR_NULLPAD;
         CSET H5T_CSET_ASCII;
         CTYPE H5T_C_S1;
      }
   DATASPACE  SCALAR
   DATA {
   (0): "waveform"
   }
}

我想从属性中检索波形。我尝试了下面的代码片段,但它崩溃了

Group* signalgroup = new Group(outputgroup->openGroup(signalgrpName));
Attribute *attr = new Attribute(signalgroup->openAttribute("dtype"));
DataType  *type = new DataType(attr->getDataType());
H5std_string test;
attr->read(*type, &test); //crashes here

有关如何阅读本文的任何意见?

1 个答案:

答案 0 :(得分:0)

这很晚了,但是我偶然发现了这个问题,寻找了类似的东西。 HDF5 API具有重载的attribute.read()函数,该函数通过引用(而不是通过指针)引入std::string

请参见此处的文档:https://support.hdfgroup.org/HDF5/doc/cpplus_RM/class_h5_1_1_attribute.html#a8dae50d14de724c87507cba37f86793d(在下面引用)

void H5::Attribute::read(const DataType& mem_type, H5std_string& strg) const

Parameters
mem_type    - IN: Attribute datatype (in memory)
strg    - IN: Buffer for read string
相关问题