2017-04-24 42 views
0

有沒有辦法,如何在h5文件中設置列名?C++ - 在HDF5中設置列名稱

我可以用化合物數據類型來做到這一點,或者可以使用H5Table來完成。

一個選項也是通過這種方式來創建屬性並保存列的名稱。

但通常的單一數據類型矩陣不能有命名列,是嗎?

回答

1

據我所知,您不能在原子數據類型中設置列名稱。正如你所看到的H5Table的技巧是它創建了一個compund數據類型,其中每個「列」都有一個字段。 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]);