SCIDIR/examples/intersci-examples-so
contains
several examples for using intersci
which is a tool for
producing gateway routines from a descriptor file.
Let us describe a simple example, ex01
.
We want to build an interface for the following C function :
int ext1c(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); }This function just adds the two real vectors
a
and b
with n
entries and returns the result in c
.
We want to have in Scilab a function c=ext1c(a,b)
which
performs this operation by calling ext1c
.
For that, we provide a .desc
file, ex01fi.desc
:
ext1c a b a vector m b vector m c vector m ext1c m a b c m integer a double b double c double out sequence c ***********************This file in divided into three parts separated by a blank line. The upper part (four first lines) describes the Scilab function
c=ext1c(a,b)
.
Then (next five lines) the C function is described. The last line of
ex01fi.desc
gives the name of output variables.
To run intersci
with this file as input we enter the command :
SCIDIR/bin/intersci-n ex01fiTwo files are created :
ex01fi.c
and ex01fi_builder.sce
.
The file ex01fi.c
is the C gateway function needed for interfacing
ext1c
with Scilab. It is a gateway file built as explained above
(see 6.2.2) :
#include "stack-c.h" int intsext1c(fname) char *fname; { int m1,n1,l1,mn1,m2,n2,l2,mn2,un=1,mn3,l3; CheckRhs(2,2); CheckLhs(1,1); /* checking variable a */ GetRhsVar(1,"d",&m1,&n1,&l1); CheckVector(1,m1,n1); mn1=m1*n1; /* checking variable b */ GetRhsVar(2,"d",&m2,&n2,&l2); CheckVector(2,m2,n2); mn2=m2*n2; /* cross variable size checking */ CheckDimProp(1,2,m1*n1 != m2*n2); CreateVar(3,"d",(un=1,&un),(mn3=mn1,&mn3),&l3);/* named: c */ C2F(ext1c)(&mn1,stk(l1),stk(l2),stk(l3)); LhsVar(1)= 3; return 0; }
The file ex01fi_builder.sce
is the following :
// generated with intersci ilib_name = 'libex01fi' // interface library name table =["ext1c","intsext1c"]; ilib_build(ilib_name,table,files,libs);
This builder file is to be executed
by Scilab after the variables files
and libs
have been set :
-->files = ['ex01fi.o' , 'ex01c.o']; -->libs = [] ; -->exec ex01fi_builder.sce
A dynamic library is then created as well as a file loader.sce
.
Executing loader.sce
loads the library into Scilab and executes the
addinter
command to link the library and associate the name
of the function ext1c
to it. We can then call the new function ;
-->exec loader.sce -->a=[1,2,3];b=[4,5,6]; c=ext1c(a,b);
To use intersci
one has to construct a .desc
file.
The keywords which describe the Scilab function and the function
to be called can be found in the examples given.