/* * exph5_tlist * This example creates defined types that include bags, sets or lists. */ #include "hdf5.h" #include "hdf5_hl.h" int main(void) { hid_t file, pop1_group, schema_group, arrayreal, typearray, dataset, dataspace; herr_t status; int rank; double list3[3]; double list6[6]; hsize_t dimen[5]; /* * Create a new HDF5 file. */ file = H5Fcreate("exph5_tlist.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* * Create a data and schema group in the file and set required attributes and a description. */ pop1_group = H5Gcreate(file, "/Pop1", 0); schema_group = H5Gcreate(file, "/geometry_encoding1", 0); status = H5LTset_attribute_string( pop1_group, "/Pop1", "iso_10303_26_data", "geometry" ); status = H5LTset_attribute_string( schema_group, "/geometry_encoding1", "iso_10303_26_schema", "geometry" ); status = H5LTset_attribute_string( schema_group, "/geometry_encoding1", "iso_10303_26_description", "Contains example aggregate defined types." ); /* Add example of TYPE = BAG, LIST or SET which are not based on the EXPRESS TYPE but are instead based on the size of the instance of the BAG, LIST or SET. */ /* create array that can contain three elements */ rank = 1; dimen[0] = 3; arrayreal = H5Tarray_create(H5T_NATIVE_DOUBLE, rank, dimen, NULL ); /* put three doubles in the 1 x 3 C array */ list3[0] = 1.0; list3[1] = 2.8393; list3[2] = 3.93039; /* create dataspace that can contain one array */ dimen[0] = 1; dataspace = H5Screate_simple(rank, dimen, NULL); /* create dataset to contain one array of three elements and write it to file */ dataset = H5Dcreate(pop1_group, "LIST OF REAL with 3 elements", arrayreal, dataspace, H5P_DEFAULT); status = H5Dwrite(dataset, arrayreal, H5S_ALL, H5S_ALL, H5P_DEFAULT, list3); H5Tclose(arrayreal); H5Sclose(dataspace); H5Dclose(dataset); dimen[0] = 6; arrayreal = H5Tarray_create(H5T_NATIVE_DOUBLE, rank, dimen, NULL ); /* put six doubles in the 1 x 6 C array */ list6[0] = 1.1111; list6[1] = 2.8393; list6[2] = 3.93039; list6[3] = 4.44; list6[4] = 5.93039; list6[5] = 6.93039; /* create dataspace that can contain one array */ dimen[0] = 1; dataspace = H5Screate_simple(rank, dimen, NULL); /* create dataset to contain one array of three elements and write it to file */ dataset = H5Dcreate(pop1_group, "LIST OF REAL with 6 elements", arrayreal, dataspace, H5P_DEFAULT); status = H5Dwrite(dataset, arrayreal, H5S_ALL, H5S_ALL, H5P_DEFAULT, list6); H5Tclose(arrayreal); H5Sclose(dataspace); H5Dclose(dataset); H5Gclose(pop1_group); H5Gclose(schema_group); H5Fclose(file); }