orbel_scget.f 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. ***********************************************************************
  2. c ORBEL_SCGET.F
  3. ***********************************************************************
  4. * PURPOSE: Given an angle, efficiently compute sin and cos.
  5. *
  6. * Input:
  7. * angle ==> angle in radians (real scalar)
  8. *
  9. * Output:
  10. * sx ==> sin(angle) (real scalar)
  11. * cx ==> cos(angle) (real scalar)
  12. *
  13. * ALGORITHM: Obvious from the code
  14. * REMARKS: The HP 700 series won't return correct answers for sin
  15. * and cos if the angle is bigger than 3e7. We first reduce it
  16. * to the range [0,2pi) and use the sqrt rather than cos (it's faster)
  17. * BE SURE THE ANGLE IS IN RADIANS - NOT DEGREES!
  18. * AUTHOR: M. Duncan.
  19. * DATE WRITTEN: May 6, 1992.
  20. * REVISIONS:
  21. ***********************************************************************
  22. subroutine orbel_scget(angle,sx,cx)
  23. include '../swift.inc'
  24. c... Inputs Only:
  25. real*8 angle
  26. c... Output:
  27. real*8 sx,cx
  28. c... Internals:
  29. integer nper
  30. real*8 x
  31. real*8 PI3BY2
  32. parameter(PI3BY2 = 1.5d0*PI)
  33. c----
  34. c... Executable code
  35. nper = angle/TWOPI
  36. x = angle - nper*TWOPI
  37. if(x.lt.0.d0) then
  38. x = x + TWOPI
  39. endif
  40. sx = sin(x)
  41. cx= sqrt(1.d0 - sx*sx)
  42. if( (x .gt. PIBY2) .and. (x .lt.PI3BY2)) then
  43. cx = -cx
  44. endif
  45. return
  46. end ! orbel_scget
  47. c-------------------------------------------------------------------