1 | /*
|
---|
2 | =============================================================================
|
---|
3 | moon.c -- calculate the phase of the moon
|
---|
4 | Version 3 -- 1988-12-05 -- D.N. Lynx Crowe
|
---|
5 |
|
---|
6 | Modified version of the public domain code "mphase.c" from Usenet.
|
---|
7 | Original author unknown.
|
---|
8 |
|
---|
9 | Modified to run under GEMDOS.
|
---|
10 | =============================================================================
|
---|
11 | */
|
---|
12 |
|
---|
13 | #define MAIN 1
|
---|
14 |
|
---|
15 | #include "stddefs.h"
|
---|
16 |
|
---|
17 | /*
|
---|
18 | =============================================================================
|
---|
19 | mphase() -- return the phase of the moon
|
---|
20 |
|
---|
21 | returns 0..7 where: 0 = new, 4 = full
|
---|
22 | =============================================================================
|
---|
23 | */
|
---|
24 |
|
---|
25 | int
|
---|
26 | mphase(year, diy)
|
---|
27 | register int year, diy;
|
---|
28 | {
|
---|
29 | /* moon period: 29.5306 days */
|
---|
30 | /* year: 365.2422 days */
|
---|
31 |
|
---|
32 | register int epact, golden;
|
---|
33 |
|
---|
34 | golden = (year % 19) + 1;
|
---|
35 |
|
---|
36 | epact = (11 * golden + 18) % 30;
|
---|
37 |
|
---|
38 | if (((epact EQ 25) AND (golden > 11)) OR (epact EQ 24))
|
---|
39 | epact++;
|
---|
40 |
|
---|
41 | return( (((((diy + epact) * 6) + 11) % 177) / 22) & 7);
|
---|
42 | }
|
---|
43 |
|
---|
44 | /* |
---|
45 |
|
---|
46 | */
|
---|
47 |
|
---|
48 | #if MAIN
|
---|
49 |
|
---|
50 | #include "stdio.h"
|
---|
51 |
|
---|
52 | char *mph[] = {
|
---|
53 |
|
---|
54 | "new",
|
---|
55 | "waxing, in its first quarter",
|
---|
56 | "in its first quarter",
|
---|
57 | "waxing full",
|
---|
58 | "full",
|
---|
59 | "waning full",
|
---|
60 | "in its last quarter",
|
---|
61 | "waning, in its last quarter" };
|
---|
62 |
|
---|
63 | main()
|
---|
64 | {
|
---|
65 | register int year; /* year */
|
---|
66 | register int diy; /* day in year */
|
---|
67 |
|
---|
68 | if (argc NE 3) {
|
---|
69 |
|
---|
70 | printf("usage: moon year day-in-year\n");
|
---|
71 | exit(1);
|
---|
72 | }
|
---|
73 |
|
---|
74 | year = atoi(argv[1]);
|
---|
75 | diy = atoi(argv[2]);
|
---|
76 |
|
---|
77 | printf("The moon is %s.\n", mph[mphase(year, diy)]);
|
---|
78 | }
|
---|
79 |
|
---|
80 | #endif
|
---|
81 |
|
---|