5 #define DegPerRad 57.29577951308232087680
6 #define RadPerDeg 0.01745329251994329576
8 extern double Glon
, SinGlat
, CosGlat
, TimeZone
;
11 void MoonRise(int year
, int month
, int day
, double LocalHour
, double *UTRise
, double *UTSet
){
13 double UT
, ym
, y0
, yp
, SinH0
;
14 double xe
, ye
, z1
, z2
, SinH(), hour24();
17 SinH0
= sin( 8.0/60.0 * RadPerDeg
);
24 ym
= SinH(year
, month
, day
, UT
-1.0) - SinH0
;
26 while ( (UT
<= 24.0+TimeZone
) ) {
28 y0
= SinH(year
, month
, day
, UT
) - SinH0
;
29 yp
= SinH(year
, month
, day
, UT
+1.0) - SinH0
;
31 Interp(ym
, y0
, yp
, &xe
, &ye
, &z1
, &z2
, &nz
);
65 *UTRise
= hour24(*UTRise
);
72 *UTSet
= hour24(*UTSet
);
80 void UTTohhmm(double UT
, int *h
, int *m
){
88 *m
= (int)((UT
-(double)(*h
))*60.0+0.5);
91 * If it was 23:60 this should become 24:00
92 * I prefer this designation to 00:00. So dont reset h to 0 when it goes above 24.
106 void Interp(double ym
, double y0
, double yp
, double *xe
, double *ye
, double *z1
, double *z2
, int *nz
){
108 double a
, b
, c
, d
, dx
;
115 *ye
= (a
*(*xe
) + b
) * (*xe
) + c
;
119 dx
= 0.5*sqrt(d
)/fabs(a
);
122 if (fabs(*z1
) <= 1.0) *nz
+= 1;
123 if (fabs(*z2
) <= 1.0) *nz
+= 1;
124 if (*z1
< -1.0) *z1
= *z2
;
134 double SinH(int year
, int month
, int day
, double UT
){
136 double TU
, frac(), jd();
137 double RA_Moon
, DEC_Moon
, gmst
, lmst
, Tau
, Moon();
140 TU
= (jd(year
, month
, day
, UT
) - 2451545.0)/36525.0;
142 /* this is more accurate, but wasteful for this -- use low res approx.
145 Moon(TU, &LambdaMoon, &BetaMoon, &R, &AGE);
146 LambdaMoon *= RadPerDeg;
147 BetaMoon *= RadPerDeg;
148 epsilon = (23.43929167 - 0.013004166*TU - 1.6666667e-7*TU2 - 5.0277777778e-7*TU3)*RadPerDeg;
149 RA_Moon = angle2pi(atan2(sin(LambdaMoon)*cos(epsilon)-tan(BetaMoon)*sin(epsilon), cos(LambdaMoon)));
150 DEC_Moon = asin( sin(BetaMoon)*cos(epsilon) + cos(BetaMoon)*sin(epsilon)*sin(LambdaMoon));
153 MiniMoon(TU
, &RA_Moon
, &DEC_Moon
);
154 RA_Moon
*= 15.0*RadPerDeg
;
155 DEC_Moon
*= RadPerDeg
;
158 * Compute Greenwich Mean Sidereal Time (gmst)
160 UT
= 24.0*frac( UT
/24.0 );
161 /* this is for the ephemeris meridian???
162 gmst = 6.697374558 + 1.0027379093*UT + (8640184.812866+(0.093104-6.2e-6*TU)*TU)*TU/3600.0;
164 gmst
= UT
+ 6.697374558 + (8640184.812866+(0.093104-6.2e-6*TU
)*TU
)*TU
/3600.0;
165 lmst
= 24.0*frac( (gmst
-Glon
/15.0) / 24.0 );
167 Tau
= 15.0*lmst
*RadPerDeg
- RA_Moon
;
168 return( SinGlat
*sin(DEC_Moon
) + CosGlat
*cos(DEC_Moon
)*cos(Tau
) );