summaryrefslogtreecommitdiffstats
path: root/java/src/jni/h5gImp.c
blob: 42c042a5504ed59157a53103e5f361e7ad83d70e (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the COPYING file, which can be found at the root of the source code       *
 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
 * If you do not have access to either file, you may request a copy from     *
 * help@hdfgroup.org.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
 *  For details of the HDF libraries, see the HDF Documentation at:
 *    http://hdfgroup.org/HDF5/doc/
 *
 */

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hdf5.h"
#include "h5util.h"
#include "h5gImp.h"

extern JavaVM *jvm;

/*
 * Class:     hdf_hdf5lib_H5
 * Method:    _H5Gclose
 * Signature: (J)I
 */
JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5__1H5Gclose
    (JNIEnv *env, jclass clss, jlong group_id)
{
    herr_t retVal = -1;

    retVal =  H5Gclose((hid_t)group_id);
    if (retVal < 0)
        h5libraryError(env);

    return (jint)retVal;
} /* end Java_hdf_hdf5lib_H5__1H5Gclose */

/*
 * Create a java object of hdf.h5.structs.H5G_info_t
 * public class H5G_info_t {
 *   public H5G_STORAGE_TYPE  storage_type; // Type of storage for links in group
 *   public long     nlinks;       // Number of links in group
 *   public long     max_corder;   // Current max. creation order value for group
 *   public int      mounted;      // Whether group has a file mounted on it
 * }
 *
 */
jobject
create_H5G_info_t
    (JNIEnv *env, H5G_info_t group_info)
{
    jclass   cls;
    jboolean jmounted;
    jint     storage_type;
    jobject  obj = NULL;
    jfieldID fid_storage_type, fid_nlinks, fid_max_corder, fid_mounted;

    cls = ENVPTR->FindClass(ENVPAR "hdf/hdf5lib/structs/H5G_info_t");
    if (cls != NULL) {
        obj = ENVPTR->AllocObject(ENVPAR cls);
        if (obj != NULL) {
            if ((fid_storage_type = ENVPTR->GetFieldID(ENVPAR cls, "storage_type", "I")) != NULL) {
                if ((fid_nlinks = ENVPTR->GetFieldID(ENVPAR cls, "nlinks", "J")) != NULL) {
                    if ((fid_max_corder = ENVPTR->GetFieldID(ENVPAR cls, "max_corder", "J")) != NULL) {
                        if ((fid_mounted = ENVPTR->GetFieldID(ENVPAR cls, "mounted", "Z")) != NULL) {
                            jmounted = (group_info.mounted==0) ? JNI_FALSE : JNI_TRUE;
                            storage_type = (jint)group_info.storage_type;

                            ENVPTR->SetIntField(ENVPAR obj, fid_storage_type, (jint)storage_type);
                            ENVPTR->SetLongField(ENVPAR obj, fid_nlinks, (jlong)group_info.nlinks);
                            ENVPTR->SetLongField(ENVPAR obj, fid_max_corder, (jlong)group_info.max_corder);
                            ENVPTR->SetBooleanField(ENVPAR obj, fid_mounted, jmounted);
                        }
                    }
                }
            }
        }
    }
    return obj;
} /* end create_H5G_info_t */

/*
 * Class:     hdf_hdf5lib_H5
 * Method:    _H5Gcreate2
 * Signature: (JLjava/lang/String;JJJ)J
 */
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5__1H5Gcreate2
    (JNIEnv *env, jclass clss, jlong loc_id, jstring name,
          jlong link_plist_id, jlong create_plist_id, jlong access_plist_id)
{
    hid_t       group_id = -1;
    const char *gName;

    PIN_JAVA_STRING(name, gName);
    if (gName != NULL) {
        group_id = H5Gcreate2((hid_t)loc_id, gName, (hid_t)link_plist_id, (hid_t)create_plist_id, (hid_t)access_plist_id );

        UNPIN_JAVA_STRING(name, gName);
        if (group_id < 0)
            h5libraryError(env);
    }

    return (jlong)group_id;
} /* end Java_hdf_hdf5lib_H5__1H5Gcreate2 */

/*
 * 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 Java_hdf_hdf5lib_H5__1H5Gcreate_1anon */

/*
 * Class:     hdf_hdf5lib_H5
 * Method:    _H5Gopen2
 * Signature: (JLjava/lang/String;J)J
 */
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5__1H5Gopen2
    (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_plist_id)
{
    hid_t group_id = -1;
    const char *gName;

    PIN_JAVA_STRING(name, gName);
    if (gName != NULL) {
        group_id = H5Gopen2((hid_t)loc_id, gName, (hid_t)access_plist_id );

        UNPIN_JAVA_STRING(name, gName);

        if (group_id < 0)
            h5libraryError(env);
    }

    return (jlong)group_id;
} /* end Java_hdf_hdf5lib_H5__1H5Gopen2 */


/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Gget_create_plist
 * Signature: (J)J
 */
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5_H5Gget_1create_1plist
    (JNIEnv *env, jclass cls, jlong loc_id)
{
    hid_t plist_id = H5Gget_create_plist((hid_t)loc_id);

    if (plist_id < 0)
        h5libraryError(env);

    return (jlong)plist_id;
} /* end Java_hdf_hdf5lib_H5_H5Gget_1create_1plist */

/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Gget_info
 * Signature: (J)Lhdf/hdf5lib/structs/H5G_info_t;
 */
JNIEXPORT jobject JNICALL
Java_hdf_hdf5lib_H5_H5Gget_1info
    (JNIEnv *env, jclass cls, jlong loc_id)
{
    jobject    obj = NULL;
    H5G_info_t group_info;

    if (H5Gget_info((hid_t)loc_id, &group_info) < 0)
        h5libraryError(env);
    else
        obj = create_H5G_info_t(env, group_info);

    return obj;
} /* end Java_hdf_hdf5lib_H5_H5Gget_1info */

/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Gget_info_by_name
 * Signature: (JLjava/lang/String;J)Lhdf/hdf5lib/structs/H5G_info_t;
 */
JNIEXPORT jobject JNICALL
Java_hdf_hdf5lib_H5_H5Gget_1info_1by_1name
    (JNIEnv *env, jclass cls, jlong loc_id, jstring name, jlong lapl_id)
{
    jobject     obj = NULL;
    herr_t      ret_val = -1;
    const char *gName;
    H5G_info_t  group_info;

    PIN_JAVA_STRING(name, gName);
    if (gName != NULL) {
        ret_val = H5Gget_info_by_name((hid_t)loc_id, gName, &group_info, (hid_t)lapl_id);

        UNPIN_JAVA_STRING(name, gName);

        if (ret_val < 0)
            h5libraryError(env);
        else
            obj = create_H5G_info_t(env, group_info);
    }

    return obj;
} /* end Java_hdf_hdf5lib_H5_H5Gget_1info_1by_1name */

/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Gget_info_by_idx
 * Signature: (JLjava/lang/String;IIJJ)Lhdf/hdf5lib/structs/H5G_info_t;
 */
JNIEXPORT jobject JNICALL
Java_hdf_hdf5lib_H5_H5Gget_1info_1by_1idx
    (JNIEnv *env, jclass cls, jlong loc_id, jstring name, jint index_type,
          jint order, jlong n, jlong lapl_id)
{
    jobject         obj = NULL;
    herr_t          ret_val = -1;
    const char     *gName;
    H5G_info_t      group_info;
    H5_index_t      cindex_type = (H5_index_t)index_type;
    H5_iter_order_t corder = (H5_iter_order_t)order;

    PIN_JAVA_STRING(name, gName);
    if (gName != NULL) {
        ret_val = H5Gget_info_by_idx((hid_t)loc_id, gName, cindex_type,
                corder, (hsize_t)n, &group_info, (hid_t)lapl_id);

        UNPIN_JAVA_STRING(name, gName);

        if (ret_val < 0)
            h5libraryError(env);
        else
            obj = create_H5G_info_t(env, group_info);
    }

    return obj;
} /* end Java_hdf_hdf5lib_H5_H5Gget_1info_1by_1idx */

/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Gflush
 * Signature: (J)V
 */
JNIEXPORT void JNICALL
Java_hdf_hdf5lib_H5_H5Gflush
    (JNIEnv *env, jclass clss, jlong loc_id)
{
    if (H5Gflush((hid_t)loc_id) < 0)
        h5libraryError(env);
} /* end Java_hdf_hdf5lib_H5_H5Gflush */

/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Grefresh
 * Signature: (J)V
 */
JNIEXPORT void JNICALL
Java_hdf_hdf5lib_H5_H5Grefresh
    (JNIEnv *env, jclass clss, jlong loc_id)
{
    if (H5Grefresh((hid_t)loc_id) < 0)
        h5libraryError(env);
} /* end Java_hdf_hdf5lib_H5_H5Grefresh */



#ifdef __cplusplus
} /* end extern "C" */
#endif /* __cplusplus */