NeXusJavaBindings  1
 All Classes Namespaces Files Functions Variables Typedefs Macros Pages
NexusFile.c
Go to the documentation of this file.
1 /*
2  This is the implementation file for the native methods used by the NeXus
3  Java API.
4 
5  Mark Koennecke, 2000 -- 2011
6 
7  IMPLEMENTATION NOTES
8 
9  The NAPI uses a handle type for hiding the NeXus file datastructure.
10  This handle is essentially a pointer. Now, dealing with pointers in
11  Java is hideous. Usually a a pointer is just an integer but depending
12  on the system this can be 4 byte, 8 byte or other. In order to get rid of
13  this problem we manage the pointers ourselves. The handle module maps
14  integer handles to the NeXus handle for us. All the java code sees is
15  the integer. But any routine in here has to retrieve the NXhandle for
16  the integer first before it can do useful work.
17 
18 */
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <assert.h>
22 #include <string.h>
24 #include <napi.h>
25 #include "handle.h"
26 
27 #ifdef WIN32
28 /* commented away for MINGW
29 #include <mapiwin.h>
30 */
31 #endif
32 
33 /* #define DEBUG */
34 
35 static JavaVM *jvm; // Global variable
36 
37 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
38  JNIEnv *env;
39  jclass nexusException;
40 
41  jint ret = (*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_1);
42 
43  assert(ret == JNI_OK);
44 
45  jvm = vm;
46 
47  nexusException = (*env)->FindClass(env,"org/nexusformat/NexusException");
48  if (nexusException == NULL) {
49  fprintf(stderr, "cannot find NexusException - this will not work. Terminating.");
50  assert(nexusException);
51  }
52 
53  return JNI_VERSION_1_1;
54 }
55 
56 /*---------------------------------------------------------------------------
57  ERROR TREATMENT
58 
59  The NAPI posts any errors to a customisable function.
60  We construct and throw a NexusException with the message received.
61  --------------------------------------------------------------------------*/
62 static void JapiError(void *pData, char *text) {
63  JNIEnv *env = pData;
64  jclass nexusException;
65 
66 #ifdef DEBUG
67  fprintf(stderr,"JapiError called with: %s\n", text);
68 #endif
69 
70  /* ignore env passed in seems safer */
71  (*jvm)->AttachCurrentThread (jvm, (void **) &env, NULL);
72 
73  if (env == NULL) {
74  // if there is no thread environment we do not need to throw an exception
75  return;
76  }
77 
78  // Find and store the NexusException class for use in JapiError
79  nexusException = (*env)->FindClass(env,"org/nexusformat/NexusException");
80  (*env)->ThrowNew(env, nexusException, text);
81 }
82 
83 /*------------------------------------------------------------------------
84  init or NXopen
85 -------------------------------------------------------------------------*/
86 JNIEXPORT jint JNICALL Java_org_nexusformat_NexusFile_init
87  (JNIEnv *env, jobject obj, jstring filename, jint access)
88 {
89  NXhandle handle;
90  char *fileName;
91  int iRet;
92 
93  /* set error handler */
94  NXMSetTError(env,JapiError);
95 
96  /* extract the filename as a C char* */
97  fileName = (char *) (*env)->GetStringUTFChars(env, filename, 0);
98 
99  /* call NXopen */
100 #ifdef DEBUG
101  fprintf(stderr,"Calling NXopen on %s, with %d\n", fileName, access);
102 #endif
103  iRet = NXopen(fileName,access,&handle);
104 
105 #ifdef DEBUG
106  fprintf(stderr,"Handle allocated for %s\n", fileName);
107 #endif
108 
109  /* release the filename string */
110  (*env)->ReleaseStringUTFChars(env,filename, fileName);
111 
112  /* error return */
113  if(iRet != NX_OK)
114  {
115  return -1;
116  }
117 
118  /* convert the NXhandle to a integer handle */
119  return HHMakeHandle(handle);
120 }
121 /*-----------------------------------------------------------------------
122  nxflush
123 ------------------------------------------------------------------------*/
124 JNIEXPORT jint JNICALL Java_org_nexusformat_NexusFile_nxflush
125  (JNIEnv *env, jobject obj, jint handle)
126 {
127  NXhandle nxhandle;
128  int iRet;
129 
130  /* set error handler */
131  NXMSetTError(env,JapiError);
132 
133  /* exchange the Java handler to a NXhandle */
134  nxhandle = (NXhandle)HHGetPointer(handle);
135 
136  /* kill handle */
137  HHRemoveHandle(handle);
138 
139  /* call NXflush */
140  iRet = NXflush(&nxhandle);
141 
142  /* error return */
143  if(iRet != NX_OK)
144  {
145  return -1;
146  }
147 
148  /* convert the NXhandle to a integer handle */
149  return HHMakeHandle(nxhandle);
150 }
151 /*-----------------------------------------------------------------------
152  close or NXclose
153 ------------------------------------------------------------------------*/
154 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_close
155  (JNIEnv *env, jobject obj, jint handle)
156 {
157  NXhandle nxhandle;
158  int iRet;
159 
160  /* set error handler */
161  NXMSetTError(env,JapiError);
162 
163  /* exchange the Java handler to a NXhandle */
164  nxhandle = (NXhandle)HHGetPointer(handle);
165 #ifdef DEBUG
166  fprintf(stderr,"closing handle %d, nxhandle %d\n", handle, nxhandle);
167 #endif
168 
169  iRet = NXclose(&nxhandle);
170 
171  /* kill handle */
172  HHRemoveHandle(handle);
173 
174  if (iRet != NX_OK) {
175  JapiError(env, "NXclose failed");
176  }
177 }
178 /*------------------------------------------------------------------------
179  nxmakegroup
180 --------------------------------------------------------------------------*/
181 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxmakegroup
182  (JNIEnv *env, jobject obj, jint handle, jstring name, jstring nxclass)
183 {
184  char *Name, *Nxclass;
185  NXhandle nxhandle;
186  int iRet;
187 
188  /* set error handler */
189  NXMSetTError(env,JapiError);
190 
191  /* exchange the Java handler to a NXhandle */
192  nxhandle = (NXhandle)HHGetPointer(handle);
193 
194  /* extract the name and class to char * */
195  Name = (char *) (*env)->GetStringUTFChars(env,name,0);
196  Nxclass = (char *) (*env)->GetStringUTFChars(env,nxclass,0);
197 
198  iRet = NXmakegroup(nxhandle, Name, Nxclass);
199 
200  /* release strings */
201  (*env)->ReleaseStringUTFChars(env,name, Name);
202  (*env)->ReleaseStringUTFChars(env,nxclass, Nxclass);
203 
204  if (iRet != NX_OK) {
205  JapiError(env, "NXmakegroup failed");
206  }
207 }
208 /*------------------------------------------------------------------------
209  nxopengroup
210 --------------------------------------------------------------------------*/
211 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxopengroup
212  (JNIEnv *env, jobject obj, jint handle, jstring name, jstring nxclass)
213 {
214  char *Name, *Nxclass;
215  NXhandle nxhandle;
216  int iRet;
217 
218  /* set error handler */
219  NXMSetTError(env,JapiError);
220 
221  /* exchange the Java handler to a NXhandle */
222  nxhandle = (NXhandle)HHGetPointer(handle);
223 
224  /* extract the name and class to char * */
225  Name = (char *) (*env)->GetStringUTFChars(env,name,0);
226  Nxclass = (char *) (*env)->GetStringUTFChars(env,nxclass,0);
227 
228  iRet = NXopengroup(nxhandle, Name, Nxclass);
229 
230 #ifdef DEBUG
231  if(iRet != NX_OK)
232  {
233  fprintf(stderr,"Cleanup code called after raising Exception\n");
234  }
235 #endif
236  /* release strings */
237  (*env)->ReleaseStringUTFChars(env,name, Name);
238  (*env)->ReleaseStringUTFChars(env,nxclass, Nxclass);
239 
240  if (iRet != NX_OK) {
241  JapiError(env, "NXopengroup failed");
242  }
243 }
244 /*------------------------------------------------------------------------
245  nxopenpath
246 --------------------------------------------------------------------------*/
247 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxopenpath
248  (JNIEnv *env, jobject obj, jint handle, jstring path)
249 {
250  char *nxpath;
251  NXhandle nxhandle;
252  int iRet;
253 
254  /* set error handler */
255  NXMSetTError(env,JapiError);
256 
257  /* exchange the Java handler to a NXhandle */
258  nxhandle = (NXhandle)HHGetPointer(handle);
259 
260  /* extract the name and class to char * */
261  nxpath = (char *) (*env)->GetStringUTFChars(env,path,0);
262 
263  iRet = NXopenpath(nxhandle, nxpath);
264 
265 #ifdef DEBUG
266  if(iRet != NX_OK)
267  {
268  fprintf(stderr,"Cleanup code called after raising Exception\n");
269  }
270 #endif
271  /* release strings */
272  (*env)->ReleaseStringUTFChars(env,path, nxpath);
273 
274  if (iRet != NX_OK) {
275  JapiError(env, "NXopenpath failed");
276  }
277 }
278 /*------------------------------------------------------------------------
279  nxopengrouppath
280 --------------------------------------------------------------------------*/
282  (JNIEnv *env, jobject obj, jint handle, jstring path)
283 {
284  char *nxpath;
285  NXhandle nxhandle;
286  int iRet;
287 
288  /* set error handler */
289  NXMSetTError(env,JapiError);
290 
291  /* exchange the Java handler to a NXhandle */
292  nxhandle = (NXhandle)HHGetPointer(handle);
293 
294  /* extract the name and class to char * */
295  nxpath = (char *) (*env)->GetStringUTFChars(env,path,0);
296 
297  iRet = NXopengrouppath(nxhandle, nxpath);
298 
299 #ifdef DEBUG
300  if(iRet != NX_OK)
301  {
302  fprintf(stderr,"Cleanup code called after raising Exception\n");
303  }
304 #endif
305  /* release strings */
306  (*env)->ReleaseStringUTFChars(env,path, nxpath);
307 
308  if (iRet != NX_OK) {
309  JapiError(env, "NXopengrouppath failed");
310  }
311 }
312 /*-----------------------------------------------------------------------*/
313 JNIEXPORT jstring JNICALL Java_org_nexusformat_NexusFile_nxgetpath
314  (JNIEnv *env, jobject obj, jint handle)
315 {
316  NXhandle nxhandle;
317  int iRet;
318  char path[1024];
319 
320  /* set error handler */
321  NXMSetTError(env,JapiError);
322 
323  /* exchange the Java handler to a NXhandle */
324  nxhandle = (NXhandle)HHGetPointer(handle);
325 
326  if (NXgetpath(nxhandle, path,1024) != NX_OK) {
327  JapiError(env, "NXgetpath failed");
328  }
329 
330  return (*env)->NewStringUTF(env,path);
331 }
332 
333 /*------------------------------------------------------------------------
334  nxclosegroup
335 --------------------------------------------------------------------------*/
336 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxclosegroup
337  (JNIEnv *env, jobject obj, jint handle)
338 {
339  NXhandle nxhandle;
340  int iRet;
341 
342  /* set error handler */
343  NXMSetTError(env,JapiError);
344 
345  /* exchange the Java handler to a NXhandle */
346  nxhandle = (NXhandle)HHGetPointer(handle);
347 
348  if (NXclosegroup(nxhandle) != NX_OK) {
349  JapiError(env, "NXclosegroup failed");
350  }
351 }
352 /*------------------------------------------------------------------------
353  nxmakedata
354 --------------------------------------------------------------------------*/
355 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxmakedata
356  (JNIEnv *env, jobject obj, jint handle, jstring name, jint type,
357  jint rank, jintArray dim)
358 {
359  char *Name;
360  NXhandle nxhandle;
361  jint *iDim;
362  int iRet;
363 
364  /* set error handler */
365  NXMSetTError(env,JapiError);
366 
367  /* exchange the Java handler to a NXhandle */
368  nxhandle = (NXhandle)HHGetPointer(handle);
369 
370  /* extract the name and class to char * */
371  Name = (char *) (*env)->GetStringUTFChars(env,name,0);
372 
373  /* access dim array */
374  iDim = (*env)->GetIntArrayElements(env,dim,0);
375 
376  iRet = NXmakedata(nxhandle,Name,type,rank,iDim);
377 
378  /* clean up */
379  (*env)->ReleaseStringUTFChars(env,name, Name);
380  (*env)->ReleaseIntArrayElements(env,dim,iDim,0);
381 
382  if (iRet != NX_OK) {
383  JapiError(env, "NXmakedata failed");
384  }
385 }
386 /*------------------------------------------------------------------------
387  nxmakedata64
388 --------------------------------------------------------------------------*/
389 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxmakedata64
390  (JNIEnv *env, jobject obj, jint handle, jstring name, jint type,
391  jint rank, jlongArray dim)
392 {
393  char *Name;
394  NXhandle nxhandle;
395  jlong *iDim;
396  int iRet;
397 
398  /* set error handler */
399  NXMSetTError(env,JapiError);
400 
401  /* exchange the Java handler to a NXhandle */
402  nxhandle = (NXhandle)HHGetPointer(handle);
403 
404  /* extract the name and class to char * */
405  Name = (char *) (*env)->GetStringUTFChars(env,name,0);
406 
407  /* access dim array */
408  iDim = (*env)->GetLongArrayElements(env,dim,0);
409 
410  iRet = NXmakedata64(nxhandle,Name,type,rank,iDim);
411 
412  /* clean up */
413  (*env)->ReleaseStringUTFChars(env,name, Name);
414  (*env)->ReleaseLongArrayElements(env,dim,iDim,0);
415 
416  if (iRet != NX_OK) {
417  JapiError(env, "NXmakedata failed");
418  }
419 }
420 /*-----------------------------------------------------------------------
421  nxcompmakedata
422 -------------------------------------------------------------------------*/
424  (JNIEnv *env, jobject obj, jint handle, jstring name, jint type,
425  jint rank, jintArray dim, jint compression_type, jintArray chunk)
426 {
427  char *Name;
428  NXhandle nxhandle;
429  jint *iDim, *iChunk;
430  int iRet;
431 
432  /* set error handler */
433  NXMSetTError(env,JapiError);
434 
435  /* exchange the Java handler to a NXhandle */
436  nxhandle = (NXhandle)HHGetPointer(handle);
437 
438  /* extract the name and class to char * */
439  Name = (char *) (*env)->GetStringUTFChars(env,name,0);
440 
441  /* access dim array */
442  iDim = (*env)->GetIntArrayElements(env,dim,0);
443 
444  /* access the chunksize array */
445  iChunk = (*env)->GetIntArrayElements(env,chunk,0);
446 
447  iRet = NXcompmakedata(nxhandle,Name,type,rank,iDim,
448  compression_type,iChunk);
449 
450  /* clean up */
451  (*env)->ReleaseStringUTFChars(env,name, Name);
452  (*env)->ReleaseIntArrayElements(env,dim,iDim,0);
453  (*env)->ReleaseIntArrayElements(env,chunk,iChunk,0);
454 
455  if (iRet != NX_OK) {
456  JapiError(env, "NXcompmakedata failed");
457  }
458 }
459 
460 /*-----------------------------------------------------------------------
461  nxcompmakedata64
462 -------------------------------------------------------------------------*/
464  (JNIEnv *env, jobject obj, jint handle, jstring name, jint type,
465  jint rank, jlongArray dim, jint compression_type, jlongArray chunk)
466 {
467  char *Name;
468  NXhandle nxhandle;
469  jlong *iDim, *iChunk;
470  int iRet;
471 
472  /* set error handler */
473  NXMSetTError(env,JapiError);
474 
475  /* exchange the Java handler to a NXhandle */
476  nxhandle = (NXhandle)HHGetPointer(handle);
477 
478  /* extract the name and class to char * */
479  Name = (char *) (*env)->GetStringUTFChars(env,name,0);
480 
481  /* access dim array */
482  iDim = (*env)->GetLongArrayElements(env,dim,0);
483 
484  /* access the chunksize array */
485  iChunk = (*env)->GetLongArrayElements(env,chunk,0);
486 
487  iRet = NXcompmakedata64(nxhandle,Name,type,rank,iDim,
488  compression_type,iChunk);
489 
490  /* clean up */
491  (*env)->ReleaseStringUTFChars(env,name, Name);
492  (*env)->ReleaseLongArrayElements(env,dim,iDim,0);
493  (*env)->ReleaseLongArrayElements(env,chunk,iChunk,0);
494 
495  if (iRet != NX_OK) {
496  JapiError(env, "NXcompmakedata failed");
497  }
498 }
499 
500 /*------------------------------------------------------------------------
501  nxopendata
502 --------------------------------------------------------------------------*/
503 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxopendata
504  (JNIEnv *env, jobject obj, jint handle , jstring name)
505 {
506  char *Name;
507  NXhandle nxhandle;
508  int iRet;
509 
510  /* set error handler */
511  NXMSetTError(env,JapiError);
512 
513  /* exchange the Java handler to a NXhandle */
514  nxhandle = (NXhandle)HHGetPointer(handle);
515 
516  /* extract the name and class to char * */
517  Name = (char *) (*env)->GetStringUTFChars(env,name,0);
518 
519  iRet = NXopendata(nxhandle,Name);
520 
521  /* clean up */
522  (*env)->ReleaseStringUTFChars(env,name, Name);
523 
524  if (iRet != NX_OK) {
525  JapiError(env, "NXopendata failed");
526  }
527 }
528 /*------------------------------------------------------------------------
529  nxclosedata
530 --------------------------------------------------------------------------*/
531 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxclosedata
532  (JNIEnv *env, jobject obj, jint handle)
533 {
534  NXhandle nxhandle;
535  int iRet;
536 
537  /* set error handler */
538  NXMSetTError(env,JapiError);
539 
540  /* exchange the Java handler to a NXhandle */
541  nxhandle = (NXhandle)HHGetPointer(handle);
542 
543  if (NXclosedata(nxhandle) != NX_OK) {
544  JapiError(env, "NXclosedata failed");
545  }
546 }
547 /*------------------------------------------------------------------------
548  nxcompress
549 --------------------------------------------------------------------------*/
550 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxcompress
551  (JNIEnv *env, jobject obj, jint handle , jint comp_type)
552 {
553  NXhandle nxhandle;
554  int iRet;
555 
556  /* set error handler */
557  NXMSetTError(env,JapiError);
558 
559  /* exchange the Java handler to a NXhandle */
560  nxhandle = (NXhandle)HHGetPointer(handle);
561 
562 #ifdef DEBUG
563  fprintf(stderr,"Compressing at %d with type %d\n", nxhandle, comp_type);
564 #endif
565 
566  if (NXcompress(nxhandle,comp_type) != NX_OK) {
567  JapiError(env, "NXcompress failed");
568  }
569 }
570 /*------------------------------------------------------------------------
571  nxputdata
572 --------------------------------------------------------------------------*/
573 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxputdata
574  (JNIEnv *env, jobject obj, jint handle, jbyteArray data)
575 {
576  NXhandle nxhandle;
577  jbyte *bdata;
578  int iRet;
579 
580  /* set error handler */
581  NXMSetTError(env,JapiError);
582 
583  /* exchange the Java handler to a NXhandle */
584  nxhandle = (NXhandle)HHGetPointer(handle);
585 
586  /* convert jbteArray to C byte array */
587  bdata = (*env)->GetByteArrayElements(env,data,0);
588 
589  iRet = NXputdata(nxhandle, bdata);
590 
591  /* cleanup */
592  (*env)->ReleaseByteArrayElements(env,data,bdata,0);
593  if(iRet != NX_OK)
594  {
595 #ifdef DEBUG
596  HEprint(stderr,0);
597 #else
598  JapiError(env, "NXputdata failed");
599 #endif
600  }
601 }
602 /*------------------------------------------------------------------------
603  nxputslab
604 --------------------------------------------------------------------------*/
605 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxputslab
606  (JNIEnv *env, jobject obj, jint handle, jbyteArray data,
607  jintArray start, jintArray end)
608 {
609  NXhandle nxhandle;
610  jbyte *bdata;
611  jint *iStart, *iEnd;
612  int iRet;
613 
614  /* set error handler */
615  NXMSetTError(env,JapiError);
616 
617  /* exchange the Java handler to a NXhandle */
618  nxhandle = (NXhandle)HHGetPointer(handle);
619 
620  /* convert arrays to C types */
621  bdata = (*env)->GetByteArrayElements(env,data,0);
622  iStart = (*env)->GetIntArrayElements(env,start,0);
623  iEnd = (*env)->GetIntArrayElements(env,end,0);
624 
625 
626  iRet = NXputslab(nxhandle, bdata, iStart, iEnd);
627 
628  /* cleanup */
629  (*env)->ReleaseByteArrayElements(env,data,bdata,0);
630  (*env)->ReleaseIntArrayElements(env,start,iStart,0);
631  (*env)->ReleaseIntArrayElements(env,end,iEnd,0);
632 
633  if (iRet != NX_OK) {
634  JapiError(env, "NXputslab failed");
635  }
636 }
637 /*------------------------------------------------------------------------
638  nxputslab64
639 --------------------------------------------------------------------------*/
640 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxputslab64
641  (JNIEnv *env, jobject obj, jint handle, jbyteArray data,
642  jlongArray start, jlongArray end)
643 {
644  NXhandle nxhandle;
645  jbyte *bdata;
646  jlong *iStart, *iEnd;
647  int iRet;
648 
649  /* set error handler */
650  NXMSetTError(env,JapiError);
651 
652  /* exchange the Java handler to a NXhandle */
653  nxhandle = (NXhandle)HHGetPointer(handle);
654 
655  /* convert arrays to C types */
656  bdata = (*env)->GetByteArrayElements(env,data,0);
657  iStart = (*env)->GetLongArrayElements(env,start,0);
658  iEnd = (*env)->GetLongArrayElements(env,end,0);
659 
660 
661  iRet = NXputslab64(nxhandle, bdata, iStart, iEnd);
662 
663  /* cleanup */
664  (*env)->ReleaseByteArrayElements(env,data,bdata,0);
665  (*env)->ReleaseLongArrayElements(env,start,iStart,0);
666  (*env)->ReleaseLongArrayElements(env,end,iEnd,0);
667 
668  if (iRet != NX_OK) {
669  JapiError(env, "NXputslab failed");
670  }
671 }
672 /*------------------------------------------------------------------------
673  nxputattr
674 --------------------------------------------------------------------------*/
675 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxputattr
676  (JNIEnv *env, jobject obj, jint handle , jstring name,
677  jbyteArray data, jint type)
678 {
679  NXhandle nxhandle;
680  jbyte *bdata;
681  char *Name;
682  int iRet, iDataLen, div = 1;
683 
684  /* set error handler */
685  NXMSetTError(env,JapiError);
686 
687  /* exchange the Java handler to a NXhandle */
688  nxhandle = (NXhandle)HHGetPointer(handle);
689 
690  /* convert java types to C types*/
691  bdata = (*env)->GetByteArrayElements(env,data,0);
692  iDataLen = (*env)->GetArrayLength(env,data);
693  switch(type)
694  {
695  case NX_INT8:
696  case NX_UINT8:
697  case NX_CHAR:
698  div = 1;
699  break;
700  case NX_UINT16:
701  case NX_INT16:
702  div = 2;
703  break;
704  case NX_INT32:
705  case NX_UINT32:
706  case NX_FLOAT32:
707  div = 4;
708  break;
709  case NX_FLOAT64:
710  case NX_INT64:
711  case NX_UINT64:
712  div = 8;
713  break;
714  default:
715  JapiError(env, "Bad data type in NXputattr");
716  return;
717  }
718  iDataLen /= div;
719  Name = (char *) (*env)->GetStringUTFChars(env,name,0);
720 
721  iRet = NXputattr(nxhandle,Name, bdata, iDataLen, type);
722 
723  /* cleanup */
724  (*env)->ReleaseByteArrayElements(env,data,bdata,0);
725  (*env)->ReleaseStringUTFChars(env,name, Name);
726 
727  if (iRet != NX_OK) {
728  JapiError(env, "NXputattr failed");
729  }
730 }
731 /*------------------------------------------------------------------------
732  nxgetdata
733 --------------------------------------------------------------------------*/
734 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxgetdata
735  (JNIEnv *env, jobject obj, jint handle, jbyteArray data)
736 {
737  NXhandle nxhandle;
738  jbyte *bdata;
739  int iRet;
740 
741  /* set error handler */
742  NXMSetTError(env,JapiError);
743 
744  /* exchange the Java handler to a NXhandle */
745  nxhandle = (NXhandle)HHGetPointer(handle);
746 
747  /* convert jbteArray to C byte array */
748  bdata = (*env)->GetByteArrayElements(env,data,0);
749 
750  iRet = NXgetdata(nxhandle, bdata);
751 
752  /* cleanup */
753  (*env)->ReleaseByteArrayElements(env,data,bdata,0);
754  if(iRet != NX_OK)
755  {
756 #ifdef DEBUG
757  HEprint(stderr,0);
758 #else
759  JapiError(env, "NXgetdata failed");
760 #endif
761  }
762 }
763 /*------------------------------------------------------------------------
764  nxgetslab
765 --------------------------------------------------------------------------*/
766 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxgetslab
767  (JNIEnv *env, jobject obj, jint handle, jintArray start,
768  jintArray end, jbyteArray data)
769 {
770  NXhandle nxhandle;
771  jbyte *bdata;
772  jint *iStart, *iEnd;
773  int iRet;
774 
775  /* set error handler */
776  NXMSetTError(env,JapiError);
777 
778  /* exchange the Java handler to a NXhandle */
779  nxhandle = (NXhandle)HHGetPointer(handle);
780 
781  /* convert arrays to C types */
782  bdata = (*env)->GetByteArrayElements(env,data,0);
783  iStart = (*env)->GetIntArrayElements(env,start,0);
784  iEnd = (*env)->GetIntArrayElements(env,end,0);
785 
786  iRet = NXgetslab(nxhandle, bdata, iStart, iEnd);
787 
788  /* cleanup */
789  (*env)->ReleaseByteArrayElements(env,data,bdata,0);
790  (*env)->ReleaseIntArrayElements(env,start,iStart,0);
791  (*env)->ReleaseIntArrayElements(env,end,iEnd,0);
792 
793  if (iRet != NX_OK) {
794  JapiError(env, "NXgetslab failed");
795  }
796 }
797 /*------------------------------------------------------------------------
798  nxgetslab64
799 --------------------------------------------------------------------------*/
800 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxgetslab64
801  (JNIEnv *env, jobject obj, jint handle, jlongArray start,
802  jlongArray end, jbyteArray data)
803 {
804  NXhandle nxhandle;
805  jbyte *bdata;
806  jlong *iStart, *iEnd;
807  int iRet;
808 
809  /* set error handler */
810  NXMSetTError(env,JapiError);
811 
812  /* exchange the Java handler to a NXhandle */
813  nxhandle = (NXhandle)HHGetPointer(handle);
814 
815  /* convert arrays to C types */
816  bdata = (*env)->GetByteArrayElements(env,data,0);
817  iStart = (*env)->GetLongArrayElements(env,start,0);
818  iEnd = (*env)->GetLongArrayElements(env,end,0);
819 
820  iRet = NXgetslab64(nxhandle, bdata, iStart, iEnd);
821 
822  /* cleanup */
823  (*env)->ReleaseByteArrayElements(env,data,bdata,0);
824  (*env)->ReleaseLongArrayElements(env,start,iStart,0);
825  (*env)->ReleaseLongArrayElements(env,end,iEnd,0);
826 
827  if (iRet != NX_OK) {
828  JapiError(env, "NXgetslab failed");
829  }
830 }
831 /*------------------------------------------------------------------------
832  nxgetattr
833 --------------------------------------------------------------------------*/
834 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxgetattr
835  (JNIEnv *env, jobject obj, jint handle, jstring name,
836  jbyteArray data, jintArray args)
837 {
838  NXhandle nxhandle;
839  jbyte *bdata;
840  char *Name;
841  int iRet;
842  jint *iargs;
843  int iLen, iType;
844 
845  /* set error handler */
846  NXMSetTError(env,JapiError);
847 
848  /* exchange the Java handler to a NXhandle */
849  nxhandle = (NXhandle)HHGetPointer(handle);
850 
851  /* convert java types to C types*/
852  bdata = (*env)->GetByteArrayElements(env,data,0);
853  Name = (char *) (*env)->GetStringUTFChars(env,name,0);
854  iargs = (*env)->GetIntArrayElements(env,args,0);
855 #ifdef DEBUG
856  fprintf(stderr,"nxgetattr converted types \n");
857 #endif
858 
859  iLen = iargs[0];
860  iType = iargs[1];
861 #ifdef DEBUG
862  fprintf(stderr,"nxgetattr: iLen %d, iType: %d\n",iLen, iType);
863 #endif
864 
865  iRet = NXgetattr(nxhandle, Name, bdata, &iLen, &iType);
866  iargs[0] = iLen;
867  iargs[1] = iType;
868 #ifdef DEBUG
869  fprintf(stderr,"nxgetattr cleaning up \n");
870 #endif
871 
872  /* cleanup */
873  (*env)->ReleaseByteArrayElements(env,data,bdata,0);
874  (*env)->ReleaseStringUTFChars(env,name, Name);
875  (*env)->ReleaseIntArrayElements(env,args,iargs,0);
876 
877  if (iRet != NX_OK) {
878  JapiError(env, "NXgetattr failed");
879  }
880 }
881 /*------------------------------------------------------------------------
882  nxgetgroupid
883 --------------------------------------------------------------------------*/
884 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxgetgroupid
885  (JNIEnv *env, jobject obj, jint handle, jobject linki)
886 {
887  NXhandle nxhandle;
888  NXlink myLink;
889  int iRet;
890  jclass cls;
891  jfieldID fid;
892  jstring jstr;
893 
894  /* set error handler */
895  NXMSetTError(env,JapiError);
896 
897  /* exchange the Java handler to a NXhandle */
898  nxhandle = (NXhandle)HHGetPointer(handle);
899 
900  iRet = NXgetgroupID(nxhandle, &myLink);
901  if(iRet == NX_OK)
902  {
903  /* put the link info from our link structure into the object */
904  cls = (*env)->GetObjectClass(env, linki);
905  if(cls == NULL)
906  {
907  JapiError(env,
908  "ERROR: failed to locate class in nxgetgroupid");
909  return;
910  }
911  fid = (*env)->GetFieldID(env,cls,"tag","I");
912  if(fid == 0)
913  {
914  JapiError(env,
915  "ERROR: failed to locate fieldID in nxgetgroupid");
916  return;
917  }
918  (*env)->SetIntField(env,linki,fid,myLink.iTag);
919 
920  fid = (*env)->GetFieldID(env,cls,"ref","I");
921  if(fid == 0)
922  {
923  JapiError(env,
924  "ERROR: failed to locate fieldID in nxgetgroupid");
925  return;
926  }
927  (*env)->SetIntField(env,linki,fid,myLink.iRef);
928 
929 #ifdef HDF5
930  /*
931  set HDF-5 String variables
932  */
933  fid = (*env)->GetFieldID(env,cls,"targetPath","Ljava/lang/String;");
934  if(fid == 0)
935  {
936  JapiError(env,
937  "ERROR: failed to locate targetPath in nxgetgroupid");
938  return;
939  }
940  jstr = (*env)->NewStringUTF(env,myLink.targetPath);
941  (*env)->SetObjectField(env, linki, fid, jstr);
942 
943  fid = (*env)->GetFieldID(env,cls,"linkType","I");
944  if(fid == 0)
945  {
946  JapiError(env,
947  "ERROR: failed to locate linkType in nxgetgroupid");
948  return;
949  }
950  (*env)->SetIntField(env,linki,fid,myLink.linkType);
951 
952 #endif
953  fid = (*env)->GetFieldID(env,cls,"targetPath","Ljava/lang/String;");
954  if(fid == 0)
955  {
956  JapiError(env,
957  "ERROR: failed to locate targetPath in nxgetgroupid");
958  return;
959  }
960  jstr = (*env)->NewStringUTF(env,myLink.targetPath);
961  (*env)->SetObjectField(env, linki, fid, jstr);
962  }
963 }
964 /*------------------------------------------------------------------------
965  nxgetgroupid
966 --------------------------------------------------------------------------*/
967 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxgetdataid
968  (JNIEnv *env, jobject obj, jint handle, jobject linki)
969 {
970  NXhandle nxhandle;
971  NXlink myLink;
972  int iRet;
973  jclass cls;
974  jfieldID fid;
975  jstring jstr;
976 
977  /* set error handler */
978  NXMSetTError(env,JapiError);
979 
980  /* exchange the Java handler to a NXhandle */
981  nxhandle = (NXhandle)HHGetPointer(handle);
982 
983  iRet = NXgetdataID(nxhandle, &myLink);
984  if(iRet == NX_OK)
985  {
986  /* put the link info from our link structure into the object */
987  cls = (*env)->GetObjectClass(env, linki);
988  if(cls == NULL)
989  {
990  JapiError(env,
991  "ERROR: failed to locate class in nxgetdataid");
992  return;
993  }
994  fid = (*env)->GetFieldID(env,cls,"tag","I");
995  if(fid == 0)
996  {
997  JapiError(env,
998  "ERROR: failed to locate fieldID in nxgetdataid");
999  return;
1000  }
1001  (*env)->SetIntField(env,linki,fid,myLink.iTag);
1002  fid = (*env)->GetFieldID(env,cls,"ref","I");
1003  if(fid == 0)
1004  {
1005  JapiError(env,
1006  "ERROR: failed to locate fieldID in nxgetdataid");
1007  return;
1008  }
1009  (*env)->SetIntField(env,linki,fid,myLink.iRef);
1010 
1011 #ifdef HDF5
1012  /*
1013  set HDF-5 String variables
1014  */
1015  fid = (*env)->GetFieldID(env,cls,"targetPath","Ljava/lang/String;");
1016  if(fid == 0)
1017  {
1018  JapiError(env,
1019  "ERROR: failed to locate targetPath in nxgetgroupid");
1020  return;
1021  }
1022  jstr = (*env)->NewStringUTF(env,myLink.targetPath);
1023  (*env)->SetObjectField(env, linki, fid, jstr);
1024 
1025  fid = (*env)->GetFieldID(env,cls,"linkType","I");
1026  if(fid == 0)
1027  {
1028  JapiError(env,
1029  "ERROR: failed to locate linkType in nxgetgroupid");
1030  return;
1031  }
1032  (*env)->SetIntField(env,linki,fid,myLink.linkType);
1033 
1034 #endif
1035  fid = (*env)->GetFieldID(env,cls,"targetPath","Ljava/lang/String;");
1036  if(fid == 0)
1037  {
1038  JapiError(env,
1039  "ERROR: failed to locate targetPath in nxgetdataid");
1040  return;
1041  }
1042  jstr = (*env)->NewStringUTF(env,myLink.targetPath);
1043  (*env)->SetObjectField(env, linki, fid, jstr);
1044 
1045  }
1046 }
1047 /*------------------------------------------------------------------------
1048  nxmakelink
1049 --------------------------------------------------------------------------*/
1050 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxmakelink
1051  (JNIEnv *env, jobject obj, jint handle, jobject target)
1052 {
1053  NXhandle nxhandle;
1054  NXlink myLink;
1055  jclass cls;
1056  jfieldID fid;
1057  jstring jstr;
1058  const char *cData;
1059 
1060  /* set error handler */
1061  NXMSetTError(env,JapiError);
1062 
1063  /* exchange the Java handler to a NXhandle */
1064  nxhandle = (NXhandle)HHGetPointer(handle);
1065 
1066  // convert target object data to myLink structure */
1067  cls = (*env)->GetObjectClass(env, target);
1068  if(cls == NULL)
1069  {
1070  JapiError(env,
1071  "ERROR: failed to locate class in nxmakelink");
1072  return;
1073  }
1074  fid = (*env)->GetFieldID(env,cls,"tag","I");
1075  if(fid == 0)
1076  {
1077  JapiError(env,
1078  "ERROR: failed to locate fieldID in nxmakelink");
1079  return;
1080  }
1081  myLink.iTag = (*env)->GetIntField(env,target,fid);
1082  fid = (*env)->GetFieldID(env,cls,"ref","I");
1083  if(fid == 0)
1084  {
1085  JapiError(env,
1086  "ERROR: failed to locate fieldID in nxmakelink");
1087  return;
1088  }
1089  myLink.iRef = (*env)->GetIntField(env,target,fid);
1090 
1091 #ifdef HDF5
1092  /*
1093  get the HDF-5 Strings
1094  */
1095  fid = (*env)->GetFieldID(env,cls,"targetPath","Ljava/lang/String;");
1096  if(fid == 0)
1097  {
1098  JapiError(env,
1099  "ERROR: failed to locate targetPath in nxmakelink");
1100  return;
1101  }
1102  jstr = (*env)->GetObjectField(env, target, fid);
1103  cData = (*env)->GetStringUTFChars(env, jstr, 0);
1104  strcpy(myLink.targetPath,cData);
1105  (*env)->ReleaseStringUTFChars(env, jstr, cData);
1106 
1107  fid = (*env)->GetFieldID(env,cls,"linkType","I");
1108  if(fid == 0)
1109  {
1110  JapiError(env,
1111  "ERROR: failed to locate linkType in nxmakelink");
1112  return;
1113  }
1114  myLink.linkType = (*env)->GetIntField(env,target,fid);
1115 
1116 #endif
1117  fid = (*env)->GetFieldID(env,cls,"targetPath","Ljava/lang/String;");
1118  if(fid == 0)
1119  {
1120  JapiError(env,
1121  "ERROR: failed to locate targetPath in nxmakelink");
1122  return;
1123  }
1124  jstr = (*env)->GetObjectField(env, target, fid);
1125  cData = (*env)->GetStringUTFChars(env, jstr, 0);
1126  strcpy(myLink.targetPath,cData);
1127  (*env)->ReleaseStringUTFChars(env, jstr, cData);
1128 
1129  // do actually link
1130  if (NXmakelink(nxhandle, &myLink) != NX_OK) {
1131  JapiError(env, "NXmakelink failed");
1132  }
1133 }
1134 /*------------------------------------------------------------------------
1135  nxmakenamedlink
1136 --------------------------------------------------------------------------*/
1138  (JNIEnv *env, jobject obj, jint handle, jstring name, jobject target)
1139 {
1140  NXhandle nxhandle;
1141  NXlink myLink;
1142  jclass cls;
1143  jfieldID fid;
1144  jstring jstr;
1145  const char *cData;
1146  char *Name;
1147 
1148  /* set error handler */
1149  NXMSetTError(env,JapiError);
1150 
1151  /* exchange the Java handler to a NXhandle */
1152  nxhandle = (NXhandle)HHGetPointer(handle);
1153 
1154  /* get link name */
1155  Name = (char *) (*env)->GetStringUTFChars(env,name,0);
1156 
1157  // convert target object data to myLink structure */
1158  cls = (*env)->GetObjectClass(env, target);
1159  if(cls == NULL)
1160  {
1161  JapiError(env,
1162  "ERROR: failed to locate class in nxmakelink");
1163  return;
1164  }
1165  fid = (*env)->GetFieldID(env,cls,"tag","I");
1166  if(fid == 0)
1167  {
1168  JapiError(env,
1169  "ERROR: failed to locate fieldID in nxmakelink");
1170  return;
1171  }
1172  myLink.iTag = (*env)->GetIntField(env,target,fid);
1173  fid = (*env)->GetFieldID(env,cls,"ref","I");
1174  if(fid == 0)
1175  {
1176  JapiError(env,
1177  "ERROR: failed to locate fieldID in nxmakelink");
1178  return;
1179  }
1180  myLink.iRef = (*env)->GetIntField(env,target,fid);
1181 
1182 #ifdef HDF5
1183  /*
1184  get the HDF-5 Strings
1185  */
1186  fid = (*env)->GetFieldID(env,cls,"targetPath","Ljava/lang/String;");
1187  if(fid == 0)
1188  {
1189  JapiError(env,
1190  "ERROR: failed to locate targetPath in nxmakelink");
1191  return;
1192  }
1193  jstr = (*env)->GetObjectField(env, target, fid);
1194  cData = (*env)->GetStringUTFChars(env, jstr, 0);
1195  strcpy(myLink.targetPath,cData);
1196  (*env)->ReleaseStringUTFChars(env, jstr, cData);
1197 
1198  fid = (*env)->GetFieldID(env,cls,"linkType","I");
1199  if(fid == 0)
1200  {
1201  JapiError(env,
1202  "ERROR: failed to locate linkType in nxmakelink");
1203  return;
1204  }
1205  myLink.linkType = (*env)->GetIntField(env,target,fid);
1206 
1207 #endif
1208  fid = (*env)->GetFieldID(env,cls,"targetPath","Ljava/lang/String;");
1209  if(fid == 0)
1210  {
1211  JapiError(env,
1212  "ERROR: failed to locate targetPath in nxmakelink");
1213  return;
1214  }
1215  jstr = (*env)->GetObjectField(env, target, fid);
1216  cData = (*env)->GetStringUTFChars(env, jstr, 0);
1217  strcpy(myLink.targetPath,cData);
1218  (*env)->ReleaseStringUTFChars(env, jstr, cData);
1219 
1220  // do actually link
1221  if (NXmakenamedlink(nxhandle, Name, &myLink) != NX_OK) {
1222  JapiError(env, "NXmakenamedlink failed");
1223  }
1224 }
1225 
1226 /*------------------------------------------------------------------------
1227  nxopensourcepath
1228 --------------------------------------------------------------------------*/
1230  (JNIEnv *env, jobject obj, jint handle)
1231 {
1232  NXhandle nxhandle;
1233 
1234  /* set error handler */
1235  NXMSetTError(env,JapiError);
1236 
1237  /* exchange the Java handler to a NXhandle */
1238  nxhandle = (NXhandle)HHGetPointer(handle);
1239 
1240  if (NXopensourcegroup(nxhandle) != NX_OK) {
1241  JapiError(env, "NXopensourcegroup failed");
1242  }
1243 }
1244 
1245 /*----------------------------------------------------------------------
1246  nxsetnumberformat
1247 -----------------------------------------------------------------------*/
1249  (JNIEnv *env, jobject obj, jint handle, jint type, jstring format)
1250 {
1251  NXhandle nxhandle;
1252  char *cformat;
1253  int iRet;
1254 
1255  /* set error handler */
1256  NXMSetTError(env,JapiError);
1257 
1258  /* exchange the Java handler to a NXhandle */
1259  nxhandle = (NXhandle)HHGetPointer(handle);
1260 
1261  /*
1262  extract format string
1263  */
1264  cformat = (char *) (*env)->GetStringUTFChars(env,format,0);
1265 
1266  /*
1267  call
1268  */
1269  iRet = NXsetnumberformat(nxhandle,type,cformat);
1270  /*
1271  release format string
1272  */
1273  (*env)->ReleaseStringUTFChars(env,format, cformat);
1274 
1275  if (iRet != NX_OK) {
1276  JapiError(env, "NXsetnumberformat failed");
1277  }
1278 }
1279 /*------------------------------------------------------------------------
1280  nxgetinfo
1281 --------------------------------------------------------------------------*/
1282 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxgetinfo
1283  (JNIEnv *env, jobject obj, jint handle, jintArray dim, jintArray args)
1284 {
1285  int rank, type, iRet, iDim[NX_MAXRANK], i;
1286  NXhandle nxhandle;
1287  jint *jdata;
1288 
1289  /* set error handler */
1290  NXMSetTError(env,JapiError);
1291 
1292  /* exchange the Java handler to a NXhandle */
1293  nxhandle = (NXhandle)HHGetPointer(handle);
1294 
1295  /* call */
1296  iRet = NXgetinfo(nxhandle, &rank, iDim, &type);
1297 
1298  /* copy data to Java types */
1299  if(iRet == NX_OK)
1300  {
1301  jdata = (*env)->GetIntArrayElements(env,dim,0);
1302  for(i = 0; i < rank; i++)
1303  {
1304  jdata[i] = iDim[i];
1305  }
1306  (*env)->ReleaseIntArrayElements(env,dim,jdata,0);
1307  jdata = (*env)->GetIntArrayElements(env,args,0);
1308  jdata[0] = rank;
1309  jdata[1] = type;
1310  (*env)->ReleaseIntArrayElements(env,args,jdata,0);
1311  }
1312 }
1313 /*------------------------------------------------------------------------
1314  nxgetinfo64
1315 --------------------------------------------------------------------------*/
1316 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxgetinfo64
1317  (JNIEnv *env, jobject obj, jint handle, jlongArray dim, jintArray args)
1318 {
1319  int rank, type, iRet, i;
1320  jlong iDim[NX_MAXRANK];
1321  NXhandle nxhandle;
1322  jlong *jdata;
1323  jint *jargsdata;
1324 
1325  /* set error handler */
1326  NXMSetTError(env,JapiError);
1327 
1328  /* exchange the Java handler to a NXhandle */
1329  nxhandle = (NXhandle)HHGetPointer(handle);
1330 
1331  /* call */
1332  iRet = NXgetinfo64(nxhandle, &rank, iDim, &type);
1333 
1334  /* copy data to Java types */
1335  if(iRet == NX_OK)
1336  {
1337  jdata = (*env)->GetLongArrayElements(env,dim,0);
1338  for(i = 0; i < rank; i++)
1339  {
1340  jdata[i] = iDim[i];
1341  }
1342  (*env)->ReleaseLongArrayElements(env,dim,jdata,0);
1343 
1344  jargsdata = (*env)->GetIntArrayElements(env,args,0);
1345  jargsdata[0] = rank;
1346  jargsdata[1] = type;
1347  (*env)->ReleaseIntArrayElements(env,args,jargsdata,0);
1348  }
1349 }
1350 /*------------------------------------------------------------------------
1351  nextentry
1352 --------------------------------------------------------------------------*/
1353 JNIEXPORT jint JNICALL Java_org_nexusformat_NexusFile_nextentry
1354  (JNIEnv *env, jobject obj, jint handle, jobjectArray jnames)
1355 {
1356  NXhandle nxhandle;
1357  NXname pName, pClass;
1358  int iRet, iType;
1359  jstring rstring;
1360 
1361  /* set error handler */
1362  NXMSetTError(env,JapiError);
1363 
1364  /* exchange the Java handler to a NXhandle */
1365  nxhandle = (NXhandle)HHGetPointer(handle);
1366 
1367  iRet = NXgetnextentry(nxhandle,pName, pClass,&iType);
1368  if(iRet != NX_ERROR)
1369  {
1370  /* convert C strings to Java Strings */
1371  rstring = (*env)->NewStringUTF(env,pName);
1372  (*env)->SetObjectArrayElement(env,jnames,0,(jobject)rstring);
1373  rstring = (*env)->NewStringUTF(env,pClass);
1374  (*env)->SetObjectArrayElement(env,jnames,1,(jobject)rstring);
1375  }
1376  return iRet;
1377 }
1378 /*------------------------------------------------------------------------
1379  nextattr
1380 --------------------------------------------------------------------------*/
1381 JNIEXPORT jint JNICALL Java_org_nexusformat_NexusFile_nextattr
1382  (JNIEnv *env, jobject obj, jint handle, jobjectArray jnames, jintArray args)
1383 {
1384  NXhandle nxhandle;
1385  NXname pName;
1386  int iRet, iType, iLen;
1387  jstring rstring;
1388  jint *jarray;
1389  /* set error handler */
1390  NXMSetTError(env,JapiError);
1391 
1392  /* exchange the Java handler to a NXhandle */
1393  nxhandle = (NXhandle)HHGetPointer(handle);
1394 
1395  iRet = NXgetnextattr(nxhandle, pName, &iLen, &iType);
1396  if(iRet != NX_ERROR)
1397  {
1398  /* copy C types to Java */
1399  rstring = (*env)->NewStringUTF(env,pName);
1400  (*env)->SetObjectArrayElement(env,jnames,0,(jobject)rstring);
1401  jarray = (*env)->GetIntArrayElements(env,args,0);
1402  jarray[0] = iLen;
1403  jarray[1] = iType;
1404  (*env)->ReleaseIntArrayElements(env,args,jarray,0);
1405  }
1406  return iRet;
1407 }
1408 /*-----------------------------------------------------------------------*/
1409 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxinquirefile(JNIEnv *env,
1410  jobject obj , jint handle, jobjectArray jnames){
1411  NXhandle nxhandle;
1412  int status;
1413  char filename[1024];
1414  jstring rstring;
1415 
1416  /* set error handler */
1417  NXMSetTError(env,JapiError);
1418 
1419  /* exchange the Java handler to a NXhandle */
1420  nxhandle = (NXhandle)HHGetPointer(handle);
1421  status = NXinquirefile(nxhandle,filename,1023);
1422  if(status == NX_OK){
1423  rstring = (*env)->NewStringUTF(env,filename);
1424  (*env)->SetObjectArrayElement(env,jnames,0,(jobject)rstring);
1425  }
1426 }
1427 /*------------------------------------------------------------------------*/
1428 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_nxlinkexternal
1429 (JNIEnv *env, jobject obj, jint handle, jstring name,
1430  jstring nxclass, jstring nxurl){
1431  int iRet;
1432  NXhandle nxhandle;
1433  char *Name, *Nxclass, *Nxurl;
1434 
1435  /* set error handler */
1436  NXMSetTError(env,JapiError);
1437 
1438  /* exchange the Java handler to a NXhandle */
1439  nxhandle = (NXhandle)HHGetPointer(handle);
1440 
1441  /* extract the name and class to char * */
1442  Name = (char *) (*env)->GetStringUTFChars(env,name,0);
1443  Nxclass = (char *) (*env)->GetStringUTFChars(env,nxclass,0);
1444  Nxurl = (char *) (*env)->GetStringUTFChars(env,nxurl,0);
1445  iRet = NXlinkexternal(nxhandle,Name,Nxclass,Nxurl);
1446 
1447  /* release strings */
1448  (*env)->ReleaseStringUTFChars(env,name, Name);
1449  (*env)->ReleaseStringUTFChars(env,nxclass, Nxclass);
1450  (*env)->ReleaseStringUTFChars(env,nxurl, Nxurl);
1451 
1452  if (iRet != NX_OK) {
1453  JapiError(env, "NXlinkexternal failed");
1454  }
1455 }
1456 /*------------------------------------------------------------------------*/
1458 (JNIEnv *env, jobject obj, jint handle, jstring name, jstring nxurl){
1459  int iRet;
1460  NXhandle nxhandle;
1461  char *Name, *Nxurl;
1462 
1463  /* set error handler */
1464  NXMSetTError(env,JapiError);
1465 
1466  /* exchange the Java handler to a NXhandle */
1467  nxhandle = (NXhandle)HHGetPointer(handle);
1468 
1469  /* extract the name and class to char * */
1470  Name = (char *) (*env)->GetStringUTFChars(env,name,0);
1471  Nxurl = (char *) (*env)->GetStringUTFChars(env,nxurl,0);
1472  iRet = NXlinkexternaldataset(nxhandle,Name,Nxurl);
1473 
1474  /* release strings */
1475  (*env)->ReleaseStringUTFChars(env,name, Name);
1476  (*env)->ReleaseStringUTFChars(env,nxurl, Nxurl);
1477 
1478  if (iRet != NX_OK) {
1479  JapiError(env, "NXlinkexternaldataset failed");
1480  }
1481 }
1482 /*------------------------------------------------------------------------*/
1484 (JNIEnv *env, jobject obj, jint handle, jstring name, jstring nxclass,
1485  jobjectArray jnames){
1486  int status, length = 1024;
1487  NXhandle nxhandle;
1488  char *Name, *Nxclass, nxurl[1024];
1489  jstring rstring;
1490 
1491  /* set error handler */
1492  NXMSetTError(env,JapiError);
1493 
1494  /* exchange the Java handler to a NXhandle */
1495  nxhandle = (NXhandle)HHGetPointer(handle);
1496 
1497  /* extract the name and class to char * */
1498  Name = (char *) (*env)->GetStringUTFChars(env,name,0);
1499  Nxclass = (char *) (*env)->GetStringUTFChars(env,nxclass,0);
1500 
1501  status = NXisexternalgroup(nxhandle,Name,Nxclass,nxurl,length);
1502 
1503  /* release strings */
1504  (*env)->ReleaseStringUTFChars(env,name, Name);
1505  (*env)->ReleaseStringUTFChars(env,nxclass, Nxclass);
1506 
1507  if(status == NX_OK){
1508  rstring = (*env)->NewStringUTF(env,nxurl);
1509  (*env)->SetObjectArrayElement(env,jnames,0,(jobject)rstring);
1510  }
1511  return status;
1512 }
1513 /*------------------------------------------------------------------------*/
1515 (JNIEnv *env, jobject obj, jint handle, jstring name, jobjectArray jnames){
1516  int status, length = 1024;
1517  NXhandle nxhandle;
1518  char *Name, nxurl[1024];
1519  jstring rstring;
1520 
1521  /* set error handler */
1522  NXMSetTError(env,JapiError);
1523 
1524  /* exchange the Java handler to a NXhandle */
1525  nxhandle = (NXhandle)HHGetPointer(handle);
1526 
1527  /* extract the name and class to char * */
1528  Name = (char *) (*env)->GetStringUTFChars(env,name,0);
1529 
1530  status = NXisexternaldataset(nxhandle,Name,nxurl,length);
1531 
1532  /* release strings */
1533  (*env)->ReleaseStringUTFChars(env,name, Name);
1534 
1535  if(status == NX_OK){
1536  rstring = (*env)->NewStringUTF(env,nxurl);
1537  (*env)->SetObjectArrayElement(env,jnames,0,(jobject)rstring);
1538  }
1539  return status;
1540 }
1541 /*---------------------------------------------------------------------*/
1542 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_initattrdir
1543 (JNIEnv *env, jobject obj, jint handle)
1544 {
1545  NXhandle nxhandle;
1546  int iRet;
1547 
1548  /* set error handler */
1549  NXMSetTError(env,JapiError);
1550 
1551  /* exchange the Java handler to a NXhandle */
1552  nxhandle = (NXhandle)HHGetPointer(handle);
1553 
1554  if (NXinitattrdir(nxhandle) != NX_OK) {
1555  JapiError(env, "NXinitattrdir failed");
1556  }
1557 }
1558 /*---------------------------------------------------------------------*/
1559 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_initgroupdir
1560 (JNIEnv *env, jobject obj, jint handle)
1561 {
1562  NXhandle nxhandle;
1563  int iRet;
1564 
1565  /* set error handler */
1566  NXMSetTError(env,JapiError);
1567 
1568  /* exchange the Java handler to a NXhandle */
1569  nxhandle = (NXhandle)HHGetPointer(handle);
1570 
1571  if (NXinitgroupdir(nxhandle) != NX_OK) {
1572  JapiError(env, "NXinitgroupdir failed");
1573  }
1574 }
1575 /*------------------------------------------------------------------------
1576  debugstop
1577 --------------------------------------------------------------------------*/
1578 
1579 JNIEXPORT void JNICALL Java_org_nexusformat_NexusFile_debugstop
1580  (JNIEnv *env, jobject obj)
1581 {
1582  int iStop = 1;
1583 
1584  while(iStop)
1585  {
1586 /* sleep(2); */
1587  }
1588 }