[comp.sys.hp] moon phase program for the 28S

taff@venus.ucsc.edu (Thomas Affinito,,,4582136) (08/01/88)

ok, someone sent a message about two weeks ago requesting a moon phase
program for the 28S...i didn't have anything at the time, but recently came
across an algorithm for this problem in John Ball's "Algorithms for RPN
Calculators". I'll try to explain the algorithm so you all can write your own
programs if you want; I've also included my solution in case you're interested.

The algorithm: John Ball gets credit for this guys; also creditted in the
book is Norman M. Brenner, who wrote an HP 25 program version of this.

N = D + [367 * ((M - 2)/12 + X)] + [[365.25 * (Y - X)] - 0.75 * C]

where N is the day number (actually, N + 1721089 is the Julian day number used
by astronomers)
M, D, Y are the month, day, and year of the date we're interested in
X is 0, unless M is 1 or 2, in which case X = 1
C is 2 if S is 0, else C is [(Y - X) / 100]
	S is 0 if M, D, Y specify an old style, pre-Julian date
	S is 1 if M, D, Y specify a Julian date

also, the [] above denote truncation (ie, IP on a 28).

So, if you want to calculate how many days elapse from one date to another,
just specify M1, D1, Y1 and S1 to get N1, then M2, D2, Y2 and S2 to get N2,
then do N2 - N1.

If you take N, divide it by 7, take the fractional part, and multiply by 7,
you'll get the day of the week....where 0 is Sunday, 1 is Monday, ...

If you take N, divide it by 29.53059, and take the fractional part, you'll get
the moon phase, where 0 is first quarter, .25 is full, .5 is third quarter, and
.75 is new.



My solution: I wrote a program call DAYN that should be run from the Solver;
that is, store 'DAYN' in EQ and go to the Solver menu and you'll see
boxes for M, D, Y, and S. Enter your date, then press EXPR= and you'll
get N on the stack.

Now, I tinkered a bit, and added a program called MOON which is called by DAYN
... MOON leaves a string on the stack which tells you the day, the moon phase,
and how many days have gone by since the moon phase listed. For example, setting
M to 9 (September), D to 18, Y to 1965, S to 1 (my birthday!) and then pressing
EXPR= returns 717933 and "SAT/ 3rd + 0" (ie, I was born on Saturday exactly
on the third quarter). This is good, but now DROP (goodbye string!) and then do
M gets 7, D gets 30, Y gets 1988 (S stays the same so we don't have to worry),
then EXPR=, and 726284 and "SAT/ Ful + 1" are returned (the "+ 1" means it's
one day past the full moon). Do DROP - and you'll find out that it's been 8351
days from my birth to this year's Katemas! WOW.

DAYN
<< M D Y S 4 DROPN                  <-  so the Solver boxes are in a nice order
M 2 <= -1 0 IFTE                    the <= is the less than or equal to key
S OVER Y + 100 / IP 2 IFTE
-.75 * OVER Y + 365.25 * IP
+ IP M 2 - 12 / ROT - 367 * IP
+ D + MOON
>>

MOON
<< "SUNMONTUEWEDTHUFRISAT" OVER 7 / FP 21 * 1 + DUP 2 + SUB "/ " +
OVER 29.53059 / FP DUP .25 / IP 3 * 1 + "1stFul3rdNew" SWAP DUP 2 + SUB " + " +
SWAP .25 MOD .033863 / .5 + IP ->STR + +
>>


can anyone cut some keystrokes on the above? (there should be a way to work in
% to help with the (Y-X)/100 part, but I haven't thought of a shorter way yet).

enjoy!

-----------
Thomas J. Affinito 
UC Santa Cruz, Board of Computer & Information Sciences
Internet:  taff@saturn.ucsc.edu or taff%saturn@ucscc.ucsc.edu
Bitnet:    taff@ucsccrls (probably)
Postal addr:  Box 14 Grad Student Housing, 401 Heller Dr., Santa Cruz CA 95064