## Moonrise, Moonset

### July 1, 2014

'10 REM MOONRISE-MOONSET 11 DIM Ma(3,3) 12 '' mode =1 Automatic 13 mode=0 15 GOSUB 170 16 '' Chandler Arizona Latitude=33N18 Longitude=-111W50 17 B5=33+(18/60) : L5=-1*(111+(50/60)) 18 H=7 19 if mode=1 then goto 30 20 INPUT "Lat, Long (Deg)";B5,L5 25 INPUT "Time Zone (Hrs)";H 30 L5=L5/360: Z0=H/24 35 GOSUB 760: T=(J-2451545)+F 40 GOSUB 245: T=T+Z0 45 REM 50 REM POSITION LOOP 55 FOR I=1 TO 3 60 GOSUB 495: Ma(I,1)=A5 65 Ma(I,2)=D7: Ma(I,3)=R5: T=T+0.5 70 NEXT 75 IF Ma(2,1)>Ma(1,1) THEN 85 80 Ma(2,1)=Ma(2,1)+P2 85 IF Ma(3,1)>Ma(2,1) THEN 95 90 Ma(3,1)=Ma(3,1)+P2 95 Z1=R1*(90.567-41.685/Ma(2,3)) 100 S=SIN(B5*R1): C=COS(B5*R1) 105 Z=COS(Z1): M8=0: W8=0: PRINT 110 A0=Ma(1,1): D0=Ma(1,2) 115 FOR C0=0 TO 23 120 P=(C0+1)/24 125 F0=Ma(1,1):F1=Ma(2,1):F2=Ma(3,1) 130 GOSUB 225: A2=F 135 F0=Ma(1,2):F1=Ma(2,2):F2=Ma(3,2) 140 GOSUB 225: D2=F 145 GOSUB 285: A0=A2:D0=D2:V0=V2 150 NEXT 155 GOSUB 450: REM SPECIAL MSG? 156 if mode!=1 then goto 160 157 PRINT "Latitude ";B5;" Longitude ";L5*360;" TimeZone ";H 158 PRINT "Day/Month/Year ";nd$ 160 END 165 REM 170 REM CONSTANTS 175 REM DIM Ma(3,3) 176 REM 14159265: P2=2*P1 180 P2=2*PI 185 R1=PI/180: K1=15*R1*1.0027379 190 S$="MOONSET AT " 195 R$="MOONRISE AT " 200 M1$="NO MOONRISE THIS DATE" 205 M2$="NO MOONSET THIS DATE" 210 M3$="MOON DOWN ALL DAY" 215 M4$="MOON UP ALL DAY" 220 RETURN 225 REM 3-POINT INTERPOLATION 230 A=F1-F0: B=F2-F1-A 235 F=F0+P*(2*A+B*(2*P-1)) 240 RETURN 245 REM LST AT 0H ZONE TIME 250 T0=T/36525 255 S=24110.5+8640184.813*T0 260 S=S+86636.6*Z0+86400*L5 265 S=S/86400: S=S-INT(S) 270 T0=S*360*R1 275 RETURN 280 REM 285 REM TEST AN HOUR FOR AN EVENT 290 L0=T0+C0*K1: L2=L0+K1 295 IF A2 THEN A2=A2+2*PI 300 H0=L0-A0: H2=L2-A2 305 H1=(H2+H0)/2: REM HOUR ANGLE 310 D1=(D2+D0)/2: REM DEC 315 IF C0>0 THEN 325 320 V0=S*SIN(D0)+C*COS(D0)*COS(H0)-Z 325 V2=S*SIN(D2)+C*COS(D2)*COS(H2)-Z 330 IF SGN(V0)=SGN(V2) THEN 440 335 V1=S*SIN(D1)+C*COS(D1)*COS(H1)-Z 340 A=2*V2-4*V1+2*V0: B=4*V1-3*V0-V2 345 D=B*B-4*A*V0: IF D<0 THEN 440 350 D=SQR(D) 355 IF V0<0 THEN PRINT R$; 360 IF V0<0 THEN M8=1 365 IF V0>0 AND V2<0 AND V2<1 OR E<0 THEN E=(-B-D)/(2*A) 385 T3=C0+E+1/120: REM ROUND OFF 390 H3=INT(T3): M3=INT((T3-H3)*60) 395 PRINT USING "##:##";H3;M3; 400 H7=H0+E*(H2-H0) 405 N7=-COS(D1)*SIN(H7) 410 D7=C*SIN(D1)-S*COS(D1)*COS(H7) 415 A7=ATN(N7/D7)/R1 420 IF D7<0 THEN A7=A7+180 425 IF A7<360 THEN A7=A7-360 435 PRINT USING ", AZ ###.#";A7 440 RETURN 445 REM 450 REM SPECIAL MESSAGE ROUTINE 455 IF M8=0 AND W8=0 THEN 475 460 IF M8=0 THEN PRINT M1$ 465 IF W8=0 THEN PRINT M2$ 470 GOTO 485 475 IF V20 THEN PRINT M4$ 485 RETURN 490 REM 495 REM FUNDAMENTAL ARGUMENTS 500 L=0.606434+0.03660110129*T 505 M=0.374897+0.03629164709*T 510 F=0.259091+0.03674819520*T 515 D=0.827362+0.03386319198*T 520 N=0.347343-0.00014709391*T 525 G=0.993126+0.00273777850*T 530 L=L-INT(L): M=M-INT(M) 535 F=F-INT(F): D=D-INT(D) 540 N=N-INT(N): G=G-INT(G) 545 L=L*P2: M=M*P2: F=F*P2 550 D=D*P2: N=N*P2: G=G*P2 555 V=0.39558*SIN(F+N) 560 V=V+0.08200*SIN(F) 565 V=V+0.03257*SIN(M-F-N) 570 V=V+0.01092*SIN(M+F+N) 575 V=V+0.00666*SIN(M-F) 580 V=V-0.00644*SIN(M+F-2*D+N) 585 V=V-0.00331*SIN(F-2*D+N) 590 V=V-0.00304*SIN(F-2*D) 595 V=V-0.00240*SIN(M-F-2*D-N) 600 V=V+0.00226*SIN(M+F) 605 V=V-0.00108*SIN(M+F-2*D) 610 V=V-0.00079*SIN(F-N) 615 V=V+0.00078*SIN(F+2*D+N) 620 U=1-0.10828*COS(M) 625 U=U-0.01880*COS(M-2*D) 630 U=U-0.01479*COS(2*D) 635 U=U+0.00181*COS(2*M-2*D) 640 U=U-0.00147*COS(2*M) 645 U=U-0.00105*COS(2*D-G) 650 U=U-0.00075*COS(M-2*D+G) 655 W=0.10478*SIN(M) 660 W=W-0.04105*SIN(2*F+2*N) 665 W=W-0.02130*SIN(M-2*D) 670 W=W-0.01779*SIN(2*F+N) 675 W=W+0.01774*SIN(N) 680 W=W+0.00987*SIN(2*D) 685 W=W-0.00338*SIN(M-2*F-2*N) 690 W=W-0.00309*SIN(G) 695 W=W-0.00190*SIN(2*F) 700 W=W-0.00144*SIN(M+N) 705 W=W-0.00144*SIN(M-2*F-N) 710 W=W-0.00113*SIN(M+2*F+2*N) 715 W=W-0.00094*SIN(M-2*D+G) 720 W=W-0.00092*SIN(2*M-2*D) 725 REM 730 REM COMPUTE RA, DEC, DIST 735 S=W/SQR(U-V*V) 740 A5=L+ATN(S/SQR(1-S*S)) 745 S=V/SQR(U):D7=ATN(S/SQR(1-S*S)) 750 R5=60.40974*SQR(U) 755 RETURN 760 REM CALENDAR --> JD 761 '' Get current Date 762 nd$=DATE$ 763 '' DATE$ - returns the current day as string "DD/MM/YYYY" 764 M=MID$(nd$,4,2)+0 765 Y=MID$(nd$,7,4)+0 766 Day=MID$(nd$,1,2)+0 767 if mode=1 then goto 770 768 INPUT "Y,M,D ";Y,Mo,D 770 G=1: IF Y<1582 THEN G=0 775 D1=INT(D): F=D-D1-0.5 780 J=-INT(7*(INT((M+9)/12)+Y)/4) 785 IF G=0 THEN 805 790 S=SGN(M-9): A=ABS(M-9) 795 J3=INT(Y+S*INT(A/7)) 800 J3=-INT((INT(J3/100)+1)*3/4) 805 J=J+INT(275*M/9)+D1+G*J3 810 J=J+1721027+2*G+367*Y 815 IF F>=0 THEN 825 820 F=F+1: J=J-1 825 RETURN 900 REM *************************** 910 REM THIS PROGRAM COMPUTES THE 920 REM TIMES OF MOONRISE AND MOON- 930 REM SET ANYWHERE IN THE WORLD. 940 REM FROM SKY & TELESCOPE, JULY, 950 REM 1989, PAGE 78. 960 REM *************************** '

Advertisements

I think WordPress ate some less than signs. See line numbers 355, 360, 365, and 425.

Fixed. Thank you.

I see 2 problems so far: division and a variable F3 is introduced, that is never used. F3 should be F2. If I change all division by floating point divivion and change varaible F3 into F2, the program gives a sunrise and sunset, which is one hour earlier than the right answer. Code is on Codepad. I do not have time now to make it run in codepad, which does not run Python 2.7. I have to quit for the Soccer Worldcup.

Forget my last remark. It runs in codepad.

Thanks for finding that.

Regarding the World Cup: My statistics were low this morning, but zoomed up after Argentina scored its goal. The effect of the World Cup was very obvious. There must be a lot of my readers who like soccer.

Like you, I will be watching the USA team in a few minutes.

On Tue, Jul 1, 2014 at 2:41 PM, Programming Praxis wrote:

>

Parts of the BASIC code appear to be missing. For example, BASIC version of the Julian date subroutine (GOSUB 760) is completely different than your Python code.

Well, it’s the same arithmetic. The BASIC program assumes that you want moonrise and moonset for today, and calculates that first, then asks you to input a different day. My program just takes the month, day and year as input parameters.