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

Last change on this file since 3477 was 3477, checked in by cmv, 18 years ago

mise a jour Xephem 3.7.3 , cmv 25/03/2008

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