module global

TYPE matrix(real_kind, m, n)
    INTEGER, KIND :: real_kind
    integer, len  :: m, n
    REAL(real_kind), dimension(m,n) :: element
END TYPE matrix

end module

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

program ringleb_flow

integer :: q, w

read (*,*) q, w

call indat(q, w)

end program

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

subroutine indat(q, w)

use global

integer :: i, j, q, w
type( matrix(kind(0.0), q, w) ) :: a, b
!type( matrix(kind(0.0), w, q) ) :: b
type( matrix(kind(0.0), q, q) ) :: x
type( matrix(kind(0.0), w, w) ) :: y

print *, q, w

do concurrent (i=1:q, j=1:w)
    a%element(i,j) = 100*i+j
    b%element(j,i) = q*(j-1)+i
enddo
x%element(:,:) = transpose( matmul(a%element(:,:), b%element(:,:)) )
y%element(:,:) = transpose( matmul(b%element(:,:), a%element(:,:)) )

do i=1, q
    print *, a%element(i,:)
enddo

print *

do i=1, w
    print *, b%element(:,i)
enddo

print *

do i=1, q
    print *, matmul(a%element(i,:), b%element(:,:)) - x%element(:,i)
    !print *, x%element(:,i)
enddo

print *

do i=1, w
    print *, matmul(b%element(i,:), a%element(:,:)) - y%element(:,i)
    !print *, y%element(:,i)
enddo

end subroutine
