Fix:maptool:Another name for faroe islands
[navit-package] / navit / sunriset.h
1 extern const char* timezone_name;
2 extern long int timezone_offset;
3
4 #define TMOD(x) ((x)<0?(x)+24:((x)>=24?(x)-24:(x)))
5 #define DAYSOFF(x) ((x)<0?"(-1) ":((x)>=24?"(+1) ":""))
6
7 #define HOURS(h) ((int)(floor(h)))
8 #define MINUTES(h) ((int)(60*(h-floor(h))))
9
10 #define ABS(x) ((x)<0?-(x):(x)) 
11
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)
17
18 /* Some conversion factors between radians and degrees */
19
20 #ifndef PI
21  #define PI        3.1415926535897932384
22 #endif
23
24 #define RADEG     ( 180.0 / PI )
25 #define DEGRAD    ( PI / 180.0 )
26
27 /* The trigonometric functions in degrees */
28
29 #define sind(x)  sin((x)*DEGRAD)
30 #define cosd(x)  cos((x)*DEGRAD)
31 #define tand(x)  tan((x)*DEGRAD)
32
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))
37
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.                         */
42
43
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 )
52
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  */
55 /* the horizon.                                                         */
56 #define day_civil_twilight_length(year,month,day,lon,lat)  \
57         __daylen__( year, month, day, lon, lat, -6.0, 0 )
58
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 )
64
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 )
70
71
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 )
78
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  */
81 /* the horizon.                                                         */
82 #define civil_twilight(year,month,day,lon,lat,start,end)  \
83         __sunriset__( year, month, day, lon, lat, -6.0, 0, start, end )
84
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 )
90
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 )
96
97
98 /* Function prototypes */
99
100 double __daylen__( int year, int month, int day, double lon, double lat,
101                    double altit, int upper_limb );
102
103 int __sunriset__( int year, int month, int day, double lon, double lat,
104                   double altit, int upper_limb, double *rise, double *set );
105
106 void sunpos( double d, double *lon, double *r );
107
108 void sun_RA_dec( double d, double *RA, double *dec, double *r );
109
110 double revolution( double x );
111
112 double rev180( double x );
113
114 double GMST0( double d );
115