next up previous
Next: Concatenations and inversions Up: Scilab to Fortran translator Previous: Clauses, loops and operations

Matrix concatenation

Source code of Scilab function:

function x=t2(a,b,c,d)
z=[a b b],
y=[a;c;c],
x=[a b;c d]*3.5

Translation procedure

-->lt2=list();
-->lt2(1)=list('1','m1','n1');
-->lt2(2)=list('1','m1','n2');
-->lt2(3)=list('1','m2','n1');
-->lt2(4)=list('1','m2','n2');

-->// show the initial data
-->printspecs(t2,lt2)
type and dimension of input parameters
---------------------------------------
| variable number    | fortran type    |# rows     |# columns    |
|1                   |double precision |m1         |n1           |
|2                   |double precision |m1         |n2           |
|3                   |double precision |m2         |n1           |
|4                   |double precision |m2         |n2           |

-->//translate
-->txt=sci2for(t2,'t2',lt2);

Generated Fortran code:

       subroutine t2(a,b,c,d,x,m1,n1,n2,m2,work)
c!
c automatic translation
c
c!     calling sequence
c      ----------------
c
c      a          : double precision variable of size m1,n1
c      b          : double precision variable of size m1,n2
c      c          : double precision variable of size m2,n1
c      d          : double precision variable of size m2,n2
c      x          : double precision variable of size m1+m2,n1+n2
c      m1         : integer variable
c      n1         : integer variable
c      n2         : integer variable
c      m2         : integer variable
c      work  : working array :
c              (m1+m2)*(n1+n2)+m1*(n1+n2+n2)+(m1+m2+m2)*n1
c
c      dimension of local variables
c      -----------------------------
c!
       double precision a(m1,n1),b(m1,n2),c(m2,n1),d(m2,n2),x(m1+m2,n1+n
     & 2),z(m1,n1+n2+n2),y(m1+m2+m2,n1),work(*)
       integer m1,n1,n2,m2
c
c      adress of local variables
       iwz = 1
       iwy = iwz+m1*(n1+n2+n2)
c
       iw0 = iwy+(m1+m2+m2)*n1
c
       call dmcopy(a,n1,work(iwz+1),m1,n1,m1)
       call dmcopy(b,n2,work(iwz+n1*m1+1),m1,n2,m1)
       call dmcopy(b,n2,work(iwz+(n2+n1)*m1+1),m1,n2,m1)
c
       call dmcopy(a,n1,work(iwy+1),m1+m2+m2,n1,m1)
       call dmcopy(c,n1,work(iwy+m1+1),m1+m2+m2,n1,m2)
       call dmcopy(c,n1,work(iwy+m2+m1+1),m1+m2+m2,n1,m2)
c
       iw1 = iw0+(m1+m2)*(n1+n2)
       call dmcopy(a,n1,work(iw0+1),m1+m2,n1,m1)
       call dmcopy(b,n2,work(iw0+n1*(m1+m2)+1),m1+m2,n2,m1)
       call dmcopy(c,n1,work(iw0+m1+1),m1+m2,n1,m2)
       call dmcopy(d,n2,work(iw0+n1*(m1+m2)+m1+1),m1+m2,n2,m2)
       call dcopy((m1+m2)*(n1+n2),work(iw0),1,x,1)
       call dscal((m1+m2)*(n1+n2),3.5,x,1)
c
       return
c
       end


Scilab group