! Predictor-Corector: ADAMS explicit-implicit, ordinul 4.
! Pas h = constant
! Predictor:
! x#(i+1) =x#i +(h/25)*( 55f#i -59f#(i-1) +37f#(i-2) -9f#(i-3) )
! Corector:
! x#(i+1) =x#i +(h/24)*( 9f#(i+1) +19f#i -5f#(i-1) +f#(i-2) )
! 1 iteratie: TOL <= 0

subroutine Adams4(t, TOL, iter)
use work
use DFLIB

implicit real(8) (a-h, o-z)
real(8) xEnd0(n), xEndAnt(n)
real(8) norm

! Predictor:
xEnd0 =x0 +h*( 55*fa(0,:) -59*fa(-1,:) +37*fa(-2,:) -9*fa(-3,:) )/24

! Iteratie in corector:
iter =0
xEndAnt =xEnd0

100 iter =iter+1
! Calculeaza fa(1) - in val. prezisa:
xEnd =xEndAnt
call derivs(t)
fa(1,:) =f(:)

! Corector:
xEnd =x0 +h*( 9*fa(1,:) +19*fa(0,:) -5*fa(-1,:) +fa(-2,:) )/24

if(TOL <=0 ) GOTO 200

if(norm(n, xEnd -xEndAnt) <= TOL .or. iter ==500) then
goto 200
else
xEndAnt =xEnd
goto 100
endif

! Iesire iteratie:
200 continue


END subroutine Adams4