4 #define DegPerRad 57.29577951308232087680
5 #define RadPerDeg 0.01745329251994329576
7 extern double Glon
, SinGlat
, CosGlat
, TimeZone
;
9 double cosEPS
= 0.91748;
10 double sinEPS
= 0.39778;
11 double P2
= 6.283185307;
13 Interp(double ym
, double y0
, double yp
, double *xe
, double *ye
, double *z1
, double *z2
, int *nz
){
15 double a
, b
, c
, d
, dx
;
22 *ye
= (a
*(*xe
) + b
) * (*xe
) + c
;
26 dx
= 0.5*sqrt(d
)/fabs(a
);
29 if (fabs(*z1
) <= 1.0) *nz
+= 1;
30 if (fabs(*z2
) <= 1.0) *nz
+= 1;
31 if (*z1
< -1.0) *z1
= *z2
;
39 SunRise(int year
, int month
, int day
, double LocalHour
, double *UTRise
, double *UTSet
){
41 double UT
, ym
, y0
, yp
, SinH0
;
42 double xe
, ye
, z1
, z2
, SinH(), hour24();
45 SinH0
= sin( -50.0/60.0 * RadPerDeg
);
52 ym
= SinH(year
, month
, day
, UT
-1.0) - SinH0
;
54 while ( (UT
<= 24.0+TimeZone
) ) {
56 y0
= SinH(year
, month
, day
, UT
) - SinH0
;
57 yp
= SinH(year
, month
, day
, UT
+1.0) - SinH0
;
59 Interp(ym
, y0
, yp
, &xe
, &ye
, &z1
, &z2
, &nz
);
93 *UTRise
= hour24(*UTRise
);
100 *UTSet
= hour24(*UTSet
);
108 UTTohhmm(double UT
, int *h
, int *m
){
116 *m
= (int)((UT
-(double)(*h
))*60.0+0.5);
121 double SinH(int year
, int month
, int day
, double UT
){
123 double TU
, frac(), jd();
124 double RA_Sun
, DEC_Sun
, gmst
, lmst
, Tau
;
125 double M
, DL
, L
, SL
, X
, Y
, Z
, RHO
;
128 TU
= (jd(year
, month
, day
, UT
+62.0/3600.0) - 2451545.0)/36525.0;
130 M
= P2
*frac(0.993133 + 99.997361*TU
);
131 DL
= 6893.0*sin(M
) + 72.0*sin(2.0*M
);
132 L
= P2
*frac(0.7859453 + M
/P2
+ (6191.2*TU
+DL
)/1296e3
);
134 X
= cos(L
); Y
= cosEPS
*SL
; Z
= sinEPS
*SL
; RHO
= sqrt(1.0-Z
*Z
);
135 DEC_Sun
= atan2(Z
, RHO
);
136 RA_Sun
= (48.0/P2
)*atan(Y
/(X
+RHO
));
137 if (RA_Sun
< 0) RA_Sun
+= 24.0;
139 RA_Sun
= RA_Sun
*15.0*RadPerDeg
;
142 * Compute Greenwich Mean Sidereal Time (gmst)
144 UT
= 24.0*frac( UT
/24.0 );
146 gmst
= 6.697374558 + 1.0*UT
+ (8640184.812866+(0.093104-6.2e-6*TU
)*TU
)*TU
/3600.0;
147 lmst
= 24.0*frac( (gmst
-Glon
/15.0) / 24.0 );
149 Tau
= 15.0*lmst
*RadPerDeg
- RA_Sun
;
150 return( SinGlat
*sin(DEC_Sun
) + CosGlat
*cos(DEC_Sun
)*cos(Tau
) );
157 * Compute the Julian Day number for the given date.
158 * Julian Date is the number of days since noon of Jan 1 4713 B.C.
160 double jd(ny
, nm
, nd
, UT
)
164 double A
, B
, C
, D
, JD
, day
;
169 if ((nm
== 1) || (nm
== 2)){
174 if (((double)ny
+nm
/12.0+day
/365.25)>=(1582.0+10.0/12.0+15.0/365.25)){
175 A
= ((int)(ny
/ 100.0));
176 B
= 2.0 - A
+ (int)(A
/4.0);
183 C
= (int)((365.25*(double)ny
) - 0.75);
186 C
= (int)(365.25*(double)ny
);
189 D
= (int)(30.6001*(double)(nm
+1));
192 JD
= B
+ C
+ D
+ day
+ 1720994.5;
203 n
= (int)(hour
/24.0) - 1;
206 else if (hour
> 24.0){
207 n
= (int)(hour
/24.0);
215 double frac(double x
){
218 return( (x
<0) ? x
+1.0 : x
);