/* * This example shows how to create a compound data type, * write an array which has the compound data type to the file, * and read back fields' subsets. */ #include "hdf5.h" #define H5FILE_NAME "SDScompound.h5" #define DATASETNAME "ArrayOfStructures" #define LENGTH 0 #define RANK 1 /* #define DIM_ARRAY 65*1000 */ /* works */ #define DIM_ARRAY 66*1000 /* does not work */ #define CHUNK_SIZE 10*1000 int main(void) { /* First structure and dataset*/ typedef struct s1_t { char a[DIM_ARRAY]; } s1_t; hid_t tid; hid_t s1_tid; /* File datatype identifier */ hid_t plist_id; hid_t file, dataset, space; /* Handles */ hsize_t dims[] = {LENGTH}; /* Dataspace dimensions */ hsize_t maxdims[] = {H5S_UNLIMITED}; /* Unlimited dimensions */ hsize_t adims[] = {DIM_ARRAY}; /* ARRAY type dimensions */ hsize_t dims_chunk[] = {CHUNK_SIZE}; char fill_data[DIM_ARRAY]; /* * Create the data space. */ space = H5Screate_simple(RANK, dims, maxdims); /* Modify dataset creation properties, i.e. enable chunking */ plist_id = H5Pcreate(H5P_DATASET_CREATE); H5Pset_chunk(plist_id, 1, dims_chunk); /* * Create the file. */ file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* * Create the memory data type. */ s1_tid = H5Tcreate(H5T_COMPOUND, sizeof(s1_t)); tid = H5Tarray_create(H5T_NATIVE_CHAR, RANK, adims, NULL); H5Tinsert(s1_tid, "a_name", HOFFSET(s1_t, a), tid); /* Set the fill value using a struct as the data type. */ /* Makes the example to fail */ H5Pset_fill_value(plist_id, s1_tid, fill_data); /* * Create the dataset. */ dataset = H5Dcreate(file, DATASETNAME, s1_tid, space, plist_id); /* * Release resources */ H5Tclose(tid); H5Tclose(s1_tid); H5Sclose(space); H5Dclose(dataset); H5Fclose(file); return 0; }