diff options
Diffstat (limited to 'modules/javasci/src')
30 files changed, 6236 insertions, 0 deletions
diff --git a/modules/javasci/src/c/.deps/.dirstamp b/modules/javasci/src/c/.deps/.dirstamp new file mode 100755 index 000000000..e69de29bb --- /dev/null +++ b/modules/javasci/src/c/.deps/.dirstamp diff --git a/modules/javasci/src/c/.deps/libjavasci2_la-javasci2_helper.Plo b/modules/javasci/src/c/.deps/libjavasci2_la-javasci2_helper.Plo new file mode 100755 index 000000000..f972c4ab4 --- /dev/null +++ b/modules/javasci/src/c/.deps/libjavasci2_la-javasci2_helper.Plo @@ -0,0 +1,271 @@ +src/c/libjavasci2_la-javasci2_helper.lo: src/c/javasci2_helper.c \ + /usr/include/stdc-predef.h /usr/include/stdlib.h /usr/include/features.h \ + /usr/include/x86_64-linux-gnu/sys/cdefs.h \ + /usr/include/x86_64-linux-gnu/bits/wordsize.h \ + /usr/include/x86_64-linux-gnu/gnu/stubs.h \ + /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h \ + /usr/include/x86_64-linux-gnu/bits/waitflags.h \ + /usr/include/x86_64-linux-gnu/bits/waitstatus.h /usr/include/endian.h \ + /usr/include/x86_64-linux-gnu/bits/endian.h \ + /usr/include/x86_64-linux-gnu/bits/byteswap.h \ + /usr/include/x86_64-linux-gnu/bits/types.h \ + /usr/include/x86_64-linux-gnu/bits/typesizes.h \ + /usr/include/x86_64-linux-gnu/bits/byteswap-16.h \ + /usr/include/x86_64-linux-gnu/sys/types.h /usr/include/time.h \ + /usr/include/x86_64-linux-gnu/sys/select.h \ + /usr/include/x86_64-linux-gnu/bits/select.h \ + /usr/include/x86_64-linux-gnu/bits/sigset.h \ + /usr/include/x86_64-linux-gnu/bits/time.h \ + /usr/include/x86_64-linux-gnu/bits/select2.h \ + /usr/include/x86_64-linux-gnu/sys/sysmacros.h \ + /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h \ + /usr/include/x86_64-linux-gnu/bits/stdlib-float.h \ + /usr/include/x86_64-linux-gnu/bits/stdlib.h /usr/include/string.h \ + /usr/include/xlocale.h /usr/include/x86_64-linux-gnu/bits/string.h \ + /usr/include/x86_64-linux-gnu/bits/string2.h \ + /usr/include/x86_64-linux-gnu/bits/string3.h src/c/javasci2_helper.h \ + ../../modules/core/includes/BOOL.h \ + ../../modules/core/includes/sci_types.h \ + ../../modules/api_scilab/includes/api_scilab.h \ + ../../modules/core/includes/stack-c.h \ + ../../modules/core/includes/core_math.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h \ + /usr/include/limits.h /usr/include/x86_64-linux-gnu/bits/posix1_lim.h \ + /usr/include/x86_64-linux-gnu/bits/local_lim.h \ + /usr/include/linux/limits.h \ + /usr/include/x86_64-linux-gnu/bits/posix2_lim.h /usr/include/math.h \ + /usr/include/x86_64-linux-gnu/bits/math-vector.h \ + /usr/include/x86_64-linux-gnu/bits/libm-simd-decl-stubs.h \ + /usr/include/x86_64-linux-gnu/bits/huge_val.h \ + /usr/include/x86_64-linux-gnu/bits/huge_valf.h \ + /usr/include/x86_64-linux-gnu/bits/huge_vall.h \ + /usr/include/x86_64-linux-gnu/bits/inf.h \ + /usr/include/x86_64-linux-gnu/bits/nan.h \ + /usr/include/x86_64-linux-gnu/bits/mathdef.h \ + /usr/include/x86_64-linux-gnu/bits/mathcalls.h \ + /usr/include/x86_64-linux-gnu/bits/mathinline.h \ + ../../modules/core/includes/stack-def.h \ + ../../modules/core/includes/machine.h \ + ../../modules/core/includes/stackTypeVariable.h \ + ../../modules/core/includes/BOOL.h \ + ../../modules/core/includes/doublecomplex.h \ + ../../modules/core/includes/stack1.h \ + ../../modules/core/includes/scisparse.h \ + ../../modules/core/includes/stack2.h \ + ../../modules/core/includes/stack3.h \ + ../../modules/core/includes/stack-optional.h \ + ../../modules/core/includes/sci_types.h \ + ../../modules/api_scilab/includes/api_common.h \ + ../../modules/api_scilab/includes/api_scilab.h \ + ../../modules/api_scilab/includes/api_double.h \ + ../../modules/core/includes/doublecomplex.h \ + ../../modules/api_scilab/includes/api_string.h /usr/include/wchar.h \ + /usr/include/stdio.h /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \ + /usr/include/x86_64-linux-gnu/bits/wchar.h \ + /usr/include/x86_64-linux-gnu/bits/wchar2.h \ + ../../modules/api_scilab/includes/api_int.h \ + ../../modules/api_scilab/includes/api_poly.h \ + ../../modules/api_scilab/includes/api_sparse.h \ + ../../modules/api_scilab/includes/api_boolean.h \ + ../../modules/api_scilab/includes/api_boolean_sparse.h \ + ../../modules/api_scilab/includes/api_pointer.h \ + ../../modules/api_scilab/includes/api_list.h \ + ../../modules/api_scilab/includes/api_error.h \ + ../../modules/api_scilab/includes/api_handle.h \ + ../../modules/api_scilab/includes/api_optional.h \ + ../../modules/core/includes/stack-optional.h \ + ../../modules/api_scilab/includes/api_hypermat.h \ + ../../modules/core/includes/core_math.h \ + ../../modules/output_stream/includes/lasterror.h \ + ../../modules/output_stream/includes/dynlib_output_stream.h + +/usr/include/stdc-predef.h: + +/usr/include/stdlib.h: + +/usr/include/features.h: + +/usr/include/x86_64-linux-gnu/sys/cdefs.h: + +/usr/include/x86_64-linux-gnu/bits/wordsize.h: + +/usr/include/x86_64-linux-gnu/gnu/stubs.h: + +/usr/include/x86_64-linux-gnu/gnu/stubs-64.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h: + +/usr/include/x86_64-linux-gnu/bits/waitflags.h: + +/usr/include/x86_64-linux-gnu/bits/waitstatus.h: + +/usr/include/endian.h: + +/usr/include/x86_64-linux-gnu/bits/endian.h: + +/usr/include/x86_64-linux-gnu/bits/byteswap.h: + +/usr/include/x86_64-linux-gnu/bits/types.h: + +/usr/include/x86_64-linux-gnu/bits/typesizes.h: + +/usr/include/x86_64-linux-gnu/bits/byteswap-16.h: + +/usr/include/x86_64-linux-gnu/sys/types.h: + +/usr/include/time.h: + +/usr/include/x86_64-linux-gnu/sys/select.h: + +/usr/include/x86_64-linux-gnu/bits/select.h: + +/usr/include/x86_64-linux-gnu/bits/sigset.h: + +/usr/include/x86_64-linux-gnu/bits/time.h: + +/usr/include/x86_64-linux-gnu/bits/select2.h: + +/usr/include/x86_64-linux-gnu/sys/sysmacros.h: + +/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h: + +/usr/include/alloca.h: + +/usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h: + +/usr/include/x86_64-linux-gnu/bits/stdlib-float.h: + +/usr/include/x86_64-linux-gnu/bits/stdlib.h: + +/usr/include/string.h: + +/usr/include/xlocale.h: + +/usr/include/x86_64-linux-gnu/bits/string.h: + +/usr/include/x86_64-linux-gnu/bits/string2.h: + +/usr/include/x86_64-linux-gnu/bits/string3.h: + +src/c/javasci2_helper.h: + +../../modules/core/includes/BOOL.h: + +../../modules/core/includes/sci_types.h: + +../../modules/api_scilab/includes/api_scilab.h: + +../../modules/core/includes/stack-c.h: + +../../modules/core/includes/core_math.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h: + +/usr/include/limits.h: + +/usr/include/x86_64-linux-gnu/bits/posix1_lim.h: + +/usr/include/x86_64-linux-gnu/bits/local_lim.h: + +/usr/include/linux/limits.h: + +/usr/include/x86_64-linux-gnu/bits/posix2_lim.h: + +/usr/include/math.h: + +/usr/include/x86_64-linux-gnu/bits/math-vector.h: + +/usr/include/x86_64-linux-gnu/bits/libm-simd-decl-stubs.h: + +/usr/include/x86_64-linux-gnu/bits/huge_val.h: + +/usr/include/x86_64-linux-gnu/bits/huge_valf.h: + +/usr/include/x86_64-linux-gnu/bits/huge_vall.h: + +/usr/include/x86_64-linux-gnu/bits/inf.h: + +/usr/include/x86_64-linux-gnu/bits/nan.h: + +/usr/include/x86_64-linux-gnu/bits/mathdef.h: + +/usr/include/x86_64-linux-gnu/bits/mathcalls.h: + +/usr/include/x86_64-linux-gnu/bits/mathinline.h: + +../../modules/core/includes/stack-def.h: + +../../modules/core/includes/machine.h: + +../../modules/core/includes/stackTypeVariable.h: + +../../modules/core/includes/BOOL.h: + +../../modules/core/includes/doublecomplex.h: + +../../modules/core/includes/stack1.h: + +../../modules/core/includes/scisparse.h: + +../../modules/core/includes/stack2.h: + +../../modules/core/includes/stack3.h: + +../../modules/core/includes/stack-optional.h: + +../../modules/core/includes/sci_types.h: + +../../modules/api_scilab/includes/api_common.h: + +../../modules/api_scilab/includes/api_scilab.h: + +../../modules/api_scilab/includes/api_double.h: + +../../modules/core/includes/doublecomplex.h: + +../../modules/api_scilab/includes/api_string.h: + +/usr/include/wchar.h: + +/usr/include/stdio.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h: + +/usr/include/x86_64-linux-gnu/bits/wchar.h: + +/usr/include/x86_64-linux-gnu/bits/wchar2.h: + +../../modules/api_scilab/includes/api_int.h: + +../../modules/api_scilab/includes/api_poly.h: + +../../modules/api_scilab/includes/api_sparse.h: + +../../modules/api_scilab/includes/api_boolean.h: + +../../modules/api_scilab/includes/api_boolean_sparse.h: + +../../modules/api_scilab/includes/api_pointer.h: + +../../modules/api_scilab/includes/api_list.h: + +../../modules/api_scilab/includes/api_error.h: + +../../modules/api_scilab/includes/api_handle.h: + +../../modules/api_scilab/includes/api_optional.h: + +../../modules/core/includes/stack-optional.h: + +../../modules/api_scilab/includes/api_hypermat.h: + +../../modules/core/includes/core_math.h: + +../../modules/output_stream/includes/lasterror.h: + +../../modules/output_stream/includes/dynlib_output_stream.h: diff --git a/modules/javasci/src/c/.dirstamp b/modules/javasci/src/c/.dirstamp new file mode 100755 index 000000000..e69de29bb --- /dev/null +++ b/modules/javasci/src/c/.dirstamp diff --git a/modules/javasci/src/c/.libs/libjavasci2_la-javasci2_helper.o b/modules/javasci/src/c/.libs/libjavasci2_la-javasci2_helper.o Binary files differnew file mode 100755 index 000000000..fe70acf09 --- /dev/null +++ b/modules/javasci/src/c/.libs/libjavasci2_la-javasci2_helper.o diff --git a/modules/javasci/src/c/DllmainJavasci.c b/modules/javasci/src/c/DllmainJavasci.c new file mode 100755 index 000000000..4b23d9192 --- /dev/null +++ b/modules/javasci/src/c/DllmainJavasci.c @@ -0,0 +1,33 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2005 - INRIA - Allan CORNET + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ + +#include <windows.h> +/*--------------------------------------------------------------------------*/ +#pragma comment(lib,"../../bin/libintl.lib") +/*--------------------------------------------------------------------------*/ +int WINAPI DllMain (HINSTANCE hInstance , DWORD reason, PVOID pvReserved) +{ + switch (reason) + { + case DLL_PROCESS_ATTACH: + break; + case DLL_PROCESS_DETACH: + break; + case DLL_THREAD_ATTACH: + break; + case DLL_THREAD_DETACH: + break; + } + return 1; +} +/*--------------------------------------------------------------------------*/ + diff --git a/modules/javasci/src/c/javasci2_helper.c b/modules/javasci/src/c/javasci2_helper.c new file mode 100755 index 000000000..1420dcc2a --- /dev/null +++ b/modules/javasci/src/c/javasci2_helper.c @@ -0,0 +1,623 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +#include <stdlib.h> +#include <string.h> + +#define ENABLE_HELPERS +#include "javasci2_helper.h" +#include "api_scilab.h" +#include "lasterror.h" + +BOOL isComplexVar(char *variableName) +{ + /* 0 = not complex */ + return isNamedVarComplex(pvApiCtx, variableName) != 0; +} + +sci_int_types getIntegerPrecision(char *variableName) +{ + SciErr sciErr; + int iPrec; + + sciErr = getNamedMatrixOfIntegerPrecision(pvApiCtx, variableName, &iPrec); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return sciErr.iErr; + } + return iPrec; +} + +double *getDouble(char *variableName, int *nbRow, int *nbCol) +{ + SciErr sciErr; + double *matrixOfDouble = NULL; + + sciErr = readNamedMatrixOfDouble(pvApiCtx, variableName, nbRow, nbCol, NULL); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + /* Alloc the memory */ + matrixOfDouble = (double *)malloc(((*nbRow) * (*nbCol)) * sizeof(double)); + + /* Load the matrix */ + sciErr = readNamedMatrixOfDouble(pvApiCtx, variableName, nbRow, nbCol, matrixOfDouble); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + return matrixOfDouble; + +} + +int putDouble(char *variableName, double *variable, int nbRow, int nbCol) +{ + SciErr sciErr; + + sciErr = createNamedMatrixOfDouble(pvApiCtx, variableName, nbRow, nbCol, variable); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return -1; + } + return 0; +} + +double *getDoubleComplexReal(char *variableName, int *nbRow, int *nbCol) +{ + SciErr sciErr; + double *matrixOfDoubleComplexReal = NULL; + double *matrixOfDoubleComplexImg = NULL; + + sciErr = readNamedComplexMatrixOfDouble(pvApiCtx, variableName, nbRow, nbCol, NULL, NULL); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + /* Alloc the memory */ + matrixOfDoubleComplexReal = (double *)malloc(((*nbRow) * (*nbCol)) * sizeof(double)); + matrixOfDoubleComplexImg = (double *)malloc(((*nbRow) * (*nbCol)) * sizeof(double)); + + /* Load the matrix */ + sciErr = readNamedComplexMatrixOfDouble(pvApiCtx, variableName, nbRow, nbCol, matrixOfDoubleComplexReal, matrixOfDoubleComplexImg); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + return matrixOfDoubleComplexReal; +} + +double *getDoubleComplexImg(char *variableName, int *nbRow, int *nbCol) +{ + SciErr sciErr; + double *matrixOfDoubleComplexReal = NULL; + double *matrixOfDoubleComplexImg = NULL; + + sciErr = readNamedComplexMatrixOfDouble(pvApiCtx, variableName, nbRow, nbCol, NULL, NULL); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + /* Alloc the memory */ + matrixOfDoubleComplexReal = (double *)malloc(((*nbRow) * (*nbCol)) * sizeof(double)); + matrixOfDoubleComplexImg = (double *)malloc(((*nbRow) * (*nbCol)) * sizeof(double)); + + /* Load the matrix */ + sciErr = readNamedComplexMatrixOfDouble(pvApiCtx, variableName, nbRow, nbCol, matrixOfDoubleComplexReal, matrixOfDoubleComplexImg); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + return matrixOfDoubleComplexImg; + +} + +int putDoubleComplex(char* variableName, double *variable, int nbRow, int nbCol, double * imag, int nbRowI, int nbColI) +{ + SciErr sciErr; + + sciErr = createNamedComplexMatrixOfDouble(pvApiCtx, variableName, nbRow, nbCol, variable, imag); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return -1; + } + return 0; +} + +BOOL *getBoolean(char *variableName, int *nbRow, int *nbCol) +{ + SciErr sciErr; + BOOL *matrixOfBoolean = NULL; + + sciErr = readNamedMatrixOfBoolean(pvApiCtx, variableName, nbRow, nbCol, NULL); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + /* Alloc the memory */ + matrixOfBoolean = (BOOL *) malloc(((*nbRow) * (*nbCol)) * sizeof(BOOL)); + + /* Load the matrix */ + sciErr = readNamedMatrixOfBoolean(pvApiCtx, variableName, nbRow, nbCol, matrixOfBoolean); + + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + return matrixOfBoolean; + +} + +int putBoolean(char *variableName, BOOL * variable, int nbRow, int nbCol) +{ + SciErr sciErr; + + sciErr = createNamedMatrixOfBoolean(pvApiCtx, variableName, nbRow, nbCol, variable); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return -1; + } + return 0; + +} + +///////////////////// byte / int8 +byte *getByte(char *variableName, int *nbRow, int *nbCol) +{ + SciErr sciErr; + byte *matrixOfByte = NULL; + + sciErr = readNamedMatrixOfInteger8(pvApiCtx, variableName, nbRow, nbCol, NULL); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + /* Alloc the memory */ + matrixOfByte = (byte *) malloc(((*nbRow) * (*nbCol)) * sizeof(byte)); + + /* Load the matrix */ + sciErr = readNamedMatrixOfInteger8(pvApiCtx, variableName, nbRow, nbCol, (char *)matrixOfByte); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + return matrixOfByte; + +} + +int putByte(char *variableName, byte * variable, int nbRow, int nbCol) +{ + SciErr sciErr; + + sciErr = createNamedMatrixOfInteger8(pvApiCtx, variableName, nbRow, nbCol, (const char *)variable); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return -1; + } + return 0; +} + +byte *getUnsignedByte(char *variableName, int *nbRow, int *nbCol) +{ + SciErr sciErr; + byte *matrixOfByte = NULL; + + sciErr = readNamedMatrixOfUnsignedInteger8(pvApiCtx, variableName, nbRow, nbCol, NULL); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + /* Alloc the memory */ + matrixOfByte = (byte *) malloc(((*nbRow) * (*nbCol)) * sizeof(byte)); + + /* Load the matrix */ + sciErr = readNamedMatrixOfUnsignedInteger8(pvApiCtx, variableName, nbRow, nbCol, matrixOfByte); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + return matrixOfByte; + +} + +int putUnsignedByte(char *variableName, byte * variable, int nbRow, int nbCol) +{ + SciErr sciErr; + + sciErr = createNamedMatrixOfUnsignedInteger8(pvApiCtx, variableName, nbRow, nbCol, variable); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return -1; + } + return 0; +} + +//////////////////////////// short / int16 + +short *getShort(char *variableName, int *nbRow, int *nbCol) +{ + SciErr sciErr; + short *matrixOfShort = NULL; + + sciErr = readNamedMatrixOfInteger16(pvApiCtx, variableName, nbRow, nbCol, NULL); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + /* Alloc the memory */ + matrixOfShort = (short *)malloc(((*nbRow) * (*nbCol)) * sizeof(short)); + + /* Load the matrix */ + sciErr = readNamedMatrixOfInteger16(pvApiCtx, variableName, nbRow, nbCol, matrixOfShort); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + return matrixOfShort; + +} + +int putShort(char *variableName, short *variable, int nbRow, int nbCol) +{ + SciErr sciErr; + + sciErr = createNamedMatrixOfInteger16(pvApiCtx, variableName, nbRow, nbCol, variable); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return -1; + } + return 0; +} + +unsigned short *getUnsignedShort(char *variableName, int *nbRow, int *nbCol) +{ + SciErr sciErr; + unsigned short *matrixOfShort = NULL; + + sciErr = readNamedMatrixOfUnsignedInteger16(pvApiCtx, variableName, nbRow, nbCol, NULL); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + /* Alloc the memory */ + matrixOfShort = (unsigned short *)malloc(((*nbRow) * (*nbCol)) * sizeof(unsigned short)); + + /* Load the matrix */ + sciErr = readNamedMatrixOfUnsignedInteger16(pvApiCtx, variableName, nbRow, nbCol, matrixOfShort); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + return matrixOfShort; + +} + +int putUnsignedShort(char *variableName, unsigned short *variable, int nbRow, int nbCol) +{ + SciErr sciErr; + + sciErr = createNamedMatrixOfUnsignedInteger16(pvApiCtx, variableName, nbRow, nbCol, variable); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return -1; + } + return 0; +} + +////////////////////// int / int32 + +int *getInt(char *variableName, int *nbRow, int *nbCol) +{ + SciErr sciErr; + int *matrixOfInt = NULL; + + sciErr = readNamedMatrixOfInteger32(pvApiCtx, variableName, nbRow, nbCol, NULL); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + /* Alloc the memory */ + matrixOfInt = (int *)malloc(((*nbRow) * (*nbCol)) * sizeof(int)); + + /* Load the matrix */ + sciErr = readNamedMatrixOfInteger32(pvApiCtx, variableName, nbRow, nbCol, matrixOfInt); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + return matrixOfInt; + +} + +int putInt(char *variableName, int *variable, int nbRow, int nbCol) +{ + SciErr sciErr; + + sciErr = createNamedMatrixOfInteger32(pvApiCtx, variableName, nbRow, nbCol, variable); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return -1; + } + return 0; +} + +unsigned int *getUnsignedInt(char *variableName, int *nbRow, int *nbCol) +{ + SciErr sciErr; + int *matrixOfInt = NULL; + + sciErr = readNamedMatrixOfUnsignedInteger32(pvApiCtx, variableName, nbRow, nbCol, NULL); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + /* Alloc the memory */ + matrixOfInt = (int *)malloc(((*nbRow) * (*nbCol)) * sizeof(int)); + + /* Load the matrix */ + sciErr = readNamedMatrixOfUnsignedInteger32(pvApiCtx, variableName, nbRow, nbCol, (unsigned int *)matrixOfInt); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + return (unsigned int *)matrixOfInt; + +} + +int putUnsignedInt(char *variableName, unsigned int *variable, int nbRow, int nbCol) +{ + SciErr sciErr; + + sciErr = createNamedMatrixOfUnsignedInteger32(pvApiCtx, variableName, nbRow, nbCol, variable); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return -1; + } + return 0; +} + +////////////////////// long / int64 +#ifdef __SCILAB_INT64__ + +long *getLong(char *variableName, int *nbRow, int *nbCol) +{ + SciErr sciErr; + long *matrixOfLong = NULL; + + sciErr = readNamedMatrixOfInteger64(pvApiCtx, variableName, nbRow, nbCol, NULL); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + /* Alloc the memory */ + matrixOfLong = (long *)malloc(((*nbRow) * (*nbCol)) * sizeof(long)); + + /* Load the matrix */ + sciErr = readNamedMatrixOfInteger64(pvApiCtx, variableName, nbRow, nbCol, matrixOfLong); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + return matrixOfLong; + +} + +int putLong(char *variableName, long *variable, int *nbRow, int *nbCol) +{ + SciErr sciErr; + + sciErr = createNamedMatrixOfInteger64(pvApiCtx, variableName, nbRow, nbCol, variable); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return -1; + } + return 0; +} + +unsigned long *getUnsignedLong(char *variableName, int *nbRow, int *nbCol) +{ + SciErr sciErr; + long *matrixOfLong = NULL; + + sciErr = readNamedMatrixOfUnsignedInteger64(pvApiCtx, variableName, nbRow, nbCol, NULL); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + /* Alloc the memory */ + matrixOfLong = (long *)malloc(((*nbRow) * (*nbCol)) * sizeof(long)); + + /* Load the matrix */ + sciErr = readNamedMatrixOfUnsignedInteger64(pvApiCtx, variableName, nbRow, nbCol, matrixOfLong); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + return matrixOfLong; + +} + +int putUnsignedLong(char *variableName, unsigned long *variable, int *nbRow, int *nbCol) +{ + SciErr sciErr; + + sciErr = createNamedMatrixOfUnsignedInteger64(pvApiCtx, variableName, nbRow, nbCol, variable); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return -1; + } + return 0; +} + +#endif + +char **getString(char *variableName, int *nbRow, int *nbCol) +{ + SciErr sciErr; + int i = 0; + + int *piLen = NULL; + char **pstData = NULL; + + //first call to retrieve dimensions + sciErr = readNamedMatrixOfString(pvApiCtx, variableName, nbRow, nbCol, NULL, NULL); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + piLen = (int *)malloc(sizeof(int) * (*nbRow) * (*nbCol)); + + //second call to retrieve length of each string + sciErr = readNamedMatrixOfString(pvApiCtx, variableName, nbRow, nbCol, piLen, NULL); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + pstData = (char **)malloc(sizeof(char *) * (*nbRow) * (*nbCol)); + + for (i = 0; i < (*nbRow) * (*nbCol); i++) + { + pstData[i] = (char *)malloc(sizeof(char) * (piLen[i] + 1)); //+ 1 for null termination + } + //third call to retrieve data + sciErr = readNamedMatrixOfString(pvApiCtx, variableName, nbRow, nbCol, piLen, pstData); + if (sciErr.iErr) + { + printError(&sciErr, 0); + } + + return pstData; + +} + +int putString(char *variableName, char **variable, int nbRow, int nbCol) +{ + SciErr sciErr; + + sciErr = createNamedMatrixOfString(pvApiCtx, variableName, nbRow, nbCol, variable); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return -1; + } + return 0; +} + +int putSparse(char * variableName, int nbRow, int nbCol, int * nbRowItem, int nbRowItemL, int * colPos, int colPosL, double * data, int dataL) +{ + SciErr sciErr; + + sciErr = createNamedSparseMatrix(pvApiCtx, variableName, nbRow, nbCol, colPosL, nbRowItem, colPos, data); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return -1; + } + return 0; +} + +int putComplexSparse(char * variableName, int nbRow, int nbCol, int * nbRowItem, int nbRowItemL, int * colPos, int colPosL, double * data, int dataL, double * imag, int imagL) +{ + SciErr sciErr; + + sciErr = createNamedComplexSparseMatrix(pvApiCtx, variableName, nbRow, nbCol, colPosL, nbRowItem, colPos, data, imag); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return -1; + } + return 0; +} + +int putBooleanSparse(char * variableName, int nbRow, int nbCol, int * nbRowItem, int nbRowItemL, int * colPos, int colPosL) +{ + SciErr sciErr; + + sciErr = createNamedBooleanSparseMatrix(pvApiCtx, variableName, nbRow, nbCol, colPosL, nbRowItem, colPos); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return -1; + } + return 0; +} + +int putPolynomial(char * variableName, char * polyVarName, double ** data, int nbRow, int nbCol, int * nbCoef) +{ + SciErr sciErr; + + sciErr = createNamedMatrixOfPoly(pvApiCtx, variableName, polyVarName, nbRow, nbCol, nbCoef, data); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return -1; + } + return 0; +} + +int putComplexPolynomial(char * variableName, char * polyVarName, double ** data, int nbRow, int nbCol, int * nbCoef, double ** imag, int nbRowI, int nbColI, int * nbCoefI) +{ + SciErr sciErr; + + sciErr = createNamedComplexMatrixOfPoly(pvApiCtx, variableName, polyVarName, nbRow, nbCol, nbCoef, data, imag); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return -1; + } + return 0; +} + + +BOOL isExistingVariable(char *variableName) +{ + int iExisting = isNamedVarExist(pvApiCtx, variableName); + + return iExisting != 0; /* 0 = not existing variable */ +} diff --git a/modules/javasci/src/c/javasci2_helper.h b/modules/javasci/src/c/javasci2_helper.h new file mode 100755 index 000000000..5b14a8c2e --- /dev/null +++ b/modules/javasci/src/c/javasci2_helper.h @@ -0,0 +1,403 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ + +#ifndef __JAVASCI2_HELPER_H__ +#define __JAVASCI2_HELPER_H__ + +/** + * This header describes a serie of helper functions. + * This function should be only used when writing a wrapper of Scilab into an + * other language (Java). + * All these functions are based on api_scilab. They provide a simple profile + * to be easily integrate into a SWIG wrapper. + */ + +#ifndef ENABLE_HELPERS +#error "This file cannot be used directly" +#endif +#include "BOOL.h" +#include "sci_types.h" + +typedef unsigned char byte; + +/** + * If the variable is complex or not + * + * @param variableName The name of the variable + * @return TRUE is complex, FALSE otherwise + */ +BOOL isComplex(char *variableName); + +/** + * Return the precision of an integer + * + * @param variableName The name of tbe variable + * @return the type of the integer (see sci_int_types) + */ +sci_int_types getIntegerPrecision(char* variableName); + + +/** + * Return a matrix of double (the default type in Scilab) + * + * @param variableName The name of the variable + * @param[out] nbRow Number of rows + * @param[out] nbCol Number of cols + * @return The matrix of double (column sorted) + */ +double * getDouble(char* variableName, int *nbRow, int *nbCol); + +/** + * Set a matrix of double (the default type in Scilab) + * + * @param variableName The name of the variable + * @param variable The values + * @param nbRow Number of rows + * @param nbCol Number of cols + * @return 0 if successfull, != 0 otherwise + */ +int putDouble(char* variableName, double *variable, int nbRow, int nbCol); + +/** + * Return the real part of a matrix of complex double + * + * @param variableName The name of the variable + * @param[out] nbRow Number of rows + * @param[out] nbCol Number of cols + * @return The real part of a matrix of complex double (column sorted) + */ +double * getDoubleComplexReal(char* variableName, int *nbRow, int *nbCol); + +/** + * Return the imaginary part of a matrix of complex double + * + * @param variableName The name of the variable + * @param[out] nbRow Number of rows + * @param[out] nbCol Number of cols + * @return The imaginary part of a matrix of complex double (column sorted) + */ +double * getDoubleComplexImg(char* variableName, int *nbRow, int *nbCol); + +/** + * Set a matrix of complex double + * + * @param variableName The name of the variable + * @param variable The complex values + * @param nbRow Number of rows + * @param nbCol Number of cols + * @return 0 if successfull, != 0 otherwise + */ +int putDoubleComplex(char* variableName, double *variable, int nbRow, int nbCol, double * imag, int nbRowI, int nbColI); + +/** + * Return a matrix of boolean + * + * @param variableName The name of the variable + * @param[out] nbRow Number of rows + * @param[out] nbCol Number of cols + * @return The matrix of boolean (column sorted) + */ +BOOL * getBoolean(char* variableName, int *nbRow, int *nbCol); + +/** + * Set a matrix of boolean + * + * @param variableName The name of the variable + * @param variable The values + * @param nbRow Number of rows + * @param nbCol Number of cols + * @return 0 if successfull, != 0 otherwise + */ +int putBoolean(char* variableName, BOOL *variable, int nbRow, int nbCol); + +/** + * Return a matrix of byte (int8) + * + * @param variableName The name of the variable + * @param[out] nbRow Number of rows + * @param[out] nbCol Number of cols + * @return The matrix of byte (column sorted) + */ +byte * getByte(char* variableName, int *nbRow, int *nbCol); + +/** + * Set a matrix of byte (int8) + * + * @param variableName The name of the variable + * @param variable The values + * @param nbRow Number of rows + * @param nbCol Number of cols + * @return 0 if successfull, != 0 otherwise + */ +int putByte(char* variableName, byte *variable, int nbRow, int nbCol); + +/** + * Return a matrix of unsigned byte (uint8) + * + * @param variableName The name of the variable + * @param[out] nbRow Number of rows + * @param[out] nbCol Number of cols + * @return The matrix of unsigned byte (column sorted) + */ +byte * getUnsignedByte(char* variableName, int *nbRow, int *nbCol); + +/** + * Set a matrix of unsigned byte (uint8) + * + * @param variableName The name of the variable + * @param variable The values + * @param nbRow Number of rows + * @param nbCol Number of cols + * @return 0 if successfull, != 0 otherwise + */ +int putUnsignedByte(char* variableName, byte *variable, int nbRow, int nbCol); + +/** + * Return a matrix of short (int16) + * + * @param variableName The name of the variable + * @param[out] nbRow Number of rows + * @param[out] nbCol Number of cols + * @return The matrix of short (column sorted) + */ +short * getShort(char* variableName, int *nbRow, int *nbCol); + +/** + * Set a matrix of short (int16) + * + * @param variableName The name of the variable + * @param variable The values + * @param nbRow Number of rows + * @param nbCol Number of cols + * @return 0 if successfull, != 0 otherwise + */ +int putShort(char* variableName, short *variable, int nbRow, int nbCol); + +/** + * Return a matrix of unsigned short (uint16) + * + * @param variableName The name of the variable + * @param[out] nbRow Number of rows + * @param[out] nbCol Number of cols + * @return The matrix of unsigned short (column sorted) + */ +unsigned short * getUnsignedShort(char* variableName, int *nbRow, int *nbCol); + +/** + * Set a matrix of unsigned short (uint16) + * + * @param variableName The name of the variable + * @param variable The values + * @param nbRow Number of rows + * @param nbCol Number of cols + * @return 0 if successfull, != 0 otherwise + */ +int putUnsignedShort(char* variableName, unsigned short *variable, int nbRow, int nbCol); + +/** + * Return a matrix of integer (int32) + * + * @param variableName The name of the variable + * @param[out] nbRow Number of rows + * @param[out] nbCol Number of cols + * @return The matrix of integer (column sorted) + */ +int * getInt(char* variableName, int *nbRow, int *nbCol); + +/** + * Set a matrix of integer (int32) + * + * @param variableName The name of the variable + * @param variable The values + * @param nbRow Number of rows + * @param nbCol Number of cols + * @return 0 if successfull, != 0 otherwise + */ +int putInt(char* variableName, int *variable, int nbRow, int nbCol); + +/** + * Return a matrix of unsigned integer (uint32) + * + * @param variableName The name of the variable + * @param[out] nbRow Number of rows + * @param[out] nbCol Number of cols + * @return The matrix of unsigned integer (column sorted) + */ +unsigned int * getUnsignedInt(char* variableName, int *nbRow, int *nbCol); + +/** + * Set a matrix of unsigned integer (uint32) + * + * @param variableName The name of the variable + * @param variable The values + * @param nbRow Number of rows + * @param nbCol Number of cols + * @return 0 if successfull, != 0 otherwise + */ +int putUnsignedInt(char* variableName, unsigned int *variable, int nbRow, int nbCol); + +/** + * Return a matrix of long (int64) + * + * @param variableName The name of the variable + * @param[out] nbRow Number of rows + * @param[out] nbCol Number of cols + * @return The matrix of long (column sorted) + */ +long * getLong(char* variableName, int *nbRow, int *nbCol); + +/** + * Set a matrix of long (int64) + * + * @param variableName The name of the variable + * @param variable The values + * @param nbRow Number of rows + * @param nbCol Number of cols + * @return 0 if successfull, != 0 otherwise + */ +int putLong(char* variableName, long *variable, int nbRow, int nbCol); + +/** + * Return a matrix of unsigned long (uint64) + * + * @param variableName The name of the variable + * @param[out] nbRow Number of rows + * @param[out] nbCol Number of cols + * @return The matrix of unsigned long (column sorted) + */ +unsigned long * getUnsignedLong(char* variableName, int *nbRow, int *nbCol); + +/** + * Set a matrix of unsigned long (int64) + * + * @param variableName The name of the variable + * @param variable The values + * @param nbRow Number of rows + * @param nbCol Number of cols + * @return 0 if successfull, != 0 otherwise + */ +int putUnsignedLong(char* variableName, unsigned long *variable, int nbRow, int nbCol); + +/** + * Return a matrix of string + * + * @param variableName The name of the variable + * @param[out] nbRow Number of rows + * @param[out] nbCol Number of cols + * @return The matrix of string (column sorted) + */ +char ** getString(char* variableName, int *nbRow, int *nbCol); + +/** + * Set a matrix of string + * + * @param variableName The name of the variable + * @param variable The values + * @param nbRow Number of rows + * @param nbCol Number of cols + * @return 0 if successfull, != 0 otherwise + */ +int putString(char* variableName, char **variable, int nbRow, int nbCol); + +/** + * Set a sparse matrix + * + * @param variableName The name of the variable + * @param nbRow Number of rows + * @param nbCol Number of cols + * @param nbRowItem the number of non null items by row + * @param nbRowItemL the length of the previous array + * @param colPos the column position of each non null item + * @param colPosL the length of the previous array + * @param data the double data + * @param dataL the length of the previous array + * @return 0 if successfull, != 0 otherwise + */ +int putSparse(char * variableName, int nbRow, int nbCol, int * nbRowItem, int nbRowItemL, int * colPos, int colPosL, double * data, int dataL); + +/** + * Set a complex sparse matrix + * + * @param variableName The name of the variable + * @param nbRow Number of rows + * @param nbCol Number of cols + * @param nbRowItem the number of non null items by row + * @param nbRowItemL the length of the previous array + * @param colPos the column position of each non null item + * @param colPosL the length of the previous array + * @param data the double data + * @param dataL the length of the previous array + * @param imag the double data + * @param imagL the length of the previous array + * @return 0 if successfull, != 0 otherwise + */ +int putComplexSparse(char * variableName, int nbRow, int nbCol, int * nbRowItem, int nbRowItemL, int * colPos, int colPosL, double * data, int dataL, double * imag, int imagL); + +/** + * Set a boolean sparse matrix + * + * @param variableName The name of the variable + * @param nbRow Number of rows + * @param nbCol Number of cols + * @param nbRowItem the number of non null items by row + * @param nbRowItemL the length of the previous array + * @param colPos the column position of each non null item + * @param colPosL the length of the previous array + * @return 0 if successfull, != 0 otherwise + */ +int putBooleanSparse(char * variableName, int nbRow, int nbCol, int * nbRowItem, int nbRowItemL, int * colPos, int colPosL); + +/** + * Set a polynomial matrix + * + * @param variableName The name of the variable + * @param polyVarName The name of the polynomial variable + * @param data the double data + * @param nbRow Number of rows + * @param nbCol Number of cols + * @param nbCoef the number of coef of each polynomial + * @return 0 if successfull, != 0 otherwise + */ +int putPolynomial(char * variableName, char * polyVarName, double ** data, int nbRow, int nbCol, int * nbCoef); + +/** + * Set a complex polynomial matrix + * + * @param variableName The name of the variable + * @param polyVarName The name of the polynomial variable + * @param data the double data + * @param nbRow Number of rows + * @param nbCol Number of cols + * @param imag the double data + * @param nbRowI Number of rows + * @param nbColI Number of cols + * @param nbCoef the number of coef of each polynomial + * @return 0 if successfull, != 0 otherwise + */ +int putComplexPolynomial(char * variableName, char * polyVarName, double ** data, int nbRow, int nbCol, int * nbCoef, double ** imag, int nbRowI, int nbColI, int * nbCoefI); + +/** + * Check if a variable exists in Context + * + * @param variableName The name of the variable + * @return TRUE if the given variable exists, FALSE otherwise + */ +BOOL isExistingVariable(char* variableName); + +/** + * Check if a variable is complex. + * + * @param variableName The name of the variable + * @return TRUE if the given variable is complex, FALSE otherwise + */ +BOOL isComplexVar(char *variableName); +#endif /* __JAVASCI2_HELPER_H__ */ diff --git a/modules/javasci/src/c/libjavasci2_la-javasci2_helper.lo b/modules/javasci/src/c/libjavasci2_la-javasci2_helper.lo new file mode 100755 index 000000000..c5c027a09 --- /dev/null +++ b/modules/javasci/src/c/libjavasci2_la-javasci2_helper.lo @@ -0,0 +1,12 @@ +# src/c/libjavasci2_la-javasci2_helper.lo - a libtool object file +# Generated by libtool (GNU libtool) 2.4.2 +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# Name of the PIC object. +pic_object='.libs/libjavasci2_la-javasci2_helper.o' + +# Name of the non-PIC object +non_pic_object=none + diff --git a/modules/javasci/src/java/org/scilab/modules/javasci/Call_Scilab.java b/modules/javasci/src/java/org/scilab/modules/javasci/Call_Scilab.java new file mode 100755 index 000000000..f9ee451ba --- /dev/null +++ b/modules/javasci/src/java/org/scilab/modules/javasci/Call_Scilab.java @@ -0,0 +1,137 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 2.0.7 + * + * Do not make changes to this file unless you know what you are doing--modify + * the SWIG interface file instead. + * ----------------------------------------------------------------------------- */ + +package org.scilab.modules.javasci; + + +import org.scilab.modules.types.ScilabTypeEnum; +import org.scilab.modules.types.ScilabIntegerTypeEnum; + + /** + * Connector for Javasci v2. + * This class should <b>not</b> be used directly + * @see org.scilab.modules.javasci.Scilab + * @author DIGITEO - Sylvestre LEDRU + */ +public class Call_Scilab { + + /** + * Constructor + */ + protected Call_Scilab() { + throw new UnsupportedOperationException(); + } + public static int Call_ScilabOpen(String SCIpath, boolean advancedMode, String ScilabStartup, int Stacksize) { + return Call_ScilabJNI.Call_ScilabOpen(SCIpath, advancedMode, ScilabStartup, Stacksize); + } + + public static boolean TerminateScilab(String ScilabQuit) { + return Call_ScilabJNI.TerminateScilab(ScilabQuit); + } + + public static int SendScilabJob(String job) { + return Call_ScilabJNI.SendScilabJob(job); + } + + public static int SendScilabJobs(String[] jobs, int numberjobs) { + return Call_ScilabJNI.SendScilabJobs(jobs, numberjobs); + } + + public static void SetFromJavaToON() { + Call_ScilabJNI.SetFromJavaToON(); + } + + public static boolean isGraphicOpened() { + return Call_ScilabJNI.isGraphicOpened(); + } + + public static int GetLastErrorCode() { + return Call_ScilabJNI.GetLastErrorCode(); + } + + public static boolean isExistingVariable(String varname) { + return Call_ScilabJNI.isExistingVariable(varname); + } + + public static String getLastErrorMessage() { + return Call_ScilabJNI.getLastErrorMessage(); + } + + public static ScilabTypeEnum getVariableType(String varname) { + return ScilabTypeEnum.swigToEnum(Call_ScilabJNI.getVariableType(varname)); + } + + public static ScilabIntegerTypeEnum getIntegerPrecision(String varname) { + return ScilabIntegerTypeEnum.swigToEnum(Call_ScilabJNI.getIntegerPrecision(varname)); + } + + public static boolean isComplex(String varname) { + return Call_ScilabJNI.isComplex(varname); + } + + public static int putString(String variableName, String[][] variable) { + return Call_ScilabJNI.putString(variableName, variable); + } + + public static int putDoubleComplex(String variableName, double[][] variable, double[][] imag) { + return Call_ScilabJNI.putDoubleComplex(variableName, variable, imag); + } + + public static int putDouble(String variableName, double[][] variable) { + return Call_ScilabJNI.putDouble(variableName, variable); + } + + public static int putBoolean(String variableName, boolean[][] variable) { + return Call_ScilabJNI.putBoolean(variableName, variable); + } + + public static int putByte(String variableName, byte[][] variable) { + return Call_ScilabJNI.putByte(variableName, variable); + } + + public static int putUnsignedByte(String variableName, byte[][] variable) { + return Call_ScilabJNI.putUnsignedByte(variableName, variable); + } + + public static int putShort(String variableName, short[][] variable) { + return Call_ScilabJNI.putShort(variableName, variable); + } + + public static int putUnsignedShort(String variableName, short[][] variable) { + return Call_ScilabJNI.putUnsignedShort(variableName, variable); + } + + public static int putInt(String variableName, int[][] variable) { + return Call_ScilabJNI.putInt(variableName, variable); + } + + public static int putUnsignedInt(String variableName, int[][] variable) { + return Call_ScilabJNI.putUnsignedInt(variableName, variable); + } + + public static int putSparse(String variableName, int nbRow, int nbCol, int[] nbRowItem, int[] colPos, double[] data) { + return Call_ScilabJNI.putSparse(variableName, nbRow, nbCol, nbRowItem, colPos, data); + } + + public static int putComplexSparse(String variableName, int nbRow, int nbCol, int[] nbRowItem, int[] colPos, double[] data, double[] imag) { + return Call_ScilabJNI.putComplexSparse(variableName, nbRow, nbCol, nbRowItem, colPos, data, imag); + } + + public static int putBooleanSparse(String variableName, int nbRow, int nbCol, int[] nbRowItem, int[] colPos) { + return Call_ScilabJNI.putBooleanSparse(variableName, nbRow, nbCol, nbRowItem, colPos); + } + + public static int putPolynomial(String variableName, String polyVarName, double[][][] data) { + return Call_ScilabJNI.putPolynomial(variableName, polyVarName, data); + } + + public static int putComplexPolynomial(String variableName, String polyVarName, double[][][] data, double[][][] imag) { + return Call_ScilabJNI.putComplexPolynomial(variableName, polyVarName, data, imag); + } + +} diff --git a/modules/javasci/src/java/org/scilab/modules/javasci/Call_ScilabJNI.java b/modules/javasci/src/java/org/scilab/modules/javasci/Call_ScilabJNI.java new file mode 100755 index 000000000..d157c450c --- /dev/null +++ b/modules/javasci/src/java/org/scilab/modules/javasci/Call_ScilabJNI.java @@ -0,0 +1,74 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 2.0.7 + * + * Do not make changes to this file unless you know what you are doing--modify + * the SWIG interface file instead. + * ----------------------------------------------------------------------------- */ + +package org.scilab.modules.javasci; + + +/* It is generated code. Disable checkstyle */ +//CHECKSTYLE:OFF + /** + * Connector for Javasci v2. + * This class should <b>not</b> be used directly + * @see org.scilab.modules.javasci.Scilab + * @author DIGITEO - Sylvestre LEDRU + */ +class Call_ScilabJNI { + + /** + * Constructor + */ + protected Call_ScilabJNI() { + throw new UnsupportedOperationException(); + } + + static { + try { + if (System.getProperty("os.name").toLowerCase().contains("windows")) { + System.loadLibrary("javasci"); + } else { + System.loadLibrary("javasci2"); + } + } catch (SecurityException e) { + System.err.println("A security manager exists and does not allow the loading of the specified dynamic library :"); + e.printStackTrace(System.err); + } catch (UnsatisfiedLinkError e) { + System.err.println("The native library javasci does not exist or cannot be found."); + e.printStackTrace(System.err); + } + } + + public final static native int putList(String varNmae, Object list, char type); + + public final static native int Call_ScilabOpen(String jarg1, boolean jarg2, String jarg3, int jarg4); + public final static native boolean TerminateScilab(String jarg1); + public final static native int SendScilabJob(String jarg1); + public final static native int SendScilabJobs(String[] jarg1, int jarg2); + public final static native void SetFromJavaToON(); + public final static native boolean isGraphicOpened(); + public final static native int GetLastErrorCode(); + public final static native boolean isExistingVariable(String jarg1); + public final static native String getLastErrorMessage(); + public final static native int getVariableType(String jarg1); + public final static native int getIntegerPrecision(String jarg1); + public final static native boolean isComplex(String jarg1); + public final static native int putString(String jarg1, String[][] jarg2); + public final static native int putDoubleComplex(String jarg1, double[][] jarg2, double[][] jarg5); + public final static native int putDouble(String jarg1, double[][] jarg2); + public final static native int putBoolean(String jarg1, boolean[][] jarg2); + public final static native int putByte(String jarg1, byte[][] jarg2); + public final static native int putUnsignedByte(String jarg1, byte[][] jarg2); + public final static native int putShort(String jarg1, short[][] jarg2); + public final static native int putUnsignedShort(String jarg1, short[][] jarg2); + public final static native int putInt(String jarg1, int[][] jarg2); + public final static native int putUnsignedInt(String jarg1, int[][] jarg2); + public final static native int putSparse(String jarg1, int jarg2, int jarg3, int[] jarg4, int[] jarg6, double[] jarg8); + public final static native int putComplexSparse(String jarg1, int jarg2, int jarg3, int[] jarg4, int[] jarg6, double[] jarg8, double[] jarg10); + public final static native int putBooleanSparse(String jarg1, int jarg2, int jarg3, int[] jarg4, int[] jarg6); + public final static native int putPolynomial(String jarg1, String jarg2, double[][][] jarg3); + public final static native int putComplexPolynomial(String jarg1, String jarg2, double[][][] jarg3, double[][][] jarg7); +} diff --git a/modules/javasci/src/java/org/scilab/modules/javasci/JavasciException.java b/modules/javasci/src/java/org/scilab/modules/javasci/JavasciException.java new file mode 100755 index 000000000..329fa630d --- /dev/null +++ b/modules/javasci/src/java/org/scilab/modules/javasci/JavasciException.java @@ -0,0 +1,132 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - INRIA - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ + +package org.scilab.modules.javasci; + +/** + * This class provides a general exception class for Javasci v2 API. + */ +public abstract class JavasciException extends Exception { + + + /** + * This class provides a exception class when an error occurs on the + * initialization + */ + public static class InitializationException extends JavasciException { + + public InitializationException(String message) { + super(message); + } + + public InitializationException(String message, Throwable cause) { + super(message, cause); + } + + } + + + /** + * This class provides a exception class when an unsupported type is used + */ + public static class UnsupportedTypeException extends JavasciException { + + public UnsupportedTypeException(String message) { + super(message); + } + } + + + /** + * This class provides a exception class when a type is unknown + * This should be very very rare. + */ + public static class UnknownTypeException extends JavasciException { + + public UnknownTypeException(String message) { + super(message); + } + + } + + /** + * This class provides a exception class when Scilab is already running + */ + public static class AlreadyRunningException extends JavasciException { + + public AlreadyRunningException(String message) { + super(message); + } + } + + + /** + * This class provides a exception class when an internal error occurs + */ + public static class ScilabInternalException extends JavasciException { + + public ScilabInternalException(String message) { + super(message); + } + + } + + /** + * This class provides a exception class when a Scilab error occurs + * @since 5.4.0 + */ + public static class ScilabErrorException extends JavasciException { + + public ScilabErrorException(String message, int errorCode) { + super(message + "\nCode: " + errorCode); + } + + } + + + /** + * This class provides a exception class when an non-existing variable is + * accessed. + */ + public static class UndefinedVariableException extends JavasciException { + + public UndefinedVariableException(String message) { + super(message); + } + + } + + /** + * Default constructor + */ + public JavasciException() { + super(); + } + + /** + * Default constructor + */ + public JavasciException(String message) { + super(message); + } + + /** + * + * @param message the message to be printed + * @param cause the cause + */ + public JavasciException(String message, Throwable cause) { + super(message, cause); + } + + +} diff --git a/modules/javasci/src/java/org/scilab/modules/javasci/Scilab.java b/modules/javasci/src/java/org/scilab/modules/javasci/Scilab.java new file mode 100755 index 000000000..207b8f1cd --- /dev/null +++ b/modules/javasci/src/java/org/scilab/modules/javasci/Scilab.java @@ -0,0 +1,770 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - INRIA - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +package org.scilab.modules.javasci; + +import java.io.File; +import java.io.FileNotFoundException; + +import org.scilab.modules.types.ScilabType; +import org.scilab.modules.types.ScilabTypeEnum; +import org.scilab.modules.types.ScilabIntegerTypeEnum; +import org.scilab.modules.types.ScilabDouble; +import org.scilab.modules.types.ScilabList; +import org.scilab.modules.types.ScilabMList; +import org.scilab.modules.types.ScilabTList; +import org.scilab.modules.types.ScilabString; +import org.scilab.modules.types.ScilabBoolean; +import org.scilab.modules.types.ScilabBooleanSparse; +import org.scilab.modules.types.ScilabInteger; +import org.scilab.modules.types.ScilabPolynomial; +import org.scilab.modules.types.ScilabSparse; +import org.scilab.modules.javasci.Call_Scilab; +import org.scilab.modules.javasci.JavasciException.AlreadyRunningException; +import org.scilab.modules.javasci.JavasciException.InitializationException; +import org.scilab.modules.javasci.JavasciException.UnsupportedTypeException; +import org.scilab.modules.javasci.JavasciException.UndefinedVariableException; +import org.scilab.modules.javasci.JavasciException.UnknownTypeException; +import org.scilab.modules.javasci.JavasciException.ScilabInternalException; +import org.scilab.modules.javasci.JavasciException.ScilabErrorException; + +/** + * This class provides the capability to access to the Scilab engine from + * a Java application.<br /> + * <br /> + * Example:<br /> + * <code> + * Scilab sci = new Scilab();<br /> + * if (sci.open()) {<br /> + * double [][]a={{21.2, 22.0, 42.0, 39.0},{23.2, 24.0, 44.0, 40.0}};<br /> + * ScilabDouble aOriginal = new ScilabDouble(a);<br /> + * sci.put("a",aOriginal);<br /> + * ScilabDouble aFromScilab = (ScilabDouble)sci.get("a");<br /> + * }<br /> + * </code> + * @see org.scilab.modules.types + */ +public class Scilab { + + private static int notHandledError = -999; + + private String SCI = null; + private boolean advancedMode = false; + + /** + * Creator of the Scilab Javasci object. <br /> + * Scilab data path is autodetected and advanced features disabled + */ + public Scilab() throws InitializationException { + this(null, false); + } + + /** + * Creator of the Scilab Javasci object with a specific Scilab path.<br /> + * Advanced features are disabled (faster) + * <br /> + * Example:<br /> + * <code> + * Scilab sci = new Scilab("/path/to/Scilab/data/dir/");<br /> + * <br /> + * </code> + * @param SCI provide the path to Scilab data + */ + public Scilab(String SCI) throws InitializationException { + this(SCI, false); + } + + /** + * Creator of the Scilab Javasci object in advanced mode<br /> + * Scilab data path is autodetected + * <br /> + * Example:<br /> + * <code> + * Scilab sci = new Scilab(true); // Starts in advanced mode<br /> + * <br /> + * </code> + * @param advancedMode true enables the advanced mode (GUI, graphics, Tcl/Tk, sciNotes...). Smaller. + */ + public Scilab(boolean advancedMode) throws InitializationException { + this(null, advancedMode); + } + + /** + * Creator of the Scilab Javasci object. <br /> + * Under GNU/Linux / Mac OS X, try to detect Scilab base path<br /> + * if the property SCI is set, use it<br /> + * if not, try with the global variable SCI<br /> + * if not, throws a new exception<br /> + * Under Windows, use also the registery<br /> + * <br /> + * Example:<br /> + * <code> + * Scilab sci = new Scilab("/path/to/Scilab/data/dir/",true); // Starts in advanced mode<br /> + * <br /> + * </code> + * @param SCIPath the path to Scilab data + * @param advancedMode true enables the advanced mode (GUI, graphics, Tcl/Tk, sciNotes...). Smaller. + */ + public Scilab(String SCIPath, boolean advancedMode) throws InitializationException { + String SCI = SCIPath; + if (!System.getProperty("os.name").toLowerCase().contains("windows")) { + if (SCI == null) { + // Auto detect + try { + SCI = System.getProperty("SCI"); + if (SCI == null || SCI.length() == 0) { + SCI = System.getenv("SCI"); + if (SCI == null || SCI.length() == 0) { + throw new InitializationException("Auto detection of SCI failed.\nSCI empty."); + } + } + } catch (Exception e) { + throw new InitializationException("Auto detection of SCI failed.\nCould not retrieve the variable SCI.", e); + } + } + } + this.advancedMode = advancedMode; + this.initScilab(SCI); + + } + + + private void initScilab(String SCI) throws InitializationException { + /* Let Scilab engine knows that he is run through the Javasci API */ + Call_Scilab.SetFromJavaToON(); + if (!System.getProperty("os.name").toLowerCase().contains("windows")) { + File f = new File(SCI); + if (!f.isDirectory()) { + throw new InitializationException("Could not find directory " + f.getAbsolutePath()); + } + this.SCI = SCI; + } + } + + /** + * Open a connection to the Scilab engine<br /> + * This function is based on Call_ScilabOpen from call_scilab<br /> + * Note: For now, only one instance of Scilab can be launched<br /> + * A second launch will return FALSE<br /> + * <br /> + * Example:<br /> + * <code> + * Scilab sci = new Scilab();<br /> + * sci.open();<br /> + * <br /> + * </code> + * @return if the operation is successful + * @throws AlreadyRunningException Scilab is already running + * @throws InitializationException Cannot start Scilab + */ + public boolean open() throws JavasciException { + int res = Call_Scilab.Call_ScilabOpen(this.SCI, this.advancedMode, null, -1); + switch (res) { + case 0: /* Success */ + return true; + case -1: + throw new AlreadyRunningException("Javasci already running."); + case -2: + /* Should not occurd (processed before) */ + throw new InitializationException("Could not find SCI."); + case -3: + throw new InitializationException("No existing directory."); + case 10001: + throw new InitializationException("Stacksize failed (not enought memory ?)."); + default: + throw new InitializationException("Unknown startup error: " + res); + } + } + + /** + * Open a connection to the Scilab engine and run the command job<br /> + * This function is based on Call_ScilabOpen from call_scilab<br /> + * Note: For now, only one instance of Scilab can be launched<br /> + * A second launch will return FALSE<br /> + * <br /> + * Example:<br /> + * <code> + * Scilab sci = new Scilab();<br /> + * sci.open("a=%pi;");<br /> + * <br /> + * </code> + * @param job The job to run on startup + * @return if the operation is successful + */ + public boolean open(String job) throws JavasciException { + if (!this.open()) { + return false; + } + + return this.exec(job); + } + + /** + * Open a connection to the Scilab engine and run commands job<br /> + * This function is based on Call_ScilabOpen from call_scilab<br /> + * Note: For now, only one instance of Scilab can be launched<br /> + * A second launch will return FALSE<br /> + * <br /> + * Example:<br /> + * <code> + * Scilab sci = new Scilab();<br /> + * sci.open(new String[]{"a=42*2;","b=44*2", "c=(a==b)"});<br /> + * <br /> + * </code> + * @param jobs The serie of jobs to run on startup + * @return if the operation is successful + */ + public boolean open(String jobs[]) throws JavasciException { + if (!this.open()) { + return false; + } + return this.exec(jobs); + } + + + /** + * Open a connection to the Scilab engine and run thefile scriptFilename<br /> + * This function is based on Call_ScilabOpen from call_scilab<br /> + * Note: For now, only one instance of Scilab can be launched<br /> + * A second launch will return FALSE<br /> + * <br /> + * Example:<br /> + * <code> + * Scilab sci = new Scilab();<br /> + * sci.open(new File("/tmp/myscript.sce"));<br /> + * <br /> + * </code> + * @param scriptFilename The script to execute on startup + * @return if the operation is successful + */ + public boolean open(File scriptFilename) throws JavasciException, FileNotFoundException { + if (!this.open()) { + return false; + } + + return this.exec(scriptFilename); + } + + + /** + * Execute a single command in Scilab<br /> + * This function is based on SendScilabJob from call_scilab + * <br /> + * Example:<br /> + * <code> + * sci.exec("a=2*%pi");<br /> + * <br /> + * </code> + * @param job the job to execute + * @return if the operation is successful + */ + public boolean exec(String job) { + try { + this.execException(job); + return true; + } catch (Exception e) { + return false; + } + } + + + /** + * Execute a single command in Scilab<br /> + * Returns a ScilabErrorException in case of Scilab problem<br /> + * This function is based on SendScilabJob from call_scilab + * <br /> + * Example:<br /> + * <code> + * sci.exec("a=2*%pi");<br /> + * <br /> + * </code> + * @param job the job to execute + * @since 5.4.0 + */ + public void execException(String job) throws ScilabErrorException { + int result = Call_Scilab.SendScilabJob(job); + if (result != 0) { + throw new ScilabErrorException("A Scilab error occurred: " + this.getLastErrorMessage(), this.getLastErrorCode()); + } + } + + + /** + * Execute several commands in Scilab<br /> + * This function is based on SendScilabJob from call_scilab + * <br /> + * Example:<br /> + * <code> + * sci.exec(new String[]{"a=42*2;","b=44*2", "c=(a==b)"});<br /> + * <br /> + * </code> + * @param jobs the serie of job to execute + * @return if the operation is successful + */ + public boolean exec(String jobs[]) { + try { + this.execException(jobs); + return true; + } catch (Exception e) { + return false; + } + } + + /** + * Execute several commands in Scilab<br /> + * Returns a ScilabErrorException in case of Scilab problem<br /> + * This function is based on SendScilabJob from call_scilab + * <br /> + * Example:<br /> + * <code> + * sci.exec(new String[]{"a=42*2;","b=44*2", "c=(a==b)"});<br /> + * <br /> + * </code> + * @param jobs the serie of job to execute + * @since 5.4.0 + */ + public void execException(String jobs[]) throws ScilabErrorException { + int result = Call_Scilab.SendScilabJobs(jobs, jobs.length); + if (result != 0) { + throw new ScilabErrorException("A Scilab error occurred: " + this.getLastErrorMessage(), this.getLastErrorCode()); + } + } + + /** + * Execute a Scilab script .sce/.sci and throws an exception in case<br /> + * of a Scilab error<br /> + * Returns a ScilabErrorException in case of Scilab problem<br /> + * This function is based on SendScilabJob from call_scilab<br /> + * Note that this function is a direct call on the Scilab function exec: + * <code> this.exec("exec('" + scriptFilename + "');");</code> + * <br /> + * Example:<br /> + * <code> + * sci.exec(new File("/tmp/myscript.sci"));<br /> + * <br /> + * </code> + * @param scriptFilename the script to execute + * @since 5.4.0 + */ + public void execException(File scriptFilename) throws FileNotFoundException, ScilabErrorException { + if (!scriptFilename.exists()) { + throw new FileNotFoundException("Could not find " + scriptFilename); + } + this.execException("exec('" + scriptFilename + "');"); + } + + /** + * Execute a Scilab script .sce/.sci and throws an exception in case<br /> + * the file is not found<br /> + * This function is based on SendScilabJob from call_scilab<br /> + * Note that this function is a direct call on the Scilab function exec: + * <code> this.exec("exec('" + scriptFilename + "');");</code> + * <br /> + * Example:<br /> + * <code> + * sci.exec(new File("/tmp/myscript.sci"));<br /> + * <br /> + * </code> + * @param scriptFilename the script to execute + * @return if the operation is successful + */ + public boolean exec(File scriptFilename) throws FileNotFoundException { + if (!scriptFilename.exists()) { + throw new FileNotFoundException("Could not find " + scriptFilename); + } + return this.exec("exec('" + scriptFilename + "');"); + } + + + /** + * Detect if a variable (varname) exists in Scilab + * <br /> + * Example:<br /> + * <code> + * double [][]a={{21.2, 22.0, 42.0, 39.0},{23.2, 24.0, 44.0, 40.0}};<br /> + * ScilabDouble aOriginal = new ScilabDouble(a);<br /> + * sci.put("a",aOriginal);<br /> + * assert sci.isExistingVariable("a") == true;<br /> + * <br /> + * </code> + * @param varname the variable to check + * @return if the variable exists or not + */ + public boolean isExistingVariable(String varname) { + return Call_Scilab.isExistingVariable(varname); + } + + + /** + * Shutdown Scilab<br /> + * This function is based on TerminateScilab from call_scilab + * <br /> + * Example:<br /> + * <code> + * sci.close();<br /> + * <br /> + * </code> + * @return if the operation is successful + */ + public boolean close() { + return Call_Scilab.TerminateScilab(null); + } + + + /** + * Return the last error code + * <br /> + * Example:<br /> + * <code> + * sci.open("a=1+"); // Wrong operation<br /> + * sci.getLastErrorCode() // Returns 2<br /> + * <br /> + * </code> + * @return the error code + */ + public int getLastErrorCode() { + return Call_Scilab.GetLastErrorCode(); + } + + + /** + * Return the last error message + * <br /> + * Example:<br /> + * <code> + * sci.open("a=1+");<br /> + * System.err.println(sci.getLastErrorMessage());<br /> + * <br /> + * </code> + * @return the error message itself + */ + public String getLastErrorMessage() { + return Call_Scilab.getLastErrorMessage(); + } + + + /** + * Detect if a Scilab graphic window is still opened<br /> + * This function is based on ScilabHaveAGraph from call_scilab + * <br /> + * Example:<br /> + * <code> + * sci.exec("plot3d();");<br /> + * sci.isGraphicOpened();<br /> + * <br /> + * </code> + * @return if the graphic is open or not + */ + public boolean isGraphicOpened() { + return Call_Scilab.isGraphicOpened(); + } + + /** + * Return the code type of a variable varname + * <br /> + * Example:<br /> + * <code> + * sci.exec("a = 2*%pi");<br /> + * if (sci.getVariableType("a") == ScilabTypeEnum.sci_matrix) {<br /> + * System.out.println("a is a double matrix");<br /> + * }<br /> + * <br /> + * </code> + * @param varName the name of the variable + * @return the type of the variable + * @throws UndefinedVariableException The variable does not exist + * @throws UnknownTypeException Cannot find the type + */ + public ScilabTypeEnum getVariableType(String varName) throws JavasciException { + return getVariableTypeInCurrentScilabSession(varName); + } + + /** + * Return the code type of a variable varname in the current Scilab session + * <br /> + * Example:<br /> + * <code> + * sci.exec("a = 2*%pi");<br /> + * if (sci.getVariableType("a") == ScilabTypeEnum.sci_matrix) {<br /> + * System.out.println("a is a double matrix");<br /> + * }<br /> + * <br /> + * </code> + * @param varName the name of the variable + * @return the type of the variable + * @throws UndefinedVariableException The variable does not exist + * @throws UnknownTypeException Cannot find the type + */ + public static ScilabTypeEnum getVariableTypeInCurrentScilabSession(String varName) throws JavasciException { + ScilabTypeEnum variableType = null; + try { + variableType = Call_Scilab.getVariableType(varName); + if (variableType == null ) { + throw new UndefinedVariableException("Could not find the type of the variable '" + varName + "'"); + } + } catch (IllegalArgumentException e) { + String lastWord = e.getMessage().substring(e.getMessage().lastIndexOf(' ') + 1); + if (lastWord.equals("-2")) { /* Crappy workaround. Parse the exception */ + throw new UndefinedVariableException("Could not find variable '" + varName + "'"); + } + throw new UnknownTypeException("Type of " + varName + " unknown"); + + } + return variableType; + } + + /** + * Returns a variable named varname<br /> + * Throws an exception if the datatype is not managed or if the variable is not available + * <br /> + * Example:<br /> + * <code> + * double [][]a={{21.2, 22.0, 42.0, 39.0},{23.2, 24.0, 44.0, 40.0}};<br /> + * double [][]aImg={{212.2, 221.0, 423.0, 393.0},{234.2, 244.0, 441.0, 407.0}};<br /> + * ScilabDouble aOriginal = new ScilabDouble(a, aImg);<br /> + * sci.put("a",aOriginal);<br /> + * ScilabDouble aFromScilab = (ScilabDouble)sci.get("a");<br /> + * <br /> + * </code> + * @param varname the name of the variable + * @return return the variable + * @throws UnsupportedTypeException Type not managed yet. + */ + public ScilabType get(String varname) throws JavasciException { + return getInCurrentScilabSession(varname); + } + + /** + * Returns a reference variable named varname<br /> + * Throws an exception if the datatype is not managed or if the variable is not available + * <br /> + * Example:<br /> + * <code> + * double [][]a={{21.2, 22.0, 42.0, 39.0},{23.2, 24.0, 44.0, 40.0}};<br /> + * double [][]aImg={{212.2, 221.0, 423.0, 393.0},{234.2, 244.0, 441.0, 407.0}};<br /> + * ScilabDouble aOriginal = new ScilabDouble(a, aImg);<br /> + * sci.put("a",aOriginal);<br /> + * ScilabDouble aFromScilab = (ScilabDouble)sci.get("a");<br /> + * <br /> + * </code> + * @param varname the name of the variable + * @return return the variable + * @throws UnsupportedTypeException Type not managed yet. + */ + public ScilabType getByReference(String varname) throws JavasciException { + return getInCurrentScilabSession(varname, true); + } + + /** + * Returns a variable named varname in the current Scilab session<br /> + * Throws an exception if the datatype is not managed or if the variable is not available + * <br /> + * Example:<br /> + * <code> + * double [][]a={{21.2, 22.0, 42.0, 39.0},{23.2, 24.0, 44.0, 40.0}};<br /> + * double [][]aImg={{212.2, 221.0, 423.0, 393.0},{234.2, 244.0, 441.0, 407.0}};<br /> + * ScilabDouble aOriginal = new ScilabDouble(a, aImg);<br /> + * sci.put("a",aOriginal);<br /> + * ScilabDouble aFromScilab = (ScilabDouble)sci.get("a");<br /> + * <br /> + * </code> + * @param varname the name of the variable + * @return return the variable + * @throws UnsupportedTypeException Type not managed yet. + */ + public static ScilabType getInCurrentScilabSession(String varname) throws JavasciException { + return getInCurrentScilabSession(varname, false); + } + + /** + * Returns a variable named varname in the current Scilab session<br /> + * Throws an exception if the datatype is not managed or if the variable is not available + * <br /> + * Example:<br /> + * <code> + * double [][]a={{21.2, 22.0, 42.0, 39.0},{23.2, 24.0, 44.0, 40.0}};<br /> + * double [][]aImg={{212.2, 221.0, 423.0, 393.0},{234.2, 244.0, 441.0, 407.0}};<br /> + * ScilabDouble aOriginal = new ScilabDouble(a, aImg);<br /> + * sci.put("a",aOriginal);<br /> + * ScilabDouble aFromScilab = (ScilabDouble)sci.get("a");<br /> + * <br /> + * </code> + * @param varname the name of the variable + * @return return the variable + * @throws UnsupportedTypeException Type not managed yet. + */ + public static ScilabType getInCurrentScilabSession(String varname, boolean byref) throws JavasciException { + ScilabTypeEnum sciType = getVariableTypeInCurrentScilabSession(varname); + switch (sciType) { + case sci_matrix: + case sci_boolean: + case sci_strings: + + case sci_poly: + case sci_sparse: + case sci_boolean_sparse: + case sci_list: + case sci_tlist: + case sci_mlist: + return ScilabVariablesJavasci.getScilabVariable(varname, true, byref); + case sci_ints: + ScilabIntegerTypeEnum typeInt = Call_Scilab.getIntegerPrecision(varname); + + switch (typeInt) { + case sci_int8: + case sci_uint8: + case sci_int16: + case sci_uint16: + case sci_int32: + case sci_uint32: + return ScilabVariablesJavasci.getScilabVariable(varname, true, byref); + case sci_int64: + case sci_uint64: + // will be available in Scilab 6 + throw new UnsupportedTypeException("64 bit (signed and unsigned) integer types not managed in Scilab 5.X"); + + } + + default: + throw new UnsupportedTypeException("Type not managed: " + sciType); + } + } + + /** + * Send to Scilab a variable theVariable named varname<br /> + * Throws an exception if the datatype is not managed or if the variable is not available + * <br /> + * Example:<br /> + * <code> + * boolean [][]a={{true, true, false, false},{true, false, true, false}};<br /> + * ScilabBoolean aOriginal = new ScilabBoolean(a);<br /> + * sci.put("a",aOriginal);<br /> + * ScilabBoolean aFromScilab = (ScilabBoolean)sci.get("a");<br /> + * <br /> + * </code> + * @param varname the name of the variable + * @param theVariable the variable itself + * @return true if the operation is successful + * @throws UnsupportedTypeException Type not managed yet. + */ + public boolean put(String varname, ScilabType theVariable) throws JavasciException { + return putInCurrentScilabSession(varname, theVariable); + } + + /** + * Send to the current Scilab session a variable theVariable named varname<br /> + * Throws an exception if the datatype is not managed or if the variable is not available + * <br /> + * Example:<br /> + * <code> + * boolean [][]a={{true, true, false, false},{true, false, true, false}};<br /> + * ScilabBoolean aOriginal = new ScilabBoolean(a);<br /> + * sci.put("a",aOriginal);<br /> + * ScilabBoolean aFromScilab = (ScilabBoolean)sci.get("a");<br /> + * <br /> + * </code> + * @param varname the name of the variable + * @param theVariable the variable itself + * @return true if the operation is successful + * @throws UnsupportedTypeException Type not managed yet. + */ + public static boolean putInCurrentScilabSession(String varname, ScilabType theVariable) throws JavasciException { + int err = notHandledError; /* -999: if the type is not handled */ + + switch (theVariable.getType()) { + case sci_matrix : + ScilabDouble sciDouble = (ScilabDouble) theVariable; + if (sciDouble.isReal()) { + err = Call_Scilab.putDouble(varname, sciDouble.getRealPart()); + } else { + err = Call_Scilab.putDoubleComplex(varname, sciDouble.getRealPart(), sciDouble.getImaginaryPart()); + } + break; + case sci_poly : + ScilabPolynomial sciPoly = (ScilabPolynomial) theVariable; + if (sciPoly.isReal()) { + err = Call_Scilab.putPolynomial(varname, sciPoly.getPolyVarName(), sciPoly.getRealPart()); + } else { + err = Call_Scilab.putComplexPolynomial(varname, sciPoly.getPolyVarName(), sciPoly.getRealPart(), sciPoly.getImaginaryPart()); + } + break; + case sci_boolean : + ScilabBoolean sciBoolean = (ScilabBoolean) theVariable; + err = Call_Scilab.putBoolean(varname, sciBoolean.getData()); + break; + case sci_sparse : + ScilabSparse sciSparse = (ScilabSparse) theVariable; + if (sciSparse.isReal()) { + err = Call_Scilab.putSparse(varname, sciSparse.getHeight(), sciSparse.getWidth(), sciSparse.getNbItemRow(), sciSparse.getScilabColPos(), sciSparse.getRealPart()); + } else { + err = Call_Scilab.putComplexSparse(varname, sciSparse.getHeight(), sciSparse.getWidth(), sciSparse.getNbItemRow(), sciSparse.getScilabColPos(), sciSparse.getRealPart(), sciSparse.getImaginaryPart()); + } + break; + case sci_boolean_sparse : + ScilabBooleanSparse sciBooleanSparse = (ScilabBooleanSparse) theVariable; + err = Call_Scilab.putBooleanSparse(varname, sciBooleanSparse.getHeight(), sciBooleanSparse.getWidth(), sciBooleanSparse.getNbItemRow(), sciBooleanSparse.getScilabColPos()); + break; + case sci_ints : + ScilabInteger sciInteger = (ScilabInteger) theVariable; + switch (sciInteger.getPrec()) { + case sci_uint8: + err = Call_Scilab.putUnsignedByte(varname, sciInteger.getDataAsByte()); + break; + case sci_int8: + err = Call_Scilab.putByte(varname, sciInteger.getDataAsByte()); + break; + case sci_uint16: + err = Call_Scilab.putUnsignedShort(varname, sciInteger.getDataAsShort()); + break; + case sci_int16: + err = Call_Scilab.putShort(varname, sciInteger.getDataAsShort()); + break; + case sci_uint32: + err = Call_Scilab.putUnsignedInt(varname, sciInteger.getDataAsInt()); + break; + case sci_int32: + err = Call_Scilab.putInt(varname, sciInteger.getDataAsInt()); + break; + case sci_uint64: + // err = Call_Scilab.putUnsignedLong(varname, sciInteger.getData_()); + case sci_int64: + // err = Call_Scilab.putLong(varname, sciInteger.getData_()); + break; + } + break; + case sci_strings : + ScilabString sciString = (ScilabString) theVariable; + err = Call_Scilab.putString(varname, sciString.getData()); + break; + case sci_list : + ScilabList sciList = (ScilabList) theVariable; + err = Call_ScilabJNI.putList(varname, sciList.getSerializedObject(), 'l'); + break; + case sci_tlist : + ScilabTList sciTList = (ScilabTList) theVariable; + err = Call_ScilabJNI.putList(varname, sciTList.getSerializedObject(), 't'); + break; + case sci_mlist : + ScilabMList sciMList = (ScilabMList) theVariable; + err = Call_ScilabJNI.putList(varname, sciMList.getSerializedObject(), 'm'); + break; + } + + if (err == notHandledError) { + throw new UnsupportedTypeException("Type not managed: " + theVariable.getClass()); + } else { + if (err != 0) { + throw new ScilabInternalException("Storage of the variable '" + varname + "' (" + theVariable.getClass() + ") failed."); + } + } + return true; + } +} diff --git a/modules/javasci/src/java/org/scilab/modules/javasci/ScilabVariablesJavasci.java b/modules/javasci/src/java/org/scilab/modules/javasci/ScilabVariablesJavasci.java new file mode 100755 index 000000000..ed01e1df0 --- /dev/null +++ b/modules/javasci/src/java/org/scilab/modules/javasci/ScilabVariablesJavasci.java @@ -0,0 +1,90 @@ +/* + * Scilab (http://www.scilab.org/) - This file is part of Scilab + * Copyright (C) 2011 - DIGITEO - Calixte DENIZET + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ + +package org.scilab.modules.javasci; + +import java.util.HashMap; +import java.util.Map; + +import org.scilab.modules.types.GetScilabVariable; +import org.scilab.modules.types.ScilabVariables; +import org.scilab.modules.types.ScilabVariablesHandler; +import org.scilab.modules.types.ScilabType; + +/** + * Class to get Scilab data from a Java call + */ +public final class ScilabVariablesJavasci implements ScilabVariablesHandler { + + private static final Map<Thread, ScilabType> map = new HashMap<Thread, ScilabType>(); + + private static int id = -1; + + /** + * Constructor + */ + private ScilabVariablesJavasci() { } + + /** + * {@inheritDoc} + */ + public void handle(ScilabType var) { + map.put(Thread.currentThread(), var); + } + + /** + * Get a Scilab variable with a given name + * @param name the variable name + * @param swapRowCol if true the returned data will be stored row by row + * @param byref if true the variable is passed by reference if it is possible + * @return the corresponding ScilabType object + */ + public static final ScilabType getScilabVariable(String name, boolean swapRowCol, boolean byref) { + if (id == -1) { + id = ScilabVariables.addScilabVariablesHandler(new ScilabVariablesJavasci()); + } + + if (name != null && !name.isEmpty()) { + if (byref) { + GetScilabVariable.getScilabVariableAsReference(name, id); + } else { + GetScilabVariable.getScilabVariable(name, swapRowCol ? 1 : 0, id); + } + Thread t = Thread.currentThread(); + ScilabType var = map.get(t); + map.remove(t); + + return var; + } + + return null; + } + + /** + * Get a Scilab variable with a given name + * @param name the variable name + * @param swapRowCol if true the returned data will be stored row by row + * @return the corresponding ScilabType object + */ + public static final ScilabType getScilabVariable(String name, boolean swapRowCol) { + return getScilabVariable(name, swapRowCol, false); + } + + /** + * Get a Scilab variable with a given name + * @param name the variable name + * @return the corresponding ScilabType object where the data are stored row by row + */ + public static final ScilabType getScilabVariable(String name) { + return getScilabVariable(name, true); + } +} diff --git a/modules/javasci/src/java/org/scilab/modules/javasci/package.html b/modules/javasci/src/java/org/scilab/modules/javasci/package.html new file mode 100755 index 000000000..d65eeb7f4 --- /dev/null +++ b/modules/javasci/src/java/org/scilab/modules/javasci/package.html @@ -0,0 +1,18 @@ +<html> +<body> + +This package provides a way to use and call Scilab engine from a Java +application or library.<br /> +<br /> +Example:<br /> +<code> +Scilab sci = new Scilab();<br /> +sci.open();<br /> +sci.exec("b = matrix(1:100,10,10)");<br /> +ScilabType b = sci.get("b");<br /> +b.getHeight(); // 10 <br /> +b.getWidth(); // 10<br /> +ScilabDouble b2 = (ScilabDouble)sci.get("b");<br /> +b2.equals(b); // true<br /> +</body> +</html>
\ No newline at end of file diff --git a/modules/javasci/src/jni/.deps/.dirstamp b/modules/javasci/src/jni/.deps/.dirstamp new file mode 100755 index 000000000..e69de29bb --- /dev/null +++ b/modules/javasci/src/jni/.deps/.dirstamp diff --git a/modules/javasci/src/jni/.deps/libjavasci2_la-call_scilab_wrap.Plo b/modules/javasci/src/jni/.deps/libjavasci2_la-call_scilab_wrap.Plo new file mode 100755 index 000000000..4c903fe29 --- /dev/null +++ b/modules/javasci/src/jni/.deps/libjavasci2_la-call_scilab_wrap.Plo @@ -0,0 +1,321 @@ +src/jni/libjavasci2_la-call_scilab_wrap.lo: src/jni/call_scilab_wrap.c \ + /usr/include/stdc-predef.h \ + /usr/lib/jvm/java-8-openjdk-amd64/include/jni.h /usr/include/stdio.h \ + /usr/include/features.h /usr/include/x86_64-linux-gnu/sys/cdefs.h \ + /usr/include/x86_64-linux-gnu/bits/wordsize.h \ + /usr/include/x86_64-linux-gnu/gnu/stubs.h \ + /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h \ + /usr/include/x86_64-linux-gnu/bits/types.h \ + /usr/include/x86_64-linux-gnu/bits/typesizes.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \ + /usr/include/x86_64-linux-gnu/bits/stdio_lim.h \ + /usr/include/x86_64-linux-gnu/bits/sys_errlist.h \ + /usr/include/x86_64-linux-gnu/bits/stdio.h \ + /usr/include/x86_64-linux-gnu/bits/stdio2.h \ + /usr/lib/jvm/java-8-openjdk-amd64/include/linux/jni_md.h \ + /usr/include/stdlib.h /usr/include/x86_64-linux-gnu/bits/waitflags.h \ + /usr/include/x86_64-linux-gnu/bits/waitstatus.h /usr/include/endian.h \ + /usr/include/x86_64-linux-gnu/bits/endian.h \ + /usr/include/x86_64-linux-gnu/bits/byteswap.h \ + /usr/include/x86_64-linux-gnu/bits/byteswap-16.h \ + /usr/include/x86_64-linux-gnu/sys/types.h /usr/include/time.h \ + /usr/include/x86_64-linux-gnu/sys/select.h \ + /usr/include/x86_64-linux-gnu/bits/select.h \ + /usr/include/x86_64-linux-gnu/bits/sigset.h \ + /usr/include/x86_64-linux-gnu/bits/time.h \ + /usr/include/x86_64-linux-gnu/bits/select2.h \ + /usr/include/x86_64-linux-gnu/sys/sysmacros.h \ + /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h \ + /usr/include/x86_64-linux-gnu/bits/stdlib-float.h \ + /usr/include/x86_64-linux-gnu/bits/stdlib.h /usr/include/string.h \ + /usr/include/xlocale.h /usr/include/x86_64-linux-gnu/bits/string.h \ + /usr/include/x86_64-linux-gnu/bits/string2.h \ + /usr/include/x86_64-linux-gnu/bits/string3.h \ + ../../modules/core/includes/BOOL.h src/c/javasci2_helper.h \ + ../../modules/core/includes/sci_types.h \ + ../../modules/core/includes/MALLOC.h \ + ../../modules/core/includes/sci_mem_alloc.h \ + src/jni/../../../call_scilab/includes/call_scilab.h \ + ../../modules/core/includes/stack-c.h \ + ../../modules/core/includes/core_math.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h \ + /usr/include/limits.h /usr/include/x86_64-linux-gnu/bits/posix1_lim.h \ + /usr/include/x86_64-linux-gnu/bits/local_lim.h \ + /usr/include/linux/limits.h \ + /usr/include/x86_64-linux-gnu/bits/posix2_lim.h /usr/include/math.h \ + /usr/include/x86_64-linux-gnu/bits/math-vector.h \ + /usr/include/x86_64-linux-gnu/bits/libm-simd-decl-stubs.h \ + /usr/include/x86_64-linux-gnu/bits/huge_val.h \ + /usr/include/x86_64-linux-gnu/bits/huge_valf.h \ + /usr/include/x86_64-linux-gnu/bits/huge_vall.h \ + /usr/include/x86_64-linux-gnu/bits/inf.h \ + /usr/include/x86_64-linux-gnu/bits/nan.h \ + /usr/include/x86_64-linux-gnu/bits/mathdef.h \ + /usr/include/x86_64-linux-gnu/bits/mathcalls.h \ + /usr/include/x86_64-linux-gnu/bits/mathinline.h \ + ../../modules/core/includes/stack-def.h \ + ../../modules/core/includes/machine.h \ + ../../modules/core/includes/stackTypeVariable.h \ + ../../modules/core/includes/BOOL.h \ + ../../modules/core/includes/doublecomplex.h \ + ../../modules/core/includes/stack1.h \ + ../../modules/core/includes/scisparse.h \ + ../../modules/core/includes/stack2.h \ + ../../modules/core/includes/stack3.h \ + ../../modules/core/includes/stack-optional.h \ + ../../modules/core/includes/sci_types.h \ + ../../modules/core/includes/machine.h \ + src/jni/../../../call_scilab/includes/fromjava.h \ + src/jni/../../../call_scilab/includes/dynlib_call_scilab.h \ + src/jni/../../../api_scilab/includes/api_scilab.h \ + src/jni/../../../api_scilab/includes/api_common.h \ + src/jni/../../../api_scilab/includes/api_scilab.h \ + src/jni/../../../api_scilab/includes/api_double.h \ + ../../modules/core/includes/doublecomplex.h \ + src/jni/../../../api_scilab/includes/api_string.h \ + /usr/include/x86_64-linux-gnu/bits/wchar.h \ + /usr/include/x86_64-linux-gnu/bits/wchar2.h \ + src/jni/../../../api_scilab/includes/api_int.h \ + src/jni/../../../api_scilab/includes/api_poly.h \ + src/jni/../../../api_scilab/includes/api_sparse.h \ + src/jni/../../../api_scilab/includes/api_boolean.h \ + src/jni/../../../api_scilab/includes/api_boolean_sparse.h \ + src/jni/../../../api_scilab/includes/api_pointer.h \ + src/jni/../../../api_scilab/includes/api_list.h \ + src/jni/../../../api_scilab/includes/api_error.h \ + src/jni/../../../api_scilab/includes/api_handle.h \ + src/jni/../../../api_scilab/includes/api_optional.h \ + ../../modules/core/includes/stack-optional.h \ + src/jni/../../../api_scilab/includes/api_hypermat.h \ + ../../modules/core/includes/core_math.h \ + src/jni/../../../output_stream/includes/lasterror.h \ + src/jni/../../../output_stream/includes/dynlib_output_stream.h \ + ../../modules/core/includes/../../../modules/graphic_objects/includes/FigureList.h \ + ../../modules/core/includes/../../../modules/graphic_objects/includes/dynlib_graphic_objects.h \ + src/jni/../../../core/includes/sci_types.h + +/usr/include/stdc-predef.h: + +/usr/lib/jvm/java-8-openjdk-amd64/include/jni.h: + +/usr/include/stdio.h: + +/usr/include/features.h: + +/usr/include/x86_64-linux-gnu/sys/cdefs.h: + +/usr/include/x86_64-linux-gnu/bits/wordsize.h: + +/usr/include/x86_64-linux-gnu/gnu/stubs.h: + +/usr/include/x86_64-linux-gnu/gnu/stubs-64.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h: + +/usr/include/x86_64-linux-gnu/bits/types.h: + +/usr/include/x86_64-linux-gnu/bits/typesizes.h: + +/usr/include/libio.h: + +/usr/include/_G_config.h: + +/usr/include/wchar.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h: + +/usr/include/x86_64-linux-gnu/bits/stdio_lim.h: + +/usr/include/x86_64-linux-gnu/bits/sys_errlist.h: + +/usr/include/x86_64-linux-gnu/bits/stdio.h: + +/usr/include/x86_64-linux-gnu/bits/stdio2.h: + +/usr/lib/jvm/java-8-openjdk-amd64/include/linux/jni_md.h: + +/usr/include/stdlib.h: + +/usr/include/x86_64-linux-gnu/bits/waitflags.h: + +/usr/include/x86_64-linux-gnu/bits/waitstatus.h: + +/usr/include/endian.h: + +/usr/include/x86_64-linux-gnu/bits/endian.h: + +/usr/include/x86_64-linux-gnu/bits/byteswap.h: + +/usr/include/x86_64-linux-gnu/bits/byteswap-16.h: + +/usr/include/x86_64-linux-gnu/sys/types.h: + +/usr/include/time.h: + +/usr/include/x86_64-linux-gnu/sys/select.h: + +/usr/include/x86_64-linux-gnu/bits/select.h: + +/usr/include/x86_64-linux-gnu/bits/sigset.h: + +/usr/include/x86_64-linux-gnu/bits/time.h: + +/usr/include/x86_64-linux-gnu/bits/select2.h: + +/usr/include/x86_64-linux-gnu/sys/sysmacros.h: + +/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h: + +/usr/include/alloca.h: + +/usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h: + +/usr/include/x86_64-linux-gnu/bits/stdlib-float.h: + +/usr/include/x86_64-linux-gnu/bits/stdlib.h: + +/usr/include/string.h: + +/usr/include/xlocale.h: + +/usr/include/x86_64-linux-gnu/bits/string.h: + +/usr/include/x86_64-linux-gnu/bits/string2.h: + +/usr/include/x86_64-linux-gnu/bits/string3.h: + +../../modules/core/includes/BOOL.h: + +src/c/javasci2_helper.h: + +../../modules/core/includes/sci_types.h: + +../../modules/core/includes/MALLOC.h: + +../../modules/core/includes/sci_mem_alloc.h: + +src/jni/../../../call_scilab/includes/call_scilab.h: + +../../modules/core/includes/stack-c.h: + +../../modules/core/includes/core_math.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h: + +/usr/include/limits.h: + +/usr/include/x86_64-linux-gnu/bits/posix1_lim.h: + +/usr/include/x86_64-linux-gnu/bits/local_lim.h: + +/usr/include/linux/limits.h: + +/usr/include/x86_64-linux-gnu/bits/posix2_lim.h: + +/usr/include/math.h: + +/usr/include/x86_64-linux-gnu/bits/math-vector.h: + +/usr/include/x86_64-linux-gnu/bits/libm-simd-decl-stubs.h: + +/usr/include/x86_64-linux-gnu/bits/huge_val.h: + +/usr/include/x86_64-linux-gnu/bits/huge_valf.h: + +/usr/include/x86_64-linux-gnu/bits/huge_vall.h: + +/usr/include/x86_64-linux-gnu/bits/inf.h: + +/usr/include/x86_64-linux-gnu/bits/nan.h: + +/usr/include/x86_64-linux-gnu/bits/mathdef.h: + +/usr/include/x86_64-linux-gnu/bits/mathcalls.h: + +/usr/include/x86_64-linux-gnu/bits/mathinline.h: + +../../modules/core/includes/stack-def.h: + +../../modules/core/includes/machine.h: + +../../modules/core/includes/stackTypeVariable.h: + +../../modules/core/includes/BOOL.h: + +../../modules/core/includes/doublecomplex.h: + +../../modules/core/includes/stack1.h: + +../../modules/core/includes/scisparse.h: + +../../modules/core/includes/stack2.h: + +../../modules/core/includes/stack3.h: + +../../modules/core/includes/stack-optional.h: + +../../modules/core/includes/sci_types.h: + +../../modules/core/includes/machine.h: + +src/jni/../../../call_scilab/includes/fromjava.h: + +src/jni/../../../call_scilab/includes/dynlib_call_scilab.h: + +src/jni/../../../api_scilab/includes/api_scilab.h: + +src/jni/../../../api_scilab/includes/api_common.h: + +src/jni/../../../api_scilab/includes/api_scilab.h: + +src/jni/../../../api_scilab/includes/api_double.h: + +../../modules/core/includes/doublecomplex.h: + +src/jni/../../../api_scilab/includes/api_string.h: + +/usr/include/x86_64-linux-gnu/bits/wchar.h: + +/usr/include/x86_64-linux-gnu/bits/wchar2.h: + +src/jni/../../../api_scilab/includes/api_int.h: + +src/jni/../../../api_scilab/includes/api_poly.h: + +src/jni/../../../api_scilab/includes/api_sparse.h: + +src/jni/../../../api_scilab/includes/api_boolean.h: + +src/jni/../../../api_scilab/includes/api_boolean_sparse.h: + +src/jni/../../../api_scilab/includes/api_pointer.h: + +src/jni/../../../api_scilab/includes/api_list.h: + +src/jni/../../../api_scilab/includes/api_error.h: + +src/jni/../../../api_scilab/includes/api_handle.h: + +src/jni/../../../api_scilab/includes/api_optional.h: + +../../modules/core/includes/stack-optional.h: + +src/jni/../../../api_scilab/includes/api_hypermat.h: + +../../modules/core/includes/core_math.h: + +src/jni/../../../output_stream/includes/lasterror.h: + +src/jni/../../../output_stream/includes/dynlib_output_stream.h: + +../../modules/core/includes/../../../modules/graphic_objects/includes/FigureList.h: + +../../modules/core/includes/../../../modules/graphic_objects/includes/dynlib_graphic_objects.h: + +src/jni/../../../core/includes/sci_types.h: diff --git a/modules/javasci/src/jni/.deps/libjavasci2_la-putLists.Plo b/modules/javasci/src/jni/.deps/libjavasci2_la-putLists.Plo new file mode 100755 index 000000000..8f22555d6 --- /dev/null +++ b/modules/javasci/src/jni/.deps/libjavasci2_la-putLists.Plo @@ -0,0 +1,292 @@ +src/jni/libjavasci2_la-putLists.lo: src/jni/putLists.c \ + /usr/include/stdc-predef.h /usr/include/string.h /usr/include/features.h \ + /usr/include/x86_64-linux-gnu/sys/cdefs.h \ + /usr/include/x86_64-linux-gnu/bits/wordsize.h \ + /usr/include/x86_64-linux-gnu/gnu/stubs.h \ + /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h /usr/include/xlocale.h \ + /usr/include/x86_64-linux-gnu/bits/string.h \ + /usr/include/x86_64-linux-gnu/bits/string2.h /usr/include/endian.h \ + /usr/include/x86_64-linux-gnu/bits/endian.h \ + /usr/include/x86_64-linux-gnu/bits/byteswap.h \ + /usr/include/x86_64-linux-gnu/bits/types.h \ + /usr/include/x86_64-linux-gnu/bits/typesizes.h \ + /usr/include/x86_64-linux-gnu/bits/byteswap-16.h /usr/include/stdlib.h \ + /usr/include/x86_64-linux-gnu/bits/string3.h \ + /usr/lib/jvm/java-8-openjdk-amd64/include/jni.h /usr/include/stdio.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \ + /usr/include/x86_64-linux-gnu/bits/stdio_lim.h \ + /usr/include/x86_64-linux-gnu/bits/sys_errlist.h \ + /usr/include/x86_64-linux-gnu/bits/stdio.h \ + /usr/include/x86_64-linux-gnu/bits/stdio2.h \ + /usr/lib/jvm/java-8-openjdk-amd64/include/linux/jni_md.h \ + ../../modules/api_scilab/includes/api_scilab.h \ + ../../modules/core/includes/stack-c.h \ + ../../modules/core/includes/core_math.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h \ + /usr/include/limits.h /usr/include/x86_64-linux-gnu/bits/posix1_lim.h \ + /usr/include/x86_64-linux-gnu/bits/local_lim.h \ + /usr/include/linux/limits.h \ + /usr/include/x86_64-linux-gnu/bits/posix2_lim.h /usr/include/math.h \ + /usr/include/x86_64-linux-gnu/bits/math-vector.h \ + /usr/include/x86_64-linux-gnu/bits/libm-simd-decl-stubs.h \ + /usr/include/x86_64-linux-gnu/bits/huge_val.h \ + /usr/include/x86_64-linux-gnu/bits/huge_valf.h \ + /usr/include/x86_64-linux-gnu/bits/huge_vall.h \ + /usr/include/x86_64-linux-gnu/bits/inf.h \ + /usr/include/x86_64-linux-gnu/bits/nan.h \ + /usr/include/x86_64-linux-gnu/bits/mathdef.h \ + /usr/include/x86_64-linux-gnu/bits/mathcalls.h \ + /usr/include/x86_64-linux-gnu/bits/mathinline.h \ + /usr/include/x86_64-linux-gnu/bits/waitflags.h \ + /usr/include/x86_64-linux-gnu/bits/waitstatus.h \ + /usr/include/x86_64-linux-gnu/sys/types.h /usr/include/time.h \ + /usr/include/x86_64-linux-gnu/sys/select.h \ + /usr/include/x86_64-linux-gnu/bits/select.h \ + /usr/include/x86_64-linux-gnu/bits/sigset.h \ + /usr/include/x86_64-linux-gnu/bits/time.h \ + /usr/include/x86_64-linux-gnu/bits/select2.h \ + /usr/include/x86_64-linux-gnu/sys/sysmacros.h \ + /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h \ + /usr/include/x86_64-linux-gnu/bits/stdlib-float.h \ + /usr/include/x86_64-linux-gnu/bits/stdlib.h \ + ../../modules/core/includes/stack-def.h \ + ../../modules/core/includes/machine.h \ + ../../modules/core/includes/stackTypeVariable.h \ + ../../modules/core/includes/BOOL.h \ + ../../modules/core/includes/doublecomplex.h \ + ../../modules/core/includes/stack1.h \ + ../../modules/core/includes/scisparse.h \ + ../../modules/core/includes/stack2.h \ + ../../modules/core/includes/stack3.h \ + ../../modules/core/includes/stack-optional.h \ + ../../modules/core/includes/sci_types.h \ + ../../modules/api_scilab/includes/api_common.h \ + ../../modules/api_scilab/includes/api_scilab.h \ + ../../modules/api_scilab/includes/api_double.h \ + ../../modules/core/includes/doublecomplex.h \ + ../../modules/api_scilab/includes/api_string.h \ + /usr/include/x86_64-linux-gnu/bits/wchar.h \ + /usr/include/x86_64-linux-gnu/bits/wchar2.h \ + ../../modules/api_scilab/includes/api_int.h \ + ../../modules/api_scilab/includes/api_poly.h \ + ../../modules/api_scilab/includes/api_sparse.h \ + ../../modules/api_scilab/includes/api_boolean.h \ + ../../modules/api_scilab/includes/api_boolean_sparse.h \ + ../../modules/api_scilab/includes/api_pointer.h \ + ../../modules/api_scilab/includes/api_list.h \ + ../../modules/api_scilab/includes/api_error.h \ + ../../modules/api_scilab/includes/api_handle.h \ + ../../modules/api_scilab/includes/api_optional.h \ + ../../modules/core/includes/stack-optional.h \ + ../../modules/api_scilab/includes/api_hypermat.h \ + ../../modules/core/includes/core_math.h \ + ../../modules/core/includes/sci_types.h \ + ../../modules/core/includes/MALLOC.h \ + ../../modules/core/includes/sci_mem_alloc.h \ + ../../modules/core/includes/BOOL.h + +/usr/include/stdc-predef.h: + +/usr/include/string.h: + +/usr/include/features.h: + +/usr/include/x86_64-linux-gnu/sys/cdefs.h: + +/usr/include/x86_64-linux-gnu/bits/wordsize.h: + +/usr/include/x86_64-linux-gnu/gnu/stubs.h: + +/usr/include/x86_64-linux-gnu/gnu/stubs-64.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h: + +/usr/include/xlocale.h: + +/usr/include/x86_64-linux-gnu/bits/string.h: + +/usr/include/x86_64-linux-gnu/bits/string2.h: + +/usr/include/endian.h: + +/usr/include/x86_64-linux-gnu/bits/endian.h: + +/usr/include/x86_64-linux-gnu/bits/byteswap.h: + +/usr/include/x86_64-linux-gnu/bits/types.h: + +/usr/include/x86_64-linux-gnu/bits/typesizes.h: + +/usr/include/x86_64-linux-gnu/bits/byteswap-16.h: + +/usr/include/stdlib.h: + +/usr/include/x86_64-linux-gnu/bits/string3.h: + +/usr/lib/jvm/java-8-openjdk-amd64/include/jni.h: + +/usr/include/stdio.h: + +/usr/include/libio.h: + +/usr/include/_G_config.h: + +/usr/include/wchar.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h: + +/usr/include/x86_64-linux-gnu/bits/stdio_lim.h: + +/usr/include/x86_64-linux-gnu/bits/sys_errlist.h: + +/usr/include/x86_64-linux-gnu/bits/stdio.h: + +/usr/include/x86_64-linux-gnu/bits/stdio2.h: + +/usr/lib/jvm/java-8-openjdk-amd64/include/linux/jni_md.h: + +../../modules/api_scilab/includes/api_scilab.h: + +../../modules/core/includes/stack-c.h: + +../../modules/core/includes/core_math.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h: + +/usr/include/limits.h: + +/usr/include/x86_64-linux-gnu/bits/posix1_lim.h: + +/usr/include/x86_64-linux-gnu/bits/local_lim.h: + +/usr/include/linux/limits.h: + +/usr/include/x86_64-linux-gnu/bits/posix2_lim.h: + +/usr/include/math.h: + +/usr/include/x86_64-linux-gnu/bits/math-vector.h: + +/usr/include/x86_64-linux-gnu/bits/libm-simd-decl-stubs.h: + +/usr/include/x86_64-linux-gnu/bits/huge_val.h: + +/usr/include/x86_64-linux-gnu/bits/huge_valf.h: + +/usr/include/x86_64-linux-gnu/bits/huge_vall.h: + +/usr/include/x86_64-linux-gnu/bits/inf.h: + +/usr/include/x86_64-linux-gnu/bits/nan.h: + +/usr/include/x86_64-linux-gnu/bits/mathdef.h: + +/usr/include/x86_64-linux-gnu/bits/mathcalls.h: + +/usr/include/x86_64-linux-gnu/bits/mathinline.h: + +/usr/include/x86_64-linux-gnu/bits/waitflags.h: + +/usr/include/x86_64-linux-gnu/bits/waitstatus.h: + +/usr/include/x86_64-linux-gnu/sys/types.h: + +/usr/include/time.h: + +/usr/include/x86_64-linux-gnu/sys/select.h: + +/usr/include/x86_64-linux-gnu/bits/select.h: + +/usr/include/x86_64-linux-gnu/bits/sigset.h: + +/usr/include/x86_64-linux-gnu/bits/time.h: + +/usr/include/x86_64-linux-gnu/bits/select2.h: + +/usr/include/x86_64-linux-gnu/sys/sysmacros.h: + +/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h: + +/usr/include/alloca.h: + +/usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h: + +/usr/include/x86_64-linux-gnu/bits/stdlib-float.h: + +/usr/include/x86_64-linux-gnu/bits/stdlib.h: + +../../modules/core/includes/stack-def.h: + +../../modules/core/includes/machine.h: + +../../modules/core/includes/stackTypeVariable.h: + +../../modules/core/includes/BOOL.h: + +../../modules/core/includes/doublecomplex.h: + +../../modules/core/includes/stack1.h: + +../../modules/core/includes/scisparse.h: + +../../modules/core/includes/stack2.h: + +../../modules/core/includes/stack3.h: + +../../modules/core/includes/stack-optional.h: + +../../modules/core/includes/sci_types.h: + +../../modules/api_scilab/includes/api_common.h: + +../../modules/api_scilab/includes/api_scilab.h: + +../../modules/api_scilab/includes/api_double.h: + +../../modules/core/includes/doublecomplex.h: + +../../modules/api_scilab/includes/api_string.h: + +/usr/include/x86_64-linux-gnu/bits/wchar.h: + +/usr/include/x86_64-linux-gnu/bits/wchar2.h: + +../../modules/api_scilab/includes/api_int.h: + +../../modules/api_scilab/includes/api_poly.h: + +../../modules/api_scilab/includes/api_sparse.h: + +../../modules/api_scilab/includes/api_boolean.h: + +../../modules/api_scilab/includes/api_boolean_sparse.h: + +../../modules/api_scilab/includes/api_pointer.h: + +../../modules/api_scilab/includes/api_list.h: + +../../modules/api_scilab/includes/api_error.h: + +../../modules/api_scilab/includes/api_handle.h: + +../../modules/api_scilab/includes/api_optional.h: + +../../modules/core/includes/stack-optional.h: + +../../modules/api_scilab/includes/api_hypermat.h: + +../../modules/core/includes/core_math.h: + +../../modules/core/includes/sci_types.h: + +../../modules/core/includes/MALLOC.h: + +../../modules/core/includes/sci_mem_alloc.h: + +../../modules/core/includes/BOOL.h: diff --git a/modules/javasci/src/jni/.dirstamp b/modules/javasci/src/jni/.dirstamp new file mode 100755 index 000000000..e69de29bb --- /dev/null +++ b/modules/javasci/src/jni/.dirstamp diff --git a/modules/javasci/src/jni/.libs/libjavasci2_la-call_scilab_wrap.o b/modules/javasci/src/jni/.libs/libjavasci2_la-call_scilab_wrap.o Binary files differnew file mode 100755 index 000000000..d8872168b --- /dev/null +++ b/modules/javasci/src/jni/.libs/libjavasci2_la-call_scilab_wrap.o diff --git a/modules/javasci/src/jni/.libs/libjavasci2_la-putLists.o b/modules/javasci/src/jni/.libs/libjavasci2_la-putLists.o Binary files differnew file mode 100755 index 000000000..38cc962c2 --- /dev/null +++ b/modules/javasci/src/jni/.libs/libjavasci2_la-putLists.o diff --git a/modules/javasci/src/jni/call_scilab.i b/modules/javasci/src/jni/call_scilab.i new file mode 100755 index 000000000..aa2faeaae --- /dev/null +++ b/modules/javasci/src/jni/call_scilab.i @@ -0,0 +1,189 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * Copyright (C) 2011 - Scilab Enterprises - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ + +/* Call_Scilab.i */ +/** + * Windows: swig -java -package org.scilab.modules.javasci -outdir ../java/org/scilab/modules/javasci/ call_scilab.i + * Other: Use the option --enable-build-swig to the configure +*/ + +//%rename(ScilabTypeEnum) sci_types; + +%module Call_Scilab +%{ +#include "BOOL.h" +#define ENABLE_HELPERS +#include "javasci2_helper.h" +#include "MALLOC.h" +#include "../../../call_scilab/includes/call_scilab.h" +#include "../../../call_scilab/includes/fromjava.h" +#include "../../../api_scilab/includes/api_scilab.h" +#include "../../../output_stream/includes/lasterror.h" +#include "../../../modules/graphic_objects/includes/FigureList.h" +#include "../../../core/includes/sci_types.h" +%} +%include "../../../jvm/src/jni/scilab_typemaps.i" + +%import "../../../types/src/jni/sci_types.i" + +#ifdef SWIGJAVA + +/* JavaDoc for Call_ScilabJNI class */ +%pragma(java) jniclassclassmodifiers=%{ +/* It is generated code. Disable checkstyle */ +//CHECKSTYLE:OFF + /** + * Connector for Javasci v2. + * This class should <b>not</b> be used directly + * @see org.scilab.modules.javasci.Scilab + * @author DIGITEO - Sylvestre LEDRU + */ +class%} + +/* Constructor for Call_ScilabJNI class */ +%pragma(java) jniclasscode=" + /** + * Constructor + */ + protected Call_ScilabJNI() { + throw new UnsupportedOperationException(); + }"; + +/* static load of library */ +%pragma(java) jniclasscode=%{ + static { + try { + if (System.getProperty("os.name").toLowerCase().contains("windows")) { + System.loadLibrary("javasci"); + } else { + System.loadLibrary("javasci2"); + } + } catch (SecurityException e) { + System.err.println("A security manager exists and does not allow the loading of the specified dynamic library :"); + e.printStackTrace(System.err); + } catch (UnsatisfiedLinkError e) { + System.err.println("The native library javasci does not exist or cannot be found."); + e.printStackTrace(System.err); + } + } + + public final static native int putList(String varNmae, Object list, char type); +%} + +/* JavaDoc for Call_Scilab class */ +%pragma(java) moduleclassmodifiers=" +import org.scilab.modules.types.ScilabTypeEnum; +import org.scilab.modules.types.ScilabIntegerTypeEnum; + + /** + * Connector for Javasci v2. + * This class should <b>not</b> be used directly + * @see org.scilab.modules.javasci.Scilab + * @author DIGITEO - Sylvestre LEDRU + */ +public class"; + +/* Constructor for Call_Scilab class */ +%pragma(java) modulecode=" + /** + * Constructor + */ + protected Call_Scilab() { + throw new UnsupportedOperationException(); + }"; + +#endif + + +int Call_ScilabOpen(char* SCIpath, BOOL advancedMode, char *ScilabStartup, int Stacksize); + +BOOL TerminateScilab(char *ScilabQuit); + +int SendScilabJob(char *job); + +int SendScilabJobs(char **jobs,int numberjobs); + +// Direct access to the Scilab function (no helper) +void SetFromJavaToON(void); + +// Direct access to the Scilab function (no helper) +%rename(isGraphicOpened) sciHasFigures; +BOOL sciHasFigures( void ); + +// Direct access to the Scilab function (no helper) +%rename(GetLastErrorCode) getLastErrorValue; +int getLastErrorValue(void); + +BOOL isExistingVariable(char* varname); + +%rename(getLastErrorMessage) getLastErrorMessageSingle; +const char* getLastErrorMessageSingle(); + +sci_types getVariableType(char *varname); + +sci_int_types getIntegerPrecision(char* varname); + +%rename(isComplex) isComplexVar; +BOOL isComplexVar(char* varname); + +%include "call_scilab_java_typemaps_string.i" +// string +int putString(char* variableName, char **variable, int nbRow, int nbCol); + +// This position matters. It will apply only to the following lines +%include "call_scilab_java_typemaps.i" + +int putDoubleComplex(char * variableName, double variable[], int nbRow, int nbCol, double imag[], int nbRowI, int nbColI); + +// double (default Scilab type) +int putDouble(char * variableName, double variable[], int nbRow, int nbCol); + +// boolean (%t / %f) +int putBoolean(char * variableName, BOOL variable[], int nbRow, int nbCol); + +// byte/char = int8 +int putByte(char * variableName, byte variable[], int nbRow, int nbCol); + +int putUnsignedByte(char * variableName, byte variable[], int nbRow, int nbCol); + +// short = int16 +int putShort(char * variableName, short variable[], int nbRow, int nbCol); + +int putUnsignedShort(char * variableName, unsigned short variable[], int nbRow, int nbCol); + +// int = int32 +int putInt(char * variableName, int variable[], int nbRow, int nbCol); + +int putUnsignedInt(char * variableName, unsigned int variable[], int nbRow, int nbCol); + +#ifdef __SCILAB_INT64__ +// long = int64 +int putLong(char * variableName, long variable[], int nbRow, int nbCol); + +int putUnsignedLong(char * variableName, unsigned long variable[], int nbRow, int nbCol); +#endif + +// This position matters. It will apply only to the following lines +%include "call_scilab_java_typemaps_sparse.i" + +int putSparse(char * variableName, int nbRow, int nbCol, int * nbRowItem, int nbRowItemL, int * colPos, int colPosL, double * data, int dataL); + +int putComplexSparse(char * variableName, int nbRow, int nbCol, int * nbRowItem, int nbRowItemL, int * colPos, int colPosL, double * data, int dataL, double * imag, int imagL); + +int putBooleanSparse(char * variableName, int nbRow, int nbCol, int * nbRowItem, int nbRowItemL, int * colPos, int colPosL); + +// This position matters. It will apply only to the following lines +%include "call_scilab_java_typemaps_poly.i" + +int putPolynomial(char * variableName, char * polyVarName, double ** data, int nbRow, int nbCol, int * nbCoef); +int putComplexPolynomial(char * variableName, char * polyVarName, double ** data, int nbRow, int nbCol, int * nbCoef, double ** imag, int nbRowI, int nbColI, int * nbCoefI); diff --git a/modules/javasci/src/jni/call_scilab_java_typemaps.i b/modules/javasci/src/jni/call_scilab_java_typemaps.i new file mode 100755 index 000000000..f37cc2b47 --- /dev/null +++ b/modules/javasci/src/jni/call_scilab_java_typemaps.i @@ -0,0 +1,111 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ + + +////////////////////////////////////////////// + + + +////////////////////////////////////////////// + +%define JAVASCI_ARRAYS_IMPL(CTYPE, JNITYPE, JAVATYPE, JAVAPRIMITIVETYPE) + +%typemap(jni) (CTYPE *) "jobjectArray" +%typemap(jtype) (CTYPE *) "JAVAPRIMITIVETYPE[][]" +%typemap(jstype) (CTYPE *) "JAVAPRIMITIVETYPE[][]" +%typemap(javain) CTYPE *OUTVALUE "$javainput" +%typemap(javaout) (CTYPE *) { + return $jnicall; +} + + +%typemap(javain) CTYPE[ANY], CTYPE[] "$javainput" + +////////////////////////// + +//%include "arrays_java.i" + +/* Transform the input datatype CTYPE[] to JAVAPRIMITIVETYPE[][] to facilitate the +matching in Java */ +%typemap(jni) CTYPE[] "jobjectArray" +%typemap(jtype) CTYPE[] "JAVAPRIMITIVETYPE[][]" +%typemap(jstype) CTYPE[] "JAVAPRIMITIVETYPE[][]" + + +%typemap(argout) (CTYPE variable[], int nbRow, int nbCol) { +// Specific target because it was freeing the wrong argument + free($1); +} + + +%typemap(in) (CTYPE variable[], int nbRow, int nbCol) { +// Convert the CTYPE[][] => CTYPE * + int i = 0, j = 0; + $2 = (*jenv)->GetArrayLength(jenv, $input); + $3 = 0; + $1 = NULL; + + + for (; i < $2; i++) + { + jboolean isCopy = JNI_FALSE; + ##JNITYPE##* element = NULL; + ##JNITYPE##Array oneDim = (##JNITYPE##Array)(*jenv)->GetObjectArrayElement(jenv, $input, i); + if ($3 == 0) + { + /* First time we are here, init + create the array where we store the data */ + $3 = (*jenv)->GetArrayLength(jenv, oneDim); + $1 = (CTYPE*)malloc(sizeof(CTYPE) * $2 * $3); + } + isCopy = JNI_FALSE; + element = (##JNITYPE##*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy); + + for (j = 0; j < $3; j++) + { + $1[j * $2 + i] = element[j]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } +} + +%typemap(in) (CTYPE imag[], int nbRowI, int nbColI) = (CTYPE variable[], int nbRow, int nbCol); +%typemap(argout) (CTYPE imag[], int nbRowI, int nbColI) = (CTYPE variable[], int nbRow, int nbCol); +%enddef + +// See SWIG documentation for the full list: +// http://www.swig.org/Doc1.3/Java.html#default_primitive_type_mappings + +// Scilab: int8 +JAVASCI_ARRAYS_IMPL(byte, jbyte, Byte, byte) /* signed char[] */ +JAVASCI_ARRAYS_IMPL(unsigned char, jshort, Short, jshort) /* unsigned char */ + +// Scilab: int16 + +JAVASCI_ARRAYS_IMPL(short, jshort, Short, short) /* short[] */ +JAVASCI_ARRAYS_IMPL(unsigned short, jchar, Char, short) /* unsigned short[] */ + +// Scilab: int32 +JAVASCI_ARRAYS_IMPL(int, jint, Int, int) /* int[] */ +JAVASCI_ARRAYS_IMPL(unsigned int, jint, Int, int) /* unsigned int[] */ + +#ifdef __SCILAB_INT64__ +// Scilab: int64 +JAVASCI_ARRAYS_IMPL(long, jint, int, long) /* long[] */ +JAVASCI_ARRAYS_IMPL(unsigned long, jlong, Long, long) /* unsigned long[] */ +#endif + +//JAVASCI_ARRAYS_IMPL(float, jfloat, Float, float, ) /* float[] */ +// Scilab: double +JAVASCI_ARRAYS_IMPL(double, jdouble, Double, double) /* double[] */ +// Scilab: boolean +JAVASCI_ARRAYS_IMPL(BOOL, jboolean, Boolean, boolean) /* double[] */ diff --git a/modules/javasci/src/jni/call_scilab_java_typemaps_complex.i b/modules/javasci/src/jni/call_scilab_java_typemaps_complex.i new file mode 100755 index 000000000..15de13ac6 --- /dev/null +++ b/modules/javasci/src/jni/call_scilab_java_typemaps_complex.i @@ -0,0 +1,53 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ + + +%define JAVASCI_COMPLEX_ARRAYS_IMPL(CTYPE, JNITYPE, JAVATYPE, JAVAPRIMITIVETYPE, JNICODE) + +/* Transform the input datatype CTYPE[] to JAVAPRIMITIVETYPE[][] to facilitate the +matching in Java */ +%typemap(jni) CTYPE[] "jobjectArray" +%typemap(jtype) CTYPE[] "JAVAPRIMITIVETYPE[]" +%typemap(jstype) CTYPE[] "JAVAPRIMITIVETYPE[]" + +%typemap(argout) (CTYPE variable[], int nbRow, int nbCol) { +// Specific target because it was freeing the wrong argument +} + +%typemap(in) (CTYPE variable[], int nbRow, int nbCol) { +// Convert the CTYPE[][] => CTYPE * + $2 = (*jenv)->GetArrayLength(jenv, $input); + $3 = 0; + $1 = NULL; + int i=0, j=0; + ##JNITYPE## *element = NULL; + + for(i=0; i<$2; i++) { + ##JNITYPE##Array oneDim=(##JNITYPE##Array)(*jenv)->GetObjectArrayElement(jenv, jarg2, i); + if ($3==0) { + /* First time we are here, init + create the array where we store the data */ + $3 = (*jenv)->GetArrayLength(jenv, oneDim); + $1 = (CTYPE*)malloc(sizeof(##CTYPE##)*arg3*arg4); + } + element = (*jenv)->Get##JAVATYPE##ArrayElements(jenv, oneDim, 0); + + for(j=0; j<$3; j++) { + $1[j*$2+i]=element[j]; + } + } + +} +%enddef + + + +JAVASCI_COMPLEX_ARRAYS_IMPL(double, jdouble, Double, double, "[D") /* double[] */ diff --git a/modules/javasci/src/jni/call_scilab_java_typemaps_poly.i b/modules/javasci/src/jni/call_scilab_java_typemaps_poly.i new file mode 100755 index 000000000..6c2c57b22 --- /dev/null +++ b/modules/javasci/src/jni/call_scilab_java_typemaps_poly.i @@ -0,0 +1,82 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ + + +////////////////////////////////////////////// + + + +////////////////////////////////////////////// + +%define JAVASCI_POLY_ARRAYS_IMPL(CTYPE, JNITYPE, JAVATYPE, JAVAPRIMITIVETYPE) + +%typemap(jni) (CTYPE **) "jobjectArray" +%typemap(jtype) (CTYPE **) "JAVAPRIMITIVETYPE[][][]" +%typemap(jstype) (CTYPE **) "JAVAPRIMITIVETYPE[][][]" +%typemap(javain) (CTYPE **) "$javainput" +%typemap(javaout) CTYPE** { + return $jnicall; +} + +////////////////////////// + +%typemap(argout) (CTYPE ** data, int nbRow, int nbCol, int * nbCoef) { +// Specific target because it was freeing the wrong argument + int i = 0; + for (; i < $2 * $3; i++) + { + FREE($1[i]); + } + FREE($1); + FREE($4); +} + + +%typemap(in) (CTYPE ** data, int nbRow, int nbCol, int * nbCoef) { +// Convert the CTYPE[][] => CTYPE * + int i = 0, j = 0, k = 0; + $2 = (*jenv)->GetArrayLength(jenv, $input); + $3 = 0; + $1 = NULL; + + for (; i < $2; i++) { + jobjectArray dblDim = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, $input, i); + if ($3 == 0) { + /* First time we are here, init + create the array where we store the data */ + $3 = (*jenv)->GetArrayLength(jenv, dblDim); + $1 = (CTYPE**)malloc(sizeof(##CTYPE##*) * $2 * $3); + $4 = (int*)malloc(sizeof(int) * $2 * $3); + } + for (j = 0; j < $3; j++) + { + ##JNITYPE##Array oneDim = (##JNITYPE##Array)(*jenv)->GetObjectArrayElement(jenv, dblDim, j); + jboolean isCopy = JNI_FALSE; + ##JNITYPE##* element = NULL; + $4[j * $2 + i] = (*jenv)->GetArrayLength(jenv, oneDim); + $1[j * $2 + i] = (##CTYPE##*)MALLOC(sizeof(##JNITYPE##) * $4[j * $2 + i]); + isCopy = JNI_FALSE; + element = (##JNITYPE##*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy); + memcpy($1[j * $2 + i], element, sizeof(##JNITYPE##) * $4[j * $2 + i]); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, 0); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + (*jenv)->DeleteLocalRef(jenv, dblDim); + } + } + +%typemap(argout) (CTYPE ** imag, int nbRowI, int nbColI, int * nbCoefI) = (CTYPE ** data, int nbRow, int nbCol, int * nbCoef); +%typemap(in) (CTYPE ** imag, int nbRowI, int nbColI, int * nbCoefI) = (CTYPE ** data, int nbRow, int nbCol, int * nbCoef); + +%enddef + +JAVASCI_POLY_ARRAYS_IMPL(double, jdouble, Double, double) /* double[] */ + diff --git a/modules/javasci/src/jni/call_scilab_java_typemaps_sparse.i b/modules/javasci/src/jni/call_scilab_java_typemaps_sparse.i new file mode 100755 index 000000000..986ede081 --- /dev/null +++ b/modules/javasci/src/jni/call_scilab_java_typemaps_sparse.i @@ -0,0 +1,63 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ + + +////////////////////////////////////////////// + + + +////////////////////////////////////////////// + +%define JAVASCI_SPARSE_ARRAYS_IMPL(CTYPE, JNITYPE, JAVATYPE, JAVAPRIMITIVETYPE) + +%typemap(jni) (CTYPE *) "jobjectArray" +%typemap(jtype) (CTYPE *) "JAVAPRIMITIVETYPE[]" +%typemap(jstype) (CTYPE *) "JAVAPRIMITIVETYPE[]" +%typemap(javain) (CTYPE *) "$javainput" +%typemap(javaout) (CTYPE *) { + return $jnicall; +} + +////////////////////////// + +%typemap(argout) (CTYPE * nbRowItem, int nbRowItemL) { +// Specific target because it was freeing the wrong argument + FREE($1); +} + + +%typemap(in) (CTYPE * nbRowItem, int nbRowItemL) { + jboolean isCopy = JNI_FALSE; + ##JNITYPE##* element = NULL; +// Convert the CTYPE[][] => CTYPE * + $2 = (*jenv)->GetArrayLength(jenv, $input); + $1 = (CTYPE*)MALLOC(sizeof(##CTYPE##) * $2); + + isCopy = JNI_FALSE; + element = (##JNITYPE##*)(*jenv)->GetPrimitiveArrayCritical(jenv, $input, &isCopy); + memcpy($1, element, sizeof(##CTYPE##) * $2); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, $input, element, 0); + } + +%typemap(in) (CTYPE * colPos, int colPosL) = (CTYPE * nbRowItem, int nbRowItemL); +%typemap(argout) (CTYPE * colPos, int colPosL) = (CTYPE * nbRowItem, int nbRowItemL); +%typemap(in) (CTYPE * data, int dataL) = (CTYPE * nbRowItem, int nbRowItemL); +%typemap(argout) (CTYPE * data, int dataL) = (CTYPE * nbRowItem, int nbRowItemL); +%typemap(in) (CTYPE * imag, int imagL) = (CTYPE * nbRowItem, int nbRowItemL); +%typemap(argout) (CTYPE * imag, int imagL) = (CTYPE * nbRowItem, int nbRowItemL); +%enddef + +// See SWIG documentation for the full list: +// http://www.swig.org/Doc1.3/Java.html#default_primitive_type_mappings + +JAVASCI_SPARSE_ARRAYS_IMPL(double, jdouble, Double, double) /* double[] */ +JAVASCI_SPARSE_ARRAYS_IMPL(int, jint, Int, int) /* int[] */ diff --git a/modules/javasci/src/jni/call_scilab_java_typemaps_string.i b/modules/javasci/src/jni/call_scilab_java_typemaps_string.i new file mode 100755 index 000000000..fd4235af2 --- /dev/null +++ b/modules/javasci/src/jni/call_scilab_java_typemaps_string.i @@ -0,0 +1,110 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ + +%typemap(in) (char* variableName, int *nbRow, int *nbCol) { + $2 = &nbRow; + $3 = &nbCol; + $1 = 0; + if ($input) { + $1 = (char *)(*jenv)->GetStringUTFChars(jenv, $input, 0); + if (!$1) return 0; + } +} + +// retrieve from the native code a char ** => String[][] (java) +%typemap(out) (char **) (int nbRow, int nbCol) { + const jclass clazz = (*jenv)->FindClass(jenv, "java/lang/Object"); + int i = 0, j = 0; + + jresult = (*jenv)->NewObjectArray(jenv, nbRow,clazz, NULL); + + for (; i < nbRow; i++) + { + jobjectArray jarray = (*jenv)->NewObjectArray(jenv, nbCol, clazz, NULL); + if (jarray == NULL) + { + printf("Could not allocate\n"); + fflush(NULL); + } + + for (j = 0; j < nbCol; j++) { + /* Scilab is storing matrice cols by cols while Java is doing it + row by row. Therefor, we need to convert it */ + jstring temp_string = (*jenv)->NewStringUTF(jenv, (const char *)result[nbRow*j+i]); + (*jenv)->SetObjectArrayElement(jenv, jarray, j, temp_string); + (*jenv)->DeleteLocalRef(jenv, temp_string); + } + + (*jenv)->SetObjectArrayElement(jenv, jresult, i, jarray); + (*jenv)->DeleteLocalRef(jenv, jarray); + } + + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + free(result); +} + +/* Transform the input datatype char[] to char[][] to facilitate the +matching in Java */ +%typemap(jni) (char **) "jobjectArray" +%typemap(jtype) (char **) "String[][]" +%typemap(jstype) (char **) "String[][]" + +%typemap(argout) (char **variable, int nbRow, int nbCol) { +// Specific target because it was freeing the wrong argument + int i = 0; + for (; i < $2 * $3; i++) + { + FREE($1[i]); + } + FREE($1); +} + +%typemap(in) (char **variable, int nbRow, int nbCol) { + int i=0, j=0; + // Convert the String[][] => char * + $2 = (*jenv)->GetArrayLength(jenv, $input); + $3 = 0; + $1 = NULL; + + for (; i < $2; i++) + { + jobjectArray oneDim = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, $input, i); + if ($3 == 0) + { + /* First time we are here, init + create the array where we store the data */ + $3 = (*jenv)->GetArrayLength(jenv, oneDim); + $1 = (char**)malloc(sizeof(char*) * $2 * $3); + } + for (j = 0; j < $3; j++) + { + jstring j_string = (jstring)(*jenv)->GetObjectArrayElement(jenv, oneDim, j); + jboolean isCopy = JNI_FALSE; + char *str = (char *)(*jenv)->GetStringUTFChars(jenv, j_string, &isCopy); + $1[j * $2 + i] = (char*)MALLOC(sizeof(char)*(strlen(str) + 1)); + strcpy($1[j * $2 + i], str); + if (isCopy) + { + (*jenv)->ReleaseStringUTFChars(jenv, j_string, (const char *)str); + } + (*jenv)->DeleteLocalRef(jenv, j_string); + } + (*jenv)->DeleteLocalRef(jenv, oneDim); + } +} + +%typemap(javain) char[ANY], char[] "$javainput" + +%typemap(jtype) (char* variableName, int *nbRow, int *nbCol) "String" +%typemap(jstype) (char* variableName, int *nbRow, int *nbCol) "String" + + + diff --git a/modules/javasci/src/jni/call_scilab_wrap.c b/modules/javasci/src/jni/call_scilab_wrap.c new file mode 100755 index 000000000..820256049 --- /dev/null +++ b/modules/javasci/src/jni/call_scilab_wrap.c @@ -0,0 +1,1480 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 2.0.7 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + +#define SWIGJAVA + +/* ----------------------------------------------------------------------------- + * This section contains generic SWIG labels for method/variable + * declarations/attributes, and other compiler dependent labels. + * ----------------------------------------------------------------------------- */ + +/* template workaround for compilers that cannot correctly implement the C++ standard */ +#ifndef SWIGTEMPLATEDISAMBIGUATOR +# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) +# define SWIGTEMPLATEDISAMBIGUATOR template +# elif defined(__HP_aCC) +/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ +/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ +# define SWIGTEMPLATEDISAMBIGUATOR template +# else +# define SWIGTEMPLATEDISAMBIGUATOR +# endif +#endif + +/* inline attribute */ +#ifndef SWIGINLINE +# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) +# define SWIGINLINE inline +# else +# define SWIGINLINE +# endif +#endif + +/* attribute recognised by some compilers to avoid 'unused' warnings */ +#ifndef SWIGUNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define SWIGUNUSED __attribute__ ((__unused__)) +# else +# define SWIGUNUSED +# endif +# elif defined(__ICC) +# define SWIGUNUSED __attribute__ ((__unused__)) +# else +# define SWIGUNUSED +# endif +#endif + +#ifndef SWIG_MSC_UNSUPPRESS_4505 +# if defined(_MSC_VER) +# pragma warning(disable : 4505) /* unreferenced local function has been removed */ +# endif +#endif + +#ifndef SWIGUNUSEDPARM +# ifdef __cplusplus +# define SWIGUNUSEDPARM(p) +# else +# define SWIGUNUSEDPARM(p) p SWIGUNUSED +# endif +#endif + +/* internal SWIG method */ +#ifndef SWIGINTERN +# define SWIGINTERN static SWIGUNUSED +#endif + +/* internal inline SWIG method */ +#ifndef SWIGINTERNINLINE +# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE +#endif + +/* exporting methods */ +#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) +# ifndef GCC_HASCLASSVISIBILITY +# define GCC_HASCLASSVISIBILITY +# endif +#endif + +#ifndef SWIGEXPORT +# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# if defined(STATIC_LINKED) +# define SWIGEXPORT +# else +# define SWIGEXPORT __declspec(dllexport) +# endif +# else +# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) +# define SWIGEXPORT __attribute__ ((visibility("default"))) +# else +# define SWIGEXPORT +# endif +# endif +#endif + +/* calling conventions for Windows */ +#ifndef SWIGSTDCALL +# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# define SWIGSTDCALL __stdcall +# else +# define SWIGSTDCALL +# endif +#endif + +/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ +#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) +# define _CRT_SECURE_NO_DEPRECATE +#endif + +/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ +#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) +# define _SCL_SECURE_NO_DEPRECATE +#endif + + + +/* Fix for jlong on some versions of gcc on Windows */ +#if defined(__GNUC__) && !defined(__INTEL_COMPILER) + typedef long long __int64; +#endif + +/* Fix for jlong on 64-bit x86 Solaris */ +#if defined(__x86_64) +# ifdef _LP64 +# undef _LP64 +# endif +#endif + +#include <jni.h> +#include <stdlib.h> +#include <string.h> + + +/* Support for throwing Java exceptions */ +typedef enum { + SWIG_JavaOutOfMemoryError = 1, + SWIG_JavaIOException, + SWIG_JavaRuntimeException, + SWIG_JavaIndexOutOfBoundsException, + SWIG_JavaArithmeticException, + SWIG_JavaIllegalArgumentException, + SWIG_JavaNullPointerException, + SWIG_JavaDirectorPureVirtual, + SWIG_JavaUnknownError +} SWIG_JavaExceptionCodes; + +typedef struct { + SWIG_JavaExceptionCodes code; + const char *java_exception; +} SWIG_JavaExceptions_t; + + +static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg) { + jclass excep; + static const SWIG_JavaExceptions_t java_exceptions[] = { + { SWIG_JavaOutOfMemoryError, "java/lang/OutOfMemoryError" }, + { SWIG_JavaIOException, "java/io/IOException" }, + { SWIG_JavaRuntimeException, "java/lang/RuntimeException" }, + { SWIG_JavaIndexOutOfBoundsException, "java/lang/IndexOutOfBoundsException" }, + { SWIG_JavaArithmeticException, "java/lang/ArithmeticException" }, + { SWIG_JavaIllegalArgumentException, "java/lang/IllegalArgumentException" }, + { SWIG_JavaNullPointerException, "java/lang/NullPointerException" }, + { SWIG_JavaDirectorPureVirtual, "java/lang/RuntimeException" }, + { SWIG_JavaUnknownError, "java/lang/UnknownError" }, + { (SWIG_JavaExceptionCodes)0, "java/lang/UnknownError" } + }; + const SWIG_JavaExceptions_t *except_ptr = java_exceptions; + + while (except_ptr->code != code && except_ptr->code) + except_ptr++; + + (*jenv)->ExceptionClear(jenv); + excep = (*jenv)->FindClass(jenv, except_ptr->java_exception); + if (excep) + (*jenv)->ThrowNew(jenv, excep, msg); +} + + +/* Contract support */ + +#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, msg); return nullreturn; } else + + +#include "BOOL.h" +#define ENABLE_HELPERS +#include "javasci2_helper.h" +#include "MALLOC.h" +#include "../../../call_scilab/includes/call_scilab.h" +#include "../../../call_scilab/includes/fromjava.h" +#include "../../../api_scilab/includes/api_scilab.h" +#include "../../../output_stream/includes/lasterror.h" +#include "../../../modules/graphic_objects/includes/FigureList.h" +#include "../../../core/includes/sci_types.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_Call_1ScilabOpen(JNIEnv *jenv, jclass jcls, jstring jarg1, jboolean jarg2, jstring jarg3, jint jarg4) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + BOOL arg2 ; + char *arg3 = (char *) 0 ; + int arg4 ; + int result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + { + if (jarg2 == JNI_TRUE) arg2 = TRUE; + else arg2 = FALSE; + } + arg3 = 0; + if (jarg3) { + arg3 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg3, 0); + if (!arg3) return 0; + } + arg4 = (int)jarg4; + result = (int)Call_ScilabOpen(arg1,arg2,arg3,arg4); + jresult = (jint)result; + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + if (arg3) (*jenv)->ReleaseStringUTFChars(jenv, jarg3, (const char *)arg3); + return jresult; +} + + +SWIGEXPORT jboolean JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_TerminateScilab(JNIEnv *jenv, jclass jcls, jstring jarg1) { + jboolean jresult = 0 ; + char *arg1 = (char *) 0 ; + BOOL result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + result = TerminateScilab(arg1); + { + if (result) jresult = JNI_TRUE ; + else jresult = JNI_FALSE ; + } + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_SendScilabJob(JNIEnv *jenv, jclass jcls, jstring jarg1) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + int result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + result = (int)SendScilabJob(arg1); + jresult = (jint)result; + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_SendScilabJobs(JNIEnv *jenv, jclass jcls, jobjectArray jarg1, jint jarg2) { + jint jresult = 0 ; + char **arg1 = (char **) 0 ; + int arg2 ; + jint size1 ; + int result; + + (void)jenv; + (void)jcls; + { + int i = 0; + size1 = (*jenv)->GetArrayLength(jenv, jarg1); + arg1 = (char **) MALLOC((size1+1)*sizeof(char *)); + /* make a copy of each string */ + for (i = 0; i<size1; i++) { + jstring j_string = (jstring)(*jenv)->GetObjectArrayElement(jenv, jarg1, i); + const char * c_string = (*jenv)->GetStringUTFChars(jenv, j_string, 0); + arg1[i] = MALLOC((strlen(c_string)+1)*sizeof(const char *)); + strcpy(arg1[i], c_string); + (*jenv)->ReleaseStringUTFChars(jenv, j_string, c_string); + (*jenv)->DeleteLocalRef(jenv, j_string); + } + arg1[i] = 0; + } + arg2 = (int)jarg2; + result = (int)SendScilabJobs(arg1,arg2); + jresult = (jint)result; + { + int i; + for (i=0; i<size1-1; i++) { + FREE(arg1[i]); + arg1[i] = NULL; + } + FREE(arg1); + arg1 = NULL; + } + return jresult; +} + + +SWIGEXPORT void JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_SetFromJavaToON(JNIEnv *jenv, jclass jcls) { + (void)jenv; + (void)jcls; + SetFromJavaToON(); +} + + +SWIGEXPORT jboolean JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_isGraphicOpened(JNIEnv *jenv, jclass jcls) { + jboolean jresult = 0 ; + BOOL result; + + (void)jenv; + (void)jcls; + result = sciHasFigures(); + { + if (result) jresult = JNI_TRUE ; + else jresult = JNI_FALSE ; + } + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_GetLastErrorCode(JNIEnv *jenv, jclass jcls) { + jint jresult = 0 ; + int result; + + (void)jenv; + (void)jcls; + result = (int)getLastErrorValue(); + jresult = (jint)result; + return jresult; +} + + +SWIGEXPORT jboolean JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_isExistingVariable(JNIEnv *jenv, jclass jcls, jstring jarg1) { + jboolean jresult = 0 ; + char *arg1 = (char *) 0 ; + BOOL result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + result = isExistingVariable(arg1); + { + if (result) jresult = JNI_TRUE ; + else jresult = JNI_FALSE ; + } + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jstring JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_getLastErrorMessage(JNIEnv *jenv, jclass jcls) { + jstring jresult = 0 ; + char *result = 0 ; + + (void)jenv; + (void)jcls; + result = (char *)getLastErrorMessageSingle(); + { + if (result != NULL) + { + jresult = (*jenv)->NewStringUTF(jenv, (const char *)result); + FREE(result); + result = NULL; + } + } + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_getVariableType(JNIEnv *jenv, jclass jcls, jstring jarg1) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + sci_types result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + result = (sci_types)getVariableType(arg1); + jresult = (jint)result; + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_getIntegerPrecision(JNIEnv *jenv, jclass jcls, jstring jarg1) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + sci_int_types result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + result = (sci_int_types)getIntegerPrecision(arg1); + jresult = (jint)result; + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jboolean JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_isComplex(JNIEnv *jenv, jclass jcls, jstring jarg1) { + jboolean jresult = 0 ; + char *arg1 = (char *) 0 ; + BOOL result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + result = isComplexVar(arg1); + { + if (result) jresult = JNI_TRUE ; + else jresult = JNI_FALSE ; + } + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_putString(JNIEnv *jenv, jclass jcls, jstring jarg1, jobjectArray jarg2) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + char **arg2 = (char **) 0 ; + int arg3 ; + int arg4 ; + int result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + { + int i=0, j=0; + // Convert the String[][] => char * + arg3 = (*jenv)->GetArrayLength(jenv, jarg2); + arg4 = 0; + arg2 = NULL; + + for (; i < arg3; i++) + { + jobjectArray oneDim = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, jarg2, i); + if (arg4 == 0) + { + /* First time we are here, init + create the array where we store the data */ + arg4 = (*jenv)->GetArrayLength(jenv, oneDim); + arg2 = (char**)malloc(sizeof(char*) * arg3 * arg4); + } + for (j = 0; j < arg4; j++) + { + jstring j_string = (jstring)(*jenv)->GetObjectArrayElement(jenv, oneDim, j); + jboolean isCopy = JNI_FALSE; + char *str = (char *)(*jenv)->GetStringUTFChars(jenv, j_string, &isCopy); + arg2[j * arg3 + i] = (char*)MALLOC(sizeof(char)*(strlen(str) + 1)); + strcpy(arg2[j * arg3 + i], str); + if (isCopy) + { + (*jenv)->ReleaseStringUTFChars(jenv, j_string, (const char *)str); + } + (*jenv)->DeleteLocalRef(jenv, j_string); + } + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + } + result = (int)putString(arg1,arg2,arg3,arg4); + jresult = (jint)result; + { + // Specific target because it was freeing the wrong argument + int i = 0; + for (; i < arg3 * arg4; i++) + { + FREE(arg2[i]); + } + FREE(arg2); + } + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_putDoubleComplex(JNIEnv *jenv, jclass jcls, jstring jarg1, jobjectArray jarg2, jobjectArray jarg5) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + double *arg2 ; + int arg3 ; + int arg4 ; + double *arg5 ; + int arg6 ; + int arg7 ; + int result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + { + // Convert the double[][] => double * + int i = 0, j = 0; + arg3 = (*jenv)->GetArrayLength(jenv, jarg2); + arg4 = 0; + arg2 = NULL; + + + for (; i < arg3; i++) + { + jboolean isCopy = JNI_FALSE; + jdouble* element = NULL; + jdoubleArray oneDim = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, jarg2, i); + if (arg4 == 0) + { + /* First time we are here, init + create the array where we store the data */ + arg4 = (*jenv)->GetArrayLength(jenv, oneDim); + arg2 = (double*)malloc(sizeof(double) * arg3 * arg4); + } + isCopy = JNI_FALSE; + element = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy); + + for (j = 0; j < arg4; j++) + { + arg2[j * arg3 + i] = element[j]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + } + { + // Convert the double[][] => double * + int i = 0, j = 0; + arg6 = (*jenv)->GetArrayLength(jenv, jarg5); + arg7 = 0; + arg5 = NULL; + + + for (; i < arg6; i++) + { + jboolean isCopy = JNI_FALSE; + jdouble* element = NULL; + jdoubleArray oneDim = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, jarg5, i); + if (arg7 == 0) + { + /* First time we are here, init + create the array where we store the data */ + arg7 = (*jenv)->GetArrayLength(jenv, oneDim); + arg5 = (double*)malloc(sizeof(double) * arg6 * arg7); + } + isCopy = JNI_FALSE; + element = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy); + + for (j = 0; j < arg7; j++) + { + arg5[j * arg6 + i] = element[j]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + } + result = (int)putDoubleComplex(arg1,arg2,arg3,arg4,arg5,arg6,arg7); + jresult = (jint)result; + { + // Specific target because it was freeing the wrong argument + free(arg2); + } + { + // Specific target because it was freeing the wrong argument + free(arg5); + } + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_putDouble(JNIEnv *jenv, jclass jcls, jstring jarg1, jobjectArray jarg2) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + double *arg2 ; + int arg3 ; + int arg4 ; + int result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + { + // Convert the double[][] => double * + int i = 0, j = 0; + arg3 = (*jenv)->GetArrayLength(jenv, jarg2); + arg4 = 0; + arg2 = NULL; + + + for (; i < arg3; i++) + { + jboolean isCopy = JNI_FALSE; + jdouble* element = NULL; + jdoubleArray oneDim = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, jarg2, i); + if (arg4 == 0) + { + /* First time we are here, init + create the array where we store the data */ + arg4 = (*jenv)->GetArrayLength(jenv, oneDim); + arg2 = (double*)malloc(sizeof(double) * arg3 * arg4); + } + isCopy = JNI_FALSE; + element = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy); + + for (j = 0; j < arg4; j++) + { + arg2[j * arg3 + i] = element[j]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + } + result = (int)putDouble(arg1,arg2,arg3,arg4); + jresult = (jint)result; + { + // Specific target because it was freeing the wrong argument + free(arg2); + } + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_putBoolean(JNIEnv *jenv, jclass jcls, jstring jarg1, jobjectArray jarg2) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + BOOL *arg2 ; + int arg3 ; + int arg4 ; + int result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + { + // Convert the BOOL[][] => BOOL * + int i = 0, j = 0; + arg3 = (*jenv)->GetArrayLength(jenv, jarg2); + arg4 = 0; + arg2 = NULL; + + + for (; i < arg3; i++) + { + jboolean isCopy = JNI_FALSE; + jboolean* element = NULL; + jbooleanArray oneDim = (jbooleanArray)(*jenv)->GetObjectArrayElement(jenv, jarg2, i); + if (arg4 == 0) + { + /* First time we are here, init + create the array where we store the data */ + arg4 = (*jenv)->GetArrayLength(jenv, oneDim); + arg2 = (BOOL*)malloc(sizeof(BOOL) * arg3 * arg4); + } + isCopy = JNI_FALSE; + element = (jboolean*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy); + + for (j = 0; j < arg4; j++) + { + arg2[j * arg3 + i] = element[j]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + } + result = (int)putBoolean(arg1,arg2,arg3,arg4); + jresult = (jint)result; + { + // Specific target because it was freeing the wrong argument + free(arg2); + } + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_putByte(JNIEnv *jenv, jclass jcls, jstring jarg1, jobjectArray jarg2) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + byte *arg2 ; + int arg3 ; + int arg4 ; + int result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + { + // Convert the byte[][] => byte * + int i = 0, j = 0; + arg3 = (*jenv)->GetArrayLength(jenv, jarg2); + arg4 = 0; + arg2 = NULL; + + + for (; i < arg3; i++) + { + jboolean isCopy = JNI_FALSE; + jbyte* element = NULL; + jbyteArray oneDim = (jbyteArray)(*jenv)->GetObjectArrayElement(jenv, jarg2, i); + if (arg4 == 0) + { + /* First time we are here, init + create the array where we store the data */ + arg4 = (*jenv)->GetArrayLength(jenv, oneDim); + arg2 = (byte*)malloc(sizeof(byte) * arg3 * arg4); + } + isCopy = JNI_FALSE; + element = (jbyte*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy); + + for (j = 0; j < arg4; j++) + { + arg2[j * arg3 + i] = element[j]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + } + result = (int)putByte(arg1,arg2,arg3,arg4); + jresult = (jint)result; + { + // Specific target because it was freeing the wrong argument + free(arg2); + } + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_putUnsignedByte(JNIEnv *jenv, jclass jcls, jstring jarg1, jobjectArray jarg2) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + byte *arg2 ; + int arg3 ; + int arg4 ; + int result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + { + // Convert the byte[][] => byte * + int i = 0, j = 0; + arg3 = (*jenv)->GetArrayLength(jenv, jarg2); + arg4 = 0; + arg2 = NULL; + + + for (; i < arg3; i++) + { + jboolean isCopy = JNI_FALSE; + jbyte* element = NULL; + jbyteArray oneDim = (jbyteArray)(*jenv)->GetObjectArrayElement(jenv, jarg2, i); + if (arg4 == 0) + { + /* First time we are here, init + create the array where we store the data */ + arg4 = (*jenv)->GetArrayLength(jenv, oneDim); + arg2 = (byte*)malloc(sizeof(byte) * arg3 * arg4); + } + isCopy = JNI_FALSE; + element = (jbyte*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy); + + for (j = 0; j < arg4; j++) + { + arg2[j * arg3 + i] = element[j]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + } + result = (int)putUnsignedByte(arg1,arg2,arg3,arg4); + jresult = (jint)result; + { + // Specific target because it was freeing the wrong argument + free(arg2); + } + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_putShort(JNIEnv *jenv, jclass jcls, jstring jarg1, jobjectArray jarg2) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + short *arg2 ; + int arg3 ; + int arg4 ; + int result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + { + // Convert the short[][] => short * + int i = 0, j = 0; + arg3 = (*jenv)->GetArrayLength(jenv, jarg2); + arg4 = 0; + arg2 = NULL; + + + for (; i < arg3; i++) + { + jboolean isCopy = JNI_FALSE; + jshort* element = NULL; + jshortArray oneDim = (jshortArray)(*jenv)->GetObjectArrayElement(jenv, jarg2, i); + if (arg4 == 0) + { + /* First time we are here, init + create the array where we store the data */ + arg4 = (*jenv)->GetArrayLength(jenv, oneDim); + arg2 = (short*)malloc(sizeof(short) * arg3 * arg4); + } + isCopy = JNI_FALSE; + element = (jshort*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy); + + for (j = 0; j < arg4; j++) + { + arg2[j * arg3 + i] = element[j]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + } + result = (int)putShort(arg1,arg2,arg3,arg4); + jresult = (jint)result; + { + // Specific target because it was freeing the wrong argument + free(arg2); + } + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_putUnsignedShort(JNIEnv *jenv, jclass jcls, jstring jarg1, jobjectArray jarg2) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + unsigned short *arg2 ; + int arg3 ; + int arg4 ; + int result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + { + // Convert the unsigned short[][] => unsigned short * + int i = 0, j = 0; + arg3 = (*jenv)->GetArrayLength(jenv, jarg2); + arg4 = 0; + arg2 = NULL; + + + for (; i < arg3; i++) + { + jboolean isCopy = JNI_FALSE; + jchar* element = NULL; + jcharArray oneDim = (jcharArray)(*jenv)->GetObjectArrayElement(jenv, jarg2, i); + if (arg4 == 0) + { + /* First time we are here, init + create the array where we store the data */ + arg4 = (*jenv)->GetArrayLength(jenv, oneDim); + arg2 = (unsigned short*)malloc(sizeof(unsigned short) * arg3 * arg4); + } + isCopy = JNI_FALSE; + element = (jchar*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy); + + for (j = 0; j < arg4; j++) + { + arg2[j * arg3 + i] = element[j]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + } + result = (int)putUnsignedShort(arg1,arg2,arg3,arg4); + jresult = (jint)result; + { + // Specific target because it was freeing the wrong argument + free(arg2); + } + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_putInt(JNIEnv *jenv, jclass jcls, jstring jarg1, jobjectArray jarg2) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + int *arg2 ; + int arg3 ; + int arg4 ; + int result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + { + // Convert the int[][] => int * + int i = 0, j = 0; + arg3 = (*jenv)->GetArrayLength(jenv, jarg2); + arg4 = 0; + arg2 = NULL; + + + for (; i < arg3; i++) + { + jboolean isCopy = JNI_FALSE; + jint* element = NULL; + jintArray oneDim = (jintArray)(*jenv)->GetObjectArrayElement(jenv, jarg2, i); + if (arg4 == 0) + { + /* First time we are here, init + create the array where we store the data */ + arg4 = (*jenv)->GetArrayLength(jenv, oneDim); + arg2 = (int*)malloc(sizeof(int) * arg3 * arg4); + } + isCopy = JNI_FALSE; + element = (jint*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy); + + for (j = 0; j < arg4; j++) + { + arg2[j * arg3 + i] = element[j]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + } + result = (int)putInt(arg1,arg2,arg3,arg4); + jresult = (jint)result; + { + // Specific target because it was freeing the wrong argument + free(arg2); + } + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_putUnsignedInt(JNIEnv *jenv, jclass jcls, jstring jarg1, jobjectArray jarg2) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + unsigned int *arg2 ; + int arg3 ; + int arg4 ; + int result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + { + // Convert the unsigned int[][] => unsigned int * + int i = 0, j = 0; + arg3 = (*jenv)->GetArrayLength(jenv, jarg2); + arg4 = 0; + arg2 = NULL; + + + for (; i < arg3; i++) + { + jboolean isCopy = JNI_FALSE; + jint* element = NULL; + jintArray oneDim = (jintArray)(*jenv)->GetObjectArrayElement(jenv, jarg2, i); + if (arg4 == 0) + { + /* First time we are here, init + create the array where we store the data */ + arg4 = (*jenv)->GetArrayLength(jenv, oneDim); + arg2 = (unsigned int*)malloc(sizeof(unsigned int) * arg3 * arg4); + } + isCopy = JNI_FALSE; + element = (jint*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy); + + for (j = 0; j < arg4; j++) + { + arg2[j * arg3 + i] = element[j]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + } + result = (int)putUnsignedInt(arg1,arg2,arg3,arg4); + jresult = (jint)result; + { + // Specific target because it was freeing the wrong argument + free(arg2); + } + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_putSparse(JNIEnv *jenv, jclass jcls, jstring jarg1, jint jarg2, jint jarg3, jobjectArray jarg4, jobjectArray jarg6, jobjectArray jarg8) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + int arg2 ; + int arg3 ; + int *arg4 = (int *) 0 ; + int arg5 ; + int *arg6 = (int *) 0 ; + int arg7 ; + double *arg8 = (double *) 0 ; + int arg9 ; + int result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + arg2 = (int)jarg2; + arg3 = (int)jarg3; + { + jboolean isCopy = JNI_FALSE; + jint* element = NULL; + // Convert the int[][] => int * + arg5 = (*jenv)->GetArrayLength(jenv, jarg4); + arg4 = (int*)MALLOC(sizeof(int) * arg5); + + isCopy = JNI_FALSE; + element = (jint*)(*jenv)->GetPrimitiveArrayCritical(jenv, jarg4, &isCopy); + memcpy(arg4, element, sizeof(int) * arg5); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, jarg4, element, 0); + } + { + jboolean isCopy = JNI_FALSE; + jint* element = NULL; + // Convert the int[][] => int * + arg7 = (*jenv)->GetArrayLength(jenv, jarg6); + arg6 = (int*)MALLOC(sizeof(int) * arg7); + + isCopy = JNI_FALSE; + element = (jint*)(*jenv)->GetPrimitiveArrayCritical(jenv, jarg6, &isCopy); + memcpy(arg6, element, sizeof(int) * arg7); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, jarg6, element, 0); + } + { + jboolean isCopy = JNI_FALSE; + jdouble* element = NULL; + // Convert the double[][] => double * + arg9 = (*jenv)->GetArrayLength(jenv, jarg8); + arg8 = (double*)MALLOC(sizeof(double) * arg9); + + isCopy = JNI_FALSE; + element = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, jarg8, &isCopy); + memcpy(arg8, element, sizeof(double) * arg9); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, jarg8, element, 0); + } + result = (int)putSparse(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9); + jresult = (jint)result; + { + // Specific target because it was freeing the wrong argument + FREE(arg4); + } + { + // Specific target because it was freeing the wrong argument + FREE(arg6); + } + { + // Specific target because it was freeing the wrong argument + FREE(arg8); + } + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_putComplexSparse(JNIEnv *jenv, jclass jcls, jstring jarg1, jint jarg2, jint jarg3, jobjectArray jarg4, jobjectArray jarg6, jobjectArray jarg8, jobjectArray jarg10) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + int arg2 ; + int arg3 ; + int *arg4 = (int *) 0 ; + int arg5 ; + int *arg6 = (int *) 0 ; + int arg7 ; + double *arg8 = (double *) 0 ; + int arg9 ; + double *arg10 = (double *) 0 ; + int arg11 ; + int result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + arg2 = (int)jarg2; + arg3 = (int)jarg3; + { + jboolean isCopy = JNI_FALSE; + jint* element = NULL; + // Convert the int[][] => int * + arg5 = (*jenv)->GetArrayLength(jenv, jarg4); + arg4 = (int*)MALLOC(sizeof(int) * arg5); + + isCopy = JNI_FALSE; + element = (jint*)(*jenv)->GetPrimitiveArrayCritical(jenv, jarg4, &isCopy); + memcpy(arg4, element, sizeof(int) * arg5); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, jarg4, element, 0); + } + { + jboolean isCopy = JNI_FALSE; + jint* element = NULL; + // Convert the int[][] => int * + arg7 = (*jenv)->GetArrayLength(jenv, jarg6); + arg6 = (int*)MALLOC(sizeof(int) * arg7); + + isCopy = JNI_FALSE; + element = (jint*)(*jenv)->GetPrimitiveArrayCritical(jenv, jarg6, &isCopy); + memcpy(arg6, element, sizeof(int) * arg7); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, jarg6, element, 0); + } + { + jboolean isCopy = JNI_FALSE; + jdouble* element = NULL; + // Convert the double[][] => double * + arg9 = (*jenv)->GetArrayLength(jenv, jarg8); + arg8 = (double*)MALLOC(sizeof(double) * arg9); + + isCopy = JNI_FALSE; + element = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, jarg8, &isCopy); + memcpy(arg8, element, sizeof(double) * arg9); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, jarg8, element, 0); + } + { + jboolean isCopy = JNI_FALSE; + jdouble* element = NULL; + // Convert the double[][] => double * + arg11 = (*jenv)->GetArrayLength(jenv, jarg10); + arg10 = (double*)MALLOC(sizeof(double) * arg11); + + isCopy = JNI_FALSE; + element = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, jarg10, &isCopy); + memcpy(arg10, element, sizeof(double) * arg11); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, jarg10, element, 0); + } + result = (int)putComplexSparse(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11); + jresult = (jint)result; + { + // Specific target because it was freeing the wrong argument + FREE(arg4); + } + { + // Specific target because it was freeing the wrong argument + FREE(arg6); + } + { + // Specific target because it was freeing the wrong argument + FREE(arg8); + } + { + // Specific target because it was freeing the wrong argument + FREE(arg10); + } + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_putBooleanSparse(JNIEnv *jenv, jclass jcls, jstring jarg1, jint jarg2, jint jarg3, jobjectArray jarg4, jobjectArray jarg6) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + int arg2 ; + int arg3 ; + int *arg4 = (int *) 0 ; + int arg5 ; + int *arg6 = (int *) 0 ; + int arg7 ; + int result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + arg2 = (int)jarg2; + arg3 = (int)jarg3; + { + jboolean isCopy = JNI_FALSE; + jint* element = NULL; + // Convert the int[][] => int * + arg5 = (*jenv)->GetArrayLength(jenv, jarg4); + arg4 = (int*)MALLOC(sizeof(int) * arg5); + + isCopy = JNI_FALSE; + element = (jint*)(*jenv)->GetPrimitiveArrayCritical(jenv, jarg4, &isCopy); + memcpy(arg4, element, sizeof(int) * arg5); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, jarg4, element, 0); + } + { + jboolean isCopy = JNI_FALSE; + jint* element = NULL; + // Convert the int[][] => int * + arg7 = (*jenv)->GetArrayLength(jenv, jarg6); + arg6 = (int*)MALLOC(sizeof(int) * arg7); + + isCopy = JNI_FALSE; + element = (jint*)(*jenv)->GetPrimitiveArrayCritical(jenv, jarg6, &isCopy); + memcpy(arg6, element, sizeof(int) * arg7); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, jarg6, element, 0); + } + result = (int)putBooleanSparse(arg1,arg2,arg3,arg4,arg5,arg6,arg7); + jresult = (jint)result; + { + // Specific target because it was freeing the wrong argument + FREE(arg4); + } + { + // Specific target because it was freeing the wrong argument + FREE(arg6); + } + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_putPolynomial(JNIEnv *jenv, jclass jcls, jstring jarg1, jstring jarg2, jobjectArray jarg3) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + char *arg2 = (char *) 0 ; + double **arg3 = (double **) 0 ; + int arg4 ; + int arg5 ; + int *arg6 = (int *) 0 ; + int result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + arg2 = 0; + if (jarg2) { + arg2 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg2, 0); + if (!arg2) return 0; + } + { + // Convert the double[][] => double * + int i = 0, j = 0, k = 0; + arg4 = (*jenv)->GetArrayLength(jenv, jarg3); + arg5 = 0; + arg3 = NULL; + + for (; i < arg4; i++) { + jobjectArray dblDim = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, jarg3, i); + if (arg5 == 0) { + /* First time we are here, init + create the array where we store the data */ + arg5 = (*jenv)->GetArrayLength(jenv, dblDim); + arg3 = (double**)malloc(sizeof(double*) * arg4 * arg5); + arg6 = (int*)malloc(sizeof(int) * arg4 * arg5); + } + for (j = 0; j < arg5; j++) + { + jdoubleArray oneDim = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, dblDim, j); + jboolean isCopy = JNI_FALSE; + jdouble* element = NULL; + arg6[j * arg4 + i] = (*jenv)->GetArrayLength(jenv, oneDim); + arg3[j * arg4 + i] = (double*)MALLOC(sizeof(jdouble) * arg6[j * arg4 + i]); + isCopy = JNI_FALSE; + element = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy); + memcpy(arg3[j * arg4 + i], element, sizeof(jdouble) * arg6[j * arg4 + i]); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, 0); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + (*jenv)->DeleteLocalRef(jenv, dblDim); + } + } + result = (int)putPolynomial(arg1,arg2,arg3,arg4,arg5,arg6); + jresult = (jint)result; + { + // Specific target because it was freeing the wrong argument + int i = 0; + for (; i < arg4 * arg5; i++) + { + FREE(arg3[i]); + } + FREE(arg3); + FREE(arg6); + } + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + if (arg2) (*jenv)->ReleaseStringUTFChars(jenv, jarg2, (const char *)arg2); + return jresult; +} + + +SWIGEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_putComplexPolynomial(JNIEnv *jenv, jclass jcls, jstring jarg1, jstring jarg2, jobjectArray jarg3, jobjectArray jarg7) { + jint jresult = 0 ; + char *arg1 = (char *) 0 ; + char *arg2 = (char *) 0 ; + double **arg3 = (double **) 0 ; + int arg4 ; + int arg5 ; + int *arg6 = (int *) 0 ; + double **arg7 = (double **) 0 ; + int arg8 ; + int arg9 ; + int *arg10 = (int *) 0 ; + int result; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0); + if (!arg1) return 0; + } + arg2 = 0; + if (jarg2) { + arg2 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg2, 0); + if (!arg2) return 0; + } + { + // Convert the double[][] => double * + int i = 0, j = 0, k = 0; + arg4 = (*jenv)->GetArrayLength(jenv, jarg3); + arg5 = 0; + arg3 = NULL; + + for (; i < arg4; i++) { + jobjectArray dblDim = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, jarg3, i); + if (arg5 == 0) { + /* First time we are here, init + create the array where we store the data */ + arg5 = (*jenv)->GetArrayLength(jenv, dblDim); + arg3 = (double**)malloc(sizeof(double*) * arg4 * arg5); + arg6 = (int*)malloc(sizeof(int) * arg4 * arg5); + } + for (j = 0; j < arg5; j++) + { + jdoubleArray oneDim = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, dblDim, j); + jboolean isCopy = JNI_FALSE; + jdouble* element = NULL; + arg6[j * arg4 + i] = (*jenv)->GetArrayLength(jenv, oneDim); + arg3[j * arg4 + i] = (double*)MALLOC(sizeof(jdouble) * arg6[j * arg4 + i]); + isCopy = JNI_FALSE; + element = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy); + memcpy(arg3[j * arg4 + i], element, sizeof(jdouble) * arg6[j * arg4 + i]); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, 0); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + (*jenv)->DeleteLocalRef(jenv, dblDim); + } + } + { + // Convert the double[][] => double * + int i = 0, j = 0, k = 0; + arg8 = (*jenv)->GetArrayLength(jenv, jarg7); + arg9 = 0; + arg7 = NULL; + + for (; i < arg8; i++) { + jobjectArray dblDim = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, jarg7, i); + if (arg9 == 0) { + /* First time we are here, init + create the array where we store the data */ + arg9 = (*jenv)->GetArrayLength(jenv, dblDim); + arg7 = (double**)malloc(sizeof(double*) * arg8 * arg9); + arg10 = (int*)malloc(sizeof(int) * arg8 * arg9); + } + for (j = 0; j < arg9; j++) + { + jdoubleArray oneDim = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, dblDim, j); + jboolean isCopy = JNI_FALSE; + jdouble* element = NULL; + arg10[j * arg8 + i] = (*jenv)->GetArrayLength(jenv, oneDim); + arg7[j * arg8 + i] = (double*)MALLOC(sizeof(jdouble) * arg10[j * arg8 + i]); + isCopy = JNI_FALSE; + element = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy); + memcpy(arg7[j * arg8 + i], element, sizeof(jdouble) * arg10[j * arg8 + i]); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, 0); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + (*jenv)->DeleteLocalRef(jenv, dblDim); + } + } + result = (int)putComplexPolynomial(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10); + jresult = (jint)result; + { + // Specific target because it was freeing the wrong argument + int i = 0; + for (; i < arg4 * arg5; i++) + { + FREE(arg3[i]); + } + FREE(arg3); + FREE(arg6); + } + { + // Specific target because it was freeing the wrong argument + int i = 0; + for (; i < arg8 * arg9; i++) + { + FREE(arg7[i]); + } + FREE(arg7); + FREE(arg10); + } + if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1); + if (arg2) (*jenv)->ReleaseStringUTFChars(jenv, jarg2, (const char *)arg2); + return jresult; +} + + +#ifdef __cplusplus +} +#endif + diff --git a/modules/javasci/src/jni/libjavasci2_la-call_scilab_wrap.lo b/modules/javasci/src/jni/libjavasci2_la-call_scilab_wrap.lo new file mode 100755 index 000000000..ecc3ecee8 --- /dev/null +++ b/modules/javasci/src/jni/libjavasci2_la-call_scilab_wrap.lo @@ -0,0 +1,12 @@ +# src/jni/libjavasci2_la-call_scilab_wrap.lo - a libtool object file +# Generated by libtool (GNU libtool) 2.4.2 +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# Name of the PIC object. +pic_object='.libs/libjavasci2_la-call_scilab_wrap.o' + +# Name of the non-PIC object +non_pic_object=none + diff --git a/modules/javasci/src/jni/libjavasci2_la-putLists.lo b/modules/javasci/src/jni/libjavasci2_la-putLists.lo new file mode 100755 index 000000000..37b498302 --- /dev/null +++ b/modules/javasci/src/jni/libjavasci2_la-putLists.lo @@ -0,0 +1,12 @@ +# src/jni/libjavasci2_la-putLists.lo - a libtool object file +# Generated by libtool (GNU libtool) 2.4.2 +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# Name of the PIC object. +pic_object='.libs/libjavasci2_la-putLists.o' + +# Name of the non-PIC object +non_pic_object=none + diff --git a/modules/javasci/src/jni/putLists.c b/modules/javasci/src/jni/putLists.c new file mode 100755 index 000000000..dc11de084 --- /dev/null +++ b/modules/javasci/src/jni/putLists.c @@ -0,0 +1,948 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +/*--------------------------------------------------------------------------*/ +#include <string.h> +#include <jni.h> +#include "api_scilab.h" +#include "stack-c.h" +#include "sci_types.h" +#include "MALLOC.h" +#include "BOOL.h" + +#ifdef __cplusplus +extern "C" { +#endif + + /*--------------------------------------------------------------------------*/ + SciErr sendList(JNIEnv * jenv, jobject list, int * parentList, int pos, char * varName, char listType); + JNIEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_putList(JNIEnv *jenv, jclass cl, jstring jvarName, jobject list, jchar type); + /*--------------------------------------------------------------------------*/ + + JNIEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_putList(JNIEnv *jenv, jclass cl, jstring jvarName, jobject list, jchar type) + { + char * varName = (char*)(*jenv)->GetStringUTFChars(jenv, jvarName, 0); + SciErr sciErr = sendList(jenv, list, 0, 0, varName, (char)type); + (*jenv)->ReleaseStringUTFChars(jenv, jvarName, (const char *)varName); + + if (sciErr.iErr) + { + return -1; + } + + return 0; + } + + SciErr sendList(JNIEnv * jenv, jobject list, int * parentList, int pos, char * varName, char listType) + { + int listLen = (*jenv)->GetArrayLength(jenv, list); + jboolean isCopy = JNI_FALSE; + jintArray jtypes = (jintArray)(*jenv)->GetObjectArrayElement(jenv, list, 0); + jint * types = (*jenv)->GetIntArrayElements(jenv, jtypes, &isCopy); + int i = 0; + SciErr sciErr; + int * currentList = 0; + if (parentList) + { + switch (listType) + { + case 'l' : + sciErr = createListInNamedList(pvApiCtx, varName, parentList, pos, listLen - 1, ¤tList); + break; + case 't' : + sciErr = createTListInNamedList(pvApiCtx, varName, parentList, pos, listLen - 1, ¤tList); + break; + case 'm' : + sciErr = createMListInNamedList(pvApiCtx, varName, parentList, pos, listLen - 1, ¤tList); + break; + } + } + else + { + //cleanStackListAddress(); + switch (listType) + { + case 'l' : + sciErr = createNamedList(pvApiCtx, varName, listLen - 1, ¤tList); + break; + case 't' : + sciErr = createNamedTList(pvApiCtx, varName, listLen - 1, ¤tList); + break; + case 'm' : + sciErr = createNamedMList(pvApiCtx, varName, listLen - 1, ¤tList); + break; + } + } + + if (sciErr.iErr) + { + (*jenv)->ReleaseIntArrayElements(jenv, jtypes, types, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, jtypes); + return sciErr; + } + + //pushListAddress(currentList); + + for (; i < listLen - 1; i++) + { + switch (types[i]) + { + case sci_matrix : + { + int nbCol = 0; + int j = 0, k = 0; + double * real = 0; + double * imag = 0; + int nbRow = 0; + + jobjectArray infos = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, list, i + 1); + int isReal = (*jenv)->GetArrayLength(jenv, infos) == 1; + jobjectArray data = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, infos, 0); + + if (!data) + { + // empty matrix + sciErr = createMatrixOfDoubleInNamedList(pvApiCtx, varName, currentList, i + 1, 0, 0, 0); + (*jenv)->DeleteLocalRef(jenv, infos); + break; + } + + nbRow = (*jenv)->GetArrayLength(jenv, data); + + if (isReal) + { + // Get the matrix rowsw + for (; j < nbRow; j++) + { + jboolean isCopy1 = JNI_FALSE; + jdouble* element = NULL; + jdoubleArray oneDim = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, data, j); + if (nbCol == 0) + { + nbCol = (*jenv)->GetArrayLength(jenv, oneDim); + real = (double*)MALLOC(sizeof(double) * nbRow * nbCol); + } + + element = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1); + + // Get the matrix element + for (k = 0; k < nbCol; k++) + { + real[k * nbRow + j] = element[k]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + (*jenv)->DeleteLocalRef(jenv, data); + + sciErr = createMatrixOfDoubleInNamedList(pvApiCtx, varName, currentList, i + 1, nbRow, nbCol, real); + FREE(real); + } + else + { + jobject imagData = (jobject)(*jenv)->GetObjectArrayElement(jenv, infos, 1); + // Get the matrix rows + for (; j < nbRow; j++) + { + jboolean isCopy1 = JNI_FALSE; + jdouble* elementR = NULL; + jdouble* elementI = NULL; + jdoubleArray oneDimR = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, data, j); + jdoubleArray oneDimI = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, imagData, j); + if (nbCol == 0) + { + nbCol = (*jenv)->GetArrayLength(jenv, oneDimR); + real = (double*)MALLOC(sizeof(double) * nbRow * nbCol); + imag = (double*)MALLOC(sizeof(double) * nbRow * nbCol); + } + + elementR = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDimR, &isCopy1); + isCopy1 = JNI_FALSE; + elementI = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDimI, &isCopy1); + + // Get the matrix element + for (k = 0; k < nbCol; k++) + { + real[k * nbRow + j] = elementR[k]; + imag[k * nbRow + j] = elementI[k]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDimR, elementR, JNI_ABORT); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDimI, elementI, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDimR); + (*jenv)->DeleteLocalRef(jenv, oneDimI); + } + (*jenv)->DeleteLocalRef(jenv, data); + (*jenv)->DeleteLocalRef(jenv, imagData); + + sciErr = createComplexMatrixOfDoubleInNamedList(pvApiCtx, varName, currentList, i + 1, nbRow, nbCol, real, imag); + FREE(real); + FREE(imag); + } + (*jenv)->DeleteLocalRef(jenv, infos); + break; + } + case sci_poly : + { + jobjectArray infos = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, list, i + 1); + jobject data = (*jenv)->GetObjectArrayElement(jenv, infos, 1); + int nbRow = (*jenv)->GetArrayLength(jenv, data); + int isReal = 0; + jstring js; + char * polyVarName = NULL; + int nbCol = 0; + int j = 0, k = 0; + double ** real = NULL; + double ** imag = NULL; + int * nbCoef = NULL; + + if (!data || nbRow == 0) + { + sciErr = createMatrixOfDoubleInNamedList(pvApiCtx, varName, currentList, i + 1, 0, 0, 0); + if (!data) + { + (*jenv)->DeleteLocalRef(jenv, data); + } + (*jenv)->DeleteLocalRef(jenv, infos); + break; + } + + isReal = (*jenv)->GetArrayLength(jenv, infos) == 2; + js = (jstring)(*jenv)->GetObjectArrayElement(jenv, infos, 0); + polyVarName = (char*)(*jenv)->GetStringUTFChars(jenv, js, 0); + + if (isReal) + { + // Get the matrix rows + for (; j < nbRow; j++) + { + jobjectArray dblDim = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, data, j); + if (nbCol == 0) + { + nbCol = (*jenv)->GetArrayLength(jenv, dblDim); + real = (double**)MALLOC(sizeof(double*) * nbRow * nbCol); + nbCoef = (int*)MALLOC(sizeof(int) * nbRow * nbCol); + } + + // Get the matrix element + for (k = 0; k < nbCol; k++) + { + jboolean isCopy1 = JNI_FALSE; + jdouble* element = NULL; + jdoubleArray oneDim = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, dblDim, k); + int len = (*jenv)->GetArrayLength(jenv, oneDim); + nbCoef[k * nbRow + j] = len; + real[k * nbRow + j] = (double*)MALLOC(sizeof(double) * len); + element = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1); + memcpy(real[k * nbRow + j], element, sizeof(double) * len); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, 0); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + (*jenv)->DeleteLocalRef(jenv, dblDim); + } + (*jenv)->DeleteLocalRef(jenv, data); + + sciErr = createMatrixOfPolyInNamedList(pvApiCtx, varName, currentList, i + 1, polyVarName, nbRow, nbCol, nbCoef, (const double * const*)real); + for (j = 0; j < nbRow * nbCol; j++) + { + FREE(real[j]); + } + FREE(real); + FREE(nbCoef); + } + else + { + jobject imagData = (*jenv)->GetObjectArrayElement(jenv, infos, 2); + // Get the matrix rows + for (; j < nbRow; j++) + { + jobjectArray dblDimR = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, data, j); + jobjectArray dblDimI = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, imagData, j); + if (nbCol == 0) + { + nbCol = (*jenv)->GetArrayLength(jenv, dblDimR); + real = (double**)MALLOC(sizeof(double*) * nbRow * nbCol); + imag = (double**)MALLOC(sizeof(double*) * nbRow * nbCol); + nbCoef = (int*)MALLOC(sizeof(int) * nbRow * nbCol); + } + + // Get the matrix element + for (k = 0; k < nbCol; k++) + { + jboolean isCopy1 = JNI_FALSE; + jdouble* element = NULL; + jdoubleArray oneDimR = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, dblDimR, k); + jdoubleArray oneDimI = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, dblDimI, k); + int len = (*jenv)->GetArrayLength(jenv, oneDimR); + nbCoef[k * nbRow + j] = len; + real[k * nbRow + j] = (double*)MALLOC(sizeof(double) * len); + imag[k * nbRow + j] = (double*)MALLOC(sizeof(double) * len); + element = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDimR, &isCopy1); + memcpy(real[k * nbRow + j], element, sizeof(double) * len); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDimR, element, 0); + (*jenv)->DeleteLocalRef(jenv, oneDimR); + isCopy1 = JNI_FALSE; + element = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDimI, &isCopy1); + memcpy(imag[k * nbRow + j], element, sizeof(double) * len); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDimI, element, 0); + (*jenv)->DeleteLocalRef(jenv, oneDimI); + } + (*jenv)->DeleteLocalRef(jenv, dblDimR); + (*jenv)->DeleteLocalRef(jenv, dblDimI); + } + (*jenv)->DeleteLocalRef(jenv, data); + (*jenv)->DeleteLocalRef(jenv, imagData); + + sciErr = createComplexMatrixOfPolyInNamedList(pvApiCtx, varName, currentList, i + 1, polyVarName, nbRow, nbCol, nbCoef, (const double * const*)real, (const double * const*)imag); + for (j = 0; j < nbRow * nbCol; j++) + { + FREE(real[j]); + FREE(imag[j]); + } + FREE(real); + FREE(imag); + FREE(nbCoef); + } + + (*jenv)->ReleaseStringUTFChars(jenv, js, polyVarName); + (*jenv)->DeleteLocalRef(jenv, js); + (*jenv)->DeleteLocalRef(jenv, infos); + break; + } + case sci_boolean : + { + jobject data = (*jenv)->GetObjectArrayElement(jenv, list, i + 1); + int nbRow = (*jenv)->GetArrayLength(jenv, data); + int nbCol = 0; + int j = 0, k; + int * b = 0; + + if (!data || nbRow == 0) + { + sciErr = createMatrixOfDoubleInNamedList(pvApiCtx, varName, currentList, i + 1, 0, 0, 0); + if (!data) + { + (*jenv)->DeleteLocalRef(jenv, data); + } + break; + } + + // Get the matrix rows + for (; j < nbRow; j++) + { + jboolean isCopy1 = JNI_FALSE; + jboolean* element = NULL; + jdoubleArray oneDim = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, data, j); + if (nbCol == 0) + { + nbCol = (*jenv)->GetArrayLength(jenv, oneDim); + b = (int*)MALLOC(sizeof(int) * nbRow * nbCol); + } + + element = (jboolean*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1); + + // Get the matrix element + for (k = 0; k < nbCol; k++) + { + b[k * nbRow + j] = element[k]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + (*jenv)->DeleteLocalRef(jenv, data); + + sciErr = createMatrixOfBooleanInNamedList(pvApiCtx, varName, currentList, i + 1, nbRow, nbCol, (const int *)b); + FREE(b); + break; + } + case sci_sparse : + { + jboolean isCopy1 = JNI_FALSE; + int* dims = NULL; + int* nbItemRow = NULL; + int* colPos = NULL; + double* data = NULL; + double * imagData = NULL; + jobjectArray infos = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, list, i + 1); + int isReal = (*jenv)->GetArrayLength(jenv, infos) == 4; + jintArray jdims = (jintArray)(*jenv)->GetObjectArrayElement(jenv, infos, 0); + jintArray jnbItemRow = (jintArray)(*jenv)->GetObjectArrayElement(jenv, infos, 1); + jintArray jcolPos = (jintArray)(*jenv)->GetObjectArrayElement(jenv, infos, 2); + jint nbNonNull = (*jenv)->GetArrayLength(jenv, jcolPos); + jdoubleArray jdata = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, infos, 3); + jdoubleArray jimagData; + + if (!isReal) + { + jimagData = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, infos, 4); + } + + dims = (jint*)(*jenv)->GetPrimitiveArrayCritical(jenv, jdims, &isCopy1); + isCopy1 = JNI_FALSE; + nbItemRow = (int*)(*jenv)->GetPrimitiveArrayCritical(jenv, jnbItemRow, &isCopy1); + isCopy1 = JNI_FALSE; + colPos = (int*)(*jenv)->GetPrimitiveArrayCritical(jenv, jcolPos, &isCopy1); + isCopy1 = JNI_FALSE; + data = (double*)(*jenv)->GetPrimitiveArrayCritical(jenv, jdata, &isCopy1); + isCopy1 = JNI_FALSE; + + if (!isReal) + { + imagData = (double*)(*jenv)->GetPrimitiveArrayCritical(jenv, jimagData, &isCopy1); + } + + if (isReal) + { + sciErr = createSparseMatrixInNamedList(pvApiCtx, varName, currentList, i + 1, dims[0], dims[1], nbNonNull, nbItemRow, colPos, data); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, jdata, data, JNI_ABORT); + } + else + { + sciErr = createComplexSparseMatrixInNamedList(pvApiCtx, varName, currentList, i + 1, dims[0], dims[1], nbNonNull, nbItemRow, colPos, data, imagData); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, jimagData, imagData, JNI_ABORT); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, jdata, data, JNI_ABORT); + } + + (*jenv)->ReleasePrimitiveArrayCritical(jenv, jcolPos, colPos, JNI_ABORT); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, jnbItemRow, nbItemRow, JNI_ABORT); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, jdims, dims, JNI_ABORT); + + if (!isReal) + { + (*jenv)->DeleteLocalRef(jenv, jimagData); + } + (*jenv)->DeleteLocalRef(jenv, jdata); + (*jenv)->DeleteLocalRef(jenv, jcolPos); + (*jenv)->DeleteLocalRef(jenv, jnbItemRow); + (*jenv)->DeleteLocalRef(jenv, jdims); + (*jenv)->DeleteLocalRef(jenv, infos); + + break; + } + case sci_boolean_sparse : + { + jobjectArray infos = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, list, i + 1); + jintArray jdims = (jintArray)(*jenv)->GetObjectArrayElement(jenv, infos, 0); + jintArray jnbItemRow = (jintArray)(*jenv)->GetObjectArrayElement(jenv, infos, 1); + jintArray jcolPos = (jintArray)(*jenv)->GetObjectArrayElement(jenv, infos, 2); + jint nbNonNull = (*jenv)->GetArrayLength(jenv, jcolPos); + int* nbItemRow = NULL; + int* dims = NULL; + int* colPos = NULL; + + jboolean isCopy1 = JNI_FALSE; + + dims = (jint*)(*jenv)->GetPrimitiveArrayCritical(jenv, jdims, &isCopy1); + isCopy1 = JNI_FALSE; + nbItemRow = (int*)(*jenv)->GetPrimitiveArrayCritical(jenv, jnbItemRow, &isCopy1); + isCopy1 = JNI_FALSE; + colPos = (int*)(*jenv)->GetPrimitiveArrayCritical(jenv, jcolPos, &isCopy1); + + sciErr = createBooleanSparseMatrixInNamedList(pvApiCtx, varName, currentList, i + 1, dims[0], dims[1], nbNonNull, nbItemRow, colPos); + + (*jenv)->ReleasePrimitiveArrayCritical(jenv, jcolPos, colPos, JNI_ABORT); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, jnbItemRow, nbItemRow, JNI_ABORT); + (*jenv)->ReleasePrimitiveArrayCritical(jenv, jdims, dims, JNI_ABORT); + + (*jenv)->DeleteLocalRef(jenv, jcolPos); + (*jenv)->DeleteLocalRef(jenv, jnbItemRow); + (*jenv)->DeleteLocalRef(jenv, jdims); + (*jenv)->DeleteLocalRef(jenv, infos); + + break; + } + case sci_ints : + { + jobjectArray infos = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, list, i + 1); + jintArray jtype = (jintArray)(*jenv)->GetObjectArrayElement(jenv, infos, 0); + jint * typep = (*jenv)->GetIntArrayElements(jenv, jtype, 0); + int type = *typep; + + (*jenv)->ReleaseIntArrayElements(jenv, jtype, typep, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, jtype); + + switch (type) + { + case sci_int8 : + { + jobject jdata = (*jenv)->GetObjectArrayElement(jenv, infos, 1); + int nbRow = (*jenv)->GetArrayLength(jenv, jdata); + int nbCol = 0; + int j = 0, k; + char * data = 0; + + if (!jdata || nbRow == 0) + { + sciErr = createMatrixOfDoubleInNamedList(pvApiCtx, varName, currentList, i + 1, 0, 0, 0); + if (!jdata) + { + (*jenv)->DeleteLocalRef(jenv, jdata); + } + break; + } + + // Get the matrix rows + for (; j < nbRow; j++) + { + jboolean isCopy1 = JNI_FALSE; + jbyte* element = NULL; + jbyteArray oneDim = (jbyteArray)(*jenv)->GetObjectArrayElement(jenv, jdata, j); + if (nbCol == 0) + { + nbCol = (*jenv)->GetArrayLength(jenv, oneDim); + data = (char*)MALLOC(sizeof(char) * nbRow * nbCol); + } + isCopy1 = JNI_FALSE; + element = (jbyte*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1); + + // Get the matrix element + for (k = 0; k < nbCol; k++) + { + data[k * nbRow + j] = element[k]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + (*jenv)->DeleteLocalRef(jenv, jdata); + + sciErr = createMatrixOfInteger8InNamedList(pvApiCtx, varName, currentList, i + 1, nbRow, nbCol, data); + FREE(data); + break; + } + case sci_uint8 : + { + jobject jdata = (*jenv)->GetObjectArrayElement(jenv, infos, 1); + int nbRow = (*jenv)->GetArrayLength(jenv, jdata); + int nbCol = 0; + int j = 0, k; + unsigned char * data = 0; + + if (!jdata || nbRow == 0) + { + sciErr = createMatrixOfDoubleInNamedList(pvApiCtx, varName, currentList, i + 1, 0, 0, 0); + if (!jdata) + { + (*jenv)->DeleteLocalRef(jenv, jdata); + } + break; + } + + // Get the matrix rows + for (; j < nbRow; j++) + { + jbyte* element = NULL; + jboolean isCopy1 = JNI_FALSE; + jbyteArray oneDim = (jbyteArray)(*jenv)->GetObjectArrayElement(jenv, jdata, j); + if (nbCol == 0) + { + nbCol = (*jenv)->GetArrayLength(jenv, oneDim); + data = (unsigned char*)MALLOC(sizeof(unsigned char) * nbRow * nbCol); + } + + element = (jbyte*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1); + + // Get the matrix element + for (k = 0; k < nbCol; k++) + { + data[k * nbRow + j] = element[k]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + (*jenv)->DeleteLocalRef(jenv, jdata); + + sciErr = createMatrixOfUnsignedInteger8InNamedList(pvApiCtx, varName, currentList, i + 1, nbRow, nbCol, data); + FREE(data); + + break; + } + case sci_int16 : + { + jobject jdata = (*jenv)->GetObjectArrayElement(jenv, infos, 1); + int nbRow = (*jenv)->GetArrayLength(jenv, jdata); + int nbCol = 0; + int j = 0, k; + short * data = 0; + + if (!jdata || nbRow == 0) + { + sciErr = createMatrixOfDoubleInNamedList(pvApiCtx, varName, currentList, i + 1, 0, 0, 0); + if (!jdata) + { + (*jenv)->DeleteLocalRef(jenv, jdata); + } + break; + } + + // Get the matrix rows + for (; j < nbRow; j++) + { + jboolean isCopy1 = JNI_FALSE; + jshort* element = NULL; + jshortArray oneDim = (jshortArray)(*jenv)->GetObjectArrayElement(jenv, jdata, j); + if (nbCol == 0) + { + nbCol = (*jenv)->GetArrayLength(jenv, oneDim); + data = (short*)MALLOC(sizeof(short) * nbRow * nbCol); + } + + element = (jshort*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1); + + // Get the matrix element + for (k = 0; k < nbCol; k++) + { + data[k * nbRow + j] = element[k]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + (*jenv)->DeleteLocalRef(jenv, jdata); + + sciErr = createMatrixOfInteger16InNamedList(pvApiCtx, varName, currentList, i + 1, nbRow, nbCol, data); + FREE(data); + + break; + } + case sci_uint16 : + { + jobject jdata = (*jenv)->GetObjectArrayElement(jenv, infos, 1); + int nbRow = (*jenv)->GetArrayLength(jenv, jdata); + int nbCol = 0; + int j = 0, k; + unsigned short * data = 0; + + if (!jdata || nbRow == 0) + { + sciErr = createMatrixOfDoubleInNamedList(pvApiCtx, varName, currentList, i + 1, 0, 0, 0); + if (!jdata) + { + (*jenv)->DeleteLocalRef(jenv, jdata); + } + break; + } + + // Get the matrix rows + for (; j < nbRow; j++) + { + jboolean isCopy1 = JNI_FALSE; + jshort* element = NULL; + jshortArray oneDim = (jshortArray)(*jenv)->GetObjectArrayElement(jenv, jdata, j); + if (nbCol == 0) + { + nbCol = (*jenv)->GetArrayLength(jenv, oneDim); + data = (unsigned short*)MALLOC(sizeof(unsigned short) * nbRow * nbCol); + } + isCopy1 = JNI_FALSE; + element = (jshort*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1); + + // Get the matrix element + for (k = 0; k < nbCol; k++) + { + data[k * nbRow + j] = element[k]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + (*jenv)->DeleteLocalRef(jenv, jdata); + + sciErr = createMatrixOfUnsignedInteger16InNamedList(pvApiCtx, varName, currentList, i + 1, nbRow, nbCol, data); + FREE(data); + + break; + } + case sci_int32 : + { + jobject jdata = (*jenv)->GetObjectArrayElement(jenv, infos, 1); + int nbRow = (*jenv)->GetArrayLength(jenv, jdata); + int nbCol = 0; + int j = 0, k; + int * data = 0; + + if (!jdata || nbRow == 0) + { + sciErr = createMatrixOfDoubleInNamedList(pvApiCtx, varName, currentList, i + 1, 0, 0, 0); + if (!jdata) + { + (*jenv)->DeleteLocalRef(jenv, jdata); + } + break; + } + + // Get the matrix rows + for (; j < nbRow; j++) + { + jboolean isCopy1 = JNI_FALSE; + jint* element = NULL; + jintArray oneDim = (jintArray)(*jenv)->GetObjectArrayElement(jenv, jdata, j); + if (nbCol == 0) + { + nbCol = (*jenv)->GetArrayLength(jenv, oneDim); + data = (int*)MALLOC(sizeof(int) * nbRow * nbCol); + } + isCopy1 = JNI_FALSE; + element = (jint*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1); + + // Get the matrix element + for (k = 0; k < nbCol; k++) + { + data[k * nbRow + j] = element[k]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + (*jenv)->DeleteLocalRef(jenv, jdata); + + sciErr = createMatrixOfInteger32InNamedList(pvApiCtx, varName, currentList, i + 1, nbRow, nbCol, data); + FREE(data); + + break; + } + case sci_uint32 : + { + jobject jdata = (*jenv)->GetObjectArrayElement(jenv, infos, 1); + int nbRow = (*jenv)->GetArrayLength(jenv, jdata); + int nbCol = 0; + int j = 0, k; + unsigned int * data = 0; + + if (!jdata || nbRow == 0) + { + sciErr = createMatrixOfDoubleInNamedList(pvApiCtx, varName, currentList, i + 1, 0, 0, 0); + if (!jdata) + { + (*jenv)->DeleteLocalRef(jenv, jdata); + } + break; + } + + // Get the matrix rows + for (; j < nbRow; j++) + { + jboolean isCopy1 = JNI_FALSE; + jint* element = NULL; + jintArray oneDim = (jintArray)(*jenv)->GetObjectArrayElement(jenv, jdata, j); + if (nbCol == 0) + { + nbCol = (*jenv)->GetArrayLength(jenv, oneDim); + data = (unsigned int*)MALLOC(sizeof(unsigned int) * nbRow * nbCol); + } + isCopy1 = JNI_FALSE; + element = (jint*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1); + + // Get the matrix element + for (k = 0; k < nbCol; k++) + { + data[k * nbRow + j] = element[k]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + (*jenv)->DeleteLocalRef(jenv, jdata); + + sciErr = createMatrixOfUnsignedInteger32InNamedList(pvApiCtx, varName, currentList, i + 1, nbRow, nbCol, data); + FREE(data); + + break; + } +#ifdef __SCILAB_INT64__ + case sci_int64 : + { + jobject jdata = (*jenv)->GetObjectArrayElement(jenv, infos, 1); + int nbRow = (*jenv)->GetArrayLength(jenv, jdata); + int nbCol = 0; + int j = 0, k; + long * data = 0; + + if (!jdata || nbRow == 0) + { + sciErr = createMatrixOfDoubleInNamedList(pvApiCtx, varName, currentList, i + 1, 0, 0, 0); + if (!jdata) + { + (*jenv)->DeleteLocalRef(jenv, jdata); + } + break; + } + + // Get the matrix rows + for (; j < nbRow; j++) + { + jlongArray oneDim = (jlongArray)(*jenv)->GetObjectArrayElement(jenv, jdata, j); + if (nbCol == 0) + { + nbCol = (*jenv)->GetArrayLength(jenv, oneDim); + data = (long*)MALLOC(sizeof(long) * nbRow * nbCol); + } + jboolean isCopy1 = JNI_FALSE; + jlong* element = (jlong*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1); + + // Get the matrix element + for (k = 0; k < nbCol; k++) + { + data[k * nbRow + j] = element[k]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + (*jenv)->DeleteLocalRef(jenv, jdata); + + sciErr = createMatrixOfInteger64InNamedList(pvApiCtx, varName, currentList, i + 1, nbRow, nbCol, data); + FREE(data); + + break; + } + case sci_uint64 : + { + jobject jdata = (*jenv)->GetObjectArrayElement(jenv, infos, 1); + int nbRow = (*jenv)->GetArrayLength(jenv, jdata); + int nbCol = 0; + int j = 0, k; + unsigned long * data = 0; + + if (!jdata || nbRow == 0) + { + sciErr = createMatrixOfDoubleInNamedList(pvApiCtx, varName, currentList, i + 1, 0, 0, 0); + if (!jdata) + { + (*jenv)->DeleteLocalRef(jenv, jdata); + } + break; + } + + // Get the matrix rows + for (; j < nbRow; j++) + { + jlongArray oneDim = (jlongArray)(*jenv)->GetObjectArrayElement(jenv, jdata, j); + if (nbCol == 0) + { + nbCol = (*jenv)->GetArrayLength(jenv, oneDim); + data = (unsigned long*)MALLOC(sizeof(unsigned long) * nbRow * nbCol); + } + jboolean isCopy1 = JNI_FALSE; + jlong* element = (jlong*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1); + + // Get the matrix element + for (k = 0; k < nbCol; k++) + { + data[k * nbRow + j] = element[k]; + } + (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + (*jenv)->DeleteLocalRef(jenv, jdata); + + sciErr = createMatrixOfUnsignedInteger64InNamedList(pvApiCtx, varName, currentList, i + 1, nbRow, nbCol, data); + FREE(data); + break; + } +#endif + } + (*jenv)->DeleteLocalRef(jenv, infos); + break; + } + case sci_strings : + { + jobject data = (*jenv)->GetObjectArrayElement(jenv, list, i + 1); + int nbRow = (*jenv)->GetArrayLength(jenv, data); + int nbCol = 0; + int j = 0, k; + char ** strings = 0; + + if (!data || nbRow == 0) + { + sciErr = createMatrixOfDoubleInNamedList(pvApiCtx, varName, currentList, i + 1, 0, 0, 0); + if (!data) + { + (*jenv)->DeleteLocalRef(jenv, data); + } + break; + } + + // Get the matrix rows + for (; j < nbRow; j++) + { + jobjectArray oneDim = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, data, j); + if (nbCol == 0) + { + nbCol = (*jenv)->GetArrayLength(jenv, oneDim); + strings = (char**)MALLOC(sizeof(char*) * nbRow * nbCol); + } + + // Get the matrix element + for (k = 0; k < nbCol; k++) + { + jstring j_string = (jstring)(*jenv)->GetObjectArrayElement(jenv, oneDim, k); + jboolean isCopy1 = JNI_FALSE; + char *str = (char *)(*jenv)->GetStringUTFChars(jenv, j_string, &isCopy1); + strings[k * nbRow + j] = (char*)MALLOC(sizeof(char) * (strlen(str) + 1)); + strcpy(strings[k * nbRow + j], str); + if (isCopy1) + { + (*jenv)->ReleaseStringUTFChars(jenv, j_string, (const char *)str); + } + (*jenv)->DeleteLocalRef(jenv, j_string); + } + (*jenv)->DeleteLocalRef(jenv, oneDim); + } + (*jenv)->DeleteLocalRef(jenv, data); + + sciErr = createMatrixOfStringInNamedList(pvApiCtx, varName, currentList, i + 1, nbRow, nbCol, (const char * const*)strings); + for (j = 0; j < nbRow * nbCol; j++) + { + FREE(strings[j]); + } + FREE(strings); + break; + } + case sci_list : + { + jobject data = (*jenv)->GetObjectArrayElement(jenv, list, i + 1); + sciErr = sendList(jenv, data, currentList, i + 1, varName, 'l'); + (*jenv)->DeleteLocalRef(jenv, data); + break; + } + case sci_tlist : + { + jobject data = (*jenv)->GetObjectArrayElement(jenv, list, i + 1); + sciErr = sendList(jenv, data, currentList, i + 1, varName, 't'); + (*jenv)->DeleteLocalRef(jenv, data); + break; + } + case sci_mlist : + { + jobject data = (*jenv)->GetObjectArrayElement(jenv, list, i + 1); + sciErr = sendList(jenv, data, currentList, i + 1, varName, 'm'); + (*jenv)->DeleteLocalRef(jenv, data); + break; + } + } + + if (sciErr.iErr) + { + break; + } + } + + (*jenv)->ReleaseIntArrayElements(jenv, jtypes, types, JNI_ABORT); + (*jenv)->DeleteLocalRef(jenv, jtypes); + + //popListAddress(); + + if (!parentList) + { + //pushVariable(varName); + //cleanStackListAddress(); + } + + return sciErr; + } + +#ifdef __cplusplus +} +#endif |