summaryrefslogtreecommitdiffstats
path: root/test/tcoords.c
blob: 29b31c53de6820594ba8c2793bad4d9b902d4a0e (plain)
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
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * 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://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
 * access to either file, you may request a copy from help@hdfgroup.org.     *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/***********************************************************
*
* Test program:	 tcoords
*
* Test the element coordinates for dataspace selection.  For
* chunked dataset, when the hyperslab selection of some 
* dimensions is full, the library optimize it by "flattenning"
* the fully selected dimensions.  This program tests if the
* coordinates of selected elements are correctly calculated.
*
*************************************************************/

#include "testhdf5.h"

#define FILENAME   "coord.h5"

#define SINGLE_END_DSET	                "single_end_dset"
#define MULTI_ENDS_SEL_HYPER_DSET	"multiple_ends_dset"

#define NAME_LEN        128

/* Data written to the dataset for single block test.  Global variable
 * for convenience. */
int da_buffer[2][3][6][2];

/***********************************************************
**
** test_singleEnd_selElements(): Test element selection of only 
** one block.
** 
*************************************************************/
static void test_singleEnd_selElements(hid_t file, hbool_t is_chunked)
{
    hid_t sid, plid, did, msid;
    char dset_name[NAME_LEN];        /* Dataset name */
    size_t elmts_numb;
    herr_t ret;                 /* Generic error return */
    int i, j, k;
    hsize_t da_dims[4] = { 2, 3, 6, 2 };
    hsize_t da_chunksize[4] = { 1, 3, 3, 2 };
    
    /* For testing the full selection in the fastest-growing end */
    int mem1_buffer[1][1][6][2];
    hsize_t mem1_dims[4] = { 1, 1, 6, 2 };
    hsize_t da_elmts1[12][4] = { {0, 0, 0, 0},
                                 {0, 0, 0, 1},
                                 {0, 0, 1, 0},
                                 {0, 0, 1, 1},
                                 {0, 0, 2, 0},
                                 {0, 0, 2, 1},
                                 {0, 0, 3, 0},
                                 {0, 0, 3, 1},
                                 {0, 0, 4, 0},
                                 {0, 0, 4, 1},
                                 {0, 0, 5, 0},
                                 {0, 0, 5, 1} };

    /* For testing the full selection in the slowest-growing end */
    int mem2_buffer[2][3][1][1];
    hsize_t mem2_dims[4] = { 2, 3, 1, 1 };
    hsize_t da_elmts2[6][4] = { {0, 0, 0, 0},
                                {0, 1, 0, 0},
                                {0, 2, 0, 0},
                                {1, 0, 0, 0},
                                {1, 1, 0, 0},
                                {1, 2, 0, 0} };

    /* For testing the full selection in the middle dimensions */
    int mem3_buffer[1][3][6][1];
    hsize_t mem3_dims[4] = { 1, 3, 6, 1 };
    hsize_t da_elmts3[18][4] = { {0, 0, 0, 0},
                                 {0, 0, 1, 0},
                                 {0, 0, 2, 0},
                                 {0, 0, 3, 0},
                                 {0, 0, 4, 0},
                                 {0, 0, 5, 0},
                                 {0, 1, 0, 0},
                                 {0, 1, 1, 0},
                                 {0, 1, 2, 0},
                                 {0, 1, 3, 0},
                                 {0, 1, 4, 0},
                                 {0, 1, 5, 0},
                                 {0, 2, 0, 0},
                                 {0, 2, 1, 0},
                                 {0, 2, 2, 0},
                                 {0, 2, 3, 0},
                                 {0, 2, 4, 0},
                                 {0, 2, 5, 0} };

    /* Create and write the dataset */
    sid = H5Screate_simple(4, da_dims, da_dims);
    CHECK(sid, FAIL, "H5Screate_simple");

    plid = H5Pcreate(H5P_DATASET_CREATE);
    CHECK(plid, FAIL, "H5Pcreate");

    if(is_chunked) {
        ret = H5Pset_chunk(plid, 4, da_chunksize);
        CHECK(ret, FAIL, "H5Pset_chunk");
    }

    /* Construct dataset's name */
    memset(dset_name, 0, (size_t)NAME_LEN);
    strcat(dset_name, SINGLE_END_DSET);
    if(is_chunked)
        strcat(dset_name, "_chunked");

    did = H5Dcreate2(file, dset_name, H5T_NATIVE_INT, sid, H5P_DEFAULT, plid, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dcreate2");

    /* Initialize the data to be written to file */
    for(i=0; i<2; i++) {
        for(j=0; j<3; j++) {
            for(k=0; k<6; k++) {
                da_buffer[i][j][k][0] = i*100 + j*10 + k;
                da_buffer[i][j][k][1] = i*100 + j*10 + k + 1;
            }
        }
    }

    ret = H5Dwrite(did, H5T_NATIVE_INT, sid, sid, H5P_DEFAULT, da_buffer);
    CHECK(ret, FAIL, "H5Dwrite");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

  
    /* ****** Case 1: ******
     * Testing the full selection in the fastest-growing end */
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen2");

    /* Select the elements in the dataset */
    elmts_numb = 12;

    ret = H5Sselect_elements(sid, H5S_SELECT_SET, elmts_numb, (const hsize_t *)da_elmts1);
    CHECK(ret, FAIL, "H5Sselect_elements");

    /* Dataspace for memory buffer */
    msid = H5Screate_simple(4, mem1_dims, mem1_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem1_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<6; i++)
        for(j=0; j<2; j++)
            if(da_buffer[0][0][i][j] != mem1_buffer[0][0][i][j]) {
                TestErrPrintf("%u: Read different values than written at index 0,0,%d,%d\n", __LINE__, i, j);
            }

    /* ****** Case 2: ******
     * Testing the full selection in the slowest-growing end */
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen2");

    /* Select the elements in the dataset */
    elmts_numb = 6;

    ret = H5Sselect_elements(sid, H5S_SELECT_SET, elmts_numb, (const hsize_t *)da_elmts2);
    CHECK(ret, FAIL, "H5Sselect_elements");

    /* Dataspace for memory buffer */
    msid = H5Screate_simple(4, mem2_dims, mem2_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem2_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<2; i++)
        for(j=0; j<3; j++)
            if(da_buffer[i][j][0][0] != mem2_buffer[i][j][0][0]) {
                TestErrPrintf("%u: Read different values than written at index %d,%d,0,0, da_buffer = %d, mem2_buffer = %d\n", __LINE__, i, j, da_buffer[i][j][0][0], mem2_buffer[i][j][0][0]);
            }

    /* ****** Case 3: ******
     * Testing the full selection in the middle dimensions */
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen2");

    /* Select the elements in the dataset */
    elmts_numb = 18;

    ret = H5Sselect_elements(sid, H5S_SELECT_SET, elmts_numb, (const hsize_t *)da_elmts3);
    CHECK(ret, FAIL, "H5Sselect_elements");

    /* Dataspace for memory buffer */
    msid = H5Screate_simple(4, mem3_dims, mem3_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem3_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<3; i++)
        for(j=0; j<6; j++)
            if(da_buffer[0][i][j][0] != mem3_buffer[0][i][j][0]) {
                TestErrPrintf("%u: Read different values than written at index 0,%d,%d,0\n", __LINE__, i, j);
            }


    ret = H5Sclose(sid);
    CHECK(ret, FAIL, "H5Sclose");

    ret = H5Pclose(plid);
    CHECK(ret, FAIL, "H5Pclose");
}

/***********************************************************
**
** test_singleEnd_selHyperslab(): Test full hyperslab selection
** of only one block.
** 
*************************************************************/
static void test_singleEnd_selHyperslab(hid_t file, hbool_t is_chunked)
{
    hid_t sid, did, msid;
    char dset_name[NAME_LEN];        /* Dataset name */
    herr_t ret;                 /* Generic error return */
    int i, j;
    hsize_t da_dims[4] = { 2, 3, 6, 2 };

    /* For testing the full selection in the fastest-growing end */
    int mem1_buffer[1][1][6][2];
    hsize_t mem1_dims[4] = { 1, 1, 6, 2 };
    hsize_t mem1_start[4] = { 0, 0, 0, 0 };
    hsize_t mem1_count[4] = { 1, 1, 1, 1 };
    hsize_t mem1_stride[4] = { 1, 1, 1, 1 };
    hsize_t mem1_block[4] = { 1, 1, 6, 2 };

    /* For testing the full selection in the slowest-growing end */
    int mem2_buffer[2][3][1][1];
    hsize_t mem2_dims[4] = { 2, 3, 1, 1 };
    hsize_t mem2_start[4] = { 0, 0, 0, 0 };
    hsize_t mem2_count[4] = { 1, 1, 1, 1 };
    hsize_t mem2_stride[4] = { 1, 1, 1, 1 };
    hsize_t mem2_block[4] = { 2, 3, 1, 1 };

    /* For testing the full selection in the middle dimensions */
    int mem3_buffer[1][3][6][1];
    hsize_t mem3_dims[4] = { 1, 3, 6, 1 };
    hsize_t mem3_start[4] = { 0, 0, 0, 0 };
    hsize_t mem3_count[4] = { 1, 1, 1, 1 };
    hsize_t mem3_stride[4] = { 1, 1, 1, 1 };
    hsize_t mem3_block[4] = { 1, 3, 6, 1 };

    /* Construct dataset's name */
    memset(dset_name, 0, NAME_LEN);
    strcat(dset_name, SINGLE_END_DSET);
    if(is_chunked)
        strcat(dset_name, "_chunked");

    /* Dataspace for the dataset in file */
    sid = H5Screate_simple(4, da_dims, da_dims);
    CHECK(sid, FAIL, "H5Screate_simple");

    /* ****** Case 1: ******
     * Testing the full selection in the fastest-growing end */
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen2");

    /* Select the elements in the dataset */
    ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem1_start, mem1_stride, mem1_count, mem1_block);
    CHECK(ret, FAIL, "H5Sselect_hyperslab");

    /* Dataspace for memory buffer */
    msid = H5Screate_simple(4, mem1_dims, mem1_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem1_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<6; i++)
        for(j=0; j<2; j++)
            if(da_buffer[0][0][i][j] != mem1_buffer[0][0][i][j]) {
                TestErrPrintf("%u: Read different values than written at index 0,0,%d,%d\n", __LINE__, i, j);
            }

    /* ****** Case 2: ******
     * Testing the full selection in the slowest-growing end */
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen2");

    /* Select the elements in the dataset */
    ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem2_start, mem2_stride, mem2_count, mem2_block);
    CHECK(ret, FAIL, "H5Sselect_hyperslab");

    /* Dataspace for memory buffer */
    msid = H5Screate_simple(4, mem2_dims, mem2_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem2_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<2; i++)
        for(j=0; j<3; j++)
            if(da_buffer[i][j][0][0] != mem2_buffer[i][j][0][0]) {
                TestErrPrintf("%u: Read different values than written at index %d,%d,0,0\n", __LINE__, i, j);
            }

    /* ****** Case 3: ******
     * Testing the full selection in the middle dimensions */
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen2");

    /* Select the elements in the dataset */
    ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem3_start, mem3_stride, mem3_count, mem3_block);
    CHECK(ret, FAIL, "H5Sselect_hyperslab");

    /* Dataspace for memory buffer */
    msid = H5Screate_simple(4, mem3_dims, mem3_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem3_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<3; i++)
        for(j=0; j<6; j++)
            if(da_buffer[0][i][j][0] != mem3_buffer[0][i][j][0]) {
                TestErrPrintf("%u: Read different values than written at index 0,%d,%d,0\n", __LINE__, i, j);
            }


    ret = H5Sclose(sid);
    CHECK(ret, FAIL, "H5Sclose");
}



/***********************************************************
**
** test_multiple_end(): Test full hyperslab selection of 
** multiple blocks.
** 
*************************************************************/
static void test_multiple_ends(hid_t file, hbool_t is_chunked)
{
    hid_t sid, plid, did, msid;
    char dset_name[NAME_LEN];        /* Dataset name */
    herr_t ret;                 /* Generic error return */
    int i, j, k, l, m, n, p;
    hsize_t da_dims[8] = { 4, 5, 3, 4, 2, 3, 6, 2 };
    hsize_t da_chunksize[8] = { 1, 5, 3, 2, 2, 3, 3, 2 };
    int data_buf[4][5][3][4][2][3][6][2];

    /* For testing the full selections in the fastest-growing end and in the middle dimensions */
    int mem1_buffer[1][1][1][4][2][1][6][2];
    hsize_t mem1_dims[8] = { 1, 1, 1, 4, 2, 1, 6, 2 };
    hsize_t mem1_start[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
    hsize_t mem1_count[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem1_stride[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem1_block[8] = { 1, 1, 1, 4, 2, 1, 6, 2 };

    /* For testing the full selections in the slowest-growing end and in the middle dimensions */
    int mem2_buffer[4][5][1][4][2][1][1][1];
    hsize_t mem2_dims[8] = { 4, 5, 1, 4, 2, 1, 1, 1 };
    hsize_t mem2_start[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
    hsize_t mem2_count[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem2_stride[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem2_block[8] = { 4, 5, 1, 4, 2, 1, 1, 1 };

    /* For testing two unadjacent full selections in the middle dimensions */
    int mem3_buffer[1][5][3][1][1][3][6][1];
    hsize_t mem3_dims[8] = { 1, 5, 3, 1, 1, 3, 6, 1 };
    hsize_t mem3_start[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
    hsize_t mem3_count[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem3_stride[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem3_block[8] = { 1, 5, 3, 1, 1, 3, 6, 1 };

    /* For testing the full selections in the fastest-growing end and the slowest-growing end */
    int mem4_buffer[4][5][1][1][1][1][6][2];
    hsize_t mem4_dims[8] = { 4, 5, 1, 1, 1, 1, 6, 2 };
    hsize_t mem4_start[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
    hsize_t mem4_count[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem4_stride[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem4_block[8] = { 4, 5, 1, 1, 1, 1, 6, 2 };

    /* For testing the full selections in the fastest-growing end and slowest-growing end,
     * also in the middle dimensions */
    int mem5_buffer[4][5][1][4][2][1][6][2];
    hsize_t mem5_dims[8] = { 4, 5, 1, 4, 2, 1, 6, 2 };
    hsize_t mem5_start[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
    hsize_t mem5_count[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem5_stride[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem5_block[8] = { 4, 5, 1, 4, 2, 1, 6, 2 };

    /* Create and write the dataset */
    sid = H5Screate_simple(8, da_dims, da_dims);
    CHECK(sid, FAIL, "H5Screate_simple");

    plid = H5Pcreate(H5P_DATASET_CREATE);
    CHECK(plid, FAIL, "H5Pcreate");

    if(is_chunked) {
        ret = H5Pset_chunk(plid, 8, da_chunksize);
        CHECK(ret, FAIL, "H5Pset_chunk");
    }

    /* Construct dataset's name */
    memset(dset_name, 0, NAME_LEN);
    strcat(dset_name, MULTI_ENDS_SEL_HYPER_DSET);
    if(is_chunked)
        strcat(dset_name, "_chunked");

    did = H5Dcreate2(file, dset_name, H5T_NATIVE_INT, sid, H5P_DEFAULT, plid, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dcreate2");

    for(i=0; i<4; i++)
        for(j=0; j<5; j++)
            for(k=0; k<3; k++)
                for(l=0; l<4; l++)
                    for(m=0; m<2; m++)
                        for(n=0; n<3; n++)
                            for(p=0; p<6; p++) {                
                                data_buf[i][j][k][l][m][n][p][0] = i*1000000 + j*100000 + k*10000 + l*1000 + m*100 + n*10 + p;
                                data_buf[i][j][k][l][m][n][p][1] = i*1000000 + j*100000 + k*10000 + l*1000 + m*100 + n*10 + p + 1;
                            }

    ret = H5Dwrite(did, H5T_NATIVE_INT, sid, sid, H5P_DEFAULT, data_buf);
    CHECK(ret, FAIL, "H5Dwrite");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    /* ****** Case 1: ******
     * Testing the full selections in the fastest-growing end and in the middle dimensions*/
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen2");

    /* Select the elements in the dataset */
    ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem1_start, mem1_stride, mem1_count, mem1_block);
    CHECK(ret, FAIL, "H5Sselect_hyperslab");

    msid = H5Screate_simple(8, mem1_dims, mem1_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem1_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<4; i++)
        for(j=0; j<2; j++)
            for(k=0; k<6; k++)
                for(l=0; l<2; l++)
                    if(data_buf[0][0][0][i][j][0][k][l] != mem1_buffer[0][0][0][i][j][0][k][l]) {
                        TestErrPrintf("%u: Read different values than written at index 0,0,0,%d,%d,0,%d,%d\n", __LINE__, i, j, k, l);
                    }

    /* ****** Case 2: ******
     * Testing the full selections in the slowest-growing end and in the middle dimensions*/
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen2");

    /* Select the elements in the dataset */
    ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem2_start, mem2_stride, mem2_count, mem2_block);
    CHECK(ret, FAIL, "H5Sselect_hyperslab");

    msid = H5Screate_simple(8, mem2_dims, mem2_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem2_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<4; i++)
        for(j=0; j<5; j++)
            for(k=0; k<4; k++)
                for(l=0; l<2; l++)
                    if(data_buf[i][j][0][k][l][0][0][0] != mem2_buffer[i][j][0][k][l][0][0][0]) {
                        TestErrPrintf("%u: Read different values than written at index %d,%d,0,%d,%d,0,0,0\n", __LINE__, i, j, k, l);
                    }

    /* ****** Case 3: ******
     * Testing two unadjacent full selections in the middle dimensions */
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen2");

    /* Select the elements in the dataset */
    ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem3_start, mem3_stride, mem3_count, mem3_block);
    CHECK(ret, FAIL, "H5Sselect_hyperslab");

    msid = H5Screate_simple(8, mem3_dims, mem3_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem3_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<5; i++)
        for(j=0; j<3; j++)
            for(k=0; k<3; k++)
                for(l=0; l<6; l++)
                    if(data_buf[0][i][j][0][0][k][l][0] != mem3_buffer[0][i][j][0][0][k][l][0]) {
                        TestErrPrintf("%u: Read different values than written at index 0,%d,%d,0,0,%d,%d,0\n", __LINE__, i, j, k, l);
                    }

    /* ****** Case 4: ******
     * Testing the full selections in the fastest-growing end and the slowest-growing end */
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen2");

    /* Select the elements in the dataset */
    ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem4_start, mem4_stride, mem4_count, mem4_block);
    CHECK(ret, FAIL, "H5Sselect_hyperslab");

    msid = H5Screate_simple(8, mem4_dims, mem4_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem4_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<4; i++)
        for(j=0; j<5; j++)
            for(k=0; k<6; k++)
                for(l=0; l<2; l++)
                    if(data_buf[i][j][0][0][0][0][k][l] != mem4_buffer[i][j][0][0][0][0][k][l]) {
                        TestErrPrintf("%u: Read different values than written at index %d,%d,0,0,0,0,%d,%d\n", __LINE__, i, j, k, l);
                    }


    /* ****** Case 5: ******
     * Testing the full selections in the fastest-growing end and the slowest-growing end, 
     * and also in the middle dimensions */
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen2");

    /* Select the elements in the dataset */
    ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem5_start, mem5_stride, mem5_count, mem5_block);
    CHECK(ret, FAIL, "H5Sselect_hyperslab");

    msid = H5Screate_simple(8, mem5_dims, mem5_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem5_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<4; i++)
        for(j=0; j<5; j++)
            for(k=0; k<4; k++)
                for(l=0; l<2; l++)
                    for(m=0; m<6; m++)
                        for(n=0; n<2; n++)
                            if(data_buf[i][j][0][k][l][0][m][n] != mem5_buffer[i][j][0][k][l][0][m][n]) {
                                TestErrPrintf("%u: Read different values than written at index %d,%d,0,%d,%d,0,%d,%d\n", __LINE__, i, j, k, l, m, n);
                            }


    ret = H5Sclose(sid);
    CHECK(ret, FAIL, "H5Sclose");

    ret = H5Pclose(plid);
    CHECK(ret, FAIL, "H5Pclose");
}


/****************************************************************
**
**  test_coords(): Main testing routine.
**
****************************************************************/
void test_coords(void)
{
    hid_t   fid;
    int     i;
    hbool_t is_chunk;
    herr_t  ret;                 /* Generic error return */

    fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
    CHECK(fid, FAIL, "H5Fcreate");

    for(i=0, is_chunk=FALSE; i<2; i++, is_chunk++) {
        /* Test H5Sselect_elements with selection of one block of data */
        test_singleEnd_selElements(fid, is_chunk);

        /* Test H5Sselect_hyperslab with selection of one block of data */
        test_singleEnd_selHyperslab(fid, is_chunk);

        /* Test H5Sselect_hyperslab with selection of multiple blocks of data */
        test_multiple_ends(fid, is_chunk);
    }

    ret = H5Fclose(fid);
    CHECK(ret, FAIL, "H5Fclose");
}


/*-------------------------------------------------------------------------
 * Function:	cleanup_coords
 *
 * Purpose:	Cleanup temporary test files
 *
 * Return:	none
 *
 * Programmer:	Raymond Lu
 *              20 Dec. 2007
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
void
cleanup_coords(void)
{
    remove(FILENAME);
}