1 #include "sofa.h"
2 
iauAtioq(double ri,double di,iauASTROM * astrom,double * aob,double * zob,double * hob,double * dob,double * rob)3 void iauAtioq(double ri, double di, iauASTROM *astrom,
4               double *aob, double *zob,
5               double *hob, double *dob, double *rob)
6 /*
7 **  - - - - - - - - -
8 **   i a u A t i o q
9 **  - - - - - - - - -
10 **
11 **  Quick CIRS to observed place transformation.
12 **
13 **  Use of this function is appropriate when efficiency is important and
14 **  where many star positions are all to be transformed for one date.
15 **  The star-independent astrometry parameters can be obtained by
16 **  calling iauApio[13] or iauApco[13].
17 **
18 **  This function is part of the International Astronomical Union's
19 **  SOFA (Standards of Fundamental Astronomy) software collection.
20 **
21 **  Status:  support function.
22 **
23 **  Given:
24 **     ri     double     CIRS right ascension
25 **     di     double     CIRS declination
26 **     astrom iauASTROM* star-independent astrometry parameters:
27 **      pmt    double       PM time interval (SSB, Julian years)
28 **      eb     double[3]    SSB to observer (vector, au)
29 **      eh     double[3]    Sun to observer (unit vector)
30 **      em     double       distance from Sun to observer (au)
31 **      v      double[3]    barycentric observer velocity (vector, c)
32 **      bm1    double       sqrt(1-|v|^2): reciprocal of Lorenz factor
33 **      bpn    double[3][3] bias-precession-nutation matrix
34 **      along  double       longitude + s' (radians)
35 **      xpl    double       polar motion xp wrt local meridian (radians)
36 **      ypl    double       polar motion yp wrt local meridian (radians)
37 **      sphi   double       sine of geodetic latitude
38 **      cphi   double       cosine of geodetic latitude
39 **      diurab double       magnitude of diurnal aberration vector
40 **      eral   double       "local" Earth rotation angle (radians)
41 **      refa   double       refraction constant A (radians)
42 **      refb   double       refraction constant B (radians)
43 **
44 **  Returned:
45 **     aob    double*    observed azimuth (radians: N=0,E=90)
46 **     zob    double*    observed zenith distance (radians)
47 **     hob    double*    observed hour angle (radians)
48 **     dob    double*    observed declination (radians)
49 **     rob    double*    observed right ascension (CIO-based, radians)
50 **
51 **  Notes:
52 **
53 **  1) This function returns zenith distance rather than altitude in
54 **     order to reflect the fact that no allowance is made for
55 **     depression of the horizon.
56 **
57 **  2) The accuracy of the result is limited by the corrections for
58 **     refraction, which use a simple A*tan(z) + B*tan^3(z) model.
59 **     Providing the meteorological parameters are known accurately and
60 **     there are no gross local effects, the predicted observed
61 **     coordinates should be within 0.05 arcsec (optical) or 1 arcsec
62 **     (radio) for a zenith distance of less than 70 degrees, better
63 **     than 30 arcsec (optical or radio) at 85 degrees and better
64 **     than 20 arcmin (optical) or 30 arcmin (radio) at the horizon.
65 **
66 **     Without refraction, the complementary functions iauAtioq and
67 **     iauAtoiq are self-consistent to better than 1 microarcsecond all
68 **     over the celestial sphere.  With refraction included, consistency
69 **     falls off at high zenith distances, but is still better than
70 **     0.05 arcsec at 85 degrees.
71 **
72 **  3) It is advisable to take great care with units, as even unlikely
73 **     values of the input parameters are accepted and processed in
74 **     accordance with the models used.
75 **
76 **  4) The CIRS RA,Dec is obtained from a star catalog mean place by
77 **     allowing for space motion, parallax, the Sun's gravitational lens
78 **     effect, annual aberration and precession-nutation.  For star
79 **     positions in the ICRS, these effects can be applied by means of
80 **     the iauAtci13 (etc.) functions.  Starting from classical "mean
81 **     place" systems, additional transformations will be needed first.
82 **
83 **  5) "Observed" Az,El means the position that would be seen by a
84 **     perfect geodetically aligned theodolite.  This is obtained from
85 **     the CIRS RA,Dec by allowing for Earth orientation and diurnal
86 **     aberration, rotating from equator to horizon coordinates, and
87 **     then adjusting for refraction.  The HA,Dec is obtained by
88 **     rotating back into equatorial coordinates, and is the position
89 **     that would be seen by a perfect equatorial with its polar axis
90 **     aligned to the Earth's axis of rotation.  Finally, the RA is
91 **     obtained by subtracting the HA from the local ERA.
92 **
93 **  6) The star-independent CIRS-to-observed-place parameters in ASTROM
94 **     may be computed with iauApio[13] or iauApco[13].  If nothing has
95 **     changed significantly except the time, iauAper[13] may be used to
96 **     perform the requisite adjustment to the astrom structure.
97 **
98 **  Called:
99 **     iauS2c       spherical coordinates to unit vector
100 **     iauC2s       p-vector to spherical
101 **     iauAnp       normalize angle into range 0 to 2pi
102 **
103 **  This revision:   2020 December 7
104 **
105 **  SOFA release 2021-05-12
106 **
107 **  Copyright (C) 2021 IAU SOFA Board.  See notes at end.
108 */
109 {
110 /* Minimum cos(alt) and sin(alt) for refraction purposes */
111    const double CELMIN = 1e-6;
112    const double SELMIN = 0.05;
113 
114    double v[3], x, y, z, sx, cx, sy, cy, xhd, yhd, zhd, f,
115           xhdt, yhdt, zhdt, xaet, yaet, zaet, azobs, r, tz, w, del,
116           cosdel, xaeo, yaeo, zaeo, zdobs, hmobs, dcobs, raobs;
117 
118 
119 /* CIRS RA,Dec to Cartesian -HA,Dec. */
120    iauS2c(ri-astrom->eral, di, v);
121    x = v[0];
122    y = v[1];
123    z = v[2];
124 
125 /* Polar motion. */
126    sx = sin(astrom->xpl);
127    cx = cos(astrom->xpl);
128    sy = sin(astrom->ypl);
129    cy = cos(astrom->ypl);
130    xhd = cx*x + sx*z;
131    yhd = sx*sy*x + cy*y - cx*sy*z;
132    zhd = -sx*cy*x + sy*y + cx*cy*z;
133 
134 /* Diurnal aberration. */
135    f = ( 1.0 - astrom->diurab*yhd );
136    xhdt = f * xhd;
137    yhdt = f * ( yhd + astrom->diurab );
138    zhdt = f * zhd;
139 
140 /* Cartesian -HA,Dec to Cartesian Az,El (S=0,E=90). */
141    xaet = astrom->sphi*xhdt - astrom->cphi*zhdt;
142    yaet = yhdt;
143    zaet = astrom->cphi*xhdt + astrom->sphi*zhdt;
144 
145 /* Azimuth (N=0,E=90). */
146    azobs = ( xaet != 0.0 || yaet != 0.0 ) ? atan2(yaet,-xaet) : 0.0;
147 
148 /* ---------- */
149 /* Refraction */
150 /* ---------- */
151 
152 /* Cosine and sine of altitude, with precautions. */
153    r = sqrt(xaet*xaet + yaet*yaet);
154    r = r > CELMIN ? r : CELMIN;
155    z = zaet > SELMIN ? zaet : SELMIN;
156 
157 /* A*tan(z)+B*tan^3(z) model, with Newton-Raphson correction. */
158    tz = r/z;
159    w = astrom->refb*tz*tz;
160    del = ( astrom->refa + w ) * tz /
161          ( 1.0 + ( astrom->refa + 3.0*w ) / ( z*z ) );
162 
163 /* Apply the change, giving observed vector. */
164    cosdel = 1.0 - del*del/2.0;
165    f = cosdel - del*z/r;
166    xaeo = xaet*f;
167    yaeo = yaet*f;
168    zaeo = cosdel*zaet + del*r;
169 
170 /* Observed ZD. */
171    zdobs = atan2(sqrt(xaeo*xaeo+yaeo*yaeo), zaeo);
172 
173 /* Az/El vector to HA,Dec vector (both right-handed). */
174    v[0] = astrom->sphi*xaeo + astrom->cphi*zaeo;
175    v[1] = yaeo;
176    v[2] = - astrom->cphi*xaeo + astrom->sphi*zaeo;
177 
178 /* To spherical -HA,Dec. */
179    iauC2s ( v, &hmobs, &dcobs );
180 
181 /* Right ascension (with respect to CIO). */
182    raobs = astrom->eral + hmobs;
183 
184 /* Return the results. */
185    *aob = iauAnp(azobs);
186    *zob = zdobs;
187    *hob = -hmobs;
188    *dob = dcobs;
189    *rob = iauAnp(raobs);
190 
191 /* Finished. */
192 
193 /*----------------------------------------------------------------------
194 **
195 **  Copyright (C) 2021
196 **  Standards Of Fundamental Astronomy Board
197 **  of the International Astronomical Union.
198 **
199 **  =====================
200 **  SOFA Software License
201 **  =====================
202 **
203 **  NOTICE TO USER:
204 **
205 **  BY USING THIS SOFTWARE YOU ACCEPT THE FOLLOWING SIX TERMS AND
206 **  CONDITIONS WHICH APPLY TO ITS USE.
207 **
208 **  1. The Software is owned by the IAU SOFA Board ("SOFA").
209 **
210 **  2. Permission is granted to anyone to use the SOFA software for any
211 **     purpose, including commercial applications, free of charge and
212 **     without payment of royalties, subject to the conditions and
213 **     restrictions listed below.
214 **
215 **  3. You (the user) may copy and distribute SOFA source code to others,
216 **     and use and adapt its code and algorithms in your own software,
217 **     on a world-wide, royalty-free basis.  That portion of your
218 **     distribution that does not consist of intact and unchanged copies
219 **     of SOFA source code files is a "derived work" that must comply
220 **     with the following requirements:
221 **
222 **     a) Your work shall be marked or carry a statement that it
223 **        (i) uses routines and computations derived by you from
224 **        software provided by SOFA under license to you; and
225 **        (ii) does not itself constitute software provided by and/or
226 **        endorsed by SOFA.
227 **
228 **     b) The source code of your derived work must contain descriptions
229 **        of how the derived work is based upon, contains and/or differs
230 **        from the original SOFA software.
231 **
232 **     c) The names of all routines in your derived work shall not
233 **        include the prefix "iau" or "sofa" or trivial modifications
234 **        thereof such as changes of case.
235 **
236 **     d) The origin of the SOFA components of your derived work must
237 **        not be misrepresented;  you must not claim that you wrote the
238 **        original software, nor file a patent application for SOFA
239 **        software or algorithms embedded in the SOFA software.
240 **
241 **     e) These requirements must be reproduced intact in any source
242 **        distribution and shall apply to anyone to whom you have
243 **        granted a further right to modify the source code of your
244 **        derived work.
245 **
246 **     Note that, as originally distributed, the SOFA software is
247 **     intended to be a definitive implementation of the IAU standards,
248 **     and consequently third-party modifications are discouraged.  All
249 **     variations, no matter how minor, must be explicitly marked as
250 **     such, as explained above.
251 **
252 **  4. You shall not cause the SOFA software to be brought into
253 **     disrepute, either by misuse, or use for inappropriate tasks, or
254 **     by inappropriate modification.
255 **
256 **  5. The SOFA software is provided "as is" and SOFA makes no warranty
257 **     as to its use or performance.   SOFA does not and cannot warrant
258 **     the performance or results which the user may obtain by using the
259 **     SOFA software.  SOFA makes no warranties, express or implied, as
260 **     to non-infringement of third party rights, merchantability, or
261 **     fitness for any particular purpose.  In no event will SOFA be
262 **     liable to the user for any consequential, incidental, or special
263 **     damages, including any lost profits or lost savings, even if a
264 **     SOFA representative has been advised of such damages, or for any
265 **     claim by any third party.
266 **
267 **  6. The provision of any version of the SOFA software under the terms
268 **     and conditions specified herein does not imply that future
269 **     versions will also be made available under the same terms and
270 **     conditions.
271 *
272 **  In any published work or commercial product which uses the SOFA
273 **  software directly, acknowledgement (see www.iausofa.org) is
274 **  appreciated.
275 **
276 **  Correspondence concerning SOFA software should be addressed as
277 **  follows:
278 **
279 **      By email:  sofa@ukho.gov.uk
280 **      By post:   IAU SOFA Center
281 **                 HM Nautical Almanac Office
282 **                 UK Hydrographic Office
283 **                 Admiralty Way, Taunton
284 **                 Somerset, TA1 2DN
285 **                 United Kingdom
286 **
287 **--------------------------------------------------------------------*/
288 }
289