source: Sophya/trunk/SophyaExt/XephemAstroLib/jupmoon.c@ 2551

Last change on this file since 2551 was 2551, checked in by cmv, 21 years ago

nouvelle version de xephem/libastro (3.6) cmv 15/6/04

File size: 8.8 KB
Line 
1/* jupiter moon info */
2
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6#include <math.h>
7
8#include "astro.h"
9#include "bdl.h"
10
11static int use_bdl (double jd, char *dir, MoonData md[J_NMOONS]);
12static void meeus_jupiter (double d, double *cmlI, double *cmlII,
13 MoonData md[J_NMOONS]);
14static void moonradec (double jupsize, MoonData md[J_NMOONS]);
15static void moonSVis (Obj *eop, Obj *jop, MoonData md[J_NMOONS]);
16static void moonEVis (MoonData md[J_NMOONS]);
17
18/* moon table and a few other goodies and when it was last computed */
19static double mdmjd = -123456;
20static MoonData jmd[J_NMOONS] = {
21 {"Jupiter", NULL},
22 {"Io", "I"},
23 {"Europa", "II"},
24 {"Ganymede", "III"},
25 {"Callisto", "IV"}
26};
27static double sizemjd; /* size at last mjd */
28static double cmlImjd; /* central meridian long sys I, at last mjd */
29static double cmlIImjd; /* " II " */
30
31/* file containing BDL coefficients */
32static char jbdlfn[] = "jupiter.9910";
33
34/* get jupiter info in md[0], moon info in md[1..J_NMOONS-1].
35 * if !dir always use meeus model.
36 * if !jop caller just wants md[] for names
37 * N.B. we assume eop and jop are updated.
38 */
39void
40jupiter_data (
41double Mjd, /* mjd */
42char dir[], /* dir in which to look for helper files */
43Obj *eop, /* earth == Sun */
44Obj *jop, /* jupiter */
45double *sizep, /* jup angular diam, rads */
46double *cmlI, double *cmlII, /* central meridian longitude, rads */
47MoonData md[J_NMOONS]) /* return info */
48{
49 double JD;
50
51 /* always copy back at least for name */
52 memcpy (md, jmd, sizeof(jmd));
53
54 /* nothing else if repeat call or just want names */
55 if (Mjd == mdmjd || !jop) {
56 if (jop) {
57 *sizep = sizemjd;
58 *cmlI = cmlImjd;
59 *cmlII = cmlIImjd;
60 }
61 return;
62 }
63 JD = Mjd + MJD0;
64
65 /* planet in [0] */
66 md[0].ra = jop->s_ra;
67 md[0].dec = jop->s_dec;
68 md[0].mag = get_mag(jop);
69 md[0].x = 0;
70 md[0].y = 0;
71 md[0].z = 0;
72 md[0].evis = 1;
73 md[0].svis = 1;
74
75 /* size is straight from jop */
76 *sizep = degrad(jop->s_size/3600.0);
77
78 /* mags from JPL ephemeris */
79 md[1].mag = 5.7;
80 md[2].mag = 5.8;
81 md[3].mag = 5.3;
82 md[4].mag = 6.7;
83
84 /* get moon data from BDL if possible, else Meeus' model.
85 * always use Meeus for cml
86 */
87 if (dir && use_bdl (JD, dir, md) == 0)
88 meeus_jupiter (Mjd, cmlI, cmlII, NULL);
89 else
90 meeus_jupiter (Mjd, cmlI, cmlII, md);
91
92 /* set visibilities */
93 moonSVis (eop, jop, md);
94 moonEVis (md);
95
96 /* fill in moon ra and dec */
97 moonradec (*sizep, md);
98
99 /* save */
100 mdmjd = Mjd;
101 sizemjd = *sizep;
102 cmlImjd = *cmlI;
103 cmlIImjd = *cmlII;
104 memcpy (jmd, md, sizeof(jmd));
105}
106
107/* hunt for BDL file in dir[] and use if possible
108 * return 0 if ok, else -1
109 */
110static int
111use_bdl (
112double JD, /* julian date */
113char dir[], /* directory */
114MoonData md[J_NMOONS]) /* fill md[1..NM-1].x/y/z for each moon */
115{
116#define JUPRAU .0004769108 /* jupiter radius, AU */
117 double x[J_NMOONS], y[J_NMOONS], z[J_NMOONS];
118 char buf[1024];
119 FILE *fp;
120 int i;
121
122 /* only valid 1999 through 2010 */
123 if (JD < 2451179.50000 || JD >= 2455562.5)
124 return (-1);
125
126 /* open */
127 (void) sprintf (buf, "%s/%s", dir, jbdlfn);
128 fp = fopen (buf, "r");
129 if (!fp)
130 return (-1);
131
132 /* use it */
133 if ((i = read_bdl (fp, JD, x, y, z, buf)) < 0) {
134 fprintf (stderr, "%s: %s\n", jbdlfn, buf);
135 fclose (fp);
136 return (-1);
137 }
138 if (i != J_NMOONS-1) {
139 fprintf (stderr, "%s: BDL says %d moons, code expects %d", jbdlfn,
140 i, J_NMOONS-1);
141 fclose (fp);
142 return (-1);
143 }
144
145 /* copy into md[1..NM-1] with our scale and sign conventions */
146 for (i = 1; i < J_NMOONS; i++) {
147 md[i].x = x[i-1]/JUPRAU; /* we want jup radii +E */
148 md[i].y = -y[i-1]/JUPRAU; /* we want jup radii +S */
149 md[i].z = -z[i-1]/JUPRAU; /* we want jup radii +front */
150 }
151
152 /* ok */
153 fclose (fp);
154 return (0);
155}
156
157/* compute location of GRS and Galilean moons.
158 * if md == NULL, just to cml.
159 * from "Astronomical Formulae for Calculators", 2nd ed, by Jean Meeus,
160 * Willmann-Bell, Richmond, Va., U.S.A. (c) 1982, chapters 35 and 36.
161 */
162static void
163meeus_jupiter(
164double d,
165double *cmlI, double *cmlII, /* central meridian longitude, rads */
166MoonData md[J_NMOONS]) /* fill in md[1..NM-1].x/y/z for each moon.
167 * N.B. md[0].ra/dec must already be set
168 */
169{
170#define POLE_RA degrad(268.05) /* RA of Jupiter's north pole */
171#define POLE_DEC degrad(64.50) /* Dec of Jupiter's north pole */
172#define dsin(x) sin(degrad(x))
173#define dcos(x) cos(degrad(x))
174 double A, B, Del, J, K, M, N, R, V;
175 double cor_u1, cor_u2, cor_u3, cor_u4;
176 double solc, tmp, G, H, psi, r, r1, r2, r3, r4;
177 double u1, u2, u3, u4;
178 double lam, Ds;
179 double z1, z2, z3, z4;
180 double De, dsinDe;
181 double theta, phi;
182 double tvc, pvc;
183 double salpha, calpha;
184 int i;
185
186 V = 134.63 + 0.00111587 * d;
187
188 M = (358.47583 + 0.98560003*d);
189 N = (225.32833 + 0.0830853*d) + 0.33 * dsin (V);
190
191 J = 221.647 + 0.9025179*d - 0.33 * dsin(V);
192
193 A = 1.916*dsin(M) + 0.02*dsin(2*M);
194 B = 5.552*dsin(N) + 0.167*dsin(2*N);
195 K = (J+A-B);
196 R = 1.00014 - 0.01672 * dcos(M) - 0.00014 * dcos(2*M);
197 r = 5.20867 - 0.25192 * dcos(N) - 0.00610 * dcos(2*N);
198 Del = sqrt (R*R + r*r - 2*R*r*dcos(K));
199 psi = raddeg (asin (R/Del*dsin(K)));
200
201 *cmlI = degrad(268.28 + 877.8169088*(d - Del/173) + psi - B);
202 range (cmlI, 2*PI);
203 *cmlII = degrad(290.28 + 870.1869088*(d - Del/173) + psi - B);
204 range (cmlII, 2*PI);
205
206 /* that's it if don't want moon info too */
207 if (!md)
208 return;
209
210 solc = (d - Del/173.); /* speed of light correction */
211 tmp = psi - B;
212
213 u1 = 84.5506 + 203.4058630 * solc + tmp;
214 u2 = 41.5015 + 101.2916323 * solc + tmp;
215 u3 = 109.9770 + 50.2345169 * solc + tmp;
216 u4 = 176.3586 + 21.4879802 * solc + tmp;
217
218 G = 187.3 + 50.310674 * solc;
219 H = 311.1 + 21.569229 * solc;
220
221 cor_u1 = 0.472 * dsin (2*(u1-u2));
222 cor_u2 = 1.073 * dsin (2*(u2-u3));
223 cor_u3 = 0.174 * dsin (G);
224 cor_u4 = 0.845 * dsin (H);
225
226 r1 = 5.9061 - 0.0244 * dcos (2*(u1-u2));
227 r2 = 9.3972 - 0.0889 * dcos (2*(u2-u3));
228 r3 = 14.9894 - 0.0227 * dcos (G);
229 r4 = 26.3649 - 0.1944 * dcos (H);
230
231 md[1].x = -r1 * dsin (u1+cor_u1);
232 md[2].x = -r2 * dsin (u2+cor_u2);
233 md[3].x = -r3 * dsin (u3+cor_u3);
234 md[4].x = -r4 * dsin (u4+cor_u4);
235
236 lam = 238.05 + 0.083091*d + 0.33*dsin(V) + B;
237 Ds = 3.07*dsin(lam + 44.5);
238 De = Ds - 2.15*dsin(psi)*dcos(lam+24.)
239 - 1.31*(r-Del)/Del*dsin(lam-99.4);
240 dsinDe = dsin(De);
241
242 z1 = r1 * dcos(u1+cor_u1);
243 z2 = r2 * dcos(u2+cor_u2);
244 z3 = r3 * dcos(u3+cor_u3);
245 z4 = r4 * dcos(u4+cor_u4);
246
247 md[1].y = z1*dsinDe;
248 md[2].y = z2*dsinDe;
249 md[3].y = z3*dsinDe;
250 md[4].y = z4*dsinDe;
251
252 /* compute sky transformation angle as triple vector product */
253 tvc = PI/2.0 - md[0].dec;
254 pvc = md[0].ra;
255 theta = PI/2.0 - POLE_DEC;
256 phi = POLE_RA;
257 salpha = -sin(tvc)*sin(theta)*(cos(pvc)*sin(phi) - sin(pvc)*cos(phi));
258 calpha = sqrt (1.0 - salpha*salpha);
259
260 for (i = 0; i < J_NMOONS; i++) {
261 double tx = md[i].x*calpha + md[i].y*salpha;
262 double ty = -md[i].x*salpha + md[i].y*calpha;
263 md[i].x = tx;
264 md[i].y = ty;
265 }
266
267 md[1].z = z1;
268 md[2].z = z2;
269 md[3].z = z3;
270 md[4].z = z4;
271}
272
273
274/* given jupiter loc in md[0].ra/dec and size, and location of each moon in
275 * md[1..NM-1].x/y in jup radii, find ra/dec of each moon in md[1..NM-1].ra/dec.
276 */
277static void
278moonradec (
279double jupsize, /* jup diameter, rads */
280MoonData md[J_NMOONS]) /* fill in RA and Dec */
281{
282 double juprad = jupsize/2;
283 double jupra = md[0].ra;
284 double jupdec = md[0].dec;
285 int i;
286
287 for (i = 1; i < J_NMOONS; i++) {
288 double dra = juprad * md[i].x;
289 double ddec = juprad * md[i].y;
290 md[i].ra = jupra + dra;
291 md[i].dec = jupdec - ddec;
292 }
293}
294
295/* set svis according to whether moon is in sun light */
296static void
297moonSVis(
298Obj *eop, /* earth == SUN */
299Obj *jop, /* jupiter */
300MoonData md[J_NMOONS])
301{
302 double esd = eop->s_edist;
303 double eod = jop->s_edist;
304 double sod = jop->s_sdist;
305 double soa = degrad(jop->s_elong);
306 double esa = asin(esd*sin(soa)/sod);
307 double h = sod*jop->s_hlat;
308 double nod = h*(1./eod - 1./sod);
309 double sca = cos(esa), ssa = sin(esa);
310 int i;
311
312 for (i = 1; i < J_NMOONS; i++) {
313 MoonData *mdp = &md[i];
314 double xp = sca*mdp->x + ssa*mdp->z;
315 double yp = mdp->y;
316 double zp = -ssa*mdp->x + sca*mdp->z;
317 double ca = cos(nod), sa = sin(nod);
318 double xpp = xp;
319 double ypp = ca*yp - sa*zp;
320 double zpp = sa*yp + ca*zp;
321 int outside = xpp*xpp + ypp*ypp > 1.0;
322 int infront = zpp > 0.0;
323 mdp->svis = outside || infront;
324 }
325}
326
327/* set evis according to whether moon is geometrically visible from earth */
328static void
329moonEVis (MoonData md[J_NMOONS])
330{
331 int i;
332
333 for (i = 1; i < J_NMOONS; i++) {
334 MoonData *mdp = &md[i];
335 int outside = mdp->x*mdp->x + mdp->y*mdp->y > 1.0;
336 int infront = mdp->z > 0.0;
337 mdp->evis = outside || infront;
338 }
339}
340
341/* For RCS Only -- Do Not Edit */
342static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: jupmoon.c,v $ $Date: 2004-06-15 16:54:12 $ $Revision: 1.1 $ $Name: not supported by cvs2svn $"};
Note: See TracBrowser for help on using the repository browser.