call - Fortran or C user routines call
Interactive call of Fortran (or C) user program from Scilab. The routine must be previously linked with Scilab. This link may be done:
There are two forms of calling syntax, a short one and a long one. The short one will give faster code and an easier calling syntax but one has to write a small (C or Fortran) interface in order to make the short form possible. The long one make it possible to call a Fortran routine (or a C one) whitout modification of the code but the syntax is more complex and the interpreted code slower.
The meaning of each parameter is described now:
If an output variable coincides with an input variable (i.e. pyi=pxj ) one can pass only its position pyi . The size and type of yi are then the same as those of xi . If an output variable coincides with an input variable and one specify the dimensions of the output variable [myl,nyl] must follow the compatibility condition mxk*nxk >= myl*nyl .
In the case of short syntax , [y1,....,yk]=call("ident",x1,...,xn) , the input parameters xi 's and the name "ident" are sent to the interface routine Ex-fort . This interface routine is then very similar to an interface (see the source code in the directory SCIDIR/default/Ex-fort.f ).
//Example 1 with a simple C code f1=['#include <math.h>' 'void fooc(c,a,b,m,n)' 'double a[],*b,c[];' 'int *m,*n;' '{' ' int i;' ' for ( i =0 ; i < (*m)*(*n) ; i++) ' ' c[i] = sin(a[i]) + *b; ' '}']; mputl(f1,'fooc.c') //creating the shared library (a gateway, a Makefile and a loader are //generated. ilib_for_link('fooc','fooc.o',[],"c") // load the shared library exec loader.sce //using the new primitive a=[1,2,3;4,5,6];b= %pi; [m,n]=size(a); // Inputs: // a is in position 2 and double // b 3 double // n 4 integer // m 5 integer // Outputs: // c is in position 1 and double with size [m,n] c=call("fooc",a,2,"d",b,3,"d",m,4,"i",n,5,"i","out",[m,n],1,"d"); //Example 2 with a simple Fortran code f1=[' subroutine foof(c,a,b,n,m)' ' integer n,m' ' double precision a(*),b,c(*)' ' do 10 i=1,m*n ' ' c(i) = sin(a(i))+b' ' 10 continue' ' end']; mputl(f1,'foof.f') //creating the shared library (a gateway, a Makefile and a loader are //generated. ilib_for_link('foof','foof.o',[],"f") // load the shared library exec loader.sce //using the new primitive a=[1,2,3;4,5,6];b= %pi; [m,n]=size(a); c=call("foof",a,2,"d",b,3,"d",m,4,"i",n,5,"i","out",[m,n],1,"d");