! Predictor-Corector: ADAMS explicit-implicit, ordinul 5.
! Pas h = constant
! Predictor:
! x#(i+1) =x#i +(h/720)*( 1901f#i -2774f#(i-1) +2616f#(i-2) -1274f#(i-3)+251f#(i-4) )
! Corector:
! x#(i+1) =x#i +(h/720)*( 251f#(i+1) +646f#i -264f#(i-1) +106f#(i-2)-19f#(i-3) )
! 1 iteratie: TOL <= 0

subroutine Adams5(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*(1901*fa(0,:) -2774*fa(-1,:) +2616*fa(-2,:) -1274*fa(-3,:)+251*fa(-4,:))/720

! 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*( 251*fa(1,:) +646*fa(0,:) -264*fa(-1,:) +106*fa(-2,:) -19*fa(-3,:) )/720

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 Adams5
