/* * Class: hdf_hdf5lib_H5 * Method: H5Oset_comment_by_name * Signature: (JLjava/lang/String;Ljava/lang/String;J)V */ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Oset_1comment_1by_1name (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jstring comment, jlong access_id) { herr_t status = -1; const char *oName; const char *oComment; PIN_JAVA_STRING(name, oName); if (oName != NULL) { if (comment == NULL) { status = H5Oset_comment_by_name((hid_t)loc_id, oName, NULL, (hid_t)access_id); } /* end if */ else { jboolean isCopy; oComment = ENVPTR->GetStringUTFChars(ENVPAR comment, &isCopy); if (oComment != NULL) { status = H5Oset_comment_by_name((hid_t)loc_id, oName, oComment, (hid_t)access_id); ENVPTR->ReleaseStringUTFChars(ENVPAR comment, oComment); } /* end if */ } /* end else */ UNPIN_JAVA_STRING(name, oName); if (status < 0) h5libraryError(env); } } /* end Java_hdf_hdf5lib_H5_H5Oset_1comment_1by_1name */
/* * Class: hdf_hdf5lib_H5 * Method: H5Oset_comment_by_name * Signature: (JLjava/lang/String;Ljava/lang/String;J)V */ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Oset_1comment_1by_1name (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jstring comment, jlong access_id) { const char *objName = NULL; const char *objComment = NULL; jboolean isCopy; herr_t status = FAIL; UNUSED(clss); if (NULL == name) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Oset_comment_by_name: object name is NULL"); PIN_JAVA_STRING(ENVONLY, name, objName, NULL, "H5Oset_comment_by_name: object name not pinned"); if (NULL != comment) PIN_JAVA_STRING(ENVONLY, comment, objComment, &isCopy, "H5Oset_comment_by_name: object comment not pinned"); if ((status = H5Oset_comment_by_name((hid_t)loc_id, objName, objComment, (hid_t)access_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); done: if (objComment) UNPIN_JAVA_STRING(ENVONLY, comment, objComment); if (objName) UNPIN_JAVA_STRING(ENVONLY, name, objName); } /* end Java_hdf_hdf5lib_H5_H5Oset_1comment_1by_1name */
/****if* H5Of/h5oset_comment_by_name_c * NAME * h5oset_comment_by_name_c * PURPOSE * Calls H5Oset_comment_by_name * INPUTS * object_id - Identifier of the target object. * name - Name of the object whose comment is to be set or reset, * specified as a path relative to loc_id. * namelen - Length of the name. * comment - The new comment. * commentlen - Length of the comment. * lapl_id - Link access property list identifier. * RETURNS * 0 on success, -1 on failure * AUTHOR * M. Scot Breitenfeld * May 17, 2012 * SOURCE */ int_f nh5oset_comment_by_name_c (hid_t_f *object_id, _fcd name, size_t_f *namelen, _fcd comment, size_t_f *commentlen, hid_t_f *lapl_id) /******/ { char *c_comment = NULL; /* Buffer to hold C string */ char *c_name = NULL; /* Buffer to hold C string */ int_f ret_value = 0; /* Return value */ /* * Convert FORTRAN string to C string */ if((c_comment = HD5f2cstring(comment, (size_t)*commentlen)) == NULL) HGOTO_DONE(FAIL); /* * Convert FORTRAN string to C string */ if((c_name = HD5f2cstring(name, (size_t)*namelen)) == NULL) HGOTO_DONE(FAIL); /* * Call H5Oset_comment_by_name function. */ if((hid_t_f)H5Oset_comment_by_name((hid_t)*object_id, c_name, c_comment, (hid_t)*lapl_id) < 0) HGOTO_DONE(FAIL); done: if(c_name) HDfree(c_name); if(c_comment) HDfree(c_comment); return ret_value; }
//-------------------------------------------------------------------------- // Function: CommonFG::removeComment ///\brief Removes the comment from an object specified by its name. ///\param name - IN: Name of the object ///\exception H5::FileIException or H5::GroupIException // Programmer Binh-Minh Ribler - May 2005 // 2007: QAK modified to use H5O APIs; however the first parameter is // no longer just file or group, this function should be moved // to another class to accommodate attribute, dataset, and named // datatype. - BMR //-------------------------------------------------------------------------- void CommonFG::removeComment(const char* name) const { herr_t ret_value = H5Oset_comment_by_name(getLocId(), name, NULL, H5P_DEFAULT); if( ret_value < 0 ) { throwException("removeComment", "H5Oset_comment_by_name failed"); } }
/* * test_objnames * Tests that UTF-8 can be used for object names in the file. * Tests groups, datasets, named datatypes, and soft links. * Note that this test doesn't actually mark the names as being * in UTF-8. At the time this test was written, that feature * didn't exist in HDF5, and when the character encoding property * was added to links it didn't change how they were stored in the file, * -JML 2/2/2006 */ void test_objnames(hid_t fid, const char* string) { hid_t grp_id, grp1_id, grp2_id, grp3_id; hid_t type_id, dset_id, space_id; char read_buf[MAX_STRING_LENGTH]; char path_buf[MAX_PATH_LENGTH]; hsize_t dims=1; hobj_ref_t obj_ref; herr_t ret; /* Create a group with a UTF-8 name */ grp_id = H5Gcreate2(fid, string, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(grp_id, FAIL, "H5Gcreate2"); /* Set a comment on the group to test that we can access the group * Also test that UTF-8 comments can be read. */ ret = H5Oset_comment_by_name(fid, string, string, H5P_DEFAULT); CHECK(ret, FAIL, "H5Oset_comment_by_name"); ret = H5Oget_comment_by_name(fid, string, read_buf, (size_t)MAX_STRING_LENGTH, H5P_DEFAULT); CHECK(ret, FAIL, "H5Oget_comment_by_name"); ret = H5Gclose(grp_id); CHECK(ret, FAIL, "H5Gclose"); VERIFY(HDstrcmp(string, read_buf), 0, "strcmp"); /* Create a new dataset with a UTF-8 name */ grp1_id = H5Gcreate2(fid, GROUP1_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(grp1_id, FAIL, "H5Gcreate2"); space_id = H5Screate_simple(RANK, &dims, NULL); CHECK(space_id, FAIL, "H5Screate_simple"); dset_id = H5Dcreate2(grp1_id, string, H5T_NATIVE_INT, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(dset_id, FAIL, "H5Dcreate2"); /* Make sure that dataset can be opened again */ ret = H5Dclose(dset_id); CHECK(ret, FAIL, "H5Dclose"); ret = H5Sclose(space_id); CHECK(ret, FAIL, "H5Sclose"); dset_id = H5Dopen2(grp1_id, string, H5P_DEFAULT); CHECK(ret, FAIL, "H5Dopen2"); ret = H5Dclose(dset_id); CHECK(ret, FAIL, "H5Dclose"); ret = H5Gclose(grp1_id); CHECK(ret, FAIL, "H5Gclose"); /* Do the same for a named datatype */ grp2_id = H5Gcreate2(fid, GROUP2_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(grp2_id, FAIL, "H5Gcreate2"); type_id = H5Tcreate(H5T_OPAQUE, (size_t)1); CHECK(type_id, FAIL, "H5Tcreate"); ret = H5Tcommit2(grp2_id, string, type_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(type_id, FAIL, "H5Tcommit2"); ret = H5Tclose(type_id); CHECK(type_id, FAIL, "H5Tclose"); type_id = H5Topen2(grp2_id, string, H5P_DEFAULT); CHECK(type_id, FAIL, "H5Topen2"); ret = H5Tclose(type_id); CHECK(type_id, FAIL, "H5Tclose"); /* Don't close the group -- use it to test that object references * can refer to objects named in UTF-8 */ space_id = H5Screate_simple(RANK, &dims, NULL); CHECK(space_id, FAIL, "H5Screate_simple"); dset_id = H5Dcreate2(grp2_id, DSET3_NAME, H5T_STD_REF_OBJ, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(ret, FAIL, "H5Dcreate2"); /* Create reference to named datatype */ ret = H5Rcreate(&obj_ref, grp2_id, string, H5R_OBJECT, -1); CHECK(ret, FAIL, "H5Rcreate"); /* Write selection and read it back*/ ret = H5Dwrite(dset_id, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, &obj_ref); CHECK(ret, FAIL, "H5Dwrite"); ret = H5Dread(dset_id, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, &obj_ref); CHECK(ret, FAIL, "H5Dread"); /* Ensure that we can open named datatype using object reference */ type_id = H5Rdereference2(dset_id, H5P_DEFAULT, H5R_OBJECT, &obj_ref); CHECK(type_id, FAIL, "H5Rdereference2"); ret = H5Tcommitted(type_id); VERIFY(ret, 1, "H5Tcommitted"); ret = H5Tclose(type_id); CHECK(type_id, FAIL, "H5Tclose"); ret = H5Dclose(dset_id); CHECK(ret, FAIL, "H5Dclose"); ret = H5Sclose(space_id); CHECK(ret, FAIL, "H5Sclose"); ret = H5Gclose(grp2_id); CHECK(ret, FAIL, "H5Gclose"); /* Create "group3". Build a hard link from group3 to group2, which has * a datatype with the UTF-8 name. Create a soft link in group3 * pointing through the hard link to the datatype. Give the soft * link a name in UTF-8. Ensure that the soft link works. */ grp3_id = H5Gcreate2(fid, GROUP3_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(grp3_id, FAIL, "H5Gcreate2"); ret = H5Lcreate_hard(fid, GROUP2_NAME, grp3_id, GROUP2_NAME, H5P_DEFAULT, H5P_DEFAULT); CHECK(ret, FAIL, "H5Lcreate_hard"); HDstrcpy(path_buf, GROUP2_NAME); HDstrcat(path_buf, "/"); HDstrcat(path_buf, string); ret = H5Lcreate_hard(grp3_id, path_buf, H5L_SAME_LOC, string, H5P_DEFAULT, H5P_DEFAULT); CHECK(ret, FAIL, "H5Lcreate_hard"); /* Open named datatype using soft link */ type_id = H5Topen2(grp3_id, string, H5P_DEFAULT); CHECK(type_id, FAIL, "H5Topen2"); ret = H5Tclose(type_id); CHECK(type_id, FAIL, "H5Tclose"); ret = H5Gclose(grp3_id); CHECK(ret, FAIL, "H5Gclose"); }
//-------------------------------------------------------------------------- // Function: H5Location::removeComment ///\brief Removes the comment from an object specified by its name. ///\param name - IN: Name of the object ///\exception H5::LocationException // Programmer Binh-Minh Ribler - May 2005 (moved from CommonFG, Sep 2013) // 2007: QAK modified to use H5O APIs; however the first parameter is // no longer just file or group, this function should be moved // to another class to accommodate attribute, dataset, and named // datatype. - BMR //-------------------------------------------------------------------------- void H5Location::removeComment(const char* name) const { herr_t ret_value = H5Oset_comment_by_name(getId(), name, NULL, H5P_DEFAULT); if( ret_value < 0 ) throw LocationException(inMemFunc("removeComment"), "H5Oset_comment_by_name failed"); }
//-------------------------------------------------------------------------- // Function: H5Location::setComment ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it doesn't take /// an object name. // Programmer Binh-Minh Ribler - Sep 2013 // Modification //-------------------------------------------------------------------------- void H5Location::setComment(const char* comment) const { herr_t ret_value = H5Oset_comment_by_name(getId(), ".", comment, H5P_DEFAULT); if( ret_value < 0 ) throw LocationException(inMemFunc("setComment"), "H5Oset_comment_by_name failed"); }