/* * exph5_groups * This example creates an HDF5 File, two HDF5 Groups and assigned some HDF5 Attributes to the Groups. */ #include "hdf5.h" #include "hdf5_hl.h" int main(void) { hid_t file, pop1_group, schema_group, dataspace, desc_attr, string_type; herr_t status; /* * Create a new HDF5 file. */ file = H5Fcreate("exph5_groups.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* * Create a data and schema group in the file and set required attribute */ pop1_group = H5Gcreate(file, "/Pop1", 0); schema_group = H5Gcreate(file, "/geometry_encoding1", 0); /* These use the High Level API Set Attributes calls */ 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" ); /* This uses the core API to set an attribute on a group */ /* Define dataspace for iso_10303_26_description attribute. */ dataspace = H5Screate(H5S_SCALAR); /* * Define datatype for iso_10303_26_description value */ string_type = H5Tcopy(H5T_C_S1); H5Tset_size(string_type, 30); H5Tset_strpad(string_type,H5T_STR_NULLTERM); desc_attr = H5Acreate(schema_group, "iso_10303_26_description", string_type, dataspace, H5P_DEFAULT ); /* Write the attribute data. */ status = H5Awrite(desc_attr, string_type, "Example group for schema info."); H5Aclose(desc_attr); /* Terminate access to the data space. */ status = H5Sclose(dataspace); H5Gclose(pop1_group); H5Gclose(schema_group); H5Fclose(file); }