diff options
Diffstat (limited to 'map65/libm65/coord.f90')
| -rw-r--r-- | map65/libm65/coord.f90 | 102 |
1 files changed, 62 insertions, 40 deletions
diff --git a/map65/libm65/coord.f90 b/map65/libm65/coord.f90 index 8934b612..62bd9a42 100644 --- a/map65/libm65/coord.f90 +++ b/map65/libm65/coord.f90 @@ -1,40 +1,62 @@ -SUBROUTINE COORD(A0,B0,AP,BP,A1,B1,A2,B2) - -! Examples: -! 1. From ha,dec to az,el: -! call coord(pi,pio2-lat,0.,lat,ha,dec,az,el) -! 2. From az,el to ha,dec: -! call coord(pi,pio2-lat,0.,lat,az,el,ha,dec) -! 3. From ra,dec to l,b -! call coord(4.635594495,-0.504691042,3.355395488,0.478220215, -! ra,dec,l,b) -! 4. From l,b to ra,dec -! call coord(1.705981071d0,-1.050357016d0,2.146800277d0, -! 0.478220215d0,l,b,ra,dec) -! 5. From ra,dec to ecliptic latitude (eb) and longitude (el): -! call coord(0.d0,0.d0,-pio2,pio2-23.443*pi/180,ra,dec,el,eb) -! 6. From ecliptic latitude (eb) and longitude (el) to ra,dec: -! call coord(0.d0,0.d0,-pio2,pio2-23.443*pi/180,el,eb,ra,dec) - - SB0=sin(B0) - CB0=cos(B0) - SBP=sin(BP) - CBP=cos(BP) - SB1=sin(B1) - CB1=cos(B1) - SB2=SBP*SB1 + CBP*CB1*cos(AP-A1) - CB2=SQRT(1.e0-SB2**2) - B2=atan(SB2/CB2) - SAA=sin(AP-A1)*CB1/CB2 - CAA=(SB1-SB2*SBP)/(CB2*CBP) - CBB=SB0/CBP - SBB=sin(AP-A0)*CB0 - SA2=SAA*CBB-CAA*SBB - CA2=CAA*CBB+SAA*SBB - TA2O2=0.0 !Shut up compiler warnings. -db - IF(CA2.LE.0.e0) TA2O2=(1.e0-CA2)/SA2 - IF(CA2.GT.0.e0) TA2O2=SA2/(1.e0+CA2) - A2=2.e0*atan(TA2O2) - IF(A2.LT.0.e0) A2=A2+6.2831853 - RETURN -END SUBROUTINE COORD +module coord_mod + implicit none +contains + +subroutine coord(A0, B0, AP, BP, A1, B1, A2, B2) + use iso_fortran_env, only: real32, real64 + implicit none + + !-------------------------------------------------------------------- + ! Arguments (all double precision) + !-------------------------------------------------------------------- + real(real32), intent(in) :: A0, B0, AP, BP + real(real32), intent(in) :: A1, B1 + real(real32), intent(out) :: A2, B2 + + !-------------------------------------------------------------------- + ! Locals + !-------------------------------------------------------------------- + real(real64) :: SB0, CB0, SBP, CBP, SB1, CB1 + real(real64) :: SB2, CB2, SAA, CAA, CBB, SBB + real(real64) :: SA2, CA2, TA2O2 + + !-------------------------------------------------------------------- + ! Compute sines and cosines + !-------------------------------------------------------------------- + SB0 = sin(B0) + CB0 = cos(B0) + SBP = sin(BP) + CBP = cos(BP) + SB1 = sin(B1) + CB1 = cos(B1) + + !-------------------------------------------------------------------- + ! Core spherical rotation + !-------------------------------------------------------------------- + SB2 = SBP*SB1 + CBP*CB1*cos(AP - A1) + CB2 = sqrt(1.0d0 - SB2**2) + B2 = atan(SB2 / CB2) + + SAA = sin(AP - A1) * CB1 / CB2 + CAA = (SB1 - SB2*SBP) / (CB2*CBP) + + CBB = SB0 / CBP + SBB = sin(AP - A0) * CB0 + + SA2 = SAA*CBB - CAA*SBB + CA2 = CAA*CBB + SAA*SBB + + !-------------------------------------------------------------------- + ! atan2-like reconstruction using stable formula + !-------------------------------------------------------------------- + TA2O2 = 0.0d0 + if (CA2 <= 0.0d0) TA2O2 = (1.0d0 - CA2) / SA2 + if (CA2 > 0.0d0) TA2O2 = SA2 / (1.0d0 + CA2) + + A2 = 2.0d0 * atan(TA2O2) + + if (A2 < 0.0d0) A2 = A2 + 6.2831853071795864d0 + +end subroutine coord + +end module coord_mod |
