]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - pom/pom.c
2 * Copyright (c) 1989 The Regents of the University of California.
5 * This code is derived from software posted to USENET.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 "@(#) Copyright (c) 1989 The Regents of the University of California.\n\
39 All rights reserved.\n";
43 /*static char sccsid[] = "from: @(#)pom.c 5.3 (Berkeley) 2/28/91";*/
44 static char rcsid
[] = "$Id: pom.c,v 1.2 1993/08/01 18:53:16 mycroft Exp $";
48 * Phase of the Moon. Calculates the current phase of the moon.
49 * Based on routines from `Practical Astronomy with Your Calculator',
50 * by Duffett-Smith. Comments give the section from the book that
51 * particular piece of code was adapted from.
53 * -- Keith E. Brandt VIII 1984
62 #define PI 3.141592654
64 #define EPSILONg 279.611371 /* solar ecliptic long at EPOCH */
65 #define RHOg 282.680403 /* solar ecliptic long of perigee at EPOCH */
66 #define ECCEN 0.01671542 /* solar orbit eccentricity */
67 #define lzero 18.251907 /* lunar mean long at EPOCH */
68 #define Pzero 192.917585 /* lunar mean long of perigee at EPOCH */
69 #define Nzero 55.204723 /* lunar mean long of node at EPOCH */
71 double dtor(), potm(), adj360();
78 struct tm
*GMT
, *gmtime();
79 double days
, today
, tomorrow
;
83 if (gettimeofday(&tp
,&tzp
)) {
84 (void)fprintf(stderr
, "pom: %s\n", strerror(errno
));
87 GMT
= gmtime(&tp
.tv_sec
);
88 days
= (GMT
->tm_yday
+ 1) + ((GMT
->tm_hour
+
89 (GMT
->tm_min
/ 60.0) + (GMT
->tm_sec
/ 3600.0)) / 24.0);
90 for (cnt
= EPOCH
; cnt
< GMT
->tm_year
; ++cnt
)
91 days
+= isleap(cnt
) ? 366 : 365;
92 today
= potm(days
) + .5;
93 (void)printf("The Moon is ");
94 if ((int)today
== 100)
95 (void)printf("Full\n");
97 (void)printf("New\n");
99 tomorrow
= potm(days
+ 1);
100 if ((int)today
== 50)
101 (void)printf("%s\n", tomorrow
> today
?
102 "at the First Quarter" : "at the Last Quarter");
104 (void)printf("%s ", tomorrow
> today
?
105 "Waxing" : "Waning");
107 (void)printf("Gibbous (%1.0f%% of Full)\n",
110 (void)printf("Crescent (%1.0f%% of Full)\n",
118 * return phase of the moon
124 double N
, Msol
, Ec
, LambdaSol
, l
, Mm
, Ev
, Ac
, A3
, Mmprime
;
125 double A4
, lprime
, V
, ldprime
, D
, Nm
;
127 N
= 360 * days
/ 365.2422; /* sec 42 #3 */
129 Msol
= N
+ EPSILONg
- RHOg
; /* sec 42 #4 */
131 Ec
= 360 / PI
* ECCEN
* sin(dtor(Msol
)); /* sec 42 #5 */
132 LambdaSol
= N
+ Ec
+ EPSILONg
; /* sec 42 #6 */
134 l
= 13.1763966 * days
+ lzero
; /* sec 61 #4 */
136 Mm
= l
- (0.1114041 * days
) - Pzero
; /* sec 61 #5 */
138 Nm
= Nzero
- (0.0529539 * days
); /* sec 61 #6 */
140 Ev
= 1.2739 * sin(dtor(2*(l
- LambdaSol
) - Mm
)); /* sec 61 #7 */
141 Ac
= 0.1858 * sin(dtor(Msol
)); /* sec 61 #8 */
142 A3
= 0.37 * sin(dtor(Msol
));
143 Mmprime
= Mm
+ Ev
- Ac
- A3
; /* sec 61 #9 */
144 Ec
= 6.2886 * sin(dtor(Mmprime
)); /* sec 61 #10 */
145 A4
= 0.214 * sin(dtor(2 * Mmprime
)); /* sec 61 #11 */
146 lprime
= l
+ Ev
+ Ec
- Ac
+ A4
; /* sec 61 #12 */
147 V
= 0.6583 * sin(dtor(2 * (lprime
- LambdaSol
))); /* sec 61 #13 */
148 ldprime
= lprime
+ V
; /* sec 61 #14 */
149 D
= ldprime
- LambdaSol
; /* sec 63 #2 */
150 return(50 * (1 - cos(dtor(D
)))); /* sec 63 #3 */
155 * convert degrees to radians
161 return(deg
* PI
/ 180);
166 * adjust value so 0 <= deg <= 360