Navit SVN

/work/compile/navit/src/navit/sunriset.h

00001 extern const char* timezone_name;
00002 extern long int timezone_offset;
00003 
00004 #define TMOD(x) ((x)<0?(x)+24:((x)>=24?(x)-24:(x)))
00005 #define DAYSOFF(x) ((x)<0?"(-1) ":((x)>=24?"(+1) ":""))
00006 
00007 #define HOURS(h) ((int)(floor(h)))
00008 #define MINUTES(h) ((int)(60*(h-floor(h))))
00009 
00010 #ifndef ABS
00011 #define ABS(x) ((x)<0?-(x):(x)) 
00012 #endif
00013 
00014 /* A macro to compute the number of days elapsed since 2000 Jan 0.0 */
00015 /* (which is equal to 1999 Dec 31, 0h UT)                           */
00016 /* Dan R sez: This is some pretty fucking high magic. */
00017 #define days_since_2000_Jan_0(y,m,d) \
00018     (367L*(y)-((7*((y)+(((m)+9)/12)))/4)+((275*(m))/9)+(d)-730530L)
00019 
00020 /* Some conversion factors between radians and degrees */
00021 
00022 #ifndef PI
00023  #define PI        3.1415926535897932384
00024 #endif
00025 
00026 #define RADEG     ( 180.0 / PI )
00027 #define DEGRAD    ( PI / 180.0 )
00028 
00029 /* The trigonometric functions in degrees */
00030 
00031 #define sind(x)  sin((x)*DEGRAD)
00032 #define cosd(x)  cos((x)*DEGRAD)
00033 #define tand(x)  tan((x)*DEGRAD)
00034 
00035 #define atand(x)    (RADEG*atan(x))
00036 #define asind(x)    (RADEG*asin(x))
00037 #define acosd(x)    (RADEG*acos(x))
00038 #define atan2d(y,x) (RADEG*atan2(y,x))
00039 
00040 /* Following are some macros around the "workhorse" function __daylen__ */
00041 /* They mainly fill in the desired values for the reference altitude    */
00042 /* below the horizon, and also selects whether this altitude should     */
00043 /* refer to the Sun's center or its upper limb.                         */
00044 
00045 
00046 /* This macro computes the length of the day, from sunrise to sunset. */
00047 /* Sunrise/set is considered to occur when the Sun's upper limb is    */
00048 /* 50 arc minutes below the horizon (this accounts for the refraction */
00049 /* of the Earth's atmosphere).                                        */
00050 /* The original version of the program used the value of 35 arc mins, */
00051 /* which is the accepted value in Sweden.                             */
00052 #define day_length(year,month,day,lon,lat)  \
00053         __daylen__( year, month, day, lon, lat, -50.0/60.0, 1 )
00054 
00055 /* This macro computes the length of the day, including civil twilight. */
00056 /* Civil twilight starts/ends when the Sun's center is 6 degrees below  */
00057 /* the horizon.                                                         */
00058 #define day_civil_twilight_length(year,month,day,lon,lat)  \
00059         __daylen__( year, month, day, lon, lat, -6.0, 0 )
00060 
00061 /* This macro computes the length of the day, incl. nautical twilight.  */
00062 /* Nautical twilight starts/ends when the Sun's center is 12 degrees    */
00063 /* below the horizon.                                                   */
00064 #define day_nautical_twilight_length(year,month,day,lon,lat)  \
00065         __daylen__( year, month, day, lon, lat, -12.0, 0 )
00066 
00067 /* This macro computes the length of the day, incl. astronomical twilight. */
00068 /* Astronomical twilight starts/ends when the Sun's center is 18 degrees   */
00069 /* below the horizon.                                                      */
00070 #define day_astronomical_twilight_length(year,month,day,lon,lat)  \
00071         __daylen__( year, month, day, lon, lat, -18.0, 0 )
00072 
00073 
00074 /* This macro computes times for sunrise/sunset.                      */
00075 /* Sunrise/set is considered to occur when the Sun's upper limb is    */
00076 /* 35 arc minutes below the horizon (this accounts for the refraction */
00077 /* of the Earth's atmosphere).                                        */
00078 #define sun_rise_set(year,month,day,lon,lat,rise,set)  \
00079         __sunriset__( year, month, day, lon, lat, -35.0/60.0, 1, rise, set )
00080 
00081 /* This macro computes the start and end times of civil twilight.       */
00082 /* Civil twilight starts/ends when the Sun's center is 6 degrees below  */
00083 /* the horizon.                                                         */
00084 #define civil_twilight(year,month,day,lon,lat,start,end)  \
00085         __sunriset__( year, month, day, lon, lat, -6.0, 0, start, end )
00086 
00087 /* This macro computes the start and end times of nautical twilight.    */
00088 /* Nautical twilight starts/ends when the Sun's center is 12 degrees    */
00089 /* below the horizon.                                                   */
00090 #define nautical_twilight(year,month,day,lon,lat,start,end)  \
00091         __sunriset__( year, month, day, lon, lat, -12.0, 0, start, end )
00092 
00093 /* This macro computes the start and end times of astronomical twilight.   */
00094 /* Astronomical twilight starts/ends when the Sun's center is 18 degrees   */
00095 /* below the horizon.                                                      */
00096 #define astronomical_twilight(year,month,day,lon,lat,start,end)  \
00097         __sunriset__( year, month, day, lon, lat, -18.0, 0, start, end )
00098 
00099 
00100 /* Function prototypes */
00101 
00102 double __daylen__( int year, int month, int day, double lon, double lat,
00103                    double altit, int upper_limb );
00104 
00105 int __sunriset__( int year, int month, int day, double lon, double lat,
00106                   double altit, int upper_limb, double *rise, double *set );
00107 
00108 void sunpos( double d, double *lon, double *r );
00109 
00110 void sun_RA_dec( double d, double *RA, double *dec, double *r );
00111 
00112 double revolution( double x );
00113 
00114 double rev180( double x );
00115 
00116 double GMST0( double d );
00117