next up previous contents index
Next: 6.2.2 Example Up: 6.2 Interface programs Previous: 6.2 Interface programs

6.2.1 Building an interface program

Examples of interface programs are given in the directory examples/addinter-examples.

The two files template.c and template.f are skeletons of interface programs.

The interface programs use a set of C or Fortran routines which should be used to build the interface program. The simplest way to learn how to build an interface program is to customize the previous skeletons files and to look at the examples provided in this directory. An interface program defines a set of Scilab functions and the calls to the corresponding numerical programs. Note that a unique interface program can be used to interface an arbitrary (but less that 99) number of functions.

The functions used to build an interface are Fortran subroutines when the interface is written in Fortran and are coded as C macros (defined in stack-c.h ) when the interface is coded in C. The main functions are as follows:

Once the variables have been processed by GetRhsVar or created by CreateVar, they are given values by calling one or several numerical routine. The call to the numerical routine is done in such a way that each argument of the routine points to the corresponding Scilab variable (see example below). Character, integer, real, double type variables are in the cstk (resp. istk, sstk, stk) Scilab internal stack at the adresses lk's returned by GetRhsVar or CreateVar.

Then they are returned to Scilab as lhs variables (this is done by function PutLhsVar). The interface should define how the lhs (output) variables are numbered. This is done by the global variable LhsVar. For instance

  LhsVar(1) = 5;
  LhsVar(2) = 3;
  LhsVar(3) = 1;
  LhsVar(4) = 2;
  PutLhsVar();
means that the Scilab function has at most 4 output parameters which are variables numbered k= 5, k=3, k=1, k=2 respectively.

The functions sciprint(amessage) and Error(k) are used for managing messages and errors.

Other useful functions which can be used are the following.

The Fortran functions have the same syntax and return logical values.


next up previous contents index
Next: 6.2.2 Example Up: 6.2 Interface programs Previous: 6.2 Interface programs
Scilab Group