Program T_svdFMM

! Test procedury svd z LinalgFMM
! Procedura svd z LinalgFMM pouzivava JINY ALGORITMUS (Golub and Reinsch)
! nez procedura svd z modulu LinEqu
! Porovnejte ortogonalni matice U,V z obou procedur (mohou byt odlisne)
! a singularni cisla (musi byt v mezich zaokrouhlovacich chyb shodna 
! Uprava pro VV ver 2.2


use std_type
use VstupVystup
use LinalgFMM

implicit none

integer :: radku,sloupcu
real(Kind=SP),dimension(:,:),allocatable :: A,U,V
character(len=20) :: FmtRetez
real(kind=SP),dimension(:),allocatable :: w
integer :: ierr

call cti_cislo("Pocet radku = ",radku)
call cti_cislo("Pocet sloupcu = ",sloupcu)
allocate(A(radku,sloupcu))
Allocate(U(radku,radku))
Allocate(V(sloupcu,sloupcu))
allocate(w(sloupcu))

print *, "Zadej matici A po radcich"
call cti_matici(radku,sloupcu,A)

print *
Print *,"Zadana matice A:"
FmtRetez = "(f10.3)"
call pis_matici(A,FmtRetez)

call Svd(A,w,.true.,U,.true.,V,ierr)

print *,char(10)//"Singularni cisla z Svd:"
FmtRetez = "(es12.4e2)"
call pis_vektor(w,FmtRetez,.true.)

print *,char(10)//"Matice U z Svd:"
FmtRetez = "(f12.4)"
call pis_matici(U,FmtRetez)

print *,char(10)//"Matice V z Svd:"
FmtRetez = "(f12.4)"
call pis_matici(V,FmtRetez)

Print *,char(10),"Kontrola ortogonality U: U_tran*U=I ?"
call pis_matici(MatMul(transpose(U),U),FmtRetez)

Print *,char(10),"Kontrola ortogonality V: V_tran*V=I ?"
call pis_matici(MatMul(transpose(V),V),FmtRetez)


print *,char(10),"Pro ukonceni zadej ENTER "
read *

end program T_svdFMM
