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

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

import de la partie libastro de Xephem cmv+rz 10/4/2001

File size: 2.1 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}
36
37static void
38unrefractGE15 (pr, tr, aa, ta)
39double pr, tr;
40double aa;
41double *ta;
42{
43 double r;
44
45 r = 7.888888e-5*pr/((273+tr)*tan(aa));
46 *ta = aa - r;
47}
48
49static void
50unrefractLT15 (pr, tr, aa, ta)
51double pr, tr;
52double aa;
53double *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 */
69void
70refract (pr, tr, ta, aa)
71double pr, tr;
72double ta;
73double *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 */
103static 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 $"};
Note: See TracBrowser for help on using the repository browser.