h5dImpJHDF5.c 39.4 KB
Newer Older
brinn's avatar
brinn committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/****************************************************************************
 * NCSA HDF                                                                 *
 * National Comptational Science Alliance                                   *
 * University of Illinois at Urbana-Champaign                               *
 * 605 E. Springfield, Champaign IL 61820                                   *
 *                                                                          *
 * For conditions of distribution and use, see the accompanying             *
 * hdf-java/COPYING file.                                                   *
 *                                                                          *
 ****************************************************************************/

/*
 *  This code is the C-interface called by Java programs to access the
 *  Dataset Object API Functions of HDF5 library.
 *
 *  Each routine wraps a single HDF entry point, generally with the
 *  analogous arguments and return codes.
 *
 *  For details of the HDF libraries, see the HDF Documentation at:
 *   http://hdf.ncsa.uiuc.edu/&isCopy/doc/
 *
 */

#ifdef __cplusplus
extern "C" {
#endif

#include "hdf5.h"
29
#include "h5utilJHDF5.h"
brinn's avatar
brinn committed
30
31
32
33
34
35
36
37
38
#include <jni.h>
#include <stdlib.h>
#include <string.h>

extern jboolean h5outOfMemory( JNIEnv *env, char *functName);
extern jboolean h5JNIFatalError( JNIEnv *env, char *functName);
extern jboolean h5nullArgument( JNIEnv *env, char *functName);
extern jboolean h5libraryError( JNIEnv *env );

39
40
herr_t H5DreadVL_str_jhdf5 (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf);
herr_t H5DreadVL_num_jhdf5 (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf);
brinn's avatar
brinn committed
41
42
43
44
45
46

/*
 * Class:     ncsa_hdf_hdf5lib_H5
 * Method:    H5Dcreate
 * Signature: (ILjava/lang/String;III)I
 */
47
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dcreate
brinn's avatar
brinn committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  (JNIEnv *env, jclass clss, jint loc_id, jstring name, jint type_id,
  jint space_id, jint link_create_plist_id, jint dset_create_plist_id, 
  jint dset_access_plist_id)
{
    herr_t status;
    char* file;
    jboolean isCopy;

    if (name == NULL) {
        h5nullArgument( env, "H5Dcreate:  name is NULL");
        return -1;
    }
#ifdef __cplusplus
    file = (char *)env->GetStringUTFChars(name,&isCopy);
#else
    file = (char *)(*env)->GetStringUTFChars(env,name,&isCopy);
#endif
    if (file == NULL) {
        h5JNIFatalError( env, "H5Dcreate:  file name not pinned");
        return -1;
    }

    status = H5Dcreate((hid_t)loc_id, file, (hid_t)type_id, 
71
72
        (hid_t)space_id, (hid_t)link_create_plist_id, 
    (hid_t) dset_create_plist_id, (hid_t)dset_access_plist_id);
brinn's avatar
brinn committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

#ifdef __cplusplus
    env->ReleaseStringUTFChars(name,file);
#else
    (*env)->ReleaseStringUTFChars(env,name,file);
#endif
    if (status < 0) {
        h5libraryError(env);
    }
    return (jint)status;
}

/*
 * Class:     ncsa_hdf_hdf5lib_H5
 * Method:    H5Dchdir_ext
 * Signature: (ILjava/lang/String;)I
 */
90
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dchdir_1ext
brinn's avatar
brinn committed
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
  (JNIEnv *env, jclass clss, jstring dir_name)
{
    hid_t status;
    char* file;
    jboolean isCopy;

    if (dir_name == NULL) {
        h5nullArgument( env, "H5Dchdir_ext:  dir_name is NULL");
        return -1;
    }
#ifdef __cplusplus
    file = (char *)env->GetStringUTFChars(dir_name,&isCopy);
#else
    file = (char *)(*env)->GetStringUTFChars(env,dir_name,&isCopy);
#endif
    if (file == NULL) {
        h5JNIFatalError( env, "H5Dchdir_ext:  file dir not pinned");
        return -1;
    }
    status = chdir ( file );

#ifdef __cplusplus
    env->ReleaseStringUTFChars(dir_name,file);
#else
    (*env)->ReleaseStringUTFChars(env,dir_name,file);
#endif
    if (status < 0) {
        h5libraryError(env);
    }
    return (jint)status;
}

/*
 * Class:     ncsa_hdf_hdf5lib_H5
 * Method:    H5Dgetdir_1ext
 * Signature: (ILjava/lang/String;)I
 */
128
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dgetdir_1ext
brinn's avatar
brinn committed
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
  (JNIEnv *env, jclass clss, jstring dir_name, jint buf_size)
{
    char *aName;
    jstring str;

    if (buf_size <= 0) {
        h5badArgument( env, "H5Dgetcwd:  buf_size <= 0");
        return -1;
    }
    aName = (char*)malloc(sizeof(char)*buf_size);
    if (aName == NULL) {
        h5outOfMemory( env, "H5Dgetcwd:  malloc failed");
        return -1;
    }
    getcwd( (char *)aName, (size_t)buf_size);

    str = (*env)->NewStringUTF(env,aName);

    if (str == NULL) {
        free(aName);
149
        h5outOfMemory( env,"H5Dgetcwd:  return string failed");
brinn's avatar
brinn committed
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
        return -1;
    }
    free(aName);

    (*env)->SetObjectArrayElement(env,dir_name,0,str);

    return 0;
}


/*
 * Class:     ncsa_hdf_hdf5lib_H5
 * Method:    H5Dopen
 * Signature: (ILjava/lang/String;)I
 */
165
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dopen
brinn's avatar
brinn committed
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
  (JNIEnv *env, jclass clss, jint loc_id, jstring name, jint access_plist_id)
{
    hid_t status;
    char* file;
    jboolean isCopy;

    if (name == NULL) {
        h5nullArgument( env, "H5Dopen:  name is NULL");
        return -1;
    }
#ifdef __cplusplus
    file = (char *)env->GetStringUTFChars(name,&isCopy);
#else
    file = (char *)(*env)->GetStringUTFChars(env,name,&isCopy);
#endif
    if (file == NULL) {
        h5JNIFatalError( env, "H5Dopen:  file name not pinned");
        return -1;
    }
    status = H5Dopen((hid_t)loc_id, file, (hid_t) access_plist_id);

#ifdef __cplusplus
    env->ReleaseStringUTFChars(name,file);
#else
    (*env)->ReleaseStringUTFChars(env,name,file);
#endif
    if (status < 0) {
        h5libraryError(env);
    }
    return (jint)status;
}

/*
 * Class:     ncsa_hdf_hdf5lib_H5
 * Method:    H5Dget_space
 * Signature: (I)I
 */
203
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dget_1space
brinn's avatar
brinn committed
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
  (JNIEnv *env, jclass clss, jint dataset_id)
{
    hid_t retVal = -1;
    retVal =  H5Dget_space((hid_t)dataset_id );
    if (retVal < 0) {
        h5libraryError(env);
    }
    return (jint)retVal;
}

/*
 * Class:     ncsa_hdf_hdf5lib_H5
 * Method:    H5Dget_type
 * Signature: (I)I
 */
219
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dget_1type
brinn's avatar
brinn committed
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
  (JNIEnv *env, jclass clss, jint dataset_id)
{
    hid_t retVal = -1;
    retVal = H5Dget_type((hid_t)dataset_id );
    if (retVal < 0) {
        h5libraryError(env);
    }
    return (jint)retVal;
}

/*
 * Class:     ncsa_hdf_hdf5lib_H5
 * Method:    H5Dget_create_plist
 * Signature: (I)I
 */
235
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dget_1create_1plist
brinn's avatar
brinn committed
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
  (JNIEnv *env, jclass clss, jint dataset_id)
{
    hid_t retVal = -1;
    retVal =  H5Dget_create_plist((hid_t)dataset_id );
    if (retVal < 0) {
        h5libraryError(env);
    }
    return (jint)retVal;
}

/*
 * Class:     ncsa_hdf_hdf5lib_H5
 * Method:    H5Dread
 * Signature: (IIIII[B)I
 */
251
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dread
brinn's avatar
brinn committed
252
253
254
255
256
257
258
259
260
261
262
263
264
  (JNIEnv *env, jclass clss, jint dataset_id, jint mem_type_id, jint mem_space_id,
  jint file_space_id, jint xfer_plist_id, jbyteArray buf)
{
    herr_t status;
    jbyte *byteP;
    jboolean isCopy;


    if ( buf == NULL ) {
        h5nullArgument( env, "H5Dread:  buf is NULL");
        return -1;
    }
#ifdef __cplusplus
265
    byteP = env->GetPrimitiveArrayCritical(buf,&isCopy);
brinn's avatar
brinn committed
266
#else
267
    byteP = (*env)->GetPrimitiveArrayCritical(env,buf,&isCopy);
brinn's avatar
brinn committed
268
269
270
271
272
273
274
275
276
277
278
#endif
    if (byteP == NULL) {
        h5JNIFatalError( env, "H5Dread:  buf not pinned");
        return -1;
    }

    status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id,
        (hid_t)file_space_id, (hid_t)xfer_plist_id, byteP);

    if (status < 0) {
#ifdef __cplusplus
279
        env->ReleasePrimitiveArrayCritical(buf,byteP,JNI_ABORT);
brinn's avatar
brinn committed
280
#else
281
        (*env)->ReleasePrimitiveArrayCritical(env,buf,byteP,JNI_ABORT);
brinn's avatar
brinn committed
282
283
284
285
#endif
        h5libraryError(env);
    } else  {
#ifdef __cplusplus
286
        env->ReleasePrimitiveArrayCritical(buf,byteP,0);
brinn's avatar
brinn committed
287
#else
288
        (*env)->ReleasePrimitiveArrayCritical(env,buf,byteP,0);
brinn's avatar
brinn committed
289
290
291
292
293
294
295
296
297
298
299
#endif
    }

    return (jint)status;
}

/*
 * Class:     ncsa_hdf_hdf5lib_H5
 * Method:    H5Dwrite
 * Signature: (IIIII[B)I
 */
300
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dwrite
brinn's avatar
brinn committed
301
302
303
304
305
306
307
308
309
310
311
312
313
  (JNIEnv *env, jclass clss, jint dataset_id, jint mem_type_id, jint mem_space_id,
  jint file_space_id, jint xfer_plist_id, jbyteArray buf)
{
    herr_t status;
    jbyte *byteP;
    jboolean isCopy;

    if ( buf == NULL ) {
        h5nullArgument( env, "H5Dwrite:  buf is NULL");
        return -1;
    }

#ifdef __cplusplus
314
    byteP = env->GetPrimitiveArrayCritical(buf,&isCopy);
brinn's avatar
brinn committed
315
#else
316
    byteP = (*env)->GetPrimitiveArrayCritical(env,buf,&isCopy);
brinn's avatar
brinn committed
317
318
319
320
321
322
323
324
325
326
#endif
    if (byteP == NULL) {
        h5JNIFatalError( env, "H5Dwrite:  buf not pinned");
        return -1;
    }

    status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id,
        (hid_t)file_space_id, (hid_t)xfer_plist_id, byteP);

#ifdef __cplusplus
327
    env->ReleasePrimitiveArrayCritical(buf,byteP,JNI_ABORT);
brinn's avatar
brinn committed
328
#else
329
    (*env)->ReleasePrimitiveArrayCritical(env,buf,byteP,JNI_ABORT);
brinn's avatar
brinn committed
330
331
332
333
334
335
336
337
338
339
340
341
342
#endif

    if (status < 0) {
        h5libraryError(env);
    }
    return (jint)status;
}

/*
 * Class:     ncsa_hdf_hdf5lib_H5
 * Method:    H5Dextend
 * Signature: (IB)I
 */
343
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dextend
brinn's avatar
brinn committed
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
  (JNIEnv *env, jclass clss, jint dataset_id, jbyteArray size)
{
    herr_t status;
    jbyte *P;
    jboolean isCopy;
    hsize_t *sa;
    int i;
    int rank;
    hsize_t *lp;
    jlong *jlp;

    if ( size == NULL ) {
        h5nullArgument( env, "H5Dextend:  array of sizes is NULL");
        return -1;
    }
    /*
     *  Future:  check that the array has correct
     *           rank (same as dataset dataset_id)
     */
#ifdef __cplusplus
    P = env->GetByteArrayElements(size,&isCopy);
#else
    P = (*env)->GetByteArrayElements(env,size,&isCopy);
#endif
    if (P == NULL) {
        h5JNIFatalError( env, "H5Dextend:  array not pinned");
        return -1;
    }
#ifdef __cplusplus
    i = env->GetArrayLength(size);
#else
    i = (*env)->GetArrayLength(env,size);
#endif
    rank = i / sizeof(jlong);
    sa = lp = (hsize_t *)malloc(rank * sizeof(hsize_t));
    if (sa == NULL)  {
#ifdef __cplusplus
        env->ReleaseByteArrayElements(size,P,JNI_ABORT);
#else
        (*env)->ReleaseByteArrayElements(env,size,P,JNI_ABORT);
#endif
385
        h5outOfMemory(env,  "H5Dextend:  size not converted to hsize_t");
brinn's avatar
brinn committed
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
        return -1;
    }
    jlp = (jlong *)P;
    for (i = 0; i < rank; i++) {
        *lp = (hsize_t)*jlp;
        lp++;
        jlp++;
    }

    status = H5Dextend((hid_t)dataset_id, (hsize_t *)sa);

#ifdef __cplusplus
    env->ReleaseByteArrayElements(size,P,JNI_ABORT);
#else
    (*env)->ReleaseByteArrayElements(env,size,P,JNI_ABORT);
#endif
    free(sa);

    if (status < 0) {
        h5libraryError(env);
    }
    return (jint)status;
}

/*
 * Class:     ncsa_hdf_hdf5lib_H5
 * Method:    H5Dset_1extent
 * Signature: (IB)I
 */
415
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dset_1extent
brinn's avatar
brinn committed
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
  (JNIEnv *env, jclass clss, jint dataset_id, jbyteArray size)
{
    herr_t status;
    jbyte *P;
    jboolean isCopy;
    hsize_t *sa;
    int i;
    int rank;
    hsize_t *lp;
    jlong *jlp;

    if ( size == NULL ) {
        h5nullArgument( env, "H5Dextend:  array of sizes is NULL");
        return -1;
    }
    /*
     *  Future:  check that the array has correct
     *           rank (same as dataset dataset_id)
     */
#ifdef __cplusplus
    P = env->GetByteArrayElements(size,&isCopy);
#else
    P = (*env)->GetByteArrayElements(env,size,&isCopy);
#endif
    if (P == NULL) {
        h5JNIFatalError( env, "H5Dextend:  array not pinned");
        return -1;
    }
#ifdef __cplusplus
    i = env->GetArrayLength(size);
#else
    i = (*env)->GetArrayLength(env,size);
#endif
    rank = i / sizeof(jlong);
    sa = lp = (hsize_t *)malloc(rank * sizeof(hsize_t));
    if (sa == NULL)  {
#ifdef __cplusplus
        env->ReleaseByteArrayElements(size,P,JNI_ABORT);
#else
        (*env)->ReleaseByteArrayElements(env,size,P,JNI_ABORT);
#endif
457
        h5outOfMemory(env,  "H5Dextend:  size not converted to hsize_t");
brinn's avatar
brinn committed
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
        return -1;
    }
    jlp = (jlong *)P;
    for (i = 0; i < rank; i++) {
        *lp = (hsize_t)*jlp;
        lp++;
        jlp++;
    }

    status = H5Dset_extent((hid_t)dataset_id, (hsize_t *)sa);

#ifdef __cplusplus
    env->ReleaseByteArrayElements(size,P,JNI_ABORT);
#else
    (*env)->ReleaseByteArrayElements(env,size,P,JNI_ABORT);
#endif
    free(sa);

    if (status < 0) {
        h5libraryError(env);
    }
    return (jint)status;
}

/*
 * Class:     ncsa_hdf_hdf5lib_H5
 * Method:    H5Dclose
 * Signature: (I)I
 */
487
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dclose
brinn's avatar
brinn committed
488
489
490
491
  (JNIEnv *env, jclass clss, jint dataset_id)
{
    hid_t retVal = 0;

492
493
    if (dataset_id > 0)
        retVal =  H5Dclose((hid_t)dataset_id );
brinn's avatar
brinn committed
494
495
496
497
498
499
500
501
502
503
504
505

    if (retVal < 0) {
        h5libraryError(env);
    }
    return (jint)retVal;
}

/*
 * Class:     ncsa_hdf_hdf5lib_H5
 * Method:    H5Dget_storage_size
 * Signature: (I)J
 */
506
JNIEXPORT jlong JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dget_1storage_1size
brinn's avatar
brinn committed
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
  (JNIEnv *env, jclass clss, jint dataset_id)
{
    hsize_t retVal = (hsize_t)-1;
    retVal =  H5Dget_storage_size((hid_t)dataset_id );
/* probably returns '0' if fails--don't do an exception
    if (retVal < 0) {
        h5libraryError(env);
    }
*/
    return (jlong)retVal;
}

/*
 * Copies the content of one dataset to another dataset
 * Class:     ncsa_hdf_hdf5lib_H5
 * Method:    H5Dcopy
 * Signature: (I)I
 */
525
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dcopy
brinn's avatar
brinn committed
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
  (JNIEnv *env, jclass clss, jint src_id, jint dst_id)
{
    jbyte *buf;
    herr_t retVal = -1;
    hid_t src_did = (hid_t)src_id;
    hid_t dst_did = (hid_t)dst_id;
    hid_t tid=-1;
    hid_t sid=-1;
    hsize_t total_size = 0;


    sid = H5Dget_space(src_did);
    if (sid < 0) {
        h5libraryError(env);
        return -1;
    }

    tid = H5Dget_type(src_did);
    if (tid < 0) {
        H5Sclose(sid);
        h5libraryError(env);
        return -1;
    }

    total_size = H5Sget_simple_extent_npoints(sid) *
            H5Tget_size(tid);

    H5Sclose(sid);

555
    buf = (jbyte *)calloc( (int) (total_size), sizeof(jbyte));
brinn's avatar
brinn committed
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
        if (buf == NULL) {
        H5Tclose(tid);
                h5outOfMemory( env, "H5Dcopy:  malloc failed");
                return -1;
        }

    retVal = H5Dread(src_did, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
    H5Tclose(tid);

    if (retVal < 0) {
        free(buf);
        h5libraryError(env);
        return (jint)retVal;
    }

    tid = H5Dget_type(dst_did);
    if (tid < 0) {
        free(buf);
        h5libraryError(env);
        return -1;
    }
    retVal = H5Dwrite(dst_did, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
    H5Tclose(tid);
    free(buf);

    if (retVal < 0) {
        h5libraryError(env);
    }

    return (jint)retVal;
}


/*
 * Copies the content of one dataset to another dataset
 * Class:     ncsa_hdf_hdf5lib_H5
 * Method:    H5Dvlen_get_buf_size
 * Signature: (III[I)I
 */
595
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dvlen_1get_1buf_1size
brinn's avatar
brinn committed
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
  (JNIEnv *env, jclass clss,
jint dataset_id, jint type_id, jint space_id, jintArray size )
{
    herr_t status;
    jint *P;
    jboolean isCopy;
    hsize_t sz;

    if ( size == NULL ) {
        h5nullArgument( env, "H5Dvlen_get_buf_size:  size is NULL");
        return -1;
    }

#ifdef __cplusplus
    P = env->GetIntArrayElements(size,&isCopy);
#else
    P = (*env)->GetIntArrayElements(env,size,&isCopy);
#endif
    if (P == NULL) {
        h5JNIFatalError( env, "H5Dvlen_get_buf_size:  array not pinned");
        return -1;
    }

    status = (jint)H5Dvlen_get_buf_size((hid_t) dataset_id,
        (hid_t) type_id, (hid_t) space_id, (hsize_t *)&sz);



    if (status < 0) {
#ifdef __cplusplus
        env->ReleaseIntArrayElements(size,P,JNI_ABORT);
#else
        (*env)->ReleaseIntArrayElements(env,size,P,JNI_ABORT);
#endif
        h5libraryError(env);
    } else {
        P[0] = (jint)sz;
#ifdef __cplusplus
        env->ReleaseIntArrayElements(size,P,0);
#else
        (*env)->ReleaseIntArrayElements(env,size,P,0);
#endif
    }
    return (jint)status;
}


/*
 * Class:     ncsa_hdf_hdf5lib_H5
 * Method:    H5Dvlen_reclaim
 * Signature: (IIIII[B)I
 */
648
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dvlen_1reclaim
brinn's avatar
brinn committed
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
  (JNIEnv *env, jclass clss, jint type_id, jint space_id,
   jint xfer_plist_id, jbyteArray buf)
{
    herr_t status;
    jbyte *byteP;
    jboolean isCopy;

    if ( buf == NULL ) {
        h5nullArgument( env, "H5Dwrite:  buf is NULL");
        return -1;
    }
#ifdef __cplusplus
    byteP = env->GetByteArrayElements(buf,&isCopy);
#else
    byteP = (*env)->GetByteArrayElements(env,buf,&isCopy);
#endif
    if (byteP == NULL) {
        h5JNIFatalError( env, "H5Dwrite:  buf not pinned");
        return -1;
    }

    status = H5Dvlen_reclaim((hid_t)type_id,
        (hid_t)space_id, (hid_t)xfer_plist_id, byteP);

#ifdef __cplusplus
    env->ReleaseByteArrayElements(buf,byteP,JNI_ABORT);
#else
    (*env)->ReleaseByteArrayElements(env,buf,byteP,JNI_ABORT);
#endif

    if (status < 0) {
        h5libraryError(env);
    }
    return (jint)status;
}

/***************************************************************
 *                   New APIs for HDF5.1.6                     *
 ***************************************************************/

/*
 * Class:     ncsa_hdf_hdf5lib_H5
 * Method:    H5Dget_space_status(hid_t dset_id, H5D_space_status_t *status)
 * Signature: (IJ)I
 */
694
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dget_1space_1status
brinn's avatar
brinn committed
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
  (JNIEnv *env, jclass clss, jint dset_id, jintArray status)
{
    herr_t retVal = -1;
    jint *theArray;
    jboolean isCopy;
    H5D_space_status_t space_status;


    if (status == NULL) {
        /* exception ? */
        h5nullArgument( env, "H5Dget_space_status:  status is NULL");
        return -1;
    }
#ifdef __cplusplus
    theArray = (jint *)env->GetIntArrayElements(status,&isCopy);
#else
    theArray = (jint *)(*env)->GetIntArrayElements(env,status,&isCopy);
#endif
    if (theArray == NULL) {
        h5JNIFatalError( env, "H5Dget_space_status:  status not pinned");
        return -1;
    }

    retVal =  H5Dget_space_status((hid_t)dset_id, &space_status );

    if (retVal < 0) {
#ifdef __cplusplus
        env->ReleaseIntArrayElements(status,theArray,JNI_ABORT);
#else
        (*env)->ReleaseIntArrayElements(env,status,theArray,JNI_ABORT);
#endif
        h5libraryError(env);
    } else {
        theArray[0] = space_status;
#ifdef __cplusplus
        env->ReleaseIntArrayElements(status,theArray,0);
#else
        (*env)->ReleaseIntArrayElements(env,status,theArray,0);
#endif
    }

    return (jint)retVal;
}


/*
    ////////////////////////////////////////////////////////////////////
    //                                                                //
    //         New APIs for read data from library                    //
    //  Using H5Dread(..., Object buf) requires function calls        //
    //  theArray.emptyBytes() and theArray.arrayify( buf), which      //
    //  triples the actual memory needed by the data set.             //
    //  Using the following APIs solves the problem.                  //
    //                                                                //
    ////////////////////////////////////////////////////////////////////
*/
/*
 * Class:     ncsa_hdf_hdf5lib_H5
 * Method:    H5Dread_short
754
 * Signature: (IIIII[S)I
brinn's avatar
brinn committed
755
 */
756
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dread__IIIII_3S
brinn's avatar
brinn committed
757
758
759
760
761
762
763
  (JNIEnv *env, jclass clss, jint dataset_id, jint mem_type_id, jint mem_space_id,
  jint file_space_id, jint xfer_plist_id, jshortArray buf)
{
    herr_t status;
    jshort *buffP;
    jboolean isCopy;

764
    if ( buf == NULL ) {
brinn's avatar
brinn committed
765
766
767
768
769
        h5nullArgument( env, "H5Dread:  buf is NULL");
        return -1;
    }

#ifdef __cplusplus
770
    buffP = env->GetPrimitiveArrayCritical(buf,&isCopy);
brinn's avatar
brinn committed
771
#else
772
    buffP = (*env)->GetPrimitiveArrayCritical(env,buf,&isCopy);
brinn's avatar
brinn committed
773
774
775
776
777
778
779
780
781
782
783
#endif
    if (buffP == NULL) {
        h5JNIFatalError( env, "H5Dread:  buf not pinned");
        return -1;
    }

    status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id,
        (hid_t)file_space_id, (hid_t)xfer_plist_id, buffP);

    if (status < 0) {
#ifdef __cplusplus
784
        env->ReleasePrimitiveArrayCritical(buf,buffP,JNI_ABORT);
brinn's avatar
brinn committed
785
#else
786
        (*env)->ReleasePrimitiveArrayCritical(env,buf,buffP,JNI_ABORT);
brinn's avatar
brinn committed
787
788
789
790
#endif
        h5libraryError(env);
    } else  {
#ifdef __cplusplus
791
        env->ReleasePrimitiveArrayCritical(buf,buffP,0);
brinn's avatar
brinn committed
792
#else
793
        (*env)->ReleasePrimitiveArrayCritical(env,buf,buffP,0);
brinn's avatar
brinn committed
794
795
796
797
798
799
#endif
    }

    return (jint)status;
}

800
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dread__IIIII_3I
brinn's avatar
brinn committed
801
802
803
804
805
806
807
808
809
810
811
812
  (JNIEnv *env, jclass clss, jint dataset_id, jint mem_type_id, jint mem_space_id,
  jint file_space_id, jint xfer_plist_id, jintArray buf)
{
    herr_t status;
    jint *buffP;
    jboolean isCopy;

    if ( buf == NULL ) {
        h5nullArgument( env, "H5Dread:  buf is NULL");
        return -1;
    }
#ifdef __cplusplus
813
    buffP = env->GetPrimitiveArrayCritical(buf,&isCopy);
brinn's avatar
brinn committed
814
#else
815
    buffP = (*env)->GetPrimitiveArrayCritical(env,buf,&isCopy);
brinn's avatar
brinn committed
816
817
818
819
820
821
822
823
824
825
826
#endif
    if (buffP == NULL) {
        h5JNIFatalError( env, "H5Dread:  buf not pinned");
        return -1;
    }

    status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id,
        (hid_t)file_space_id, (hid_t)xfer_plist_id, buffP);

    if (status < 0) {
#ifdef __cplusplus
827
        env->ReleasePrimitiveArrayCritical(buf,buffP,JNI_ABORT);
brinn's avatar
brinn committed
828
#else
829
        (*env)->ReleasePrimitiveArrayCritical(env,buf,buffP,JNI_ABORT);
brinn's avatar
brinn committed
830
831
832
833
#endif
        h5libraryError(env);
    } else  {
#ifdef __cplusplus
834
        env->ReleasePrimitiveArrayCritical(buf,buffP,0);
brinn's avatar
brinn committed
835
#else
836
        (*env)->ReleasePrimitiveArrayCritical(env,buf,buffP,0);
brinn's avatar
brinn committed
837
838
839
840
841
842
843
#endif
    }

    return (jint)status;
}


844
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dread__IIIII_3J
brinn's avatar
brinn committed
845
846
847
848
849
850
851
852
853
854
855
856
  (JNIEnv *env, jclass clss, jint dataset_id, jint mem_type_id, jint mem_space_id,
  jint file_space_id, jint xfer_plist_id, jlongArray buf)
{
    herr_t status;
    jlong *buffP;
    jboolean isCopy;

    if ( buf == NULL ) {
        h5nullArgument( env, "H5Dread:  buf is NULL");
        return -1;
    }
#ifdef __cplusplus
857
    buffP = env->GetPrimitiveArrayCritical(buf,&isCopy);
brinn's avatar
brinn committed
858
#else
859
    buffP = (*env)->GetPrimitiveArrayCritical(env,buf,&isCopy);
brinn's avatar
brinn committed
860
861
862
863
864
865
866
867
868
869
870
#endif
    if (buffP == NULL) {
        h5JNIFatalError( env, "H5Dread:  buf not pinned");
        return -1;
    }

    status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id,
        (hid_t)file_space_id, (hid_t)xfer_plist_id, buffP);

    if (status < 0) {
#ifdef __cplusplus
871
        env->ReleasePrimitiveArrayCritical(buf,buffP,JNI_ABORT);
brinn's avatar
brinn committed
872
#else
873
        (*env)->ReleasePrimitiveArrayCritical(env,buf,buffP,JNI_ABORT);
brinn's avatar
brinn committed
874
875
876
877
#endif
        h5libraryError(env);
    } else  {
#ifdef __cplusplus
878
        env->ReleasePrimitiveArrayCritical(buf,buffP,0);
brinn's avatar
brinn committed
879
#else
880
        (*env)->ReleasePrimitiveArrayCritical(env,buf,buffP,0);
brinn's avatar
brinn committed
881
882
883
884
885
886
#endif
    }

    return (jint)status;
}

887
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dread__IIIII_3F
brinn's avatar
brinn committed
888
889
890
891
892
893
894
895
896
897
898
899
  (JNIEnv *env, jclass clss, jint dataset_id, jint mem_type_id, jint mem_space_id,
  jint file_space_id, jint xfer_plist_id, jfloatArray buf)
{
    herr_t status;
    jfloat *buffP;
    jboolean isCopy;

    if ( buf == NULL ) {
        h5nullArgument( env, "H5Dread:  buf is NULL");
        return -1;
    }
#ifdef __cplusplus
900
    buffP = env->GetPrimitiveArrayCritical(buf,&isCopy);
brinn's avatar
brinn committed
901
#else
902
    buffP = (*env)->GetPrimitiveArrayCritical(env,buf,&isCopy);
brinn's avatar
brinn committed
903
904
905
906
907
908
909
910
911
912
913
#endif
    if (buffP == NULL) {
        h5JNIFatalError( env, "H5Dread:  buf not pinned");
        return -1;
    }

    status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id,
        (hid_t)file_space_id, (hid_t)xfer_plist_id, buffP);

    if (status < 0) {
#ifdef __cplusplus
914
        env->ReleasePrimitiveArrayCritical(buf,buffP,JNI_ABORT);
brinn's avatar
brinn committed
915
#else
916
        (*env)->ReleasePrimitiveArrayCritical(env,buf,buffP,JNI_ABORT);
brinn's avatar
brinn committed
917
918
919
920
#endif
        h5libraryError(env);
    } else  {
#ifdef __cplusplus
921
        env->ReleasePrimitiveArrayCritical(buf,buffP,0);
brinn's avatar
brinn committed
922
#else
923
        (*env)->ReleasePrimitiveArrayCritical(env,buf,buffP,0);
brinn's avatar
brinn committed
924
925
926
927
928
929
#endif
    }

    return (jint)status;
}

930
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dread__IIIII_3D
brinn's avatar
brinn committed
931
932
933
934
935
936
937
938
939
940
941
942
  (JNIEnv *env, jclass clss, jint dataset_id, jint mem_type_id, jint mem_space_id,
  jint file_space_id, jint xfer_plist_id, jdoubleArray buf)
{
    herr_t status;
    jdouble *buffP;
    jboolean isCopy;

    if ( buf == NULL ) {
        h5nullArgument( env, "H5Dread:  buf is NULL");
        return -1;
    }
#ifdef __cplusplus
943
    buffP = env->GetPrimitiveArrayCritical(buf,&isCopy);
brinn's avatar
brinn committed
944
#else
945
    buffP = (*env)->GetPrimitiveArrayCritical(env,buf,&isCopy);
brinn's avatar
brinn committed
946
947
948
949
950
951
952
953
954
955
956
#endif
    if (buffP == NULL) {
        h5JNIFatalError( env, "H5Dread:  buf not pinned");
        return -1;
    }

    status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id,
        (hid_t)file_space_id, (hid_t)xfer_plist_id, buffP);

    if (status < 0) {
#ifdef __cplusplus
957
        env->ReleasePrimitiveArrayCritical(buf,buffP,JNI_ABORT);
brinn's avatar
brinn committed
958
#else
959
        (*env)->ReleasePrimitiveArrayCritical(env,buf,buffP,JNI_ABORT);
brinn's avatar
brinn committed
960
961
962
963
#endif
        h5libraryError(env);
    } else  {
#ifdef __cplusplus
964
        env->ReleasePrimitiveArrayCritical(buf,buffP,0);
brinn's avatar
brinn committed
965
#else
966
        (*env)->ReleasePrimitiveArrayCritical(env,buf,buffP,0);
brinn's avatar
brinn committed
967
968
969
970
971
972
#endif
    }

    return (jint)status;
}

973
JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_hdf5_hdf5lib_H5_H5Dread_1string
brinn's avatar
brinn committed
974
975
976
977
978
979
980
  (JNIEnv *env, jclass clss, jint dataset_id, jint mem_type_id, jint mem_space_id,
  jint file_space_id, jint xfer_plist_id, jobjectArray j_buf)
{
    herr_t status;
    jstring jstr;
    char *c_buf;
    char *cstr;
981
982
    char cterm;
    size_t str_len, i, n;
brinn's avatar
brinn committed
983
984
985
    
    c_buf = cstr = NULL;
    if ( j_buf == NULL) {
986
        h5nullArgument( env, "H5Dread_string:  buf is NULL");
brinn's avatar
brinn committed
987
988
989
990
991
        return -1;
    }

    n = (*env)->GetArrayLength(env, j_buf);
    if ( n<=0) {
992
        h5nullArgument( env, "H5Dread_string:  buf length <=0");
brinn's avatar
brinn committed
993
994
995
996
997
998
999
        return -1;
    }

    if ( (str_len = H5Tget_size((hid_t)mem_type_id)) <=0 ) {
        h5libraryError(env);
    }

1000
    /* Note: we need one additional character at the end of the buffer for the final '\0'. */
For faster browsing, not all history is shown. View entire blame