Please, help us to better serve our user community by answering the following short survey: https://www.hdfgroup.org/website-survey/
HDF5 1.14.5
API Reference
Loading...
Searching...
No Matches
Groups (H5G)

Detailed Description

Use the functions in this module to manage HDF5 groups.

CreateRead
15 {
16 __label__ fail_group, fail_prop, fail_lcpl, fail_file;
17 hid_t file, lcpl, group;
18 char fname[] = "g1.h5";
19 char path[] = "/αυτή/είναι/μια/νέα/ομάδα";
20
22 ret_val = EXIT_FAILURE;
23 goto fail_file;
24 }
25
26 if ((lcpl = H5Pcreate(H5P_LINK_CREATE)) == H5I_INVALID_HID) {
27 ret_val = EXIT_FAILURE;
28 goto fail_lcpl;
29 }
30 // ensure that intermediate groups are created automatically
31 if (H5Pset_create_intermediate_group(lcpl, 1) < 0) {
32 ret_val = EXIT_FAILURE;
33 goto fail_prop;
34 }
35 // use UTF-8 encoding for link names
36 if (H5Pset_char_encoding(lcpl, H5T_CSET_UTF8) < 0) {
37 ret_val = EXIT_FAILURE;
38 goto fail_prop;
39 }
40 // create five groups
41 if ((group = H5Gcreate(file, path, lcpl, H5P_DEFAULT, H5P_DEFAULT)) == H5I_INVALID_HID) {
42 ret_val = EXIT_FAILURE;
43 goto fail_group;
44 }
45
46 H5Gclose(group);
47fail_group:
48fail_prop:
49 H5Pclose(lcpl);
50fail_lcpl:
51 H5Fclose(file);
52fail_file:;
53 }
#define H5F_ACC_TRUNC
Definition H5Fpublic.h:50
int64_t hid_t
Definition H5Ipublic.h:60
#define H5I_INVALID_HID
Definition H5Ipublic.h:75
#define H5P_LINK_CREATE
Definition H5Ppublic.h:124
#define H5P_DEFAULT
Definition H5Ppublic.h:228
@ H5T_CSET_UTF8
Definition H5Tpublic.h:96
herr_t H5Pset_char_encoding(hid_t plist_id, H5T_cset_t encoding)
Sets the character encoding used to encode link and attribute names.
herr_t H5Fclose(hid_t file_id)
Terminates access to an HDF5 file.
hid_t H5Fcreate(const char *filename, unsigned flags, hid_t fcpl_id, hid_t fapl_id)
Creates an HDF5 file.
#define H5Gcreate
Definition H5version.h:821
herr_t H5Gclose(hid_t group_id)
Closes the specified group.
herr_t H5Pset_create_intermediate_group(hid_t plist_id, unsigned crt_intmd)
Specifies in property list whether to create missing intermediate groups.
herr_t H5Pclose(hid_t plist_id)
Terminates access to a property list.
hid_t H5Pcreate(hid_t cls_id)
Creates a new property list as an instance of a property list class.
57 {
58 __label__ fail_file;
59 char fname[] = "g1.h5";
60 char path[] = "/αυτή/είναι";
61 hid_t file;
62 H5G_info_t info;
63
64 if ((file = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT)) == H5I_INVALID_HID) {
65 ret_val = EXIT_FAILURE;
66 goto fail_file;
67 }
68 // open one of the intermediate groups
69 if (H5Gget_info_by_name(file, path, &info, H5P_DEFAULT) < 0) {
70 ret_val = EXIT_FAILURE;
71 goto fail_info;
72 }
73
74 printf("Link count: %llu\n", info.nlinks);
75 switch (info.storage_type) {
77 printf("Compact storage\n");
78 break;
80 printf("Compact storage\n");
81 break;
83 printf("Symbol table\n");
84 break;
85 default:
86 printf("UFO\n");
87 break;
88 }
89
90fail_info:
91 H5Fclose(file);
92fail_file:;
93 }
#define H5F_ACC_RDONLY
Definition H5Fpublic.h:48
@ H5G_STORAGE_TYPE_SYMBOL_TABLE
Definition H5Gpublic.h:43
@ H5G_STORAGE_TYPE_COMPACT
Definition H5Gpublic.h:45
@ H5G_STORAGE_TYPE_DENSE
Definition H5Gpublic.h:46
hid_t H5Fopen(const char *filename, unsigned flags, hid_t fapl_id)
Opens an existing HDF5 file.
herr_t H5Gget_info_by_name(hid_t loc_id, const char *name, H5G_info_t *ginfo, hid_t lapl_id)
Retrieves information about a group by its name.
Definition H5Gpublic.h:55
H5G_storage_type_t storage_type
Definition H5Gpublic.h:56
hsize_t nlinks
Definition H5Gpublic.h:57
UpdateDelete
97 {
98 __label__ fail_group, fail_prop, fail_lcpl, fail_file;
99 hid_t file, lcpl, group;
100 char fname[] = "g1.h5";
101 char path[] = "/αυτή/είναι/μια/άλλη/νέα/ομάδα";
102
103 if ((file = H5Fopen(fname, H5F_ACC_RDWR, H5P_DEFAULT)) == H5I_INVALID_HID) {
104 ret_val = EXIT_FAILURE;
105 goto fail_file;
106 }
107
108 if ((lcpl = H5Pcreate(H5P_LINK_CREATE)) == H5I_INVALID_HID) {
109 ret_val = EXIT_FAILURE;
110 goto fail_lcpl;
111 }
112 // ensure that intermediate groups are created automatically
113 if (H5Pset_create_intermediate_group(lcpl, 1) < 0) {
114 ret_val = EXIT_FAILURE;
115 goto fail_prop;
116 }
117 // use UTF-8 encoding for link names
118 if (H5Pset_char_encoding(lcpl, H5T_CSET_UTF8) < 0) {
119 ret_val = EXIT_FAILURE;
120 goto fail_prop;
121 }
122 // create an anonymous group
123 if ((group = H5Gcreate_anon(file, H5P_DEFAULT, H5P_DEFAULT)) == H5I_INVALID_HID) {
124 ret_val = EXIT_FAILURE;
125 goto fail_group;
126 }
127 // link the new group to existing the group at "/αυτή/είναι/μια"
128 if (H5Lcreate_hard(group, ".", file, path, lcpl, H5P_DEFAULT) < 0) {
129 ret_val = EXIT_FAILURE;
130 }
131
132 H5Gclose(group);
133fail_group:
134fail_prop:
135 H5Pclose(lcpl);
136fail_lcpl:
137 H5Fclose(file);
138fail_file:;
139 }
#define H5F_ACC_RDWR
Definition H5Fpublic.h:49
hid_t H5Gcreate_anon(hid_t loc_id, hid_t gcpl_id, hid_t gapl_id)
Creates a new empty group without linking it into the file structure.
herr_t H5Lcreate_hard(hid_t cur_loc, const char *cur_name, hid_t dst_loc, const char *dst_name, hid_t lcpl_id, hid_t lapl_id)
Creates a hard link to an object.
143 {
144 __label__ fail_info, fail_object, fail_file;
145 hid_t file, obj;
146 char fname[] = "g1.h5";
147 char path[] = "/αυτή/είναι/μια/άλλη/νέα/ομάδα";
148 char delete_path[] = "/αυτή/είναι/μια";
149 H5O_info_t info;
150
151 if ((file = H5Fopen(fname, H5F_ACC_RDWR, H5P_DEFAULT)) == H5I_INVALID_HID) {
152 ret_val = EXIT_FAILURE;
153 goto fail_file;
154 }
155
156 // open a "leaf" group as object
157 if ((obj = H5Oopen(file, path, H5P_DEFAULT)) == H5I_INVALID_HID) {
158 ret_val = EXIT_FAILURE;
159 goto fail_object;
160 }
161 // delete the link to an intermediate group on the path to the leaf
162 if (H5Ldelete(file, delete_path, H5P_DEFAULT) < 0) {
163 ret_val = EXIT_FAILURE;
164 }
165 // link deletion will propagate along hard links along all paths
166 // reachable from the intermediate group and cause reference counts to
167 // be decremented, freeing the objects if the count reaches 0
168 if (H5Oget_info(obj, &info, H5O_INFO_BASIC) < 0) {
169 ret_val = EXIT_FAILURE;
170 goto fail_info;
171 }
172
173 printf("Leaf reference count: %d\n", info.rc);
174
175fail_info:
176 H5Oclose(obj);
177fail_object:
178 H5Fclose(file);
179fail_file:;
180 }
#define H5O_INFO_BASIC
Definition H5Opublic.h:81
#define H5O_info_t
Definition H5version.h:1134
herr_t H5Ldelete(hid_t loc_id, const char *name, hid_t lapl_id)
Removes a link from a group.
herr_t H5Oclose(hid_t object_id)
Closes an object in an HDF5 file.
hid_t H5Oopen(hid_t loc_id, const char *name, hid_t lapl_id)
Opens an object in an HDF5 file by location identifier and path name.
#define H5Oget_info
Definition H5version.h:921

Groups in HDF5: 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 an out-degree greater than zero) must be groups, while the leaf nodes (nodes with an 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 superblock.

Locating objects in the HDF5 file hierarchy: 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 at the location specified by the create or access function.

Group implementations in HDF5: The original HDF5 group implementation provided a single-indexed structure for link storage. A new group implementation, in HDF5 Release 1.8.0, enables more efficient compact storage for very small groups, improved link indexing for large groups, and other advanced features.

The original group structure and the newer structures are not directly interoperable. By default, a group will be created in the original indexed format. An existing group can be changed to a compact-or-indexed format if the need arises; there is no capability to change back. As stated above, once in the compact-or-indexed format, a group can switch between compact and indexed as needed.

Groups will be initially created in the compact-or-indexed format only when one or more of the following conditions is met:

An existing group, currently in the original indexed format, will be converted to the compact-or-indexed format upon the occurrence of any of the following events:

The compact-or-indexed format offers performance improvements that will be most notable at the extremes, i.e., in groups with zero members and in groups with tens of thousands of members. But measurable differences may sometimes appear at a threshold as low as eight group members. Since these performance thresholds and criteria differ from application to application, tunable settings are provided to govern the switch between the compact and indexed formats (see H5Pset_link_phase_change()). Optimal thresholds will depend on the application and the operating environment.

Future versions of HDF5 will retain the ability to create, read, write, and manipulate all groups stored in either the original indexed format or the compact-or-indexed format.

Macros

#define H5Gcreate   H5Gcreate2
 
#define H5Gopen   H5Gopen2
 

Functions

hid_t H5Gcreate2 (hid_t loc_id, const char *name, hid_t lcpl_id, hid_t gcpl_id, hid_t gapl_id)
 Creates a new group and links it into the file.
 
hid_t H5Gcreate_anon (hid_t loc_id, hid_t gcpl_id, hid_t gapl_id)
 Creates a new empty group without linking it into the file structure.
 
hid_t H5Gopen2 (hid_t loc_id, const char *name, hid_t gapl_id)
 Opens an existing group in a file.
 
hid_t H5Gget_create_plist (hid_t group_id)
 Gets a group creation property list identifier.
 
herr_t H5Gget_info (hid_t loc_id, H5G_info_t *ginfo)
 Retrieves information about a group.
 
herr_t H5Gget_info_by_name (hid_t loc_id, const char *name, H5G_info_t *ginfo, hid_t lapl_id)
 Retrieves information about a group by its name.
 
herr_t H5Gget_info_by_idx (hid_t loc_id, const char *group_name, H5_index_t idx_type, H5_iter_order_t order, hsize_t n, H5G_info_t *ginfo, hid_t lapl_id)
 Retrieves information about a group, according to the group's position within an index.
 
herr_t H5Gflush (hid_t group_id)
 Flushes all buffers associated with a group to disk.
 
herr_t H5Grefresh (hid_t group_id)
 Refreshes all buffers associated with a group.
 
herr_t H5Gclose (hid_t group_id)
 Closes the specified group.
 
hid_t H5Gcreate1 (hid_t loc_id, const char *name, size_t size_hint)
 Creates a new group and links it into the file.
 
hid_t H5Gopen1 (hid_t loc_id, const char *name)
 Opens an existing group for modification and returns a group identifier for that group.
 
herr_t H5Glink (hid_t cur_loc_id, H5L_type_t type, const char *cur_name, const char *new_name)
 Creates a link of the specified type from new_name to cur_name.
 
herr_t H5Glink2 (hid_t cur_loc_id, const char *cur_name, H5L_type_t type, hid_t new_loc_id, const char *new_name)
 Creates a link of the specified type from cur_name to new_name.
 
herr_t H5Gmove (hid_t src_loc_id, const char *src_name, const char *dst_name)
 Renames an object within an HDF5 file.
 
herr_t H5Gmove2 (hid_t src_loc_id, const char *src_name, hid_t dst_loc_id, const char *dst_name)
 Renames an object within an HDF5 file.
 
herr_t H5Gunlink (hid_t loc_id, const char *name)
 Removes the link to an object from a group.
 
herr_t H5Gget_linkval (hid_t loc_id, const char *name, size_t size, char *buf)
 Returns the name of the object that the symbolic link points to.
 
herr_t H5Gset_comment (hid_t loc_id, const char *name, const char *comment)
 Sets comment for specified object.
 
int H5Gget_comment (hid_t loc_id, const char *name, size_t bufsize, char *buf)
 Retrieves comment for specified object.
 
herr_t H5Giterate (hid_t loc_id, const char *name, int *idx, H5G_iterate_t op, void *op_data)
 Iterates over the entries of a group invoking a callback for each entry encountered.
 
herr_t H5Gget_num_objs (hid_t loc_id, hsize_t *num_objs)
 Returns number of objects in the group specified by its identifier.
 
herr_t H5Gget_objinfo (hid_t loc_id, const char *name, hbool_t follow_link, H5G_stat_t *statbuf)
 Returns information about an object.
 
ssize_t H5Gget_objname_by_idx (hid_t loc_id, hsize_t idx, char *name, size_t size)
 Returns the name of an object specified by an index.
 
H5G_obj_t H5Gget_objtype_by_idx (hid_t loc_id, hsize_t idx)
 Returns the type of an object specified by an index.
 

Macro Definition Documentation

◆ H5Gcreate

#define H5Gcreate   H5Gcreate2

H5Gcreate() is a macro that is mapped to either H5Gcreate1() or H5Gcreate2().

See also
API Compatibility Macros

◆ H5Gopen

#define H5Gopen   H5Gopen2

H5Gopen() is a macro that is mapped to either H5Gopen1() or H5Gopen2().

See also
API Compatibility Macros

Function Documentation

◆ H5Gclose()

herr_t H5Gclose ( hid_t  group_id)

Closes the specified group.


Parameters
[in]group_idGroup identifier
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Gclose() releases resources used by a group that was opened by H5Gcreate() or H5Gopen(). After closing a group, group_id cannot be used again until another H5Gcreate() or H5Gopen() is called on it.

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

Example
{
hid_t file = H5Fopen("f11.h5", H5F_ACC_RDWR, H5P_DEFAULT);
if (file != H5I_INVALID_HID) {
hid_t group, child;
if ((group = H5Gcreate1(file, "mount_point", H5P_DEFAULT)) != H5I_INVALID_HID) {
if ((child = H5Fopen("f1.h5", H5F_ACC_RDONLY, H5P_DEFAULT)) != H5I_INVALID_HID) {
if (H5Fmount(group, ".", child, H5P_DEFAULT) >= 0) {
// do something useful w/ the mounted file
}
else {
ret_val = EXIT_FAILURE;
perror("H5Fmount failed.");
}
H5Fclose(child);
}
H5Gclose(group);
}
H5Fclose(file);
}
else
ret_val = EXIT_FAILURE;
}
herr_t H5Fmount(hid_t loc_id, const char *name, hid_t child, hid_t plist)
Mounts an HDF5 file.
hid_t H5Gcreate1(hid_t loc_id, const char *name, size_t size_hint)
Creates a new group and links it into the file.
Since
1.0.0

◆ H5Gcreate1()

hid_t H5Gcreate1 ( hid_t  loc_id,
const char *  name,
size_t  size_hint 
)

Creates a new group and links it into the file.


Parameters
[in]loc_idLocation identifier. The identifier may be that of a file, group, dataset, named datatype, or attribute.
[in]nameName of the group to create
[in]size_hintThe number of bytes to reserve for the names that will appear in the group
Returns
Returns a group identifier if successful; otherwise returns H5I_INVALID_HID.
Deprecated:
This function is deprecated in favor of H5Gcreate2().

H5Gcreate1() creates a new group with the specified name at the specified location, loc_id. loc_id may be a file, group, dataset, named datatype or attribute. If an attribute, dataset, or named datatype is specified for loc_id then the group will be created at the location where the attribute, dataset, or named datatype is attached. The name, name, must not already be taken by some other object and all parent groups must already exist.

name can be a relative path based at loc_id or an absolute path from the root of the file. Use of this function requires that any intermediate groups specified in the path already exist.

The length of a group name, or of the name of any object within a group, is not limited.

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. This value must be between 0 and UINT32_MAX (inclusive). If this parameter is zero, a default value will be used.

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.

See H5Gcreate_anon() for a discussion of the differences between H5Gcreate1() and H5Gcreate_anon().

Example
{
hid_t file = H5Fopen("f11.h5", H5F_ACC_RDWR, H5P_DEFAULT);
if (file != H5I_INVALID_HID) {
hid_t group, child;
if ((group = H5Gcreate1(file, "mount_point", H5P_DEFAULT)) != H5I_INVALID_HID) {
if ((child = H5Fopen("f1.h5", H5F_ACC_RDONLY, H5P_DEFAULT)) != H5I_INVALID_HID) {
if (H5Fmount(group, ".", child, H5P_DEFAULT) >= 0) {
// do something useful w/ the mounted file
}
else {
ret_val = EXIT_FAILURE;
perror("H5Fmount failed.");
}
H5Fclose(child);
}
H5Gclose(group);
}
H5Fclose(file);
}
else
ret_val = EXIT_FAILURE;
}
Version
1.8.0 Function H5Gcreate() renamed to H5Gcreate1() and deprecated in this release.
Since
1.0.0

◆ H5Gcreate2()

hid_t H5Gcreate2 ( hid_t  loc_id,
const char *  name,
hid_t  lcpl_id,
hid_t  gcpl_id,
hid_t  gapl_id 
)

Creates a new group and links it into the file.


Parameters
[in]loc_idLocation identifier. The identifier may be that of a file, group, dataset, named datatype, or attribute.
[in]nameName of the group to create
[in]lcpl_idLink creation property list identifier
[in]gcpl_idGroup creation property list identifier
[in]gapl_idGroup access property list identifier
Returns
Returns a group identifier if successful; otherwise returns H5I_INVALID_HID.

H5Gcreate2() creates a new group in a file. After a group has been created, links to datasets and to other groups can be added.

The loc_id and name parameters specify where the group is located. loc_id may be a file, group, dataset, named datatype or attribute in the file. If an attribute, dataset, or named datatype is specified for loc_id then the group will be created at the location where the attribute, dataset, or named datatype is attached. name is the link to the group; name may be either an absolute path in the file (the links from the root group to the new group) or a relative path from loc_id (the link(s) from the group specified by loc_id to the new group).

lcpl_id, gcpl_id, and gapl_id are property list identifiers. These property lists govern how the link to the group is created, how the group is created, and how the group can be accessed in the future, respectively. H5P_DEFAULT can be passed in if the default properties are appropriate for these property lists. Currently, there are no APIs for the group access property list; use H5P_DEFAULT.

The group identifier should be closed by H5Gclose() when access is no longer required to prevent resource leaks.

Since
1.8.0
See also
H5Gopen2()

◆ H5Gcreate_anon()

hid_t H5Gcreate_anon ( hid_t  loc_id,
hid_t  gcpl_id,
hid_t  gapl_id 
)

Creates a new empty group without linking it into the file structure.


Parameters
[in]loc_idLocation identifier. The identifier may be that of a file, group, dataset, named datatype, or attribute.
[in]gcpl_idGroup creation property list identifier
[in]gapl_idGroup access property list identifier
Returns
Returns a group identifier if successful; otherwise returns H5I_INVALID_HID.

H5Gcreate_anon() creates a new empty group in the file specified by loc_id. With default settings, H5Gcreate_anon() provides similar functionality to that provided by H5Gcreate1(), with the differences described in the list below.

The new group's creation and access properties are specified in gcpl_id and gapl_id, respectively.

H5Gcreate_anon() returns a new group identifier. This identifier must be linked into the HDF5 file structure with H5Olink() or it will be deleted from the file when the file is closed.

The differences between this function and H5Gcreate1() are as follows:

  • H5Gcreate1() does not provide for the use of custom property lists; H5Gcreate1() always uses default properties.
  • H5Gcreate_anon() neither provides the new group's name nor links it into the HDF5 file structure; those actions must be performed separately through a call to H5Olink(), which offers greater control over linking.
  • H5Gcreate_anon() does not directly provide a hint mechanism for the group's heap size. Comparable information can be included in the group creation property list gcpl_id through a H5Pset_local_heap_size_hint() call.

A group created with this function should be closed with H5Gclose() when the group is no longer needed so that resource leaks will not develop.

See also
H5Olink(), H5Gcreate()
Since
1.8.0

◆ H5Gflush()

herr_t H5Gflush ( hid_t  group_id)

Flushes all buffers associated with a group to disk.


Parameters
[in]group_idGroup identifier
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Gflush() causes all buffers associated with a group to be immediately flushed to the disk without removing the data from the cache.

Attention
HDF5 does not possess full control over buffering. H5G_FLUSH flushes the internal HDF5 buffers and then asks the operating system (the OS) to flush the system buffers for the open files. After that, the OS is responsible for ensuring that the data is actually flushed to the disk.
Since
1.8.0

◆ H5Gget_comment()

int H5Gget_comment ( hid_t  loc_id,
const char *  name,
size_t  bufsize,
char *  buf 
)

Retrieves comment for specified object.


Parameters
[in]loc_idLocation identifier. The identifier may be that of a file, group, dataset, or named datatype.
[in]nameName of the object whose comment is to be set or reset name must be '.' (dot) if loc_id fully specifies the object for which the comment is to be set.
[in]bufsizeMaximum number of comment characters to be returned in buf.
[in]bufThe 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 a negative value.
Deprecated:
This function is deprecated in favor of the function H5Oget_comment().

H5Gget_comment() retrieves the comment for the object specified by loc_id and name. The comment is returned in the buffer buf.

loc_id can specify any object in the file. name can be one of the following:

  • The name of the object relative to loc_id
  • An absolute name of the object, starting from /, the file's root group
  • A dot (.), if loc_id fully specifies the object

Up to size characters of the comment name are returned in name; additional characters, if any, are not returned to the user application.

If the length of the comment name, which determines the required value of size, is unknown, a preliminary call to H5Gget_comment() with the last two parameters set to NULL and zero respectively can be made. The return value of this call will be the size in bytes of the comment name. That value, plus 1 for a NULL terminator, must then be assigned to size for a second H5Gget_comment() call, which will retrieve the actual comment name.

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

Version
1.8.0 Function deprecated in this release.
Since
1.0.0

◆ H5Gget_create_plist()

hid_t H5Gget_create_plist ( hid_t  group_id)

Gets a group creation property list identifier.


Parameters
[in]group_idGroup identifier
Returns
Returns a creation property list identifier if successful; otherwise returns H5I_INVALID_HID.

H5Gget_create_plist() returns an identifier for the group creation property list associated with the group specified by group_id.

The creation property list identifier should be released with H5Pclose() to prevent resource leaks.

Since
1.8.0

◆ H5Gget_info()

herr_t H5Gget_info ( hid_t  loc_id,
H5G_info_t ginfo 
)

Retrieves information about a group.


Parameters
[in]loc_idLocation identifier. The identifier may be that of a file, group, dataset, named datatype, or attribute.
[out]ginfoStruct in which group information is returned
Returns
Returns a group identifier if successful; otherwise returns H5I_INVALID_HID.

H5Gget_info() retrieves information about the group at location specified by loc_id. The information is returned in the ginfo.

ginfo is an H5G_info_t struct and is defined (in H5Gpublic.h) as follows:

typedef struct H5G_info_t {
int64_t max_corder;
H5G_storage_type_t
Definition H5Gpublic.h:41
uint64_t hsize_t
Definition H5public.h:301
bool hbool_t
Definition H5public.h:253
int64_t max_corder
Definition H5Gpublic.h:58
hbool_t mounted
Definition H5Gpublic.h:59

Possible values of storage_type are:

H5G_STORAGE_TYPE_COMPACTCompact storage
H5G_STORAGE_TYPE_DENSEIndexed storage
H5G_STORAGE_TYPE_SYMBOL_TABLESymbol tables, the original HDF5 structure
Since
1.8.0

◆ H5Gget_info_by_idx()

herr_t H5Gget_info_by_idx ( hid_t  loc_id,
const char *  group_name,
H5_index_t  idx_type,
H5_iter_order_t  order,
hsize_t  n,
H5G_info_t ginfo,
hid_t  lapl_id 
)

Retrieves information about a group, according to the group's position within an index.


Parameters
[in]loc_idLocation identifier. The identifier may be that of a file, group, dataset, named datatype, or attribute.
[in]group_nameName of the group to query
[in]idx_typeTransient index identifying object
[in]orderTransient index identifying object
[in]nPosition in the index of the group to query
[out]ginfoStruct in which group information is returned
[in]lapl_idLink access property list identifier
Returns
Returns
  • The size of the object name if successful, or
  • 0 if no name is associated with the group identifier, or
  • negative value, if failure occurred
H5Gget_info_by_idx() retrieves the same information about a group as retrieved by the function H5Gget_info(), but the means of identifying the group differs; the group is identified by position in an index rather than by name.

loc_id and group_name specify the group containing the group for which information is sought. The groups in group_name are indexed by idx_type; the group for which information is retrieved is identified in that index by index order, order, and index position, n.

If loc_id specifies the group containing the group for which information is queried, group_name can be a dot (.).

Valid values for index_type are as follows:

H5_INDEX_NAMELexicographic order on name
H5_INDEX_CRT_ORDERIndex on creation order

The order in which the index is to be examined, as specified by order, can be one of the following:

H5_ITER_INCIncreasing order
H5_ITER_DECDecreasing order
H5_ITER_NATIVEFastest available order
Since
1.8.0

◆ H5Gget_info_by_name()

herr_t H5Gget_info_by_name ( hid_t  loc_id,
const char *  name,
H5G_info_t ginfo,
hid_t  lapl_id 
)

Retrieves information about a group by its name.


Parameters
[in]loc_idLocation identifier. The identifier may be that of a file, group, dataset, named datatype, or attribute.
[in]nameName of the group to query
[out]ginfoStruct in which group information is returned
[in]lapl_idLink access property list identifier
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Gget_info_by_name() retrieves information about the group name at location specified by loc_id. The information is returned in the ginfo struct.

If loc_id specifies the group for which information is queried, then the group's name can be a dot (.).

ginfo is an H5G_info_t struct and is defined (in H5Gpublic.h) as follows:

Possible values of storage_type are:

H5G_STORAGE_TYPE_COMPACTCompact storage
H5G_STORAGE_TYPE_DENSEIndexed storage
H5G_STORAGE_TYPE_SYMBOL_TABLESymbol tables, the original HDF5 structure
Since
1.8.0

◆ H5Gget_linkval()

herr_t H5Gget_linkval ( hid_t  loc_id,
const char *  name,
size_t  size,
char *  buf 
)

Returns the name of the object that the symbolic link points to.


Parameters
[in]loc_idLocation identifier. The identifier may be that of a file or group.
[in]nameSymbolic link to the object whose name is to be returned
[in]sizeMaximum number of characters of value to be returned
[out]bufA buffer to hold the name of the object being sought
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.
Deprecated:
This function is deprecated in favor of the function H5Lget_val().

H5Gget_linkval() returns up to size characters of the name of the object that the symbolic link name points to.

The parameter loc_id is a file or group identifier.

The parameter name must be a symbolic link pointing to the desired object and must be defined relative to loc_id.

If size is smaller than the size of the returned object name, then the name stored in the buffer value will not be NULL terminated.

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

This function should be used only after H5Lget_info1() (or the deprecated function H5Gget_objinfo()) has been called to verify that name is a symbolic link.

Version
1.8.0 Function deprecated in this release.
Since
1.0.0

◆ H5Gget_num_objs()

herr_t H5Gget_num_objs ( hid_t  loc_id,
hsize_t num_objs 
)

Returns number of objects in the group specified by its identifier.


Parameters
[in]loc_idLocation identifier. The identifier may be that of a file or group.
[out]num_objsNumber of objects in the group
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.
Deprecated:
This function is deprecated in favor of the function H5Gget_info().

H5Gget_num_objs() returns number of objects in a group. Group is specified by its identifier loc_id. If a file identifier is passed in, then the number of objects in the root group is returned.

Version
1.8.0 Function deprecated in this release.
Since
1.6.0

◆ H5Gget_objinfo()

herr_t H5Gget_objinfo ( hid_t  loc_id,
const char *  name,
hbool_t  follow_link,
H5G_stat_t statbuf 
)

Returns information about an object.


Parameters
[in]loc_idLocation identifier. The identifier may be that of a file, group, dataset, or named datatype.
[in]nameName of the object for which status is being sought
[in]follow_linkLink flag
[out]statbufBuffer in which to return information about the object
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.
Deprecated:
This function is deprecated in favor of the functions H5Oget_info() and H5Lget_info1().

H5Gget_objinfo() returns information about the specified object through the statbuf argument.

A file or group identifier, loc_id, and an object name, name, relative to loc_id, are commonly used to specify the object. However, if the object identifier is already known to the application, an alternative approach is to use that identifier, obj_id, in place of loc_id, and a dot (.) in place of name. Thus, the alternative versions of the first portion of an H5Gget_objinfo() call would be as follows:

H5Gget_objinfo (loc_id name ...)
H5Gget_objinfo (obj_id . ...)
herr_t H5Gget_objinfo(hid_t loc_id, const char *name, hbool_t follow_link, H5G_stat_t *statbuf)
Returns information about an object.

If the object is a symbolic link and follow_link is zero (0), then the information returned describes the link itself; otherwise the link is followed and the information returned describes 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 (defined in H5Gpublic.h):

typedef struct H5G_stat_t {
unsigned long fileno[2];
unsigned long objno[2];
unsigned nlink;
time_t mtime;
size_t linklen;
H5G_obj_t
Definition H5Gpublic.h:550
Definition H5Gpublic.h:578
H5G_obj_t type
Definition H5Gpublic.h:582
unsigned nlink
Definition H5Gpublic.h:581
unsigned long fileno[2]
Definition H5Gpublic.h:579
time_t mtime
Definition H5Gpublic.h:583
unsigned long objno[2]
Definition H5Gpublic.h:580
size_t linklen
Definition H5Gpublic.h:584
H5O_stat_t ohdr
Definition H5Gpublic.h:585
Definition H5Opublic.h:1709

where H5O_stat_t (defined in H5Opublic.h) is:

typedef struct H5O_stat_t {
unsigned nmesgs;
unsigned nchunks;
unsigned nmesgs
Definition H5Opublic.h:1712
unsigned nchunks
Definition H5Opublic.h:1713
hsize_t size
Definition H5Opublic.h:1710
hsize_t free
Definition H5Opublic.h:1711
Attention
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).
Version
1.8.0 Function deprecated in this release.
1.6.1 Two new fields were added to the H5G_stat_t struct in this release.
Since
1.0.0

◆ H5Gget_objname_by_idx()

ssize_t H5Gget_objname_by_idx ( hid_t  loc_id,
hsize_t  idx,
char *  name,
size_t  size 
)

Returns the name of an object specified by an index.


Parameters
[in]loc_idLocation identifier. The identifier may be that of a file or group.
[in]idxTransient index identifying object
[in,out]namePointer to user-provided buffer the object name
[in]sizeName length
Returns
Returns the size of the object name if successful, or 0 if no name is associated with the group identifier. Otherwise returns a negative value.
Deprecated:
This function is deprecated in favor of the function H5Lget_name_by_idx().

H5Gget_objname_by_idx() returns the name of the object specified by the index idx in the group loc_id.

The group is specified by a group identifier loc_id. If preferred, a file identifier may be passed in loc_id; that file's root group will be assumed.

idx is the transient index used to iterate through the objects in the group. The value of idx is any nonnegative number less than the total number of objects in the group, which is returned by the function H5Gget_num_objs(). Note that this is a transient index; an object may have a different index each time a group is opened.

The object name is returned in the user-specified buffer name.

If the size of the provided buffer name is less or equal the actual object name length, the object name is truncated to max_size - 1 characters.

Note that if the size of the object's name is unknown, a preliminary call to H5Gget_objname_by_idx() with name set to NULL will return the length of the object's name. A second call to H5Gget_objname_by_idx() can then be used to retrieve the actual name.

Version
1.8.0 Function deprecated in this release.
Since
1.6.0

◆ H5Gget_objtype_by_idx()

H5G_obj_t H5Gget_objtype_by_idx ( hid_t  loc_id,
hsize_t  idx 
)

Returns the type of an object specified by an index.


Parameters
[in]loc_idLocation identifier. The identifier may be that of a file or group.
[in]idxTransient index identifying object
Returns
Returns the type of the object if successful. Otherwise returns a negative value.
Deprecated:
This function is deprecated in favor of the function H5Oget_info().

H5Gget_objtype_by_idx() returns the type of the object specified by the index idx in the group loc_id.

The group is specified by a group identifier loc_id. If preferred, a file identifier may be passed in loc_id; that file's root group will be assumed.

idx is the transient index used to iterate through the objects in the group. This parameter is described in more detail in the discussion of H5Gget_objname_by_idx().

Note
As of 1.12.0, H5Gget_objtype_by_idx() returns the type of the object that the link points to, but it has been deprecated for H5Oget_info(). Previous behavior for this function returned H5G_LINK for any link type. To get the link type, an application may use H5Lget_info_by_idx() instead.
Version
1.8.0 Function deprecated in this release.
1.6.0 The function return type changed from int to the enumerated type H5G_obj_t.
Since
1.6.0

◆ H5Giterate()

herr_t H5Giterate ( hid_t  loc_id,
const char *  name,
int *  idx,
H5G_iterate_t  op,
void *  op_data 
)

Iterates over the entries of a group invoking a callback for each entry encountered.


Parameters
[in]loc_idLocation identifier. The identifier may be that of a file or group.
[in]nameGroup over which the iteration is performed
[in,out]idxLocation at which to begin the iteration
[in]opOperation to be performed on an object at each step of the iteration
[in,out]op_dataData associated with the operation
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.
Deprecated:
This function is deprecated in favor of the function H5Literate1().

H5Giterate() iterates over the members of name in the file or group specified with loc_id. For each object in the group, the op_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. H5Giterate() does not recursively follow links into subgroups of the specified group.

The prototype for H5G_iterate_t is:

typedef herr_t (*H5G_iterate_t)(hid_t group, const char *name, void *op_data);
herr_t(* H5G_iterate_t)(hid_t group, const char *name, void *op_data)
Definition H5Gpublic.h:569
int herr_t
Definition H5public.h:239

The operation receives the group identifier for the group being iterated over, group, the name of the current object within the group, name, and the pointer to the operator data passed into H5Giterate(), op_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.

H5Giterate() assumes that the membership of the group identified by name remains unchanged through the iteration. If the membership changes during the iteration, the function's behavior is undefined.

H5Giterate() is not recursive. In particular, if a member of name is found to be a group, call it subgroup_a, H5Giterate() does not examine the members of subgroup_a. When recursive iteration is required, the application must handle the recursion, explicitly calling H5Giterate() on discovered subgroups.

Warning
Adding or removing members to the group during iteration will lead to undefined behavior.
Version
1.8.0 Function deprecated in this release.
Since
1.0.0

◆ H5Glink()

herr_t H5Glink ( hid_t  cur_loc_id,
H5L_type_t  type,
const char *  cur_name,
const char *  new_name 
)

Creates a link of the specified type from new_name to cur_name.


Parameters
[in]cur_loc_idLocation identifier. The identifier may be that of a file or group.
[in]typeLink type
[in]cur_nameName of the existing object
[in]new_nameNew name for the object
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.
Deprecated:
This function is deprecated.

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 cur_name must specify the name of an existing object and both names are interpreted relative to cur_loc_id, which is either a file identifier or a group identifier.

If link_type is H5G_LINK_SOFT, then cur_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 cur_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.

Version
1.8.0 Function deprecated in this release.
Since
1.0.0

◆ H5Glink2()

herr_t H5Glink2 ( hid_t  cur_loc_id,
const char *  cur_name,
H5L_type_t  type,
hid_t  new_loc_id,
const char *  new_name 
)

Creates a link of the specified type from cur_name to new_name.


Parameters
[in]cur_loc_idLocation identifier. The identifier may be that of a file or group.
[in]cur_nameName of the existing object
[in]typeLink type
[in]new_loc_idLocation identifier. The identifier may be that of a file or group.
[in]new_nameNew name for the object
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.
Deprecated:
This function is deprecated.

H5Glink2() 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 cur_name must specify the name of an existing object and both names are interpreted relative to cur_loc_id and new_loc_id, respectively, which are either file identifiers or group identifiers.

If link_type is H5G_LINK_SOFT, then cur_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.

Version
1.8.0 Function deprecated in this release.
Since
1.6.0

◆ H5Gmove()

herr_t H5Gmove ( hid_t  src_loc_id,
const char *  src_name,
const char *  dst_name 
)

Renames an object within an HDF5 file.


Parameters
[in]src_loc_idLocation identifier. The identifier may be that of a file or group.
[in]src_nameObject's original name
[in]dst_nameObject's new name
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.
Deprecated:
This function is deprecated.

H5Gmove() renames an object within an HDF5 file. The original name, src_name, is unlinked from the group graph and the new name, dst_name, is inserted as an atomic operation. Both names are interpreted relative to loc_id, which is either a file or a group identifier.

Attention
Exercise care in moving groups as it is possible to render data in a file inaccessible with H5Gmove(). See The Group Interface in the HDF5 User Guide.
Version
1.8.0 Function deprecated in this release.
Since
1.0.0

◆ H5Gmove2()

herr_t H5Gmove2 ( hid_t  src_loc_id,
const char *  src_name,
hid_t  dst_loc_id,
const char *  dst_name 
)

Renames an object within an HDF5 file.


Parameters
[in]src_loc_idLocation identifier. The identifier may be that of a file or group.
[in]src_nameObject's original name
[in]dst_loc_idLocation identifier. The identifier may be that of a file or group.
[in]dst_nameObject's new name
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.
Deprecated:
This function is deprecated.

H5Gmove2() renames an object within an HDF5 file. The original name, src_name, is unlinked from the group graph and the new name, dst_name, is inserted as an atomic operation.

src_name and dst_name are interpreted relative to src_loc_id and dst_loc_id, respectively, which are either file or group identifiers.

Attention
Exercise care in moving groups as it is possible to render data in a file inaccessible with H5Gmove2(). See The Group Interface in the HDF5 User Guide.
Version
1.8.0 Function deprecated in this release.
Since
1.6.0

◆ H5Gopen1()

hid_t H5Gopen1 ( hid_t  loc_id,
const char *  name 
)

Opens an existing group for modification and returns a group identifier for that group.


Parameters
[in]loc_idLocation identifier. The identifier may be that of a file, group, dataset, named datatype, or attribute.
[in]nameName of the group to open
Returns
Returns a group identifier if successful; otherwise returns H5I_INVALID_HID.
Deprecated:
This function is deprecated in favor of H5Gopen2().

H5Gopen1() opens an existing group, name, at the location specified by loc_id.

H5Gopen1() returns a group identifier for the group that was opened. This group identifier should be released by calling H5Gclose() when it is no longer needed.

Version
1.8.0 The function H5Gopen() was renamed to H5Gopen1() and deprecated in this release.
Since
1.0.0

◆ H5Gopen2()

hid_t H5Gopen2 ( hid_t  loc_id,
const char *  name,
hid_t  gapl_id 
)

Opens an existing group in a file.


Parameters
[in]loc_idLocation identifier. The identifier may be that of a file, group, dataset, named datatype, or attribute.
[in]nameName of the group to open
[in]gapl_idGroup access property list identifier
Returns
Returns a group identifier if successful; otherwise returns H5I_INVALID_HID.

H5Gopen2() opens an existing group, name, at the location specified by loc_id.

With default settings, H5Gopen2() provides similar functionality to that provided by H5Gopen(). The only difference is that H5Gopen2() can provide a group access property list, gapl_id.

H5Gopen2() returns a group identifier for the group that was opened. This group identifier should be released by H5Gclose() when it is no longer needed to prevent resource leaks.

Since
1.8.0
See also
H5Gcreate2()

◆ H5Grefresh()

herr_t H5Grefresh ( hid_t  group_id)

Refreshes all buffers associated with a group.


Parameters
[in]group_idGroup identifier
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Grefresh() causes all buffers associated with a group to be cleared and immediately re-loaded with updated contents from disk.

This function essentially closes the group, evicts all metadata associated with it from the cache, and then reopens the group. The reopened group is automatically re-registered with the same identifier.

Since
1.8.0

◆ H5Gset_comment()

herr_t H5Gset_comment ( hid_t  loc_id,
const char *  name,
const char *  comment 
)

Sets comment for specified object.


Parameters
[in]loc_idLocation identifier. The identifier may be that of a file, group, dataset, or named datatype.
[in]nameName of the object whose comment is to be set or reset name must be '.' (dot) if loc_id fully specifies the object for which the comment is to be set.
[in]commentThe new comment
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.
Deprecated:
This function is deprecated in favor of the function H5Oset_comment().

H5Gset_comment() sets the comment for the object specified by loc_id and name to comment. Any previously existing comment is overwritten.

loc_id can specify any object in the file. name can be one of the following:

  • The name of the object relative to loc_id
  • An absolute name of the object, starting from /, the file's root group
  • A dot (.), if loc_id fully specifies the object

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., datasets, groups, and named datatypes, but not symbolic links.

Version
1.8.0 Function deprecated in this release.
Since
1.0.0

◆ H5Gunlink()

herr_t H5Gunlink ( hid_t  loc_id,
const char *  name 
)

Removes the link to an object from a group.


Parameters
[in]loc_idLocation identifier. The identifier may be that of a file or group.
[in]nameName of the object to unlink
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.
Deprecated:
This function is deprecated in favor of the function H5Ldelete().

H5Gunlink() removes the object specified by name from the group graph and decrements the link count for the object to which name points. This action eliminates any association between name and the object to which name pointed.

Object headers keep track of how many hard links refer to an object; when the 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 released, i.e., identified in memory as freespace. If any object identifier is open for the object, the space will not be released until after the object identifier is closed.

Note that space identified as freespace is available for reuse only as long as the file remains open; once a file has been closed, the HDF5 library loses track of freespace. See “Freespace Management” in the HDF5 User Guide for further details.

Attention
Exercise care in moving groups as it is possible to render data in a file inaccessible with H5Gunlink(). See The Group Interface in the HDF5 User Guide.
Version
1.8.0 Function deprecated in this release.
Since
1.0.0