source: Sophya/trunk/SophyaExt/XephemAstroLib/refract.c@ 1719

Last change on this file since 1719 was 1719, checked in by cmv, 24 years ago

Adapted to version 3.5 xephem cmv 22/10/2001

File size: 2.2 KB
Line 
1#include <stdio.h>
2#include <math.h>
3
4#include "P_.h"
5#include "astro.h"
6
7static void unrefractLT15 P_((double pr, double tr, double aa, double *ta));
8static void unrefractGE15 P_((double pr, double tr, double aa, double *ta));
9
10void
11unrefract (pr, tr, aa, ta)
12double pr, tr;
13double aa;
14double *ta;
15{
16#define LTLIM 14.5
17#define GELIM 15.5
18
19 double aadeg = raddeg(aa);
20
21 if (aadeg < LTLIM)
22 unrefractLT15 (pr, tr, aa, ta);
23 else if (aadeg >= GELIM)
24 unrefractGE15 (pr, tr, aa, ta);
25 else {
26 /* smooth blend -- important for inverse */
27 double taLT, taGE, p;
28
29 unrefractLT15 (pr, tr, aa, &taLT);
30 unrefractGE15 (pr, tr, aa, &taGE);
31 p = (aadeg - LTLIM)/(GELIM - LTLIM);
32 *ta = taLT + (taGE - taLT)*p;
33 }
34}
35
36static void
37unrefractGE15 (pr, tr, aa, ta)
38double pr, tr;
39double aa;
40double *ta;
41{
42 double r;
43
44 r = 7.888888e-5*pr/((273+tr)*tan(aa));
45 *ta = aa - r;
46}
47
48static void
49unrefractLT15 (pr, tr, aa, ta)
50double pr, tr;
51double aa;
52double *ta;
53{
54 double aadeg = raddeg(aa);
55 double r, a, b;
56
57 a = ((2e-5*aadeg+1.96e-2)*aadeg+1.594e-1)*pr;
58 b = (273+tr)*((8.45e-2*aadeg+5.05e-1)*aadeg+1);
59 r = degrad(a/b);
60
61 *ta = (aa < 0 && r < 0) ? aa : aa - r; /* 0 below ~5 degs */
62}
63
64/* correct the true altitude, ta, for refraction to the apparent altitude, aa,
65 * each in radians, given the local atmospheric pressure, pr, in mbars, and
66 * the temperature, tr, in degrees C.
67 */
68void
69refract (pr, tr, ta, aa)
70double pr, tr;
71double ta;
72double *aa;
73{
74#define MAXRERR degrad(0.1/3600.) /* desired accuracy, rads */
75
76 double d, t, t0, a;
77
78 /* first guess of error is to go backwards.
79 * make use that we know delta-apparent is always < delta-true.
80 */
81 unrefract (pr, tr, ta, &t);
82 d = 0.8*(ta - t);
83 t0 = t;
84 a = ta;
85
86 /* use secant method to discover a value that unrefracts to ta.
87 * max=7 ave=2.4 loops in hundreds of test cases.
88 */
89 do {
90 a += d;
91 unrefract (pr, tr, a, &t);
92 d *= -(ta - t)/(t0 - t);
93 t0 = t;
94 } while (fabs(ta-t) > MAXRERR);
95
96 *aa = a;
97
98#undef MAXRERR
99}
100
101/* For RCS Only -- Do Not Edit */
102static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: refract.c,v $ $Date: 2001-10-22 12:08:27 $ $Revision: 1.2 $ $Name: not supported by cvs2svn $"};
Note: See TracBrowser for help on using the repository browser.