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 #include "hdf5.h"
15 #include <assert.h>
16
17 #define NELMTS(X) (sizeof(X)/sizeof(X[0])) /* # of elements */
18
19 const char *FILENAMES[] = {
20 "fsm_aggr_nopersist.h5", /* H5F_FSPACE_STRATEGY_FSM_AGGR + not persisting free-space */
21 "fsm_aggr_persist.h5", /* H5F_FSPACE_STRATEGY_FSM_AGGR + persisting free-space */
22 "paged_nopersist.h5", /* H5F_FSPACE_STRATEGY_PAGE + not persisting free-space */
23 "paged_persist.h5", /* H5F_FSPACE_STRATEGY_PAGE + persisting free-space */
24 "aggr.h5", /* H5F_FSPACE_STRATEGY_AGGR */
25 "none.h5" /* H5F_FSPACE_STRATEGY_NONE */
26 };
27
28 #define DATASET "dset"
29 #define NUM_ELMTS 100
30 #define FALSE 0
31 #define TRUE 1
32 #define INC_ENUM(TYPE,VAR) (VAR)=((TYPE)((VAR)+1))
33
34 /*
35 * Compile and run this program in the trunk to generate
36 * HDF5 files with combinations of 4 file space strategies
37 * and persist/not persist free-space.
38 * The library creates the file space info message with "mark if unknown"
39 * in these files.
40 *
41 * Move these files to 1.8 branch for compatibility testing:
42 * test_filespace_compatible() in test/tfile.c will use these files.
43 *
44 * Copy these files from the 1.8 branch back to the trunk for
45 * compatibility testing via test_filespace_round_compatible() in test/tfile.c.
46 *
47 */
main(void)48 int main(void)
49 {
50 hid_t fid = -1; /* File ID */
51 hid_t fcpl = -1; /* File creation property list */
52 hid_t did = -1; /* Dataset ID */
53 hid_t sid = -1; /* Dataspace ID */
54 hsize_t dim[1]; /* Dimension sizes */
55 int data[NUM_ELMTS]; /* Buffer for data */
56 int i, j; /* Local index variables */
57 H5F_fspace_strategy_t fs_strategy; /* File space handling strategy */
58 unsigned fs_persist; /* Persisting free-space or not */
59
60 j = 0;
61 for(fs_strategy = H5F_FSPACE_STRATEGY_FSM_AGGR; fs_strategy < H5F_FSPACE_STRATEGY_NTYPES; INC_ENUM(H5F_fspace_strategy_t, fs_strategy)) {
62 for(fs_persist = FALSE; fs_persist <= TRUE; fs_persist++) {
63
64 if(fs_persist && fs_strategy >= H5F_FSPACE_STRATEGY_AGGR)
65 continue;
66
67 /* Get a copy of the default file creation property */
68 if((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0)
69 goto error;
70
71 if(H5Pset_file_space_strategy(fcpl, fs_strategy, fs_persist, (hsize_t)1) < 0)
72 goto error;
73
74 /* Create the file with the file space info */
75 if((fid = H5Fcreate(FILENAMES[j], H5F_ACC_TRUNC, fcpl, H5P_DEFAULT)) < 0)
76 goto error;
77
78 /* Create the dataset */
79 dim[0] = NUM_ELMTS;
80 if((sid = H5Screate_simple(1, dim, NULL)) < 0)
81 goto error;
82 if((did = H5Dcreate2(fid, DATASET, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
83 goto error;
84
85 for(i = 0; i < NUM_ELMTS; i++)
86 data[i] = i;
87
88 /* Write the dataset */
89 if(H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data) < 0)
90 goto error;
91
92 /* Closing */
93 if(H5Dclose(did) < 0)
94 goto error;
95 if(H5Sclose(sid) < 0)
96 goto error;
97 if(H5Fclose(fid) < 0)
98 goto error;
99 if(H5Pclose(fcpl) < 0)
100 goto error;
101 ++j;
102 }
103 }
104 assert(j == NELMTS(FILENAMES));
105
106 return 0;
107
108 error:
109 H5E_BEGIN_TRY {
110 H5Sclose(sid);
111 H5Sclose(did);
112 H5Pclose(fcpl);
113 H5Fclose(fid);
114 } H5E_END_TRY;
115 return -1;
116 }
117