-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathplplotjavac.i
More file actions
2142 lines (1947 loc) · 67.4 KB
/
Copy pathplplotjavac.i
File metadata and controls
2142 lines (1947 loc) · 67.4 KB
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
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
385
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
415
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
457
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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
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
555
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
595
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
648
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
694
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
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// Copyright (C) 2002 Gary Bishop
// Copyright (C) 2002-2019 Alan W. Irwin
// Copyright (C) 2004-2005 Rafael Laboissiere
// Copyright (C) 2004-2013 Andrew Ross
// Copyright (C) 2009 Werner Smekal
// Copyright (C) 2013 Arjen Markus
//This file is part of PLplot.
//
//PLplot is free software; you can redistribute it and/or modify
//it under the terms of the GNU Library General Public License as published by
//the Free Software Foundation; version 2 of the License.
//
//PLplot is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU Library General Public License for more details.
//
//You should have received a copy of the GNU Library General Public License
//along with the file PLplot; if not, write to the Free Software
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
//
//A SWIG interface to PLplot for Java. This wrapper does the following:
//
// 1) it strictly provides the C-API with the usual change of not
// requiring lengths for arrays,
//
// 2) it attempts to provide the entire API *excluding* callbacks for
// plcont and plshade(s) (for now).
//
// 3) it works both with the single and double-precision versions of the
// PLplot library.
//
//This is known to work with swig-1.3.21.
//
//
%module plplotjavac
%include <typemaps.i>
%{
#include "plplotP.h"
%}
#ifdef PL_DOUBLE_INTERFACE
typedef double PLFLT;
#else
typedef float PLFLT;
#endif
// This assumes that C int is 32-bit - swig doesn't know about int32_t
// Ideally we should have a typemap for it
typedef int PLINT;
typedef unsigned int PLUNICODE;
typedef PLINT PLBOOL;
// Set jni version and cache JVM - needed for callbacks
%{
static JavaVM *cached_jvm = NULL;
SWIGEXPORT JNIEXPORT jint JNICALL JNI_OnLoad( JavaVM *jvm, void * PL_UNUSED( reserved ) )
{
cached_jvm = jvm;
return JNI_VERSION_1_2;
}
%}
// Simple (input) PLBOOL arguments
// Use macro style similar to INPUT_TYPEMAP defined in typemaps.i, but
// actually follow what is done in java.swg for bool C type except
// change action of typemap(in) from "? true : false;" to "? 1 : 0;" to
// be consistent with actual C type of PLBOOL which is PLINT. If C type
// of PLBOOL ever changed to bool, none of this would be necessary, but
// such a change would demand using the c99 standard for PLplot which is
// not widely implemented yet.
//
%define PLBOOL_INPUT_TYPEMAP( TYPE, JNITYPE, JTYPE, JNIDESC )
%typemap( jni ) TYPE "JNITYPE"
%typemap( jtype ) TYPE "JTYPE"
%typemap( jstype ) TYPE "JTYPE"
%typemap( in ) TYPE
%{
$1 = $input ? 1 : 0;
%}
%typemap( javadirectorin ) TYPE "$jniinput"
%typemap( javadirectorout ) TYPE "$javacall"
%typemap( directorin, descriptor = JNIDESC ) TYPE
%{
$input = (JNITYPE *) $1;
%}
%typemap( javain ) TYPE "$javainput"
%enddef
PLBOOL_INPUT_TYPEMAP( PLBOOL, jboolean, boolean, "Z" );
// This renamed macro copied exactly from OUTPUT_TYPEMAP macro
// in typemaps.i which handles *OUTPUT types.
%define PLBOOL_OUTPUT_TYPEMAP( TYPE, JNITYPE, JTYPE, JAVATYPE, JNIDESC, TYPECHECKTYPE )
%typemap( jni ) TYPE * OUTPUT, TYPE & OUTPUT
%{
JNITYPE ## Array
%}
%typemap( jtype ) TYPE * OUTPUT, TYPE & OUTPUT "JTYPE[]"
%typemap( jstype ) TYPE * OUTPUT, TYPE & OUTPUT "JTYPE[]"
%typemap( javain ) TYPE * OUTPUT, TYPE & OUTPUT "$javainput"
%typemap( javadirectorin ) TYPE * OUTPUT, TYPE & OUTPUT "$jniinput"
%typemap( javadirectorout ) TYPE * OUTPUT, TYPE & OUTPUT "$javacall"
%typemap( in ) TYPE * OUTPUT( $*1_ltype temp ), TYPE & OUTPUT( $*1_ltype temp )
{
if ( !$input )
{
SWIG_JavaThrowException( jenv, SWIG_JavaNullPointerException, "array null" );
return $null;
}
if ( JCALL1( GetArrayLength, jenv, $input ) == 0 )
{
SWIG_JavaThrowException( jenv, SWIG_JavaIndexOutOfBoundsException, "Array must contain at least 1 element" );
return $null;
}
$1 = &temp;
}
%typemap( directorin, descriptor = JNIDESC ) TYPE & OUTPUT
%{
*( ($&1_ltype) $input ) = &$1;
%}
%typemap( directorin, descriptor = JNIDESC, warning = "Need to provide TYPE *OUTPUT directorin typemap, TYPE array length is unknown" ) TYPE * OUTPUT
{
}
%typemap( freearg ) TYPE * OUTPUT, TYPE & OUTPUT ""
%typemap( argout ) TYPE * OUTPUT, TYPE & OUTPUT
{
JNITYPE jvalue = (JNITYPE) temp$argnum;
JCALL4( Set ## JAVATYPE ## ArrayRegion, jenv, $input, 0, 1, &jvalue );
}
%typemap( typecheck ) TYPE * INOUT = TYPECHECKTYPE;
%typemap( typecheck ) TYPE &INOUT = TYPECHECKTYPE;
%enddef
// Copy what is done for C bool type, only use PLBOOL instead.
PLBOOL_OUTPUT_TYPEMAP( PLBOOL, jboolean, boolean, Boolean, "[Ljava/lang/Boolean;", jbooleanArray );
//**************************
// A trick for docstrings
//***************************
%define DOC( func, string )
%wrapper
%{
# define _doc_ ## func string
%}
%enddef
// Infrastructure for handling swig compatible plplot API definitions.
#ifdef PL_DOUBLE_INTERFACE
#define setup_array_1d_PLFLT setup_array_1d_d
#define setup_array_2d_PLFLT setup_array_2d_d
#define jPLFLTArray "jdoubleArray"
#define jPLFLTbracket "double[]"
#define jPLFLTbracket2 "double[][]"
#define GetPLFLTArrayElements GetDoubleArrayElements
#define ReleasePLFLTArrayElements ReleaseDoubleArrayElements
#define jPLFLT jdouble
#else
#define setup_array_1d_PLFLT setup_array_1d_f
#define setup_array_2d_PLFLT setup_array_2d_f
#define jPLFLTArray "jfloatArray"
#define jPLFLTbracket "float[]"
#define jPLFLTbracket2 "float[][]"
#define GetPLFLTArrayElements GetFloatArrayElements
#define ReleasePLFLTArrayElements ReleaseFloatArrayElements
#define jPLFLT jfloat
#endif
%{
//--------------------------------------------------------------------------
// Array allocation & copy helper routines. Note because of swig limitations
// it is necessary to release the java array memory right after calling these
// routines. Thus it is necessary to allocate and copy the arrays even if
// the java and plplot arrays are of the same type. Note, because of this
// change to Geoffrey's original versions, caller must always free memory
// afterwards. Thus, the must_free_buffers logic is gone as well.
//--------------------------------------------------------------------------
// 1d array of jbooleans
static void
setup_array_1d_b( PLBOOL **pa, jboolean *adat, int n )
{
int i;
*pa = (PLBOOL *) malloc( (size_t) n * sizeof ( PLBOOL ) );
for ( i = 0; i < n; i++ )
{
( *pa )[i] = adat[i] ? 1 : 0;
}
}
// 1d array of jints
static void
setup_array_1d_i( PLINT **pa, jint *adat, int n )
{
int i;
*pa = (PLINT *) malloc( (size_t) n * sizeof ( PLINT ) );
for ( i = 0; i < n; i++ )
{
( *pa )[i] = adat[i];
}
}
// 1d array of jfloats
static void
setup_array_1d_f( PLFLT **pa, jfloat *adat, int n )
{
int i;
*pa = (PLFLT *) malloc( (size_t) n * sizeof ( PLFLT ) );
for ( i = 0; i < n; i++ )
{
( *pa )[i] = adat[i];
}
}
// 1d array of jdoubles
static void
setup_array_1d_d( PLFLT **pa, jdouble *adat, int n )
{
int i;
*pa = (PLFLT *) malloc( (size_t) n * sizeof ( PLFLT ) );
for ( i = 0; i < n; i++ )
{
( *pa )[i] = adat[i];
}
}
// 2d array of floats
// Here caller must free(a[0]) and free(a) (in that order) afterward
static void
setup_array_2d_f( PLFLT ***pa, jfloat **adat, int nx, int ny )
{
int i, j;
*pa = (PLFLT **) malloc( (size_t) nx * sizeof ( PLFLT * ) );
( *pa )[0] = (PLFLT *) malloc( (size_t) ( nx * ny ) * sizeof ( PLFLT ) );
for ( i = 0; i < nx; i++ )
{
( *pa )[i] = ( *pa )[0] + i * ny;
for ( j = 0; j < ny; j++ )
( *pa )[i][j] = adat[i][j];
}
}
// 2d array of doubles
// Here caller must free(a[0]) and free(a) (in that order) afterward
static void
setup_array_2d_d( PLFLT ***pa, jdouble **adat, int nx, int ny )
{
int i, j;
*pa = (PLFLT **) malloc( (size_t) nx * sizeof ( PLFLT * ) );
( *pa )[0] = (PLFLT *) malloc( (size_t) ( nx * ny ) * sizeof ( PLFLT ) );
for ( i = 0; i < nx; i++ )
{
( *pa )[i] = ( *pa )[0] + i * ny;
for ( j = 0; j < ny; j++ )
( *pa )[i][j] = adat[i][j];
}
}
// Setup java arrays (for callback functions)
// Create a jdoubleArray and fill it from the C PLFLT array dat
static jdoubleArray
setup_java_array_1d_PLFLT( JNIEnv *jenv, PLFLT *dat, PLINT n )
{
double *x;
jdoubleArray jadat;
#ifdef PL_DOUBLE
x = (double *) dat;
#else
x = (double *) malloc( (size_t) n * sizeof ( double ) );
for ( i = 0; i < n; i++ )
{
x[i] = (double) dat[i];
}
#endif
jadat = ( *jenv )->NewDoubleArray( jenv, n );
( *jenv )->SetDoubleArrayRegion( jenv, jadat, 0, n, x );
#ifndef PL_DOUBLE
free( x );
#endif
return jadat;
}
// Copy back data from jdoubleArray to C PLFLT array then release java array
static void
release_java_array_1d_PLFLT( JNIEnv *jenv, jdoubleArray jadat, PLFLT *dat, PLINT n )
{
PLINT i;
jdouble *jdata = ( *jenv )->GetDoubleArrayElements( jenv, jadat, 0 );
for ( i = 0; i < n; i++ )
{
dat[i] = (PLFLT) jdata[i];
}
( *jenv )->ReleaseDoubleArrayElements( jenv, jadat, jdata, 0 );
}
%}
// I hate global variables but this is the best way I can think of to manage consistency
// checking among function arguments.
%{
static PLINT Alen = 0;
static PLINT Xlen = 0, Ylen = 0;
static PLFLT **xg;
static PLFLT **yg;
static PLcGrid2 *cgrid;
%}
// The following typemaps take care of marshaling values into and out of PLplot functions. The
//Array rules are trickly because of the need for length checking. These rules manage
//some global variables (above) to handle consistency checking amoung parameters.
//
//Naming rules:
// Array (sets Alen to dim[0])
// ArrayCk (tests that dim[0] == Alen)
// ArrayCkNull (tests that dim[0] == Alen or array is null)
// ArrayX (sets Xlen to dim[0]
// ArrayCkX (tests dim[0] == Xlen)
// ArrayY (sets Ylen to dim[1])
// ArrayCkY (tests dim[1] == Ylen)
// Matrix (sets Xlen to dim[0], Ylen to dim[1])
// MatrixCk (test Xlen == dim[0] && Ylen == dim[1])
//
//--------------------------------------------------------------------------
// PLINT arrays
//--------------------------------------------------------------------------
// with preceding count
%typemap( in ) ( PLINT n, const PLINT * Array )
{
jint *jxdata = ( *jenv )->GetIntArrayElements( jenv, $input, 0 );
$1 = ( *jenv )->GetArrayLength( jenv, $input );
Alen = $1;
setup_array_1d_i( &$2, jxdata, Alen );
// Could find no easy way to do this as part of freearg so I modified
// the previous function so it ALWAYS mallocs and copies so that
// the java array can be released immediately.
( *jenv )->ReleaseIntArrayElements( jenv, $input, jxdata, 0 );
}
%typemap( freearg ) ( PLINT n, const PLINT * Array )
{
free( $2 );
}
%typemap( jni ) ( PLINT n, const PLINT * Array ) "jintArray"
%typemap( jtype ) ( PLINT n, const PLINT * Array ) "int[]"
%typemap( jstype ) ( PLINT n, const PLINT * Array ) "int[]"
%typemap( javain ) ( PLINT n, const PLINT * Array ) "$javainput"
%typemap( javaout ) ( PLINT n, const PLINT * Array )
{
return $jnicall;
}
// Trailing count and check consistency with previous
%typemap( in ) ( const PLINT * ArrayCk, PLINT n )
{
jint *jydata = ( *jenv )->GetIntArrayElements( jenv, $input, 0 );
if ( ( *jenv )->GetArrayLength( jenv, $input ) != Alen )
{
printf( "Vectors must be same length.\n" );
return;
}
$2 = ( *jenv )->GetArrayLength( jenv, $input );
setup_array_1d_i( &$1, jydata, Alen );
( *jenv )->ReleaseIntArrayElements( jenv, $input, jydata, 0 );
}
%typemap( freearg ) ( const PLINT * ArrayCk, PLINT n )
{
free( $1 );
}
%typemap( jni ) ( const PLINT * ArrayCk, PLINT n ) "jintArray"
%typemap( jtype ) ( const PLINT * ArrayCk, PLINT n ) "int[]"
%typemap( jstype ) ( const PLINT * ArrayCk, PLINT n ) "int[]"
%typemap( javain ) ( const PLINT * ArrayCk, PLINT n ) "$javainput"
%typemap( javaout ) ( const PLINT * ArrayCk, PLINT n )
{
return $jnicall;
}
// no count but check consistency with previous
%typemap( in ) const PLINT * ArrayCk {
jint *jydata = ( *jenv )->GetIntArrayElements( jenv, $input, 0 );
if ( ( *jenv )->GetArrayLength( jenv, $input ) != Alen )
{
printf( "Vectors must be same length.\n" );
return;
}
setup_array_1d_i( &$1, jydata, Alen );
( *jenv )->ReleaseIntArrayElements( jenv, $input, jydata, 0 );
}
%typemap( freearg ) const PLINT * ArrayCk {
free( $1 );
}
%typemap( jni ) const PLINT * ArrayCk "jintArray"
%typemap( jtype ) const PLINT * ArrayCk "int[]"
%typemap( jstype ) const PLINT * ArrayCk "int[]"
%typemap( javain ) const PLINT * ArrayCk "$javainput"
%typemap( javaout ) const PLINT * ArrayCk {
return $jnicall;
}
// no count but check consistency with previous or is null
%typemap( in ) const PLINT * ArrayCkNull {
if ( $input != NULL )
{
jint *jydata = ( *jenv )->GetIntArrayElements( jenv, $input, 0 );
if ( ( *jenv )->GetArrayLength( jenv, $input ) != Alen )
{
printf( "Vectors must be same length.\n" );
return;
}
setup_array_1d_i( &$1, jydata, Alen );
( *jenv )->ReleaseIntArrayElements( jenv, $input, jydata, 0 );
}
else
{
$1 = NULL;
}
}
%typemap( freearg ) const PLINT * ArrayCkNull {
if ( $1 != NULL )
free( $1 );
}
%typemap( jni ) const PLINT * ArrayCkNull "jintArray"
%typemap( jtype ) const PLINT * ArrayCkNull "int[]"
%typemap( jstype ) const PLINT * ArrayCkNull "int[]"
%typemap( javain ) const PLINT * ArrayCkNull "$javainput"
%typemap( javaout ) const PLINT * ArrayCkNull {
return $jnicall;
}
// Weird case to allow argument to be one shorter than others
// This case is used both for PLBOOL and PLINT. Define PLBOOL version
// first. (AWI thinks this may be necessary because of the above
// typedef PLINT PLBOOL;)
// Also add version which must be one shorter than others or null.
//
%typemap( in ) const PLBOOL * ArrayCkMinus1 {
jboolean *jydata = ( *jenv )->GetBooleanArrayElements( jenv, $input, 0 );
if ( ( *jenv )->GetArrayLength( jenv, $input ) < Alen - 1 )
{
printf( "Vector must be at least length of others minus 1.\n" );
return;
}
setup_array_1d_b( &$1, jydata, Alen );
( *jenv )->ReleaseBooleanArrayElements( jenv, $input, jydata, 0 );
}
%typemap( freearg ) const PLBOOL * ArrayCkMinus1 {
free( $1 );
}
%typemap( jni ) const PLBOOL * ArrayCkMinus1 "jbooleanArray"
%typemap( jtype ) const PLBOOL * ArrayCkMinus1 "boolean[]"
%typemap( jstype ) const PLBOOL * ArrayCkMinus1 "boolean[]"
%typemap( javain ) const PLBOOL * ArrayCkMinus1 "$javainput"
%typemap( javaout ) const PLBOOL * ArrayCkMinus1 {
return $jnicall;
}
%typemap( in ) const PLBOOL * ArrayCkMinus1Null {
if ( $input != NULL )
{
jboolean *jydata = ( *jenv )->GetBooleanArrayElements( jenv, $input, 0 );
if ( ( *jenv )->GetArrayLength( jenv, $input ) < Alen - 1 )
{
printf( "Vector must be at least length of others minus 1.\n" );
return;
}
setup_array_1d_b( &$1, jydata, Alen );
( *jenv )->ReleaseBooleanArrayElements( jenv, $input, jydata, 0 );
}
else
{
$1 = NULL;
}
}
%typemap( freearg ) const PLBOOL * ArrayCkMinus1Null {
if ( $1 != NULL )
free( $1 );
}
%typemap( jni ) const PLBOOL * ArrayCkMinus1Null "jbooleanArray"
%typemap( jtype ) const PLBOOL * ArrayCkMinus1Null "boolean[]"
%typemap( jstype ) const PLBOOL * ArrayCkMinus1Null "boolean[]"
%typemap( javain ) const PLBOOL * ArrayCkMinus1Null "$javainput"
%typemap( javaout ) const PLBOOL * ArrayCkMinus1Null {
return $jnicall;
}
%typemap( in ) const PLINT * ArrayCkMinus1 {
jint *jydata = ( *jenv )->GetIntArrayElements( jenv, $input, 0 );
if ( ( *jenv )->GetArrayLength( jenv, $input ) < Alen - 1 )
{
printf( "Vector must be at least length of others minus 1.\n" );
return;
}
setup_array_1d_i( &$1, jydata, Alen );
( *jenv )->ReleaseIntArrayElements( jenv, $input, jydata, 0 );
}
%typemap( freearg ) const PLINT * ArrayCkMinus1 {
free( $1 );
}
%typemap( jni ) const PLINT * ArrayCkMinus1 "jintArray"
%typemap( jtype ) const PLINT * ArrayCkMinus1 "int[]"
%typemap( jstype ) const PLINT * ArrayCkMinus1 "int[]"
%typemap( javain ) const PLINT * ArrayCkMinus1 "$javainput"
%typemap( javaout ) const PLINT * ArrayCkMinus1 {
return $jnicall;
}
%typemap( in ) const PLINT * ArrayCkMinus1Null {
if ( $input != NULL )
{
jint *jydata = ( *jenv )->GetIntArrayElements( jenv, $input, 0 );
if ( ( *jenv )->GetArrayLength( jenv, $input ) < Alen - 1 )
{
printf( "Vector must be at least length of others minus 1.\n" );
return;
}
setup_array_1d_i( &$1, jydata, Alen );
( *jenv )->ReleaseIntArrayElements( jenv, $input, jydata, 0 );
}
else
{
$1 = NULL;
}
}
%typemap( freearg ) const PLINT * ArrayCkMinus1Null {
if ( $1 != NULL )
free( $1 );
}
%typemap( jni ) const PLINT * ArrayCkMinus1Null "jintArray"
%typemap( jtype ) const PLINT * ArrayCkMinus1Null "int[]"
%typemap( jstype ) const PLINT * ArrayCkMinus1Null "int[]"
%typemap( javain ) const PLINT * ArrayCkMinus1Null "$javainput"
%typemap( javaout ) const PLINT * ArrayCkMinus1Null {
return $jnicall;
}
// No length but remember size to check others
%typemap( in ) const PLINT * Array {
jint *jydata = ( *jenv )->GetIntArrayElements( jenv, $input, 0 );
Alen = ( *jenv )->GetArrayLength( jenv, $input );
setup_array_1d_i( &$1, jydata, Alen );
( *jenv )->ReleaseIntArrayElements( jenv, $input, jydata, 0 );
}
%typemap( freearg ) const PLINT * Array {
free( $1 );
}
%typemap( jni ) const PLINT * Array "jintArray"
%typemap( jtype ) const PLINT * Array "int[]"
%typemap( jstype ) const PLINT * Array "int[]"
%typemap( javain ) const PLINT * Array "$javainput"
%typemap( javaout ) const PLINT * Array {
return $jnicall;
}
// Set X and Y length for later consistency checking
%typemap( in ) const PLINT * ArrayN {
int i;
jint *jydata = ( *jenv )->GetIntArrayElements( jenv, $input, 0 );
if ( ( *jenv )->GetArrayLength( jenv, $input ) != Alen )
{
printf( "Vectors must be same length.\n" );
return;
}
Xlen = ( *jenv )->GetArrayLength( jenv, $input );
Ylen = -1;
for ( i = 0; i < Xlen; i++ )
if ( jydata[i] > Ylen )
Ylen = jydata[i];
setup_array_1d_i( &$1, jydata, Alen );
( *jenv )->ReleaseIntArrayElements( jenv, $input, jydata, 0 );
}
%typemap( freearg ) const PLINT * ArrayN {
free( $1 );
}
%typemap( jni ) const PLINT * ArrayN "jintArray"
%typemap( jtype ) const PLINT * ArrayN "int[]"
%typemap( jstype ) const PLINT * ArrayN "int[]"
%typemap( javain ) const PLINT * ArrayN "$javainput"
%typemap( javaout ) const PLINT * ArrayN {
return $jnicall;
}
// With trailing count and NULL array option.
%typemap( in ) ( const PLINT * ArrayNull, PLINT n )
{
if ( $input != NULL )
{
jint *jydata = ( *jenv )->GetIntArrayElements( jenv, $input, 0 );
$2 = ( *jenv )->GetArrayLength( jenv, $input );
setup_array_1d_i( &$1, jydata, $2 );
( *jenv )->ReleaseIntArrayElements( jenv, $input, jydata, 0 );
}
else
{
$1 = NULL;
$2 = 0;
}
}
%typemap( freearg ) ( const PLINT * ArrayNull, PLINT n )
{
free( $1 );
}
%typemap( jni ) ( const PLINT * ArrayNull, PLINT n ) "jintArray"
%typemap( jtype ) ( const PLINT * ArrayNull, PLINT n ) "int[]"
%typemap( jstype ) ( const PLINT * ArrayNull, PLINT n ) "int[]"
%typemap( javain ) ( const PLINT * ArrayNull, PLINT n ) "$javainput"
%typemap( javaout ) ( const PLINT * ArrayNull, PLINT n )
{
return $jnicall;
}
//--------------------------------------------------------------------------
// PLFLT Arrays
//--------------------------------------------------------------------------
//temporary
#if 0
#ifndef PL_DOUBLE
%wrapper
%{
// some really twisted stuff to allow calling a single precision library from python
PyArrayObject* myArray_ContiguousFromObject( PyObject* in, int type, int mindims, int maxdims )
{
PyArrayObject* tmp = (PyArrayObject *) PyArray_ContiguousFromObject( in, PyArray_FLOAT,
mindims, maxdims );
if ( !tmp )
{
// could be an incoming double array which can't be "safely" converted, do it anyway
if ( PyArray_Check( in ) )
{
PyErr_Clear();
tmp = (PyArrayObject *) PyArray_Cast( (PyArrayObject *) in, PyArray_FLOAT );
}
}
return tmp;
}
%}
#else
%wrapper
%{
#define myArray_ContiguousFromObject PyArray_ContiguousFromObject
%}
#endif
// temporary
#endif
// with preceding count
%typemap( in ) ( PLINT n, const PLFLT * Array )
{
jPLFLT *jxdata = ( *jenv )->GetPLFLTArrayElements( jenv, $input, 0 );
$1 = ( *jenv )->GetArrayLength( jenv, $input );
Alen = $1;
setup_array_1d_PLFLT( &$2, jxdata, Alen );
// Could find no easy way to do this as part of freearg so I modified
// the previous function so it ALWAYS mallocs and copies so that
// the java array can be released immediately.
( *jenv )->ReleasePLFLTArrayElements( jenv, $input, jxdata, 0 );
}
%typemap( freearg ) ( PLINT n, const PLFLT * Array )
{
free( $2 );
}
%typemap( jni ) ( PLINT n, const PLFLT * Array ) jPLFLTArray
%typemap( jtype ) ( PLINT n, const PLFLT * Array ) jPLFLTbracket
%typemap( jstype ) ( PLINT n, const PLFLT * Array ) jPLFLTbracket
%typemap( javain ) ( PLINT n, const PLFLT * Array ) "$javainput"
%typemap( javaout ) ( PLINT n, const PLFLT * Array )
{
return $jnicall;
}
// trailing count, and check consistency with previous
%typemap( in ) ( const PLFLT * ArrayCk, PLINT n )
{
jPLFLT *jydata = ( *jenv )->GetPLFLTArrayElements( jenv, $input, 0 );
$2 = ( *jenv )->GetArrayLength( jenv, $input );
if ( ( *jenv )->GetArrayLength( jenv, $input ) != Alen )
{
printf( "Vectors must be same length.\n" );
return;
}
setup_array_1d_PLFLT( &$1, jydata, Alen );
( *jenv )->ReleasePLFLTArrayElements( jenv, $input, jydata, 0 );
}
%typemap( freearg ) ( const PLFLT * ArrayCk, PLINT n )
{
free( $1 );
}
%typemap( jni ) ( const PLFLT * ArrayCk, PLINT n ) jPLFLTArray
%typemap( jtype ) ( const PLFLT * ArrayCk, PLINT n ) jPLFLTbracket
%typemap( jstype ) ( const PLFLT * ArrayCk, PLINT n ) jPLFLTbracket
%typemap( javain ) ( const PLFLT * ArrayCk, PLINT n ) "$javainput"
%typemap( javaout ) ( const PLFLT * ArrayCk, PLINT n )
{
return $jnicall;
}
// no count, but check consistency with previous
%typemap( in ) const PLFLT * ArrayCk {
jPLFLT *jydata = ( *jenv )->GetPLFLTArrayElements( jenv, $input, 0 );
if ( ( *jenv )->GetArrayLength( jenv, $input ) != Alen )
{
printf( "Vectors must be same length.\n" );
return;
}
setup_array_1d_PLFLT( &$1, jydata, Alen );
( *jenv )->ReleasePLFLTArrayElements( jenv, $input, jydata, 0 );
}
%typemap( freearg ) const PLFLT * ArrayCk {
free( $1 );
}
%typemap( jni ) const PLFLT * ArrayCk jPLFLTArray
%typemap( jtype ) const PLFLT * ArrayCk jPLFLTbracket
%typemap( jstype ) const PLFLT * ArrayCk jPLFLTbracket
%typemap( javain ) const PLFLT * ArrayCk "$javainput"
%typemap( javaout ) const PLFLT * ArrayCk {
return $jnicall;
}
// trailing count, and check consistency with previous
%typemap( in ) ( const PLFLT * ArrayCkNull, PLINT n )
{
if ( $input != NULL )
{
jPLFLT *jydata = ( *jenv )->GetPLFLTArrayElements( jenv, $input, 0 );
$2 = ( *jenv )->GetArrayLength( jenv, $input );
if ( ( *jenv )->GetArrayLength( jenv, $input ) != Alen )
{
printf( "Vectors must be same length.\n" );
return;
}
setup_array_1d_PLFLT( &$1, jydata, Alen );
( *jenv )->ReleasePLFLTArrayElements( jenv, $input, jydata, 0 );
}
else
{
$1 = NULL;
$2 = 0;
}
}
%typemap( freearg ) ( const PLFLT * ArrayCkNull, PLINT n )
{
if ( $1 != NULL )
free( $1 );
}
%typemap( jni ) ( const PLFLT * ArrayCkNull, PLINT n ) jPLFLTArray
%typemap( jtype ) ( const PLFLT * ArrayCkNull, PLINT n ) jPLFLTbracket
%typemap( jstype ) ( const PLFLT * ArrayCkNull, PLINT n ) jPLFLTbracket
%typemap( javain ) ( const PLFLT * ArrayCkNull, PLINT n ) "$javainput"
%typemap( javaout ) ( const PLFLT * ArrayCkNull, PLINT n )
{
return $jnicall;
}
// no count, but check consistency with previous or NULL
%typemap( in ) const PLFLT * ArrayCkNull {
if ( $input != NULL )
{
jPLFLT *jydata = ( *jenv )->GetPLFLTArrayElements( jenv, $input, 0 );
if ( ( *jenv )->GetArrayLength( jenv, $input ) != Alen )
{
printf( "Vectors must be same length.\n" );
return;
}
setup_array_1d_PLFLT( &$1, jydata, Alen );
( *jenv )->ReleasePLFLTArrayElements( jenv, $input, jydata, 0 );
}
else
{
$1 = NULL;
}
}
%typemap( freearg ) const PLFLT * ArrayCkNull {
if ( $1 != NULL )
free( $1 );
}
%typemap( jni ) const PLFLT * ArrayCkNull jPLFLTArray
%typemap( jtype ) const PLFLT * ArrayCkNull jPLFLTbracket
%typemap( jstype ) const PLFLT * ArrayCkNull jPLFLTbracket
%typemap( javain ) const PLFLT * ArrayCkNull "$javainput"
%typemap( javaout ) const PLFLT * ArrayCkNull {
return $jnicall;
}
// set X length for later consistency checking
%typemap( in ) ( const PLFLT * ArrayX, PLINT nx )
{
jPLFLT *jxdata = ( *jenv )->GetPLFLTArrayElements( jenv, $input, 0 );
Xlen = ( *jenv )->GetArrayLength( jenv, $input );
$2 = Xlen;
setup_array_1d_PLFLT( &$1, jxdata, Xlen );
( *jenv )->ReleasePLFLTArrayElements( jenv, $input, jxdata, 0 );
}
%typemap( freearg ) ( const PLFLT * ArrayX, PLINT nx )
{
free( $1 );
}
%typemap( jni ) ( const PLFLT * ArrayX, PLINT nx ) jPLFLTArray
%typemap( jtype ) ( const PLFLT * ArrayX, PLINT nx ) jPLFLTbracket
%typemap( jstype ) ( const PLFLT * ArrayX, PLINT nx ) jPLFLTbracket
%typemap( javain ) ( const PLFLT * ArrayX, PLINT nx ) "$javainput"
%typemap( javaout ) ( const PLFLT * ArrayX, PLINT nx )
{
return $jnicall;
}
%typemap( in ) const PLFLT * ArrayX {
jPLFLT *jxdata = ( *jenv )->GetPLFLTArrayElements( jenv, $input, 0 );
Xlen = ( *jenv )->GetArrayLength( jenv, $input );
setup_array_1d_PLFLT( &$1, jxdata, Xlen );
( *jenv )->ReleasePLFLTArrayElements( jenv, $input, jxdata, 0 );
}
%typemap( freearg ) const PLFLT * ArrayX {
free( $1 );
}
%typemap( jni ) const PLFLT * ArrayX jPLFLTArray
%typemap( jtype ) const PLFLT * ArrayX jPLFLTbracket
%typemap( jstype ) const PLFLT * ArrayX jPLFLTbracket
%typemap( javain ) const PLFLT * ArrayX "$javainput"
%typemap( javaout ) const PLFLT * ArrayX {
return $jnicall;
}
// set Y length for later consistency checking
%typemap( in ) ( const PLFLT * ArrayY, PLINT ny )
{
jPLFLT *jydata = ( *jenv )->GetPLFLTArrayElements( jenv, $input, 0 );
Ylen = ( *jenv )->GetArrayLength( jenv, $input );
$2 = Ylen;
setup_array_1d_PLFLT( &$1, jydata, Ylen );
( *jenv )->ReleasePLFLTArrayElements( jenv, $input, jydata, 0 );
}
%typemap( freearg ) ( const PLFLT * ArrayY, PLINT ny )
{
free( $1 );
}
%typemap( jni ) ( const PLFLT * ArrayY, PLINT ny ) jPLFLTArray
%typemap( jtype ) ( const PLFLT * ArrayY, PLINT ny ) jPLFLTbracket
%typemap( jstype ) ( const PLFLT * ArrayY, PLINT ny ) jPLFLTbracket
%typemap( javain ) ( const PLFLT * ArrayY, PLINT ny ) "$javainput"
%typemap( javaout ) ( const PLFLT * ArrayY, PLINT ny )
{
return $jnicall;
}
%typemap( in ) const PLFLT * ArrayY {
jPLFLT *jydata = ( *jenv )->GetPLFLTArrayElements( jenv, $input, 0 );
Ylen = ( *jenv )->GetArrayLength( jenv, $input );
setup_array_1d_PLFLT( &$1, jydata, Ylen );
( *jenv )->ReleasePLFLTArrayElements( jenv, $input, jydata, 0 );
}
%typemap( freearg ) const PLFLT * ArrayY {
free( $1 );
}
%typemap( jni ) const PLFLT * ArrayY jPLFLTArray
%typemap( jtype ) const PLFLT * ArrayY jPLFLTbracket
%typemap( jstype ) const PLFLT * ArrayY jPLFLTbracket
%typemap( javain ) const PLFLT * ArrayY "$javainput"
%typemap( javaout ) const PLFLT * ArrayY {
return $jnicall;
}
// with trailing count
%typemap( in ) ( const PLFLT * Array, PLINT n )
{
jPLFLT *jxdata = ( *jenv )->GetPLFLTArrayElements( jenv, $input, 0 );
$2 = ( *jenv )->GetArrayLength( jenv, $input );
setup_array_1d_PLFLT( &$1, jxdata, $2 );
( *jenv )->ReleasePLFLTArrayElements( jenv, $input, jxdata, 0 );
}
%typemap( freearg ) ( const PLFLT * Array, PLINT n )
{
free( $1 );
}
%typemap( jni ) ( const PLFLT * Array, PLINT n ) jPLFLTArray
%typemap( jtype ) ( const PLFLT * Array, PLINT n ) jPLFLTbracket
%typemap( jstype ) ( const PLFLT * Array, PLINT n ) jPLFLTbracket
%typemap( javain ) ( const PLFLT * Array, PLINT n ) "$javainput"
%typemap( javaout ) ( const PLFLT * Array, PLINT n )
{
return $jnicall;
}
// with no trailing count
%typemap( in ) const PLFLT * Array {
jPLFLT *jxdata = ( *jenv )->GetPLFLTArrayElements( jenv, $input, 0 );
Alen = ( *jenv )->GetArrayLength( jenv, $input );
setup_array_1d_PLFLT( &$1, jxdata, Alen );
( *jenv )->ReleasePLFLTArrayElements( jenv, $input, jxdata, 0 );
}
%typemap( freearg ) const PLFLT * Array {
free( $1 );
}
%typemap( jni ) const PLFLT * Array jPLFLTArray
%typemap( jtype ) const PLFLT * Array jPLFLTbracket
%typemap( jstype ) const PLFLT * Array jPLFLTbracket
%typemap( javain ) const PLFLT * Array "$javainput"
%typemap( javaout ) const PLFLT * Array {
return $jnicall;
}
// with no trailing count
%typemap( in ) const PLFLT * ArrayNull {
if ( $input != NULL )
{
jPLFLT *jxdata = ( *jenv )->GetPLFLTArrayElements( jenv, $input, 0 );
Alen = ( *jenv )->GetArrayLength( jenv, $input );
setup_array_1d_PLFLT( &$1, jxdata, Alen );
( *jenv )->ReleasePLFLTArrayElements( jenv, $input, jxdata, 0 );
}
else
{
$1 = NULL;
Alen = 0;
}
}
%typemap( freearg ) const PLFLT * ArrayNull {
if ( $1 != NULL )
free( $1 );
}
%typemap( jni ) const PLFLT * ArrayNull jPLFLTArray
%typemap( jtype ) const PLFLT * ArrayNull jPLFLTbracket
%typemap( jstype ) const PLFLT * ArrayNull jPLFLTbracket
%typemap( javain ) const PLFLT * ArrayNull "$javainput"
%typemap( javaout ) const PLFLT * ArrayNull {
return $jnicall;
}
// check consistency with X dimension of previous
%typemap( in ) const PLFLT * ArrayCkX {
jPLFLT *jxdata = ( *jenv )->GetPLFLTArrayElements( jenv, $input, 0 );
if ( ( *jenv )->GetArrayLength( jenv, $input ) != Xlen )
{
printf( "Vectors must be same length.\n" );
return;
}
setup_array_1d_PLFLT( &$1, jxdata, Xlen );
( *jenv )->ReleasePLFLTArrayElements( jenv, $input, jxdata, 0 );
}
%typemap( freearg ) const PLFLT * ArrayCkX {
free( $1 );
}
%typemap( jni ) const PLFLT * ArrayCkX jPLFLTArray
%typemap( jtype ) const PLFLT * ArrayCkX jPLFLTbracket
%typemap( jstype ) const PLFLT * ArrayCkX jPLFLTbracket
%typemap( javain ) const PLFLT * ArrayCkX "$javainput"
%typemap( javaout ) const PLFLT * ArrayCkX {
return $jnicall;
}
// check consistency with Y dimension of previous
%typemap( in ) const PLFLT * ArrayCkY {
jPLFLT *jydata = ( *jenv )->GetPLFLTArrayElements( jenv, $input, 0 );
if ( ( *jenv )->GetArrayLength( jenv, $input ) != Ylen )
{
printf( "Vectors must be same length.\n" );
return;
}
setup_array_1d_PLFLT( &$1, jydata, Ylen );
( *jenv )->ReleasePLFLTArrayElements( jenv, $input, jydata, 0 );
}
%typemap( freearg ) const PLFLT * ArrayCkY {
free( $1 );
}
%typemap( jni ) const PLFLT * ArrayCkY jPLFLTArray
%typemap( jtype ) const PLFLT * ArrayCkY jPLFLTbracket