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.

有帮助吗?

解决方案 2

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.

其他提示

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"
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top