Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix asr calculation and adding a new extreme calculation method #3

Merged
merged 1 commit into from
May 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions libs/prayertime/prayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ enum exmethods { NONE_EX,
HALF_INVALID,
MIN_ALWAYS,
MIN_INVALID,
GOOD_INVALID_SAME };
GOOD_INVALID_SAME,
ANGLE_BASED };

enum methods { NONE,
EGYPT_SURVEY,
Expand Down Expand Up @@ -158,8 +159,12 @@ static void getPrayerTimesByDay ( const Location* loc, const Method* conf,
else tempPrayer[5] = zu + is;


/* Calculate all prayer times as Base-10 numbers in Extreme Latitudes (if
* needed) */
/* Re-calculate Fajr and Ishaa in Extreme Latitudes */
if (lat > conf->nearestLat) {
tempPrayer[0] = 99;
tempPrayer[5] = 99;
invalid = 1;
}

/* Reset status of extreme switches */
for (i=0; i<6; i++)
Expand All @@ -183,6 +188,18 @@ static void getPrayerTimesByDay ( const Location* loc, const Method* conf,

switch(conf->extreme)
{
/* Angle Based */
case ANGLE_BASED:
portion = ((24 - tempPrayer[4]) + tempPrayer[1]);
double fajrDiff = (1/60.0 * conf->fajrAng) * portion;
double ishaDiff = (1/60.0 * conf->ishaaAng) * portion;

tempPrayer[0] = tempPrayer[1] - fajrDiff;
tempPrayer[5] = tempPrayer[4] + ishaDiff;
pt[0].isExtreme = 1;
pt[5].isExtreme = 1;
break;

/* Nearest Latitude (Method.nearestLat) */
case LAT_ALL:
case LAT_ALWAYS:
Expand Down Expand Up @@ -608,24 +625,19 @@ static double getZuhr(double lon, const Astro* astro)

static double getAssr(double lat, double dec, int mathhab)
{
double part1, part2, part3, part4, ndec;
double part1, part2, part3, part4;
double rlat = DEG_TO_RAD(lat);

part1 = mathhab + tan(fabs(rlat - dec));
part2 = atan(1.0 / part1);

/* Reverse if at or near the southern hemisphere */
ndec = dec;
if (lat < 0.0)
ndec = -dec;
part1 = mathhab + tan(rlat - ndec);
if (part1 < 1.0)
part1 = mathhab - tan(rlat - ndec);

part2 = (PI/2.0) - atan(part1);
/* Compute the hour angle */
part3 = sin(part2) - (sin(rlat) * sin(ndec));
part4 = (part3 / (cos(rlat) * cos(ndec)));

if ( part4 < -INVALID_TRIGGER || part4 > INVALID_TRIGGER)
part3 = sin(part2) - (sin(rlat) * sin(dec));
part4 = (part3 / (cos(rlat) * cos(dec)));
if ( part4 < -INVALID_TRIGGER || part4 > INVALID_TRIGGER) {
return 99;
}

return DEG_TO_10_BASE * RAD_TO_DEG (acos(part4));
}
Expand Down
3 changes: 2 additions & 1 deletion libs/prayertime/prayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ extern "C" {
11: Half of the Night: Fajr Ishaa if invalid
12: Minutes from Shorooq/Maghrib: Fajr Ishaa Always (e.g. Maghrib=Ishaa)
13: Minutes from Shorooq/Maghrib: Fajr Ishaa If invalid

14: Nearest Good Day: Fajr Ishaa if either is invalid
15: Angle based: Fajr Ishaa if invalid
*/


Expand Down