      program vektorMatMat
      
      integer  L1, L2, n1,m1, n2,m2
      real  V1(10),V2(10), SPROD, MatVec(10)
      real  MA1(10,50),MA2(10,50),MM(10,50)
      integer i,j,k,fp
      real tmp

      open (unit=8,file="V2M2.dat",status="unknown")
      fp=8

c komentar
      call readline(fp)
 
c   vector
      read (8,*) L1
      call readvektor(V1,L1,fp)

      call  displayvektor(V1,L1)

      call readline(fp)   
      read (fp,*) L2
      call readvektor(V2,L2,fp)

      call displayvektor(V2,L2)

      call readline(fp) 
      read (fp,*) n1,m1
      call readmatrix(MA1,n1,m1,fp)
      
      call displaymatrix(MA1,n1,m1)

      call readline(fp) 
      read (fp,*) n2,m2
      call readmatrix(MA2,n2,m2,fp)
      
      call displaymatrix(MA2,n2,m2)

      close(fp)

c Calculate
      SPROD=0
      do i=1,L1
         SPROD=SPROD+V1(i)
      end do
      print *, "Skalarni produkt"
      print *, SPROD

      call multMatrixVector(MA1,V1,MatVec,n1,m1)
      print *, "Matrica x Vektor"
      call displayvektor(MatVec,n1)

c Pomnozi matrice
       print *, "Matrica x Matrica"
      call multMatrixMatrix(MA1,MA2,MM,n1,m1,n2,m2)
      
       call displaymatrix(MM,n1,m2);
      end program


      subroutine multMatrixVector(a,b,c,n,m)
      integer n,m
      real b(m),c(m)
      real a(n,m)

      do i=1,n
         c(i)=0.0
         do j=1,m
            c(i)=c(i)+a(i,j)*b(j)
         end do
      end do
      end

      subroutine multMatrixMatrix(MA1,MA2,MM,n1,m1,n2,m2)
      INTEGER n1,m1,m2,n2,i,j,k
      REAL MA1(n1,m1),MA2(n2,m2),MM(n1,m2)

      Do i=1,n1
         Do j=1,m2
            MM(i,j) = 0.0
            Do k=1,m1
               MM(i,j) = MM(i,j) + MA1(i,k)*MA2(k,j)
            End Do
         End Do
      End Do
      end
