summaryrefslogtreecommitdiffstats
path: root/doc/html/Tutor/crtgrpar.html
blob: d5fbc66340f0366c42259f45897ae27272cc352c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<HTML><HEAD>
<TITLE>HDF5 Tutorial - Creating Groups using Absolute/Relative Names
</TITLE> 
</HEAD>

<body bgcolor="#ffffff">

<!-- BEGIN MAIN BODY -->

<A HREF="http://www.ncsa.uiuc.edu/"><img border=0 
src="http://www.ncsa.uiuc.edu/Images/NCSAhome/footerlogo.gif"
width=78 height=27 alt="NCSA"><P></A>

 [ <A HREF="title.html"><I>HDF5 Tutorial Top</I></A> ]
<H1>
<BIG><BIG><BIG><FONT COLOR="#c101cd">Creating Groups using 
Absolute/Relative Names</FONT>
</BIG></BIG></BIG></H1>

<hr noshade size=1>

<BODY>
<H2>Contents:</H2>
<UL>
    <LI> <A HREF="#def">Absolute vs. Relative Names</A>
    <LI> Programming Example 
    <UL>
      <LI> <A HREF="#desc">Description</A> 
      <LI> <A HREF="#rem">Remarks</A> 
      <LI> <A HREF="#fc">File Contents</A>
    </UL>
</UL>
<HR>
<A NAME="def">
<H2>Absolute vs. Relative Names</h2>
<P>
Recall that to create an HDF5 object, we have to specify the location where the
object is to be created. This location is determined by the identifier of an HDF5
object and the name of the object to be created. The name of the created
object can be either an absolute name or a name relative to the specified 
identifier.
In Example 5, we used the file identifier and the absolute name "/MyGroup" to create a
group. The file identifier and the name "/" specifies the location where the group
"MyGroup" was created.
<P>
In this section, we discuss HDF5 names and show how to use absolute/relative
names by giving an example of creating groups in a file.

<H3>Names</H3>

HDF5 object names are a slash-separated list of components. There are few
restrictions on names: component names may be any length except zero and may
contain any character except slash ("/") and the null terminator. A full name
may be composed of any number of component names separated by slashes, with any
of the component names being the special name ".". A name which begins with a
slash is an absolute name which is accessed beginning with the root group of the
file while all other relative names are accessed beginning with the specified
group. Multiple consecutive slashes in a full name are treated as single slashes
and trailing slashes are not significant. A special case is the name "/" (or
equivalent) which refers to the root group.
<P>
Functions which operate on names generally take a location identifier which
is either a file ID or a group ID and perform the lookup with respect to that
location. Some possibilities are:

<table width="67%" border="1" bordercolor="#000000" cellpadding="4">
  <tr bgcolor="#ffcc99" bordercolor="#FFFFFF"> 
    <td><b> Location Type </b></td>
    <td><b>Object Name</b></td>
    <td><b>Description</b></td>
  </tr>
  <tr bordercolor="#FFFFFF"> 
    <td bgcolor="#99cccc" height="22">File ID</td>
    <td height="22" bgcolor="#CCCCCC"> 
      <div align="center">/foo/bar</div>
    </td>
    <td height="22">The object bar in group foo in the root group. </td>
  </tr>
  <tr bordercolor="#FFFFFF"> 
    <td bgcolor="#99cccc">Group ID </td>
    <td bgcolor="#CCCCCC"> 
      <div align="center">/foo/bar</div>
    </td>
    <td>The object bar in group foo in the root group of the file containing the 
      specified group. In other words, the group ID's only purpose is to supply 
      a file. </td>
  </tr>
  <tr bordercolor="#FFFFFF"> 
    <td bgcolor="#99cccc">File ID</td>
    <td bgcolor="#CCCCCC"> 
      <div align="center">/</div>
    </td>
    <td>The root group of the specified file.</td>
  </tr>
  <tr bordercolor="#FFFFFF"> 
    <td bgcolor="#99cccc">Group ID</td>
    <td bgcolor="#CCCCCC"> 
      <div align="center">/</div>
    </td>
    <td>The root group of the file containing the specified group.</td>
  </tr>
  <tr bordercolor="#FFFFFF"> 
    <td bgcolor="#99cccc">Group ID</td>
    <td bgcolor="#CCCCCC"> 
      <div align="center">foo/bar</div>
    </td>
    <td>The object bar in group foo in the specified group.</td>
  </tr>
  <tr bordercolor="#FFFFFF"> 
    <td bgcolor="#99cccc">File ID</td>
    <td bgcolor="#CCCCCC"> 
      <div align="center">.</div>
    </td>
    <td>The root group of the file.</td>
  </tr>
  <tr bordercolor="#FFFFFF"> 
    <td bgcolor="#99cccc">Group ID</td>
    <td bgcolor="#CCCCCC"> 
      <div align="center">.</div>
    </td>
    <td>The specified group.</td>
  </tr>
  <tr bordercolor="#FFFFFF"> 
    <td bgcolor="#99cccc">Other ID</td>
    <td bgcolor="#CCCCCC"> 
      <div align="center">.</div>
    </td>
    <td>The specified object.</td>
  </tr>
</table>


<P>
<H2> Programming Example</H2>
<A NAME="desc">
<H3><U>Description</U></H3>      
The following example code shows how to create groups using absolute
and relative names. It creates three groups: the first two groups are
created using the file identifier and the group absolute names, and the 
third group is created using a group identifier and the name relative 
to the specified group. <BR>
[ <A HREF="examples/h5_crtgrpar.c">Download h5_crtgrpar.c</A> ]

<PRE>

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

#include &lt;hdf5.h&gt;
#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);
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
</PRE>


<A NAME="rem">
<H3><U>Remarks</U></H3>
<UL>
<LI> H5Gcreate creates a group at the location specified by a location ID and a
   name. The location ID can be a file ID or a group ID and the name can be
   relative or absolute.

<LI> The first H5Gcreate creates the group 'MyGroup' in the root group of the
   specified file.

<LI> The second H5Gcreate creates the group 'Group_A' in the group 'MyGroup'
   in the root group of the specified file. Note that the parent group (MyGroup)
   already exists.

<LI> The third H5Gcreate creates the group 'Group_B' in the specified group.
</UL>
<A NAME="fc">
<H3><U>File Contents</U></H3>
The file contents are shown below:
<P>
<B>Fig. 9.1</B>  &nbsp; <I>The Contents of 'groups.h5'</I>
<P>
<!--<IMG src="groupsh5.jpg" width="285" height="383"></P> -->
<IMG src="img004.gif"></P>


     <B> Fig. 9.2</B> &nbsp; <I>'groups.h5' in DDL</I>
<PRE>

      HDF5 "groups.h5" {
      GROUP "/" {
         GROUP "MyGroup" {
            GROUP "Group_A" {
            }
            GROUP "Group_B" {
            }
         }
      }
      }

</PRE>

<!-- BEGIN FOOTER INFO -->

<P><hr noshade size=1>
<font face="arial,helvetica" size="-1">
  <a href="http://www.ncsa.uiuc.edu/"><img border=0
     src="http://www.ncsa.uiuc.edu/Images/NCSAhome/footerlogo.gif"
     width=78 height=27 alt="NCSA"><br>
  The National Center for Supercomputing Applications</A><br>
  <a href="http://www.uiuc.edu/">University of Illinois
    at Urbana-Champaign</a><br>
  <br>
<!-- <A HREF="helpdesk.mail.html"> -->
<A HREF="mailto:hdfhelp@ncsa.uiuc.edu">
hdfhelp@ncsa.uiuc.edu</A>
<BR> <H6>Last Modified: August 27, 1999</H6><BR>
<!-- modified by Barbara Jones - bljones@ncsa.uiuc.edu -->
</FONT>
<BR>
<!-- <A HREF="mailto:hdfhelp@ncsa.uiuc.edu"> -->

</BODY>
</HTML>