program test_lib
use fi_int
use smc_int
use smc_tools
use ponte_f_f, only:wout, debug, verb
implicit none
real(kind(0.d0)),dimension(:,:,:),allocatable:: a
real(kind(0.d0)),dimension(:,:),allocatable:: g,x0
integer :: i,j,m,itermax,method
logical :: ds
real(kind(0.d0)):: drift, norm1,myeps, s

debug=.false.
!debug=.true.
verb=.true.
!verb=.false.

 open(file='Examples/usedA',unit=2)
read(2,*)m
read(2,*)m,m
allocate(a(m,m,3),g(m,m),x0(m,m))
A(:,:,1)=0.d0
A(:,:,2)=0.d0
A(:,:,3)=0.d0
 read(2,*) A(:,:,1)
read(2,*)m,m
 read(2,*) A(:,:,2)
read(2,*)m,m
 read(2,*) A(:,:,3)
!do j=1,m
!   do i=1,m
!         read(2,*) A(:,:,1)
!   end do
!end do
!do j=1,m
!   do i=1,m
!         read(2,*) A(i,j,2)
 !  end do
!end do
!do j=1,m
!   do i=1,m
!         read(2,*) A(i,j,3)
!   end do
!end do


! normalization
!G=A(:,:,1)+A(:,:,2)+A(:,:,3)
!do i=1,m
!s=sum(G(i,:))

!A(i,:,1)=A(i,:,1)/s
!A(i,:,2)=A(i,:,2)/s
!A(i,:,3)=A(i,:,3)/s
!end do

x0=0.d0
ds=.false.
method = 1
myeps=1.e-12
itermax = 1000


call fi(A=A, doshift=ds, method=method, eps=myeps, maxit=itermax, x0=X0, G=G, &
drift=drift, err=norm1)

write(*,*)"drift=",drift,"error=",norm1

do i=1,m
  do j=1,m
  write(*,*) "G(",i,j,")=",G(i,j)
  end do
end do

end program test_lib

