summaryrefslogtreecommitdiffstats
path: root/doxygen/dox/cookbook/Files.c
blob: b824933a37a856475cfe1f9884f189b26daccb69 (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
/* -*- c-file-style: "stroustrup" -*- */

#include "hdf5.h"

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

int
main(void)
{
    int ret_val = EXIT_SUCCESS;

    //! <!-- [free_space] -->
    {
        __label__ fail_fcpl, fail_fapl, fail_file;
        hid_t fcpl, fapl, file;

        if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) {
            ret_val = EXIT_FAILURE;
            goto fail_fcpl;
        }
#if H5_VERSION_GE(1, 10, 1)
        if (H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_FSM_AGGR, 1, 4096) < 0) {
#else
#error HDF5 1.10.1+ required
#endif
            ret_val = EXIT_FAILURE;
            goto fail_fapl;
        }

        if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) {
            ret_val = EXIT_FAILURE;
            goto fail_fapl;
        }
#if H5_VERSION_GE(1, 10, 1)
        if (H5Pset_libver_bounds(fapl, H5F_LIBVER_V110, H5F_LIBVER_LATEST) < 0) {
#else
#error HDF5 1.10.x+ required
#endif
            ret_val = EXIT_FAILURE;
            goto fail_file;
        }

        if ((file = H5Fcreate("free_space.h5", H5F_ACC_TRUNC, fcpl, fapl)) < 0) {
            ret_val = EXIT_FAILURE;
            goto fail_file;
        }
        H5Fclose(file);

fail_file:
        H5Pclose(fapl);
fail_fapl:
        H5Pclose(fcpl);
fail_fcpl:;
    }
    //! <!-- [free_space] -->

    //! <!-- [user_block] -->
    {
        __label__ fail_fcpl, fail_file;
        hid_t fcpl, file;

        if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) {
            ret_val = EXIT_FAILURE;
            goto fail_fcpl;
        }
        if (H5Pset_userblock(fcpl, 8192 * 1024) < 0) {
            ret_val = EXIT_FAILURE;
            goto fail_file;
        }
        if ((file = H5Fcreate("userblock.h5", H5F_ACC_TRUNC, fcpl, H5P_DEFAULT)) < 0) {
            ret_val = EXIT_FAILURE;
            goto fail_file;
        }
        H5Fclose(file);

fail_file:
        H5Pclose(fcpl);
fail_fcpl:;
    }
    //! <!-- [user_block] -->

    assert(ret_val == EXIT_SUCCESS);

    return ret_val;
}