File Coverage

erfasrc/src/ldn.c
Criterion Covered Total %
statement 0 10 0.0
branch 0 4 0.0
condition n/a
subroutine n/a
pod n/a
total 0 14 0.0


line stmt bran cond sub pod time code
1             #include "erfa.h"
2              
3 0           void eraLdn(int n, eraLDBODY b[], double ob[3], double sc[3],
4             double sn[3])
5             /*+
6             ** - - - - - - -
7             ** e r a L d n
8             ** - - - - - - -
9             **
10             ** For a star, apply light deflection by multiple solar-system bodies,
11             ** as part of transforming coordinate direction into natural direction.
12             **
13             ** Given:
14             ** n int number of bodies (note 1)
15             ** b eraLDBODY[n] data for each of the n bodies (Notes 1,2):
16             ** bm double mass of the body (solar masses, Note 3)
17             ** dl double deflection limiter (Note 4)
18             ** pv [2][3] barycentric PV of the body (au, au/day)
19             ** ob double[3] barycentric position of the observer (au)
20             ** sc double[3] observer to star coord direction (unit vector)
21             **
22             ** Returned:
23             ** sn double[3] observer to deflected star (unit vector)
24             **
25             ** 1) The array b contains n entries, one for each body to be
26             ** considered. If n = 0, no gravitational light deflection will be
27             ** applied, not even for the Sun.
28             **
29             ** 2) The array b should include an entry for the Sun as well as for
30             ** any planet or other body to be taken into account. The entries
31             ** should be in the order in which the light passes the body.
32             **
33             ** 3) In the entry in the b array for body i, the mass parameter
34             ** b[i].bm can, as required, be adjusted in order to allow for such
35             ** effects as quadrupole field.
36             **
37             ** 4) The deflection limiter parameter b[i].dl is phi^2/2, where phi is
38             ** the angular separation (in radians) between star and body at
39             ** which limiting is applied. As phi shrinks below the chosen
40             ** threshold, the deflection is artificially reduced, reaching zero
41             ** for phi = 0. Example values suitable for a terrestrial
42             ** observer, together with masses, are as follows:
43             **
44             ** body i b[i].bm b[i].dl
45             **
46             ** Sun 1.0 6e-6
47             ** Jupiter 0.00095435 3e-9
48             ** Saturn 0.00028574 3e-10
49             **
50             ** 5) For cases where the starlight passes the body before reaching the
51             ** observer, the body is placed back along its barycentric track by
52             ** the light time from that point to the observer. For cases where
53             ** the body is "behind" the observer no such shift is applied. If
54             ** a different treatment is preferred, the user has the option of
55             ** instead using the eraLd function. Similarly, eraLd can be used
56             ** for cases where the source is nearby, not a star.
57             **
58             ** 6) The returned vector sn is not normalized, but the consequential
59             ** departure from unit magnitude is always negligible.
60             **
61             ** 7) The arguments sc and sn can be the same array.
62             **
63             ** 8) For efficiency, validation is omitted. The supplied masses must
64             ** be greater than zero, the position and velocity vectors must be
65             ** right, and the deflection limiter greater than zero.
66             **
67             ** Reference:
68             **
69             ** Urban, S. & Seidelmann, P. K. (eds), Explanatory Supplement to
70             ** the Astronomical Almanac, 3rd ed., University Science Books
71             ** (2013), Section 7.2.4.
72             **
73             ** Called:
74             ** eraCp copy p-vector
75             ** eraPdp scalar product of two p-vectors
76             ** eraPmp p-vector minus p-vector
77             ** eraPpsp p-vector plus scaled p-vector
78             ** eraPn decompose p-vector into modulus and direction
79             ** eraLd light deflection by a solar-system body
80             **
81             ** Copyright (C) 2013-2019, NumFOCUS Foundation.
82             ** Derived, with permission, from the SOFA library. See notes at end of file.
83             */
84             {
85             /* Light time for 1 au (days) */
86             const double CR = ERFA_AULT/ERFA_DAYSEC;
87              
88             int i;
89             double v[3], dt, ev[3], em, e[3];
90              
91              
92             /* Star direction prior to deflection. */
93 0           eraCp(sc, sn);
94              
95             /* Body by body. */
96 0 0         for ( i = 0; i < n; i++ ) {
97              
98             /* Body to observer vector at epoch of observation (au). */
99 0           eraPmp ( ob, b[i].pv[0], v );
100              
101             /* Minus the time since the light passed the body (days). */
102 0           dt = eraPdp(sn,v) * CR;
103              
104             /* Neutralize if the star is "behind" the observer. */
105 0 0         dt = ERFA_GMIN(dt, 0.0);
106              
107             /* Backtrack the body to the time the light was passing the body. */
108 0           eraPpsp(v, -dt, b[i].pv[1], ev);
109              
110             /* Body to observer vector as magnitude and direction. */
111 0           eraPn(ev, &em, e);
112              
113             /* Apply light deflection for this body. */
114 0           eraLd ( b[i].bm, sn, sn, e, em, b[i].dl, sn );
115              
116             /* Next body. */
117             }
118              
119             /* Finished. */
120              
121 0           }
122             /*----------------------------------------------------------------------
123             **
124             **
125             ** Copyright (C) 2013-2019, NumFOCUS Foundation.
126             ** All rights reserved.
127             **
128             ** This library is derived, with permission, from the International
129             ** Astronomical Union's "Standards of Fundamental Astronomy" library,
130             ** available from http://www.iausofa.org.
131             **
132             ** The ERFA version is intended to retain identical functionality to
133             ** the SOFA library, but made distinct through different function and
134             ** file names, as set out in the SOFA license conditions. The SOFA
135             ** original has a role as a reference standard for the IAU and IERS,
136             ** and consequently redistribution is permitted only in its unaltered
137             ** state. The ERFA version is not subject to this restriction and
138             ** therefore can be included in distributions which do not support the
139             ** concept of "read only" software.
140             **
141             ** Although the intent is to replicate the SOFA API (other than
142             ** replacement of prefix names) and results (with the exception of
143             ** bugs; any that are discovered will be fixed), SOFA is not
144             ** responsible for any errors found in this version of the library.
145             **
146             ** If you wish to acknowledge the SOFA heritage, please acknowledge
147             ** that you are using a library derived from SOFA, rather than SOFA
148             ** itself.
149             **
150             **
151             ** TERMS AND CONDITIONS
152             **
153             ** Redistribution and use in source and binary forms, with or without
154             ** modification, are permitted provided that the following conditions
155             ** are met:
156             **
157             ** 1 Redistributions of source code must retain the above copyright
158             ** notice, this list of conditions and the following disclaimer.
159             **
160             ** 2 Redistributions in binary form must reproduce the above copyright
161             ** notice, this list of conditions and the following disclaimer in
162             ** the documentation and/or other materials provided with the
163             ** distribution.
164             **
165             ** 3 Neither the name of the Standards Of Fundamental Astronomy Board,
166             ** the International Astronomical Union nor the names of its
167             ** contributors may be used to endorse or promote products derived
168             ** from this software without specific prior written permission.
169             **
170             ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
171             ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
172             ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
173             ** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
174             ** COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
175             ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
176             ** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
177             ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
178             ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
179             ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
180             ** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
181             ** POSSIBILITY OF SUCH DAMAGE.
182             **
183             */