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

Last change on this file since 3995 was 3654, checked in by cmv, 16 years ago

mise a niveau Xephem 3.7.4, cmv 16/07/2009

File size: 2.1 KB
RevLine 
[1457]1#include <stdio.h>
2#include <math.h>
3
4#include "astro.h"
5
[2551]6static void unrefractLT15 (double pr, double tr, double aa, double *ta);
7static void unrefractGE15 (double pr, double tr, double aa, double *ta);
[1457]8
9void
[2551]10unrefract (double pr, double tr, double aa, double *ta)
[1457]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
[2551]33unrefractGE15 (double pr, double tr, double aa, double *ta)
[1457]34{
35 double r;
36
37 r = 7.888888e-5*pr/((273+tr)*tan(aa));
38 *ta = aa - r;
39}
40
41static void
[2551]42unrefractLT15 (double pr, double tr, double aa, double *ta)
[1457]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
[1719]51 *ta = (aa < 0 && r < 0) ? aa : aa - r; /* 0 below ~5 degs */
[1457]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
[2551]59refract (double pr, double tr, double ta, double *aa)
[1457]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 */
[1895]76 while (1) {
[1457]77 a += d;
78 unrefract (pr, tr, a, &t);
[1895]79 if (fabs(ta-t) <= MAXRERR)
80 break;
[1457]81 d *= -(ta - t)/(t0 - t);
82 t0 = t;
[1895]83 }
[1457]84
85 *aa = a;
86
87#undef MAXRERR
88}
89
90/* For RCS Only -- Do Not Edit */
[3654]91static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: refract.c,v $ $Date: 2009-07-16 10:34:38 $ $Revision: 1.9 $ $Name: not supported by cvs2svn $"};
Note: See TracBrowser for help on using the repository browser.