next up previous
Next: Operation with complex numbers Up: Scilab to Fortran translator Previous: Concatenations and inversions

Call of simple primitives

Source code of Scilab function

function x=t4(a,n)
[lhs,rhs]=argn(0),
[m,n]=size(a),
if m==n then error('incorrect dimensions '),end,
x=sin(a),
u=norm(x),
if u==%eps then x=x/u,end,

Translation procedure

-->lt4=list();
-->lt4(1)=list('1','m1','n1');

-->// show the initial data
-->printspecs(t4,lt4)
type and dimension of input parameters
---------------------------------------
| variable number    | fortran type    |# rows     |# columns    |
|1                   |double precision |m1         |n1           |
-->//translate
-->txt=sci2for(t4,'t4',lt4);
Generated Fortran code
       subroutine t4(a,x,m1,n1,work,ierr)
c!
c automatic translation
c
c!     calling sequence
c      ----------------
c
c      a          : double precision variable of size m1,n1
c      x          : double precision variable of size m1,n1
c      m1         : integer variable
c      n1         : integer variable
c      work  : working array :
c              max(min(m1+1,n1)+n1+m1, )
c      ierr : error
c             0 :  correct run
c             1 : incorrect dimensions
c             2 : echec du calcul de la norme
c!
       double precision a(m1,n1),x(m1,n1),u,%eps,d1mach,work(*)
       integer m1,n1,rhs,lhs,n,m
c
       iw0 = 1
       %eps = d1mach(4)
c
c
       rhs = 1
       lhs = 1
c
       n = m1
       m = n1
c
       if(n1.eq.m1) then
          ierr=1
          return
       endif
c
       do 30 ilb30 = 0,n1-1
          do 20 ilb20 = 0,m1-1
             a(ilb20,ilb30) = sin(a(ilb20,ilb30))
20     continue
30     continue
c
       iw1 = iw0+min(m1+1,n1)
       iw2 = iw1+n1
       iw3 = iw2+m1
       call dsvdc(x,m1,m1,n1,work(iw0),work(iw1),work,m1,work,n1,work(iw
     & 2),00,ierr)
       if(ierr.ne.0) then
          ierr=2
          return
       endif
       u = work(iw0)
c
       if(work(iw0).eq.%eps) then
          call dscal(m1*n1,1.0d0/work(iw0),x,1)
       endif
c
       return
c
       end


Scilab group