svn commit: r203814 - user/edwin/calendar
Edwin Groothuis
edwin at FreeBSD.org
Sat Feb 13 08:23:48 UTC 2010
Author: edwin
Date: Sat Feb 13 08:23:47 2010
New Revision: 203814
URL: http://svn.freebsd.org/changeset/base/203814
Log:
Since moon-oriented events are not stuck to one day, let alone the
same day around the globe, make sure we are able to specify where
we are on this big marble and that events related to it are calculated
properly (still have to do the sun-related calculations)
Modified:
user/edwin/calendar/Makefile
user/edwin/calendar/calendar.1
user/edwin/calendar/calendar.c
user/edwin/calendar/calendar.h
user/edwin/calendar/io.c
user/edwin/calendar/parsedata.c
user/edwin/calendar/pom.c
user/edwin/calendar/sunpos.c
Modified: user/edwin/calendar/Makefile
==============================================================================
--- user/edwin/calendar/Makefile Sat Feb 13 05:38:21 2010 (r203813)
+++ user/edwin/calendar/Makefile Sat Feb 13 08:23:47 2010 (r203814)
@@ -1,7 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
# $FreeBSD$
-CFLAGS= -pipe -g -pg -std=gnu99 -fstack-protector -Wall
+CFLAGS= -pipe -g -std=gnu99 -fstack-protector -Wall
PROG= calendar
SRCS= calendar.c locale.c events.c dates.c parsedata.c io.c day.c \
Modified: user/edwin/calendar/calendar.1
==============================================================================
--- user/edwin/calendar/calendar.1 Sat Feb 13 05:38:21 2010 (r203813)
+++ user/edwin/calendar/calendar.1 Sat Feb 13 08:23:47 2010 (r203814)
@@ -285,10 +285,17 @@ command appeared in
.Sh NOTES
Chinese New Year is calculated at 120 degrees east of Greenwich,
which roughly corresponds with the east coast of China.
+For people west of China, this might result that the start of Chinese
+New Year and the day of the related new moon might differ.
.Pp
The phases of the moon and the longitude of the sun are calculated
against the local position which corresponds with 30 degrees times
the time-difference towards Greenwich.
+.Pp
+The new and full moons are happening on the day indicated: They
+might happen in the time period in the early night or in the late
+evening.
+It doesn't indicate that they are starting in the night on that date.
.Sh BUGS
The
.Nm
Modified: user/edwin/calendar/calendar.c
==============================================================================
--- user/edwin/calendar/calendar.c Sat Feb 13 05:38:21 2010 (r203813)
+++ user/edwin/calendar/calendar.c Sat Feb 13 08:23:47 2010 (r203814)
@@ -52,14 +52,21 @@ __FBSDID("$FreeBSD$");
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <time.h>
#include <unistd.h>
#include "calendar.h"
+#define UTCOFFSET_NOTSET 100 /* Expected between -24 and +24 */
+#define LONGITUDE_NOTSET 1000 /* Expected between -360 and +360 */
+
struct passwd *pw;
int doall = 0;
int debug = 0;
+char *DEBUG = NULL;
+double UTCoffset = UTCOFFSET_NOTSET;
+int eastlongitude = LONGITUDE_NOTSET;
time_t f_time = 0;
int f_dayAfter = 0; /* days after current date */
@@ -75,7 +82,7 @@ main(int argc, char *argv[])
(void)setlocale(LC_ALL, "");
- while ((ch = getopt(argc, argv, "-A:aB:dF:f:t:W:")) != -1)
+ while ((ch = getopt(argc, argv, "-A:aB:dD:F:f:l:t:U:W:")) != -1)
switch (ch) {
case '-': /* backward contemptible */
case 'a':
@@ -90,10 +97,6 @@ main(int argc, char *argv[])
calendarFile = optarg;
break;
- case 't': /* other date, undocumented, for tests */
- f_time = Mktime(optarg);
- break;
-
case 'W': /* we don't need no steenking Fridays */
Friday = -1;
/* FALLTHROUGH */
@@ -106,13 +109,25 @@ main(int argc, char *argv[])
f_dayBefore = atoi(optarg);
break;
- case 'F':
+ case 'F': /* Change the time: When does weekend start? */
Friday = atoi(optarg);
break;
+ case 'l': /* Change longitudal position */
+ eastlongitude = strtol(optarg, NULL, 10);
+ break;
+ case 'U': /* Change UTC offset */
+ UTCoffset = strtod(optarg, NULL);
+ break;
case 'd':
debug = 1;
break;
+ case 'D':
+ DEBUG = optarg;
+ break;
+ case 't': /* other date, undocumented, for tests */
+ f_time = Mktime(optarg);
+ break;
case '?':
default:
@@ -129,9 +144,61 @@ main(int argc, char *argv[])
if (f_time <= 0)
(void)time(&f_time);
+ /* if not set, determine where I could be */
+ {
+ if (UTCoffset == UTCOFFSET_NOTSET &&
+ eastlongitude == LONGITUDE_NOTSET) {
+ /* Calculate on difference between here and UTC */
+ time_t t;
+ struct tm tm;
+ long utcoffset, hh, mm, ss;
+ double uo;
+
+ time(&t);
+ localtime_r(&t, &tm);
+ utcoffset = tm.tm_gmtoff;
+ /* seconds -> hh:mm:ss */
+ hh = utcoffset / SECSPERHOUR;
+ utcoffset %= SECSPERHOUR;
+ mm = utcoffset / SECSPERMINUTE;
+ utcoffset %= SECSPERMINUTE;
+ ss = utcoffset;
+
+ /* hh:mm:ss -> hh.mmss */
+ uo = mm + (100.0 * (ss / 60.0));
+ uo /= 60.0 / 100.0;
+ uo = hh + uo / 100;
+
+ UTCoffset = uo;
+ eastlongitude = UTCoffset * 15;
+ } else if (UTCoffset == UTCOFFSET_NOTSET) {
+ /* Base on information given */
+ UTCoffset = eastlongitude / 15;
+ } else {
+ /* Base on information given */
+ eastlongitude = UTCoffset * 15;
+ }
+ }
+
settimes(f_time, f_dayBefore, f_dayAfter, &tp1, &tp2);
generatedates(&tp1, &tp2);
+ /*
+ * FROM now on, we are working in UTC.
+ * This will only affect moon and sun related events anyway.
+ */
+ if (setenv("TZ", "UTC", 1) != 0)
+ errx(1, "setenv: %s", strerror(errno));
+ tzset();
+
+ if (debug)
+ dumpdates();
+
+ if (DEBUG != NULL) {
+ dodebug(DEBUG);
+ exit(0);
+ }
+
if (doall)
while ((pw = getpwent()) != NULL) {
(void)setegid(pw->pw_gid);
Modified: user/edwin/calendar/calendar.h
==============================================================================
--- user/edwin/calendar/calendar.h Sat Feb 13 05:38:21 2010 (r203813)
+++ user/edwin/calendar/calendar.h Sat Feb 13 08:23:47 2010 (r203814)
@@ -36,7 +36,17 @@
#include <sys/types.h>
#include <sys/uio.h>
-#define SECSPERDAY 24 * 60 * 60
+#define SECSPERDAY (24 * 60 * 60)
+#define SECSPERHOUR (60 * 60)
+#define SECSPERMINUTE (60)
+#define HOURSPERDAY (24)
+#define FSECSPERDAY (24.0 * 60.0 * 60.0)
+#define FSECSPERHOUR (60.0 * 60.0)
+#define FSECSPERMINUTE (60.0)
+#define FHOURSPERDAY (24.0)
+
+#define DAYSPERYEAR 365
+#define DAYSPERLEAPYEAR 366
/* Not yet categorized */
@@ -49,6 +59,8 @@ extern const char *calendarFile;
extern int yrdays;
extern struct fixs neaster, npaskha, ncny, nfullmoon, nnewmoon;
extern struct fixs nmarequinox, nsepequinox, njunsolstice, ndecsolstice;
+extern double UTCoffset;
+extern int eastlongitude;
#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
@@ -73,16 +85,22 @@ extern struct fixs nmarequinox, nsepequi
#define F_JUNSOLSTICE 0x10000
#define F_DECSOLSTICE 0x20000
-#define STRING_EASTER "Easter"
-#define STRING_PASKHA "Paskha"
-#define STRING_CNY "ChineseNewYear"
-#define STRING_NEWMOON "NewMoon"
-#define STRING_FULLMOON "FullMoon"
+#define STRING_EASTER "Easter"
+#define STRING_PASKHA "Paskha"
+#define STRING_CNY "ChineseNewYear"
+#define STRING_NEWMOON "NewMoon"
+#define STRING_FULLMOON "FullMoon"
#define STRING_MAREQUINOX "MarEquinox"
#define STRING_SEPEQUINOX "SepEquinox"
#define STRING_JUNSOLSTICE "JunSolstice"
#define STRING_DECSOLSTICE "DecSolstice"
+/*
+ * All the astronomical calculations are carried out for the meridian 120
+ * degrees east of Greenwich.
+ */
+#define UTCOFFSET_CNY 8.0
+
extern int debug; /* show parsing of the input */
extern int f_dayAfter; /* days after current date */
extern int f_dayBefore; /* days before current date */
@@ -134,6 +152,7 @@ time_t Mktime(char *);
/* parsedata.c */
int parsedaymonth(char *, int *, int *, int *, int *);
+void dodebug(char *type);
/* io.c */
void cal(void);
@@ -158,8 +177,9 @@ int walkthrough_dates(struct event **e);
void addtodate(struct event *e, int year, int month, int day);
/* pom.c */
-#define MAXMOONS 15
-void pom(int year, int *fms, int *nms);
+#define MAXMOONS 18
+void pom(int year, double UTCoffset, int *fms, int *nms);
+void fpom(int year, double utcoffset, double *ffms, double *fnms);
/* sunpos.c */
void equinoxsolstice(int year, double UTCoffset, int *equinoxdays, int *solsticedays);
Modified: user/edwin/calendar/io.c
==============================================================================
--- user/edwin/calendar/io.c Sat Feb 13 05:38:21 2010 (r203813)
+++ user/edwin/calendar/io.c Sat Feb 13 08:23:47 2010 (r203814)
@@ -189,6 +189,8 @@ cal(void)
tm.tm_year = year[i] - 1900;
(void)strftime(dbuf, sizeof(dbuf),
d_first ? "%e %b" : "%b %e", &tm);
+ if (debug)
+ fprintf(stderr, "got %s\n", pp);
events[i] = event_add(year[i], month[i], day[i], dbuf,
((flags &= F_VARIABLE) != 0) ? 1 : 0, pp);
}
Modified: user/edwin/calendar/parsedata.c
==============================================================================
--- user/edwin/calendar/parsedata.c Sat Feb 13 05:38:21 2010 (r203813)
+++ user/edwin/calendar/parsedata.c Sat Feb 13 08:23:47 2010 (r203814)
@@ -28,6 +28,7 @@
__FBSDID("$FreeBSD: user/edwin/calendar/day.c 200813 2009-12-21 21:17:59Z edwin $");
#include <ctype.h>
+#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -44,6 +45,7 @@ static int checkdayofweek(char *s, int *
static int isonlydigits(char *s, int nostar);
static int indextooffset(char *s);
static int parseoffset(char *s);
+static char *floattoday(int year, double f);
/*
* Expected styles:
@@ -332,8 +334,9 @@ debug_determinestyle(int dateonly, char
struct yearinfo {
int year;
int ieaster, ipaskha, firstcnyday;
- int ifullmoon[MAXMOONS], inewmoon[MAXMOONS],
- ichinesemonths[MAXMOONS], equinoxdays[2], solsticedays[2];
+ double ffullmoon[MAXMOONS], fnewmoon[MAXMOONS];
+ double ffullmooncny[MAXMOONS], fnewmooncny[MAXMOONS];
+ int ichinesemonths[MAXMOONS], equinoxdays[2], solsticedays[2];
int *mondays;
struct yearinfo *next;
};
@@ -406,7 +409,10 @@ parsedaymonth(char *date, int *yearp, in
yearinfo->mondays = mondaytab[isleap(year)];
yearinfo->ieaster = easter(year);
- pom(year, yearinfo->ifullmoon, yearinfo->inewmoon);
+ fpom(year, UTCoffset, yearinfo->ffullmoon,
+ yearinfo->fnewmoon);
+ fpom(year, UTCOFFSET_CNY, yearinfo->ffullmooncny,
+ yearinfo->fnewmooncny);
equinoxsolstice(year, 0.0,
yearinfo->equinoxdays, yearinfo->solsticedays);
@@ -415,12 +421,12 @@ parsedaymonth(char *date, int *yearp, in
* moon
*/
yearinfo->firstcnyday = calculatesunlongitude30(year,
- 120, yearinfo->ichinesemonths);
- for (m = 0; yearinfo->inewmoon[m] != 0; m++) {
- if (yearinfo->inewmoon[m] >
+ UTCOFFSET_CNY, yearinfo->ichinesemonths);
+ for (m = 0; yearinfo->fnewmooncny[m] >= 0; m++) {
+ if (yearinfo->fnewmooncny[m] >
yearinfo->firstcnyday) {
yearinfo->firstcnyday =
- yearinfo->inewmoon[m - 1];
+ floor(yearinfo->fnewmooncny[m - 1]);
break;
}
}
@@ -576,9 +582,10 @@ parsedaymonth(char *date, int *yearp, in
offset = 0;
if ((*flags & F_MODIFIEROFFSET) != 0)
offset = parseoffset(modifieroffset);
- for (i = 0; yearinfo->ifullmoon[i] != 0; i++) {
+ for (i = 0; yearinfo->ffullmoon[i] > 0; i++) {
if (remember_yd(year,
- yearinfo->ifullmoon[i] + offset, &rm, &rd))
+ floor(yearinfo->ffullmoon[i]) + offset,
+ &rm, &rd))
remember(index++, yearp, monthp, dayp,
year, rm, rd);
}
@@ -593,9 +600,10 @@ parsedaymonth(char *date, int *yearp, in
offset = 0;
if ((*flags & F_MODIFIEROFFSET) != 0)
offset = parseoffset(modifieroffset);
- for (i = 0; yearinfo->ifullmoon[i] != 0; i++) {
+ for (i = 0; yearinfo->ffullmoon[i] > 0; i++) {
if (remember_yd(year,
- yearinfo->inewmoon[i] + offset, &rm, &rd))
+ floor(yearinfo->fnewmoon[i]) + offset,
+ &rm, &rd))
remember(index++, yearp, monthp, dayp,
year, rm, rd);
}
@@ -844,3 +852,76 @@ parseoffset(char *s)
return strtol(s, NULL, 10);
}
+
+static char *
+floattoday(int year, double f)
+{
+ static char buf[100];
+ int i, m, d, hh, mm, ss;
+ int *cumdays = cumdaytab[isleap(year)];
+
+ for (i = 0; 1 + cumdays[i] < f; i++)
+ ;;
+ m = --i;
+ d = floor(f - 1 - cumdays[i]);
+ f -= floor(f);
+ i = f * SECSPERDAY;
+
+ hh = i / SECSPERHOUR;
+ i %= SECSPERHOUR;
+ mm = i / SECSPERMINUTE;
+ i %= SECSPERMINUTE;
+ ss = i;
+
+ sprintf(buf, "%02d-%02d %02d:%02d:%02d", m, d, hh, mm, ss);
+ return (buf);
+}
+
+char *
+inttoday(int year, int f)
+{
+ static char buf[100];
+ int i, m, d;
+ int *cumdays = cumdaytab[isleap(year)];
+
+ for (i = 0; 1 + cumdays[i] < f; i++)
+ ;;
+ m = --i;
+ d = floor(f - 1 - cumdays[i]);
+ f -= floor(f);
+
+ sprintf(buf, "%02d-%02d", m, d);
+ return (buf);
+}
+
+void
+dodebug(char *what)
+{
+ int year;
+
+ printf("UTFOffset: %g\n", UTCoffset);
+ printf("eastlongitude: %d\n", eastlongitude);
+
+ if (strcmp(what, "moon") == 0) {
+ double ffullmoon[MAXMOONS], fnewmoon[MAXMOONS];
+ int i;
+
+ for (year = year1; year <= year2; year++) {
+ fpom(year, UTCoffset, ffullmoon, fnewmoon);
+ printf("Full moon %d:\t", year);
+ for (i = 0; ffullmoon[i] >= 0; i++) {
+ printf("%g (%s) ", ffullmoon[i],
+ floattoday(year, ffullmoon[i]));
+ }
+ printf("\nNew moon %d:\t", year);
+ for (i = 0; fnewmoon[i] >= 0; i++) {
+ printf("%g (%s) ", fnewmoon[i],
+ floattoday(year, fnewmoon[i]));
+ }
+ printf("\n");
+
+ }
+
+ return;
+ }
+}
Modified: user/edwin/calendar/pom.c
==============================================================================
--- user/edwin/calendar/pom.c Sat Feb 13 05:38:21 2010 (r203813)
+++ user/edwin/calendar/pom.c Sat Feb 13 08:23:47 2010 (r203814)
@@ -65,6 +65,8 @@ __FBSDID("$FreeBSD: head/games/pom/pom.c
#include <time.h>
#include <unistd.h>
+#include "calendar.h"
+
#ifndef PI
#define PI 3.14159265358979323846
#endif
@@ -80,9 +82,27 @@ __FBSDID("$FreeBSD: head/games/pom/pom.c
static void adj360(double *);
static double dtor(double);
static double potm(double);
+static double potm_minute(double days, int olddir);
+
+void
+pom(int year, double utcoffset, int *fms, int *nms)
+{
+ double ffms[MAXMOONS];
+ double fnms[MAXMOONS];
+ int i, j;
+
+ fpom(year, utcoffset, ffms, fnms);
+
+ for (i = 0; ffms[i] != 0; i++)
+ fms[j++] = round(ffms[i]);
+ fms[i] = -1;
+ for (i = 0; fnms[i] != 0; i++)
+ nms[i] = round(fnms[i]);
+ nms[i] = -1;
+}
void
-pom(int year, int *fms, int *nms)
+fpom(int year, double utcoffset, double *ffms, double *fnms)
{
time_t tt;
struct tm GMT, tmd_today, tmd_tomorrow;
@@ -90,10 +110,10 @@ pom(int year, int *fms, int *nms)
int cnt, d;
int yeardays;
int olddir, newdir;
- int *pnms, *pfms;
+ double *pfnms, *pffms, t;
- pnms = nms;
- pfms = fms;
+ pfnms = fnms;
+ pffms = ffms;
/*
* We take the phase of the moon one second before and one second
@@ -102,14 +122,14 @@ pom(int year, int *fms, int *nms)
memset(&tmd_today, 0, sizeof(tmd_today));
tmd_today.tm_year = year - 1900;
tmd_today.tm_mon = 0;
- tmd_today.tm_mday = 0; /* 31 December */
+ tmd_today.tm_mday = -1; /* 31 December */
tmd_today.tm_hour = 23;
tmd_today.tm_min = 59;
tmd_today.tm_sec = 59;
memset(&tmd_tomorrow, 0, sizeof(tmd_tomorrow));
tmd_tomorrow.tm_year = year - 1900;
tmd_tomorrow.tm_mon = 0;
- tmd_tomorrow.tm_mday = 1; /* 1 January */
+ tmd_tomorrow.tm_mday = 0; /* 01 January */
tmd_tomorrow.tm_hour = 0;
tmd_tomorrow.tm_min = 0;
tmd_tomorrow.tm_sec = 1;
@@ -118,48 +138,85 @@ pom(int year, int *fms, int *nms)
gmtime_r(&tt, &GMT);
yeardays = 0;
for (cnt = EPOCH; cnt < GMT.tm_year; ++cnt)
- yeardays += isleap(1900 + cnt) ? 366 : 365;
+ yeardays += isleap(1900 + cnt) ? DAYSPERLEAPYEAR : DAYSPERYEAR;
days_today = (GMT.tm_yday + 1) + ((GMT.tm_hour +
- (GMT.tm_min / 60.0) + (GMT.tm_sec / 3600.0)) / 24.0);
+ (GMT.tm_min / FSECSPERMINUTE) + (GMT.tm_sec / FSECSPERHOUR)) /
+ FHOURSPERDAY);
days_today += yeardays;
tt = mktime(&tmd_tomorrow);
gmtime_r(&tt, &GMT);
yeardays = 0;
for (cnt = EPOCH; cnt < GMT.tm_year; ++cnt)
- yeardays += isleap(1900 + cnt) ? 366 : 365;
+ yeardays += isleap(1900 + cnt) ? DAYSPERLEAPYEAR : DAYSPERYEAR;
days_tomorrow = (GMT.tm_yday + 1) + ((GMT.tm_hour +
- (GMT.tm_min / 60.0) + (GMT.tm_sec / 3600.0)) / 24.0);
+ (GMT.tm_min / FSECSPERMINUTE) + (GMT.tm_sec / FSECSPERHOUR)) /
+ FHOURSPERDAY);
days_tomorrow += yeardays;
today = potm(days_today); /* 30 December 23:59:59 */
tomorrow = potm(days_tomorrow); /* 31 December 00:00:01 */
olddir = today > tomorrow ? -1 : +1;
- yeardays = isleap(year) ? 366 : 365; /* reuse */
+ yeardays = 1 + isleap(year) ? DAYSPERLEAPYEAR : DAYSPERYEAR; /* reuse */
for (d = 0; d <= yeardays; d++) {
today = potm(days_today);
tomorrow = potm(days_tomorrow);
newdir = today > tomorrow ? -1 : +1;
- if (olddir == -1 && newdir == +1) {
- *pnms = d;
- pnms++;
- }
- if (olddir == +1 && newdir == -1) {
- *pfms = d;
- pfms++;
+ if (olddir != newdir) {
+ t = potm_minute(days_today - 1, olddir) +
+ utcoffset / FHOURSPERDAY;
+ if (olddir == -1 && newdir == +1) {
+ *pfnms = d - 1 + t;
+ pfnms++;
+ } else if (olddir == +1 && newdir == -1) {
+ *pffms = d - 1 + t;
+ pffms++;
+ }
}
olddir = newdir;
days_today++;
days_tomorrow++;
}
- *pfms = 0;
- *pnms = 0;
+ *pffms = -1;
+ *pfnms = -1;
+}
+
+static double
+potm_minute(double days, int olddir) {
+ double period = FSECSPERDAY / 2.0;
+ double p1, p2;
+ double before, after;
+ int newdir;
+
+// printf("---> days:%g olddir:%d\n", days, olddir);
+
+ p1 = days + (period / SECSPERDAY);
+ period /= 2;
+
+ while (period > 30) { /* half a minute */
+// printf("period:%g - p1:%g - ", period, p1);
+ p2 = p1 + (2.0 / SECSPERDAY);
+ before = potm(p1);
+ after = potm(p2);
+// printf("before:%10.10g - after:%10.10g\n", before, after);
+ newdir = before < after ? -1 : +1;
+ if (olddir != newdir)
+ p1 += (period / SECSPERDAY);
+ else
+ p1 -= (period / SECSPERDAY);
+ period /= 2;
+// printf("newdir:%d - p1:%10.10f - period:%g\n",
+// newdir, p1, period);
+ }
+ p1 -= floor(p1);
+ //exit(0);
+ return (p1);
}
/*
* potm --
- * return phase of the moon
+ * return phase of the moon, as a percentage [0 ... 100]
*/
static double
potm(double days)
Modified: user/edwin/calendar/sunpos.c
==============================================================================
--- user/edwin/calendar/sunpos.c Sat Feb 13 05:38:21 2010 (r203813)
+++ user/edwin/calendar/sunpos.c Sat Feb 13 08:23:47 2010 (r203814)
@@ -102,9 +102,9 @@ sunpos(int inYY, int inMM, int inDD, dou
if (inMM <= 2 && isleap(inYY))
ZJ -= 1.0;
- UTHM = inHOUR + inMIN / 60.0 + UTCOFFSET;
+ UTHM = inHOUR + inMIN / FSECSPERMINUTE + UTCOFFSET;
Y = inYY - 1900; /* 1 */
- D = floor(365.25 * Y) + ZJ + inDD + UTHM / 24; /* 3 */
+ D = floor(365.25 * Y) + ZJ + inDD + UTHM / FHOURSPERDAY; /* 3 */
T = D / 36525.0; /* 4 */
*L = 279.697 + 36000.769 * T; /* 5 */
fixup(L);
@@ -113,12 +113,12 @@ sunpos(int inYY, int inMM, int inDD, dou
epsilon = 23.452 - 0.013 * T; /* 7 */
fixup(&epsilon);
- lambda = *L + (1.919 - 0.005 * T) * SIN(M) + 0.020 * SIN(2 * M); /* 8 */
+ lambda = *L + (1.919 - 0.005 * T) * SIN(M) + 0.020 * SIN(2 * M);/* 8 */
fixup(&lambda);
alpha = ATAN(TAN(lambda) * COS(epsilon)); /* 9 */
/* Alpha should be in the same quadrant as lamba */
- if (1) {
+ {
int lssign = sin(D2R(lambda)) < 0 ? -1 : 1;
int lcsign = cos(D2R(lambda)) < 0 ? -1 : 1;
while (((sin(D2R(alpha)) < 0) ? -1 : 1) != lssign
@@ -206,7 +206,7 @@ equinoxsolstice(int year, double UTCoffs
found = 0;
prevdec = 350;
for (d = 18; d < 31; d++) {
- for (h = 0; h < 4 * 24; h++) {
+ for (h = 0; h < 4 * HOURSPERDAY; h++) {
sunpos(year, 3, d, UTCoffset, HOUR(h), MIN(h),
0.0, 0.0, &L, &dec);
if (SIGN(prevdec) != SIGN(dec)) {
@@ -231,7 +231,7 @@ equinoxsolstice(int year, double UTCoffs
found = 0;
prevdec = 10;
for (d = 18; d < 31; d++) {
- for (h = 0; h < 4 * 24; h++) {
+ for (h = 0; h < 4 * HOURSPERDAY; h++) {
sunpos(year, 9, d, UTCoffset, HOUR(h), MIN(h),
0.0, 0.0, &L, &dec);
if (SIGN(prevdec) != SIGN(dec)) {
@@ -258,7 +258,7 @@ equinoxsolstice(int year, double UTCoffs
prevdec = 0;
prevangle = 1;
for (d = 18; d < 31; d++) {
- for (h = 0; h < 4 * 24; h++) {
+ for (h = 0; h < 4 * HOURSPERDAY; h++) {
sunpos(year, 6, d, UTCoffset, HOUR(h), MIN(h),
0.0, 0.0, &L, &dec);
angle = ANGLE(prevdec, dec);
@@ -287,7 +287,7 @@ equinoxsolstice(int year, double UTCoffs
prevdec = 360;
prevangle = -1;
for (d = 18; d < 31; d++) {
- for (h = 0; h < 4 * 24; h++) {
+ for (h = 0; h < 4 * HOURSPERDAY; h++) {
sunpos(year, 12, d, UTCoffset, HOUR(h), MIN(h),
0.0, 0.0, &L, &dec);
angle = ANGLE(prevdec, dec);
@@ -329,7 +329,7 @@ calculatesunlongitude30(int year, int de
for (m = 1; m <= 12; m++) {
for (d = 1; d <= monthdays[m]; d++) {
- for (h = 0; h < 4 * 24; h++) {
+ for (h = 0; h < 4 * HOURSPERDAY; h++) {
sunpos(year, m, d,
-24 * (degreeGMToffset / 360.0),
HOUR(h), MIN(h), 0.0, 0.0, &curL, &dec);
@@ -358,7 +358,7 @@ printf("%04d-%02d-%02d %02d:%02d - %d %g
}
}
}
- *pichinesemonths = 0;
+ *pichinesemonths = -1;
return (firstmonth330);
}
More information about the svn-src-user
mailing list