summaryrefslogtreecommitdiff
path: root/lib/ephem.f90
diff options
context:
space:
mode:
authorhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
committerhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
commitc25cbdf6fb6d946175f4335fab77bfea601b56db (patch)
tree6f7a94b7b81f999e434f61b73d47e337dfd26bf2 /lib/ephem.f90
parent71f5689252c9f13e70e1c24856904475b2307809 (diff)
parent0685fcada9f95fe90f70b387cd7d757da8209624 (diff)
Merge tag 'debian/3.2.0_rc1+dfsg-2' into debian/trixie-backportsdebian/trixie-backports
tagging wsjtx 3.2.0~rc1+dfsg-2
Diffstat (limited to 'lib/ephem.f90')
-rw-r--r--lib/ephem.f90213
1 files changed, 151 insertions, 62 deletions
diff --git a/lib/ephem.f90 b/lib/ephem.f90
index a24ddbd0..be5b711a 100644
--- a/lib/ephem.f90
+++ b/lib/ephem.f90
@@ -1,85 +1,174 @@
subroutine ephem(mjd0,dut,east_long,geodetic_lat,height,nspecial, &
- RA,Dec,Az,El,techo,dop,fspread_1GHz,vr)
+ RA,Dec,Az,El,techo,dop,fspread_1GHz,vr,ephemeris_result)
+ use ieee_arithmetic, only: ieee_is_finite
+ use jpl_ephemeris_status, only: JPL_STATUS_OK, EPHEMERIS_JPL, &
+ EPHEMERIS_ANALYTIC_FALLBACK, EPHEMERIS_UNAVAILABLE
implicit real*8 (a-h,o-z)
- real*8 jd !Time of observationa as a Julian Date
- real*8 mjd,mjd0 !Modified Julian Date
- real*8 prec(3,3) !Precession matrix, J2000 to Date
- real*8 rmatn(3,3) !Nutation matrix
- real*8 rme2000(6) !Vector from Earth center to Moon, JD2000
- real*8 rmeDate(6) !Vector from Earth center to Moon at Date
- real*8 rmeTrue(6) !Include nutation
- real*8 raeTrue(6) !Vector from Earth center to Obs at Date
- real*8 rmaTrue(6) !Vector from Obs to Moon at Date
- logical km,bary !Set km=.true. to get km, km/s from ephemeris
- common/stcomx/km,bary,pvsun(6) !Common used in JPL subroutines
+ real*8 jd
+ real*8 mjd,mjd0
+ real*8 prec(3,3)
+ real*8 rmatn(3,3)
+ real*8 rme2000(6,2)
+ real*8 rmeDate(6)
+ real*8 rmeTrue(6)
+ real*8 raeTrue(6)
+ real*8 rmaTrue(6)
+ real*8 djutc_sample(2),jd_sample(2),djtt_sample(2)
+ real*8, parameter :: max_lunar_position_km=1.d7
+ real*8, parameter :: max_lunar_velocity_km_s=100.d0
+ logical km,bary,jpl_available,use_jpl,derived_valid
+ integer ephemeris_result,jpl_status,attempt
+ common/stcomx/km,bary,pvsun(6)
common/librcom/xl(2),b(2)
- twopi=8.d0*atan(1.d0) !Define some constants
+ RA=0.d0
+ Dec=0.d0
+ Az=0.d0
+ El=0.d0
+ techo=0.d0
+ dop=0.d0
+ fspread_1GHz=0.d0
+ vr=0.d0
+ ephemeris_result=EPHEMERIS_UNAVAILABLE
+
+ twopi=8.d0*atan(1.d0)
rad=360.d0/twopi
clight=2.99792458d5
au2km=0.1495978706910000d9
- pi=0.5d0*twopi
- pio2=0.5d0*pi
km=.true.
freq=1000.0d6
+ jpl_available=nspecial.ne.8
do jj=1,2
mjd=mjd0
if(jj.eq.1) mjd=mjd - 1.d0/1440.d0
- djutc=mjd
- jd=2400000.5d0 + mjd
- djtt=mjd + sla_DTT(jd)/86400.d0
- ttjd=jd + sla_DTT(jd)/86400.d0
-
- if(nspecial.ne.8) then
- call pleph(ttjd,10,3,rme2000) !RME (J2000) from JPL ephemeris
-
- year=2000.d0 + (jd-2451545.d0)/365.25d0
- call sla_PREC (2000.0d0, year, prec) !Get precession matrix
- rmeDate(1:3)=matmul(prec,rme2000(1:3)) !Moon geocentric xyz at Date
- rmeDate(4:6)=matmul(prec,rme2000(4:6)) !Moon geocentric vel at Date
- else
- call sla_DMOON(djtt,rmeDate) !No JPL ephemeris, use DMOON
- rmeDate=rmeDate*au2km
- endif
+ djutc_sample(jj)=mjd
+ jd_sample(jj)=2400000.5d0 + mjd
+ djtt_sample(jj)=mjd + sla_DTT(jd_sample(jj))/86400.d0
- if(nspecial.eq.7) then
- rmeTrue=rmeDate
- else
-!Nutation to true equinox of Date
- call sla_NUT(djtt,rmatn)
- call sla_DMXV(rmatn,rmeDate,rmeTrue)
- call sla_DMXV(rmatn,rmeDate(4),rmeTrue(4))
+ if(jpl_available) then
+ ttjd=2400000.5d0 + djtt_sample(jj)
+ call pleph(ttjd,10,3,rme2000(:,jj),jpl_status)
+ if(jpl_status.ne.JPL_STATUS_OK) jpl_available=.false.
+ if(jpl_available) then
+ if(.not.all(ieee_is_finite(rme2000(:,jj)))) &
+ jpl_available=.false.
+ endif
+ if(jpl_available) then
+ if(any(abs(rme2000(1:3,jj)).gt.max_lunar_position_km) &
+ .or. any(abs(rme2000(4:6,jj)).gt. &
+ max_lunar_velocity_km_s)) &
+ jpl_available=.false.
+ endif
endif
+ enddo
+
+ do attempt=1,2
+ use_jpl=jpl_available
+ derived_valid=.true.
+
+ do jj=1,2
+ djutc=djutc_sample(jj)
+ jd=jd_sample(jj)
+ djtt=djtt_sample(jj)
+
+ if(use_jpl) then
+ year=2000.d0 + (jd-2451545.d0)/365.25d0
+ call sla_PREC(2000.0d0,year,prec)
+ rmeDate(1:3)=matmul(prec,rme2000(1:3,jj))
+ rmeDate(4:6)=matmul(prec,rme2000(4:6,jj))
+ else
+ call sla_DMOON(djtt,rmeDate)
+ rmeDate=rmeDate*au2km
+ endif
+ if(.not.all(ieee_is_finite(rmeDate))) then
+ derived_valid=.false.
+ exit
+ endif
-! Local Apparent Sidereal Time:
- djut1=djutc + dut/86400.d0
- if(nspecial.eq.6) djut1=djutc
- xlast=sla_DRANRM(sla_GMST(djut1) + sla_EQEQX(djtt) + east_long)
- call sla_PVOBS(geodetic_lat,height,xlast,raeTrue)
- rmaTrue=rmeTrue - raeTrue*au2km
-
- if(nspecial.ne.2) then
-! Allow for planetary aberration
- tl=499.004782D0*SQRT(rmaTrue(1)**2 + rmaTrue(2)**2 + rmaTrue(3)**2)
- rmaTrue(1:3)=rmaTrue(1:3)-tl*rmaTrue(4:6)/au2km
+ if(nspecial.eq.7) then
+ rmeTrue=rmeDate
+ else
+ call sla_NUT(djtt,rmatn)
+ call sla_DMXV(rmatn,rmeDate,rmeTrue)
+ call sla_DMXV(rmatn,rmeDate(4),rmeTrue(4))
+ endif
+ if(.not.all(ieee_is_finite(rmeTrue))) then
+ derived_valid=.false.
+ exit
+ endif
+
+ djut1=djutc + dut/86400.d0
+ if(nspecial.eq.6) djut1=djutc
+ xlast=sla_DRANRM(sla_GMST(djut1) + sla_EQEQX(djtt) + &
+ east_long)
+ call sla_PVOBS(geodetic_lat,height,xlast,raeTrue)
+ rmaTrue=rmeTrue - raeTrue*au2km
+ if(.not.ieee_is_finite(xlast) .or. &
+ .not.all(ieee_is_finite(raeTrue)) .or. &
+ .not.all(ieee_is_finite(rmaTrue))) then
+ derived_valid=.false.
+ exit
+ endif
+
+ if(nspecial.ne.2) then
+ tl=499.004782D0*SQRT(rmaTrue(1)**2 + rmaTrue(2)**2 + &
+ rmaTrue(3)**2)
+ rmaTrue(1:3)=rmaTrue(1:3)-tl*rmaTrue(4:6)/au2km
+ if(.not.ieee_is_finite(tl) .or. &
+ .not.all(ieee_is_finite(rmaTrue))) then
+ derived_valid=.false.
+ exit
+ endif
+ endif
+
+ call sla_DC62S(rmaTrue,RA,Dec,dist,RAdot,DECdot,vr)
+ dop=-2.d0 * freq * vr/clight
+ techo=2.d0*dist/clight
+ call libration(jd,RA,Dec,xl(jj),b(jj))
+ if(.not.all(ieee_is_finite((/RA,Dec,dist,RAdot,DECdot,vr, &
+ dop,techo,xl(jj),b(jj)/)))) then
+ derived_valid=.false.
+ exit
+ endif
+ enddo
+
+ if(derived_valid) then
+ dldt=57.2957795131*(xl(2)-xl(1))
+ dbdt=57.2957795131*(b(2)-b(1))
+ rate=sqrt((2*dldt)**2 + (2*dbdt)**2)
+ fspread_1GHz=0.5*6741*rate
+ call sla_DE2H(xlast-RA,Dec,geodetic_lat,Az,El)
+ if(.not.all(ieee_is_finite((/dldt,dbdt,rate,fspread_1GHz, &
+ Az,El/)))) derived_valid=.false.
endif
-!Topocentric RA, Dec, dist, velocity
- call sla_DC62S(rmaTrue,RA,Dec,dist,RAdot,DECdot,vr)
- dop=-2.d0 * freq * vr/clight !EME doppler shift
- techo=2.d0*dist/clight !Echo delay time (s)
- call libration(jd,RA,Dec,xl(jj),b(jj))
+ if(use_jpl .and. .not.derived_valid) then
+ jpl_available=.false.
+ cycle
+ endif
+ exit
enddo
- fspread_1GHz=0.0d0
- dldt=57.2957795131*(xl(2)-xl(1))
- dbdt=57.2957795131*(b(2)-b(1))
- rate=sqrt((2*dldt)**2 + (2*dbdt)**2)
- fspread_1GHz=0.5*6741*rate
-
- call sla_DE2H(xlast-RA,Dec,geodetic_lat,Az,El)
+ if(derived_valid) then
+ if(use_jpl) then
+ ephemeris_result=EPHEMERIS_JPL
+ else
+ ephemeris_result=EPHEMERIS_ANALYTIC_FALLBACK
+ endif
+ else
+ ephemeris_result=EPHEMERIS_UNAVAILABLE
+ RA=0.d0
+ Dec=0.d0
+ Az=0.d0
+ El=0.d0
+ techo=0.d0
+ dop=0.d0
+ fspread_1GHz=0.d0
+ vr=0.d0
+ xl=0.d0
+ b=0.d0
+ endif
- return
end subroutine ephem