HDF5 Reference Manual H5 H5A H5D H5E H5F H5G H5P H5S H5T H5Z Tools

# H5G: Group Interface

## Group Object API Functions

The Group interface functions create and manipulate physical groups of objects on disk.

- H5Gcreate
- H5Gopen
- H5Gset
- H5Gclose
- H5Gpush

- H5Gpop
- H5Glink
- H5Gunlink (NYI)
- H5Giterate
- H5Gmove (NYI)

- H5Gget_objinfo
- H5Gget_linkval
- H5Gset_comment
- H5Gget_comment

(NYI = Not yet implemented)

A group associates names with objects and provides a mechanism for mapping a name to an object. Since all objects appear in at least one group (with the possible exception of the root object) and since objects can have names in more than one group, the set of all objects in an HDF5 file is a directed graph. The internal nodes (nodes with out-degree greater than zero) must be groups while the leaf nodes (nodes with out-degree zero) are either empty groups or objects of some other type. Exactly one object in every non-empty file is the root object. The root object always has a positive in-degree because it is pointed to by the file boot block.

Every file identifier returned by `H5Fcreate` or `H5Fopen` maintains an independent current working group stack, the top item of which is the current working group. The stack can be manipulated with `H5Gset`, `H5Gpush`, and `H5Gpop`. The root object is the current working group if the stack is empty.

An object name consists of one or more components separated from one another by slashes. An absolute name begins with a slash and the object is located by looking for the first component in the root object, then looking for the second component in the first object, etc., until the entire name is traversed. A relative name does not begin with a slash and the traversal begins with the current working group.

The library does not maintain the full absolute name of its current working group because (1) cycles in the graph can make the name length unbounded and (2) a group does not necessarily have a unique name. A more Unix-like hierarchical naming scheme can be implemented on top of the directed graph scheme by creating a ".." entry in each group that points to its single predecessor; a `getcwd` function would then be trivial.

Name: H5Gcreate
Signature:
  hid_t `H5Gcreate`(hid_t `loc_id`, const char *`name`, size_t `size_hint` )
Purpose:
  Creates a new empty group and gives it a name.
Description:
  `H5Gcreate` creates a new group with the specified name at the specified location, `loc_id`. The location is identified by a file or group identifier. The name, `name`, must not already be taken by some other object and all parent groups must already exist.

  `size_hint` is a hint for the number of bytes to reserve to store the names which will be eventually added to the new group. Passing a value of zero for `size_hint` is usually adequate since the library is able to dynamically resize the name heap, but a correct hint may result in better performance. If a non-positive value is supplied for size_hint, then a default size is chosen.

  The return value is a group identifier for the open group. This group identifier should be closed by calling `H5Gclose()` when it is no longer needed.

Parameters:

hid_t `loc_id`
  The file or group identifier.
const char *`name`
  The absolute or relative name of the new group.
size_t `size_hint`
  An optional parameter indicating the number of bytes to reserve for the names that will appear in the group. A conservative estimate could result in multiple system-level I/O requests to read the group name heap; a liberal estimate could result in a single large I/O request even when the group has just a few names. HDF5 stores each name with a null terminator.

Returns:
  Returns a valid group identifier for the open group if successful; otherwise FAIL (-1).

Name: H5Gopen
Signature:
  hid_t `H5Gopen`(hid_t `loc_id`, const char *`name` )
Purpose:
  Opens an existing group for modification and returns a group identifier for that group.
Description:
  `H5Gopen` opens an existing group with the specified name at the specified location, `loc_id`. The location is identified by a file or group identifier, and returns a group identifier for the group. The obtained group identifier should be released by calling `H5Gclose()` when it is no longer needed.
Parameters:

hid_t `loc_id`
  File or group identifier within which group is to be open.
const char * `name`
  Name of group to open.

Returns:
  Returns a valid group identifier if successful; otherwise FAIL (-1).

Name: H5Gset
Signature:
  herr_t `H5Gset` (hid_t `loc_id`, const char *`name` )
Purpose:
  Sets the current working group within a file.
Description:
  `H5Gset` sets the group with the specified name to be the current working group for the file which contains it. This function sets the current working group by modifying the top element of the current working group stack or, if the stack is empty, by pushing a new element onto the stack. The initial current working group is the root group.

  `loc_id` can be a file identifier or a group identifier.

  `name` is an absolute or relative name and is resolved as follows. Each file identifier has a current working group, initially the root group of the file. Relative names do not begin with a slash and are relative to the specified group or to the current working group. Absolute names begin with a slash and are relative to the file's root group. For instance, the name `/Foo/Bar/Baz` is resolved by first looking up `Foo` in the root group; the name `Foo/Bar/Baz` is resolved by first looking up the name `Foo` in the current working group.

  Each file identifier maintains its own notion of the current working group. If `loc_id` is a group identifier, the file identifier is derived from the group identifier.

  If a single file is opened with multiple calls to `H5Fopen()`, which would return multiple file identifiers, then each identifier's current working group can be set independently of the other file identifiers for that file.

Parameters:

hid_t `loc_id`
  The file or group identifier.
const char *`name`
  The name of the new current working group.

Returns:
  Returns SUCCEED (0) if successful; otherwise FAIL (-1).

Name: H5Gpush
Signature:
  herr_t `H5Gpush` (hid_t `loc_id`, const char *`name` )
Purpose:
  Sets the current working group by pushing a new element onto the current working group stack.
Description:
  Each file identifier maintains a stack of groups, the top group of which is the current working group. The stack initially contains only the root group. `H5Gpush` pushes a new group onto the stack, thus setting a new current working group.
Parameters:

hid_t `loc_id`
  File or group identifier.
const char *`name`
  The name of the new current working group. The name may be an absolute or relative name.

Returns:
  Returns SUCCEED (0) if successful; otherwise FAIL (-1).

Name: H5Gpop
Signature:
  herr_t `H5Gpop` (hid_t `loc_id`)
Purpose:
  Removes the top, or latest, entry from the working group stack, setting the current working group to the previous value.
Description:
  `H5Gpop` restores the previous current working group by popping an element from the current working group stack. An empty stack implies that the current working group is the root object. Attempting to pop an empty stack results in failure.

  Each file identfier maintains its own notion of the current working group. That is, if a single file is opened with multiple calls to `H5Fopen()`, which returns multiple file handles, then each identfier's current working group can be set independently of the other file identfiers for that file.

  If `loc_id` is a group identifier, it is used only to determine the file identifier for the stack from which to pop the top entry.

Parameters:

hid_t `loc_id`
  The file, group, dataset, or datatype identifier.

Returns:
  Returns SUCCEED (0) if successful; otherwise FAIL (-1).

Name: H5Gclose
Signature:
  herr_t `H5Gclose`(hid_t `group_id`)
Purpose:
  Closes the specified group.
Description:
  `H5Gclose` releases resources used by a group which was opened by `H5Gcreate()` or `H5Gopen()`. After closing a group, the `group_id` cannot be used again.

  Failure to release a group with this call will result in resource leaks.

Parameters:

hid_t `group_id`
  Group identifier to release.

Returns:
  Returns SUCCEED (0) if successful; otherwise FAIL (-1).

Name: H5Glink
Signature:
  herr_t `H5Glink`(hid_t `loc_id`, H5G_link_t `link_type`, const char *`current_name`, const char *`new_name` )
Purpose:
  Creates a link of the specified type from `new_name` to `current_name`.
Description:
  `H5Glink` creates a new name for an object that has some current name, possibly one of many names it currently has.

  If `link_type` is `H5G_LINK_HARD`, then `current_name` must name an existing object and both names are interpreted relative to `loc_id`, which is either a file identifier or a group identifier.

  If `link_type` is `H5G_LINK_SOFT`, then `current_name` can be anything and is interpreted at lookup time relative to the group which contains the final component of `new_name`. For instance, if `current_name` is `./foo`, `new_name` is `./x/y/bar`, and a request is made for `./x/y/bar`, then the actual object looked up is `./x/y/./foo`.

Parameters:

hid_t `loc_id`
  File, group, dataset, or datatype identifier.
H5G_link_t `link_type`
  Link type. Possible values are `H5G_LINK_HARD` and `H5G_LINK_SOFT`.
const char * `current_name`
  Name of the existing object if link is a hard link. Can be anything for the soft link.
const char * `new_name`
  New name for the object.

Returns:
  Returns SUCCEED (0) if successful; otherwise FAIL (-1).

Name: H5Gunlink (Not implemented in this release.)
Signature:
  herr_t `H5Gunlink`(hid_t `loc_id`, const char *`name` )
Purpose:
  Removes the specified `name` from the group graph and decrements the link count for the object to which `name` points
Description:
  `H5Gunlink` removes an association between a name and an object. Object headers keep track of how many hard links refer to the object; when the hard link count reaches zero, the object can be removed from the file. Objects which are open are not removed until all identifiers to the object are closed.

  If the link count reaches zero, all file-space associated with the object will be reclaimed. If the object is open, the reclamation of the file space is delayed until all handles to the object are closed.

Parameters:

hid_t `loc_id`
  Identifier of the file containing the object.
const char * `name`
  Name of the object to unlink.

Returns:
  Returns SUCCEED (0) if successful; otherwise FAIL (-1).

Name: H5Giterate
Signature:
  int `H5Giterate`(hid_t `loc_id`, const char `*name`, int `*idx`, H5G_operator_t `operator`, void `*operator_data` )
Purpose:
  Iterates an operation over the entries of a group.
Description:
  `H5Giterate` iterates over the members of `name` in the file or group specified with `loc_id`. For each object in the group, the `operator_data` and some additional information, specified below, are passed to the `operator` function. The iteration begins with the `idx` object in the group and the next element to be processed by the operator is returned in `idx`. If `idx` is NULL, then the iterator starts at the first group member; since no stopping point is returned in this case, the iterator cannot be restarted if one of the calls to its operator returns non-zero.

  The prototype for `H5G_operator_t` is:

    `typedef` herr_t *(`H5G_operator_t`)(hid_t `group_id`, const char *`member_name`, void *`operator_data/*in,out*/`);
  The operation receives the group identifier for the group being iterated over, `group_id`, the name of the current object within the group, `member_name`, and the pointer to the operator data passed in to `H5Giterate`, `operator_data`.

  The return values from an operator are:

  - Zero causes the iterator to continue, returning zero when all group members have been processed.
  - Positive causes the iterator to immediately return that positive value, indicating short-circuit success. The iterator can be restarted at the next group member.
  - Negative causes the iterator to immediately return that value, indicating failure. The iterator can be restarted at the next group member.
Parameters:

hid_t `loc_id`
  IN: File or group identifier.
const char `*name`
  IN: Group over which the iteration is performed.
int `*idx`
  IN/OUT: Location at which to begin the iteration.
H5G_iterate_t `operator`
  IN: Operation to be performed on an object at each step of the iteration.
void `*operator_data`
  IN/OUT: Data associated with the operation.

Returns:
  Returns the return value of the last operator if it was non-zero, or zero if all group members were processed. Otherwise, returns FAIL (-1).

Name: H5Gmove (Not implemented in this release.)
Signature:
  herr_t `H5Gmove`(hid_t `loc_id`, const char `*src`, const char `*dst` )
Purpose:
  Renames an object within an HDF5 file.
Description:
  `H5Gmove` renames an object within an HDF5 file. The original name, `src`, is unlinked from the group graph and the new name, `dst`, is inserted as an atomic operation. Both names are interpreted relative to `loc_id`, which is either a file or a group identifier.
Parameters:

hid_t `loc_id`
  File or group identifier.
const char `*src`
  Object's original name.
const char `*dst`
  Object's new name.

Returns:
  Returns SUCCEED (0) if successful; otherwise FAIL (-1).

Name: H5Gget_objinfo
Signature:
  herr_t `H5Gget_objinfo`(hid_t `loc_id`, const char *`name`, hbool_t `follow_link`, H5G_stat_t *`statbuf` )
Purpose:
  Returns information about an object.
Description:
  `H5Gget_objinfo` returns information about the specified object through the `statbuf` argument. `loc_id` (a file, group, or dataset identifier) and `name` together determine the object. If the object is a symbolic link and `follow_link` is zero (`0`), then the information returned is that for the link itself; otherwise the link is followed and information is returned about the object to which the link points. If `follow_link` is non-zero but the final symbolic link is dangling (does not point to anything), then an error is returned. The `statbuf` fields are undefined for an error. The existence of an object can be tested by calling this function with a null `statbuf`.

  `H5Gget_objinfo()` fills in the following data structure:

                        typedef struct H5G_stat_t {
                            unsigned long fileno[2];
                            unsigned long objno[2];
                            unsigned nlink;
                            H5G_type_t type;
                            time_t mtime;
                            size_t linklen;
                        } H5G_stat_t

  The `fileno` and `objno` fields contain four values which uniquely itentify an object among those HDF5 files which are open: if all four values are the same between two objects, then the two objects are the same (provided both files are still open). The `nlink` field is the number of hard links to the object or zero when information is being returned about a symbolic link (symbolic links do not have hard links but all other objects always have at least one). The `type` field contains the type of the object, one of `H5G_GROUP`, `H5G_DATASET`, or `H5G_LINK`. The `mtime` field contains the modification time. If information is being returned about a symbolic link then `linklen` will be the length of the link value (the name of the pointed-to object with the null terminator); otherwise `linklen` will be zero. Other fields may be added to this structure in the future.
Note:
  Some systems will be able to record the time accurately but unable to retrieve the correct time; such systems (e.g., Irix64) will report an `mtime` value of 0 (zero).
Parameters:

hid_t `loc_id`
  IN: File, group, dataset, or datatype identifier.
const char `*name`
  IN: Name of the object for which status is being sought.
hbool_t `follow_link`
  IN: Link flag.
H5G_stat_t `*statbuf`
  OUT: Buffer in which to return information about the object.

Returns:
  Returns SUCCEED (0) with the fields of `statbuf` (if non-null) initialized. Otherwise returns FAIL (-1).

Name: H5Gget_linkval
Signature:
  herr_t `H5Gget_linkval`(hid_t `loc_id`, const char *`name`, size_t `size`, char *`value` )
Purpose:
  Returns link value.
Description:
  `H5Gget_linkval` returns `size` characters of the link value through the `value` argument if `loc_id` (a file or group identifier) and `name` specify a symbolic link. If `size` is smaller than the link value, then `value` will not be null terminated.

  This function fails if the specified object is not a symbolic link. The presence of a symbolic link can be tested by passing zero for `size` and NULL for `value`.

  Use `H5Gget_objinfo()` to get the size of a link value.

Parameters:

hid_t `loc_id`
  IN: Identifier of the file, group, dataset, or datatype.
const char *`name`
  IN: Name of the object whose link value is to be checked.
size_t `size`
  IN: Maximum number of characters of `value` to be returned.
char *`value`
  OUT: Link value.

Returns:
  Returns SUCCEED (0), with the link value in `value`, if successful. Otherwise returns FAIL (-1).

Name: H5Gset_comment
Signature:
  herr_t `H5Gset_comment`(hid_t `loc_id`, const char *`name`, const char *`comment` )
Purpose:
  Sets comment for specified object.
Description:
  `H5Gset_comment` sets the comment for the the object `name` to `comment`. Any previously existing comment is overwritten.

  If `comment` is the empty string or a null pointer, the comment message is removed from the object.

  Comments should be relatively short, null-terminated, ASCII strings.

  Comments can be attached to any object that has an object header, e.g., data sets, groups, named data types, and data spaces, but not symbolic links.

Parameters:

hid_t `loc_id`
  IN: Identifier of the file, group, dataset, or datatype.
const char *`name`
  IN: Name of the object whose comment is to be set or reset.
const char *`comment`
  IN: The new comment.

Returns:
  Returns SUCCEED (0) if successful; otherwise returns FAIL (-1).

Name: H5Gget_comment
Signature:
  herr_t `H5Gget_comment`(hid_t `loc_id`, const char *`name`, size_t `bufsize`, char *`comment` )
Purpose:
  Retrieves comment for specified object.
Description:
  `H5Gget_comment` retrieves the comment for the the object `name`. The comment is returned in the buffer `comment`.

  At most `bufsize` characters, including a null terminator, are copied. The result is not null terminated if the comment is longer than the supplied buffer.

  If an object does not have a comment, the empty string is returned.

Parameters:

hid_t `loc_id`
  IN: Identifier of the file, group, dataset, or datatype.
const char *`name`
  IN: Name of the object whose comment is to be set or reset.
size_t `bufsize`
  IN: Anticipated size of the buffer required to hold `comment`.
char *`comment`
  OUT: The comment.

Returns:
  Returns the number of characters in the comment, counting the null terminator, if successful; the value returned may be larger than `bufsize`. Otherwise returns FAIL (-1).

HDF5 Reference Manual H5 H5A H5D H5E H5F H5G H5P H5S H5T H5Z Tools

HDF Help Desk
Last modified: 2 September 1998