static void plist_link_example(void) { hid_t file_id; hid_t group_id, group2_id; hid_t gapl_id; char *path = NULL; /* Define the link class that we'll use to register "plist * links" using the callback we defined above. * A link class can have NULL for any callback except its traverse * callback. */ const H5L_class_t UD_plist_class[1] = {{ H5L_LINK_CLASS_T_VERS, /* Version number for this struct. * This field is always H5L_LINK_CLASS_T_VERS */ (H5L_type_t)UD_PLIST_CLASS, /* Link class id number. This can be any * value between H5L_TYPE_UD_MIN (64) and * H5L_TYPE_MAX (255). It should be a * value that isn't already being used by * another kind of link. We'll use 67. */ "UD_plist_link", /* Link class name for debugging */ NULL, /* Creation callback */ NULL, /* Move callback */ NULL, /* Copy callback */ UD_plist_traverse, /* The actual traversal function */ NULL, /* Deletion callback */ NULL /* Query callback */ }}; /* First, create a file and two objects within the file for the link to * point to. */ file_id = H5Fcreate(HARD_LINK_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); group_id = H5Gcreate2(file_id, "group_1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Gclose(group_id); group_id = H5Gcreate2(file_id, "group_1/group_2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Gclose(group_id); /* Register "plist links" and create one. It has no udata at all. */ H5Lregister(UD_plist_class); H5Lcreate_ud(file_id, "plist_link", (H5L_type_t)UD_PLIST_CLASS, NULL, 0, H5P_DEFAULT, H5P_DEFAULT); /* Create a group access property list to pass in the target for the * plist link. */ gapl_id = H5Pcreate(H5P_GROUP_ACCESS); /* There is no HDF5 API for setting the property that controls these * links, so we have to add the property manually */ H5Pinsert2(gapl_id, PLIST_LINK_PROP, sizeof(const char *), &(path), NULL, NULL, NULL, NULL, NULL, NULL); /* Set the property to point to the first group. */ path = "group_1"; H5Pset(gapl_id, PLIST_LINK_PROP, &path); /* Open the first group through the plist link using the GAPL we just * created */ group_id = H5Gopen2(file_id, "plist_link", gapl_id); /* If we change the value set on the property list, it will change where * the plist link points. */ path = "group_1/group_2"; H5Pset(gapl_id, PLIST_LINK_PROP, &path); group2_id = H5Gopen2(file_id, "plist_link", gapl_id); /* group_id points to group_1 and group2_id points to group_2, both opened * through the same link. * Using more than one of this type of link could quickly become confusing, * since they will all use the same property list; however, there is * nothing to prevent the links from changing the property list in their * traverse callbacks. */ /* Clean up */ H5Pclose(gapl_id); H5Gclose(group_id); H5Gclose(group2_id); H5Fclose(file_id); }
/* * Create datasets in the location (in "/" or "/group") with * message id: (a) H5O_BOGUS_VALID_ID or (b)H5O_BOGUS_INVALID_ID * and various unknown message flags */ static int generate_datasets(hid_t loc_id, unsigned bogus_id) { hid_t sid = -1; /* Dataspace ID */ hid_t dcpl = -1; /* Dataset creation property list ID */ hid_t did = -1; /* Dataset ID */ uint8_t bogus_flags = 0; /* Flags for bogus message */ /* Create dataspace for datasets */ if((sid = H5Screate(H5S_SCALAR)) < 0) goto error; /* Create dataset creation property list */ if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) goto error; /* Add property for bogus message flags */ if(H5Pinsert2(dcpl, H5O_BOGUS_MSG_FLAGS_NAME, H5O_BOGUS_MSG_FLAGS_SIZE, &bogus_flags, NULL, NULL, NULL, NULL, NULL, NULL) < 0) goto error; /* Add property for bogus message ID */ if(H5Pinsert2(dcpl, H5O_BOGUS_MSG_ID_NAME, H5O_BOGUS_MSG_ID_SIZE, &bogus_id, NULL, NULL, NULL, NULL, NULL, NULL) < 0) goto error; /* Create dataset with "bogus" message, but no message flags */ if((did = H5Dcreate2(loc_id, "Dataset1", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) goto error; if(H5Dclose(did) < 0) goto error; /* Set "fail if unknown and open for write" message flag for bogus message */ bogus_flags = H5O_MSG_FLAG_FAIL_IF_UNKNOWN_AND_OPEN_FOR_WRITE; if(H5Pset(dcpl, H5O_BOGUS_MSG_FLAGS_NAME, &bogus_flags) < 0) goto error; /* Create second dataset, with "fail if unknown" message flag */ if((did = H5Dcreate2(loc_id, "Dataset2", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) goto error; if(H5Dclose(did) < 0) goto error; /* Set "fail if unknown always" message flag for bogus message */ bogus_flags = H5O_MSG_FLAG_FAIL_IF_UNKNOWN_ALWAYS; if(H5Pset(dcpl, H5O_BOGUS_MSG_FLAGS_NAME, &bogus_flags) < 0) goto error; /* Create third dataset, with "fail if unknown always" message flag */ if((did = H5Dcreate2(loc_id, "Dataset3", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) goto error; if(H5Dclose(did) < 0) goto error; /* Set "mark if unknown" message flag for bogus message */ bogus_flags = H5O_MSG_FLAG_MARK_IF_UNKNOWN; if(H5Pset(dcpl, H5O_BOGUS_MSG_FLAGS_NAME, &bogus_flags) < 0) goto error; /* Create fourth dataset, with "mark if unknown" message flag */ if((did = H5Dcreate2(loc_id, "Dataset4", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) goto error; if(H5Dclose(did) < 0) goto error; /* Close dataset creation property list */ if(H5Pclose(dcpl) < 0) goto error; /* Close dataspace */ if(H5Sclose(sid) < 0) goto error; return 0; error: H5E_BEGIN_TRY { H5Dclose(did); H5Sclose(sid); H5Pclose(dcpl); } H5E_END_TRY; return -1; } /* generate_datasets() */