sofars/astro/apco13.rs
1use super::{IauAstrom, apco, refco};
2use crate::eph::epv00;
3use crate::erst::era00;
4use crate::pnp::{bpn2xy, eors, pnm06a, s06, sp00};
5use crate::ts::{taitt, utctai, utcut1};
6
7/// Prepare for ICRS <−> observed, terrestrial
8///
9/// For a terrestrial observer, prepare star-independent astrometry
10/// parameters for transformations between ICRS and observed
11/// coordinates. The caller supplies UTC, site coordinates, ambient air
12/// conditions and observing wavelength, and SOFA models are used to
13/// obtain the Earth ephemeris, CIP/CIO and refraction constants.
14///
15/// The parameters produced by this function are required in the
16/// parallax, light deflection, aberration, and bias-precession-nutation
17/// parts of the ICRS/CIRS transformations.
18///
19/// This function is part of the International Astronomical Union's
20/// SOFA (Standards of Fundamental Astronomy) software collection.
21///
22/// Status: support function.
23///
24/// Given:
25/// ```
26/// utc1 double UTC as a 2-part...
27/// utc2 double ...quasi Julian Date (Notes 1,2)
28/// dut1 double UT1-UTC (seconds, Note 3)
29/// elong double longitude (radians, east +ve, Note 4)
30/// phi double latitude (geodetic, radians, Note 4)
31/// hm double height above ellipsoid (m, geodetic, Notes 4,6)
32/// xp,yp double polar motion coordinates (radians, Note 5)
33/// phpa double pressure at the observer (hPa = mB, Note 6)
34/// tc double ambient temperature at the observer (deg C)
35/// rh double relative humidity at the observer (range 0-1)
36/// wl double wavelength (micrometers, Note 7)
37/// ```
38/// Returned:
39/// ```
40/// astrom iauASTROM* star-independent astrometry parameters:
41/// pmt double PM time interval (SSB, Julian years)
42/// eb double[3] SSB to observer (vector, au)
43/// eh double[3] Sun to observer (unit vector)
44/// em double distance from Sun to observer (au)
45/// v double[3] barycentric observer velocity (vector, c)
46/// bm1 double sqrt(1-|v|^2): reciprocal of Lorenz factor
47/// bpn double[3][3] bias-precession-nutation matrix
48/// along double longitude + s' (radians)
49/// xpl double polar motion xp wrt local meridian (radians)
50/// ypl double polar motion yp wrt local meridian (radians)
51/// sphi double sine of geodetic latitude
52/// cphi double cosine of geodetic latitude
53/// diurab double magnitude of diurnal aberration vector
54/// eral double "local" Earth rotation angle (radians)
55/// refa double refraction constant A (radians)
56/// refb double refraction constant B (radians)
57/// eo double* equation of the origins (ERA-GST, radians)
58/// ```
59/// Returned (function value):
60/// ```
61/// int status: +1 = dubious year (Note 2)
62/// 0 = OK
63/// -1 = unacceptable date
64/// ```
65/// Notes:
66///
67/// 1) utc1+utc2 is quasi Julian Date (see Note 2), apportioned in any
68/// convenient way between the two arguments, for example where utc1
69/// is the Julian Day Number and utc2 is the fraction of a day.
70///
71/// However, JD cannot unambiguously represent UTC during a leap
72/// second unless special measures are taken. The convention in the
73/// present function is that the JD day represents UTC days whether
74/// the length is 86399, 86400 or 86401 SI seconds.
75///
76/// Applications should use the function iauDtf2d to convert from
77/// calendar date and time of day into 2-part quasi Julian Date, as
78/// it implements the leap-second-ambiguity convention just
79/// described.
80///
81/// 2) The warning status "dubious year" flags UTCs that predate the
82/// introduction of the time scale or that are too far in the
83/// future to be trusted. See iauDat for further details.
84///
85/// 3) UT1-UTC is tabulated in IERS bulletins. It increases by exactly
86/// one second at the end of each positive UTC leap second,
87/// introduced in order to keep UT1-UTC within +/- 0.9s. n.b. This
88/// practice is under review, and in the future UT1-UTC may grow
89/// essentially without limit.
90///
91/// 4) The geographical coordinates are with respect to the WGS84
92/// reference ellipsoid. TAKE CARE WITH THE LONGITUDE SIGN: the
93/// longitude required by the present function is east-positive
94/// (i.e. right-handed), in accordance with geographical convention.
95///
96/// 5) The polar motion xp,yp can be obtained from IERS bulletins. The
97/// values are the coordinates (in radians) of the Celestial
98/// Intermediate Pole with respect to the International Terrestrial
99/// Reference System (see IERS Conventions 2003), measured along the
100/// meridians 0 and 90 deg west respectively. For many
101/// applications, xp and yp can be set to zero.
102///
103/// Internally, the polar motion is stored in a form rotated onto
104/// the local meridian.
105///
106/// 6) If hm, the height above the ellipsoid of the observing station
107/// in meters, is not known but phpa, the pressure in hPa (=mB), is
108/// available, an adequate estimate of hm can be obtained from the
109/// expression
110///
111/// hm = -29.3 * tsl * log ( phpa / 1013.25 );
112///
113/// where tsl is the approximate sea-level air temperature in K
114/// (See Astrophysical Quantities, C.W.Allen, 3rd edition, section
115/// 52). Similarly, if the pressure phpa is not known, it can be
116/// estimated from the height of the observing station, hm, as
117/// follows:
118///
119/// phpa = 1013.25 * exp ( -hm / ( 29.3 * tsl ) );
120///
121/// Note, however, that the refraction is nearly proportional to
122/// the pressure and that an accurate phpa value is important for
123/// precise work.
124///
125/// 7) The argument wl specifies the observing wavelength in
126/// micrometers. The transition from optical to radio is assumed to
127/// occur at 100 micrometers (about 3000 GHz).
128///
129/// 8) It is advisable to take great care with units, as even unlikely
130/// values of the input parameters are accepted and processed in
131/// accordance with the models used.
132///
133/// 9) In cases where the caller wishes to supply his own Earth
134/// ephemeris, Earth rotation information and refraction constants,
135/// the function iauApco can be used instead of the present function.
136///
137/// 10) This is one of several functions that inserts into the astrom
138/// structure star-independent parameters needed for the chain of
139/// astrometric transformations ICRS <-> GCRS <-> CIRS <-> observed.
140///
141/// The various functions support different classes of observer and
142/// portions of the transformation chain:
143/// ```
144/// functions observer transformation
145///
146/// iauApcg iauApcg13 geocentric ICRS <-> GCRS
147/// iauApci iauApci13 terrestrial ICRS <-> CIRS
148/// iauApco iauApco13 terrestrial ICRS <-> observed
149/// iauApcs iauApcs13 space ICRS <-> GCRS
150/// iauAper iauAper13 terrestrial update Earth rotation
151/// iauApio iauApio13 terrestrial CIRS <-> observed
152/// ```
153/// Those with names ending in "13" use contemporary SOFA models to
154/// compute the various ephemerides. The others accept ephemerides
155/// supplied by the caller.
156///
157/// The transformation from ICRS to GCRS covers space motion,
158/// parallax, light deflection, and aberration. From GCRS to CIRS
159/// comprises frame bias and precession-nutation. From CIRS to
160/// observed takes account of Earth rotation, polar motion, diurnal
161/// aberration and parallax (unless subsumed into the ICRS <-> GCRS
162/// transformation), and atmospheric refraction.
163///
164/// 11) The context structure astrom produced by this function is used
165/// by iauAtioq, iauAtoiq, iauAtciq* and iauAticq*.
166///
167/// Called:
168/// ```
169/// iauUtctai UTC to TAI
170/// iauTaitt TAI to TT
171/// iauUtcut1 UTC to UT1
172/// iauEpv00 Earth position and velocity
173/// iauPnm06a classical NPB matrix, IAU 2006/2000A
174/// iauBpn2xy extract CIP X,Y coordinates from NPB matrix
175/// iauS06 the CIO locator s, given X,Y, IAU 2006
176/// iauEra00 Earth rotation angle, IAU 2000
177/// iauSp00 the TIO locator s', IERS 2000
178/// iauRefco refraction constants for given ambient conditions
179/// iauApco astrometry parameters, ICRS-observed
180/// iauEors equation of the origins, given NPB matrix and s
181/// ```
182pub fn apco13(
183 utc1: f64,
184 utc2: f64,
185 dut1: f64,
186 elong: f64,
187 phi: f64,
188 hm: f64,
189 xp: f64,
190 yp: f64,
191 phpa: f64,
192 tc: f64,
193 rh: f64,
194 wl: f64,
195 astrom: &mut IauAstrom,
196 eo: &mut f64,
197) -> Result<i32, i32> {
198 let s: f64;
199 let theta: f64;
200 let sp: f64;
201
202 /* UTC to other time scales. */
203 let (tai1, tai2) = match utctai(utc1, utc2) {
204 Ok(v) => v,
205 Err(j) => return Err(j),
206 };
207
208 let (tt1, tt2) = match taitt(tai1, tai2) {
209 Ok(v) => v,
210 Err(j) => return Err(j),
211 };
212
213 let (ut11, ut12) = match utcut1(utc1, utc2, dut1) {
214 Ok(v) => v,
215 Err(j) => return Err(j),
216 };
217
218 let (ehpv, ebpv) = epv00(tt1, tt2).unwrap();
219
220 /* Form the equinox based BPN matrix, IAU 2006/2000A. */
221 let r = pnm06a(tt1, tt2);
222
223 /* Extract CIP X,Y. */
224 let (x, y) = bpn2xy(&r);
225
226 /* Obtain CIO locator s. */
227 s = s06(tt1, tt2, x, y);
228
229 /* Earth rotation angle. */
230 theta = era00(ut11, ut12);
231
232 /* TIO locator s'. */
233 sp = sp00(tt1, tt2);
234
235 /* Refraction constants A and B. */
236 let (refa, refb) = refco(phpa, tc, rh, wl);
237
238 /* Compute the star-independent astrometry parameters. */
239 apco(
240 tt1, tt2, &ebpv, &ehpv[0], x, y, s, theta, elong, phi, hm, xp, yp, sp, refa, refb, astrom,
241 );
242
243 /* Equation of the origins. */
244 *eo = eors(&r, s);
245
246 Ok(0)
247}