/***************************************************************/ /* Create and Write to a Dataset. */ /***************************************************************/ 1 #include "hdf5.h" 2 #define FILE "dset.h5" 3 int main() { 4 hid_t file_id, dataset_id, dataspace_id; /* identifiers */ 5 hsize_t dims[2]; 6 herr_t status; 7 int i, j, dset_data[4][6]; /* Initialize the dataset. */ 8 for (i = 0; i < 4; i++) 9 for (j = 0; j < 6; j++) 10 dset_data[i][j] = i * 6 + j + 1; /* Create a new file using default properties. */ 11 file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* Create the data space for the dataset. */ 12 dims[0] = 4; 13 dims[1] = 6; 14 dataspace_id = H5Screate_simple(2, dims, NULL); /* Create the dataset. */ 15 dataset_id = H5Dcreate(file_id, "/dset", H5T_STD_I32BE, dataspace_id, H5P_DEFAULT); /* Write the dataset. */ 16 status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data); /* Terminate access to the dataspace, dataset, file */ 17 status = H5Sclose(dataspace_id); 18 status = H5Dclose(dataset_id); 19 status = H5Fclose(file_id); 20 }