source: Sophya/trunk/SophyaExt/XephemAstroLib/umoon.c@ 2865

Last change on this file since 2865 was 2818, checked in by cmv, 20 years ago

Update de Xephem 3.7 cmv 21/08/2005

File size: 6.3 KB
RevLine 
[2551]1/* uranus 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[U_NMOONS]);
12static void moonradec (double usize, MoonData md[U_NMOONS]);
[2643]13static void moonSVis (Obj *sop, Obj *uop, MoonData md[U_NMOONS]);
[2551]14static void moonEVis (MoonData md[U_NMOONS]);
[2643]15static void moonPShad (Obj *sop, Obj *uop, MoonData md[U_NMOONS]);
16static void moonTrans (MoonData md[U_NMOONS]);
[2551]17
18/* moon table and a few other goodies and when it was last computed */
19static double mdmjd = -123456;
20static MoonData umd[U_NMOONS] = {
21 {"Uranus", NULL},
22 {"Ariel", "I"},
23 {"Umbriel", "II"},
24 {"Titania", "III"},
25 {"Oberon", "IV"},
26 {"Miranda", "V"},
27};
28static double sizemjd; /* size at last mjd */
29
30/* file containing BDL coefficients */
31static char ubdlfn[] = "uranus.9910";
32
[2643]33/* These values are from the Explanatory Supplement.
34 * Precession degrades them gradually over time.
35 */
36#define POLE_RA degrad(257.43) /* RA of Uranus' north pole */
37#define POLE_DEC degrad(-15.10) /* Dec of Uranus' north pole */
38
39
[2551]40/* get uranus info in md[0], moon info in md[1..U_NMOONS-1].
41 * if !uop caller just wants md[] for names
[2643]42 * N.B. we assume sop and uop are updated.
[2551]43 */
44void
45uranus_data (
46double Mjd, /* mjd */
47char dir[], /* dir in which to look for helper files */
[2643]48Obj *sop, /* Sun */
[2551]49Obj *uop, /* uranus */
50double *sizep, /* u angular diam, rads */
[2643]51double *polera, double *poledec, /* pole location */
[2551]52MoonData md[U_NMOONS]) /* return info */
53{
54 double JD;
55
56 /* always copy back at least for name */
57 memcpy (md, umd, sizeof(umd));
58
[2643]59 /* pole */
60 if (polera) *polera = POLE_RA;
61 if (poledec) *poledec = POLE_DEC;
62
[2551]63 /* nothing else if repeat call or just want names */
64 if (Mjd == mdmjd || !uop) {
65 if (uop) {
66 *sizep = sizemjd;
67 }
68 return;
69 }
70 JD = Mjd + MJD0;
71
72 /* planet in [0] */
73 md[0].ra = uop->s_ra;
74 md[0].dec = uop->s_dec;
75 md[0].mag = get_mag(uop);
76 md[0].x = 0;
77 md[0].y = 0;
78 md[0].z = 0;
79 md[0].evis = 1;
80 md[0].svis = 1;
81
82 /* size is straight from uop */
83 *sizep = degrad(uop->s_size/3600.0);
84
85 /* from Pasachoff/Menzel */
86
87 md[1].mag = 14.2;
88 md[2].mag = 14.8;
89 md[3].mag = 13.7;
90 md[4].mag = 14.0;
91 md[5].mag = 16.3;
92
93 /* get moon x,y,z from BDL if possible */
94 if (dir && use_bdl (JD, dir, md) < 0) {
95 int i;
96 for (i = 1; i < U_NMOONS; i++)
97 md[i].x = md[i].y = md[i].z = 0.0;
[2818]98 fprintf (stderr, "No uranus model available\n");
[2551]99 }
100
101 /* set visibilities */
[2643]102 moonSVis (sop, uop, md);
103 moonPShad (sop, uop, md);
[2551]104 moonEVis (md);
[2643]105 moonTrans (md);
[2551]106
107 /* fill in moon ra and dec */
108 moonradec (*sizep, md);
109
110 /* save */
111 mdmjd = Mjd;
112 sizemjd = *sizep;
113 memcpy (umd, md, sizeof(umd));
114}
115
116/* hunt for BDL file in dir[] and use if possible
117 * return 0 if ok, else -1
118 */
119static int
120use_bdl (
121double JD, /* julian date */
122char dir[], /* directory */
123MoonData md[U_NMOONS]) /* fill md[1..NM-1].x/y/z for each moon */
124{
125#define URAU .0001597 /* Uranus radius, AU */
126 double x[U_NMOONS], y[U_NMOONS], z[U_NMOONS];
127 char buf[1024];
128 FILE *fp;
129 int i;
130
131 /* only valid 1999 through 2010 */
132 if (JD < 2451179.50000 || JD >= 2455562.5)
133 return (-1);
134
135 /* open */
136 (void) sprintf (buf, "%s/%s", dir, ubdlfn);
137 fp = fopen (buf, "r");
138 if (!fp)
139 return (-1);
140
141 /* use it */
142 if ((i = read_bdl (fp, JD, x, y, z, buf)) < 0) {
143 fprintf (stderr, "%s: %s\n", ubdlfn, buf);
144 fclose (fp);
145 return (-1);
146 }
147 if (i != U_NMOONS-1) {
148 fprintf (stderr, "%s: BDL says %d moons, code expects %d", ubdlfn,
149 i, U_NMOONS-1);
150 fclose (fp);
151 return (-1);
152 }
153
154 /* copy into md[1..NM-1] with our scale and sign conventions */
155 for (i = 1; i < U_NMOONS; i++) {
156 md[i].x = x[i-1]/URAU; /* we want u radii +E */
157 md[i].y = -y[i-1]/URAU; /* we want u radii +S */
158 md[i].z = -z[i-1]/URAU; /* we want u radii +front */
159 }
160
161 /* ok */
162 fclose (fp);
163 return (0);
164}
165
166/* given uranus loc in md[0].ra/dec and size, and location of each moon in
167 * md[1..NM-1].x/y in ura radii, find ra/dec of each moon in md[1..NM-1].ra/dec.
168 */
169static void
170moonradec (
171double usize, /* ura diameter, rads */
172MoonData md[U_NMOONS]) /* fill in RA and Dec */
173{
174 double urad = usize/2;
175 double ura = md[0].ra;
176 double udec = md[0].dec;
177 int i;
178
179 for (i = 1; i < U_NMOONS; i++) {
180 double dra = urad * md[i].x;
181 double ddec = urad * md[i].y;
182 md[i].ra = ura + dra;
183 md[i].dec = udec - ddec;
184 }
185}
186
187/* set svis according to whether moon is in sun light */
188static void
189moonSVis(
[2643]190Obj *sop, /* SUN */
[2551]191Obj *uop, /* uranus */
192MoonData md[U_NMOONS])
193{
[2643]194 double esd = sop->s_edist;
[2551]195 double eod = uop->s_edist;
196 double sod = uop->s_sdist;
197 double soa = degrad(uop->s_elong);
198 double esa = asin(esd*sin(soa)/sod);
199 double h = sod*uop->s_hlat;
200 double nod = h*(1./eod - 1./sod);
201 double sca = cos(esa), ssa = sin(esa);
202 int i;
203
204 for (i = 1; i < U_NMOONS; i++) {
205 MoonData *mdp = &md[i];
206 double xp = sca*mdp->x + ssa*mdp->z;
207 double yp = mdp->y;
208 double zp = -ssa*mdp->x + sca*mdp->z;
209 double ca = cos(nod), sa = sin(nod);
210 double xpp = xp;
211 double ypp = ca*yp - sa*zp;
212 double zpp = sa*yp + ca*zp;
213 int outside = xpp*xpp + ypp*ypp > 1.0;
214 int infront = zpp > 0.0;
215 mdp->svis = outside || infront;
216 }
217}
218
219/* set evis according to whether moon is geometrically visible from earth */
220static void
221moonEVis (MoonData md[U_NMOONS])
222{
223 int i;
224
225 for (i = 1; i < U_NMOONS; i++) {
226 MoonData *mdp = &md[i];
227 int outside = mdp->x*mdp->x + mdp->y*mdp->y > 1.0;
228 int infront = mdp->z > 0.0;
229 mdp->evis = outside || infront;
230 }
231}
232
[2643]233/* set pshad and sx,sy shadow info */
234static void
235moonPShad(
236Obj *sop, /* SUN */
237Obj *uop, /* uranus */
238MoonData md[U_NMOONS])
239{
240 int i;
241
242 for (i = 1; i < U_NMOONS; i++) {
243 MoonData *mdp = &md[i];
244 mdp->pshad = !plshadow (uop, sop, POLE_RA, POLE_DEC, mdp->x,
245 mdp->y, mdp->z, &mdp->sx, &mdp->sy);
246 }
247}
248
249/* set whether moons are transiting */
250static void
251moonTrans (MoonData md[U_NMOONS])
252{
253 int i;
254
255 for (i = 1; i < U_NMOONS; i++) {
256 MoonData *mdp = &md[i];
257 mdp->trans = mdp->z > 0 && mdp->x*mdp->x + mdp->y*mdp->y < 1;
258 }
259}
260
261
[2551]262/* For RCS Only -- Do Not Edit */
[2818]263static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: umoon.c,v $ $Date: 2005-08-21 10:02:40 $ $Revision: 1.3 $ $Name: not supported by cvs2svn $"};
Note: See TracBrowser for help on using the repository browser.