1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright by The HDF Group. *
3 * Copyright by the Board of Trustees of the University of Illinois. *
4 * All rights reserved. *
5 * *
6 * This file is part of HDF5. The full HDF5 copyright notice, including *
7 * terms governing use, modification, and redistribution, is contained in *
8 * the COPYING file, which can be found at the root of the source code *
9 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
10 * If you do not have access to either file, you may request a copy from *
11 * help@hdfgroup.org. *
12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13
14 /*
15 * Programmer: Quincey Koziol <koziol@ncsa.uiuc.edu>
16 * Friday, June 30, 2006
17 *
18 * This program creates an object with fragmented object header messages
19 * that will be merged when the object is read from the file. This program
20 * needs to be compiled against the 1.6.5 or earlier version of the library
21 * in order to generate the file as desired.
22 */
23
24 #include <assert.h>
25 #include <stdio.h>
26 #include "hdf5.h"
27
28 #define FILENAME "mergemsg.h5"
29 #define GROUP1 "grp1"
30 #define GROUP2 "grp2"
31 #define GROUP3 "grp3"
32 #define ATTR1 "__111111111111__"
33 #define ATTR1_LEN 11
34 #define ATTR2 "__222222222__"
35 #define ATTR2_LEN 11
36 #define ATTR3 "__333333333__"
37 #define ATTR3_LEN 1
38
main()39 int main()
40 {
41 hid_t fid; /* File ID */
42 hid_t gid, gid2, gid3; /* Group IDs */
43 hid_t aid; /* Attribute ID */
44 hid_t sid; /* Dataspace ID */
45 hid_t tid; /* Datatype ID */
46 herr_t ret; /* Generic return value */
47
48 /* Create file */
49 fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
50 assert(fid > 0);
51
52 /* Create first group */
53 gid = H5Gcreate2(fid, GROUP1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
54 assert(gid > 0);
55
56 /* Close first group */
57 ret = H5Gclose(gid);
58 assert(ret >= 0);
59
60 /* Create second group */
61 gid2 = H5Gcreate2(fid, GROUP2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
62 assert(gid2 > 0);
63
64 /* Close second group */
65 ret = H5Gclose(gid2);
66 assert(ret >= 0);
67
68 /* Close file */
69 ret = H5Fclose(fid);
70 assert(ret >= 0);
71
72
73 /* Re-open file */
74 fid = H5Fopen(FILENAME, H5F_ACC_RDWR, H5P_DEFAULT);
75 assert(fid > 0);
76
77 /* Re-open first group */
78 gid = H5Gopen2(fid, GROUP1, H5P_DEFAULT);
79 assert(gid > 0);
80
81 /* Create dataspace for attribute */
82 sid = H5Screate(H5S_SCALAR);
83 assert(sid > 0);
84
85 /* Create dataype for attribute */
86 tid = H5Tcopy(H5T_C_S1);
87 assert(tid > 0);
88 ret = H5Tset_size(tid, ATTR1_LEN);
89 assert(ret >= 0);
90
91 /* Add 1st attribute on first group */
92 aid = H5Acreate2(gid, ATTR1, tid, sid, H5P_DEFAULT, H5P_DEFAULT);
93 assert(aid > 0);
94
95 /* Close dataspace */
96 ret = H5Sclose(sid);
97 assert(ret >= 0);
98
99 /* Close datatype */
100 ret = H5Tclose(tid);
101 assert(ret >= 0);
102
103 /* Close attribute */
104 ret = H5Aclose(aid);
105 assert(ret >= 0);
106
107 /* Create dataspace for 2nd attribute */
108 sid = H5Screate(H5S_SCALAR);
109 assert(sid > 0);
110
111 /* Create dataype for attribute */
112 tid = H5Tcopy(H5T_C_S1);
113 assert(tid > 0);
114 ret = H5Tset_size(tid, ATTR2_LEN);
115 assert(ret >= 0);
116
117 /* Add 2nd attribute on first group */
118 aid = H5Acreate2(gid, ATTR2, tid, sid, H5P_DEFAULT, H5P_DEFAULT);
119 assert(aid > 0);
120
121 /* Close dataspace */
122 ret = H5Sclose(sid);
123 assert(ret >= 0);
124
125 /* Close datatype */
126 ret = H5Tclose(tid);
127 assert(ret >= 0);
128
129 /* Close 2nd attribute */
130 ret = H5Aclose(aid);
131 assert(ret >= 0);
132
133 /* Close first group */
134 ret = H5Gclose(gid);
135 assert(ret >= 0);
136
137 /* Close file */
138 ret = H5Fclose(fid);
139 assert(ret >= 0);
140
141
142 /* Re-open file */
143 fid = H5Fopen(FILENAME, H5F_ACC_RDWR, H5P_DEFAULT);
144 assert(fid > 0);
145
146 /* Create third group */
147 gid3 = H5Gcreate2(fid, GROUP3, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
148 assert(gid3 > 0);
149
150 /* Close third group */
151 ret = H5Gclose(gid3);
152 assert(ret >= 0);
153
154 /* Re-open first group */
155 gid = H5Gopen2(fid, GROUP1, H5P_DEFAULT);
156 assert(gid > 0);
157
158 /* Delete 2nd attribute */
159 ret = H5Adelete(gid, ATTR2);
160 assert(ret >= 0);
161
162 /* Close first group */
163 ret = H5Gclose(gid);
164 assert(ret >= 0);
165
166 /* Close file */
167 ret = H5Fclose(fid);
168 assert(ret >= 0);
169
170
171
172
173 /* Re-open file */
174 fid = H5Fopen(FILENAME, H5F_ACC_RDWR, H5P_DEFAULT);
175 assert(fid > 0);
176
177 /* Re-open first group */
178 gid = H5Gopen2(fid, GROUP1, H5P_DEFAULT);
179 assert(gid > 0);
180
181 /* Create dataspace for 3rd attribute */
182 sid = H5Screate(H5S_SCALAR);
183 assert(sid > 0);
184
185 /* Create dataype for attribute */
186 tid = H5Tcopy(H5T_C_S1);
187 assert(tid > 0);
188 ret = H5Tset_size(tid, ATTR3_LEN);
189 assert(ret >= 0);
190
191 /* Add 3rd attribute on first group (smaller than 2nd attribute) */
192 aid = H5Acreate2(gid, ATTR3, tid, sid, H5P_DEFAULT, H5P_DEFAULT);
193 assert(aid > 0);
194
195 /* Close dataspace */
196 ret = H5Sclose(sid);
197 assert(ret >= 0);
198
199 /* Close datatype */
200 ret = H5Tclose(tid);
201 assert(ret >= 0);
202
203 /* Close 3rd attribute */
204 ret = H5Aclose(aid);
205 assert(ret >= 0);
206
207 /* Close first group */
208 ret = H5Gclose(gid);
209 assert(ret >= 0);
210
211 /* Close file */
212 ret = H5Fclose(fid);
213 assert(ret >= 0);
214
215
216
217 /* Re-open file */
218 fid = H5Fopen(FILENAME, H5F_ACC_RDWR, H5P_DEFAULT);
219 assert(fid > 0);
220
221 /* Re-open first group */
222 gid = H5Gopen2(fid, GROUP1, H5P_DEFAULT);
223 assert(gid > 0);
224
225 /* Delete 3rd attribute */
226 ret = H5Adelete(gid, ATTR3);
227 assert(ret >= 0);
228
229 /* Create dataspace for 3rd attribute */
230 sid = H5Screate(H5S_SCALAR);
231 assert(sid > 0);
232
233 /* Create dataype for attribute */
234 tid = H5Tcopy(H5T_C_S1);
235 assert(tid > 0);
236 ret = H5Tset_size(tid, ATTR2_LEN);
237 assert(ret >= 0);
238
239 /* Re-create 2nd attribute on first group */
240 aid = H5Acreate2(gid, ATTR2, tid, sid, H5P_DEFAULT, H5P_DEFAULT);
241 assert(aid > 0);
242
243 /* Close dataspace */
244 ret = H5Sclose(sid);
245 assert(ret >= 0);
246
247 /* Close datatype */
248 ret = H5Tclose(tid);
249 assert(ret >= 0);
250
251 /* Close 2nd attribute */
252 ret = H5Aclose(aid);
253 assert(ret >= 0);
254
255 /* Close first group */
256 ret = H5Gclose(gid);
257 assert(ret >= 0);
258
259 /* Close file */
260 ret = H5Fclose(fid);
261 assert(ret >= 0);
262
263
264 /* Re-open file */
265 fid = H5Fopen(FILENAME, H5F_ACC_RDWR, H5P_DEFAULT);
266 assert(fid > 0);
267
268 /* Re-open first group */
269 gid = H5Gopen2(fid, GROUP1, H5P_DEFAULT);
270 assert(gid > 0);
271
272 /* Delete 2nd attribute */
273 ret = H5Adelete(gid, ATTR2);
274 assert(ret >= 0);
275
276 /* Close first group */
277 ret = H5Gclose(gid);
278 assert(ret >= 0);
279
280 /* Close file */
281 ret = H5Fclose(fid);
282 assert(ret >= 0);
283
284
285 /* Re-open file */
286 fid = H5Fopen(FILENAME, H5F_ACC_RDWR, H5P_DEFAULT);
287 assert(fid > 0);
288
289 /* Re-open first group */
290 gid = H5Gopen2(fid, GROUP1, H5P_DEFAULT);
291 assert(gid > 0);
292
293 /* Create dataspace for 3rd attribute */
294 sid = H5Screate(H5S_SCALAR);
295 assert(sid > 0);
296
297 /* Create dataype for attribute */
298 tid = H5Tcopy(H5T_C_S1);
299 assert(tid > 0);
300 ret = H5Tset_size(tid, ATTR2_LEN);
301 assert(ret >= 0);
302
303 /* Re-create 2nd attribute on first group */
304 aid = H5Acreate2(gid, ATTR2, tid, sid, H5P_DEFAULT, H5P_DEFAULT);
305 assert(aid > 0);
306
307 /* Close dataspace */
308 ret = H5Sclose(sid);
309 assert(ret >= 0);
310
311 /* Close datatype */
312 ret = H5Tclose(tid);
313 assert(ret >= 0);
314
315 /* Close 2nd attribute */
316 ret = H5Aclose(aid);
317 assert(ret >= 0);
318
319 /* Close first group */
320 ret = H5Gclose(gid);
321 assert(ret >= 0);
322
323 /* Close file */
324 ret = H5Fclose(fid);
325 assert(ret >= 0);
326
327 return(0);
328 }
329
330
331