How can one get the name of an HDF5 DataSet through the C or C++ API?

故事扮演 提交于 2020-01-02 07:49:07

问题


I'm trying to read the name of a HDF5 DataSet using the C++ API. For H5::Attribute objects, there is a getName() method. However, I don't see a similar getName() method for H5:DataSet objects.

Ideally I want to do this:

 void Dump(H5::DataSet& ds)
 {
    cout << "Dataset " << ds.getName() << endl;
    // continue to print dataset values
 }

I know h5dump can do it, but briefly looking at the code, it only knows it by walking the tree using H5Giterate, that is only the parent knows the name of the children, but the children don't know their own name.


回答1:


In C, there is H5Iget_name. I couldn't find the equivalent in C++ but you can use DataSet::getId() and give that to the C function.

I guess the reason why this is not as simple as having a getName() accessor in DataSet is that to read a dataset, you either need to know its name or walk the tree. The only exception I can think of is when dereferencing a reference to a dataset.




回答2:


This is a partial answer, based on Simon's post. Note that the name is a full hierarchical name,

std::string getName(const H5::DataSet& ds)
{
    size_t len = H5Iget_name(ds.getId(),NULL,0);
    char buffer[len];
    H5Iget_name(ds.getId(),buffer,len+1);
    std::string n = buffer;
    return n;
}

example name

"/toplevel/videodata"


来源:https://stackoverflow.com/questions/22798731/how-can-one-get-the-name-of-an-hdf5-dataset-through-the-c-or-c-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!