summaryrefslogtreecommitdiffstats
path: root/examples/h5dsm_tvlen.c
blob: 596db7ab5b7d1342c72192df7647e2d87ebbcd55 (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
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
#include "h5dsm_example.h"
#include <time.h>

#define FILE_NAME "tvlen.h5"
#define NITER 10

hbool_t verbose_g = 1;

static void print_vla(const hvl_t *vla) {
    int i, j, k;

    for(i = 0; i < 4; i++) {
        for(j = 0; j < 2; j++) {
            if(j > 0)
                printf(", ");
            printf("{");
            for(k = 0; k < (int)vla[2 * i + j].len; k++) {
                if(k > 0)
                    printf(", ");
                printf("%d", ((int *)vla[2 * i + j].p)[k]);
            } /* end for */
            printf("}");
        } /* end for */
        printf("\n");
    } /* end for */

    return;
} /* end print_vla() */

static int check_vla(const hvl_t *vla1, const hvl_t *vla2) {
    int i, j, k;

    for(i = 0; i < 4; i++)
        for(j = 0; j < 2; j++) {
            if(vla1[2 * i + j].len != vla2[2 * i + j].len)
                PRINTF_ERROR("vlen array length at location %d, %d does not match", i, j);
            for(k = 0; k < (int)vla1[2 * i + j].len; k++)
                if(((int *)vla1[2 * i + j].p)[k] != ((int *)vla2[2 * i + j].p)[k])
                    PRINTF_ERROR("vlen array data at location %d, %d, %d does not match", i, j, k);
        } /* end for */

    return 0;

error:
    return -1;
} /* end check_vla() */

static void print_vls(char **vls) {
    int i, j;

    for(i = 0; i < 4; i++) {
        for(j = 0; j < 2; j++) {
            if(j > 0)
                printf(", ");
            if(vls[2 * i + j])
                printf("\"%s\"", vls[2 * i + j]);
            else
                printf("NULL");
        } /* end for */
        printf("\n");
    } /* end for */

    return;
} /* end print_vls() */

static int check_vls(char **vls1, char **vls2) {
    int i, j;

    for(i = 0; i < 4; i++)
        for(j = 0; j < 2; j++) {
            if((vls1[2 * i + j] == NULL) != (vls2[2 * i + j] == NULL))
                PRINTF_ERROR("one vlen string at location %d, %d is NULL and the other is not", i, j);
            if(vls1[2 * i + j] && strcmp(vls1[2 * i + j], vls2[2 * i + j]))
                PRINTF_ERROR("vlen strings at location %d, %d do not match", i, j);
        } /* end for */

    return 0;

error:
    return -1;
} /* end check_vls() */

#define UPDATE_FBUF_VLA(FBUF, UBUF) \
do { \
    if((FBUF).p) \
        free((FBUF).p); \
    if((UBUF).len > 0) { \
        if(NULL == ((FBUF).p = malloc((UBUF).len * sizeof(int)))) \
            ERROR; \
        memcpy((FBUF).p, (UBUF).p, (UBUF).len * sizeof(int)); \
    } /* end if */ \
    else \
        (FBUF).p = NULL; \
    (FBUF).len = (UBUF).len; \
} while(0)

#define UPDATE_FBUF_VLS(FBUF, UBUF) \
do { \
    if(FBUF) \
        free(FBUF); \
    if(UBUF) { \
        if(NULL == ((FBUF) = strdup(UBUF))) \
            ERROR; \
    } /* end if */ \
    else \
        (FBUF) = NULL; \
} while(0)

int main(int argc, char *argv[]) {
    uuid_t pool_uuid;
    char *pool_grp = NULL;
    hid_t file = -1, dset_vla = -1, dset_vls = -1, attr_vla = -1, attr_vls = -1, space = -1, fapl = -1;
    hid_t type_vla = -1, type_vls = -1;
    hid_t space_contig = -1, space_ncontig = -1;
    hsize_t dims[2] = {4, 2};
    hsize_t start[2], count[2];
    int static_buf_vla[4][2][8];
    char static_buf_vls[4][2][8];
    hvl_t rbuf_vla[4][2];
    char *rbuf_vls[4][2];
    hvl_t wbuf_vla[4][2];
    char *wbuf_vls[4][2];
    hvl_t ebuf_vla[4][2];
    char *ebuf_vls[4][2];
    hvl_t fbuf_vla[4][2];
    char *fbuf_vls[4][2];
    int bogus_int = -1;
    char bogus_str[3] = {'-', '1', '\0'};
    const hvl_t rbuf_vla_init[4][2] = {{{1, &bogus_int}, {1, &bogus_int}},
            {{1, &bogus_int}, {1, &bogus_int}},
            {{1, &bogus_int}, {1, &bogus_int}},
            {{1, &bogus_int}, {1, &bogus_int}}};
    char * const rbuf_vls_init[4][2] = {{bogus_str, bogus_str},
            {bogus_str, bogus_str},
            {bogus_str, bogus_str},
            {bogus_str, bogus_str}};
    const hvl_t wbuf_vla_init[4][2] = {{{0, &static_buf_vla[0][0][0]}, {0, &static_buf_vla[0][1][0]}},
            {{0, &static_buf_vla[1][0][0]}, {0, &static_buf_vla[1][1][0]}},
            {{0, &static_buf_vla[2][0][0]}, {0, &static_buf_vla[2][1][0]}},
            {{0, &static_buf_vla[3][0][0]}, {1, &static_buf_vla[3][1][0]}}};
    char * const wbuf_vls_init[4][2] = {{&static_buf_vls[0][0][0], &static_buf_vls[0][1][0]},
            {&static_buf_vls[1][0][0], &static_buf_vls[1][1][0]},
            {&static_buf_vls[2][0][0], &static_buf_vls[2][1][0]},
            {&static_buf_vls[3][0][0], &static_buf_vls[3][1][0]}};
    int i, j, k, l;

    memset(fbuf_vla[0], 0, sizeof(fbuf_vla));
    memset(fbuf_vls[0], 0, sizeof(fbuf_vls));

    (void)MPI_Init(&argc, &argv);

    /* Seed random number generator */
    srand(time(NULL));

    if((argc != 2) && (argc != 3))
        PRINTF_ERROR("argc must be 2 or 3\n");

    if(argc == 3)
        verbose_g = 0;

    /* Parse UUID */
    if(0 != uuid_parse(argv[1], pool_uuid))
        ERROR;

    /* Initialize VOL */
    if(H5VLdaosm_init(MPI_COMM_WORLD, pool_uuid, pool_grp) < 0)
        ERROR;

    /* Set up FAPL */
    if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
        ERROR;
    if(H5Pset_fapl_daosm(fapl, MPI_COMM_WORLD, MPI_INFO_NULL) < 0)
        ERROR;
    if(H5Pset_all_coll_metadata_ops(fapl, true) < 0)
        ERROR;

    /* Create file */
    if((file = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        ERROR;

    /* Set up dataspace */
    if((space = H5Screate_simple(2, dims, NULL)) < 0)
        ERROR;

    /* Set up contiguous dataspace selection */
    if((space_contig = H5Screate_simple(2, dims, NULL)) < 0)
        ERROR;
    start[0] = 1;
    start[1] = 0;
    count[0] = 2;
    count[1] = 2;
    if(H5Sselect_hyperslab(space_contig, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
        ERROR;

    /* Set up con-contiguous dataspace selection */
    if((space_ncontig = H5Screate_simple(2, dims, NULL)) < 0)
        ERROR;
    start[0] = 0;
    start[1] = 1;
    count[0] = 4;
    count[1] = 1;
    if(H5Sselect_hyperslab(space_ncontig, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
        ERROR;

    /*
     * Set up types
     */
    /* Create variable length array */
    /* Set up file "all" type */
    if((type_vla = H5Tvlen_create(H5T_NATIVE_INT)) < 0)
        ERROR;

    /* Set up variable length string type */
    if((type_vls = H5Tcopy(H5T_C_S1)) < 0)
        ERROR;
    if(H5Tset_size(type_vls, H5T_VARIABLE) < 0)
        ERROR;

    /*
     * Create objects
     */
    /* Create vla dataset */
    if((dset_vla = H5Dcreate2(file, "vla_dset", type_vla, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
        ERROR;

    /* Create vls dataset */
    if((dset_vls = H5Dcreate2(file, "vls_dset", type_vls, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
        ERROR;

    /* Create vla attribute */
    if((attr_vla = H5Acreate2(dset_vla, "vla_attr", type_vla, space, H5P_DEFAULT, H5P_DEFAULT)) < 0)
        ERROR;

    /* Create vls attribute */
    if((attr_vls = H5Acreate2(dset_vla, "vls_attr", type_vls, space, H5P_DEFAULT, H5P_DEFAULT)) < 0)
        ERROR;

    /*
     * Test attribute
     */
    /* Loop over iterations */
    for(i = 0; i < NITER; i++) {
        /*
         * Variable length array attribute test
         */
        /* Fill write data buffer */
        for(j = 0; j < dims[0]; j++)
            for(k = 0; k < dims[1]; k++)
                for(l = 0; l < (sizeof(static_buf_vla[0][0]) / sizeof(static_buf_vla[0][0][0])); l++)
                    static_buf_vla[j][k][l] = rand() % 100;

        /* Fill write buffer */
        memcpy(wbuf_vla, wbuf_vla_init, sizeof(wbuf_vla));
        for(j = 0; j < dims[0]; j++)
            for(k = 0; k < dims[1]; k++) {
                /* 10% chance of having a NULL sequence */
                if(rand() % 10)
                    wbuf_vla[j][k].len = rand() % 9;
                else {
                    wbuf_vla[j][k].len = 0;
                    wbuf_vla[j][k].p = NULL;
                } /* end if */
            } /* end for */

        /* Print message */
        if(verbose_g) {
            printf("Writing attribute with variable length arrays.  buf =\n");
            print_vla(wbuf_vla[0]);
        } /* end if */

        /* Write data */
        if(H5Awrite(attr_vla, type_vla, wbuf_vla) < 0)
            ERROR;

        /* Read data */
        memcpy(rbuf_vla, rbuf_vla_init, sizeof(rbuf_vla));
        if(H5Aread(attr_vla, type_vla, rbuf_vla) < 0)
            ERROR;

        /* Print message */
        if(verbose_g) {
            printf("Read attribute with variable length arrays.  buf =\n");
            print_vla(rbuf_vla[0]);
        } /* end if */

        /* Check buffer */
        if(check_vla(wbuf_vla[0], rbuf_vla[0]) < 0) {
            (void)H5Dvlen_reclaim(type_vla, space, H5P_DEFAULT, rbuf_vla);
            ERROR;
        } /* end if */

        /* Reclaim read buffer */
        if(H5Dvlen_reclaim(type_vla, space, H5P_DEFAULT, rbuf_vla) < 0)
            ERROR;

        if(verbose_g)
            printf("\n");

        /*
         * Variable length string attribute test
         */
        /* Fill write data buffer */
        for(j = 0; j < dims[0]; j++)
            for(k = 0; k < dims[1]; k++)
                for(l = 0; l < (sizeof(static_buf_vls[0][0]) / sizeof(static_buf_vls[0][0][0])); l++)
                    static_buf_vls[j][k][l] = 'a' + rand() % 26;

        /* Fill write buffer */
        memcpy(wbuf_vls, wbuf_vls_init, sizeof(wbuf_vls));
        for(j = 0; j < dims[0]; j++)
            for(k = 0; k < dims[1]; k++) {
                /* 10% chance of having a NULL sequence */
                if(rand() % 10)
                    static_buf_vls[j][k][rand() % 8] = '\0';
                else
                    wbuf_vls[j][k] = NULL;
            } /* end for */

        /* Print message */
        if(verbose_g) {
            printf("Writing attribute with variable length strings.  buf =\n");
            print_vls(wbuf_vls[0]);
        } /* end if */

        /* Write data */
        if(H5Awrite(attr_vls, type_vls, wbuf_vls) < 0)
            ERROR;

        /* Read data */
        memcpy(rbuf_vls, rbuf_vls_init, sizeof(rbuf_vls));
        if(H5Aread(attr_vls, type_vls, rbuf_vls) < 0)
            ERROR;

        /* Print message */
        if(verbose_g) {
            printf("Read attribute with variable length strings.  buf =\n");
            print_vls(rbuf_vls[0]);
        } /* end if */

        /* Check buffer */
        if(check_vls(wbuf_vls[0], rbuf_vls[0]) < 0) {
            (void)H5Dvlen_reclaim(type_vls, space, H5P_DEFAULT, rbuf_vls);
            ERROR;
        } /* end if */

        /* Reclaim read buffer */
        if(H5Dvlen_reclaim(type_vls, space, H5P_DEFAULT, rbuf_vls) < 0)
            ERROR;

        if(verbose_g)
            printf("\n");

        /*
         * Variable length array dataset test
         */
        /* Fill write data buffer */
        for(j = 0; j < dims[0]; j++)
            for(k = 0; k < dims[1]; k++)
                for(l = 0; l < (sizeof(static_buf_vla[0][0]) / sizeof(static_buf_vla[0][0][0])); l++)
                    static_buf_vla[j][k][l] = rand() % 100;

        /* Fill write buffer */
        memcpy(wbuf_vla, wbuf_vla_init, sizeof(wbuf_vla));
        for(j = 0; j < dims[0]; j++)
            for(k = 0; k < dims[1]; k++) {
                /* 10% chance of having a NULL sequence */
                if(rand() % 10)
                    wbuf_vla[j][k].len = rand() % 9;
                else {
                    wbuf_vla[j][k].len = 0;
                    wbuf_vla[j][k].p = NULL;
                } /* end if */
            } /* end for */

        /* Print message */
        if(verbose_g) {
            printf("Writing dataset with variable length arrays.  buf =\n");
            print_vla(wbuf_vla[0]);
        } /* end if */

        /* Write data */
        if(H5Dwrite(dset_vla, type_vla, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf_vla) < 0)
            ERROR;

        /* Read data */
        memcpy(rbuf_vla, rbuf_vla_init, sizeof(rbuf_vla));
        if(H5Dread(dset_vla, type_vla, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf_vla) < 0)
            ERROR;

        /* Print message */
        if(verbose_g) {
            printf("Read dataset with variable length arrays.  buf =\n");
            print_vla(rbuf_vla[0]);
        } /* end if */

        /* Check buffer */
        if(check_vla(wbuf_vla[0], rbuf_vla[0]) < 0) {
            (void)H5Dvlen_reclaim(type_vla, space, H5P_DEFAULT, rbuf_vla);
            ERROR;
        } /* end if */

        /* Reclaim read buffer */
        if(H5Dvlen_reclaim(type_vla, space, H5P_DEFAULT, rbuf_vla) < 0)
            ERROR;

        if(verbose_g)
            printf("\n");

        /*
         * Variable length string dataset test
         */
        /* Fill write data buffer */
        for(j = 0; j < dims[0]; j++)
            for(k = 0; k < dims[1]; k++)
                for(l = 0; l < (sizeof(static_buf_vls[0][0]) / sizeof(static_buf_vls[0][0][0])); l++)
                    static_buf_vls[j][k][l] = 'a' + rand() % 26;

        /* Fill write buffer */
        memcpy(wbuf_vls, wbuf_vls_init, sizeof(wbuf_vls));
        for(j = 0; j < dims[0]; j++)
            for(k = 0; k < dims[1]; k++) {
                /* 10% chance of having a NULL sequence */
                if(rand() % 10)
                    static_buf_vls[j][k][rand() % 8] = '\0';
                else
                    wbuf_vls[j][k] = NULL;
            } /* end for */

        /* Print message */
        if(verbose_g) {
            printf("Writing dataset with variable length strings.  buf =\n");
            print_vls(wbuf_vls[0]);
        } /* end if */

        /* Write data */
        if(H5Dwrite(dset_vls, type_vls, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf_vls) < 0)
            ERROR;

        /* Read data */
        memcpy(rbuf_vls, rbuf_vls_init, sizeof(rbuf_vls));
        if(H5Dread(dset_vls, type_vls, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf_vls) < 0)
            ERROR;

        /* Print message */
        if(verbose_g) {
            printf("Read dataset with variable length strings.  buf =\n");
            print_vls(rbuf_vls[0]);
        } /* end if */

        /* Check buffer */
        if(check_vls(wbuf_vls[0], rbuf_vls[0]) < 0) {
            (void)H5Dvlen_reclaim(type_vls, space, H5P_DEFAULT, rbuf_vls);
            ERROR;
        } /* end if */

        /* Reclaim read buffer */
        if(H5Dvlen_reclaim(type_vls, space, H5P_DEFAULT, rbuf_vls) < 0)
            ERROR;

        if(verbose_g)
            printf("\n");

        /*
         * Variable length array dataset test with selections
         */
        /* Fill write data buffer */
        for(j = 0; j < dims[0]; j++)
            for(k = 0; k < dims[1]; k++)
                for(l = 0; l < (sizeof(static_buf_vla[0][0]) / sizeof(static_buf_vla[0][0][0])); l++)
                    static_buf_vla[j][k][l] = rand() % 100;

        /* Fill write buffer */
        memcpy(wbuf_vla, wbuf_vla_init, sizeof(wbuf_vla));
        for(j = 0; j < dims[0]; j++)
            for(k = 0; k < dims[1]; k++) {
                /* 10% chance of having a NULL sequence */
                if(rand() % 10)
                    wbuf_vla[j][k].len = rand() % 9;
                else {
                    wbuf_vla[j][k].len = 0;
                    wbuf_vla[j][k].p = NULL;
                } /* end if */
            } /* end for */

        /* Print message */
        if(verbose_g) {
            printf("Writing dataset with variable length arrays.  buf =\n");
            print_vla(wbuf_vla[0]);
        } /* end if */

        /* Write data to whole dataset */
        if(H5Dwrite(dset_vla, type_vla, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf_vla) < 0)
            ERROR;

        /* Update fbuf */
        for(j = 0; j < dims[0]; j++)
            for(k = 0; k < dims[1]; k++)
                UPDATE_FBUF_VLA(fbuf_vla[j][k], wbuf_vla[j][k]);

        /* Read data from non-contiguous to contiguous */
        memcpy(rbuf_vla, rbuf_vla_init, sizeof(rbuf_vla));
        memcpy(ebuf_vla, rbuf_vla_init, sizeof(rbuf_vla));
        if(H5Dread(dset_vla, type_vla, space_contig, space_ncontig, H5P_DEFAULT, rbuf_vla) < 0)
            ERROR;

        /* Print message */
        if(verbose_g) {
            printf("Read dataset with variable length arrays with selection.  buf =\n");
            print_vla(rbuf_vla[0]);
        } /* end if */

        /* Update ebuf */
        ebuf_vla[1][0] = fbuf_vla[0][1];
        ebuf_vla[1][1] = fbuf_vla[1][1];
        ebuf_vla[2][0] = fbuf_vla[2][1];
        ebuf_vla[2][1] = fbuf_vla[3][1];

        /* Check buffer */
        if(check_vla(ebuf_vla[0], rbuf_vla[0]) < 0) {
            (void)H5Dvlen_reclaim(type_vla, space_contig, H5P_DEFAULT, rbuf_vla);
            ERROR;
        } /* end if */

        /* Reclaim read buffer */
        if(H5Dvlen_reclaim(type_vla, space_contig, H5P_DEFAULT, rbuf_vla) < 0)
            ERROR;

        if(verbose_g)
            printf("\n");

        /* Fill write data buffer */
        for(j = 0; j < dims[0]; j++)
            for(k = 0; k < dims[1]; k++)
                for(l = 0; l < (sizeof(static_buf_vla[0][0]) / sizeof(static_buf_vla[0][0][0])); l++)
                    static_buf_vla[j][k][l] = rand() % 100;

        /* Fill write buffer */
        memcpy(wbuf_vla, wbuf_vla_init, sizeof(wbuf_vla));
        for(j = 0; j < dims[0]; j++)
            for(k = 0; k < dims[1]; k++) {
                /* 10% chance of having a NULL sequence */
                if(rand() % 10)
                    wbuf_vla[j][k].len = rand() % 9;
                else {
                    wbuf_vla[j][k].len = 0;
                    wbuf_vla[j][k].p = NULL;
                } /* end if */
            } /* end for */

        /* Print message */
        if(verbose_g) {
            printf("Writing dataset with variable length arrays with selection.  buf =\n");
            print_vla(wbuf_vla[0]);
        } /* end if */

        /* Write data to dataset from non-contiguous to contiguous */
        if(H5Dwrite(dset_vla, type_vla, space_ncontig, space_contig, H5P_DEFAULT, wbuf_vla) < 0)
            ERROR;

        /* Update fbuf */
        UPDATE_FBUF_VLA(fbuf_vla[1][0], wbuf_vla[0][1]);
        UPDATE_FBUF_VLA(fbuf_vla[1][1], wbuf_vla[1][1]);
        UPDATE_FBUF_VLA(fbuf_vla[2][0], wbuf_vla[2][1]);
        UPDATE_FBUF_VLA(fbuf_vla[2][1], wbuf_vla[3][1]);

        /* Read entire dataset */
        memcpy(rbuf_vla, rbuf_vla_init, sizeof(rbuf_vla));
        memcpy(ebuf_vla, rbuf_vla_init, sizeof(rbuf_vla));
        if(H5Dread(dset_vla, type_vla, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf_vla) < 0)
            ERROR;

        /* Print message */
        if(verbose_g) {
            printf("Read dataset with variable length arrays.  buf =\n");
            print_vla(rbuf_vla[0]);
        } /* end if */

        /* Check buffer */
        if(check_vla(fbuf_vla[0], rbuf_vla[0]) < 0) {
            (void)H5Dvlen_reclaim(type_vla, space, H5P_DEFAULT, rbuf_vla);
            ERROR;
        } /* end if */

        /* Reclaim read buffer */
        if(H5Dvlen_reclaim(type_vla, space, H5P_DEFAULT, rbuf_vla) < 0)
            ERROR;

        if(verbose_g)
            printf("\n");

        /*
         * Variable length string dataset test with selections
         */
        /* Fill write data buffer */
        for(j = 0; j < dims[0]; j++)
            for(k = 0; k < dims[1]; k++)
                for(l = 0; l < (sizeof(static_buf_vls[0][0]) / sizeof(static_buf_vls[0][0][0])); l++)
                    static_buf_vls[j][k][l] = 'a' + rand() % 26;

        /* Fill write buffer */
        memcpy(wbuf_vls, wbuf_vls_init, sizeof(wbuf_vls));
        for(j = 0; j < dims[0]; j++)
            for(k = 0; k < dims[1]; k++) {
                /* 10% chance of having a NULL sequence */
                if(rand() % 10)
                    static_buf_vls[j][k][rand() % 8] = '\0';
                else
                    wbuf_vls[j][k] = NULL;
            } /* end for */

        /* Print message */
        if(verbose_g) {
            printf("Writing dataset with variable length strings.  buf =\n");
            print_vls(wbuf_vls[0]);
        } /* end if */

        /* Write data to whole dataset */
        if(H5Dwrite(dset_vls, type_vls, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf_vls) < 0)
            ERROR;

        /* Update fbuf */
        for(j = 0; j < dims[0]; j++)
            for(k = 0; k < dims[1]; k++)
                UPDATE_FBUF_VLS(fbuf_vls[j][k], wbuf_vls[j][k]);

        /* Read data from contiguous to non-contiguous */
        memcpy(rbuf_vls, rbuf_vls_init, sizeof(rbuf_vls));
        memcpy(ebuf_vls, rbuf_vls_init, sizeof(rbuf_vls));
        if(H5Dread(dset_vls, type_vls, space_ncontig, space_contig, H5P_DEFAULT, rbuf_vls) < 0)
            ERROR;

        /* Print message */
        if(verbose_g) {
            printf("Read dataset with variable length strings with selection.  buf =\n");
            print_vls(rbuf_vls[0]);
        } /* end if */

        /* Update ebuf */
        ebuf_vls[0][1] = fbuf_vls[1][0];
        ebuf_vls[1][1] = fbuf_vls[1][1];
        ebuf_vls[2][1] = fbuf_vls[2][0];
        ebuf_vls[3][1] = fbuf_vls[2][1];

        /* Check buffer */
        if(check_vls(ebuf_vls[0], rbuf_vls[0]) < 0) {
            (void)H5Dvlen_reclaim(type_vls, space_ncontig, H5P_DEFAULT, rbuf_vls);
            ERROR;
        } /* end if */

        /* Reclaim read buffer */
        if(H5Dvlen_reclaim(type_vls, space_ncontig, H5P_DEFAULT, rbuf_vls) < 0)
            ERROR;

        if(verbose_g)
            printf("\n");

        /* Fill write data buffer */
        for(j = 0; j < dims[0]; j++)
            for(k = 0; k < dims[1]; k++)
                for(l = 0; l < (sizeof(static_buf_vls[0][0]) / sizeof(static_buf_vls[0][0][0])); l++)
                    static_buf_vls[j][k][l] = 'a' + rand() % 26;

        /* Fill write buffer */
        memcpy(wbuf_vls, wbuf_vls_init, sizeof(wbuf_vls));
        for(j = 0; j < dims[0]; j++)
            for(k = 0; k < dims[1]; k++) {
                /* 10% chance of having a NULL sequence */
                if(rand() % 10)
                    static_buf_vls[j][k][rand() % 8] = '\0';
                else
                    wbuf_vls[j][k] = NULL;
            } /* end for */

        /* Print message */
        if(verbose_g) {
            printf("Writing dataset with variable length strings with selection.  buf =\n");
            print_vls(wbuf_vls[0]);
        } /* end if */

        /* Write data to dataset from non-contiguous to contiguous */
        if(H5Dwrite(dset_vls, type_vls, space_contig, space_ncontig, H5P_DEFAULT, wbuf_vls) < 0)
            ERROR;

        /* Update fbuf */
        UPDATE_FBUF_VLS(fbuf_vls[0][1], wbuf_vls[1][0]);
        UPDATE_FBUF_VLS(fbuf_vls[1][1], wbuf_vls[1][1]);
        UPDATE_FBUF_VLS(fbuf_vls[2][1], wbuf_vls[2][0]);
        UPDATE_FBUF_VLS(fbuf_vls[3][1], wbuf_vls[2][1]);

        /* Read entire dataset */
        memcpy(rbuf_vls, rbuf_vls_init, sizeof(rbuf_vls));
        memcpy(ebuf_vls, rbuf_vls_init, sizeof(rbuf_vls));
        if(H5Dread(dset_vls, type_vls, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf_vls) < 0)
            ERROR;

        /* Print message */
        if(verbose_g) {
            printf("Read dataset with variable length strings.  buf =\n");
            print_vls(rbuf_vls[0]);
        } /* end if */

        /* Check buffer */
        if(check_vls(fbuf_vls[0], rbuf_vls[0]) < 0) {
            (void)H5Dvlen_reclaim(type_vls, space, H5P_DEFAULT, rbuf_vls);
            ERROR;
        } /* end if */

        /* Reclaim read buffer */
        if(H5Dvlen_reclaim(type_vls, space, H5P_DEFAULT, rbuf_vls) < 0)
            ERROR;

        if(verbose_g)
            printf("\n");
    } /* end for */

    /*
     * Close
     */
    if(H5Aclose(attr_vla) < 0)
        ERROR;
    if(H5Aclose(attr_vls) < 0)
        ERROR;
    if(H5Dclose(dset_vla) < 0)
        ERROR;
    if(H5Dclose(dset_vls) < 0)
        ERROR;
    if(H5Fclose(file) < 0)
        ERROR;
    if(H5Tclose(type_vla) < 0)
        ERROR;
    if(H5Tclose(type_vls) < 0)
        ERROR;
    if(H5Sclose(space) < 0)
        ERROR;
    if(H5Sclose(space_contig) < 0)
        ERROR;
    if(H5Sclose(space_ncontig) < 0)
        ERROR;
    if(H5Pclose(fapl) < 0)
        ERROR;

    for(i = 0; i < dims[0]; i++)
        for(j = 0; j < dims[1]; j++) {
            if(fbuf_vla[i][j].p)
                free(fbuf_vla[i][j].p);
            if(fbuf_vls[i][j])
                free(fbuf_vls[i][j]);
        } /* end for */

    printf("Success\n");

    (void)MPI_Finalize();
    return 0;

error:
    H5E_BEGIN_TRY {
        H5Aclose(attr_vla);
        H5Aclose(attr_vls);
        H5Dclose(dset_vla);
        H5Dclose(dset_vls);
        H5Fclose(file);
        H5Tclose(type_vla);
        H5Tclose(type_vls);
        H5Sclose(space);
        H5Sclose(space_contig);
        H5Sclose(space_ncontig);
        H5Pclose(fapl);
    } H5E_END_TRY;

    for(i = 0; i < dims[0]; i++)
        for(j = 0; j < dims[1]; j++) {
            if(fbuf_vla[i][j].p)
                free(fbuf_vla[i][j].p);
            if(fbuf_vls[i][j])
                free(fbuf_vls[i][j]);
        } /* end for */

    (void)MPI_Finalize();
    return 1;
}