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
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* Programmer: Pedro Vicente <pvn@ncsa.uiuc.edu>
* April 12, 2002
*
* Purpose: Tests the H5Dset_extent call
*/
#include "hdf5.h"
#include "h5test.h"
/*-------------------------------------------------------------------------
*
* Tests the function H5Dset_extent. In the current version of the library
* the dataset MUST be chunked.
*
*-------------------------------------------------------------------------
*/
#define RANK 2
#define ISTORE_IK 64
int main( void )
{
hid_t file_id;
hid_t dataset_id=(-1);
hid_t space_id=(-1);
hid_t plist_id=(-1);
hid_t fcpl; /* File creation property list */
hsize_t dims[RANK] = { 90, 90 };
hsize_t dims_new[RANK] = { 70, 70 };
hsize_t dims_chunk[RANK] = { 20, 20 };
hsize_t dims_out[RANK];
hsize_t maxdims[RANK] = { H5S_UNLIMITED, H5S_UNLIMITED };
int data[ 90 ][ 90 ];
int buf1[ 70 ][ 70 ];
int buf2[ 90 ][ 90 ];
int i, j, n = 0;
int fillvalue = 1; /* Fill value for the dataset */
for( i = 0; i < 90; i++ )
for( j = 0; j < 90; j++ )
data[i][j] = n++;
/*-------------------------------------------------------------------------
* Test H5Dset_extent with chunks on the raw data cache
*-------------------------------------------------------------------------
*/
/* Create a new file using default properties. */
if ((file_id = H5Fcreate( "set_extent_create.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT ))<0) TEST_ERROR;
TESTING("extend dataset create with fill value");
/* Create the data space with unlimited dimensions. */
if ((space_id = H5Screate_simple( RANK, dims, maxdims ))<0) TEST_ERROR;
/* Modify dataset creation properties, i.e. enable chunking. */
if ((plist_id = H5Pcreate (H5P_DATASET_CREATE ))<0) TEST_ERROR;
if (H5Pset_chunk( plist_id, RANK, dims_chunk )<0) TEST_ERROR;
if (H5Pset_fill_value( plist_id, H5T_NATIVE_INT, &fillvalue )<0) TEST_ERROR;
/*-------------------------------------------------------------------------
* Create and write one dataset
*-------------------------------------------------------------------------
*/
/* Create a new dataset */
if ((dataset_id = H5Dcreate( file_id , "Dataset1", H5T_NATIVE_INT, space_id, plist_id ))<0) TEST_ERROR;
/* Write the data. */
if (H5Dwrite( dataset_id , H5T_NATIVE_INT, space_id, H5S_ALL, H5P_DEFAULT, data )<0) TEST_ERROR;
/*-------------------------------------------------------------------------
* Set new dimensions for the array; shrink it
*-------------------------------------------------------------------------
*/
/* Set new dimensions for the array. */
if (H5Dset_extent( dataset_id , dims_new )<0) TEST_ERROR;
/* Get the space. */
if ((space_id = H5Dget_space( dataset_id ))<0) TEST_ERROR;
/* Get dimensions. */
if (H5Sget_simple_extent_dims( space_id, dims_out, NULL )<0) TEST_ERROR;
if ( dims_out[0] != dims_new[0] ) TEST_ERROR;
if ( dims_out[1] != dims_new[1] ) TEST_ERROR;
/*-------------------------------------------------------------------------
* Read
*-------------------------------------------------------------------------
*/
/* Read the new dataset. */
if (H5Dread( dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf1 )<0) TEST_ERROR;
/* Compare the read array with the original array */
for( i = 0; i < (int)dims_out[0]; i++ )
for( j = 0; j < (int)dims_out[1]; j++ )
if ( buf1[i][j] != data[i][j] ) {
printf("buf1[%d][%d]=%d\n",i,j,buf1[i][j]);
printf("data[%d][%d]=%d\n",i,j,data[i][j]);
TEST_ERROR;
} /* end if */
/*-------------------------------------------------------------------------
* Set new dimensions for the array; expand it again
*-------------------------------------------------------------------------
*/
/* Set new dimensions for the array. */
if (H5Dset_extent( dataset_id , dims )<0) TEST_ERROR;
/* Get the space. */
if ((space_id = H5Dget_space( dataset_id ))<0) TEST_ERROR;
/* Get dimensions. */
if (H5Sget_simple_extent_dims( space_id, dims_out, NULL )<0) TEST_ERROR;
if ( dims_out[0] != dims[0] ) TEST_ERROR;
/*-------------------------------------------------------------------------
* Read
*-------------------------------------------------------------------------
*/
/* Read the new dataset. */
if (H5Dread( dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf2 )<0) TEST_ERROR;
/* Compare the read array with the original array */
for( i = 0; i < (int)dims_out[0]; i++ ) {
for( j = 0; j < (int)dims_out[1]; j++ ) {
if ( i >= 70 || j >= 70 ) {
if ( buf2[i][j] != fillvalue ) TEST_ERROR;
}
else {
if ( buf2[i][j] != data[i][j] ) TEST_ERROR;
}
}
}
/*-------------------------------------------------------------------------
* Close/release resources
*-------------------------------------------------------------------------
*/
H5Dclose( dataset_id );
H5Sclose( space_id );
H5Pclose( plist_id );
PASSED();
TESTING("extend dataset create without fill value");
/* Create the data space with unlimited dimensions. */
if ((space_id = H5Screate_simple( RANK, dims, maxdims ))<0) TEST_ERROR;
/* Modify dataset creation properties, i.e. enable chunking. */
if ((plist_id = H5Pcreate (H5P_DATASET_CREATE ))<0) TEST_ERROR;
if (H5Pset_chunk( plist_id, RANK, dims_chunk )<0) TEST_ERROR;
if (H5Pset_fill_time( plist_id, H5D_FILL_TIME_ALLOC)<0) TEST_ERROR;
/*-------------------------------------------------------------------------
* Create and write one dataset
*-------------------------------------------------------------------------
*/
/* Create a new dataset */
if ((dataset_id = H5Dcreate( file_id , "Dataset2", H5T_NATIVE_INT, space_id, plist_id ))<0) TEST_ERROR;
/* Write the data. */
if (H5Dwrite( dataset_id , H5T_NATIVE_INT, space_id, H5S_ALL, H5P_DEFAULT, data )<0) TEST_ERROR;
/*-------------------------------------------------------------------------
* Set new dimensions for the array; shrink it
*-------------------------------------------------------------------------
*/
/* Set new dimensions for the array. */
if (H5Dset_extent( dataset_id , dims_new )<0) TEST_ERROR;
/* Get the space. */
if ((space_id = H5Dget_space( dataset_id ))<0) TEST_ERROR;
/* Get dimensions. */
if (H5Sget_simple_extent_dims( space_id, dims_out, NULL )<0) TEST_ERROR;
if ( dims_out[0] != dims_new[0] ) TEST_ERROR;
/*-------------------------------------------------------------------------
* Read
*-------------------------------------------------------------------------
*/
/* Read the new dataset. */
if (H5Dread( dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf1 )<0) TEST_ERROR;
/* Compare the read array with the original array */
for( i = 0; i < (int)dims_out[0]; i++ )
for( j = 0; j < (int)dims_out[1]; j++ )
if ( buf1[i][j] != data[i][j] ) TEST_ERROR;
/*-------------------------------------------------------------------------
* Set new dimensions for the array; expand it again
*-------------------------------------------------------------------------
*/
/* Set new dimensions for the array. */
if (H5Dset_extent( dataset_id , dims )<0) TEST_ERROR;
/* Get the space. */
if ((space_id = H5Dget_space( dataset_id ))<0) TEST_ERROR;
/* Get dimensions. */
if (H5Sget_simple_extent_dims( space_id, dims_out, NULL )<0) TEST_ERROR;
if ( dims_out[0] != dims[0] ) TEST_ERROR;
/*-------------------------------------------------------------------------
* Read
*-------------------------------------------------------------------------
*/
/* Read the new dataset. */
if (H5Dread( dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf2 )<0) TEST_ERROR;
/* Compare the read array with the original array */
for( i = 0; i < (int)dims_out[0]; i++ ) {
for( j = 0; j < (int)dims_out[1]; j++ ) {
if ( i >= 70 || j >= 70 ) {
if ( buf2[i][j] != 0 ) TEST_ERROR;
}
else {
if ( buf2[i][j] != data[i][j] ) TEST_ERROR;
}
}
}
/*-------------------------------------------------------------------------
* Close/release resources
*-------------------------------------------------------------------------
*/
H5Dclose( dataset_id );
H5Sclose( space_id );
H5Pclose( plist_id );
H5Fclose( file_id );
PASSED();
/*-------------------------------------------------------------------------
* Test H5Dset_extent with chunks written to file
*-------------------------------------------------------------------------
*/
/* Create a file creation property list */
if((fcpl = H5Pcreate(H5P_FILE_CREATE))<0) TEST_ERROR;
/* Set non-default indexed storage B-tree internal 'K' value */
if(H5Pset_istore_k(fcpl,ISTORE_IK)<0) TEST_ERROR;
/* Create a new file using properties. */
if ((file_id = H5Fcreate( "set_extent_read.h5", H5F_ACC_TRUNC, fcpl, H5P_DEFAULT ))<0) TEST_ERROR;
/* Close property list */
if(H5Pclose(fcpl)<0) TEST_ERROR;
TESTING("extend dataset read with fill value");
/* Create the data space with unlimited dimensions. */
if ((space_id = H5Screate_simple( RANK, dims, maxdims ))<0) TEST_ERROR;
/* Modify dataset creation properties, i.e. enable chunking. */
if ((plist_id = H5Pcreate (H5P_DATASET_CREATE ))<0) TEST_ERROR;
if (H5Pset_chunk( plist_id, RANK, dims_chunk )<0) TEST_ERROR;
if (H5Pset_fill_value( plist_id, H5T_NATIVE_INT, &fillvalue )<0) TEST_ERROR;
/* Create a new dataset within the file using cparms creation properties. */
if ((dataset_id = H5Dcreate( file_id , "Dataset1", H5T_NATIVE_INT, space_id, plist_id ))<0) TEST_ERROR;
/* Write the data. */
if (H5Dwrite( dataset_id , H5T_NATIVE_INT, space_id, H5S_ALL, H5P_DEFAULT, data )<0) TEST_ERROR;
/* Close/release resources. */
H5Dclose( dataset_id );
H5Sclose( space_id );
H5Pclose( plist_id );
H5Fclose( file_id );
/* Open the file */
if ((file_id = H5Fopen( "set_extent_read.h5", H5F_ACC_RDWR, H5P_DEFAULT ))<0) TEST_ERROR;
/* Open the dataset */
if ((dataset_id = H5Dopen( file_id , "Dataset1" ))<0) TEST_ERROR;
/* Set new dimensions for the array. */
if (H5Dset_extent( dataset_id, dims_new )<0) TEST_ERROR;
/* Get the space. */
if ((space_id = H5Dget_space( dataset_id ))<0) TEST_ERROR;
/* Get dimensions. */
if (H5Sget_simple_extent_dims( space_id, dims_out, NULL )<0) TEST_ERROR;
if ( dims_out[0] != dims_new[0] ) TEST_ERROR;
/* Read the new dataset. */
if (H5Dread( dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf1 )<0) TEST_ERROR;
/* Compare the read array with the original array */
for( i = 0; i < (int)dims_out[0]; i++ )
for( j = 0; j < (int)dims_out[1]; j++ )
if ( buf1[i][j] != data[i][j] ) TEST_ERROR;
/*-------------------------------------------------------------------------
* Set new dimensions for the array; expand it again
*-------------------------------------------------------------------------
*/
/* Set new dimensions for the array. */
if (H5Dset_extent( dataset_id , dims )<0) TEST_ERROR;
/* Get the space. */
if ((space_id = H5Dget_space( dataset_id ))<0) TEST_ERROR;
/* Get dimensions. */
if (H5Sget_simple_extent_dims( space_id, dims_out, NULL )<0) TEST_ERROR;
if ( dims_out[0] != dims[0] ) TEST_ERROR;
/* Read the new dataset. */
if (H5Dread( dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf2 )<0) TEST_ERROR;
/* Compare the read array with the original array */
for( i = 0; i < (int)dims_out[0]; i++ ) {
for( j = 0; j < (int)dims_out[1]; j++ ) {
if ( i >= 70 || j >= 70 ) {
if ( buf2[i][j] != fillvalue ) TEST_ERROR;
}
else {
if ( buf2[i][j] != data[i][j] ) TEST_ERROR;
}
}
}
/*-------------------------------------------------------------------------
* Close/release resources
*-------------------------------------------------------------------------
*/
H5Dclose( dataset_id );
H5Sclose( space_id );
PASSED();
TESTING("extend dataset read without fill value");
/* Create the data space with unlimited dimensions. */
if ((space_id = H5Screate_simple( RANK, dims, maxdims ))<0) TEST_ERROR;
/* Modify dataset creation properties, i.e. enable chunking. */
if ((plist_id = H5Pcreate (H5P_DATASET_CREATE ))<0) TEST_ERROR;
if (H5Pset_chunk( plist_id, RANK, dims_chunk )<0) TEST_ERROR;
if (H5Pset_fill_time( plist_id, H5D_FILL_TIME_ALLOC)<0) TEST_ERROR;
/* Create a new dataset within the file using cparms creation properties. */
if ((dataset_id = H5Dcreate( file_id , "Dataset2", H5T_NATIVE_INT, space_id, plist_id ))<0) TEST_ERROR;
/* Write the data. */
if (H5Dwrite( dataset_id , H5T_NATIVE_INT, space_id, H5S_ALL, H5P_DEFAULT, data )<0) TEST_ERROR;
/* Close/release resources. */
H5Dclose( dataset_id );
H5Sclose( space_id );
H5Pclose( plist_id );
H5Fclose( file_id );
/* Open the file */
if ((file_id = H5Fopen( "set_extent_read.h5", H5F_ACC_RDWR, H5P_DEFAULT ))<0) TEST_ERROR;
/* Open the dataset */
if ((dataset_id = H5Dopen( file_id , "Dataset2" ))<0) TEST_ERROR;
/* Set new dimensions for the array. */
if (H5Dset_extent( dataset_id, dims_new )<0) TEST_ERROR;
/* Get the space. */
if ((space_id = H5Dget_space( dataset_id ))<0) TEST_ERROR;
/* Get dimensions. */
if (H5Sget_simple_extent_dims( space_id, dims_out, NULL )<0) TEST_ERROR;
if ( dims_out[0] != dims_new[0] ) TEST_ERROR;
/* Read the new dataset. */
if (H5Dread( dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf1 )<0) TEST_ERROR;
/* Compare the read array with the original array */
for( i = 0; i < (int)dims_out[0]; i++ )
for( j = 0; j < (int)dims_out[1]; j++ )
if ( buf1[i][j] != data[i][j] ) TEST_ERROR;
/*-------------------------------------------------------------------------
* Set new dimensions for the array; expand it again
*-------------------------------------------------------------------------
*/
/* Set new dimensions for the array. */
if (H5Dset_extent( dataset_id , dims )<0) TEST_ERROR;
/* Get the space. */
if ((space_id = H5Dget_space( dataset_id ))<0) TEST_ERROR;
/* Get dimensions. */
if (H5Sget_simple_extent_dims( space_id, dims_out, NULL )<0) TEST_ERROR;
if ( dims_out[0] != dims[0] ) TEST_ERROR;
/* Read the new dataset. */
if (H5Dread( dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf2 )<0) TEST_ERROR;
/* Compare the read array with the original array */
for( i = 0; i < (int)dims_out[0]; i++ ) {
for( j = 0; j < (int)dims_out[1]; j++ ) {
if ( i >= 70 || j >= 70 ) {
if ( buf2[i][j] != 0 ) TEST_ERROR;
}
else {
if ( buf2[i][j] != data[i][j] ) TEST_ERROR;
}
}
}
/*-------------------------------------------------------------------------
* Close/release resources
*-------------------------------------------------------------------------
*/
H5Dclose( dataset_id );
H5Sclose( space_id );
H5Fclose( file_id );
PASSED();
puts("All set_extent tests passed.");
return 0;
error:
H5Dclose( dataset_id );
H5Sclose( space_id );
H5Pclose( plist_id );
H5Fclose( file_id );
H5_FAILED();
return 1;
}
|