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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
|
<HTML><HEAD>
<TITLE>HDF5 Tutorial - Creating an Attribute
</TITLE>
</HEAD>
<body bgcolor="#ffffff">
<!-- BEGIN MAIN BODY -->
[ <A HREF="title.html"><I>HDF5 Tutorial Top</I></A> ]
<H1>
<BIG><BIG><BIG><FONT COLOR="#c101cd">Creating an Attribute</FONT>
</BIG></BIG></BIG></H1>
<hr noshade size=1>
<BODY>
<H2>Contents:</H2>
<UL>
<LI> <A HREF="#def">What is an Attribute</A>?
<LI> Programming Example
<UL>
<LI> <A HREF="#desc">Description</A>
<LI> <A HREF="#rem">Remarks</A>
<LI> <A HREF="#fc">File Contents</A>
<LI> <A HREF="#ddl">Attribute Definition in DDL</A>
</UL>
</UL>
<HR>
<A NAME="def">
<H2>What is an Attribute?</h2>
<P>
Attributes are small datasets that can be used to describe the nature and/or
the intended usage of the object they are attached to. In this section, we
show how to create, read, and write an attribute.
<P>
<P>
<H3>Creating an attribute</H3>
<P>
Creating an attribute is similar to creating a dataset. To create an
attribute, the application must specify the object which the attribute is
attached to, the datatype and dataspace of the attribute data,
and the attribute creation property list.
<P>
The steps to create an attribute are as follows:
<OL>
<LI> Obtain the object identifier that the attribute is to be attached to.
<LI> Define the characteristics of the attribute and specify the
attribute creation property list.
<UL>
<LI> Define the datatype.
<LI> Define the dataspace.
<LI> Specify the attribute creation property list.
</UL>
<LI> Create the attribute.
<LI> Close the attribute and datatype, dataspace, and
attribute creation property list, if necessary.
</OL>
<P>
To create and close an attribute, the calling program must use
<code>H5Acreate</code>/<code>h5acreate_f</code> and
<code>H5Aclose</code>/<code>h5aclose_f</code>. For example:
<P>
<I>C</I>:
<PRE>
attr_id = H5Acreate (dset_id, attr_name, type_id, space_id, creation_prp);
status = H5Aclose (attr_id);
</PRE>
<I>FORTRAN</I>:
<PRE>
CALL h5acreate_f (dset_id, attr_nam, type_id, space_id, attr_id, &
hdferr, creation_prp=creat_plist_id)
<i>or</i>
CALL h5acreate_f (dset_id, attr_nam, type_id, space_id, attr_id, hdferr)
CALL h5aclose_f (attr_id, hdferr)
</PRE>
<H3>Reading/Writing an attribute</H3>
<P>
Attributes may only be read or written as an entire object; no partial I/O is
supported. Therefore, to perform I/O operations on an attribute, the
application needs only to specify the attribute and the attribute's memory
datatype.
<P>
The steps to read or write an attribute are as follows.
<OL>
<LI> Obtain the attribute identifier.
<LI> Specify the attribute's memory datatype.
<LI> Perform the desired operation.
<LI> Close the memory datatype if necessary.
</OL>
<P>
To read and/or write an attribute, the calling program must contain the
<code>H5Aread</code>/<code>h5aread_f</code> and/or
<code>H5Awrite</code>/<code>h5awrite_f</code> routines. For example:
<P>
<I>C</I>:
<PRE>
status = H5Aread (attr_id, mem_type_id, buf);
status = H5Awrite (attr_id, mem_type_id, buf);
</PRE>
<I>FORTRAN</I>:
<PRE>
CALL h5awrite_f (attr_id, mem_type_id, buf, hdferr)
CALL h5aread_f (attr_id, mem_type_id, buf, hdferr)
</PRE>
<P>
<H2> Programming Example</H2>
<A NAME="desc">
<H3><U>Description</U></H3>
This example shows how to create and write a dataset attribute.
It opens an existing file <code>dset.h5</code> in C
(<code>dsetf.h5</code> in FORTRAN),
obtains the identifier of the dataset <code>/dset</code>,
defines the attribute's dataspace, creates the dataset attribute, writes
the attribute, and then closes the attribute's dataspace, attribute, dataset,
and file. <BR>
<UL>
[ <A HREF="examples/h5_crtatt.c">C Example </A> ] - <code>h5_crtatt.c</code><BR>
[ <A HREF="examples/attrexample.f90">FORTRAN Example</A> ] - <code>attrexample.f90</code><BR>
[ <A HREF="examples/java/CreateAttribute.java">Java Example </A> ]
- <code>CreateAttribute.java</code><BR>
</UL>
<B>NOTE:</B> To download a tar file of the examples, including a Makefile,
please go to the <A HREF="references.html">References</A> page.
<A NAME="rem">
<H3><U>Remarks</U></H3>
<UL>
<LI><code>H5Acreate</code>/<code>h5acreate_f</code> creates an attribute
which is attached to the object specified by the first parameter,
and returns an identifier.
<P>
<I>C</I>:
<PRE>
hid_t H5Acreate (hid_t obj_id, const char *name, hid_t type_id,
hid_t space_id, hid_t creation_prp)
</PRE>
<I>FORTRAN</I>:
<PRE>
h5acreate_f (obj_id, name, type_id, space_id, attr_id, &
hdferr, creation_prp)
obj_id INTEGER(HID_T)
name CHARACTER(LEN=*)
type_id INTEGER(HID_T)
space_id INTEGER(HID_T)
attr_id INTEGER(HID_T)
hdferr INTEGER
(Possible values: 0 on success and -1 on failure)
creation_prp INTEGER(HID_T), OPTIONAL
</PRE>
<UL>
<LI> The <I>obj_id</I> parameter is the identifier of the object that
the attribute is attached to.
<P>
<LI> The <I>name</I> parameter is the name of the attribute to create.
<P>
<LI> The <I>type_id</I> parameter is the identifier of the
attribute's datatype.
<P>
<LI> The <I>space_id</I> parameter is the identifier of the attribute's
dataspace.
<P>
<LI> The <I>creation_prp</I> parameter is the creation property list
identifier.
<code>H5P_DEFAULT</code> in C (<code>H5P_DEFAULT_F</code> in FORTRAN)
specifies the default creation property list.
This parameter is optional in FORTRAN; when it is omitted,
the default creation property list is used.
<P>
<LI> In FORTRAN, the return code for this call is returned in <I>hdferr</I>:
0 if successful, -1 if not. The attribute identifier is returned
in <I>attr_id</I>. In C, the function returns the
attribute identifier if successful and a negative value if not.
</UL>
<P>
<LI><code>H5Awrite</code>/<code>h5awrite_f</code> writes the entire attribute,
and returns the status of the write.
<P>
<I>C</I>:
<PRE>
herr_t H5Awrite (hid_t attr_id, hid_t mem_type_id, void *buf)
</PRE>
<I>FORTRAN</I>:
<PRE>
h5awrite_f (attr_id, mem_type_id, buf, hdferr)
attr_id INTEGER(HID_T)
memtype_id INTEGER(HID_T)
buf TYPE(VOID)
hdferr INTEGER
(Possible values: 0 on success and -1 on failure)
</PRE>
<UL>
<LI> The <I>attr_id</I> parameter is the identifier of the attribute
to write.
<P>
<LI> The <I>mem_type_id</I> parameter is the identifier of the
attribute's memory datatype.
<P>
<LI> The <I>buf</I> parameter is the data buffer to write out.
<P>
<LI>In C, this function returns a non-negative value if successful and
a negative value, otherwise. In FORTRAN, the return value is in the
<I>hdferr</I> parameter: 0 if successful, -1 otherwise.
</UL>
<P>
<LI> When an attribute is no longer accessed by a program,
<code>H5Aclose</code>/<code>h5aclose_f</code> must be called
to release the attribute from use.
The C routine returns a non-negative value if successful;
otherwise it returns a negative value.
In FORTRAN, the return value is in the <I>hdferr</I> parameter:
0 if successful, -1 otherwise.
<P>
<I>C</I>:
<pre>
herr_t H5Aclose (hid_t attr_id)
</pre>
<I>FORTRAN</I>:
<pre>
h5aclose_f (attr_id, hdferr)
attr_id INTEGER(HID_T)
hdferr INTEGER
(Possible values: 0 on success and -1 on failure)
</pre>
<ul>
<li> An <code>H5Aclose</code>/<code>h5aclose_f</code> call is mandatory.
</ul>
</UL>
<A NAME="fc">
<H3><U>File Contents</U></H3>
<P>
The contents of <code>dset.h5</code> (<code>dsetf.h5</code> for FORTRAN) and the
attribute definition are shown below:
<P>
<B>Fig. 7.1a</B> <I><code>dset.h5</code> in DDL</I>
<PRE>
HDF5 "dset.h5" {
GROUP "/" {
DATASET "dset" {
DATATYPE { H5T_STD_I32BE }
DATASPACE { SIMPLE ( 4, 6 ) / ( 4, 6 ) }
DATA {
1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24
}
ATTRIBUTE "attr" {
DATATYPE { H5T_STD_I32BE }
DATASPACE { SIMPLE ( 2 ) / ( 2 ) }
DATA {
100, 200
}
}
}
}
}
</PRE>
<B>Fig. 7.1b</B> <I><code>dsetf.h5</code> in DDL</I>
<PRE>
HDF5 "dsetf.h5" {
GROUP "/" {
DATASET "dset" {
DATATYPE { H5T_STD_I32BE }
DATASPACE { SIMPLE ( 6, 4 ) / ( 6, 4 ) }
DATA {
1, 7, 13, 19,
2, 8, 14, 20,
3, 9, 15, 21,
4, 10, 16, 22,
5, 11, 17, 23,
6, 12, 18, 24
}
ATTRIBUTE "attr" {
DATATYPE { H5T_STD_I32BE }
DATASPACE { SIMPLE ( 2 ) / ( 2 ) }
DATA {
100, 200
}
}
}
}
}
</PRE>
<A NAME="ddl">
<h3><U>Attribute Definition in DDL</U></H3>
<B>Fig. 7.2</B> <I>HDF5 Attribute Definition</I>
<PRE>
<attribute> ::= ATTRIBUTE "<attr_name>" { <datatype>
<dataspace>
<data> }
</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="footer-ncsalogo.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>
<BR> <H6>Last Modified: June 22, 2001</H6><BR>
<!-- modified by Barbara Jones - bljones@ncsa.uiuc.edu -->
</FONT>
<BR>
<!-- <A HREF="mailto:hdfhelp@ncsa.uiuc.edu"> -->
</BODY>
</HTML>
|