orbel_ehie.f 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ***********************************************************************
  2. c ORBEL_EHIE.F
  3. ***********************************************************************
  4. * PURPOSE: Solves Kepler's eqn. e is ecc. m is mean anomaly.
  5. *
  6. * Input:
  7. * e ==> eccentricity anomaly. (real scalar)
  8. * m ==> mean anomaly. (real scalar)
  9. * Returns:
  10. * orbel_ehybrid ==> eccentric anomaly. (real scalar)
  11. *
  12. * ALGORITHM: Use Danby's quartic for 3 iterations.
  13. * Eqn. is f(x) = x - e*sin(x+M). Note that
  14. * E = x + M. First guess is very good for e near 1.
  15. * Need to first get M between 0. and PI and use
  16. * symmetry to return right answer if M between PI and 2PI
  17. * REMARKS: Modifies M so that both E and M are in range (0,TWOPI)
  18. * AUTHOR: M. Duncan
  19. * DATE WRITTEN: May 25,1992.
  20. * REVISIONS:
  21. ***********************************************************************
  22. real*8 function orbel_ehie(e,m)
  23. include '../swift.inc'
  24. c... Inputs Only:
  25. real*8 e,m
  26. c... Internals:
  27. integer iflag,nper,niter,NMAX
  28. real*8 dx,x,sa,ca,esa,eca,f,fp
  29. parameter (NMAX = 3)
  30. c----
  31. c... Executable code
  32. c In this section, bring M into the range (0,TWOPI) and if
  33. c the result is greater than PI, solve for (TWOPI - M).
  34. iflag = 0
  35. nper = m/TWOPI
  36. m = m - nper*TWOPI
  37. if (m .lt. 0.d0) m = m + TWOPI
  38. if (m.gt.PI) then
  39. m = TWOPI - m
  40. iflag = 1
  41. endif
  42. c Make a first guess that works well for e near 1.
  43. x = (6.d0*m)**(1.d0/3.d0) - m
  44. niter =0
  45. c Iteration loop
  46. do niter =1,NMAX
  47. call orbel_scget(x + m,sa,ca)
  48. esa = e*sa
  49. eca = e*ca
  50. f = x - esa
  51. fp = 1.d0 -eca
  52. dx = -f/fp
  53. dx = -f/(fp + 0.5d0*dx*esa)
  54. dx = -f/(fp + 0.5d0*dx*(esa+0.3333333333333333d0*eca*dx))
  55. x = x + dx
  56. enddo
  57. orbel_ehie = m + x
  58. if (iflag.eq.1) then
  59. orbel_ehie = TWOPI - orbel_ehie
  60. m = TWOPI - m
  61. endif
  62. return
  63. end !orbel_ehie
  64. c------------------------------------------------------------------