1 | #include <stdio.h>
|
---|
2 | #include <math.h>
|
---|
3 |
|
---|
4 | #include "P_.h"
|
---|
5 | #include "astro.h"
|
---|
6 |
|
---|
7 | static void unrefractLT15 P_((double pr, double tr, double aa, double *ta));
|
---|
8 | static void unrefractGE15 P_((double pr, double tr, double aa, double *ta));
|
---|
9 |
|
---|
10 | void
|
---|
11 | unrefract (pr, tr, aa, ta)
|
---|
12 | double pr, tr;
|
---|
13 | double aa;
|
---|
14 | double *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 | }
|
---|
36 |
|
---|
37 | static void
|
---|
38 | unrefractGE15 (pr, tr, aa, ta)
|
---|
39 | double pr, tr;
|
---|
40 | double aa;
|
---|
41 | double *ta;
|
---|
42 | {
|
---|
43 | double r;
|
---|
44 |
|
---|
45 | r = 7.888888e-5*pr/((273+tr)*tan(aa));
|
---|
46 | *ta = aa - r;
|
---|
47 | }
|
---|
48 |
|
---|
49 | static void
|
---|
50 | unrefractLT15 (pr, tr, aa, ta)
|
---|
51 | double pr, tr;
|
---|
52 | double aa;
|
---|
53 | double *ta;
|
---|
54 | {
|
---|
55 | double aadeg = raddeg(aa);
|
---|
56 | double r, a, b;
|
---|
57 |
|
---|
58 | a = ((2e-5*aadeg+1.96e-2)*aadeg+1.594e-1)*pr;
|
---|
59 | b = (273+tr)*((8.45e-2*aadeg+5.05e-1)*aadeg+1);
|
---|
60 | r = degrad(a/b);
|
---|
61 |
|
---|
62 | *ta = aa - r;
|
---|
63 | }
|
---|
64 |
|
---|
65 | /* correct the true altitude, ta, for refraction to the apparent altitude, aa,
|
---|
66 | * each in radians, given the local atmospheric pressure, pr, in mbars, and
|
---|
67 | * the temperature, tr, in degrees C.
|
---|
68 | */
|
---|
69 | void
|
---|
70 | refract (pr, tr, ta, aa)
|
---|
71 | double pr, tr;
|
---|
72 | double ta;
|
---|
73 | double *aa;
|
---|
74 | {
|
---|
75 | #define MAXRERR degrad(0.1/3600.) /* desired accuracy, rads */
|
---|
76 |
|
---|
77 | double d, t, t0, a;
|
---|
78 |
|
---|
79 | /* first guess of error is to go backwards.
|
---|
80 | * make use that we know delta-apparent is always < delta-true.
|
---|
81 | */
|
---|
82 | unrefract (pr, tr, ta, &t);
|
---|
83 | d = 0.8*(ta - t);
|
---|
84 | t0 = t;
|
---|
85 | a = ta;
|
---|
86 |
|
---|
87 | /* use secant method to discover a value that unrefracts to ta.
|
---|
88 | * max=7 ave=2.4 loops in hundreds of test cases.
|
---|
89 | */
|
---|
90 | do {
|
---|
91 | a += d;
|
---|
92 | unrefract (pr, tr, a, &t);
|
---|
93 | d *= -(ta - t)/(t0 - t);
|
---|
94 | t0 = t;
|
---|
95 | } while (fabs(ta-t) > MAXRERR);
|
---|
96 |
|
---|
97 | *aa = a;
|
---|
98 |
|
---|
99 | #undef MAXRERR
|
---|
100 | }
|
---|
101 |
|
---|
102 | /* For RCS Only -- Do Not Edit */
|
---|
103 | static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: refract.c,v $ $Date: 2001-04-10 14:40:47 $ $Revision: 1.1.1.1 $ $Name: not supported by cvs2svn $"};
|
---|