!! Test procedur Zeroin, BrentZero z modulu rootFMM
!!-------------------------------------------------

module Funkce

implicit none

integer,parameter :: SP = selected_real_kind(4)
integer,parameter :: DP = selected_real_kind(8)

	! Zde je mozne nastavit single(FP=SP)|double(FP=DP)
integer,parameter,public :: FP = DP 	! pouzije se i v T_rootFMM

contains

function F(x) result(g)
	real(FP),intent(in) :: x
	real(FP) :: g
	g = x*(x*x-2)-5
end function F

end module Funkce

! ------------------------- program -------------------------------------------

program T_rootFMM

use Funkce			! zavadi FP = SP | DP a funkci F(x) 
use VstupVystup
use rootFMM

implicit none

real(FP) :: a,b,tol,z
integer :: neval,errCODE,maxIter,i
real(FP) ::xZero, fZero

!..............................................................................

Print *,"Realna cisla na ",FP,"byte"		! zadane v modulu Funkce
print *,"-----------------------",char(10)

!..............................................................................
print *,"Procedura Zeroin"
print *,"----------------",char(10)
do
	call cti_cislo("Hranice intervalu a = ",a)
	call cti_cislo("Hranice intervalu b = ",b)
	if (F(a)*F(b)<0) exit
	print *,"F(a)*F(b)>=0, ZADEJ ZNOVU!"
end do	

call cti_cislo("Zadej interval tol  = ",tol)

z = Zeroin(a,b,F,tol)
print *,char(10)," Koren = ", z
print *,"fZero = ",F(z)
print "(a,es12.3)","  Minimalni interval v okoli korene (spacing(z)) = ",&
					spacing(z)


! ............................................................................
Print *,char(10)," Procedura BrentZero"
print *,"-------------------",char(10)

print "(2a10,2a30)","errCode","maxIter","xZero","fZero"
do maxIter=2,25
	call BrentZero(a,b,F,tol,maxIter,neval,errCode,xZero,fZero)
	print "(2i10,2es30.12)",errCode,maxIter,xZero,fZero
end do
print "(a,es12.3)","  Minimalni interval v okoli xZero (spacing(xZero)) = ",&
					spacing(xzero)


print *,char(10),"ENTER = konec"
read *

end program T_rootFMM