next up previous contents index
Next: List of Figures Up: 9. Converting Scilab functions Previous: 9. Converting Scilab functions

9.1 Converting Scilab Functions to Fortran Routines

Scilab provides a compiler (under development) to transform some Scilab functions into Fortran subroutines. The routines which are thus obtained make use of the routines which are in the Fortran libraries. All the basic matrix operations are available.

Let us consider the following Scilab function:

function [x]=macr(a,b,n)
z=n+m+n,
c(1,1)=z,
c(2,1)=z+1,
c(1,2)=2,
c(2,2)=0,
if n=1 then,
 x=a+b+a,
else,
x=a+b-a'+b,
end,
y=a(3,z+1)-x(z,5),
x=2*x*x*2.21,
sel=1:5,
t=a*b,
for k=1:n,
 z1=z*a(k+1,k)+3,
end,
t(sel,5)=a(2:4,7),
x=[a b;-b' a']

which can be translated into Fortran by using the function mac2for. Each input parameter of the subroutine is described by a list which contains its type and its dimensions. Here, we have three input variables a,b,c which are, say, double precision, double precision, integer with dimensions (m,m), (m,m), (1,1). This information is gathered in the following list:

l=list();
l(1)=list('1','m','m');
l(2)=list('1','m','m');
l(3)=list('0','1','1');
The call to mac2for is made as follows:
comp(macr);
mac2for(macr2lst(macr),l)
The output of this command is a string containing a stand-alone Fortran subroutine.
       subroutine macr(a,b,n,x,m,work,iwork)
c!
c  automatic translation
.
.
.
       double precision a(m,m),b(m,m),x(m+m,m+m),y,z1,24(m,m),work(*)
       integer n,m,z,c(2,2),sel(5),k,iwork(*)
.
.
.      
       call dmcopy(b,m,x(1,m+1),m+m,m,m)
       call dmcopy(work(iw1),m,x(m+1,1),m+m,m,m)
       call dmcopy(work(iw1),m,x(m+1,m+1),m+m,m,m)
       return
c
       end
This routine can be linked to Scilab and interactively called.


next up previous contents index
Next: List of Figures Up: 9. Converting Scilab functions Previous: 9. Converting Scilab functions
Scilab Group