mirror of
https://github.com/HDFGroup/hdf5.git
synced 2025-03-07 16:37:56 +08:00
Due to HDFVIEW-19 add read VL as string function
This commit is contained in:
parent
f6920ad11c
commit
53132d8864
@ -1798,6 +1798,9 @@ public class H5 implements java.io.Serializable {
|
||||
return H5Dread_short(dataset_id, mem_type_id, mem_space_id, file_space_id, xfer_plist_id, buf, true);
|
||||
}
|
||||
|
||||
public synchronized static native int H5DreadVL(long dataset_id, long mem_type_id, long mem_space_id,
|
||||
long file_space_id, long xfer_plist_id, Object[] buf) throws HDF5LibraryException, NullPointerException;
|
||||
|
||||
public synchronized static native int H5Dread_string(long dataset_id, long mem_type_id, long mem_space_id,
|
||||
long file_space_id, long xfer_plist_id, String[] buf) throws HDF5LibraryException, NullPointerException;
|
||||
|
||||
|
@ -55,6 +55,7 @@ extern jobject visit_callback;
|
||||
/* Local Prototypes */
|
||||
/********************/
|
||||
|
||||
static herr_t H5DreadVL_asstr (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf);
|
||||
static herr_t H5DreadVL_str (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf);
|
||||
static herr_t H5DreadVL_array (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf);
|
||||
static herr_t H5DwriteVL_str (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf);
|
||||
@ -992,6 +993,96 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1double
|
||||
return (jint)status;
|
||||
} /* end Java_hdf_hdf5lib_H5_H5Dwrite_1double */
|
||||
|
||||
/*
|
||||
* Class: hdf_hdf5lib_H5
|
||||
* Method: H5DreadVL
|
||||
* Signature: (JJJJJ[Ljava/lang/String;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_hdf_hdf5lib_H5_H5DreadVL
|
||||
(JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id,
|
||||
jlong file_space_id, jlong xfer_plist_id, jobjectArray buf)
|
||||
{
|
||||
herr_t status = -1;
|
||||
htri_t isVlenStr=0;
|
||||
|
||||
if (buf == NULL) {
|
||||
h5nullArgument(env, "H5DreadVL: buf is NULL");
|
||||
} /* end if */
|
||||
else {
|
||||
isVlenStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING);
|
||||
|
||||
if (isVlenStr)
|
||||
h5badArgument(env, "H5DreadVL: type is not variable length non-string");
|
||||
else
|
||||
status = H5DreadVL_asstr(env, (hid_t)dataset_id, (hid_t)mem_type_id,
|
||||
(hid_t)mem_space_id, (hid_t)file_space_id,
|
||||
(hid_t)xfer_plist_id, buf);
|
||||
} /* end else */
|
||||
|
||||
return (jint)status;
|
||||
} /* end Java_hdf_hdf5lib_H5_H5Dread_1VLStrings */
|
||||
|
||||
herr_t
|
||||
H5DreadVL_asstr
|
||||
(JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf)
|
||||
{
|
||||
jint i;
|
||||
jint n;
|
||||
jstring jstr;
|
||||
h5str_t h5str;
|
||||
hvl_t *rdata;
|
||||
size_t size;
|
||||
size_t max_len = 0;
|
||||
herr_t status = -1;
|
||||
|
||||
n = ENVPTR->GetArrayLength(ENVPAR buf);
|
||||
rdata = (hvl_t*)HDcalloc((size_t)n, sizeof(hvl_t));
|
||||
if (rdata == NULL) {
|
||||
h5JNIFatalError(env, "H5DreadVL_notstr: failed to allocate buff for read");
|
||||
} /* end if */
|
||||
else {
|
||||
status = H5Dread(did, tid, mem_sid, file_sid, xfer_plist_id, rdata);
|
||||
|
||||
if (status < 0) {
|
||||
H5Dvlen_reclaim(tid, mem_sid, xfer_plist_id, rdata);
|
||||
HDfree(rdata);
|
||||
h5JNIFatalError(env, "H5DreadVL_notstr: failed to read data");
|
||||
} /* end if */
|
||||
else {
|
||||
max_len = 1;
|
||||
for (i=0; i < n; i++) {
|
||||
if ((rdata + i)->len > max_len)
|
||||
max_len = (rdata + i)->len;
|
||||
}
|
||||
|
||||
size = H5Tget_size(tid) * max_len;
|
||||
HDmemset(&h5str, 0, sizeof(h5str_t));
|
||||
h5str_new(&h5str, 4 * size);
|
||||
|
||||
if (h5str.s == NULL) {
|
||||
H5Dvlen_reclaim(tid, mem_sid, xfer_plist_id, rdata);
|
||||
HDfree(rdata);
|
||||
h5JNIFatalError(env, "H5DreadVL_notstr: failed to allocate buf");
|
||||
} /* end if */
|
||||
else {
|
||||
for (i=0; i < n; i++) {
|
||||
h5str.s[0] = '\0';
|
||||
h5str_sprintf(&h5str, did, tid, rdata+i, 0);
|
||||
jstr = ENVPTR->NewStringUTF(ENVPAR h5str.s);
|
||||
ENVPTR->SetObjectArrayElement(ENVPAR buf, i, jstr);
|
||||
} /* end for */
|
||||
h5str_free(&h5str);
|
||||
|
||||
H5Dvlen_reclaim(tid, mem_sid, xfer_plist_id, rdata);
|
||||
HDfree(rdata);
|
||||
} /* end else */
|
||||
} /* end else */
|
||||
} /* end else */
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: hdf_hdf5lib_H5
|
||||
* Method: H5Dread_string
|
||||
|
@ -204,6 +204,15 @@ JNIEXPORT jint JNICALL
|
||||
Java_hdf_hdf5lib_H5_H5Dwrite_1double
|
||||
(JNIEnv*, jclass, jlong, jlong, jlong, jlong, jlong, jdoubleArray, jboolean);
|
||||
|
||||
/*
|
||||
* Class: hdf_hdf5lib_H5
|
||||
* Method: H5DreadVL
|
||||
* Signature: (JJJJJ[Ljava/lang/String;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_hdf_hdf5lib_H5_H5DreadVL
|
||||
(JNIEnv*, jclass, jlong, jlong, jlong, jlong, jlong, jobjectArray);
|
||||
|
||||
/*
|
||||
* Class: hdf_hdf5lib_H5
|
||||
* Method: H5Dread_string
|
||||
|
Loading…
Reference in New Issue
Block a user