Hi,

For the purpose of some project I'd like to read HDF5 files in my C++ application using HDF5 API.

First of all I would like to read entire HDF5 file structure to know where are the groups (their names, attributes etc.) and where I can find datasets. The API functions like H5*iterate (non-recursive version) or H5*visit (recursive version) are rather useless, because their H5*_info_t structures have very limited information about the object on the given level in this structure. Thus I've decided to walk manually through this structure and get as much information as I can for the given object.

So...

Calling H5Gget_info gives me a number of links at the top ("." group) which then I can ask for details based on their index. Fine. Now, having the link index, I can call H5Lget_name_by_idx to get the link name. First initial call to that function will return the name size and second one will return the link name in the properly prepared buffer of char*.

On that stage I found a first problem (a bug I suppose):
Let's assume the link name is "foobar", so it has 6 characters.
Initial call of H5Lget_name_by_idx returns 6, but when I call it again with "size" parameter set to 6 it fills my buffer with just 5 characters ("fooba") even if the buffer has a proper size of 7 bytes (the 7th for the final \0).
So it seems I have to increase size by 1 to get the proper link name.
What's the problem here? Maybe it's just my wrong understanding for this API function?

Code example (returns "fooba" instead of "foobar" in the "link_name" buffer):

// initial call to get name size
int link_name_size = H5Lget_name_by_idx(file.getId(), ".", H5_INDEX_NAME, H5_ITER_NATIVE, i, NULL, 0, 0);

// one more byte for \0 at the end
char *link_name = new char[link_name_size + 1];

// final call
H5Lget_name_by_idx(file.getId(), ".", H5_INDEX_NAME, H5_ITER_NATIVE, i, link_name, link_name_size, 0);


Can someone please explain me what's the problem here?

Regards,
Rafal


_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

Reply via email to