next up previous index
Next: HDF5 Groups and Datasets Up: Creating and Structuring HDF5 Previous: HDF5 Attributes

HDF5 Groups

In this section I am going to show you how to create additional HDF5 groups. We are going to create groups:

/MyGroup
/MyGroup/Group_A
/MyGroup/Group_B
We will use the absolute pathname of the group in one case and a relative pathname of the group in another.

Here is the code that does this. We are going to create a new file, groups.h5, this time:

/*
 *   Creating groups using absolute and relative names.
 */

#include "hdf5.h"
#define FILE "groups.h5"

main() {

   hid_t       file_id, group1_id, group2_id, group3_id;  /* identifiers */
   herr_t      status;

   /* Create a new file using default properties. */
   file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

   /* Create group "MyGroup" in the root group using absolute name. */
   group1_id = H5Gcreate(file_id, "/MyGroup", 0);

   /* Create group "Group_A" in group "MyGroup" using absolute name. */
   group2_id = H5Gcreate(file_id, "/MyGroup/Group_A", 0);

   /* Create group "Group_B" in group "MyGroup" using relative name. */
   group3_id = H5Gcreate(group1_id, "Group_B", 0);

   /* Close groups. */
   status = H5Gclose(group1_id);
   status = H5Gclose(group2_id);
   status = H5Gclose(group3_id);

   /* Close the file. */
   status = H5Fclose(file_id);
}
Here is how the binary is made and then how the program is run and then what comes out of it:
gustav@bh1 $ h5cc -o h5_crtgrpar h5_crtgrpar.c
gustav@bh1 $ ./h5_crtgrpar
gustav@bh1 $ h5dump groups.h5
HDF5 "groups.h5" {
GROUP "/" {
   GROUP "MyGroup" {
      GROUP "Group_A" {
      }
      GROUP "Group_B" {
      }
   }
}
}
gustav@bh1 $
Creation of groups is easier than creation of datasets, because you don't have to bother with creating the dataspace. Function H5Gcreate belongs to the family of functions for manipulation of HDF5 groups. Functions in this family have names beginning with H5G.

Function H5Gcreate takes the following arguments:

After the groups have been created, they have to be closed by calling  H5Gclose. This function takes the group identifier as the sole argument.


next up previous index
Next: HDF5 Groups and Datasets Up: Creating and Structuring HDF5 Previous: HDF5 Attributes
Zdzislaw Meglicki
2004-04-29