1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /*
15  * Programmer:  Quincey Koziol
16  *              Thursday, November 14, 2002
17  *
18  * Purpose:	    Create a dataset compressed with the deflate filter.
19  *              This program is used to create the test file `tdeflate.h5'
20  *              which has a dataset compressed with the "deflate" I/O filter.
21  *              This dataset will be used to verify the correct behavior of
22  *              the library when a filter is not available for a dataset which
23  *              requires it.
24  */
25 
26 #include "h5test.h"
27 
28 #define TESTFILE   "deflate.h5"
29 
30 /* 2-D dataset with fixed dimensions */
31 #define SPACE_RANK	2
32 #define SPACE_DIM1	100
33 #define SPACE_DIM2	200
34 #define CHUNK_DIM1	50
35 #define CHUNK_DIM2	50
36 
37 
38 
39 /*-------------------------------------------------------------------------
40  * Function:	main
41  *
42  * Return:      EXIT_SUCCESS/EXIT_FAILURE
43  *
44  * Programmer:	Quincey Koziol
45  *              Thursday, November 14, 2002
46  *
47  *-------------------------------------------------------------------------
48  */
49 int
main(void)50 main(void)
51 {
52     hid_t       fid = -1, sid = -1, did = -1, dcpl_id = -1;
53     hsize_t     dims[SPACE_RANK] = {SPACE_DIM1, SPACE_DIM2};
54     hsize_t	    chunk_dims[SPACE_RANK] = {CHUNK_DIM1, CHUNK_DIM2};
55     size_t      i,j;                    /* Local index variables */
56     int        *data = NULL;            /* Dataset data */
57 
58     /* Initialize the data */
59     /* (Try for something easily compressible) */
60     if(NULL == (data = (int *)HDmalloc(SPACE_DIM1 * SPACE_DIM2 * sizeof(int))))
61         TEST_ERROR
62 
63     for(i = 0; i < SPACE_DIM1; i++)
64         for(j = 0; j < SPACE_DIM2; j++)
65             data[(i * SPACE_DIM2) + j] = (int)(j % 5);
66 
67     /* Create the file */
68     if((fid = H5Fcreate(TESTFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
69         FAIL_STACK_ERROR
70 
71     /* Create the dataspace */
72     if((sid = H5Screate_simple(SPACE_RANK, dims, NULL)) < 0)
73         FAIL_STACK_ERROR
74 
75     /* Create the dataset creation property list */
76     if((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) < 0)
77         FAIL_STACK_ERROR
78 
79     /* Set up for deflated data */
80     if(H5Pset_chunk(dcpl_id, 2, chunk_dims) < 0)
81         FAIL_STACK_ERROR
82     if(H5Pset_deflate(dcpl_id, 9) < 0)
83         FAIL_STACK_ERROR
84 
85     /* Create the compressed dataset */
86     if((did = H5Dcreate2(fid, "Dataset1", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0)
87         FAIL_STACK_ERROR
88 
89     /* Write the data to the dataset */
90     if(H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data) < 0)
91         FAIL_STACK_ERROR
92 
93     /* Close everything */
94     if(H5Pclose(dcpl_id) < 0)
95         FAIL_STACK_ERROR
96     if(H5Dclose(did) < 0)
97         FAIL_STACK_ERROR
98     if(H5Sclose(sid) < 0)
99         FAIL_STACK_ERROR
100     if(H5Fclose(fid) < 0)
101         FAIL_STACK_ERROR
102 
103     HDfree(data);
104 
105     return EXIT_SUCCESS;
106 
107 error:
108     if(data)
109         HDfree(data);
110     H5E_BEGIN_TRY {
111         H5Pclose(dcpl_id);
112         H5Dclose(did);
113         H5Sclose(sid);
114         H5Fclose(fid);
115     } H5E_END_TRY;
116 
117     return EXIT_FAILURE;
118 } /* end main() */
119 
120