navit 0.5.3-trunk
Loading...
Searching...
No Matches
sunriset.h
Go to the documentation of this file.
1extern const char *timezone_name;
2extern 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#ifndef ABS
11# define ABS(x) ((x) < 0 ? -(x) : (x))
12#endif
13
14/* A macro to compute the number of days elapsed since 2000 Jan 0.0 */
15/* (which is equal to 1999 Dec 31, 0h UT) */
16/* Dan R sez: This is some pretty fucking high magic. */
17#define days_since_2000_Jan_0(y, m, d) \
18 (367L * (y) - ((7 * ((y) + (((m) + 9) / 12))) / 4) + ((275 * (m)) / 9) + (d) - 730530L)
19
20/* Some conversion factors between radians and degrees */
21
22#ifndef PI
23# define PI 3.1415926535897932384
24#endif
25
26#define RADEG (180.0 / PI)
27#define DEGRAD (PI / 180.0)
28
29/* The trigonometric functions in degrees */
30
31#define sind(x) sin((x) * DEGRAD)
32#define cosd(x) cos((x) * DEGRAD)
33#define tand(x) tan((x) * DEGRAD)
34
35#define atand(x) (RADEG * atan(x))
36#define asind(x) (RADEG * asin(x))
37#define acosd(x) (RADEG * acos(x))
38#define atan2d(y, x) (RADEG * atan2(y, x))
39
40/* Following are some macros around the "workhorse" function __daylen__ */
41/* They mainly fill in the desired values for the reference altitude */
42/* below the horizon, and also selects whether this altitude should */
43/* refer to the Sun's center or its upper limb. */
44
45/* This macro computes the length of the day, from sunrise to sunset. */
46/* Sunrise/set is considered to occur when the Sun's upper limb is */
47/* 50 arc minutes below the horizon (this accounts for the refraction */
48/* of the Earth's atmosphere). */
49/* The original version of the program used the value of 35 arc mins, */
50/* which is the accepted value in Sweden. */
51#define day_length(year, month, day, lon, lat) __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) __daylen__(year, month, day, lon, lat, -6.0, 0)
57
58/* This macro computes the length of the day, incl. nautical twilight. */
59/* Nautical twilight starts/ends when the Sun's center is 12 degrees */
60/* below the horizon. */
61#define day_nautical_twilight_length(year, month, day, lon, lat) __daylen__(year, month, day, lon, lat, -12.0, 0)
62
63/* This macro computes the length of the day, incl. astronomical twilight. */
64/* Astronomical twilight starts/ends when the Sun's center is 18 degrees */
65/* below the horizon. */
66#define day_astronomical_twilight_length(year, month, day, lon, lat) __daylen__(year, month, day, lon, lat, -18.0, 0)
67
68/* This macro computes times for sunrise/sunset. */
69/* Sunrise/set is considered to occur when the Sun's upper limb is */
70/* 35 arc minutes below the horizon (this accounts for the refraction */
71/* of the Earth's atmosphere). */
72#define sun_rise_set(year, month, day, lon, lat, rise, set) \
73 __sunriset__(year, month, day, lon, lat, -35.0 / 60.0, 1, rise, set)
74
75/* This macro computes the start and end times of civil twilight. */
76/* Civil twilight starts/ends when the Sun's center is 6 degrees below */
77/* the horizon. */
78#define civil_twilight(year, month, day, lon, lat, start, end) \
79 __sunriset__(year, month, day, lon, lat, -6.0, 0, start, end)
80
81/* This macro computes the start and end times of nautical twilight. */
82/* Nautical twilight starts/ends when the Sun's center is 12 degrees */
83/* below the horizon. */
84#define nautical_twilight(year, month, day, lon, lat, start, end) \
85 __sunriset__(year, month, day, lon, lat, -12.0, 0, start, end)
86
87/* This macro computes the start and end times of astronomical twilight. */
88/* Astronomical twilight starts/ends when the Sun's center is 18 degrees */
89/* below the horizon. */
90#define astronomical_twilight(year, month, day, lon, lat, start, end) \
91 __sunriset__(year, month, day, lon, lat, -18.0, 0, start, end)
92
93/* Function prototypes */
94
95double __daylen__(int year, int month, int day, double lon, double lat, double altit, int upper_limb);
96
97int __sunriset__(int year, int month, int day, double lon, double lat, double altit, int upper_limb, double *rise,
98 double *set);
99
100void sunpos(double d, double *lon, double *r);
101
102void sun_RA_dec(double d, double *RA, double *dec, double *r);
103
104double revolution(double x);
105
106double rev180(double x);
107
108double GMST0(double d);
struct triple lng lat
Definition garmin_img.c:0
double __daylen__(int year, int month, int day, double lon, double lat, double altit, int upper_limb)
Definition sunriset.c:112
void sunpos(double d, double *lon, double *r)
Definition sunriset.c:177
double revolution(double x)
Definition sunriset.c:245
int __sunriset__(int year, int month, int day, double lon, double lat, double altit, int upper_limb, double *rise, double *set)
Definition sunriset.c:24
double rev180(double x)
Definition sunriset.c:253
double GMST0(double d)
Definition sunriset.c:288
const char * timezone_name
long int timezone_offset
void sun_RA_dec(double d, double *RA, double *dec, double *r)
Definition sunriset.c:209