1 /************************************************************************
2  *  Copyright (c) 2003-2006, 2009, Arabeyes, Thamer Mahmoud
3  *
4  *  A full featured Muslim Prayer Times calculator
5  *
6  * (www.arabeyes.org - under LGPL license - see COPYING file)
7  ************************************************************************/
8 
9 #ifndef _PRAYER_ENGINE_
10 #define _PRAYER_ENGINE_
11 
12 #include <math.h>
13 
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 
20     /* This holds the current date info. */
21     typedef struct
22     {
23         int day;
24         int month;
25         int year;
26 
27     } Date ;
28 
29 
30     /* This holds the location info. */
31     typedef struct
32     {
33         double degreeLong;  /* Longitude in decimal degree. */
34         double degreeLat;   /* Latitude in decimal degree. */
35         double gmtDiff;     /* GMT difference at regular time. */
36         int dst;            /* Daylight savings time switch (0 if not used).
37                                Setting this to 1 should add 1 hour to all the
38                                calculated prayer times */
39         double seaLevel;    /* Height above Sea level in meters */
40         double pressure;    /* Atmospheric pressure in millibars (the
41                                astronomical standard value is 1010) */
42         double temperature; /* Temperature in Celsius degree (the astronomical
43                                standard value is 10) */
44     } Location ;
45 
46 
47     /* This structure holds the calculation method used. NOTE: Before explicitly
48        setting any of these values, it is more safe to default initialize them
49        by calling 'getMethod(0, &method)' */
50     typedef struct
51     {
52         int method;         /* Chosen calculation method */
53         double fajrAng;     /* Fajr angle */
54         double ishaaAng;    /* Ishaa angle */
55         double imsaakAng;   /* The angle difference between Imsaak and Fajr (
56                                default is 1.5)*/
57         int fajrInv;        /* Fajr Interval is the amount of minutes between
58                                Fajr and Shurooq (0 if not used) */
59         int ishaaInv;       /* Ishaa Interval is the amount if minutes between
60                                Ishaa and Maghrib (0 if not used) */
61         int imsaakInv;      /* Imsaak Interval is the amount of minutes between
62                                Imsaak and Fajr. The default is 10 minutes before
63                                Fajr if Fajr Interval is set */
64         int round;          /* Method used for rounding seconds:
65                                0: No Rounding. "Prayer.seconds" is set to the
66                                   amount of computed seconds.
67                                1: Normal Rounding. If seconds are equal to
68                                   30 or above, add 1 minute. Sets
69                                   "Prayer.seconds" to zero.
70                                2: Special Rounding. Similar to normal rounding
71                                   but we always round down for Shurooq and
72                                   Imsaak times. (default)
73                                3: Aggressive Rounding. Similar to Special
74                                   Rounding but we add 1 minute if the seconds
75                                   value is equal to 1 second or more.  */
76         int mathhab;        /* Assr prayer shadow ratio:
77                                1: Shaf'i (default)
78                                2: Hanafi */
79         double nearestLat;  /* Latitude Used for the 'Nearest Latitude' extreme
80                                methods. The default is 48.5 */
81         int extreme;        /* Extreme latitude calculation method (see
82                                below) */
83         double extremeLat;  /* Latitude at which the extreme method should
84                                always be used. The default is 55 */
85         int offset;         /* Enable Offsets switch (set this to 1 to
86                                activate). This option allows you to add or
87                                subtract any amount of minutes to the daily
88                                computed prayer times based on values (in
89                                minutes) for each prayer in the offList array */
90         double offList[6];  /* For Example: If you want to add 30 seconds to
91                                Maghrib and subtract 2 minutes from Ishaa:
92                                offset = 1
93                                offList[4] = 0.5
94                                offList[5] = -2
95                                ..and than call getPrayerTimes as usual. */
96 
97     } Method ;
98 
99 
100     /*
101       Supported methods for Extreme Latitude calculations (Method.extreme):
102 
103       0:  none. if unable to calculate, leave as 99:99
104       1:  Nearest Latitude: All prayers Always
105       2:  Nearest Latitude: Fajr Ishaa Always
106       3:  Nearest Latitude: Fajr Ishaa if invalid
107       4:  Nearest Good Day: All prayers Always
108       5:  Nearest Good Day: Fajr Ishaa if invalid (default)
109       6:  1/7th of Night: Fajr Ishaa Always
110       7:  1/7th of Night: Fajr Ishaa if invalid
111       8:  1/7th of Day: Fajr Ishaa Always
112       9:  1/7th of Day: Fajr Ishaa if invalid
113       10: Half of the Night: Fajr Ishaa Always
114       11: Half of the Night: Fajr Ishaa if invalid
115       12: Minutes from Shorooq/Maghrib: Fajr Ishaa Always (e.g. Maghrib=Ishaa)
116       13: Minutes from Shorooq/Maghrib: Fajr Ishaa If invalid
117       14: Nearest Good Day: Fajr Ishaa if either is invalid
118       15: Angle based: Fajr Ishaa if invalid
119     */
120 
121 
122     /* This function is used to auto fill the Method structure with predefined
123        data. The supported auto-fill methods for calculations at normal
124        circumstances are:
125 
126        0: none. Set to default or 0
127        1: Egyptian General Authority of Survey
128        2: University of Islamic Sciences, Karachi (Shaf'i)
129        3: University of Islamic Sciences, Karachi (Hanafi)
130        4: Islamic Society of North America
131        5: Muslim World League (MWL)
132        6: Umm Al-Qurra, Saudi Arabia
133        7: Fixed Ishaa Interval (always 90)
134        8: Egyptian General Authority of Survey (Egypt)
135        9: Umm Al-Qurra Ramadan, Saudi Arabia
136       10: Moonsighting Committee Worldwide
137       11: Morocco Awqaf, Morocco
138     */
139     void getMethod(int n, Method* conf);
140 
141 
142     /* This structure holds the prayer time output for a single prayer. */
143     typedef struct
144     {
145         int hour;       /* prayer time hour */
146         int minute;     /* prayer time minute */
147         int second;     /* prayer time second */
148         int isExtreme;  /* Extreme calculation status. The 'getPrayerTimes'
149                            function sets this variable to 1 to indicate that
150                            this particular prayer time has been calculated
151                            through extreme latitude methods and NOT by
152                            conventional means of calculation. */
153     } Prayer ;
154 
155 
156     /* The "getPrayerTimes" function fills an array of six Prayer structures
157        "Prayer[6]". This list contains the prayer minutes and hours information
158        like this:
159 
160        - Prayer[0].minute    is today's Fajr minutes
161        - Prayer[1].hour      is today's Shorooq hours
162        - ... and so on until...
163        - Prayer[5].minute    is today's Ishaa minutes
164     */
165     void getPrayerTimes (const Location*, const Method*, const Date*, Prayer*);
166 
167 
168     /* Extended prayer times */
169     void getImsaak (const Location*, const Method*, const Date*, Prayer*);
170     void getNextDayImsaak (const Location*, const Method*, const Date*, Prayer*);
171     void getNextDayFajr (const Location*, const Method*, const Date*, Prayer*);
172 
173 
174     /* utilities */
175     int getDayofYear (int year, int month, int day);
176     double dms2Decimal (int deg, int min, double sec, char dir);
177     void decimal2Dms (double decimal, int *deg, int *min, double *sec);
178 
179 
180     /* Qibla */
181     double getNorthQibla(const Location* location);
182 
183 
184 
185 #ifdef  __cplusplus
186 }
187 #endif
188 
189 #endif  /* _PRAYER_ENGINE_ */
190