/* * exph5_entity_instance * This example creates four EXPRESS entity instances of a single entity type using an HDF5 Compound Datatype. */ #include "hdf5.h" #include "hdf5_hl.h" int main(void) { hid_t file, pop1_group, schema_group, point_group, point_space, point_dataset; herr_t status; int rank, i; /* C struct for instances of entity type point; x, y, z = REAL; */ typedef struct point_t { float x; float y; float z; } point_t; /* C array that can contain 4 (same as dim value for dataspace) instances of the point entity type*/ point_t point[4]; hid_t point_tid; /* File datatype identifier */ hsize_t dim[] = {4}; /* Dataspace dimensions */ /* * Create a new HDF5 file. */ file = H5Fcreate("exph5_entity_instance.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* * Create a data and schema group in the file and set required attributes and a decription. */ 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 entity instances of one entity type - point." ); /* Add HDF5 Compound Datatype for EXPRESS Entity Type point. */ point_tid = H5Tcreate (H5T_COMPOUND, sizeof(point_t)); H5Tinsert(point_tid, "x", HOFFSET(point_t, x), H5T_NATIVE_FLOAT); H5Tinsert(point_tid, "y", HOFFSET(point_t, y), H5T_NATIVE_FLOAT); H5Tinsert(point_tid, "z", HOFFSET(point_t, z), H5T_NATIVE_FLOAT); status = H5Tcommit (schema_group, "point", point_tid); /* Create an HDF5 Group for the objects related to the entity type point */ point_group = H5Gcreate(file, "/Pop1/point-objects", 0); /* Create dataspace of rank 1 and dimension 4 to hold the four instance of entity type point */ rank = 1; point_space = H5Screate_simple(rank, dim, NULL); /* Create dataset to hold instances of entity type point */ point_dataset = H5Dcreate(point_group, "Instances", point_tid, point_space, H5P_DEFAULT); /* Set values for the instances of entity type point */ for (i = 0; i< 4; i++) { point[i].x = (i+1)*1.33; point[i].y = (i+1)*2.66; point[i].z = (i+1)*3.99; } /* Wtite instances entity type point to the dataset */ status = H5Dwrite(point_dataset, point_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, point); H5Tclose(point_tid); H5Sclose(point_space); H5Dclose(point_dataset); H5Gclose(point_group); H5Gclose(pop1_group); H5Gclose(schema_group); H5Fclose(file); }