The HDF-5 C API provides the H5GIterate function, which requires the calling program to pass a C function to be called for each member of the group. For languages other than C, two utilities have been provided which "wrap" this function, providing a simple generic enumeration of an HDF 5 group. The Java HDF-5 Interface provides these utilities.
The two C functions are:
int H5Gn_members( hid_t locid, char *name )where,
andlocid: (IN) the id of the file or parent group
name: (IN) the name of the groupThis function returns the number of objects in the group, as would be found by H5Ginterate(). This includes all the hard and soft links. In the case where an object has more than one link to it in the same group (essentially, the object has more than one name), both links (names) will be counted.
herr_t H5Gget_obj_info_idx( hid_t locid, char * group_name, int idx, char **obj_name, int *obj_type);
where,
Usagelocid: (IN) the id of the file or parent group
group_name: (IN) the name of the group
idx: (IN) the index of the object to be read
obj_name: (OUT) the name of the object at index idx
obj_type: (OUT) the HDF-5 type of the object at index idx.
This function returns the name and type of member number 'idx' from the group 'group_name'. The function H5Gn_members returns the number of elements, which are numbered from 0 to (n_members - 1)
These functions are intended to allow a program to discover the number of members, and then iterate though them one at a time. The following program illustrates the use of these functions in a Java program.
int pid; // the hid_t of the parent of the group to be examined String group; // the group to be examined ... int [] oType = new int[1]; // the returned type String [] oName = new String[1]; oName[0] = new String(""); // the returned nameint nelems = 0;try { nelems = H5.H5Gn_members( pid, group); } catch ( HDF5Exception ex) { System.out.println("H5Gn_members: failed, exception: "+ex); exit(1); }// print out all the members for (int i = 0; i < nelems; i++) { try { H5.H5Gget_obj_info_idx( pid, group, i, oName, oType); } catch ( HDF5Exception ex) { System.out.println("H5Gget_obj_info_idx: failed, exception: "+ex); exit(1); }
System.out.println(i+": "+oName+", type: "+oType); // ...open the object and work with it... }