source: buchla-68k/orig/DATE/MPHASE.C@ 0170798

Last change on this file since 0170798 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 1.5 KB
Line 
1/*
2 =============================================================================
3 mphase.c -- calculate the phase of the moon
4 Version 1 -- 1988-01-14 -- D.N. Lynx Crowe
5
6 Modified version of the public domain code from Usenet.
7 Original author unknown.
8 =============================================================================
9*/
10
11#define MAIN 1
12
13#include "stddefs.h"
14#include "time.h"
15
16struct tm *lcltime();
17
18/*
19 =============================================================================
20 mphase() -- return the phase of the moon
21
22 returns 0..7 where: 0 = new, 4 = full
23 =============================================================================
24*/
25
26int
27mphase(lt)
28register struct tm *lt;
29{
30 /* moon period: 29.5306 days */
31 /* year: 365.2422 days */
32
33 register int epact, diy, golden;
34
35 diy = lt->tm_yday;
36
37 golden = (lt->tm_year % 19) + 1;
38
39 epact = (11 * golden + 18) % 30;
40
41 if (((epact EQ 25) AND (golden > 11)) OR (epact EQ 24))
42 epact++;
43
44 return( (((((diy + epact) * 6) + 11) % 177) / 22) & 7);
45}
46
47/*
48
49*/
50
51#if MAIN
52
53#include "stdio.h"
54
55char *mph[] = {
56 "new",
57 "waxing, in its first quarter",
58 "in its first quarter",
59 "waxing full",
60 "full",
61 "waning full",
62 "in its last quarter",
63 "waning, in its last quarter" };
64
65long lcldate;
66struct tm lcltm;
67
68struct tm *
69getlt()
70{
71 time(&lcldate);
72 return(lcltime(&lcldate, &lcltm));
73}
74
75main()
76{
77 printf("The moon is %s.\n", mph[mphase(getlt())]);
78}
79
80#endif
81
Note: See TracBrowser for help on using the repository browser.