-
-
Notifications
You must be signed in to change notification settings - Fork 265
/
h5ex_g_phase.c
128 lines (109 loc) · 4.1 KB
/
h5ex_g_phase.c
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
/************************************************************
This example shows how to set the conditions for
conversion between compact and dense (indexed) groups.
This file is intended for use with HDF5 Library version 1.8
************************************************************/
#include "hdf5.h"
#include <stdio.h>
#define FILE "h5ex_g_phase.h5"
#define MAX_GROUPS 7
#define MAX_COMPACT 5
#define MIN_DENSE 3
int
main(void)
{
hid_t file, group, subgroup, fapl, gcpl; /* Handles */
herr_t status;
H5G_info_t ginfo;
char name[3] = "G0"; /* Name of subgroup */
unsigned i;
/*
* Set file access property list to allow the latest file format.
* This will allow the library to create new format groups.
*/
fapl = H5Pcreate(H5P_FILE_ACCESS);
status = H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);
/*
* Create group access property list and set the phase change
* conditions. In this example we lowered the conversion threshold
* to simplify the output, though this may not be optimal.
*/
gcpl = H5Pcreate(H5P_GROUP_CREATE);
status = H5Pset_link_phase_change(gcpl, MAX_COMPACT, MIN_DENSE);
/*
* Create a new file using the default properties.
*/
file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
/*
* Create primary group.
*/
group = H5Gcreate(file, name, H5P_DEFAULT, gcpl, H5P_DEFAULT);
/*
* Add subgroups to "group" one at a time, print the storage type
* for "group" after each subgroup is created.
*/
for (i = 1; i <= MAX_GROUPS; i++) {
/*
* Define the subgroup name and create the subgroup.
*/
name[1] = ((char)i) + '0'; /* G1, G2, G3 etc. */
subgroup = H5Gcreate(group, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
status = H5Gclose(subgroup);
/*
* Obtain the group info and print the group storage type
*/
status = H5Gget_info(group, &ginfo);
printf("%d Group%s: Storage type is ", (int)ginfo.nlinks, ginfo.nlinks == 1 ? " " : "s");
switch (ginfo.storage_type) {
case H5G_STORAGE_TYPE_COMPACT:
printf("H5G_STORAGE_TYPE_COMPACT\n"); /* New compact format */
break;
case H5G_STORAGE_TYPE_DENSE:
printf("H5G_STORAGE_TYPE_DENSE\n"); /* New dense (indexed) format */
break;
case H5G_STORAGE_TYPE_SYMBOL_TABLE:
printf("H5G_STORAGE_TYPE_SYMBOL_TABLE\n"); /* Original format */
break;
case H5G_STORAGE_TYPE_UNKNOWN:
printf("H5G_STORAGE_TYPE_UNKNOWN\n"); /* Unknown format */
}
}
printf("\n");
/*
* Delete subgroups one at a time, print the storage type for
* "group" after each subgroup is deleted.
*/
for (i = MAX_GROUPS; i >= 1; i--) {
/*
* Define the subgroup name and delete the subgroup.
*/
name[1] = ((char)i) + '0'; /* G1, G2, G3 etc. */
status = H5Ldelete(group, name, H5P_DEFAULT);
/*
* Obtain the group info and print the group storage type
*/
status = H5Gget_info(group, &ginfo);
printf("%d Group%s: Storage type is ", (int)ginfo.nlinks, ginfo.nlinks == 1 ? " " : "s");
switch (ginfo.storage_type) {
case H5G_STORAGE_TYPE_COMPACT:
printf("H5G_STORAGE_TYPE_COMPACT\n"); /* New compact format */
break;
case H5G_STORAGE_TYPE_DENSE:
printf("H5G_STORAGE_TYPE_DENSE\n"); /* New dense (indexed) format */
break;
case H5G_STORAGE_TYPE_SYMBOL_TABLE:
printf("H5G_STORAGE_TYPE_SYMBOL_TABLE\n"); /* Original format */
break;
case H5G_STORAGE_TYPE_UNKNOWN:
printf("H5G_STORAGE_TYPE_UNKNOWN\n"); /* Unknown format */
}
}
/*
* Close and release resources.
*/
status = H5Pclose(fapl);
status = H5Pclose(gcpl);
status = H5Gclose(group);
status = H5Fclose(file);
return 0;
}