!! Test procedur minF, BrentMin z modulu minFFMM
!!-------------------------------------------------

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_minFFMM

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

implicit none

real(FP) :: a,b,tol,z
integer :: neval,errCODE,maxIter,i
real(FP) ::MinX, MinF

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

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

!..............................................................................
print *,"Procedura Fmin"
print *,"----------------",char(10)
call cti_cislo("Hranice intervalu a = ",a)
call cti_cislo("Hranice intervalu b = ",b)

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

z = Fmin(a,b,F,tol)
print *,char(10)," MinX = ", z
print *,"minF = ",F(z)
print "(a,es10.3)","  Minimalni interval v okoli minima (spacing(z)) = ",&
					spacing(z)


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

print "(3a8,2a25)","errCode","maxIter","neval","MinX","minF"
do maxIter=2,25
	call BrentMin(a,b,F,tol,maxIter,neval,errCode,MinX,minF)
	print "(3i8,2es25.12)",errCode,maxIter,neval,MinX,minF
end do
print "(a,es12.3)","  Minimalni interval v okoli MinX (spacing(MinX)) = ",&
					spacing(MinX)


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

end program T_minFFMM