#include "h5augjpss.h" #include "h5aj_private.h" #include /* #include #include */ #define RANK 1 /********************************************************************** * * Function: h5aj_restore_Data_Products_link * * Purpose: restore the link that makes the Data_Products group a member * of the root group. * * Returns: 0 if successful, non-zero otherwise * ********************************************************************** */ herr_t h5aj_restore_group_link(hid_t file, const char *group_name) { hid_t group; /* Handles */ herr_t status; hid_t grpid, spaceid, attid; hsize_t dims; int ndims; unsigned long long *rdata; haddr_t addr; char att_name[1024]; group = H5Gopen2(file, "/", H5P_DEFAULT); dims = 1; /* This may be useful to verify that the link is in fact to "/Data_Products". attid = H5Aopen(group, "HDF5_internal_name_of_/Data_Products", H5P_DEFAULT); spaceid = H5Aget_space (attid); ndims = H5Sget_simple_extent_dims (spaceid, &dims, NULL); status = H5Aread (attid, H5T_NATIVE_CHAR, group_name); if (status < 0) printf("Failed to read value of HDF5_internal_name_of_/Data_Products\n"); H5Sclose(spaceid); H5Aclose(attid); */ rdata = (unsigned long long *) malloc (sizeof (unsigned long long)); strncpy(att_name, "HDF5_internal_address_of_/", 27); strncat(att_name, group_name, strlen(group_name)); attid = H5Aopen(group, att_name , H5P_DEFAULT); spaceid = H5Aget_space (attid); ndims = H5Sget_simple_extent_dims (spaceid, &dims, NULL); status = H5Aread (attid, H5T_NATIVE_ULLONG, rdata); if (status < 0) printf("Failed to read value of %s\n", att_name); H5Sclose(spaceid); H5Aclose(attid); addr = *rdata; printf(" Address is %ulld.\n", addr); grpid = H5Oopen_by_addr(group, addr); status = H5Olink(grpid, group, group_name, H5P_DEFAULT, H5P_DEFAULT); if (status < 0) printf("Failed to create new link for %s group\n", group_name); status = H5Odecr_refcount(grpid); if (status < 0) printf("Failed to decrement refcount.\n"); status = H5Gclose (grpid); status = H5Gclose (group); return status; } herr_t remove_link_func(hid_t loc_id, const char *name, const H5L_info_t *info, void *operator_data) { herr_t status = H5Ldelete(*(hid_t *)operator_data, name, H5P_DEFAULT); if (status == -1) { printf("Unable to delete link to dataset %s.\n", name); } return status; } herr_t h5aj_remove_links_to_group_objects(hid_t file, hid_t group) { herr_t status; hid_t root_group = H5Gopen(file, "/", H5P_DEFAULT); status = H5Literate(group, H5_INDEX_NAME, H5_ITER_NATIVE, NULL, remove_link_func, &root_group); status = H5Gclose(root_group); return status; }