1 #include "erfa.h"
2 #include "erfam.h"
3 
eraApio(double sp,double theta,double elong,double phi,double hm,double xp,double yp,double refa,double refb,eraASTROM * astrom)4 void eraApio(double sp, double theta,
5              double elong, double phi, double hm, double xp, double yp,
6              double refa, double refb,
7              eraASTROM *astrom)
8 /*
9 **  - - - - - - - -
10 **   e r a A p i o
11 **  - - - - - - - -
12 **
13 **  For a terrestrial observer, prepare star-independent astrometry
14 **  parameters for transformations between CIRS and observed
15 **  coordinates.  The caller supplies the Earth orientation information
16 **  and the refraction constants as well as the site coordinates.
17 **
18 **  Given:
19 **     sp     double      the TIO locator s' (radians, Note 1)
20 **     theta  double      Earth rotation angle (radians)
21 **     elong  double      longitude (radians, east +ve, Note 2)
22 **     phi    double      geodetic latitude (radians, Note 2)
23 **     hm     double      height above ellipsoid (m, geodetic Note 2)
24 **     xp,yp  double      polar motion coordinates (radians, Note 3)
25 **     refa   double      refraction constant A (radians, Note 4)
26 **     refb   double      refraction constant B (radians, Note 4)
27 **
28 **  Returned:
29 **     astrom eraASTROM*  star-independent astrometry parameters:
30 **      pmt    double       unchanged
31 **      eb     double[3]    unchanged
32 **      eh     double[3]    unchanged
33 **      em     double       unchanged
34 **      v      double[3]    unchanged
35 **      bm1    double       unchanged
36 **      bpn    double[3][3] unchanged
37 **      along  double       adjusted longitude (radians)
38 **      xpl    double       polar motion xp wrt local meridian (radians)
39 **      ypl    double       polar motion yp wrt local meridian (radians)
40 **      sphi   double       sine of geodetic latitude
41 **      cphi   double       cosine of geodetic latitude
42 **      diurab double       magnitude of diurnal aberration vector
43 **      eral   double       "local" Earth rotation angle (radians)
44 **      refa   double       refraction constant A (radians)
45 **      refb   double       refraction constant B (radians)
46 **
47 **  Notes:
48 **
49 **  1) sp, the TIO locator s', is a tiny quantity needed only by the
50 **     most precise applications.  It can either be set to zero or
51 **     predicted using the ERFA function eraSp00.
52 **
53 **  2) The geographical coordinates are with respect to the ERFA_WGS84
54 **     reference ellipsoid.  TAKE CARE WITH THE LONGITUDE SIGN:  the
55 **     longitude required by the present function is east-positive
56 **     (i.e. right-handed), in accordance with geographical convention.
57 **
58 **  3) The polar motion xp,yp can be obtained from IERS bulletins.  The
59 **     values are the coordinates (in radians) of the Celestial
60 **     Intermediate Pole with respect to the International Terrestrial
61 **     Reference System (see IERS Conventions 2003), measured along the
62 **     meridians 0 and 90 deg west respectively.  For many applications,
63 **     xp and yp can be set to zero.
64 **
65 **     Internally, the polar motion is stored in a form rotated onto the
66 **     local meridian.
67 **
68 **  4) The refraction constants refa and refb are for use in a
69 **     dZ = A*tan(Z)+B*tan^3(Z) model, where Z is the observed
70 **     (i.e. refracted) zenith distance and dZ is the amount of
71 **     refraction.
72 **
73 **  5) It is advisable to take great care with units, as even unlikely
74 **     values of the input parameters are accepted and processed in
75 **     accordance with the models used.
76 **
77 **  6) In cases where the caller does not wish to provide the Earth
78 **     rotation information and refraction constants, the function
79 **     eraApio13 can be used instead of the present function.  This
80 **     starts from UTC and weather readings etc. and computes suitable
81 **     values using other ERFA functions.
82 **
83 **  7) This is one of several functions that inserts into the astrom
84 **     structure star-independent parameters needed for the chain of
85 **     astrometric transformations ICRS <-> GCRS <-> CIRS <-> observed.
86 **
87 **     The various functions support different classes of observer and
88 **     portions of the transformation chain:
89 **
90 **          functions         observer        transformation
91 **
92 **       eraApcg eraApcg13    geocentric      ICRS <-> GCRS
93 **       eraApci eraApci13    terrestrial     ICRS <-> CIRS
94 **       eraApco eraApco13    terrestrial     ICRS <-> observed
95 **       eraApcs eraApcs13    space           ICRS <-> GCRS
96 **       eraAper eraAper13    terrestrial     update Earth rotation
97 **       eraApio eraApio13    terrestrial     CIRS <-> observed
98 **
99 **     Those with names ending in "13" use contemporary ERFA models to
100 **     compute the various ephemerides.  The others accept ephemerides
101 **     supplied by the caller.
102 **
103 **     The transformation from ICRS to GCRS covers space motion,
104 **     parallax, light deflection, and aberration.  From GCRS to CIRS
105 **     comprises frame bias and precession-nutation.  From CIRS to
106 **     observed takes account of Earth rotation, polar motion, diurnal
107 **     aberration and parallax (unless subsumed into the ICRS <-> GCRS
108 **     transformation), and atmospheric refraction.
109 **
110 **  8) The context structure astrom produced by this function is used by
111 **     eraAtioq and eraAtoiq.
112 **
113 **  Called:
114 **     eraIr        initialize r-matrix to identity
115 **     eraRz        rotate around Z-axis
116 **     eraRy        rotate around Y-axis
117 **     eraRx        rotate around X-axis
118 **     eraAnpm      normalize angle into range +/- pi
119 **     eraPvtob     position/velocity of terrestrial station
120 **
121 **  This revision:   2021 February 24
122 **
123 **  Copyright (C) 2013-2021, NumFOCUS Foundation.
124 **  Derived, with permission, from the SOFA library.  See notes at end of file.
125 */
126 {
127    double r[3][3], a, b, eral, c, pv[2][3];
128 
129 
130 /* Form the rotation matrix, CIRS to apparent [HA,Dec]. */
131    eraIr(r);
132    eraRz(theta+sp, r);
133    eraRy(-xp, r);
134    eraRx(-yp, r);
135    eraRz(elong, r);
136 
137 /* Solve for local Earth rotation angle. */
138    a = r[0][0];
139    b = r[0][1];
140    eral = ( a != 0.0 || b != 0.0 ) ?  atan2(b, a) : 0.0;
141    astrom->eral = eral;
142 
143 /* Solve for polar motion [X,Y] with respect to local meridian. */
144    a = r[0][0];
145    c = r[0][2];
146    astrom->xpl = atan2(c, sqrt(a*a+b*b));
147    a = r[1][2];
148    b = r[2][2];
149    astrom->ypl = ( a != 0.0 || b != 0.0 ) ? -atan2(a, b) : 0.0;
150 
151 /* Adjusted longitude. */
152    astrom->along = eraAnpm(eral - theta);
153 
154 /* Functions of latitude. */
155    astrom->sphi = sin(phi);
156    astrom->cphi = cos(phi);
157 
158 /* Observer's geocentric position and velocity (m, m/s, CIRS). */
159    eraPvtob(elong, phi, hm, xp, yp, sp, theta, pv);
160 
161 /* Magnitude of diurnal aberration vector. */
162    astrom->diurab = sqrt(pv[1][0]*pv[1][0]+pv[1][1]*pv[1][1]) / ERFA_CMPS;
163 
164 /* Refraction constants. */
165    astrom->refa = refa;
166    astrom->refb = refb;
167 
168 /* Finished. */
169 
170 }
171 /*----------------------------------------------------------------------
172 **
173 **
174 **  Copyright (C) 2013-2021, NumFOCUS Foundation.
175 **  All rights reserved.
176 **
177 **  This library is derived, with permission, from the International
178 **  Astronomical Union's "Standards of Fundamental Astronomy" library,
179 **  available from http://www.iausofa.org.
180 **
181 **  The ERFA version is intended to retain identical functionality to
182 **  the SOFA library, but made distinct through different function and
183 **  file names, as set out in the SOFA license conditions.  The SOFA
184 **  original has a role as a reference standard for the IAU and IERS,
185 **  and consequently redistribution is permitted only in its unaltered
186 **  state.  The ERFA version is not subject to this restriction and
187 **  therefore can be included in distributions which do not support the
188 **  concept of "read only" software.
189 **
190 **  Although the intent is to replicate the SOFA API (other than
191 **  replacement of prefix names) and results (with the exception of
192 **  bugs;  any that are discovered will be fixed), SOFA is not
193 **  responsible for any errors found in this version of the library.
194 **
195 **  If you wish to acknowledge the SOFA heritage, please acknowledge
196 **  that you are using a library derived from SOFA, rather than SOFA
197 **  itself.
198 **
199 **
200 **  TERMS AND CONDITIONS
201 **
202 **  Redistribution and use in source and binary forms, with or without
203 **  modification, are permitted provided that the following conditions
204 **  are met:
205 **
206 **  1 Redistributions of source code must retain the above copyright
207 **    notice, this list of conditions and the following disclaimer.
208 **
209 **  2 Redistributions in binary form must reproduce the above copyright
210 **    notice, this list of conditions and the following disclaimer in
211 **    the documentation and/or other materials provided with the
212 **    distribution.
213 **
214 **  3 Neither the name of the Standards Of Fundamental Astronomy Board,
215 **    the International Astronomical Union nor the names of its
216 **    contributors may be used to endorse or promote products derived
217 **    from this software without specific prior written permission.
218 **
219 **  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
220 **  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
221 **  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
222 **  FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
223 **  COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
224 **  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
225 **  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
226 **  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
227 **  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
228 **  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
229 **  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
230 **  POSSIBILITY OF SUCH DAMAGE.
231 **
232 */
233