diff options
author | Shashank | 2017-05-29 12:40:26 +0530 |
---|---|---|
committer | Shashank | 2017-05-29 12:40:26 +0530 |
commit | 0345245e860375a32c9a437c4a9d9cae807134e9 (patch) | |
tree | ad51ecbfa7bcd3cc5f09834f1bb8c08feaa526a4 /modules/dynamic_link/examples | |
download | scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.tar.gz scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.tar.bz2 scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.zip |
CMSCOPE changed
Diffstat (limited to 'modules/dynamic_link/examples')
66 files changed, 2123 insertions, 0 deletions
diff --git a/modules/dynamic_link/examples/call_dll_in_scilab/Makefile.mak b/modules/dynamic_link/examples/call_dll_in_scilab/Makefile.mak new file mode 100755 index 000000000..a0fa4f1c3 --- /dev/null +++ b/modules/dynamic_link/examples/call_dll_in_scilab/Makefile.mak @@ -0,0 +1,31 @@ +# the list of files to produce the library +LINKER=link + +OBJS = tdll.obj + +all :: libtdll.dll + +clean :: + @del *.obj + @del *.dll + @del *.lib + @del *.exp + +libtdll.dll : $(OBJS) + $(LINKER) $(OBJS) /nologo /subsystem:windows /dll /out:"libtdll.dll" /implib:"libtdll.lib" /def:tdll.def + + + + + + + + + + + + + + + + diff --git a/modules/dynamic_link/examples/call_dll_in_scilab/demo.sce b/modules/dynamic_link/examples/call_dll_in_scilab/demo.sce new file mode 100755 index 000000000..9c316ecf5 --- /dev/null +++ b/modules/dynamic_link/examples/call_dll_in_scilab/demo.sce @@ -0,0 +1,16 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 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 + +if (findmsvccompiler()<>"unknown") then + dos("nmake /f Makefile.mak"); + link("libtdll.dll","doit","c"); + [a,b]=call("doit",1,1,"d",2,2,"d","sort",1,2); +end + + diff --git a/modules/dynamic_link/examples/call_dll_in_scilab/readme.txt b/modules/dynamic_link/examples/call_dll_in_scilab/readme.txt new file mode 100755 index 000000000..21c4c181b --- /dev/null +++ b/modules/dynamic_link/examples/call_dll_in_scilab/readme.txt @@ -0,0 +1,7 @@ + +A small example for the link Scilab function on Windows + +demo.sce : is a Scilab script which will run the make utility +and link the function defined in tdll.c + +exec(SCI+'/modules/dynamic_link/examples/call_dll_in_scilab/demo.sce')
\ No newline at end of file diff --git a/modules/dynamic_link/examples/call_dll_in_scilab/tdll.c b/modules/dynamic_link/examples/call_dll_in_scilab/tdll.c new file mode 100755 index 000000000..629ee947f --- /dev/null +++ b/modules/dynamic_link/examples/call_dll_in_scilab/tdll.c @@ -0,0 +1,36 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA - Allan CORNET + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + */ + +#include <windows.h> +#include <stdio.h> +#include <math.h> + +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; +} + +void doit (double *i, double *j) +{ + printf("Enter doit %f %f\n", *i, *j); + *j = *i + 2 * sin(3.14 / 2); + printf("Exit doit %f %f\n", *i, *j); +} + diff --git a/modules/dynamic_link/examples/call_dll_in_scilab/tdll.def b/modules/dynamic_link/examples/call_dll_in_scilab/tdll.def new file mode 100755 index 000000000..b0a51838b --- /dev/null +++ b/modules/dynamic_link/examples/call_dll_in_scilab/tdll.def @@ -0,0 +1,3 @@ +EXPORTS +DllMain +doit diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext10c.c b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext10c.c new file mode 100755 index 000000000..a85d69bdb --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext10c.c @@ -0,0 +1,46 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA - + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + */ + + +/********************************************* + * external fonction for ode + * input variables n, t, y + * n = dimension of state vector y + * t = time + * y = state variable + * output variable = ydot + * ================================ + * external routine must + * load ydot[0] with d/dt ( y(1)(t) ) + * ydot[1] with d/dt ( y(2)(t) ) + * ... + * i.e. ydot vector of derivative of state y + * ================================ + * With dynamic link: + * link('ext10c.o','ext10c','C') + * ================================ + * passing a parameter to ext6 routine by a list: + * -->param=[0.04,10000,3d+7]; + * -->y=ode([1;0;0],0,[0.4,4],list('ext10c',param)) + * param is retrieved in ext6 by: + * param[0]=y[ *n ] , param[1]=y[ *n + 1] etc + * with this calling sequence y is a n+np vector + * where np=dimension of scilab variable param + *********************************************/ + +int ext10c(int *n, double *t, double *y, double *ydot) +{ + static double param[3]; + param[0] = y[*n + 0]; + param[1] = y[*n + 1]; + param[2] = y[*n + 2]; + ydot[0] = -param[0] * y[0] + param[1] * y[1] * y[2]; + ydot[2] = param[2] * y[1] * y[1]; + ydot[1] = -ydot[0] - ydot[2]; + return(0); +} + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext10c.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext10c.sce new file mode 100755 index 000000000..21cbf66fc --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext10c.sce @@ -0,0 +1,33 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext10c example + +// builder code for ext10c.c +link_name = "ext10c"; // functions to be added to the call table +flag = "c"; // ext10c is a C function +files = ["ext10c.c" ]; // objects files for ext10c +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext10c and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the ode function +//passing a parameter to ext10c routine by a list: + +param=[0.04,10000,3d+7]; +y=ode([1;0;0],0,[0.4,4],list("ext10c",param)); + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext10f.f b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext10f.f new file mode 100755 index 000000000..5d8a843d7 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext10f.f @@ -0,0 +1,27 @@ + +c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +c Copyright (C) INRIA +c +c This file is released under the 3-clause BSD license. See COPYING-BSD. + + subroutine ext10f(neq, t, y, ydot) +c ------------------------------------------- +c exemple with a call to creadmat routine +c -->param=[0.04,10000,3d+7]; +c -->link('ext10f.o','ext10f') +c -->y=ode([1;0;0],0,[0.4,4],'ext10f') +c param must be defined as a scilab variable +c Copyright Inria + double precision t, y, ydot, param + logical creadmat + dimension y(3), ydot(3), param(3) + +c If "param" does not exists return else loads param + if(.not.creadmat('param'//char(0),m,n,param)) return +c *********************************** + + ydot(1) = -param(1)*y(1) + param(2)*y(2)*y(3) + ydot(3) = param(3)*y(2)*y(2) + ydot(2) = -ydot(1) - ydot(3) + return + end diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext10f.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext10f.sce new file mode 100755 index 000000000..d59376a5d --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext10f.sce @@ -0,0 +1,35 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext10f example + +// builder code for ext10f.c +link_name = "ext10f"; // functions to be added to the call table +flag = "f"; // ext10f is a Fortran function +files = ["ext10f.f" ]; // objects files for ext10f +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext10f and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the ode function +//passing a parameter to ext10f routine by a list: + +param=[0.04,10000,3d+7]; +y=ode([1;0;0],0,[0.4,4],list("ext10f",param)); + + + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext11c.c b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext11c.c new file mode 100755 index 000000000..0f725dc47 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext11c.c @@ -0,0 +1,28 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA - + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + */ + + +#include "stack-c.h" + +/**************************************** + * exemple with a call to ReadMatrix + * -->param=[0.04,10000,3d+7]; + * -->link('ext11c.o','ext11c','C') + * -->y=ode([1;0;0],0,[0.4,4],'ext11c') + * param must be defined as a scilab variable + *********************************/ + +int ext11c(int *neq, double *t, double *y, double *ydot) +{ + static int m, n; + static double param[3]; + ReadMatrix("param", &m, &n, param); + ydot[0] = -param[0] * y[0] + param[1] * y[1] * y[2]; + ydot[2] = param[2] * y[1] * y[1]; + ydot[1] = -ydot[0] - ydot[2]; + return(0); +} diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext11c.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext11c.sce new file mode 100755 index 000000000..93cd2c556 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext11c.sce @@ -0,0 +1,34 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext11c example + +// builder code for ext11c.c +link_name = "ext11c"; // functions to be added to the call table +flag = "c"; // ext11c is a C function +files = ["ext11c.c" ]; // objects files for ext11c +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext11c and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the ode function +// Passing a parameter to argument function of ode + +param=[0.04,10000,3d+7]; +y=ode([1;0;0],0,[0.4,4],"ext11c") +//param must be defined as a scilab variable upon calling ode + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext11f.f b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext11f.f new file mode 100755 index 000000000..bbcef3eb3 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext11f.f @@ -0,0 +1,36 @@ + +c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +c Copyright (C) INRIA +c +c This file is released under the 3-clause BSD license. See COPYING-BSD. + + subroutine ext11f(neq, t, y, ydot) +c ------------------------------------------- +c same example with call to cmatptr +c param must be defined as a scilab variable +c exemple with a call to cmatptr function +c -->param=[0.04,10000,3d+7]; +c -->link('ext11f.o','ext11f') +c -->y=ode([1;0;0],0,[0.4,4],'ext11f') +c Copyright Inria + double precision t, y, ydot + logical cmatptr + dimension y(3), ydot(3) +c + include 'stack.h' +c + +c If variable 'param' exists gets its pointer in +c internal stack else return + if(.not.cmatptr('param'//char(0),m,n,lp)) return +c ******************************** +c param entries are in stk(lp),stk(lp+1),stk(lp+2) +c i.e. param(1)= stk(lp), ... +c m,n = dimensions of param = 3,1 (or 1,3 if row v.) + +c (note that vector param not used in this example) + ydot(1) = -stk(lp)*y(1) + stk(lp+1)*y(2)*y(3) + ydot(3) = stk(lp+2)*y(2)*y(2) + ydot(2) = -ydot(1) - ydot(3) + return + end diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext12c.c b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext12c.c new file mode 100755 index 000000000..13e802f87 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext12c.c @@ -0,0 +1,31 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA - + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + */ + +#include "stack-c.h" + +/**************************************** + * same example with call to GetMatrixptr + * param must be defined as a scilab variable + * exemple with a call to matptr routine + * -->param=[0.04,10000,3d+7]; + * -->link('ext12c.o','ext12c','C'); + * -->y=ode([1;0;0],0,[0.4,4],'ext12c') + * *************************** + * param entries are in stk(lp),stk(lp+1),stk(lp+2) + * m,n = dimensions of param = 3,1 (or 1,3 if row v.) + * (note that vector param not used in this example) + ****************************************/ + +int ext12c(int *neq, double *t, double *y, double *ydot) +{ + static int m, n, lp; + GetMatrixptr("param", &m, &n, &lp); + ydot[0] = - (*stk(lp)) * y[0] + (*stk(lp + 1)) * y[1] * y[2]; + ydot[2] = (*stk(lp + 2)) * y[1] * y[1]; + ydot[1] = -ydot[0] - ydot[2]; + return 0; +} diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext12c.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext12c.sce new file mode 100755 index 000000000..8bdea3808 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext12c.sce @@ -0,0 +1,35 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext12c example + +// builder code for ext12c.c +link_name = "ext12c"; // functions to be added to the call table +flag = "c"; // ext12c is a C function +files = ["ext12c.c" ]; // objects files for ext12c +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext12c and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the ode function +//same example as # 10 with call to matptr +//param must be defined as a scilab variable + +param=[0.04,10000,3d+7]; +y=ode([1;0;0],0,[0.4,4],"ext12c"); + + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext12f.f b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext12f.f new file mode 100755 index 000000000..6b65eaf60 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext12f.f @@ -0,0 +1,16 @@ +c This file is released under the 3-clause BSD license. See COPYING-BSD. + + subroutine ext12if(n,a) + + common/cmntest/b(10) + real a(*) + do 1 k=1,max(n,10) + 1 b(k)=a(k) + end + subroutine ext12of(n,c) + common/cmntest/b(10) + real c(*) + do 1 k=1,max(n,10) + 1 c(k)=b(k) + end + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext13c.c b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext13c.c new file mode 100755 index 000000000..3709da94d --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext13c.c @@ -0,0 +1,39 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA/ENPC + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + * + */ + + +struct +{ + float b[10]; +} cmntest; + +#define Max(x,y) (((x)>(y))?(x):(y)) + +int ext13ic(int *n, float *a) +{ + int i1; + static int k; + i1 = Max(*n, 10); + for (k = 0; k < i1; ++k) + { + cmntest.b[k] = a[k]; + } +} + +int ext13oc(int *n, float *c) +{ + int i1; + static int k; + i1 = Max(*n, 10); + for (k = 0; k < i1; ++k) + { + c[k] = cmntest.b[k]; + } +} + + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext13c.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext13c.sce new file mode 100755 index 000000000..a829dfd74 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext13c.sce @@ -0,0 +1,38 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext13c example + +// builder code for ext13c.c +// functions to be added to the call table +link_name = ["ext13ic","ext13oc"]; +flag = "c"; // ext13c is a C function +files = ["ext13c.c" ]; // objects files for ext13c +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext13c and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the call function +//sharing common data + +a=1:10; +n=10;a=1:10; +call("ext13ic",n,1,"i",a,2,"r","out",2); //loads b with a +c=call("ext13oc",n,1,"i","out",[1,10],2,"r"); //loads c with b +if norm(c-a) > %eps then pause,end + + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext13f.f b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext13f.f new file mode 100755 index 000000000..f8d4c3a5b --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext13f.f @@ -0,0 +1,56 @@ +c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +c Copyright (C) INRIA +c +c This file is released under the 3-clause BSD license. See COPYING-BSD. + + + + subroutine ext13fi(fname) + character*(*) fname + logical getrhsvar, createvar, putlhsvar + include 'stack.h' +c + nbvars=0 + minrhs=3 + maxrhs=3 + minlhs=1 + maxlhs=1 +c + if(.not.((rhs.ge.minrhs).and.(rhs.le.maxrhs))) then + call erro('wrong number of rhs arguments') + return + endif + if(.not.((lhs.ge.minlhs).and.(lhs.le.maxlhs))) then + call erro('wrong number of lhs arguments') + return + endif +c +c when using fort the first parameter is the function name + if(.not.getrhsvar(1,'c',m1,n1,l1)) return + if(.not.getrhsvar(2,'d',m2,n2,l2)) return + if(.not.getrhsvar(3,'d',m3,n3,l3)) return + if(m2*n2.ne.m3*n3) then + call erro('incompatible arguments ') + return + endif +c + if(.not.createvar(4,'d',m2,n2,l4)) return +c + call ext14f(n2*m2,stk(l2),stk(l3),stk(l4)) + lhsvar(1)=4 + if(.not.putlhsvar()) return + end + + + subroutine ext13f(n,a,b,c) +c (very) simple example 1 +c -->link('ext1f.o','ext1f'); +c -->a=[1,2,3];b=[4,5,6];n=3; +c -->c=fort('ext1f',n,1,'i',a,2,'d',b,3,'d','out',[1,3],4,'d') +c c=a+b + double precision a(*),b(*),c(*) + do 1 k=1,n + c(k)=a(k)+b(k) + 1 continue + return + end diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext14c.c b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext14c.c new file mode 100755 index 000000000..4b2e0dbf2 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext14c.c @@ -0,0 +1,56 @@ +/* Copyright Inria/Enpc *//* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA/ENPC + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + * + */ + +/************************************ + * (very) simple example 1 + * with a C wrapper + * -->link('ext1c.o','ext1cI','C'); + * -->a=[1,2,3];b=[4,5,6];n=3; + * -->c=fort('ext1cI',n,a,b) + * c=a+b + ************************************/ + +#include "stack-c.h" + +int ext14cI(char *fname) +{ + int m1, n1, l1, m2, n2, l2, m3, n3, l3, n, l4; + int minlhs = 1, minrhs = 3, maxlhs = 1, maxrhs = 3; + Nbvars = 0; + CheckRhs(minrhs, maxrhs) ; + CheckLhs(minlhs, maxlhs) ; + GetRhsVar( 1, STRING_DATATYPE, &m1, &n1, &l1); + GetRhsVar( 2, MATRIX_OF_DOUBLE_DATATYPE, &m2, &n2, &l2); + GetRhsVar( 3, MATRIX_OF_DOUBLE_DATATYPE, &m3, &n3, &l3); + if ( m3*n3 != m2 * n2) + { + sciprint("%s :Incompatible dimensions\n", fname); + SciError(999); + return(0); + } + CreateVar( 4, MATRIX_OF_DOUBLE_DATATYPE, &m2, &n2, &l4); + n = m3 * n3; + ext14c(&n, stk(l2), stk(l3), stk(l4)); + LhsVar(1) = 4; + PutLhsVar(); + return(0); +} + + +int ext14c(n, a, b, c) +int *n; +double *a, *b, *c; +{ + int k; + for (k = 0; k < *n; ++k) + { + c[k] = a[k] + b[k]; + } + return(0); +} + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext14c.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext14c.sce new file mode 100755 index 000000000..5e5d8bc5f --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext14c.sce @@ -0,0 +1,36 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext14c example + +// builder code for ext14c.c +// functions to be added to the call table +link_name = ["ext14cI"]; +flag = "c"; // ext14c is a C function +files = ["ext14c.c" ]; // objects files for ext14c +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext14c and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the call function +//(very) simple example 1 + +a=[1,2,3];b=[4,5,6];n=3; +c=call("ext14cI",a,b); +if norm(c-(a+b)) > %eps then pause,end + + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext1c.c b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext1c.c new file mode 100755 index 000000000..6f4ef22de --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext1c.c @@ -0,0 +1,26 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA/ENPC + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + */ + + +/************************************ + * (very) simple example 1 + * -->link('ext1c.o','ext1c','C'); + * -->a=[1,2,3];b=[4,5,6];n=3; + * -->c=call('ext1c',n,1,'i',a,2,'d',b,3,'d','out',[1,3],4,'d') + * c=a+b + ************************************/ + +int ext1c(int *n, double *a, double *b, double *c) +{ + int k; + for (k = 0; k < *n; ++k) + { + c[k] = a[k] + b[k]; + } + return(0); +} + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext1c.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext1c.sce new file mode 100755 index 000000000..811187a14 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext1c.sce @@ -0,0 +1,39 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext1c example + +// builder code for ext1c.c +link_name = "ext1c"; // functions to be added to the call table +flag = "c"; // ext1c is a C function +files = ["ext1c.c" ]; // objects files for ext1c +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext1c and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the call function +//(very) simple example 1 + +a=[1,2,3];b=[4,5,6];n=3; +c=call("ext1c",n,1,"i",a,2,"d",b,3,"d","out",[1,3],4,"d"); +if norm(c-(a+b)) > %eps then pause,end + + + + + + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext1f.f b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext1f.f new file mode 100755 index 000000000..b859a4425 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext1f.f @@ -0,0 +1,18 @@ +c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +c Copyright (C) INRIA +c +c This file is released under the 3-clause BSD license. See COPYING-BSD. + + subroutine ext1f(n,a,b,c) +c (very) simple example 1 +c -->link('ext1f.o','ext1f'); +c -->a=[1,2,3];b=[4,5,6];n=3; +c -->c=call('ext1f',n,1,'i',a,2,'d',b,3,'d','out',[1,3],4,'d') +c c=a+b + + double precision a(*),b(*),c(*) + do 1 k=1,n + c(k)=a(k)+b(k) + 1 continue + return + end diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext1f.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext1f.sce new file mode 100755 index 000000000..b4768dcb5 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext1f.sce @@ -0,0 +1,34 @@ + + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 +// Demo file for ext1f example + +// builder code for ext1f.c +link_name = "ext1f"; // functions to be added to the call table +flag = "f"; // ext1f is a Fortran function +files = ["ext1f.f" ]; // objects files for ext1f +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext1f and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the call function +//(very) simple example 1 + +a=[1,2,3];b=[4,5,6];n=3; +c=call("ext1f",n,1,"i",a,2,"d",b,3,"d","out",[1,3],4,"d"); +if norm(c-(a+b)) > %eps then pause,end + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext2c.c b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext2c.c new file mode 100755 index 000000000..80a8eb401 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext2c.c @@ -0,0 +1,27 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA/ENPC + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + */ + + +/************************************ + * simple example 2 (using sin and cos) + * -->link('ext2c.o','ext2c','C'); + * -->a=[1,2,3];b=[4,5,6];n=3; + * -->c=call('ext2c',n,1,'i',a,2,'d',b,3,'d','out',[1,3],4,'d') + * -->c=sin(a)+cos(b) + ************************************/ + +#include <math.h> + +int ext2c(int *n, double *a, double *b, double *c) +{ + static int k; + for (k = 0; k < *n; ++k) + { + c[k] = sin(a[k]) + cos(b[k]); + } + return(0); +} diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext2c.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext2c.sce new file mode 100755 index 000000000..72d278ab7 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext2c.sce @@ -0,0 +1,32 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext2c example + +// builder code for ext2c.c +link_name = "ext2c"; // functions to be added to the call table +flag = "c"; // ext2c is a C function +files = ["ext2c.c" ]; // objects files for ext2c +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext2c and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the call function + +a=[1,2,3];b=[4,5,6];n=3; +c=call("ext2c",n,1,"i",a,2,"d",b,3,"d","out",[1,3],4,"d"); +if norm(c-(sin(a)+cos(b))) > %eps then pause,end diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext2f.f b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext2f.f new file mode 100755 index 000000000..bc95e9095 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext2f.f @@ -0,0 +1,18 @@ +c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +c Copyright (C) INRIA/ENPC +c +c This file is released under the 3-clause BSD license. See COPYING-BSD. + + subroutine ext2f(n,a,b,c) +c simple example 2 (using sin and cos) +c -->link('ext2f.o','ext2f'); +c -->a=[1,2,3];b=[4,5,6];n=3; +c -->c=call('ext2f',n,1,'i',a,2,'d',b,3,'d','out',[1,3],4,'d') +c -->c=sin(a)+cos(b) + + double precision a(*),b(*),c(*) + do 1 k=1,n + c(k)=sin(a(k))+cos(b(k)) + 1 continue + return + end diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext2f.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext2f.sce new file mode 100755 index 000000000..96ef6a16f --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext2f.sce @@ -0,0 +1,32 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext2f example + +// builder code for ext2f.c +link_name = "ext2f"; // functions to be added to the call table +flag = "f"; // ext2f is a Fortran function +files = ["ext2f.f" ]; // objects files for ext2f +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext2f and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the call function + +a=[1,2,3];b=[4,5,6];n=3; +c=call("ext2f",n,1,"i",a,2,"d",b,3,"d","out",[1,3],4,"d"); +if norm(c-(sin(a)+cos(b))) > %eps then pause,end diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext3c.c b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext3c.c new file mode 100755 index 000000000..27d48a8ab --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext3c.c @@ -0,0 +1,42 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA/ENPC + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + */ + + + +/************************************ + * simple example 3 (passing a chain) + * -->host('make /tmp/ext3c.o'); + * -->link('/tmp/ext3c.o','ext3c','C'); + * -->a=[1,2,3];b=[4,5,6];n=3; + * -->c=call('ext3c','yes',1,'c',n,2,'i',a,3,'d',b,4,'d','out',[1,3],5,'d') + * -->c-(sin(a)+cos(b) ) + * -->c=call('ext3c','no',1,'c',n,2,'i',a,3,'d',b,4,'d','out',[1,3],5,'d') + * -->c-(a+b ) + ************************************/ + +#include <math.h> +#include <string.h> + +int ext3c(char *ch, int *n, double *a, double *b, double *c) +{ + static int k; + if (strcmp(ch, "yes") == 0) + { + for (k = 0; k < *n; ++k) + { + c[k] = sin(a[k]) + cos(b[k]); + } + } + else + { + for (k = 0; k < *n; ++k) + { + c[k] = a[k] + b[k]; + } + } + return(0); +} diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext3c.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext3c.sce new file mode 100755 index 000000000..21ab5b274 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext3c.sce @@ -0,0 +1,34 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext3c example + +// builder code for ext3c.c +link_name = "ext3c"; // functions to be added to the call table +flag = "c"; // ext3c is a C function +files = ["ext3c.c" ]; // objects files for ext3c +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext3c and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the call function + +a=[1,2,3];b=[4,5,6];n=3; +c=call("ext3c","yes",1,"c",n,2,"i",a,3,"d",b,4,"d","out",[1,3],5,"d"); +if norm(c-(sin(a)+cos(b)))> %eps then pause,end +c=call("ext3c","no",1,"c",n,2,"i",a,3,"d",b,4,"d","out",[1,3],5,"d"); +if norm(c-(a+b)) > %eps then pause,end diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext3f.f b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext3f.f new file mode 100755 index 000000000..660dac04e --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext3f.f @@ -0,0 +1,27 @@ +c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +c Copyright (C) INRIA/ENPC +c +c This file is released under the 3-clause BSD license. See COPYING-BSD. + + subroutine ext3f(ch,n,a,b,c) +c ---------------------------- +c example 3 (passing a chain) +c -->link('ext3f.o','ext3f'); +c -->a=[1,2,3];b=[4,5,6];n=3; +c -->c=call('ext3f','yes',1,'c',n,2,'i',a,3,'d',b,4,'d','out',[1,3],5,'d') +c -->c=sin(a)+cos(b) +c ------------------------------------- + + double precision a(*),b(*),c(*) + character*(*) ch + if(ch(1:3).eq.'yes') then + do 1 k=1,n + c(k)=sin(a(k))+cos(b(k)) + 1 continue + else + do 2 k=1,n + c(k)=a(k)+b(k) + 2 continue + endif + return + end diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext3f.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext3f.sce new file mode 100755 index 000000000..457e854e5 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext3f.sce @@ -0,0 +1,36 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext3f example + +// builder code for ext3f.c +link_name = "ext3f"; // functions to be added to the call table +flag = "f"; // ext3f is a Fortran function +files = ["ext3f.f" ]; // objects files for ext3f +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext3f and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the call function +//reading vector with name='a' in scilab internal stack + +a=[1,2,3];b=[4,5,6];n=3; +c=call("ext3f","yes",1,"c",n,2,"i",a,3,"d",b,4,"d","out",[1,3],5,"d"); +if norm(c-(sin(a)+cos(b)))> %eps then pause,end +c=call("ext3f","no",1,"c",n,2,"i",a,3,"d",b,4,"d","out",[1,3],5,"d"); +if norm(c-(a+b)) > %eps then pause,end + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext4c.c b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext4c.c new file mode 100755 index 000000000..c3a2136fb --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext4c.c @@ -0,0 +1,58 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA/ENPC + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + * + */ + +#include <math.h> +#include "stack-c.h" + +/************************************ + * simple example 4 (reading a scilab chain) + * -->link('ext4c.o','ext4c','C'); + * -->a=[1,2,3];b=[4,5,6];n=3;YesOrNo='yes' + * -->c=call('ext4c',n,1,'i',a,2,'d',b,3,'d','out',[1,3],4,'d') + * -->c=sin(a)+cos(b) + * -->YesOrNo='no' + * -->c=a+b + * -->clear yes --> undefined variable : yes + ************************************/ + +#define MAXCH 10 + +int ext4c(int *n, double *a, double *b, double *c) +{ + int k; + char ch[MAXCH]; + int lch = MAXCH; + + /* We search a Scilab Object name YesOrNo + * check that it is a string + * and store the string in ch + * lch is used on entry to give the maximum number + * of characters which can be stored in ch + * After the call lch contains the number of + * copied characters + */ + + ReadString("YesOrNo", &lch, ch); + /******************************/ + if (strcmp(ch, "yes") == 0) + { + for (k = 0; k < *n; ++k) + { + c[k] = sin(a[k]) + cos(b[k]); + } + } + else + { + for (k = 0; k < *n; ++k) + { + c[k] = a[k] + b[k]; + } + } + return(0); +} + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext4c.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext4c.sce new file mode 100755 index 000000000..2cf23605f --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext4c.sce @@ -0,0 +1,37 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext4c example + +// builder code for ext4c.c +link_name = "ext4c"; // functions to be added to the call table +flag = "c"; // ext4c is a C function +files = ["ext4c.c" ]; // objects files for ext4c +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext4c and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the call function + +a=[1,2,3];b=[4,5,6];n=3;YesOrNo="yes"; +c=call("ext4c",n,1,"i",a,2,"d",b,3,"d","out",[1,3],4,"d"); +if norm(c-(sin(a)+cos(b))) > %eps then pause,end +YesOrNo="no"; +c=call("ext4c",n,1,"i",a,2,"d",b,3,"d","out",[1,3],4,"d"); +if norm(c-(a+b)) > %eps then pause,end +//clear yes --> undefined variable : yes + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext4f.f b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext4f.f new file mode 100755 index 000000000..cd7454f46 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext4f.f @@ -0,0 +1,34 @@ +c This file is released under the 3-clause BSD license. See COPYING-BSD. + + subroutine ext4f(n,a,b,c) +c example 4 (reading a chain) +c -->link('ext4f.o','ext4f'); +c -->a=[1,2,3];b=[4,5,6];n=3;yes='yes' +c -->c=call('ext4f',n,1,'i',a,2,'d',b,3,'d','out',[1,3],4,'d') +c -->c=sin(a)+cos(b) +c -->yes='no' +c -->c=a+b +c -->clear yes --> undefined variable : yes + + double precision a(*),b(*),c(*) + integer chmax + logical creadchain + parameter (chmax=10) + character ch*(chmax) + +c If chain named yes exists reads it in ch else return + lch=chmax + if(.not.creadchain('yes'//char(0),lch,ch)) return +c ********************************* + if(ch(1:lch).eq.'yes') then + do 1 k=1,n + c(k)=sin(a(k))+cos(b(k)) + 1 continue + else + do 2 k=1,n + c(k)=a(k)+b(k) + 2 continue + endif + return + end + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext4f.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext4f.sce new file mode 100755 index 000000000..6ede217d0 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext4f.sce @@ -0,0 +1,37 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext4f example + +// builder code for ext4f.c +link_name = "ext4f"; // functions to be added to the call table +flag = "f"; // ext4f is a Fortran function +files = ["ext4f.f" ]; // objects files for ext4f +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext4f and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the call function + +a=[1,2,3];b=[4,5,6];n=3;yes="yes"; +c=call("ext4f",n,1,"i",a,2,"d",b,3,"d","out",[1,3],4,"d"); +if norm(c-(sin(a)+cos(b))) > %eps then pause,end +yes="no"; +c=call("ext4f",n,1,"i",a,2,"d",b,3,"d","out",[1,3],4,"d"); +if norm(c-(a+b)) > %eps then pause,end +//clear yes --> undefined variable : yes + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext5c.c b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext5c.c new file mode 100755 index 000000000..9a9b97702 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext5c.c @@ -0,0 +1,32 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA/ENPC + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + */ + +#include "stack-c.h" + +/****************************************** + * Example 5 + * reading a vector in scilab internal stack using ReadMatrix + * (see SCIDIR/system2/readmat.f) + * -->link('ext5c.o','ext5c','C') + * -->Amatrix=[1,2,3];b=[2,3,4]; + * -->c=call('ext5c',b,1,'d','out',[1,3],2,'d') + * -->c=Amatrix+2*b + ******************************************/ + +int ext5c(double *b, double *c) +{ + static double a[3]; + static int k, m, n; + ReadMatrix("Amatrix", &m, &n, a); + /*******************************/ + /* [m,n]=size(Amatrix) here m=1 n=3, a=Amatrix which must exist in Scilab*/ + for (k = 0; k < n; ++k) + { + c[k] = a[k] + b[k] * 2.; + } + return(0); +} diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext5c.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext5c.sce new file mode 100755 index 000000000..69e08686b --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext5c.sce @@ -0,0 +1,34 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext5c example + +// builder code for ext5c.c +link_name = "ext5c"; // functions to be added to the call table +flag = "c"; // ext5c is a C function +files = ["ext5c.c" ]; // objects files for ext5c +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext5c and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the call function +// reading vector a in scilab internal stack + +Amatrix=[1,2,3];b=[2,3,4]; +c=call("ext5c",b,1,"d","out",[1,3],2,"d"); +if norm(c-(Amatrix+2*b)) > %eps then pause,end + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext5f.f b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext5f.f new file mode 100755 index 000000000..3f801c322 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext5f.f @@ -0,0 +1,28 @@ + +c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +c Copyright (C) INRIA/ENPC +c +c This file is released under the 3-clause BSD license. See COPYING-BSD. + + subroutine ext5f(b,c) +c example 5 +c reading a vector in scilab internal stack using creadmat +c (see SCIDIR/system2/creadmat.f) +c -->link('ext5f.o','ext5f') +c -->a=[1,2,3];b=[2,3,4]; +c -->c=call('ext5f',b,1,'d','out',[1,3],2,'d') +c -->c=a+2*b + + double precision a(3),b(*),c(*) + logical creadmat + +c If 'a' exists reads it else return + if(.not.creadmat('a'//char(0),m,n,a)) then + write(6,*) 'ext5', m,n,a(1),a(2),a(3) + return + endif + do 1 k=1,n + c(k)=a(k)+2.0d0*b(k) + 1 continue + return + end diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext5f.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext5f.sce new file mode 100755 index 000000000..e1137b716 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext5f.sce @@ -0,0 +1,33 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext5f example + +// builder code for ext5f.c +link_name = "ext5f"; // functions to be added to the call table +flag = "f"; // ext5f is a Fortran function +files = ["ext5f.f" ]; // objects files for ext5f +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext5f and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the call function +// reading vector a in scilab internal stack + +a=[1,2,3];b=[2,3,4]; +c=call("ext5f",b,1,"d","out",[1,3],2,"d"); +if norm(c-(a+2*b)) > %eps then pause,end diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext6c.c b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext6c.c new file mode 100755 index 000000000..fef285eb4 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext6c.c @@ -0,0 +1,30 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA/ENPC + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + */ + +#include "stack-c.h" + +/****************************************** + * example 6 + * reading a vector in scilab internal stack using ReadMatrix + * -->link('ext6c.o','ext6c','C') + * -->a=[1,2,3];b=[2,3,4]; + * -->c=call('ext6c',a,1,'c',b,2,'d','out',[1,3],3,'d') + * -->c=a+2*b + ******************************************/ + +int ext6c(char *aname, double *b, double *c) +{ + double a[3]; + int k, m, n; + ReadMatrix(aname, &m, &n, a); + /* [m,n]=size(a) here m=1 n=3 */ + for (k = 0; k < n; ++k) + { + c[k] = a[k] + b[k] * 2.; + } + return(0); +} diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext6c.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext6c.sce new file mode 100755 index 000000000..2c930b8f1 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext6c.sce @@ -0,0 +1,35 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext6c example + +// builder code for ext6c.c +link_name = "ext6c"; // functions to be added to the call table +flag = "c"; // ext6c is a C function +files = ["ext6c.c" ]; // objects files for ext6c +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext6c and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the call function +//reading vector with name='a' in scilab internal stack + +a=[1,2,3];b=[2,3,4]; +c=call("ext6c","a",1,"c",b,2,"d","out",[1,3],3,"d"); +if norm(c-(a+2*b)) > %eps then pause,end + + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext6f.f b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext6f.f new file mode 100755 index 000000000..08def7f42 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext6f.f @@ -0,0 +1,26 @@ +c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +c Copyright (C) INRIA/ENPC +c +c This file is released under the 3-clause BSD license. See COPYING-BSD. + + subroutine ext6f(aname,b,c) +c example 6 +c reading a vector in scilab internal stack using creadmat interface +c -->link('ext6f.o','ext6f') +c -->a=[1,2,3];b=[2,3,4]; +c -->c=call('ext6f','a',1,'c',b,2,'d','out',[1,3],3,'d') +c -->c=a+2*b + + double precision a(3),b(*),c(*) + logical creadmat + character*(*) aname + +c If aname exists reads it (in a) else return + if(.not.creadmat(aname,m,n,a)) return +c +c [m,n]=size(a) here m=1 n=3 + do 1 k=1,n + c(k)=a(k)+2.0d0*b(k) + 1 continue + return + end diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext6f.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext6f.sce new file mode 100755 index 000000000..7d88cdff2 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext6f.sce @@ -0,0 +1,38 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext6f example + +// builder code for ext6f.c +link_name = "ext6f"; // functions to be added to the call table +flag = "f"; // ext6f is a Fortran function +files = ["ext6f.f" ]; // objects files for ext6f +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext6f and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the call function +//reading vector with name='a' in scilab internal stack + +a=[1,2,3];b=[2,3,4]; +c=call("ext6f","a",1,"c",b,2,"d","out",[1,3],3,"d"); +if norm(c-(a+2*b)) > %eps then pause,end + + + + + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext7c.c b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext7c.c new file mode 100755 index 000000000..97b51a59b --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext7c.c @@ -0,0 +1,44 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA/ENPC + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + * + */ + +#include "stack-c.h" + +/****************************************** + * example 7 + * creating vector c in scilab internal stack + * -->link('ext7c.o','ext7c','C') + * -->a=[1,2,3]; b=[2,3,4]; + * c does not exist (c made by the call to matz) + * -->call('ext7c',a,1,'d',b,2,'d','out',1); + * c now exists + * -->c=a+2*b + ******************************************/ + + +int ext7c(double *a, double *b) +{ + static int c1 = 1; + static int c3 = 3; + static char str[] = "test"; + int strl; + + double c[3]; + int k = 0; + for (k = 0; k < 3; k++) + { + c[k] = a[k] + b[k] * 2.; + } + /** sending c[] to scilab variable c (size [1,3]) **/ + WriteMatrix("c", &c1, &c3, c); + /** sending f characters of "test" to Scilab variable d **/ + strl = strlen(str); + /* Creating the Scilab variable d from str */ + WriteString("d", &strl, str); + return(0); +} + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext7c.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext7c.sce new file mode 100755 index 000000000..c7dd9566e --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext7c.sce @@ -0,0 +1,39 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext7c example + +// builder code for ext7c.c +link_name = "ext7c"; // functions to be added to the call table +flag = "c"; // ext7c is a C function +files = ["ext7c.c" ]; // objects files for ext7c +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext7c and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the call function +//creating vector c in scilab internal stack + +a=[1,2,3]; b=[2,3,4]; +//c does not exist (c made by ext7c) +c1=call("ext7c",a,1,"d",b,2,"d","out",2); +if norm(c1-b) > %eps then pause,end +//c now exists +if norm(c-(a+2*b)) > %eps then pause,end +//d exists +if d<>"test" then pause,end + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext7f.f b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext7f.f new file mode 100755 index 000000000..cb004f69a --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext7f.f @@ -0,0 +1,28 @@ + +c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +c Copyright (C) INRIA/ENPC +c +c This file is released under the 3-clause BSD license. See COPYING-BSD. + + subroutine ext7f(a,b) +c example 7 +c creating vector c in scilab internal stack +c -->link('ext7f.o','ext7f') +c -->a=[1,2,3]; b=[2,3,4]; +c c does not exist (c made by the call to matz) +c -->call('ext7f',a,1,'d',b,2,'d','out',1); +c c now exists +c -->c=a+2*b + + double precision a(3),b(3),c(3),w + logical cwritemat,cwritechain + do 1 k=1,3 + c(k)=a(k)+2.0d0*b(k) + 1 continue +c sending c array values to c Scilab variable +c of size [1,3] + if (.not.cwritemat('c'//char(0),1,3,c)) return +c sending string 'test' (size 4) to Scilab variable d + if (.not.cwritechain('d'//char(0),4,'test')) return + return + end diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext7f.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext7f.sce new file mode 100755 index 000000000..8d416f750 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext7f.sce @@ -0,0 +1,40 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext7f example + +// builder code for ext7f.c +link_name = "ext7f"; // functions to be added to the call table +flag = "f"; // ext7f is a Fortran function +files = ["ext7f.f" ]; // objects files for ext7f +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext7f and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the call function +//creating vector c in scilab internal stack + + +a=[1,2,3]; b=[2,3,4]; +//c does not exist (c made by ext7c) +c1=call("ext7f",a,1,"d",b,2,"d","out",2); +if norm(c1-b) > %eps then pause,end +//c now exists +if norm(c-(a+2*b)) > %eps then pause,end +//d exists +if d<>"test" then pause,end + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext8c.c b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext8c.c new file mode 100755 index 000000000..05241db05 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext8c.c @@ -0,0 +1,29 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA/ENPC + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + */ + +#include "stack-c.h" + +/**************************************** + * an example with GetMatrixptr + * -->param=[1,2,3]; + * -->link('ext8c.o','ext8c','C'); + * -->y=call('ext8c','out',size(param),1,'d'); + ****************************************/ + +int ext8c(double *y) +{ + static int m, n, lp, i; + GetMatrixptr("param", &m, &n, &lp); + /* param can be changed */ + *stk(lp) = 18.0; + /* param can be read */ + for (i = 0; i < m * n ; i++ ) + { + y[i] = (*stk(lp + i)); + } + return 0; +} diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext8c.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext8c.sce new file mode 100755 index 000000000..806a54845 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext8c.sce @@ -0,0 +1,36 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext8c example + +// builder code for ext8c.c +link_name = "ext8c"; // functions to be added to the call table +flag = "c"; // ext8c is a C function +files = ["ext8c.c" ]; // objects files for ext8c +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext8c and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the call function +//same example as # 10 with call to matptr +//param must be defined as a scilab variable + +param=[1,2,3] +y=call("ext8c","out",size(param),1,"d"); +if norm(y-param) > %eps then pause,end +if norm(param(1)-18.0) > %eps then pause,end + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext8f.f b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext8f.f new file mode 100755 index 000000000..007f8e8e3 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext8f.f @@ -0,0 +1,35 @@ + +c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +c Copyright (C) INRIA +c +c This file is released under the 3-clause BSD license. See COPYING-BSD. + + subroutine ext8f(n, t, y, ydot) +c argument function for ode +c input variables n, t, y +c n = dimension of state vector y +c t = time +c y = state variable +c output variable = ydot +c +c external routine must +c load ydot(1) with d/dt ( y(1)(t) ) +c ydot(2) with d/dt ( y(2)(t) ) +c ... +c i.e. ydot vector of derivative of state y +c +c Example: +c call this ext8f routine: +c ode([1;0;0],0,[0.4,4],'ext9f') +c +c With dynamic link: +c -->link('ext8f.o','ext8f') +c -->ode([1;0;0],0,[0.4,4],'ext8f') +c + + double precision t, y, ydot + dimension y(3), ydot(3) + ydot(1) = -.0400d+0*y(1) + 1.0d+4*y(2)*y(3) + ydot(3) = 3.0d+7*y(2)*y(2) + ydot(2) = -ydot(1) - ydot(3) + end diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext8f.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext8f.sce new file mode 100755 index 000000000..5b921a426 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext8f.sce @@ -0,0 +1,35 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext8f example + +// builder code for ext8f.c +link_name = "ext8f"; // functions to be added to the call table +flag = "f"; // ext8f is a Fortran function +files = ["ext8f.f" ]; // objects files for ext8f +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext8f and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the ode function +//same example as # 10 with call to matptr +//param must be defined as a scilab variable + +param=[0.04,10000,3d+7]; +y=ode([1;0;0],0,[0.4,4],"ext8f"); + + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext9c.c b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext9c.c new file mode 100755 index 000000000..48466a80f --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext9c.c @@ -0,0 +1,42 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA/ENPC + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + * + */ + + +/********************************************* + * argument function for ode + * input variables n, t, y + * n = dimension of state vector y + * t = time + * y = state variable + * output variable = ydot + * ================================ + * external routine must + * load ydot[0] with d/dt ( y(1)(t) ) + * ydot[1] with d/dt ( y(2)(t) ) + * ... + * i.e. ydot vector of derivative of state y + * ================================ + * Example: + * call this ext5 routine: + * ode([1;0;0],0,[0.4,4],'ext9c') + * ================================ + * With dynamic link: + * -->link('ext9c.o','ext9c','C') + * -->ode([1;0;0],0,[0.4,4],'ext9c') + *********************************************/ + +int ext9c(int *n, double *t, double *y, double *ydot) +{ + ydot[0] = y[0] * -.04 + y[1] * 1e4 * y[2]; + ydot[2] = y[1] * 3e7 * y[1]; + ydot[1] = -ydot[0] - ydot[2]; + return(0); +} + + + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext9c.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext9c.sce new file mode 100755 index 000000000..b654b3153 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext9c.sce @@ -0,0 +1,32 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext8c example + +// builder code for ext9c.c +link_name = "ext9c"; // functions to be added to the call table +flag = "c"; // ext9c is a C function +files = ["ext9c.c" ]; // objects files for ext9c +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext9c and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +//test new function through the call function +//argument function for ode +//call ext9c argument function with dynamic link + +ode([1;0;0],0,[0.4,4],"ext9c"); diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext9f.f b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext9f.f new file mode 100755 index 000000000..667d39e03 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext9f.f @@ -0,0 +1,41 @@ + +c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +c Copyright (C) INRIA +c +c This file is released under the 3-clause BSD license. See COPYING-BSD. + + subroutine ext9f(n, t, y, ydot) +c external fonction for ode +c input variables n, t, y +c n = dimension of state vector y +c t = time +c y = state variable +c output variable = ydot +c +c external routine must +c load ydot(1) with d/dt ( y(1)(t) ) +c ydot(2) with d/dt ( y(2)(t) ) +c ... +c i.e. ydot vector of derivative of state y +c +c With dynamic link: +c link('ext9f.o','ext9f') +c +c passing a parameter to ext10f routine by a list: +c -->param=[0.04,10000,3d+7]; +c -->y=ode([1;0;0],0,[0.4,4],list('ext9f',param)) +c param is retrieved in ext9f by: +c param(1)=y(n+1) , param(2)=y(n+2) etc +c with this calling sequence y is a n+np vector +c where np=dimension of scilab variable param +c + + double precision t, y, ydot, param + dimension y(3), ydot(3),param(3) + param(1)=y(n+1) + param(2)=y(n+2) + param(3)=y(n+3) + ydot(1) = -param(1)*y(1) + param(2)*y(2)*y(3) + ydot(3) = param(3)*y(2)*y(2) + ydot(2) = -ydot(1) - ydot(3) + end diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext9f.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext9f.sce new file mode 100755 index 000000000..20cb73871 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/ext9f.sce @@ -0,0 +1,40 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +// Demo file for ext9f example + +// builder code for ext9f.c +// functions to be added to the call table +link_name = ["ext9f"]; +flag = "f"; // ext9f is a Fortran function +files = ["ext9f.f" ]; // objects files for ext9f +libs = []; // other libs needed for linking + +// the next call generates files (Makelib,loader.sce) used +// for compiling and loading ext10f and performs the compilation + +ilib_for_link(link_name,files,libs,flag); + +// load new function code in the scope of call +// using the previously generated loader +exec loader.sce; + +// test new function through the ode function +//passing a parameter to ext10f routine by a list: + +param=[0.04,10000,3d+7]; +y=ode([1;0;0],0,[0.4,4],list("ext9f",param)); + + + + + + + diff --git a/modules/dynamic_link/examples/dynamic_link_c_and_fortran/runall.sce b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/runall.sce new file mode 100755 index 000000000..d227eff87 --- /dev/null +++ b/modules/dynamic_link/examples/dynamic_link_c_and_fortran/runall.sce @@ -0,0 +1,39 @@ + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - +// +// 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 + +examples = [ "ext1c.sce" ; "ext1f.sce" ; +"ext2c.sce" ; "ext2f.sce" ; +"ext3c.sce" ; "ext3f.sce" ; +"ext4c.sce" ; "ext4f.sce" ; +"ext5c.sce" ; "ext5f.sce" ; +"ext6c.sce" ; "ext6f.sce" ; +"ext7c.sce" ; "ext7f.sce" ; +"ext8c.sce" ; "ext8f.sce" ; +"ext9c.sce" ; "ext9f.sce" ; +"ext10c.sce" ; "ext10f.sce" ; +"ext11c.sce" ; "ext12c.sce" ; +"ext13c.sce" ; "ext14c.sce" ]; + +for i=1:size(examples,"*") + disp("-----------------------------------"); + disp("Example : " + examples(i)); + disp("-----------------------------------"); + exec(examples(i)); + +end + + + + + + + + + diff --git a/modules/dynamic_link/examples/gateway/builder.sce b/modules/dynamic_link/examples/gateway/builder.sce new file mode 100755 index 000000000..d1aef5097 --- /dev/null +++ b/modules/dynamic_link/examples/gateway/builder.sce @@ -0,0 +1,25 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 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 + +// This is the builder.sce +// must be run from this directory + +ilib_name = "libtutorial"; // interface library name +files = ["sci_view.c","displ.c","sci_matmul.c","matmul.c"]; // objects files +// +libs = []; // other libs needed for linking +table = [ "matmul","sci_matmul"; +"view", "sci_view"]; // table of (scilab_name,interface-name) + +// do not modify below +// ---------------------------------------------- +ilib_build(ilib_name,table,files,libs); + + + diff --git a/modules/dynamic_link/examples/gateway/displ.c b/modules/dynamic_link/examples/gateway/displ.c new file mode 100755 index 000000000..96b8f334f --- /dev/null +++ b/modules/dynamic_link/examples/gateway/displ.c @@ -0,0 +1,20 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA - + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + * + */ +#include "displ.h" +#include "sciprint.h" + +void displ(double *a, int ma, int na, int *b, int mb, int nb, char *c, int mc, int nc) +{ + sciprint("First parameter (matrix) is %i x %i:\n", ma, na); + sciprint("its (1,1) entry is %e (double).\n", a[0]); + sciprint("Second parameter (matrix) is %i x %i:\n", mb, nb); + sciprint("its (1,1) entry is %i (int).\n", b[0]); + sciprint("Third parameter (string) is %i character long: it is the string \"%s\"\n", mc * nc, c); +} + + diff --git a/modules/dynamic_link/examples/gateway/displ.h b/modules/dynamic_link/examples/gateway/displ.h new file mode 100755 index 000000000..900ffbe55 --- /dev/null +++ b/modules/dynamic_link/examples/gateway/displ.h @@ -0,0 +1,18 @@ + +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 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 + * + */ +#ifndef __DISPL_H__ +#define __DISPL_H__ + +void displ(double *a, int ma, int na, int *b, int mb, int nb, char *c, int mc, int nc); + +#endif /* __DISPL_H__ */
\ No newline at end of file diff --git a/modules/dynamic_link/examples/gateway/example_gateway.sce b/modules/dynamic_link/examples/gateway/example_gateway.sce new file mode 100755 index 000000000..d9cf76ead --- /dev/null +++ b/modules/dynamic_link/examples/gateway/example_gateway.sce @@ -0,0 +1,20 @@ + + +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 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 + +exec(SCI+"/modules/dynamic_link/examples/gateway/builder.sce"); +exec(SCI+"/modules/dynamic_link/examples/gateway/loader.sce"); + +A=ones(2,2);B=ones(2,2); +C=matmul(A,B); +if norm(A*B-matmul(A,B)) > %eps then pause,end + +D="test string"; +view(A,C,D);
\ No newline at end of file diff --git a/modules/dynamic_link/examples/gateway/matmul.c b/modules/dynamic_link/examples/gateway/matmul.c new file mode 100755 index 000000000..1588fa609 --- /dev/null +++ b/modules/dynamic_link/examples/gateway/matmul.c @@ -0,0 +1,35 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA - + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + */ +#include "matmul.h" + +/*-------------------------------------------------------- + * Matrix multiplication C= A*B, (A,B,C stored columnwise) + * C function + *--------------------------------------------------------*/ + +#define A(i,k) a[i + k*n] +#define B(k,j) b[k + j*m] +#define C(i,j) c[i + j*n] + +void matmul(double a[], int n, int m, double b[], int l, double c[]) +{ + int i = 0, j = 0, k = 0; + double s = 0.0; + + for ( i = 0 ; i < n; i++) + { + for ( j = 0; j < l; j++) + { + s = 0.; + for ( k = 0; k < m; k++) + { + s += A(i, k) * B(k, j); + } + C(i, j) = s; + } + } +} diff --git a/modules/dynamic_link/examples/gateway/matmul.h b/modules/dynamic_link/examples/gateway/matmul.h new file mode 100755 index 000000000..5fb1f4796 --- /dev/null +++ b/modules/dynamic_link/examples/gateway/matmul.h @@ -0,0 +1,18 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA - + * + * 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 __MATMUL_H__ +#define __MATMUL_H__ + +void matmul(double a[], int n, int m, double b[], int l, double c[]); + +#endif /* __MATMUL_H__ */ + diff --git a/modules/dynamic_link/examples/gateway/sci_matmul.c b/modules/dynamic_link/examples/gateway/sci_matmul.c new file mode 100755 index 000000000..d1d587420 --- /dev/null +++ b/modules/dynamic_link/examples/gateway/sci_matmul.c @@ -0,0 +1,44 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA - + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + */ +#include "matmul.h" + +#include "stack-c.h" + +#include "sciprint.h" + +int sci_matmul(char *fname) +{ + static int l1, m1, n1, l2, m2, n2, l3; + static int minlhs = 1, maxlhs = 1, minrhs = 2, maxrhs = 2; + + /* Check number of inputs (rhs=2) and outputs (lhs=1) */ + CheckRhs(minrhs, maxrhs) ; + CheckLhs(minlhs, maxlhs) ; + + /* Get A (#1) and B (#2) and create C (#3) as double ("d") matrices */ + GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l1); /* m1, n1 (and l1) are output parameters */ + GetRhsVar(2, MATRIX_OF_DOUBLE_DATATYPE, &m2, &n2, &l2); /* m1, n1 (and l1) are output parameters */ + CreateVar(3, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n2, &l3); /* m1 and n2 are input parameters */ + + /* Check dimensions */ + if (!(n1 == m2)) + { + sciprint("%s: Incompatible inputs\n", "matmul"); + SciError(999); + return 0; + } + + /* Call multiplication function + * inputs:stk(l1)->A, stk(l2)->B + * output:stk(l3)->C + */ + matmul(stk(l1), m1, n1, stk(l2), n2, stk(l3)); + + /* Return C (3) */ + LhsVar(1) = 3; + return 0; +} diff --git a/modules/dynamic_link/examples/gateway/sci_view.c b/modules/dynamic_link/examples/gateway/sci_view.c new file mode 100755 index 000000000..b2483ffcc --- /dev/null +++ b/modules/dynamic_link/examples/gateway/sci_view.c @@ -0,0 +1,34 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) INRIA - + * + * This file is released under the 3-clause BSD license. See COPYING-BSD. + */ + +#include "displ.h" +#include "stack-c.h" + +int sci_view(char *fname) +{ + static int l1, m1, n1, l2, m2, n2, m3, n3, l3; + static int minlhs = 1, maxlhs = 3, minrhs = 3, maxrhs = 3; + + /* Check number of inputs (rhs=3) and outputs (lhs=3) */ + CheckRhs(minrhs, maxrhs) ; + CheckLhs(minlhs, maxlhs) ; + + /* Get X (1 ,double), Y (2, int) and C (3, string) */ + GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l1); + GetRhsVar(2, MATRIX_OF_INTEGER_DATATYPE, &m2, &n2, &l2); + GetRhsVar(3, STRING_DATATYPE, &m3, &n3, &l3); + + /* Call display function + stk(l1)->X (double), istk(l2)->Y (int), cstk(l3)->Z (char) */ + displ(stk(l1), m1, n1, istk(l2), m2, n2, cstk(l3), m3, n3); + + /* Return variables */ + LhsVar(1) = 1; + LhsVar(2) = 2; + LhsVar(3) = 3; + return 0; +} diff --git a/modules/dynamic_link/examples/interfaces/README b/modules/dynamic_link/examples/interfaces/README new file mode 100755 index 000000000..6313285a0 --- /dev/null +++ b/modules/dynamic_link/examples/interfaces/README @@ -0,0 +1,3 @@ +Old examples have been removed. +See api_scilab for the recommanded API or call_scilab for named functions. + |