| [1457] | 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 | static void | 
|---|
|  | 37 | unrefractGE15 (pr, tr, aa, ta) | 
|---|
|  | 38 | double pr, tr; | 
|---|
|  | 39 | double aa; | 
|---|
|  | 40 | double *ta; | 
|---|
|  | 41 | { | 
|---|
|  | 42 | double r; | 
|---|
|  | 43 |  | 
|---|
|  | 44 | r = 7.888888e-5*pr/((273+tr)*tan(aa)); | 
|---|
|  | 45 | *ta  =  aa - r; | 
|---|
|  | 46 | } | 
|---|
|  | 47 |  | 
|---|
|  | 48 | static void | 
|---|
|  | 49 | unrefractLT15 (pr, tr, aa, ta) | 
|---|
|  | 50 | double pr, tr; | 
|---|
|  | 51 | double aa; | 
|---|
|  | 52 | double *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 |  | 
|---|
| [1719] | 61 | *ta  =  (aa < 0 && r < 0) ? aa : aa - r;        /* 0 below ~5 degs */ | 
|---|
| [1457] | 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 | */ | 
|---|
|  | 68 | void | 
|---|
|  | 69 | refract (pr, tr, ta, aa) | 
|---|
|  | 70 | double pr, tr; | 
|---|
|  | 71 | double ta; | 
|---|
|  | 72 | double *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 */ | 
|---|
| [1719] | 102 | static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: refract.c,v $ $Date: 2001-10-22 12:08:27 $ $Revision: 1.2 $ $Name: not supported by cvs2svn $"}; | 
|---|