[comp.sys.handhelds] More accurate phase of the moon program

gerson@parc.xerox.com (Dan Gerson) (07/12/90)

Here is an improved program to calculate and display the phase of the moon.  It
uses the drawing routines provided by Craig Finseth's phase of the moon program,
(with the modifications to FLIP as suggested by Preston Brown and Juri Munkki),
but has an adapted version of the very complicated phase calcuation in John
Walker's moontool application on the SUN.  The HP48SX results are exactly the
same as those obtained from Moontool, which appear to be extremely accurate,
unlike the previous moon phase program.

To use it, you have to write out your current time difference from UTC in a
TMZN global variable somewhere; I have my system setup with TMZN stored in { HOME }
so it is available to other programs I use.  Otherwise, you can just put it
in the same directory as your put { JDAT }.  For example, the correct value for
California is currently 7.

Then {MPHASE} displays the current phase of the moon graphically using Craig Finseth's
code, {MTIME} returns a string containing the number of days, hours, and minutes
from the last new moon along with the current percentage of the moon which is
illuminated, {MFRAC} returns the illuminated percentage to level 2 and the
percentage of the moon's age since the last new moon in level 1, and finally,
{JDAT} return the current civil julian date and fraction of the day (UTC).

Checksum: #D058h (I think - I tend to edit the text on my mac sometimes.)
Size: 2002
------------------------------------------------------------
%%HP: T(3)A(D)F(.);
DIR
  MPHASE
    \<< RCLF -31 SF
DEG ERASE { # 0h
# 0h } PVIEW {
# 40h # 1Ch } # 1Ah
0 360 ARC 26 28
MFRAC SWAP DROP
MPLOT MFINI 7
FREEZE STOF
    \>>
  MTIME
    \<< MFRAC \-> PCT X
      \<< X
29.53058868 * DUP
'X' STO IP "d " + X
FP 24 * IP + "h " +
X FP 1440 * 60 MOD
IP + "m (" + PCT
100 * 0 RND + "%)"
+
      \>>
    \>>
  MFRAC
    \<< RCLF 0 0 0 0
0 0 JDAT 2444239 -
\-> FLGS M ML MM EV
AE A3 day
      \<< RAD day
.985647332099 * 360
MOD -3.762863 + 360
MOD D\->R 'M' STO 'E=
.016718*SIN(E)+M'
'E' M ROOT 2 / TAN
1.01686011182 *
ATAN R\->D 2 *
282.596403 + 360
MOD 'E' STO
13.1763966 day *
64.975464 + 360 MOD
DUP 'ML' STO
.1114041 day * -
349.383063 - 360
MOD 'MM' STO ML E -
2 * MM - D\->R SIN
1.2739 * 'EV' STO M
SIN DUP .1858 *
'AE' STO .37 * 'A3'
STO MM EV + AE - A3
- DUP D\->R SIN
6.2886 * SWAP 2 *
D\->R SIN .214 * SWAP
EV + ML + AE - +
DUP E - 2 * D\->R SIN
.6583 * + E - DUP
D\->R COS NEG 1 + 2 /
'Illuminated' \->TAG
SWAP 360 / 'Age'
\->TAG FLGS STOF
      \>>
    \>>
  JDAT
    \<< 1.01198 DATE
DDAYS 2444240 +
TIME HMS\-> TMZN + 24
/ +
    \>>
  MPLOT
    \<< \-> RA MI F
      \<<
        IF F .5 <
        THEN F 360
* COS RA * RA
        ELSE RA NEG
F .5 - 360 * COS RA
*
        END \-> L R
        \<< 1 0
          FOR x x
ACOS SIN DUP MI x
RA * + L R MLINE MI
x RA * - L R MLINE
RA INV NEG
          STEP
        \>>
      \>>
    \>>
  MLINE
    \<< \-> SC LI L R
      \<< SC L * 64 +
R\->B LI R\->B 2 \->LIST
SC R * 64 + R\->B LI
R\->B 2 \->LIST LINE
      \>>
    \>>
  MFINI
    \<< { # Ah # Ah }
PIXON { # 6Eh # Fh
} PIXON { # 64h
# 32h } PIXON {
# 1Eh # 29h } PIXON
{ # 1Fh # 29h }
PIXON PICT NEG
    \>>
  SLOFLIP
    \<< 0 63
      FOR l # 0h l
R\->B 2 \->LIST # 82h l
R\->B 2 \->LIST TLINE
      NEXT
    \>>
  E 109.444275789
END