next up previous
Next: Matrix concatenation Up: Scilab to Fortran translator Previous: Scilab to Fortran translator

Clauses, loops and operations

Source code of Scilab function

function x=t1(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']

Translation procedure

-->lt1=list();
-->lt1(1)=list('1','m','m');
-->lt1(2)=list('1','m','m');
-->lt1(3)=list('0','1','1');

-->// show the initial data
-->printspecs(t1,lt1)

Type and dimension of input parameters:
--------------------------------------
| variable number    | fortran type    |# rows     |# columns    |
|1                   |double precision |m          |m            |
|2                   |double precision |m          |m            |
|3                   |entier           |1          |1            |
-->//translate
-->txt=sci2for(t1,'t1',lt1);
Generated Fortran code:

       subroutine t1(a,b,n,x,m,work)
c!
c automatic translation
c
c!     calling sequence
c      ----------------
c
c      a          : double precision variable of size m,m
c      b          : double precision variable of size m,m
c      n          : integer variable
c      x          : double precision variable of size m+m,m+m
c      m          : integer variable
c      work  : working array :
c              max(m*m,m*m+m*m+m*m)+m*m
c      iwork : working array :3
c
c      dimension of local variables
c      -----------------------------
c!
       double precision a(m,m),b(m,m),x(m+m,m+m),y,t(m,m),z1,t(m,m),work
     & (*)
       integer n,m,z,c(2,2),sel(5),k,iwork(3)
c
c      adress of local variables
       iwt = 1
c
       iw0 = iwt+m*m
       iiw0 = 1
c
       z = n+m+n
c
       c(1,1)=n+m+n
c
       c(2,1)=n+m+n+1
c
       c(1,2)=2
c
       c(2,2)=0
c
       if(n.eq.1) then
c
          iw1 = iw0+m*m
          call dcopy(m*m,a,1,work(iw0),1)
          call dadd(m*m,work(iw0),1,b,1)
          call dcopy(m*m,work(iw0),1,x,1)
          call dadd(m*m,x,1,a,1)
c
       else
c
          iw1 = iw0+m*m
          call dcopy(m*m,a,1,work(iw0),1)
          call dadd(m*m,work(iw0),1,b,1)
          iw2 = iw1+m*m
          call mtran(a,m,work(iw1),m,m,m)
          iw3 = iw2+m*m
          call ddif(m*m,work(iw0),1,work(iw1),1,work(iw2),1)
          call dcopy(m*m,work(iw2),1,x,1)
          call dadd(m*m,x,1,b,1)
c
       endif
c
       y = a(3,n+m+n+1)-x(n+m+n,5)
c
       iw1 = iw0+m*m
       call dcopy(m*m,x,1,work(iw0),1)
       call dscal(m*m,2D0,work(iw0),1)
       iw2 = iw1+m*m
       call dmmul(work(iw0),m,x,m,work(iw1),m,m,m,m)
       call dcopy(m*m,work(iw1),1,x,1)
       call dscal(m*m,2.21,x,1)
c
       call ivimp(1,5,1,sel)
c
       call dmmul(a,m,b,m,work(iwt),m,m,m,m)
c
       do 20     k = 1,n
c
          z1 = dble(n+m+n)*a(k+1,k)+3
c
20    continue
c
       iiw1 = iiw0+3
       call ivimp(2,4,1,iwork(iiw0))
       iw1 = iw0+3
       call dmext(a,m,m,iwork(iiw0),3,7,1,work(iw0))
       call dmins(work(iwt),m,m,sel,5,5,1,work(iw0),3)
c
       iw1 = iw0+m*m
       call mtran(b,m,work(iw0),m,m,m)
       iw1 = iw0+m*m
       call mtran(b,m,work(iw0),m,m,m)
       call dscal(m*m,-1.0d0,work(iw0),1)
       call mtran(a,m,work(iw0),m,m,m)
       call dmcopy(a,m,x(1,1),m+m,m,m)
       call dmcopy(b,m,x(1,m+1),m+m,m,m)
       call dmcopy(work(iw0),m,x(m+1,1),m+m,m,m)
       call dmcopy(work(iw0),m,x(m+1,m+1),m+m,m,m)
c
       return
c
       end


Scilab group