; docformat = 'rst' ;+ ;Calculate the position and velocity of the spacecraft at a given time ;in either inertial or ECEF cordinate frame, and the uncertainty in ;the position and velocity. ; ; Notes: ; * This function will use either the astronomy library, if it is availabe ; or the older table-based functions if not. In either case, the TLEs or ; tables must be installed in the places expected by the astronomy ; library or scpos function. ; * "Inertial" frame in a precise sense is the True Equator, Mean Equinox ; (TEME) system used natively by SGP4. Origin is at Earth center of mass, ; X axis points towards mean equinox in plane of true equator of date, ; Z axis is along true axis of rotation normal to true equator, Y axis ; completes a right handed set (points towards 6h right ascension). ; * ECEF frame is the above inertial frame rotated by the greenwich mean ; siderial time angle. Origin is at Earth center of mass, X axis points ; towards prime meridian, Z axis points towards north pole, Y axis ; completes a right handed set (points at 90deg E) ; ; :Examples: ; position_vec = scpv(time) ;- ;+ ; :Params: ; Time : in, required, type=double ; Time in either GPS seconds (time unit of AIM telemetry) or Julian ; Date UTC. ; ; :Keywords: ; ecef : in, optional, type=boolean ; Set this keyword to calculate the state vector in the ECEF frame. ; Default is J2000 inertial frame if keyword is not. ; drv : out, optional, type=vector of double ; Uncertainty of state vector, in same format and units as returned ; position and velocity. ; ; :Returns: ; A six element vector. Elements 0,1,2 are x,y,z of position vector, ; in selected coordinate frame, in km. Elements 3,4,5 are x,y,z of ; velocity vector, in same frame, in km/s. ;- function scpv,Time,ecef=ecef,drv=drv, native_toggle=toggle if Time lt 0 then begin drv=[0,0,0,0,0,0] return,[0d,0,6978,0,0,0] end if has_astron_lib() then begin JD=usec2jd(Time) if keyword_set(toggle) then $ spacecraft_pv,!SC_NUMBER,JD,pv,pv_uncertainty=drv,tle_path=!tle_path,status=status $ ; To run in 64 bit mode we are now using Chris Jeppesen's IDL implementation of Barry Knapp's astron library else $ spacecraft_pv_msgp4, !SC_NUMBER,jd,pv,coorID=2, pv_uncertainty=drv, status=status, tle_path=!tle_path if status gt 0 then begin message,string(status,format="(%'spacecraft_pv didnt work: status %d')") + $ ' ' + usec2la(jd) + ' ' + strtrim(string(jd), 2) endif r=pv[0:2] v=pv[3:5] dr=drv[0:2] dv=drv[3:5] end else begin r=scpos(Time) v=scvel(Time) dr=[5.0,5,5] dv=[1.0,1,1]*0.001 end if keyword_set(ecef) then begin r=transformgrid(eci_to_ecef(time),r) v=transformgrid(eci_to_ecef(time),v)-crossp_grid(r,[0,0,get_wgs84_const(/omega)]) dr=transformgrid(eci_to_ecef(time),dr) dv=transformgrid(eci_to_ecef(time),dv) drv=[dr,dv] end return,[r,v]; end