int main(){ hid_t fprop; hid_t fid; hid_t vol_id = H5VL_memvol_init(); herr_t status; hid_t g1, g2; hid_t plist; char name[1024]; fprop = H5Pcreate(H5P_FILE_ACCESS); H5Pset_vol(fprop, vol_id, &fprop); fid = H5Fcreate("test", H5F_ACC_TRUNC, H5P_DEFAULT, fprop); H5VLget_plugin_name(fid, name, 1024); printf ("Using VOL %s\n", name); g1 = H5Gcreate2(fid, "g1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Gclose(g1); g2 = H5Gcreate2(fid, "g2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); g1 = H5Gcreate2(g2, "g1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Gclose(g1); H5Gclose(g2); // is this allowed? //g3 = H5Gcreate2(fid, "g1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); //H5Gclose(g3); printf("Testing additional functions\n"); g1 = H5Gopen2(fid, "g1", H5P_DEFAULT ); plist = H5Gget_create_plist(g1); H5G_info_t group_info; H5Gget_info(g1, & group_info ); H5Gget_info_by_idx(fid, "g1", H5_INDEX_CRT_ORDER, H5_ITER_NATIVE, 0, & group_info, H5P_DEFAULT ) ; H5Gget_info_by_idx(fid, "g1", H5_INDEX_NAME, H5_ITER_NATIVE, 0, & group_info, H5P_DEFAULT ) ; H5Gget_info_by_name(fid, "g1", & group_info, H5P_DEFAULT); H5Pclose(plist); status = H5Gclose(g1); g1 = H5Gopen2(fid, "g2", H5P_DEFAULT ); H5Gclose(g1); //g1 = H5Gopen2(fid, "INVALID", H5P_DEFAULT ); //H5Gclose(g1); g1 = H5Gcreate_anon( fid, H5P_DEFAULT, H5P_DEFAULT ); H5Gclose(g1); H5Fclose(fid); H5VL_memvol_finalize(); printf("Status: %d\n", status); return 0; }
/* * Class: hdf_hdf5lib_H5 * Method: _H5Gcreate_anon * Signature: (JJJ)J */ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Gcreate_1anon(JNIEnv *env, jclass cls, jlong loc_id, jlong gcpl_id, jlong gapl_id) { hid_t group_id = -1; group_id = H5Gcreate_anon((hid_t)loc_id, (hid_t)gcpl_id, (hid_t)gapl_id); if (group_id < 0) h5libraryError(env); return (jlong)group_id; } /* end JNICALL */
int main() { printf("\n*** Checking HDF5 group functions.\n"); printf("*** Checking out root group..."); { hid_t fileid, grpid, access_plistid; /* Open the root group of a new file. */ if ((access_plistid = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR; if (H5Pset_fclose_degree(access_plistid, H5F_CLOSE_SEMI)) ERR; if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, access_plistid)) < 0) ERR; if ((grpid = H5Gopen(fileid, "/")) < 0) ERR; if (H5Gclose(grpid) < 0 || H5Fclose(fileid) < 0) ERR; /* Reopen file and root group. */ if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDWR, access_plistid)) < 0) ERR; if ((grpid = H5Gopen(fileid, "/")) < 0) ERR; if (H5Gclose(grpid) < 0 || H5Fclose(fileid) < 0) ERR; } SUMMARIZE_ERR; printf("*** Checking out H5Gmove..."); { hid_t fileid, grpid; hid_t datasetid, spaceid; /* Create file with one dataset. */ if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR; if ((grpid = H5Gopen(fileid, "/")) < 0) ERR; if ((spaceid = H5Screate(H5S_SCALAR)) < 0) ERR; if ((datasetid = H5Dcreate(grpid, DATASET_NAME, H5T_NATIVE_INT, spaceid, H5P_DEFAULT)) < 0) ERR; if (H5Dclose(datasetid) < 0 || H5Sclose(spaceid) < 0 || H5Gclose(grpid) < 0 || H5Fclose(fileid) < 0) ERR; /* Reopen file and check, then rename dataset. */ if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) ERR; if ((grpid = H5Gopen(fileid, "/")) < 0) ERR; if ((datasetid = H5Dopen1(grpid, DATASET_NAME)) < 0) ERR; if (H5Dclose(datasetid) < 0) ERR; if (H5Gmove(grpid, DATASET_NAME, NEW_NAME) < 0) ERR; if ((datasetid = H5Dopen1(grpid, NEW_NAME)) < 0) ERR; if (H5Dclose(datasetid) < 0 || H5Gclose(grpid) < 0 || H5Fclose(fileid) < 0) ERR; } SUMMARIZE_ERR; printf("*** Checking out sub-groups..."); { hid_t fileid, grpid, subgrpid; /* Create file with some nested groups. */ if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR; if ((grpid = H5Gcreate(fileid, GRP_NAME, 0)) < 0) ERR; if ((subgrpid = H5Gcreate(grpid, SUB_GRP_NAME, 0)) < 0) ERR; if (H5Gclose(subgrpid) < 0 || H5Gclose(grpid) < 0 || H5Fclose(fileid) < 0) ERR; /* Reopen file and discover groups. */ if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR; if ((grpid = H5Gopen(fileid, GRP_NAME)) < 0) ERR; if ((subgrpid = H5Gopen(grpid, SUB_GRP_NAME)) < 0) ERR; if (H5Gclose(subgrpid) < 0 || H5Gclose(grpid) < 0 || H5Fclose(fileid) < 0) ERR; } SUMMARIZE_ERR; printf("*** Checking out UTF8 named sub-group..."); { hid_t fileid, grpid, subgrpid; /* Create file with nested group. */ if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR; if ((grpid = H5Gcreate(fileid, (char *)norm_utf8, 0)) < 0) ERR; if ((subgrpid = H5Gcreate(grpid, SUB_GRP_NAME, 0)) < 0) ERR; if (H5Gclose(subgrpid) < 0 || H5Gclose(grpid) < 0 || H5Fclose(fileid) < 0) ERR; /* Reopen file and discover groups. */ if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR; if ((grpid = H5Gopen(fileid, (char *)norm_utf8)) < 0) ERR; if ((subgrpid = H5Gopen(grpid, SUB_GRP_NAME)) < 0) ERR; if (H5Gclose(subgrpid) < 0 || H5Gclose(grpid) < 0 || H5Fclose(fileid) < 0) ERR; } SUMMARIZE_ERR; printf("*** Checking out UTF8 named sub-group with group creation ordering..."); { hid_t fileid, grpid, subgrpid; hid_t fapl_id, fcpl_id, gcpl_id; /* Create file with nested group. */ if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR; if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) ERR; if ((fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0) ERR; if (H5Pset_link_creation_order(fcpl_id, H5P_CRT_ORDER_TRACKED|H5P_CRT_ORDER_INDEXED) < 0) ERR; if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, fcpl_id, fapl_id)) < 0) ERR; if ((gcpl_id = H5Pcreate(H5P_GROUP_CREATE)) < 0) ERR; if (H5Pset_link_creation_order(gcpl_id, H5P_CRT_ORDER_TRACKED|H5P_CRT_ORDER_INDEXED) < 0) ERR; if ((grpid = H5Gcreate_anon(fileid, gcpl_id, H5P_DEFAULT)) < 0) ERR; if ((H5Olink(grpid, fileid, (char *)norm_utf8, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR; if ((subgrpid = H5Gcreate(grpid, SUB_GRP_NAME, 0)) < 0) ERR; if (H5Gclose(subgrpid) < 0 || H5Gclose(grpid) < 0 || H5Fclose(fileid) < 0) ERR; /* Reopen file and discover groups. */ if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR; if ((grpid = H5Gopen(fileid, (char *)norm_utf8)) < 0) ERR; if ((subgrpid = H5Gopen(grpid, SUB_GRP_NAME)) < 0) ERR; if (H5Gclose(subgrpid) < 0 || H5Gclose(grpid) < 0 || H5Fclose(fileid) < 0) ERR; } SUMMARIZE_ERR; FINAL_RESULTS; }