forked from AFD-Illinois/igrmonty2d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
h5io.c
102 lines (89 loc) · 3.91 KB
/
h5io.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
#include "h5io.h"
void h5io_add_group(hid_t fid, const char *path)
{
hid_t group_id = H5Gcreate2(fid, path, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Gclose(group_id);
}
void h5io_add_attribute_int(hid_t fid, const char *path, const char *name, int attribute)
{
hid_t dataspace_id = H5Screate(H5S_SCALAR);
hid_t attribute_id = H5Acreate_by_name(fid, path, name, H5IO_FMT_INT, H5Screate(H5S_SCALAR), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Awrite(attribute_id, H5T_NATIVE_INT, &attribute);
H5Aclose(attribute_id);
H5Sclose(dataspace_id);
}
void h5io_add_attribute_dbl(hid_t fid, const char *path, const char *name, double attribute)
{
hid_t dataspace_id = H5Screate(H5S_SCALAR);
hid_t attribute_id = H5Acreate_by_name(fid, path, name, H5IO_FMT_DBL, H5Screate(H5S_SCALAR), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Awrite(attribute_id, H5T_NATIVE_DOUBLE, &attribute);
H5Aclose(attribute_id);
H5Sclose(dataspace_id);
}
void h5io_add_attribute_str(hid_t fid, const char *path, const char *name, const char *attribute)
{
hid_t dtype_id = H5Tcopy(H5IO_FMT_STR);
H5Tset_size(dtype_id, strlen(attribute)+1);
H5Tset_strpad(dtype_id, H5T_STR_NULLTERM);
hid_t dataspace_id = H5Screate(H5S_SCALAR);
hid_t attribute_id = H5Acreate_by_name(fid, path, name, dtype_id, H5Screate(H5S_SCALAR), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Awrite(attribute_id, dtype_id, attribute);
H5Aclose(attribute_id);
H5Sclose(dataspace_id);
H5Tclose(dtype_id);
}
void h5io_add_data_int(hid_t fid, const char *path, int data)
{
hid_t dataspace_id = H5Screate(H5S_SCALAR);
hid_t dataset_id = H5Dcreate2(fid, path, H5IO_FMT_INT, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &data);
H5Dclose(dataset_id);
H5Sclose(dataspace_id);
}
void h5io_add_data_dbl(hid_t fid, const char *path, double data)
{
hid_t dataspace_id = H5Screate(H5S_SCALAR);
hid_t dataset_id = H5Dcreate2(fid, path, H5IO_FMT_DBL, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &data);
H5Dclose(dataset_id);
H5Sclose(dataspace_id);
}
void h5io_add_data_str(hid_t fid, const char *path, const char *data)
{
hid_t dtype_id = H5Tcopy(H5IO_FMT_STR);
H5Tset_size(dtype_id, strlen(data)+1);
H5Tset_strpad(dtype_id, H5T_STR_NULLTERM);
hid_t dataspace_id = H5Screate(H5S_SCALAR);
hid_t dataset_id = H5Dcreate2(fid, path, dtype_id, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Dwrite(dataset_id, dtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
H5Dclose(dataset_id);
H5Sclose(dataspace_id);
H5Tclose(dtype_id);
}
void h5io_add_data_dbl_1d(hid_t fid, const char *path, hsize_t n1, double data[n1])
{
hsize_t dims[1] = { n1 };
hid_t dataspace_id = H5Screate_simple(1, dims, NULL);
hid_t dataset_id = H5Dcreate2(fid, path, H5IO_FMT_DBL, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
H5Dclose(dataset_id);
H5Sclose(dataspace_id);
}
void h5io_add_data_dbl_2d(hid_t fid, const char *path, hsize_t n1, hsize_t n2, double data[n1][n2])
{
hsize_t dims[2] = { n1, n2 };
hid_t dataspace_id = H5Screate_simple(2, dims, NULL);
hid_t dataset_id = H5Dcreate2(fid, path, H5IO_FMT_DBL, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
H5Dclose(dataset_id);
H5Sclose(dataspace_id);
}
void h5io_add_data_dbl_3d(hid_t fid, const char *path, hsize_t n1, hsize_t n2, hsize_t n3, double data[n1][n2][n3])
{
hsize_t dims[3] = { n1, n2, n3 };
hid_t dataspace_id = H5Screate_simple(3, dims, NULL);
hid_t dataset_id = H5Dcreate2(fid, path, H5IO_FMT_DBL, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
H5Dclose(dataset_id);
H5Sclose(dataspace_id);
}