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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
|
/****************************************************************************
* NCSA HDF *
* Software Development Group *
* National Center for Supercomputing Applications *
* University of Illinois at Urbana-Champaign *
* 605 E. Springfield, Champaign IL 61820 *
* *
* For conditions of distribution and use, see the accompanying *
* hdf/COPYING file. *
* *
****************************************************************************/
#ifdef RCSID
static char RcsId[] = "@(#)$Revision$";
#endif
/* $Id$ */
/*LINTLIBRARY */
/*+
FILE
hdf5file.c
HDF5 "personality template" routines
EXPORTED ROUTINES
H5Csetparm -- Set a parameter for a template
H5Cgetparm -- Get a parameter for a template
LIBRARY-SCOPED ROUTINES
LOCAL ROUTINES
H5C_init_interface -- initialize the interface
+ */
#include "hdf5.h"
/* private header files */
#include "H5private.h" /* Generic Functions */
#include "H5Cprivate.h" /* Template information */
/*--------------------- Locally scoped variables -----------------------------*/
/* Whether we've installed the library termination function yet for this interface */
static intn interface_initialize = FALSE;
/* Define the library's default file creation template (constants in hdf5lims.h) */
const file_create_temp_t default_file_create={
HDF5_USERBLOCK_DEFAULT, /* Default user-block size */
HDF5_OFFSETSIZE_DEFAULT, /* Default offset size */
HDF5_LENGTHSIZE_DEFAULT, /* Default length size */
HDF5_BTREEPAGE_DEFAULT, /* Default B-tree page size */
HDF5_BOOTBLOCK_VERSION, /* Current Boot-Block version # */
HDF5_SMALLOBJECT_VERSION, /* Current Small-Object heap version # */
HDF5_FREESPACE_VERSION, /* Current Free-Space info version # */
HDF5_OBJECTDIR_VERSION, /* Current Object Directory info version # */
HDF5_SHAREDHEADER_VERSION /* Current Shared-Header format version # */
};
static hatom_t default_file_id=FAIL; /* Atom for the default file-creation template */
/*--------------------- Local function prototypes ----------------------------*/
static herr_t H5C_init_interface(void);
/*--------------------------------------------------------------------------
NAME
H5C_init_interface -- Initialize interface-specific information
USAGE
herr_t H5C_init_interface()
RETURNS
SUCCEED/FAIL
DESCRIPTION
Initializes any interface-specific data or routines.
--------------------------------------------------------------------------*/
static herr_t H5C_init_interface(void)
{
#ifdef LATER
CONSTR(FUNC, "H5C_init_interface"); /* For HERROR */
#endif /* LATER */
herr_t ret_value = SUCCEED;
/* Don't use "FUNC_ENTER" macro, to avoid potential infinite recursion */
PABLO_TRACE_ON(H5C_mask, ID_H5C_init_interface);
/* Don't call this routine again... */
interface_initialize = TRUE;
/* Initialize the atom group for the file IDs */
ret_value=H5Ainit_group(H5_TEMPLATE,HDF5_TEMPID_HASHSIZE,0);
FUNC_LEAVE(H5C_mask, ID_H5C_init_interface, ret_value);
} /* H5C_init_interface */
/*--------------------------------------------------------------------------
NAME
H5C_get_default_atom
PURPOSE
Retrive an atom for a default HDF5 template.
USAGE
hatom_t H5C_create(type)
hobjtype_t type; IN: Type of object to retrieve default template of
RETURNS
Returns template ID (atom) of the default object for a template type on
success, FAIL on failure
DESCRIPTION
This is function retrieves atoms for the default templates for the
different types of HDF5 templates.
--------------------------------------------------------------------------*/
hatom_t H5C_get_default_atom(hobjtype_t type)
{
CONSTR(FUNC, "H5C_create"); /* for HERROR */
hatom_t ret_value = FAIL;
FUNC_ENTER(H5C_mask, ID_H5C_get_default_atom, H5C_init_interface, FAIL);
/* Clear errors and check args and all the boring stuff. */
H5ECLEAR;
switch(type)
{
case H5_TEMPLATE:
if(default_file_id==FAIL)
{
if((default_file_id=H5Aregister_atom(H5_TEMPLATE, (const VOIDP)&default_file_create))==FAIL)
HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL);
} /* end else */
HGOTO_DONE(default_file_id);
break;
default:
HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL);
} /* end switch */
done:
if(ret_value == FAIL)
{ /* Error condition cleanup */
} /* end if */
/* Normal function cleanup */
FUNC_LEAVE(H5C_mask, ID_H5C_get_default_atom, ret_value);
} /* end H5C_get_default_atom() */
/*--------------------------------------------------------------------------
NAME
H5C_init
PURPOSE
Initialize a new HDF5 template with a copy of an existing template.
USAGE
herr_t H5C_init(dst_atm, src)
hatom_t dst_atm; IN: Atom for the template to initialize
file_create_temp_t *src; IN: Template to use to initialize with
RETURNS
SUCCEED/FAIL
DESCRIPTION
This function copies the contents of the source template into the
newly created destination template.
--------------------------------------------------------------------------*/
herr_t H5C_init(hatom_t dst_atm, const file_create_temp_t *src)
{
CONSTR(FUNC, "H5C_init"); /* for HERROR */
file_create_temp_t *dst; /* destination template */
herr_t ret_value = SUCCEED; /* return value */
FUNC_ENTER(H5C_mask, ID_H5C_init, H5C_init_interface, FAIL);
/* Clear errors and check args and all the boring stuff. */
H5ECLEAR;
if(src==NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL);
/* Get the template to initialize */
if((dst=H5Aatom_object(dst_atm))==NULL)
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL);
/* Copy in the source template */
HDmemcpy(dst,src,sizeof(file_create_temp_t));
done:
if(ret_value == FAIL)
{ /* Error condition cleanup */
} /* end if */
/* Normal function cleanup */
FUNC_LEAVE(H5C_mask, ID_H5C_init, ret_value);
} /* end H5C_init() */
/*--------------------------------------------------------------------------
NAME
H5C_create
PURPOSE
Create a new HDF5 template.
USAGE
hatom_t H5C_create(owner_id, type, name)
hatom_t owner_id; IN: Group/file which owns this template
hobjtype_t type; IN: Type of template to create
const char *name; IN: Name of the template to create
RETURNS
Returns template ID (atom) on success, FAIL on failure
DESCRIPTION
This is the primary function for creating different HDF5 templates.
Currently the name of template is not used and may be NULL.
--------------------------------------------------------------------------*/
hatom_t H5C_create(hatom_t owner_id, hobjtype_t type, const char *name)
{
CONSTR(FUNC, "H5C_create"); /* for HERROR */
hatom_t ret_value = FAIL; /* atom for template object to return */
FUNC_ENTER(H5C_mask, ID_H5C_create, H5C_init_interface, FAIL);
/* Clear errors and check args and all the boring stuff. */
H5ECLEAR;
switch(type)
{
case H5_TEMPLATE:
{
file_create_temp_t *new_create_temp; /* new template object to create */
if((new_create_temp=HDmalloc(sizeof(file_create_temp_t)))==NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL);
if((ret_value=H5Aregister_atom(H5_TEMPLATE, (const VOIDP)new_create_temp))==FAIL)
HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL);
} /* end case/block */
break;
default:
HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL);
} /* end switch */
done:
if(ret_value == FAIL)
{ /* Error condition cleanup */
} /* end if */
/* Normal function cleanup */
FUNC_LEAVE(H5C_mask, ID_H5C_create, ret_value);
} /* end H5C_create() */
/*--------------------------------------------------------------------------
NAME
H5C_release
PURPOSE
Release access to a template object.
USAGE
herr_t H5C_release(oid)
hatom_t oid; IN: Template object to release access to
RETURNS
SUCCEED/FAIL
DESCRIPTION
This function releases access to a template object
--------------------------------------------------------------------------*/
herr_t H5C_release(hatom_t oid)
{
CONSTR(FUNC, "H5C_release"); /* for HERROR */
file_create_temp_t *template; /* template to destroy */
herr_t ret_value = SUCCEED;
FUNC_ENTER(H5C_mask, ID_H5C_release, H5C_init_interface, FAIL);
/* Clear errors and check args and all the boring stuff. */
H5ECLEAR;
/* Chuck the object! :-) */
if((template=H5Aremove_atom(oid))==NULL)
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL);
HDfree(template);
done:
if(ret_value == FAIL)
{ /* Error condition cleanup */
} /* end if */
/* Normal function cleanup */
FUNC_LEAVE(H5C_mask, ID_H5C_release, ret_value);
} /* end H5C_release() */
/*--------------------------------------------------------------------------
NAME
H5Cgetparm
PURPOSE
Get a parameter from a template
USAGE
herr_t H5Cgetparm(tid, parm, buf)
hatom_t tid; IN: Template object to retrieve parameter from
file_create_param_t parm; IN: Paramter to retrieve
VOIDP buf; OUT: Pointer to buffer to store parameter in
RETURNS
SUCCEED/FAIL
DESCRIPTION
This function retrieves the value of a specific parameter from a
template
--------------------------------------------------------------------------*/
herr_t H5Cgetparm(hatom_t tid, file_create_param_t parm, VOIDP buf)
{
CONSTR(FUNC, "H5Cgetparm"); /* for HERROR */
file_create_temp_t *template; /* template to query */
herr_t ret_value = SUCCEED;
FUNC_ENTER(H5C_mask, ID_H5Cgetparm, H5C_init_interface, FAIL);
/* Clear errors and check args and all the boring stuff. */
H5ECLEAR;
if(buf==NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL);
/* Get a pointer the template to query */
if((template=H5Aatom_object(tid))==NULL)
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL);
switch(parm)
{
case H5_USERBLOCK_SIZE:
*(uintn *)buf=template->userblock_size;
break;
case H5_OFFSET_SIZE:
*(uintn *)buf=template->offset_size;
break;
case H5_LENGTH_SIZE:
*(uintn *)buf=template->length_size;
break;
case H5_BTREE_SIZE:
*(uintn *)buf=template->btree_page_size;
break;
case H5_BOOTBLOCK_VER:
*(uint8 *)buf=template->bootblock_ver;
break;
case H5_SMALLOBJECT_VER:
*(uint8 *)buf=template->smallobject_ver;
break;
case H5_FREESPACE_VER:
*(uint8 *)buf=template->freespace_ver;
break;
case H5_OBJECTDIR_VER:
*(uint8 *)buf=template->objectdir_ver;
break;
case H5_SHAREDHEADER_VER:
*(uint8 *)buf=template->sharedheader_ver;
break;
default:
HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL);
} /* end switch */
done:
if(ret_value == FAIL)
{ /* Error condition cleanup */
} /* end if */
/* Normal function cleanup */
FUNC_LEAVE(H5C_mask, ID_H5Cgetparm, ret_value);
} /* end H5Cgetparm() */
/*--------------------------------------------------------------------------
NAME
H5Csetparm
PURPOSE
Set a parameter from a template
USAGE
herr_t H5Csetparm(tid, parm, buf)
hatom_t tid; IN: Template object to store parameter in
file_create_param_t parm; IN: Parameter to store
VOIDP buf; OUT: Pointer to parameter buffer
RETURNS
SUCCEED/FAIL
DESCRIPTION
This function stores the value of a specific parameter for a template
--------------------------------------------------------------------------*/
herr_t H5Csetparm(hatom_t tid, file_create_param_t parm, const VOIDP buf)
{
CONSTR(FUNC, "H5Csetparm"); /* for HERROR */
file_create_temp_t *template; /* template to query */
herr_t ret_value = SUCCEED;
FUNC_ENTER(H5C_mask, ID_H5Csetparm, H5C_init_interface, FAIL);
/* Clear errors and check args and all the boring stuff. */
H5ECLEAR;
if(buf==NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL);
/* Get a pointer the template to query */
if((template=H5Aatom_object(tid))==NULL)
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL);
switch(parm)
{
case H5_USERBLOCK_SIZE:
template->userblock_size=*(const uintn *)buf;
break;
case H5_OFFSET_SIZE:
template->offset_size=*(const uintn *)buf;
break;
case H5_LENGTH_SIZE:
template->length_size=*(const uintn *)buf;
break;
case H5_BTREE_SIZE:
template->btree_page_size=*(const uintn *)buf;
break;
case H5_BOOTBLOCK_VER:
template->bootblock_ver=*(const uint8 *)buf;
break;
case H5_SMALLOBJECT_VER:
template->smallobject_ver=*(const uint8 *)buf;
break;
case H5_FREESPACE_VER:
template->freespace_ver=*(const uint8 *)buf;
break;
case H5_OBJECTDIR_VER:
template->objectdir_ver=*(const uint8 *)buf;
break;
case H5_SHAREDHEADER_VER:
template->sharedheader_ver=*(const uint8 *)buf;
break;
default:
HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL);
} /* end switch */
done:
if(ret_value == FAIL)
{ /* Error condition cleanup */
} /* end if */
/* Normal function cleanup */
FUNC_LEAVE(H5C_mask, ID_H5Csetparm, ret_value);
} /* end H5Csetparm() */
/*--------------------------------------------------------------------------
NAME
H5C_copy
PURPOSE
Copy a template
USAGE
hatom_t H5C_copy(tid)
hatom_t tid; IN: Template object to copy
RETURNS
Returns template ID (atom) on success, FAIL on failure
DESCRIPTION
This function creates a new copy of a template with all the same parameter
settings.
--------------------------------------------------------------------------*/
hatom_t H5C_copy(hatom_t tid)
{
CONSTR(FUNC, "H5C_copy"); /* for HERROR */
file_create_temp_t *template, *new_template; /* template to query */
herr_t ret_value = SUCCEED;
FUNC_ENTER(H5C_mask, ID_H5C_copy, H5C_init_interface, FAIL);
/* Clear errors and check args and all the boring stuff. */
H5ECLEAR;
/* Get a pointer the template to query */
if((template=H5Aatom_object(tid))==NULL)
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL);
/* Allocate space for the new template */
if((new_template=HDmalloc(sizeof(file_create_temp_t)))==NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL);
/* Copy over the information from the old template */
HDmemcpy(new_template,template,sizeof(file_create_temp_t));
/* Register the atom for the new template */
if((ret_value=H5Aregister_atom(H5_TEMPLATE, (const VOIDP)new_template))==FAIL)
HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL);
done:
if(ret_value == FAIL)
{ /* Error condition cleanup */
} /* end if */
/* Normal function cleanup */
FUNC_LEAVE(H5C_mask, ID_H5C_copy, ret_value);
} /* end H5C_copy() */
|