source: Sophya/trunk/SophyaExt/XephemAstroLib/mooncolong.c@ 4012

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

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

File size: 6.2 KB
Line 
1/* code to compute lunar sunrise position and local sun angle.
2 */
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <math.h>
7
8#include "astro.h"
9
10static void Librations (double RAD, double LAMH, double BH, double OM,
11 double F, double L, double L1, double *L0, double *B0);
12static void Moon (double RAD, double T, double T2, double LAM0, double R,
13 double M, double *F, double *L1, double *OM, double *LAM, double *B,
14 double *DR, double *LAMH, double *BH);
15static void Sun (double RAD, double T, double T2, double *L, double *M,
16 double *R, double *LAM0);
17
18/* given a Julian date and a lunar location, find selenographic colongitude of
19 * rising sun, lunar latitude of subsolar point, illuminated fraction, and alt
20 * of sun at the given location. Any pointer may be 0 if not interested.
21 * From Bruning and Talcott, October 1995 _Astronomy_, page 76.
22 * N.B. lunar coordinates use +E, but selenograhic colongs are +W.
23 */
24void
25moon_colong (
26double jd, /* jd */
27double lt, /* lat of location on moon, rads +N +E */
28double lg, /* long of location on moon, rads +N +E */
29double *cp, /* selenographic colongitude (-lng of rising sun), rads */
30double *kp, /* illuminated fraction of surface from Earth */
31double *ap, /* sun altitude at location, rads */
32double *sp) /* lunar latitude of subsolar point, rads */
33{
34 double RAD = .0174533;
35 double T;
36 double T2;
37 double L, M, R, LAM0;
38 double F, L1, OM, LAM, B, DR, LAMH, BH;
39 double L0, B0;
40 double TEMP;
41 double C0;
42 double PSI;
43 double NUM, DEN;
44 double I, K;
45 double THETA, ETA;
46 double H;
47
48 T = (jd - 2451545)/36525.0;
49 T2 = T * T;
50
51 Sun(RAD, T, T2, &L, &M, &R, &LAM0);
52 Moon(RAD, T, T2, LAM0, R, M, &F, &L1, &OM, &LAM, &B, &DR, &LAMH, &BH);
53 Librations(RAD, LAMH, BH, OM, F, L, L1, &L0, &B0);
54 if (sp)
55 *sp = B0;
56
57 TEMP = L0 / 360;
58 L0 = ((TEMP) - (int)(TEMP)) * 360;
59 if (L0 < 0) L0 = L0 + 360;
60 if (L0 <= 90) C0 = 90 - L0; else C0 = 450 - L0;
61 if (cp) {
62 *cp = degrad(C0);
63 range (cp, 2*PI); /* prefer 0..360 +W */
64 }
65
66 if (kp) {
67 TEMP = cos(B * RAD) * cos(LAM - LAM0 * RAD);
68 PSI = acos(TEMP);
69 NUM = R * sin(PSI);
70 DEN = DR - R * TEMP;
71 I = atan(NUM / DEN);
72 if (NUM * DEN < 0) I = I + 3.14159;
73 if (NUM < 0) I = I + 3.14159;
74 K = (1 + cos(I)) / 2;
75 *kp = K;
76 }
77
78 if (ap) {
79 THETA = lt;
80 ETA = lg;
81 C0 = C0 * RAD;
82 TEMP = sin(B0) * sin(THETA) + cos(B0) * cos(THETA) * sin(C0+ETA);
83 H = asin(TEMP);
84 *ap = H;
85 }
86}
87
88static void
89Librations (double RAD, double LAMH, double BH, double OM, double F,
90double L, double L1, double *L0, double *B0)
91{
92 double I, PSI, W, NUM, DEN, A, TEMP;
93
94 /* inclination of lunar equator */
95 I = 1.54242 * RAD;
96
97 /* nutation in longitude, in arcseconds */
98 PSI = -17.2 * sin(OM) - 1.32 * sin(2 * L) - .23 * sin(2 * L1) +
99 .21 * sin(2 * OM);
100 PSI = PSI * RAD / 3600;
101
102 /* optical librations */
103 W = (LAMH - PSI) - OM;
104 NUM = sin(W) * cos(BH) * cos(I) - sin(BH) * sin(I);
105 DEN = cos(W) * cos(BH);
106 A = atan(NUM / DEN);
107 if (NUM * DEN < 0) A = A + 3.14159;
108 if (NUM < 0) A = A + 3.14159;
109 *L0 = (A - F) / RAD;
110 TEMP = -sin(W) * cos(BH) * sin(I) - sin(BH) * cos(I);
111 *B0 = asin(TEMP);
112}
113
114static void
115Moon (double RAD, double T, double T2, double LAM0, double R, double M,
116double *F, double *L1, double *OM, double *LAM, double *B, double *DR,
117double *LAMH, double *BH)
118{
119 double T3, M1, D2, SUMR, SUML, DIST;
120
121 T3 = T * T2;
122
123 /* argument of the latitude of the Moon */
124 *F = (93.2721 + 483202 * T - .003403 * T2 - T3 / 3526000) * RAD;
125
126 /* mean longitude of the Moon */
127 *L1 = (218.316 + 481268. * T) * RAD;
128
129 /* longitude of the ascending node of Moon's mean orbit */
130 *OM = (125.045 - 1934.14 * T + .002071 * T2 + T3 / 450000) * RAD;
131
132 /* Moon's mean anomaly */
133 M1 = (134.963 + 477199 * T + .008997 * T2 + T3 / 69700) * RAD;
134
135 /* mean elongation of the Moon */
136 D2 = (297.85 + 445267 * T - .00163 * T2 + T3 / 545900) * 2 * RAD;
137
138 /* Lunar distance */
139 SUMR = -20954 * cos(M1) - 3699 * cos(D2 - M1) - 2956 * cos(D2);
140 *DR = 385000 + SUMR;
141
142 /* geocentric latitude */
143 *B = 5.128 * sin(*F) + .2806 * sin(M1 + *F) + .2777 * sin(M1 - *F) +
144 .1732 * sin(D2 - *F);
145 SUML = 6.289 * sin(M1) + 1.274 * sin(D2 - M1) + .6583 * sin(D2) +
146 .2136 * sin(2 * M1) - .1851 * sin(M) - .1143 * sin(2 * *F);
147 *LAM = *L1 + SUML * RAD;
148 DIST = *DR / R;
149 *LAMH = (LAM0 + 180 + DIST * cos(*B) * sin(LAM0 * RAD - *LAM) / RAD)
150 * RAD;
151 *BH = DIST * *B * RAD;
152}
153
154static void
155Sun (double RAD, double T, double T2, double *L, double *M, double *R,
156double *LAM0)
157{
158 double T3, C, V, E, THETA, OM;
159
160 T3 = T2 * T;
161
162 /* mean longitude of the Sun */
163 *L = 280.466 + 36000.8 * T;
164
165 /* mean anomaly of the Sun */
166 *M = 357.529 + 35999 * T - .0001536 * T2 + T3 / 24490000;
167 *M = *M * RAD;
168
169 /* correction for Sun's elliptical orbit */
170 C = (1.915 - .004817 * T - .000014 * T2) * sin(*M) +
171 (.01999 - .000101 * T) * sin(2 * *M) + .00029 * sin(3 * *M);
172
173 /* true anomaly of the Sun */
174 V = *M + C * RAD;
175
176 /* eccentricity of Earth's orbit */
177 E = .01671 - .00004204 * T - .0000001236 * T2;
178
179 /* Sun-Earth distance */
180 *R = .99972 / (1 + E * cos(V)) * 145980000;
181
182 /* true geometric longitude of the Sun */
183 THETA = *L + C;
184
185 /* apparent longitude of the Sun */
186 OM = 125.04 - 1934.1 * T;
187 *LAM0 = THETA - .00569 - .00478 * sin(OM * RAD);
188}
189
190#ifdef TESTCOLONG
191
192/* insure 0 <= *v < r.
193 */
194void
195range (v, r)
196double *v, r;
197{
198 *v -= r*floor(*v/r);
199}
200
201/* To be sure the program is functioning properly, try the test case
202 * 2449992.5 (1 Oct 1995): the colongitude should be 3.69 degrees.
203 */
204int
205main (int ac, char *av[])
206{
207 double jd, lt, lg;
208 double c, k, a;
209
210 if (ac != 2) {
211 fprintf (stderr, "%s: JD\n", av[0]);
212 abort();
213 }
214
215 jd = atof(av[1]);
216
217 printf ("Latitude of lunar feature: ");
218 fscanf (stdin, "%lf", &lt);
219 lt = degrad(lt);
220 printf ("Longitude: ");
221 fscanf (stdin, "%lf", &lg);
222 lg = degrad(lg);
223
224 moon_colong (jd, lt, lg, &c, &k, &a);
225
226 printf ("Selenographic colongitude is %g\n", raddeg(c));
227 printf ("The illuminated fraction of the Moon is %g\n", k);
228 printf ("Altitude of Sun above feature is %g\n", raddeg(a));
229
230 return (0);
231}
232
233#endif
234
235/* For RCS Only -- Do Not Edit */
236static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: mooncolong.c,v $ $Date: 2009-07-16 10:34:38 $ $Revision: 1.8 $ $Name: not supported by cvs2svn $"};
Note: See TracBrowser for help on using the repository browser.