This program calculates the Moon’s ecliptic longitude in degrees for a user-supplied calendar date, producing a numerical “moon phase” value from 0 to 359 degrees. The core calculation converts the Gregorian date to a Julian Day Number offset (subtracting 694038 to produce a reduced epoch), divides by 36525 to obtain Julian centuries, then applies a polynomial expansion of the Moon’s mean longitude including secular terms. The January/February adjustment at line 170 (decrementing the year and adding 12 to the month) is a standard technique for Julian Day Number conversion. Results are displayed as a rounded integer representing the Moon’s longitude, and the program loops continuously for new date entries.
Program Analysis
Program Structure
The program is organized into four clearly separated subroutines, each introduced by a REM block, with a main control loop at line 1000. Flow is entirely driven by GO SUB and GO TO:
- Lines 100–180: Date input and January/February correction
- Lines 200–280: Julian Day conversion and lunar longitude calculation
- Lines 300–350: Result display and keypress wait
- Lines 1000–1040: Main loop, calling subroutines in sequence and repeating indefinitely
The GO TO 1000 at line 20 skips the subroutine definitions, ensuring they are never accidentally fallen into on program start.
Date Normalization (Lines 170–180)
When the input month is January or February (m<3), the month is increased by 12 and the year decremented by 1. This is the standard pre-processing step required before Julian Day Number arithmetic, treating January and February as months 13 and 14 of the previous year. Without this step the INT(30.6*(m+1)) term in line 210 would produce incorrect day counts for the first two months of any year.
Astronomical Calculation (Lines 210–270)
The calculation proceeds in two stages. First, a Julian Day count offset is computed at line 210:
INT(365.25*y)— integer days in whole years (Julian calendar approximation)INT(30.6*(m+1))— integer days in whole months using the 30.6 coefficientdd - 694038— day of month minus a fixed epoch offset, reducing to a compact integer near J2000
This value is then divided by 36525 (days per Julian century) at line 220 to produce t, the time in Julian centuries from the epoch.
Lines 230–260 compute the Moon’s mean ecliptic longitude la as a polynomial in t, accumulating terms:
| Line | Term added | Astronomical meaning |
|---|---|---|
| 230 | 350.737486 + 1236·t·360 | Mean longitude epoch value plus full-revolution secular motion |
| 240 | 307·t + 6·t/60 | Additional linear and arcminute-scaled secular terms |
| 250 | 51.18·t/3600 − 5.17·t²/3600 | Arcsecond-scaled linear and quadratic correction terms |
| 260 | −INT(la/360)*360 | Reduction modulo 360° |
| 270 | INT(la+.5) | Round to nearest integer degree |
The large 1236*t*360 term at line 230 encodes the approximately 1,236 complete lunar revolutions per century. The division by 60 and 3600 at lines 240–250 suggest the original formula may have been specified with some coefficients in arcminutes and arcseconds respectively, converted inline.
Key BASIC Idioms
- Busy-wait keypress: Line 340 uses
IF INKEY$="" THEN GO TO 340— a standard polling loop to pause until any key is pressed. - Accumulating into a variable:
lais built up across lines 230–270 by repeatedLET la=la+...assignments, a common technique to work around the lack of multi-line expressions. - Infinite main loop: Line 1040 (
GO TO 1010) creates an unconditional loop back to the input subroutine; the only exit is theSTOPat line 9997, reachable only by directGO TOor breaking program execution.
Notable Techniques
The epoch offset of 694038 in line 210 corresponds to a Julian Day Number chosen to place the zero-point conveniently near a known lunar longitude reference. Using a reduced JDN rather than the full Julian Day Number (~2.4 million) keeps intermediate integer arithmetic within manageable bounds for BASIC’s floating-point.
Bugs and Anomalies
- Line 130 contains a typographical error:
"DETERNINATION OF MOONPHASE"should read"DETERMINATION OF MOONPHASE". This is a display-only issue and does not affect computation. - The program outputs only the Moon’s mean ecliptic longitude, not a conventional phase (New/First Quarter/Full/Last Quarter) or illumination percentage. The title “MOONPHASE” is therefore somewhat misleading; the result is more precisely the Moon’s mean longitude in degrees.
- No input validation is performed on
dd,m, ory, so out-of-range dates will silently produce erroneous results.
Content
Source Code
10 REM MOONPHASE ASTROLOGY
20 GO TO 1000
100 REM input date
110 CLS
130 PRINT "DETERNINATION OF MOONPHASE"
135 PRINT
140 INPUT "DAY (dd): ";dd: PRINT "Day : ";dd
150 INPUT "Month (mm): ";m: PRINT "Month: ";m
160 INPUT "Year (yyyy): ";y: PRINT "Year: ";y
170 IF m<3 THEN LET m=m+12: LET y=y-1
180 RETURN
200 REM calculation
210 LET t=INT (365.25*y)+INT (30.6*(m+1))+dd-694038
220 LET t=t/36525
230 LET la=350.737486+1236*t*360
240 LET la=la+307*t+6*t/60
250 LET la=la+51.18*t/3600-5.17*t*t/3600
260 LET la=la-INT (la/360)*360
270 LET la=INT (la+.5)
280 RETURN
300 REM display result
310 PRINT : PRINT
320 PRINT "Moonphase=";la;" degrees"
330 PRINT : PRINT "Press any key"
340 IF INKEY$="" THEN GO TO 340
350 RETURN
1000 REM main program
1010 GO SUB 100: REM input date
1020 GO SUB 200: REM calculation
1030 GO SUB 300: REM display result
1040 GO TO 1010
9997 STOP
9998 SAVE "MOONPHASE" LINE 1
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
