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
|
/****************************************************************************
* 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
H5D.c
HDF5 Dataset routines
EXPORTED ROUTINES
H5Dcreate -- Create a dataset
H5Drelease -- Release access to a dataset
LIBRARY-SCOPED ROUTINES
LOCAL ROUTINES
H5P_init_interface -- initialize the interface
+ */
#include <H5private.h> /* Generic Functions */
#include <H5Aprivate.h> /* Atoms */
#include <H5Dprivate.h> /* Dataset functions */
#include <H5Eprivate.h> /* Error handling */
#define PABLO_MASK H5D_mask
/*--------------------- Locally scoped variables -----------------------------*/
/* Whether we've installed the library termination function yet for this interface */
static intn interface_initialize_g = FALSE;
static herr_t H5D_init_interface(void);
/*--------------------------------------------------------------------------
NAME
H5D_init_interface -- Initialize interface-specific information
USAGE
herr_t H5D_init_interface()
RETURNS
SUCCEED/FAIL
DESCRIPTION
Initializes any interface-specific data or routines.
--------------------------------------------------------------------------*/
static herr_t H5D_init_interface(void)
{
herr_t ret_value = SUCCEED;
FUNC_ENTER (H5D_init_interface, NULL, FAIL);
/* Initialize the atom group for the file IDs */
ret_value=H5Ainit_group(H5_DATASET,H5A_DATASETID_HASHSIZE,H5D_RESERVED_ATOMS);
FUNC_LEAVE(ret_value);
} /* H5D_init_interface */
/*--------------------------------------------------------------------------
NAME
H5D_create
PURPOSE
Create a new HDF5 dataset object
USAGE
hatom_t H5D_create(owner_id, type, name)
hatom_t owner_id; IN: Group/file which owns this object
hobjtype_t type; IN: Type of object to create
const char *name; IN: Name of the object
RETURNS
Returns ID (atom) on success, FAIL on failure
DESCRIPTION
This function actually creates the dataset object.
--------------------------------------------------------------------------*/
hatom_t H5D_create(hatom_t owner_id, hobjtype_t type, const char *name)
{
H5D_dataset_t *new_dset; /* new dataset object to create */
hatom_t ret_value = SUCCEED;
FUNC_ENTER(H5D_create, H5D_init_interface, FAIL);
/* Clear errors and check args and all the boring stuff. */
H5ECLEAR;
/* Allocate space for the new dataset */
if((new_dset=HDmalloc(sizeof(H5D_dataset_t)))==NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL);
/* Initialize the dataset object */
if(H5Aatom_group(owner_id)==H5_FILE)
new_dset->file=owner_id;
else
new_dset->file=H5Mget_file(owner_id);
new_dset->parent=owner_id; /* set the owner's ID */
new_dset->name=HDstrdup(name); /* make a copy of the dataset name */
new_dset->modified=BTRUE; /* Yep, we're new... */
new_dset->type=0;
new_dset->dim=0;
new_dset->header=(-1); /* don't know where we are... */
new_dset->data=(-1); /* don't know where we should put the data, either... */
/* Register the new datatype and get an ID for it */
if((ret_value=H5Aregister_atom(H5_DATASET, (const VOIDP)new_dset))==FAIL)
HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL);
done:
if(ret_value == FAIL)
{ /* Error condition cleanup */
} /* end if */
/* Normal function cleanup */
FUNC_LEAVE(ret_value);
} /* end H5D_create() */
/*--------------------------------------------------------------------------
NAME
H5Dset_info
PURPOSE
Set the type and dimensionality of a dataset.
USAGE
herr_t H5Dset_info(oid)
hatom_t oid; IN: Dataset object to modify
hatom_t tid; IN: Datatype object to use as node element
hatom_t did; IN: Dimensionality object to use as dataspace
RETURNS
SUCCEED/FAIL
DESCRIPTION
This function sets the datatype and dataspace of a dataset.
--------------------------------------------------------------------------*/
herr_t H5Dset_info(hatom_t oid, hatom_t tid, hatom_t did)
{
H5D_dataset_t *dataset; /* dataset object to modify */
herr_t ret_value = SUCCEED;
FUNC_ENTER(H5Dset_info, H5D_init_interface, FAIL);
/* Clear errors and check args and all the boring stuff. */
H5ECLEAR;
/* Check that we've received correctly typed parameters */
if(H5Aatom_group(tid)!=H5_DATATYPE || H5Aatom_group(did)!=H5_DATASPACE)
HGOTO_ERROR(H5E_ATOM, H5E_BADTYPE, FAIL);
/* Get the object */
if((dataset=H5Aatom_object(oid))==NULL)
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL);
/* Check that the datatype & dataspace haven't already been initialized */
if(dataset->type!=0 || dataset->dim!=0)
HGOTO_ERROR(H5E_FUNC, H5E_ALREADYINIT, FAIL);
dataset->type=tid;
dataset->dim=did;
dataset->modified=BTRUE; /* indicate the values have changed */
done:
if(ret_value == FAIL)
{ /* Error condition cleanup */
} /* end if */
/* Normal function cleanup */
FUNC_LEAVE(ret_value);
} /* end H5Dset_info() */
/*--------------------------------------------------------------------------
NAME
H5Dwrite
PURPOSE
Write data for a dataset
USAGE
herr_t H5Dset_info(oid)
hatom_t oid; IN: Dataset object to modify
hatom_t did; IN: Dimensionality object to use as dataspace for I/O
VOIDP buf; IN: Buffer with data to write to the file
RETURNS
SUCCEED/FAIL
DESCRIPTION
This function writes dataset object data to the file. The dataspace
ID determines the slice/hyper-slab/portion of the dataset to write.
H5P_SCALAR is a special value which indicates that the entire dataset is
to be written out. (For datasets which have a scalar dataspace for the
entire dataset, this is somewhat redundant.... :-)
--------------------------------------------------------------------------*/
herr_t H5Dwrite(hatom_t oid, hatom_t did, VOIDP buf)
{
H5D_dataset_t *dataset; /* dataset object to release */
#if 0
uintn towrite; /* number of bytes to write out */
#endif
herr_t ret_value = SUCCEED;
FUNC_ENTER(H5Dwrite, H5D_init_interface, FAIL);
/* Clear errors and check args and all the boring stuff. */
H5ECLEAR;
/* Check that we've received correctly typed parameters */
if(H5Aatom_group(did)!=H5_DATASPACE)
HGOTO_ERROR(H5E_ATOM, H5E_BADTYPE, FAIL);
if(buf==NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL);
/* Get the object */
if((dataset=H5Aatom_object(oid))==NULL)
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL);
/* Check that the datatype & dataspace haven't already been initialized */
if(dataset->type==0 || dataset->dim==0)
HGOTO_ERROR(H5E_FUNC, H5E_UNINITIALIZED, FAIL);
#if 0
towrite=H5Tsize(dataset->type)*H5Pnelem(did);
#endif
/* Check memory to disk datatype conversions, etc. */
/* data out */
done:
if(ret_value == FAIL)
{ /* Error condition cleanup */
} /* end if */
/* Normal function cleanup */
FUNC_LEAVE(ret_value);
} /* end H5Dwrite() */
/*--------------------------------------------------------------------------
NAME
H5D_flush
PURPOSE
Flush an an HDF5 dataset object to disk.
USAGE
herr_t H5D_flush(oid)
hatom_t oid; IN: Object to flush to disk
RETURNS
SUCCEED/FAIL
DESCRIPTION
This function flushes a dataset to disk. (i.e. makes the disk version
agree with what's in memory, it does _not_ update the memory version with
any changes on disk)
--------------------------------------------------------------------------*/
herr_t H5D_flush(hatom_t oid)
{
H5D_dataset_t *dataset; /* dataset object to release */
herr_t ret_value = SUCCEED;
FUNC_ENTER(H5D_flush, H5D_init_interface, FAIL);
/* Clear errors and check args and all the boring stuff. */
H5ECLEAR;
/* Get the object */
if((dataset=H5Aatom_object(oid))==NULL)
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL);
/* Check if we have information to flush to the file... */
if(dataset->modified==BTRUE)
{
/* Check if we need to create the dataset header and insert the dataset in the file's hierarchy */
if(dataset->header==0)
{
H5G_entry_t d_sym;
H5F_root_symtype_t root_type=H5F_root_type(dataset->file);
hdf5_file_t *file;
group_t dset_parent=H5Aatom_group(dataset->parent);
/* Get the dataset's file... (I'm not fond of this. -QAK) */
if((file=H5Aatom_object(dataset->file))==NULL)
HGOTO_ERROR(H5E_INTERNAL, H5E_BADATOM, FAIL);
/* Flush object header, etc. to the file... */
if(root_type==H5F_ROOT_ERROR)
HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, FAIL);
/* construct dataset symbol-table entry */
d_sym.name_off=0;
/* allocate the dataset's object header */
if((d_sym.header=H5O_new(file, 0, H5D_MINHDR_SIZE))<0)
HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL);
d_sym.type=H5G_NOTHING_CACHED;
dataset->header=d_sym.header;
/* Insert dataset into parent directory, if there is one */
if(dset_parent!=H5_FILE ||
(dset_parent==H5_FILE && root_type==H5F_ROOT_DIRECTORY))
{
uintn namelen; /* length of parent directory's name */
char *name; /* pointer to parent directory's name */
/* Get the name of the parent directory */
if((namelen=H5Mname_len(dataset->parent))==UFAIL)
HGOTO_ERROR(H5E_DIRECTORY, H5E_BADVALUE, FAIL);
if((name=HDmalloc(namelen+1))==NULL);
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL);
if(H5Mget_name(dataset->parent,name)==FAIL)
HGOTO_ERROR(H5E_DIRECTORY, H5E_NOTFOUND, FAIL);
/* Insert the dataset into the parent directory */
if(H5G_insert (file, NULL, name, dataset->name, &d_sym)==FAIL)
HGOTO_ERROR(H5E_DIRECTORY, H5E_CANTINSERT, FAIL);
HDfree(name);
} /* end if */
else /* insert dataset as root-object, or into root-directory */
{
if(root_type==H5F_ROOT_DATASET || H5F_ROOT_UNKNOWN)
{
/* Make the root directory and stuff the dataset into it */
if(H5G_mkroot (file, H5G_DEFAULT_ROOT_SIZE)==FAIL)
HGOTO_ERROR(H5E_DIRECTORY, H5E_CANTCREATE, FAIL);
if(H5G_insert (file, NULL, NULL, dataset->name, &d_sym)==FAIL)
HGOTO_ERROR(H5E_DIRECTORY, H5E_CANTINSERT, FAIL);
} /* end if */
else
{
/* Set the root of the file to point to the dataset */
if(root_type==H5F_ROOT_NONE)
H5G_set_root(file, dataset->name, &d_sym);
} /* end else */
} /* end else */
/* Add the appropriate messages for the dataset */
} /* end if */
} /* end if */
done:
if(ret_value == FAIL)
{ /* Error condition cleanup */
} /* end if */
/* Normal function cleanup */
FUNC_LEAVE(ret_value);
} /* end H5D_flush() */
/*--------------------------------------------------------------------------
NAME
H5D_release
PURPOSE
Release access to an HDF5 dataset object.
USAGE
herr_t H5D_release(oid)
hatom_t oid; IN: Object to release access to
RETURNS
SUCCEED/FAIL
DESCRIPTION
This function releases a dataset from active use by a user.
--------------------------------------------------------------------------*/
herr_t H5D_release(hatom_t oid)
{
H5D_dataset_t *dataset; /* dataset object to release */
herr_t ret_value = SUCCEED;
FUNC_ENTER(H5D_release, H5D_init_interface, FAIL);
/* Clear errors and check args and all the boring stuff. */
H5ECLEAR;
/* Get the dataset so we can check for changes and release it */
if((dataset=H5Aatom_object(oid))==NULL)
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL);
/* Check if we have information to flush to the file... */
if(dataset->modified==BTRUE)
H5D_flush(oid);
/* relase the memory used for the dataset */
if(dataset->name!=NULL)
HDfree(dataset->name);
HDfree(dataset);
/* Delete the dataset from the atom group */
if(H5Aatom_object(oid)==NULL)
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL);
done:
if(ret_value == FAIL)
{ /* Error condition cleanup */
} /* end if */
/* Normal function cleanup */
FUNC_LEAVE(ret_value);
} /* end H5D_release() */
|