Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!floyd!harpo!seismo!hao!hplabs!sri-unix!mar@mit-borax From: mar%mit-borax@sri-unix.UUCP Newsgroups: net.micro Subject: Re: astronomical references/algorithms wanted Message-ID: <17663@sri-arpa.UUCP> Date: Sun, 18-Mar-84 14:36:26 EST Article-I.D.: sri-arpa.17663 Posted: Sun Mar 18 14:36:26 1984 Date-Received: Tue, 20-Mar-84 01:19:11 EST Lines: 37 From: Mark A. RosensteinI computed the phase of the moon by a fairly simple algorithm: A reference handbook lists the lunar month at 2551442.8 seconds. Find the number of seconds since an arbitrary time in the past (such as midnight Jan 1, 1980). Take that time modulo the length of a lunar month. You now have the number of seconds into this month's cycle. You can then check for which quarter you are in. The following listing uses the fact that Unix remembers dates as the number of seconds from Jan 1, 1970. -------------------------------- /* pom.c */ #include #define cycle 2251443 /* length of lunar month */ #define qcycle (cycle/4) #define offset qcycle + 4*86400-400 /* how long til the first full moon after Jan 1, 1970 */ extern long time(); char *quarter[] = {"New Moon", "First Quarter", "Full Moon "Last Quarter"}; long rem, qtr, day, hour, min, sec, instant; main() { rem = (time(0) + offset)%cycle; qtr = rem/qcycle; rem = rem%qcycle; day = rem/86400; rem = rem%86400; hour = rem/3600; rem = rem%3600; min = rem/60; sec = rem%60; printf(" %s+%dD,%dH,%dM,%dS\n", quarter[qtr], day, hour, min, sec); }