! Exact solution of 2-Body Problem:
! x = cos(u)-e
! y = sqrt(1-e**2)*sin(u)
! x'=-sin(u)/(1-e*cos(u))
! y'= sqrt(1=e**2)*cos(u)/(1-e*cos(u))
! "u" is given by: u-e*sin(u) =t
!
subroutine exact(t, icall)
use work
implicit real(8) (a-h, o-z)
real(8) xExact(ngl), xPrimeExact(ngl)

! Solve for "u" - by iteration:
!Define u =g(u):
gg(uu, e, t) =e*sin(uu) +t

!epsu =1D-13
epsu =1D-15
nlim =1000

uu0 =0.
iter =0
do while (iter <=nlim)
iter =iter +1
uu1 =gg(uu0,e,t)
dif =uu1 -uu0
	if(dabs(dif) <=epsu) then
!	write(1,'(/, a, I3, 3x, a, 1pD10.3, a)')  '(iter:', iter,'dif=', dif,')'
	exit
	else
	uu0 =uu1
	endif
end do

uu =uu1
! Compute the solution
ee =dsqrt(1-e**2)
uExact(1) = dcos(uu)-e			!x
uExact(2) = ee*dsin(uu)			!y
uPrimeExact(1)=-dsin(uu)/(1-e*dcos(uu))	!x'
uPrimeExact(2) = ee*dcos(uu)/(1-e*dcos(uu))	!y'

end subroutine exact
