-
Notifications
You must be signed in to change notification settings - Fork 0
/
HDF5Main.c
40 lines (30 loc) · 1.14 KB
/
HDF5Main.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
#include <stdlib.h>
#include "hdf5.h"
#define DATASETNAME "/myDataSet"
// creates an empty HDF5 file
void __create(const char* fileName) {
H5Fclose(H5Fcreate(fileName, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT));
}
//Write 1-dimenstion matrix to HDF5
void __writeMatrix(const char* fileName, int64_t* matrix, int64_t length) {
hid_t file_id, dataset_id,dataspace_id;
herr_t status;
hsize_t dims[2];
dims[0] = 1;
dims[1] = length;
/* Open an existing file. */
file_id = H5Fopen(fileName, H5F_ACC_RDWR, H5P_DEFAULT);
dataspace_id = H5Screate_simple(2, dims, NULL);
/* Open an existing dataset. */
dataset_id = H5Dcreate2(file_id, DATASETNAME, H5T_STD_I32BE, dataspace_id,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* Write the dataset. */
status = H5Dwrite(dataset_id, H5T_NATIVE_ULLONG, H5S_ALL, H5S_ALL, H5P_DEFAULT,
matrix);
status = H5Dread(dataset_id, H5T_NATIVE_ULLONG, H5S_ALL, H5S_ALL, H5P_DEFAULT,
matrix);
/* Close the dataset. */
status = H5Dclose(dataset_id);
/* Close the file. */
status = H5Fclose(file_id);
}