The HDF5 Group interface includes the H5Giterate
function,
which iterates over the group members.
Operations on each group member can be performed during the iteration process by passing the operator function and its data to the iterator as parameters. There are no restrictions on what kind of operations can be performed on group members during the iteration procedure.
The following steps are involved:
hgn_members_f
returns the number of group members.
h5gget_obj_info_idx_f
returns the name and type of the
group member, which is identified by its index.
h5_iterate.c
grpit.f90
Following is the output from these examples:
Output from C Example
Objects in the root group are: Object with name Dataset1 is a dataset Object with name Datatype1 is a named datatype Object with name Group1 is a groupOutput from FORTRAN Example
Number of root group member is 1 MyGroup 1 Number of group MyGroup member is 2 Group_A 1 dset1 2 Number of group MyGroup/Group_A member is 1 dset2 2
herr_t *(H5G_operator_t) (hid group_id, const char* name, void *operator_data)
H5Giterate
.
H5Giterate
.
The operator function in this example simply prints the name and type of the current object and then exits. This information can also be used to open the object and perform different operations or queries. For example a named datatype object's name can be used to open the datatype and query its properties.
The operator return value defines the behavior of the iterator.
In this example the operator function returns 0, which causes the iterator to continue and go through all group members.
H5Gget_objinfo
is used to determine the type of the object.
It also returns the modification time, number of hard links, and some
other information.
The signature of this function is as follows:
herr_t H5Gget_objinfo (hid_t loc_id, const char * name, hbool_t follow_link, H5G_stat_t *statbuf)
The root group in this example does not have objects that are links, so this flag is not important for our example.
H5G_stat_t
data structure (statbuf.type
).
Valid values are
H5G_GROUP
, H5G_DATASET
,
H5G_TYPE
, and H5G_LINK
.
H5Giterate
function has the following signature:
int H5Giterate (hid_t loc_id, const char *name , int *idx, H5G_operator_t operator, void * operator_data)
h5gn_members_f
to get the number of members in
each group and h5gget_obj_idx_f
to obtain the group member's
name and type.
h5gn_members_f
call:
h5gn_members_f (loc_id, name, nmembers, hdferr) loc_id IN: INTEGER (HID_T) name IN: CHARACTER (LEN=*) nmembers OUT: INTEGER hdferr OUT: INTEGER
h5gget_obj_info_idx_f
call:
h5gget_obj_info_idx_f (loc_id, name, idx, & obj_name, obj_type, hdferr) loc_id IN: INTEGER (HID_T) name IN: CHARACTER (LEN=*) idx IN: INTEGER obj_name OUT: CHARACTER (LEN=*) obj_type OUT: INTEGER hdferr OUT: INTEGER
H5G_LINK_F H5G_GROUP_F H5G_DATASET_F H5G_TYPE_F