【问题标题】:C++ - set column names in HDF5C++ - 在 HDF5 中设置列​​名
【发布时间】:2017-05-02 16:59:41
【问题描述】:

有没有办法,如何在h5文件中设置列名?

我可以使用复合数据类型执行此操作,也可以使用 H5Table 完成此操作。

一种选择也是以这种方式制作属性并保存列的名称。

但是通常的单一数据类型的矩阵不能有命名列,是吗?

【问题讨论】:

    标签: c++ hdf5


    【解决方案1】:

    据我所知,您不能在原子数据类型中设置列名。正如您所看到的,H5Table 的技巧在于它创建了一个复合数据类型,其中每个“列”都有一个字段。 LINK.

    如果我是你,我会将列名写入属性(字符串数组)并保持数据类型简单。

    要在 C++ 中创建字符串列表,我执行以下操作:

    H5::H5File m_h5File;
    m_h5File = H5File("MyH5File.h5", H5F_ACC_RDWR);
    DataSet theDataSet = m_h5File.openDataSet("/channel001");
    H5Object * myObject = &theDataSet;
    
    //The data of the attribute.
    vector<string> att_vector;
    att_vector.push_back("ColName1");
    att_vector.push_back("ColName2 more characters");
    att_vector.push_back("ColName3");
    const int RANK = 1;
    hsize_t dims[RANK];
    StrType str_type(PredType::C_S1, H5T_VARIABLE);
    dims[0] = att_vector.size();  //The attribute will have 3 strings
    DataSpace att_datspc(RANK, dims);
    Attribute att(myObject->createAttribute("Column_Names" , str_type, att_datspc));
    
    vector<const char *> cStrArray;
    for(int index = 0; index < att_vector.size(); ++index)
    {
      cStrArray.push_back(att_vector[index].c_str());
    }
    //att_vector must not change
    att.write(str_type, (void*)&cStrArray[0]);
    

    【讨论】:

      猜你喜欢
      • 2016-12-08
      • 2021-04-23
      • 2015-08-01
      • 2011-08-24
      • 2017-07-14
      • 1970-01-01
      • 1970-01-01
      • 2015-11-07
      • 2021-12-04
      相关资源
      最近更新 更多