1 extern const char* timezone_name;
2 extern long int timezone_offset;
4 #define TMOD(x) ((x)<0?(x)+24:((x)>=24?(x)-24:(x)))
5 #define DAYSOFF(x) ((x)<0?"(-1) ":((x)>=24?"(+1) ":""))
7 #define HOURS(h) ((int)(floor(h)))
8 #define MINUTES(h) ((int)(60*(h-floor(h))))
10 #define ABS(x) ((x)<0?-(x):(x))
12 /* A macro to compute the number of days elapsed since 2000 Jan 0.0 */
13 /* (which is equal to 1999 Dec 31, 0h UT) */
14 /* Dan R sez: This is some pretty fucking high magic. */
15 #define days_since_2000_Jan_0(y,m,d) \
16 (367L*(y)-((7*((y)+(((m)+9)/12)))/4)+((275*(m))/9)+(d)-730530L)
18 /* Some conversion factors between radians and degrees */
21 #define PI 3.1415926535897932384
24 #define RADEG ( 180.0 / PI )
25 #define DEGRAD ( PI / 180.0 )
27 /* The trigonometric functions in degrees */
29 #define sind(x) sin((x)*DEGRAD)
30 #define cosd(x) cos((x)*DEGRAD)
31 #define tand(x) tan((x)*DEGRAD)
33 #define atand(x) (RADEG*atan(x))
34 #define asind(x) (RADEG*asin(x))
35 #define acosd(x) (RADEG*acos(x))
36 #define atan2d(y,x) (RADEG*atan2(y,x))
38 /* Following are some macros around the "workhorse" function __daylen__ */
39 /* They mainly fill in the desired values for the reference altitude */
40 /* below the horizon, and also selects whether this altitude should */
41 /* refer to the Sun's center or its upper limb. */
44 /* This macro computes the length of the day, from sunrise to sunset. */
45 /* Sunrise/set is considered to occur when the Sun's upper limb is */
46 /* 50 arc minutes below the horizon (this accounts for the refraction */
47 /* of the Earth's atmosphere). */
48 /* The original version of the program used the value of 35 arc mins, */
49 /* which is the accepted value in Sweden. */
50 #define day_length(year,month,day,lon,lat) \
51 __daylen__( year, month, day, lon, lat, -50.0/60.0, 1 )
53 /* This macro computes the length of the day, including civil twilight. */
54 /* Civil twilight starts/ends when the Sun's center is 6 degrees below */
56 #define day_civil_twilight_length(year,month,day,lon,lat) \
57 __daylen__( year, month, day, lon, lat, -6.0, 0 )
59 /* This macro computes the length of the day, incl. nautical twilight. */
60 /* Nautical twilight starts/ends when the Sun's center is 12 degrees */
61 /* below the horizon. */
62 #define day_nautical_twilight_length(year,month,day,lon,lat) \
63 __daylen__( year, month, day, lon, lat, -12.0, 0 )
65 /* This macro computes the length of the day, incl. astronomical twilight. */
66 /* Astronomical twilight starts/ends when the Sun's center is 18 degrees */
67 /* below the horizon. */
68 #define day_astronomical_twilight_length(year,month,day,lon,lat) \
69 __daylen__( year, month, day, lon, lat, -18.0, 0 )
72 /* This macro computes times for sunrise/sunset. */
73 /* Sunrise/set is considered to occur when the Sun's upper limb is */
74 /* 35 arc minutes below the horizon (this accounts for the refraction */
75 /* of the Earth's atmosphere). */
76 #define sun_rise_set(year,month,day,lon,lat,rise,set) \
77 __sunriset__( year, month, day, lon, lat, -35.0/60.0, 1, rise, set )
79 /* This macro computes the start and end times of civil twilight. */
80 /* Civil twilight starts/ends when the Sun's center is 6 degrees below */
82 #define civil_twilight(year,month,day,lon,lat,start,end) \
83 __sunriset__( year, month, day, lon, lat, -6.0, 0, start, end )
85 /* This macro computes the start and end times of nautical twilight. */
86 /* Nautical twilight starts/ends when the Sun's center is 12 degrees */
87 /* below the horizon. */
88 #define nautical_twilight(year,month,day,lon,lat,start,end) \
89 __sunriset__( year, month, day, lon, lat, -12.0, 0, start, end )
91 /* This macro computes the start and end times of astronomical twilight. */
92 /* Astronomical twilight starts/ends when the Sun's center is 18 degrees */
93 /* below the horizon. */
94 #define astronomical_twilight(year,month,day,lon,lat,start,end) \
95 __sunriset__( year, month, day, lon, lat, -18.0, 0, start, end )
98 /* Function prototypes */
100 double __daylen__( int year, int month, int day, double lon, double lat,
101 double altit, int upper_limb );
103 int __sunriset__( time_t ts, double lon, double lat,
104 double altit, int upper_limb, double *rise, double *set );
106 void sunpos( double d, double *lon, double *r );
108 void sun_RA_dec( double d, double *RA, double *dec, double *r );
110 double revolution( double x );
112 double rev180( double x );
114 double GMST0( double d );