File: tst_h_vars.c

package info (click to toggle)
netcdf 1:4.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 104,952 kB
  • sloc: ansic: 228,683; sh: 10,980; yacc: 2,561; makefile: 1,319; lex: 1,173; xml: 173; awk: 2
file content (601 lines) | stat: -rw-r--r-- 23,077 bytes parent folder | download | duplicates (2)
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
/* This is part of the netCDF package. Copyright 2020 University
   Corporation for Atmospheric Research/Unidata See COPYRIGHT file for
   conditions of use.

   Test HDF5 file code. These are not intended to be exhaustive tests,
   but they use HDF5 the same way that netCDF-4 does, so if these
   tests don't work, than netCDF-4 won't work either.

   This files tests dataset creation and writing.

   Ed Hartnett
*/

#include "h5_err_macros.h"
#include <hdf5.h>

#define FILE_NAME "tst_h_vars.h5"
#define TEST_NAME "tst_h_vars"
#define GRP_NAME "Henry_V"
#define VAR_BOOL_NAME "Southhamptons_Battle_Record"
#define GRP2_NAME "Some_3D_Met_Data"
#define DIM1_LEN 3
#define MAX_DIMS 255
#define NDIM1 1

int
main()
{
    hid_t fileid, grpid, spaceid, datasetid;
    int bool_out[DIM1_LEN] = {0, 1, 0};
    hsize_t dims[1];

    printf("\n*** Checking HDF5 variable functions.\n");
    printf("*** Checking HDF5 boolean variables...");

    /* Open file and create group. */
    if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
                            H5P_DEFAULT)) < 0) ERR;
    if ((grpid = H5Gcreate(fileid, GRP_NAME, 0)) < 0) ERR;

    /* Write an array of bools. */
    dims[0] = DIM1_LEN;
    if ((spaceid = H5Screate_simple(1, dims, dims)) < 0) ERR;
    if ((datasetid = H5Dcreate(grpid, VAR_BOOL_NAME, H5T_NATIVE_HBOOL,
                               spaceid, H5P_DEFAULT)) < 0) ERR;
    if (H5Dwrite(datasetid, H5T_NATIVE_HBOOL, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                 bool_out) < 0) ERR;
    if (H5Dclose(datasetid) < 0 ||
        H5Sclose(spaceid) < 0 ||
        H5Gclose(grpid) < 0 ||
        H5Fclose(fileid) < 0)
        ERR;

    SUMMARIZE_ERR;

    printf("*** Checking HDF5 variable with unlimited dimension...");
    {
#define LAT_LEN 2
#define LON_LEN 3
#define NDIMS 3
#define LAT_NAME "Lat"
#define LON_NAME "Lon"
#define TIME_NAME "Time"
#define PRES_NAME "Pressure"
#define TEMP_NAME "Temperature"

        hid_t fileid, grpid, spaceid, write_spaceid, spaceid_in, mem_spaceid;
        hid_t pres_dsid, temp_dsid, cparmsid;
        float float_data_out[LAT_LEN][LON_LEN];
        hsize_t dims[NDIMS], max_dims[NDIMS];
        hsize_t dims_in[NDIMS], max_dims_in[NDIMS];
        hsize_t start[MAX_DIMS], count[MAX_DIMS];
        int lat, lon;

        /* Set up some phoney data, 1 record's worth. In C, first
         * dimension varies most slowly. */
        for (lat = 0; lat < LAT_LEN; lat++)
            for (lon = 0; lon < LON_LEN; lon++)
                float_data_out[lat][lon] = -666.666;

        /* Create file and group. */
        if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
                                H5P_DEFAULT)) < 0) ERR;
        if ((grpid = H5Gcreate(fileid, GRP2_NAME, 0)) < 0) ERR;

        /* Create a space corresponding to these three dimensions. */
        dims[0] = 0;
        dims[1] = LAT_LEN;
        dims[2] = LON_LEN;
        max_dims[0] = H5S_UNLIMITED;
        max_dims[1] = LAT_LEN;
        max_dims[2] = LON_LEN;
        if ((spaceid = H5Screate_simple(NDIMS, dims, max_dims)) < 0) ERR;

        /* Enable chunking for unlimited datasets.  */
        if ((cparmsid = H5Pcreate(H5P_DATASET_CREATE)) < 0) ERR;
        dims[0] = 1;
        dims[1] = 1;
        dims[2] = 1;
        if (H5Pset_chunk(cparmsid, NDIMS, dims) < 0) ERR;

        /* Create two variables which use this space. */
        if ((pres_dsid = H5Dcreate(grpid, PRES_NAME, H5T_NATIVE_FLOAT,
                                   spaceid, cparmsid)) < 0) ERR;
        if ((temp_dsid = H5Dcreate(grpid, TEMP_NAME, H5T_NATIVE_FLOAT,
                                   spaceid, cparmsid)) < 0) ERR;

        /* Get the spaceid and check various things. */
        if ((spaceid_in = H5Dget_space(pres_dsid)) < 0) ERR;
        if (H5Sget_simple_extent_dims(spaceid_in, dims_in,
                                      max_dims_in) < 0) ERR;
        if (dims_in[0] != 0 || dims_in[1] != LAT_LEN || dims_in[2] != LON_LEN) ERR;
        if (max_dims_in[0] != H5S_UNLIMITED || max_dims_in[1] != LAT_LEN || max_dims_in[2] != LON_LEN) ERR;

        /* Extend each of them to hold one record. */
        dims[0] = 1;
        dims[1] = LAT_LEN;
        dims[2] = LON_LEN;
        if (H5Dextend(pres_dsid, dims) < 0) ERR;
        if (H5Dextend(temp_dsid, dims) < 0) ERR;

        /* Create a space to deal with one record at a time in memory. */
        if ((mem_spaceid = H5Screate_simple(NDIMS, dims, NULL)) < 0) ERR;

        /* Create a space to write one record. */
        if ((write_spaceid = H5Screate_simple(NDIMS, dims, NULL)) < 0) ERR;

        /* Write one record of data to each dataset. */
        if (H5Dwrite(pres_dsid, H5T_IEEE_F32BE, mem_spaceid, write_spaceid,
                     H5P_DEFAULT, float_data_out) < 0) ERR;
        if (H5Dwrite(temp_dsid, H5T_IEEE_F32LE, mem_spaceid, write_spaceid,
                     H5P_DEFAULT, float_data_out) < 0) ERR;

        /* Get the spaceid and check various things. */
        if ((spaceid_in = H5Dget_space(temp_dsid)) < 0) ERR;
        if (H5Sget_simple_extent_dims(spaceid_in, dims_in,
                                      max_dims_in) < 0) ERR;
        if (dims_in[0] != 1 || dims_in[1] != LAT_LEN || dims_in[2] != LON_LEN) ERR;
        if (max_dims_in[0] != H5S_UNLIMITED || max_dims_in[1] != LAT_LEN || max_dims_in[2] != LON_LEN) ERR;

        /* Extend each of them to hold a second record. */
        dims[0] = 2;
        dims[1] = LAT_LEN;
        dims[2] = LON_LEN;
        if (H5Dextend(pres_dsid, dims) < 0) ERR;
        if (H5Dextend(temp_dsid, dims) < 0) ERR;

        /* Create a space to write second record. */
        if ((write_spaceid = H5Screate_simple(NDIMS, dims, NULL)) < 0) ERR;
        count[0] = 1;
        count[1] = LAT_LEN;
        count[2] = LON_LEN;
        start[0] = 1;
        start[1] = 0;
        start[2] = 0;
        if (H5Sselect_hyperslab(write_spaceid, H5S_SELECT_SET,
                                start, NULL, count, NULL) < 0) ERR;

        /* Write second record of data to each dataset. */
        if (H5Dwrite(pres_dsid, H5T_IEEE_F32LE, mem_spaceid, write_spaceid,
                     H5P_DEFAULT, float_data_out) < 0) ERR;
        if (H5Dwrite(temp_dsid, H5T_IEEE_F32LE, mem_spaceid, write_spaceid,
                     H5P_DEFAULT, float_data_out) < 0) ERR;

        /* Get the spaceid and check various things. */
        if ((spaceid_in = H5Dget_space(pres_dsid)) < 0) ERR;
        if (H5Sget_simple_extent_dims(spaceid_in, dims_in,
                                      max_dims_in) < 0) ERR;
        if (dims_in[0] != 2 || dims_in[1] != LAT_LEN || dims_in[2] != LON_LEN) ERR;
        if (max_dims_in[0] != H5S_UNLIMITED || max_dims_in[1] != LAT_LEN || max_dims_in[2] != LON_LEN) ERR;

        /* Close up the shop. */
        if (H5Dclose(pres_dsid) < 0 ||
            H5Dclose(temp_dsid) < 0 ||
            H5Sclose(spaceid) < 0 ||
            H5Gclose(grpid) < 0 ||
            H5Fclose(fileid) < 0) ERR;

    }

    SUMMARIZE_ERR;
    printf("*** Checking HDF5 deflate filter setting and getting...");
#define DEFLATE_LEVEL 9
#define MAX_NAME 100
#define NUM_CD_ELEM 10
/* HDF5 defines this... */
#define DEFLATE_NAME "deflate"
    {
        H5Z_filter_t filter;
        int num_filters;
        hid_t propid;
        unsigned int flags, cd_values[NUM_CD_ELEM], filter_config;
        size_t cd_nelems = NUM_CD_ELEM;
        size_t namelen = MAX_NAME;
        char name[MAX_NAME + 1];


        /* Open file and create group. */
        if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
                                H5P_DEFAULT)) < 0) ERR;
        if ((grpid = H5Gcreate(fileid, GRP_NAME, 0)) < 0) ERR;

        /* Write an array of bools, with compression. */
        dims[0] = DIM1_LEN;
        if ((propid = H5Pcreate(H5P_DATASET_CREATE)) < 0) ERR;
        if (H5Pset_layout(propid, H5D_CHUNKED)) ERR;
        if (H5Pset_chunk(propid, 1, dims)) ERR;
        if (H5Pset_deflate(propid, DEFLATE_LEVEL)) ERR;
        if ((spaceid = H5Screate_simple(1, dims, dims)) < 0) ERR;
        if ((datasetid = H5Dcreate(grpid, VAR_BOOL_NAME, H5T_NATIVE_HBOOL,
                                   spaceid, propid)) < 0) ERR;
        if (H5Dwrite(datasetid, H5T_NATIVE_HBOOL, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                     bool_out) < 0) ERR;
        if (H5Dclose(datasetid) < 0 ||
            H5Pclose(propid) < 0 ||
            H5Sclose(spaceid) < 0 ||
            H5Gclose(grpid) < 0 ||
            H5Fclose(fileid) < 0)
            ERR;

        /* Now reopen the file and check. */
        if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR;
        if ((grpid = H5Gopen(fileid, GRP_NAME)) < 0) ERR;
        if ((datasetid = H5Dopen1(grpid, VAR_BOOL_NAME)) < 0) ERR;
        if ((propid = H5Dget_create_plist(datasetid)) < 0) ERR;

        /* The possible values of filter (which is just an int) can be
         * found in H5Zpublic.h. */
        if ((num_filters = H5Pget_nfilters(propid)) < 0) ERR;
        if (num_filters != 1) ERR;
        if ((filter = H5Pget_filter2(propid, 0, &flags, &cd_nelems, cd_values,
                                     namelen, name, &filter_config)) < 0) ERR;
        if (filter != H5Z_FILTER_DEFLATE || cd_nelems != 1 ||
            cd_values[0] != DEFLATE_LEVEL || strcmp(name, DEFLATE_NAME)) ERR;

        if (H5Dclose(datasetid) < 0 ||
            H5Pclose(propid) < 0 ||
            H5Gclose(grpid) < 0 ||
            H5Fclose(fileid) < 0)
            ERR;
    }

    SUMMARIZE_ERR;
    printf("*** Checking HDF5 deflate, fletcher32, shuffle filter setting and getting...");
    {
        H5Z_filter_t filter;
        int num_filters;
        hid_t propid;
        unsigned int flags, cd_values[NUM_CD_ELEM], filter_config;
        size_t cd_nelems = NUM_CD_ELEM;
        size_t namelen = MAX_NAME;
        char name[MAX_NAME + 1];
        int found_shuffle = 0, found_fletcher32 = 0, found_deflate = 0;
        int f;

        /* Open file and create group. */
        if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
                                H5P_DEFAULT)) < 0) ERR;
        if ((grpid = H5Gcreate(fileid, GRP_NAME, 0)) < 0) ERR;

        /* Write an array of bools, with compression, fletcher32
         * checksum, shuffle filters. Like a hoogie with "the works." */
        dims[0] = DIM1_LEN;
        if ((propid = H5Pcreate(H5P_DATASET_CREATE)) < 0) ERR;
        if (H5Pset_layout(propid, H5D_CHUNKED)) ERR;
        if (H5Pset_chunk(propid, 1, dims)) ERR;
        if (H5Pset_shuffle(propid)) ERR;
        if (H5Pset_deflate(propid, DEFLATE_LEVEL)) ERR;
        if (H5Pset_fletcher32(propid)) ERR;
        if ((spaceid = H5Screate_simple(1, dims, dims)) < 0) ERR;
        if ((datasetid = H5Dcreate(grpid, VAR_BOOL_NAME, H5T_NATIVE_HBOOL,
                                   spaceid, propid)) < 0) ERR;
        if (H5Dwrite(datasetid, H5T_NATIVE_HBOOL, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                     bool_out) < 0) ERR;
        if (H5Dclose(datasetid) < 0 ||
            H5Pclose(propid) < 0 ||
            H5Sclose(spaceid) < 0 ||
            H5Gclose(grpid) < 0 ||
            H5Fclose(fileid) < 0)
            ERR;

        /* Now reopen the file and check. */
        if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR;
        if ((grpid = H5Gopen(fileid, GRP_NAME)) < 0) ERR;
        if ((datasetid = H5Dopen1(grpid, VAR_BOOL_NAME)) < 0) ERR;
        if ((propid = H5Dget_create_plist(datasetid)) < 0) ERR;

        /* The possible values of filter (which is just an int) can be
         * found in H5Zpublic.h. */
        if ((num_filters = H5Pget_nfilters(propid)) < 0) ERR;
        if (num_filters != 3) ERR;
        for (f = 0; f < num_filters; f++)
        {
            if ((filter = H5Pget_filter2(propid, f, &flags, &cd_nelems, cd_values,
                                         namelen, name, &filter_config)) < 0) ERR;
            switch (filter)
            {
            case H5Z_FILTER_SHUFFLE:
                found_shuffle++;
                break;
            case H5Z_FILTER_FLETCHER32:
                found_fletcher32++;
                break;
            case H5Z_FILTER_DEFLATE:
                found_deflate++;
                if (cd_nelems != 1 || cd_values[0] != DEFLATE_LEVEL ||
                    strcmp(name, DEFLATE_NAME)) ERR;
                break;
            default:
                break;
            }
        }
        if (!found_fletcher32 || !found_deflate || !found_shuffle) ERR;

        if (H5Dclose(datasetid) < 0 ||
            H5Pclose(propid) < 0 ||
            H5Gclose(grpid) < 0 ||
            H5Fclose(fileid) < 0)
            ERR;
    }

    SUMMARIZE_ERR;
    printf("*** Checking HDF5 endianness control...");

#define NATIVE_VAR_NAME "native_var"
#define LE_VAR_NAME "le_var"
#define BE_VAR_NAME "be_var"
    {
        int data[DIM1_LEN], data_in[DIM1_LEN];
        hid_t typeid, native_typeid;
        hid_t native_did, le_did, be_did;
        H5T_order_t order;
        htri_t equal;
        int i;

        for (i = 0; i < DIM1_LEN; i++)
            data[i] = i;

        /* Open file and create group. */
        if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
                                H5P_DEFAULT)) < 0) ERR;
        if ((grpid = H5Gcreate(fileid, GRP_NAME, 0)) < 0) ERR;

        /* Create a dataset of native endian. */
        dims[0] = DIM1_LEN;
        if ((spaceid = H5Screate_simple(1, dims, dims)) < 0) ERR;
        if ((native_did = H5Dcreate(grpid, NATIVE_VAR_NAME, H5T_NATIVE_INT,
                                    spaceid, H5P_DEFAULT)) < 0) ERR;
        if ((le_did = H5Dcreate(grpid, LE_VAR_NAME, H5T_STD_I32LE,
                                spaceid, H5P_DEFAULT)) < 0) ERR;
        if ((be_did = H5Dcreate(grpid, BE_VAR_NAME, H5T_STD_I32BE,
                                spaceid, H5P_DEFAULT)) < 0) ERR;
        if (H5Dwrite(native_did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                     data) < 0) ERR;
        if (H5Dwrite(le_did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                     data) < 0) ERR;
        if (H5Dwrite(be_did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                     data) < 0) ERR;
        if (H5Dclose(native_did) < 0 ||
            H5Dclose(le_did) < 0 ||
            H5Dclose(be_did) < 0 ||
            H5Sclose(spaceid) < 0 ||
            H5Gclose(grpid) < 0 ||
            H5Fclose(fileid) < 0)
            ERR;

        /* Now reopen the file and check. */
        if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR;
        if ((grpid = H5Gopen(fileid, GRP_NAME)) < 0) ERR;

        if ((native_did = H5Dopen1(grpid, NATIVE_VAR_NAME)) < 0) ERR;
        if ((typeid = H5Dget_type(native_did)) < 0) ERR;
        if ((native_typeid = H5Tget_native_type(typeid, H5T_DIR_DESCEND)) < 0) ERR;
        if ((order = H5Tget_order(typeid)) < 0) ERR;
        if ((equal = H5Tequal(typeid, native_typeid)) < 0) ERR;
        if (!equal) ERR;

        if (H5Dread(native_did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                    data_in) < 0) ERR;
        for (i = 0; i < DIM1_LEN; i++)
            if (data[i] != data_in[i]) ERR;

        if ((le_did = H5Dopen1(grpid, LE_VAR_NAME)) < 0) ERR;
        if ((typeid = H5Dget_type(le_did)) < 0) ERR;
        if ((order = H5Tget_order(typeid)) < 0) ERR;
        if (order != H5T_ORDER_LE) ERR;

        if (H5Dread(le_did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                    data_in) < 0) ERR;
        for (i = 0; i < DIM1_LEN; i++)
            if (data[i] != data_in[i]) ERR;

        if ((be_did = H5Dopen1(grpid, BE_VAR_NAME)) < 0) ERR;
        if ((typeid = H5Dget_type(be_did)) < 0) ERR;
        if ((order = H5Tget_order(typeid)) < 0) ERR;
        if (order != H5T_ORDER_BE) ERR;

        if (H5Dread(be_did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                    data_in) < 0) ERR;
        for (i = 0; i < DIM1_LEN; i++)
            if (data[i] != data_in[i]) ERR;

        if (H5Dclose(native_did) < 0 ||
            H5Dclose(le_did) < 0 ||
            H5Dclose(be_did) < 0 ||
            H5Gclose(grpid) < 0 ||
            H5Fclose(fileid) < 0)
            ERR;
    }

    SUMMARIZE_ERR;
#ifdef USE_SZIP
    printf("*** Checking szip functionality...");
#define SZIP_VAR_NAME "szip_var"
#define SZIP_DIM1_LEN 32
    {
        int data[SZIP_DIM1_LEN];
        hid_t plistid;
        hsize_t chunksize[NDIM1] = {SZIP_DIM1_LEN};
        int options_mask = 32, pixels_per_block = 4;
        hsize_t my_dims[NDIM1];
        int i;

        /* For info about HDF5 and szip, see
         * https://support.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-SetSzip
         * and
         * https://support.hdfgroup.org/doc_resource/SZIP/index.html. */

        for (i = 0; i < SZIP_DIM1_LEN; i++)
            data[i] = i;

        /* Open file and create group. */
        if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
                                H5P_DEFAULT)) < 0) ERR;
        if ((grpid = H5Gcreate(fileid, GRP_NAME, 0)) < 0) ERR;

        /* Create dataset creation property list. */
        if ((plistid = H5Pcreate(H5P_DATASET_CREATE)) < 0) ERR;

        /* Turn on chunking. */
        if (H5Pset_chunk(plistid, NDIM1, chunksize) < 0) ERR;

        /* Turn off object tracking times in HDF5 (as netcdf-4 does). */
        if (H5Pset_obj_track_times(plistid, 0) < 0) ERR;

        /* Turn on szip compression. */
        if (H5Pset_szip(plistid, options_mask, pixels_per_block) < 0) ERR;

        /* Create a space. */
        my_dims[0] = SZIP_DIM1_LEN;
        if ((spaceid = H5Screate_simple(1, my_dims, my_dims)) < 0) ERR;

        /* Create a dataset. */
        if ((datasetid = H5Dcreate2(grpid, SZIP_VAR_NAME, H5T_NATIVE_INT,
                                    spaceid, H5P_DEFAULT, plistid,
                                    H5P_DEFAULT)) < 0) ERR;

        /* Write data. */
        if (H5Dwrite(datasetid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                     data) < 0) ERR;

        /* Release resources. */
        if (H5Dclose(datasetid) < 0 ||
            H5Sclose(spaceid) < 0 ||
            H5Pclose(plistid) < 0 ||
            H5Gclose(grpid) < 0 ||
            H5Fclose(fileid) < 0)
            ERR;

        {
            /* Now reopen the file and check. */
            int data_in[SZIP_DIM1_LEN];
            hid_t native_did;
            int i;

            if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR;
            if ((grpid = H5Gopen(fileid, GRP_NAME)) < 0) ERR;

            if ((native_did = H5Dopen1(grpid, SZIP_VAR_NAME)) < 0) ERR;

            if (H5Dread(native_did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                        data_in) < 0) ERR;
            for (i = 0; i < SZIP_DIM1_LEN; i++)
                if (data[i] != data_in[i]) ERR;

            if (H5Dclose(native_did) < 0 ||
                H5Gclose(grpid) < 0 ||
                H5Fclose(fileid) < 0)
                ERR;
        }
    }
    SUMMARIZE_ERR;
    printf("*** Checking using szip and zlib on same var...");
#define BOTH_VAR_NAME "szip_var"
#define BOTH_DIM1_LEN 50
#define NUM_FILE 5
#define MAX_STR 80
    {
        int data[BOTH_DIM1_LEN];
        hid_t plistid;
        hsize_t chunksize[NDIM1] = {BOTH_DIM1_LEN};
        int options_mask = 32, pixels_per_block = 4;
        int deflate_level = 3;
        hsize_t my_dims[NDIM1];
        int i, f;

        /* Create data. */
        for (i = 0; i < BOTH_DIM1_LEN; i++)
            data[i] = i;

        /* Run test 4 times. */
        for (f = 0; f < NUM_FILE; f++)
        {
            char file_name[MAX_STR + 1];
            char desc[NUM_FILE][MAX_STR + 1] = {"uncompressed", "zlib",
                                                "szip", "zlib_and_szip",
                                                "szip_and_zlib"};

            /* Open file and create group. */
            sprintf(file_name, "%s_%s.h5", TEST_NAME, desc[f]);
            if ((fileid = H5Fcreate(file_name, H5F_ACC_TRUNC, H5P_DEFAULT,
                                    H5P_DEFAULT)) < 0) ERR;
            if ((grpid = H5Gcreate(fileid, GRP_NAME, 0)) < 0) ERR;

            /* Create dataset creation property list. */
            if ((plistid = H5Pcreate(H5P_DATASET_CREATE)) < 0) ERR;

            /* Turn on chunking. */
            if (H5Pset_chunk(plistid, NDIM1, chunksize) < 0) ERR;

            /* Turn off object tracking times in HDF5 (as netcdf-4 does). */
            if (H5Pset_obj_track_times(plistid, 0) < 0) ERR;

            /* Turn on compression for some files. */
            switch (f)
            {
            case 1:
                if (H5Pset_deflate(plistid, deflate_level) < 0)
                    break;
            case 2:
                if (H5Pset_szip(plistid, options_mask, pixels_per_block) < 0) ERR;
                break;
            case 3:
                if (H5Pset_deflate(plistid, deflate_level) < 0)
                if (H5Pset_szip(plistid, options_mask, pixels_per_block) < 0) ERR;
                break;
            case 4:
                if (H5Pset_szip(plistid, options_mask, pixels_per_block) < 0) ERR;
                if (H5Pset_deflate(plistid, deflate_level) < 0)
                break;
            }


            /* Create a space. */
            my_dims[0] = BOTH_DIM1_LEN;
            if ((spaceid = H5Screate_simple(1, my_dims, my_dims)) < 0) ERR;

            /* Create a dataset. */
            if ((datasetid = H5Dcreate2(grpid, BOTH_VAR_NAME, H5T_NATIVE_INT,
                                        spaceid, H5P_DEFAULT, plistid,
                                        H5P_DEFAULT)) < 0) ERR;

            /* Write data. */
            if (H5Dwrite(datasetid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                         data) < 0) ERR;

            /* Release resources. */
            if (H5Dclose(datasetid) < 0 ||
                H5Sclose(spaceid) < 0 ||
                H5Pclose(plistid) < 0 ||
                H5Gclose(grpid) < 0 ||
                H5Fclose(fileid) < 0)
                ERR;

            {
                /* Now reopen the file and check. */
                int data_in[BOTH_DIM1_LEN];
                hid_t native_did;
                int i;

                if ((fileid = H5Fopen(file_name, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR;
                if ((grpid = H5Gopen(fileid, GRP_NAME)) < 0) ERR;

                if ((native_did = H5Dopen1(grpid, BOTH_VAR_NAME)) < 0) ERR;

                if (H5Dread(native_did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                            data_in) < 0) ERR;
                for (i = 0; i < BOTH_DIM1_LEN; i++)
                    if (data[i] != data_in[i]) ERR;

                if (H5Dclose(native_did) < 0 ||
                    H5Gclose(grpid) < 0 ||
                    H5Fclose(fileid) < 0)
                    ERR;
            }
        } /* next file */
    }
    SUMMARIZE_ERR;
#endif /* USE_SZIP */
    FINAL_RESULTS;
}