1 #include "erfa.h"
2 
eraAtoiq(const char * type,double ob1,double ob2,eraASTROM * astrom,double * ri,double * di)3 void eraAtoiq(const char *type,
4               double ob1, double ob2, eraASTROM *astrom,
5               double *ri, double *di)
6 /*
7 **  - - - - - - - - -
8 **   e r a A t o i q
9 **  - - - - - - - - -
10 **
11 **  Quick observed place to CIRS, given the star-independent astrometry
12 **  parameters.
13 **
14 **  Use of this function is appropriate when efficiency is important and
15 **  where many star positions are all to be transformed for one date.
16 **  The star-independent astrometry parameters can be obtained by
17 **  calling eraApio[13] or eraApco[13].
18 **
19 **  Given:
20 **     type   char[]     type of coordinates: "R", "H" or "A" (Note 1)
21 **     ob1    double     observed Az, HA or RA (radians; Az is N=0,E=90)
22 **     ob2    double     observed ZD or Dec (radians)
23 **     astrom eraASTROM* star-independent astrometry parameters:
24 **      pmt    double       PM time interval (SSB, Julian years)
25 **      eb     double[3]    SSB to observer (vector, au)
26 **      eh     double[3]    Sun to observer (unit vector)
27 **      em     double       distance from Sun to observer (au)
28 **      v      double[3]    barycentric observer velocity (vector, c)
29 **      bm1    double       sqrt(1-|v|^2): reciprocal of Lorenz factor
30 **      bpn    double[3][3] bias-precession-nutation matrix
31 **      along  double       longitude + s' (radians)
32 **      xpl    double       polar motion xp wrt local meridian (radians)
33 **      ypl    double       polar motion yp wrt local meridian (radians)
34 **      sphi   double       sine of geodetic latitude
35 **      cphi   double       cosine of geodetic latitude
36 **      diurab double       magnitude of diurnal aberration vector
37 **      eral   double       "local" Earth rotation angle (radians)
38 **      refa   double       refraction constant A (radians)
39 **      refb   double       refraction constant B (radians)
40 **
41 **  Returned:
42 **     ri     double*    CIRS right ascension (CIO-based, radians)
43 **     di     double*    CIRS declination (radians)
44 **
45 **  Notes:
46 **
47 **  1) "Observed" Az,El means the position that would be seen by a
48 **     perfect geodetically aligned theodolite.  This is related to
49 **     the observed HA,Dec via the standard rotation, using the geodetic
50 **     latitude (corrected for polar motion), while the observed HA and
51 **     RA are related simply through the Earth rotation angle and the
52 **     site longitude.  "Observed" RA,Dec or HA,Dec thus means the
53 **     position that would be seen by a perfect equatorial with its
54 **     polar axis aligned to the Earth's axis of rotation.  By removing
55 **     from the observed place the effects of atmospheric refraction and
56 **     diurnal aberration, the CIRS RA,Dec is obtained.
57 **
58 **  2) Only the first character of the type argument is significant.
59 **     "R" or "r" indicates that ob1 and ob2 are the observed right
60 **     ascension and declination;  "H" or "h" indicates that they are
61 **     hour angle (west +ve) and declination;  anything else ("A" or
62 **     "a" is recommended) indicates that ob1 and ob2 are azimuth (north
63 **     zero, east 90 deg) and zenith distance.  (Zenith distance is used
64 **     rather than altitude in order to reflect the fact that no
65 **     allowance is made for depression of the horizon.)
66 **
67 **  3) The accuracy of the result is limited by the corrections for
68 **     refraction, which use a simple A*tan(z) + B*tan^3(z) model.
69 **     Providing the meteorological parameters are known accurately and
70 **     there are no gross local effects, the predicted observed
71 **     coordinates should be within 0.05 arcsec (optical) or 1 arcsec
72 **     (radio) for a zenith distance of less than 70 degrees, better
73 **     than 30 arcsec (optical or radio) at 85 degrees and better than
74 **     20 arcmin (optical) or 30 arcmin (radio) at the horizon.
75 **
76 **     Without refraction, the complementary functions eraAtioq and
77 **     eraAtoiq are self-consistent to better than 1 microarcsecond all
78 **     over the celestial sphere.  With refraction included, consistency
79 **     falls off at high zenith distances, but is still better than
80 **     0.05 arcsec at 85 degrees.
81 **
82 **  4) It is advisable to take great care with units, as even unlikely
83 **     values of the input parameters are accepted and processed in
84 **     accordance with the models used.
85 **
86 **  Called:
87 **     eraS2c       spherical coordinates to unit vector
88 **     eraC2s       p-vector to spherical
89 **     eraAnp       normalize angle into range 0 to 2pi
90 **
91 **  Copyright (C) 2013-2020, NumFOCUS Foundation.
92 **  Derived, with permission, from the SOFA library.  See notes at end of file.
93 */
94 {
95    int c;
96    double c1, c2, sphi, cphi, ce, xaeo, yaeo, zaeo, v[3],
97           xmhdo, ymhdo, zmhdo, az, sz, zdo, refa, refb, tz, dref,
98           zdt, xaet, yaet, zaet, xmhda, ymhda, zmhda,
99           f, xhd, yhd, zhd, xpl, ypl, w, hma;
100 
101 
102 /* Coordinate type. */
103    c = (int) type[0];
104 
105 /* Coordinates. */
106    c1 = ob1;
107    c2 = ob2;
108 
109 /* Sin, cos of latitude. */
110    sphi = astrom->sphi;
111    cphi = astrom->cphi;
112 
113 /* Standardize coordinate type. */
114    if ( c == 'r' || c == 'R' ) {
115       c = 'R';
116    } else if ( c == 'h' || c == 'H' ) {
117       c = 'H';
118    } else {
119       c = 'A';
120    }
121 
122 /* If Az,ZD, convert to Cartesian (S=0,E=90). */
123    if ( c == 'A' ) {
124       ce = sin(c2);
125       xaeo = - cos(c1) * ce;
126       yaeo = sin(c1) * ce;
127       zaeo = cos(c2);
128 
129    } else {
130 
131    /* If RA,Dec, convert to HA,Dec. */
132       if ( c == 'R' ) c1 = astrom->eral - c1;
133 
134    /* To Cartesian -HA,Dec. */
135       eraS2c ( -c1, c2, v );
136       xmhdo = v[0];
137       ymhdo = v[1];
138       zmhdo = v[2];
139 
140    /* To Cartesian Az,El (S=0,E=90). */
141       xaeo = sphi*xmhdo - cphi*zmhdo;
142       yaeo = ymhdo;
143       zaeo = cphi*xmhdo + sphi*zmhdo;
144    }
145 
146 /* Azimuth (S=0,E=90). */
147    az = ( xaeo != 0.0 || yaeo != 0.0 ) ? atan2(yaeo,xaeo) : 0.0;
148 
149 /* Sine of observed ZD, and observed ZD. */
150    sz = sqrt ( xaeo*xaeo + yaeo*yaeo );
151    zdo = atan2 ( sz, zaeo );
152 
153 /*
154 ** Refraction
155 ** ----------
156 */
157 
158 /* Fast algorithm using two constant model. */
159    refa = astrom->refa;
160    refb = astrom->refb;
161    tz = sz / zaeo;
162    dref = ( refa + refb*tz*tz ) * tz;
163    zdt = zdo + dref;
164 
165 /* To Cartesian Az,ZD. */
166    ce = sin(zdt);
167    xaet = cos(az) * ce;
168    yaet = sin(az) * ce;
169    zaet = cos(zdt);
170 
171 /* Cartesian Az,ZD to Cartesian -HA,Dec. */
172    xmhda = sphi*xaet + cphi*zaet;
173    ymhda = yaet;
174    zmhda = - cphi*xaet + sphi*zaet;
175 
176 /* Diurnal aberration. */
177    f = ( 1.0 + astrom->diurab*ymhda );
178    xhd = f * xmhda;
179    yhd = f * ( ymhda - astrom->diurab );
180    zhd = f * zmhda;
181 
182 /* Polar motion. */
183    xpl = astrom->xpl;
184    ypl = astrom->ypl;
185    w = xpl*xhd - ypl*yhd + zhd;
186    v[0] = xhd - xpl*w;
187    v[1] = yhd + ypl*w;
188    v[2] = w - ( xpl*xpl + ypl*ypl ) * zhd;
189 
190 /* To spherical -HA,Dec. */
191    eraC2s(v, &hma, di);
192 
193 /* Right ascension. */
194    *ri = eraAnp(astrom->eral + hma);
195 
196 /* Finished. */
197 
198 }
199 /*----------------------------------------------------------------------
200 **
201 **
202 **  Copyright (C) 2013-2020, NumFOCUS Foundation.
203 **  All rights reserved.
204 **
205 **  This library is derived, with permission, from the International
206 **  Astronomical Union's "Standards of Fundamental Astronomy" library,
207 **  available from http://www.iausofa.org.
208 **
209 **  The ERFA version is intended to retain identical functionality to
210 **  the SOFA library, but made distinct through different function and
211 **  file names, as set out in the SOFA license conditions.  The SOFA
212 **  original has a role as a reference standard for the IAU and IERS,
213 **  and consequently redistribution is permitted only in its unaltered
214 **  state.  The ERFA version is not subject to this restriction and
215 **  therefore can be included in distributions which do not support the
216 **  concept of "read only" software.
217 **
218 **  Although the intent is to replicate the SOFA API (other than
219 **  replacement of prefix names) and results (with the exception of
220 **  bugs;  any that are discovered will be fixed), SOFA is not
221 **  responsible for any errors found in this version of the library.
222 **
223 **  If you wish to acknowledge the SOFA heritage, please acknowledge
224 **  that you are using a library derived from SOFA, rather than SOFA
225 **  itself.
226 **
227 **
228 **  TERMS AND CONDITIONS
229 **
230 **  Redistribution and use in source and binary forms, with or without
231 **  modification, are permitted provided that the following conditions
232 **  are met:
233 **
234 **  1 Redistributions of source code must retain the above copyright
235 **    notice, this list of conditions and the following disclaimer.
236 **
237 **  2 Redistributions in binary form must reproduce the above copyright
238 **    notice, this list of conditions and the following disclaimer in
239 **    the documentation and/or other materials provided with the
240 **    distribution.
241 **
242 **  3 Neither the name of the Standards Of Fundamental Astronomy Board,
243 **    the International Astronomical Union nor the names of its
244 **    contributors may be used to endorse or promote products derived
245 **    from this software without specific prior written permission.
246 **
247 **  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
248 **  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
249 **  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
250 **  FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
251 **  COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
252 **  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
253 **  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
254 **  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
255 **  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
256 **  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
257 **  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
258 **  POSSIBILITY OF SUCH DAMAGE.
259 **
260 */
261