Extracting dataset names and iterating over them

Hi,
I am totally new to HDF5 and this group. So this question might have been
answered previously... In that case just pointing me to the right thread
will tremendously help.
My questions are:
1. I have an hdf5 file. Is it possible to iterate through the different
datasets and attributes etc.? If yes, how do I do that?
2. How do I extract the names of the datasets from this file to begin with?
I know how to extract info of a dataset once its name is given.

Thanks! I will really appreciate any help.

--tanzima

Use H5Giterate and pass your own, user-defined iterator function to it
to iterate over the members of a group or a file. The group may contain
things other than datasets though. You can use H5Gget_info inside your
user-defined iterator function to obtain information about each member
of the group and filter on, for example, datasets.

http://www.hdfgroup.org/HDF5/doc/RM/RM_H5G.html#Group-Iterate

Note that newer versions of HDF5 use H5Literate in favor of H5Giterate
so you may want to use H5Literate instead.

If you have the name of a dataset and open it with H5Dopen, you can get
information about that dataset with calls like H5Dget_space,
H5Dget_type, H5Dget_create_plist, etc.

http://www.hdfgroup.org/HDF5/doc/RM/RM_H5D.html

Mark

ยทยทยท

On Mon, 2010-07-12 at 15:24 -0700, Tanzima Zerin Islam wrote:

Hi,
I am totally new to HDF5 and this group. So this question might have
been answered previously... In that case just pointing me to the right
thread will tremendously help.
My questions are:
1. I have an hdf5 file. Is it possible to iterate through the
different datasets and attributes etc.? If yes, how do I do that?
2. How do I extract the names of the datasets from this file to begin
with? I know how to extract info of a dataset once its name is given.

Thanks! I will really appreciate any help.

--tanzima

--
Mark C. Miller, Lawrence Livermore National Laboratory
================!!LLNL BUSINESS ONLY!!================
miller86@llnl.gov urgent: miller86@pager.llnl.gov
T:8-6 (925)-423-5901 M/W/Th:7-12,2-7 (530)-753-8511

Hey Tanzima,

1. I have an hdf5 file. Is it possible to iterate through the different datasets and attributes etc.? If yes, how do I do that?

You can use H5Literate and H5Lvisit to iterate within a group in a flat and recursive way respectively. Check out the Link reference page:
http://www.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-Iterate
Within the callback you specify you can check for the type of the link in the info struct which will help you to decide what to do.
I also found that the example code is a fantastic source of information about how things can be used. Below is a link to the sample C code for HDF5 version 1.8:
http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/api18-c.html

2. How do I extract the names of the datasets from this file to begin with? I know how to extract info of a dataset once its name is given.

If you're not iterating/visiting through the file then you'll have to know explicitly what to query. The iterator functions supply a name to the callback, so you can use that. Alternatively, if you have an object id (dataset/group/...) you can use the H5Iget_name(...) function to return the name.
http://www.hdfgroup.org/HDF5/doc/RM/RM_H5I.html#Identify-GetName

I hope this has helped.

Richard.