!! File  : test_lu.f90
!!
!! Creation Date: 31.10.2015; Time: 10:00
!! Time-stamp: <2015-11-01 20:07:29 (andrzejbaran)> 
!!
!! Andrzej Baran
!! IF UMCS, ul. Radziszewskiego 10, 20-031 Lublin, PL
!! baran@kft.umcs.lublin.pl
!!
program test_matinv
  USE LU
  IMPLICIT NONE
  integer, parameter   :: n = 4
  real, dimension(n,n) :: A, B, X
  integer              :: INDX(n)
  integer              :: i, j, flag, d

  data &
       A/ &
       8.000000,  2.000000,  3.000000,  12.00000, &
       2.000000,  4.000000,  7.000000,  0.250000, &
       3.000000,  7.000000,  3.000000,  5.000000, &
       12.00000,  0.250000,  5.000000,  2.000000/ 

  ! Macierz odwrotna: A^-1
  !   -0.040155 -0.085788  0.056557  0.110262
  !   -0.085788 -0.062018  0.202201  0.016978
  !    0.056557  0.202201 -0.130316 -0.038826
  !    0.110262  0.016978 -0.038826 -0.066631

  B = A
  ! Odwracanie A - macierz n x n;
  call matinv(B,n,n,flag)

  ! Wydruk wyników

  write(*,*) "Macierz A"
  do i=1, n 
     write(*,200) (A(i,j),j=1,n)
  end do

  if (flag.ne.0) then

     write(*,*) 'Macierz jest osobliwa!'
     stop

  else

     write(*,*) "Macierz odwrotna"
     do i=1, n 
        write(*,200) (B(i,j),j=1,n)
     end do

     write(*,*) "Sprawdzamy czy a . a^(-1) = I?"
     B = matmul(A,B)
     do i=1, n 
        write(*,200) (B(i,j),j=1,n)
     end do

  end if

200 format(8F10.6)

END program test_matinv
