summaryrefslogtreecommitdiffstats
path: root/doxygen/examples/H5P_examples.c
blob: cdfc03b906c34f0b246f02add203e1c84bc25355 (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
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
/* -*- c-file-style: "stroustrup" -*- */

#include "hdf5.h"

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

int
main(void)
{
    int ret_val = EXIT_SUCCESS;

    //! <!-- [create] -->
    {
        __label__ fail_dcpl;
        hid_t dcpl;

        // every property list is created as an instance of a suitable
        // property list class
        if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) == H5I_INVALID_HID) {
            ret_val = EXIT_FAILURE;
            goto fail_dcpl;
        }

        // ...

        H5Pclose(dcpl);
fail_dcpl:;
    }
    //! <!-- [create] -->

    //! <!-- [read] -->
    {
        __label__ fail_dcpl, fail_plist_cls_id;
        hid_t dcpl, plist_cls_id;

        if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) == H5I_INVALID_HID) {
            ret_val = EXIT_FAILURE;
            goto fail_dcpl;
        }
        // to perform introspection on any kind of property list,
        // we need to determine its property list class by obtaining a handle
        if ((plist_cls_id = H5Pget_class(dcpl)) == H5I_INVALID_HID) {
            ret_val = EXIT_FAILURE;
            goto fail_plist_cls_id;
        }
        // Compare the handle to the handles of built-in or user-defined
        // property list classes
        assert(H5Pequal(plist_cls_id, H5P_DATASET_CREATE) > 0);

fail_plist_cls_id:
        H5Pclose(dcpl);
fail_dcpl:;
    }
    //! <!-- [read] -->

    //! <!-- [update] -->
    {
        __label__ fail_dcpl, fail_prop;
        hid_t dcpl;

        if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) == H5I_INVALID_HID) {
            ret_val = EXIT_FAILURE;
            goto fail_dcpl;
        }

        // a property list is updated by adding (or removing) properties
        if (H5Pset_fill_time(dcpl, H5D_FILL_TIME_NEVER) < 0) {
            ret_val = EXIT_FAILURE;
            goto fail_prop;
        }

fail_prop:
        H5Pclose(dcpl);
fail_dcpl:;
    }
    //! <!-- [update] -->

    //! <!-- [delete] -->
    {
        __label__ fail_dcpl;
        hid_t dcpl;

        if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) == H5I_INVALID_HID) {
            ret_val = EXIT_FAILURE;
            goto fail_dcpl;
        }

        // a property list is "deleted" by closing it
        H5Pclose(dcpl);
fail_dcpl:;
    }
    //! <!-- [delete] -->

    //! <!-- [create_class] -->
    {
        __label__ fail_cls, fail_prop;
        hid_t  plist_cls, plist;
        int    izero = 0;
        double dzero = 0.0;

        // create a new property list class
        if ((plist_cls = H5Pcreate_class(H5P_ROOT, "int & double", NULL, NULL, NULL, NULL, NULL, NULL)) ==
            H5I_INVALID_HID) {
            ret_val = EXIT_FAILURE;
            goto fail_cls;
        }
        // add a permanent integer property
        if (H5Pregister2(plist_cls, "int", sizeof(int), &izero, NULL, NULL, NULL, NULL, NULL, NULL, NULL) <
            0) {
            ret_val = EXIT_FAILURE;
            goto fail_prop;
        }
        // add a permanent double property
        if (H5Pregister2(plist_cls, "double", sizeof(double), &dzero, NULL, NULL, NULL, NULL, NULL, NULL,
                         NULL) < 0) {
            ret_val = EXIT_FAILURE;
            goto fail_prop;
        }
        // create an instance of this user-defined property list class
        if ((plist = H5Pcreate(plist_cls)) < 0) {
            ret_val = EXIT_FAILURE;
            goto fail_prop;
        }

        // ...

        H5Pclose(plist);
fail_prop:
        H5Pclose_class(plist_cls);
fail_cls:;
    }
    //! <!-- [create_class] -->

    //! <!-- [read_class] -->
    {
        __label__ fail_cls, fail_prop, fail_plist;
        hid_t  plist_cls, plist;
        size_t nprops;

        if ((plist_cls = H5Pcreate_class(H5P_ROOT, "ud_plist", NULL, NULL, NULL, NULL, NULL, NULL)) ==
            H5I_INVALID_HID) {
            ret_val = EXIT_FAILURE;
            goto fail_cls;
        }
        if ((plist = H5Pcreate(plist_cls)) < 0) {
            ret_val = EXIT_FAILURE;
            goto fail_prop;
        }
        if (H5Pinsert2(plist, "temp", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0) {
            ret_val = EXIT_FAILURE;
            goto fail_plist;
        }
        // count the registered properties of this class
        if (H5Pget_nprops(plist_cls, &nprops) < 0) {
            ret_val = EXIT_FAILURE;
            goto fail_plist;
        }
        // this will be 0 as there are no registered properties
        printf("Property list class has %lu registered properties.\n", nprops);

        // count the properties in this property list
        if (H5Pget_nprops(plist, &nprops) < 0) {
            ret_val = EXIT_FAILURE;
            goto fail_plist;
        }
        // will be 1 as there is one temporary property
        printf("Property list has %lu property.\n", nprops);

fail_plist:
        H5Pclose(plist);
fail_prop:
        H5Pclose_class(plist_cls);
fail_cls:;
    }
    //! <!-- [read_class] -->

    //! <!-- [update_class] -->
    {
        __label__ fail_cls, fail_prop, fail_plist;
        hid_t plist_cls, plist;

        if ((plist_cls = H5Pcreate_class(H5P_ROOT, "ud_plist", NULL, NULL, NULL, NULL, NULL, NULL)) ==
            H5I_INVALID_HID) {
            ret_val = EXIT_FAILURE;
            goto fail_cls;
        }
        // create an instance of this user-defined property list class
        if ((plist = H5Pcreate(plist_cls)) < 0) {
            ret_val = EXIT_FAILURE;
            goto fail_prop;
        }
        // insert a temporary property
        if (H5Pinsert2(plist, "temp", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0) {
            ret_val = EXIT_FAILURE;
            goto fail_plist;
        }

fail_plist:
        H5Pclose(plist);
fail_prop:
        H5Pclose_class(plist_cls);
fail_cls:;
    }
    //! <!-- [update_class] -->

    //! <!-- [delete_class] -->
    {
        __label__ fail_cls;
        hid_t plist_cls;

        if ((plist_cls = H5Pcreate_class(H5P_ROOT, "int & double", NULL, NULL, NULL, NULL, NULL, NULL)) ==
            H5I_INVALID_HID) {
            ret_val = EXIT_FAILURE;
            goto fail_cls;
        }
        // ...

        // a user defined property list class is destroyed by closing the handle
        H5Pclose_class(plist_cls);
fail_cls:;
    }
    //! <!-- [delete_class] -->

    return ret_val;
}