summaryrefslogtreecommitdiffstats
path: root/test/gen_filespace.c
blob: e0c42e8fa726e857c89d21a3290c72956bb14943 (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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * 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.     *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "hdf5.h"

#define NELMTS(X)    	(sizeof(X)/sizeof(X[0]))	/* # of elements */
#define TEST_THRESHOLD2	2             			/* Free space section threshold */

const char *FILENAMES[] = {
    "filespace_persist.h5",	/* H5F_FILE_SPACE_ALL_PERSIST */
    "filespace_default.h5",	/* H5F_FILE_SPACE_ALL */
    "filespace_aggr_vfd.h5",	/* H5F_FILE_SPACE_AGGR_VFD */
    "filespace_vfd.h5",		/* H5F_FILE_SPACE_VFD */
    "filespace_threshold.h5"	/* H5F_FILE_SPACE_ALL, non-default threshold */
};

#define DATASET		"dset"
#define NUM_ELMTS	100

/*
 * Compile and run this program in file-space branch to generate
 * HDF5 files with different kinds of file space strategies
 * Move the HDF5 files to the 1.6 and 1.8 branch for compatibility
 * testing:test_filespace_compatible() will use the files
 */
static void gen_file(void)
{
    hid_t   	fid;
    hid_t   	fcpl;
    hid_t       dataset, space;
    hsize_t     dim[1];
    int         data[NUM_ELMTS];
    size_t      j;			/* Local index variable */
    int         i;			/* Local index variable */
    H5F_file_space_type_t fs_type;	/* File space handling strategy */

    for(j = 0, fs_type = H5F_FILE_SPACE_ALL_PERSIST; j < NELMTS(FILENAMES); j++, fs_type = (H5F_file_space_type_t)(fs_type + 1)) {
	/* Get a copy of the default file creation property */
	fcpl = H5Pcreate(H5P_FILE_CREATE);

	if(fs_type == H5F_FILE_SPACE_NTYPES) /* last file */
	    /* Set default strategy but non-default threshold */
	    H5Pset_file_space(fcpl, H5F_FILE_SPACE_ALL, (hsize_t)TEST_THRESHOLD2);
	else
	    /* Set specified file space strategy and free space section threshold */
	    H5Pset_file_space(fcpl, fs_type, (hsize_t)0);

	/* Create the file with the file space info */
	fid = H5Fcreate(FILENAMES[j], H5F_ACC_TRUNC, fcpl, H5P_DEFAULT);

	dim[0] = NUM_ELMTS;
	space = H5Screate_simple(1, dim, NULL);
	dataset = H5Dcreate2(fid, DATASET, H5T_NATIVE_INT, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

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

	H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
	H5Dclose(dataset);
	H5Sclose(space);
	H5Fclose(fid);
    }
}

int main(void)
{
    gen_file();

    return 0;
}