NCSA

[ HDF5 Tutorial Top ]

Creating a Group


Contents:


What is a Group?

An HDF5 group is a structure containing zero or more HDF5 objects. The two primary HDF5 objects are groups and datasets. To create a group, the calling program must:

  1. Obtain the location identifier where the group is to be created.
  2. Create the group.
  3. Close the group.
To create a group, the calling program must contain the following calls:
  group_id = H5Gcreate (loc_id, name, size_hint);
  H5Gclose (group_id);

Programming Example

Description

The following example shows how to create and close a group. It creates a file called 'group.h5', creates a group called MyGroup in the root group, and then closes the group and file.
[
Download h5_crtgrp.c ]

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#include <hdf5.h>
#define FILE "group.h5"

main() {

   hid_t       file_id, group_id;  /* identifiers */
   herr_t      status;

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

   /* Create a group named "/MyGroup" in the file. */
   group_id = H5Gcreate(file_id, "/MyGroup", 0);

   /* Close the group. */
   status = H5Gclose(group_id);

   /* Terminate access to the file. */
   status = H5Fclose(file_id);
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Remarks

File Contents

The contents of 'group.h5' and the definition of the group are given in the following:

Fig. 8.1   The Contents of 'group.h5'. Fig. 8.2   'group.h5' in DDL
       
HDF5 "group.h5" {
GROUP "/" {
   GROUP "MyGroup" {
   }
}
}


NCSA
The National Center for Supercomputing Applications

University of Illinois at Urbana-Champaign

hdfhelp@ncsa.uiuc.edu
Last Modified: August 27, 1999