/* * Class: hdf_hdf5lib_H5 * Method: H5Aget_name_by_idx * Signature: (JLjava/lang/String;IIJJ)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_hdf_hdf5lib_H5_H5Aget_1name_1by_1idx (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jint idx_type, jint order, jlong n, jlong lapl_id) { size_t buf_size; char *aValue; jlong status_size; jstring str = NULL; const char *aName; PIN_JAVA_STRING(obj_name, aName); if (aName != NULL) { /* get the length of the attribute name */ status_size = H5Aget_name_by_idx((hid_t)loc_id, aName, (H5_index_t)idx_type, (H5_iter_order_t) order, (hsize_t) n, (char*)NULL, (size_t)0, (hid_t)lapl_id); if(status_size < 0) { UNPIN_JAVA_STRING(obj_name, aName); h5libraryError(env); } /* end if */ else { buf_size = (size_t)status_size + 1;/* add extra space for the null terminator */ aValue = (char*)HDmalloc(sizeof(char) * buf_size); if (aValue == NULL) { UNPIN_JAVA_STRING(obj_name, aName); h5outOfMemory(env, "H5Aget_name_by_idx: malloc failed "); } /* end if */ else { status_size = H5Aget_name_by_idx((hid_t)loc_id, aName, (H5_index_t)idx_type, (H5_iter_order_t) order, (hsize_t) n, (char*)aValue, (size_t)buf_size, (hid_t)lapl_id); UNPIN_JAVA_STRING(obj_name, aName); if (status_size < 0) { HDfree(aValue); h5libraryError(env); } /* end if */ else { str = ENVPTR->NewStringUTF(ENVPAR aValue); HDfree(aValue); if (str == NULL) { /* exception -- fatal JNI error */ h5JNIFatalError(env, "H5Aget_name_by_idx: return string not created"); } /* end if */ } /* end else */ } /* end else */ } /* end else */ } return str; } /* end Java_hdf_hdf5lib_H5_H5Aget_1name_1by_1idx */
void Object::updateAttributes() { fAttributes.clear(); if (fObjectId < 0) return; // get attributes int nAttrs = H5Aget_num_attrs(fObjectId); if (nAttrs < 0) { throw Exception("Could not retrieve number of attributes"); } for (size_t iAttr = 0; iAttr < static_cast<size_t>(nAttrs); ++iAttr) { char* attrName; char objName[] = "."; ssize_t nameLen = H5Aget_name_by_idx(fObjectId, objName, H5_INDEX_NAME, H5_ITER_INC, iAttr, 0, 0, H5P_DEFAULT); if (nameLen > 0) { // fetch name of this attribute attrName = new char[++nameLen]; H5Aget_name_by_idx(fObjectId, objName, H5_INDEX_NAME, H5_ITER_INC, iAttr, attrName, nameLen, H5P_DEFAULT); string sAttrName(attrName); delete[] attrName; // open attribute hid_t attrId = H5Aopen_by_idx(fObjectId, objName, H5_INDEX_NAME, H5_ITER_INC, iAttr, H5P_DEFAULT, H5P_DEFAULT); if (attrId < 0) { cerr << "Could not open attribute '" << sAttrName << "'" << endl; continue; } // parse type info // cout << "Reading attribute: " << sAttrName << endl; fAttributes[sAttrName] = llReadAttribute(attrId); // close attribute H5Aclose(attrId); } } }