home *** CD-ROM | disk | FTP | other *** search
/ RBBS in a Box Volume 1 #3.1 / RBBSIABOX31.cdr / swal / sunrise.bas < prev    next >
Encoding:
BASIC Source File  |  1984-09-21  |  3.8 KB  |  94 lines

  1. 100 REM ------------- THIS PROGRAM FOR IBM PC IN BASIC ------------------
  2. 110 REM One note regarding azimuth angles: In the SOUTHERN hemisphere,
  3. 120 REM this program assumes that the South Pole is zero degrees, and
  4. 130 REM the azimuth angle is measured COUNTER-clockwise through East.
  5. 140 REM Therefore, an azimuth angle of 108 degrees is NORTH of East.
  6. 150 REM When Lat and Long are input, use a negative value for Southern
  7. 160 REM Latitudes and for Eastern Longitudes.
  8. 170 REM NOTE: Although I can't guarantee perfect accuracy for this program,
  9. 180 REM it has been checked a couple of dozen times against the Nautical
  10. 190 REM Almanac and the worst case error in sunrise/sunset seems to
  11. 200 REM be 5 minutes. If anyone has better equations for the calculation,
  12. 210 REM please upload them.
  13. 220 REM Also note that times are local STANDARD time. If some form of
  14. 230 REM 'savings' time is in effect, results may be different -- use
  15. 240 REM GMT time to be sure.
  16. 250 REM ----------------- Program Begins ---------------------------
  17. 260 CLS
  18. 270 PRINT"This program finds the declination of the sun, the equation"
  19. 280 PRINT"of time, the azimuth angles of sunrise and sunset, and the"
  20. 290 PRINT"times of sunrise and sunset for any point on earth."
  21. 300 PRINT
  22. 310 PRINT"Input eastern longitudes and southern latitudes as NEGATIVE."
  23. 320 PRINT
  24. 330 PRINT
  25. 340 DIM N(12)
  26. 350 PL=3.14159/26:J=57.2958
  27. 360 INPUT"ENTER LATITUDE (FORMAT DD.MM)";D1
  28. 370 INPUT"ENTER LONGITUDE (FORMAT DD.MM)";D2
  29. 380 GOSUB 930
  30. 390 LA = D1
  31. 400 IF LA < 0 THEN LA = LA + 180
  32. 410 IF D2 < 0 THEN D2 = D2 + 360
  33. 420 LO = FIX(D2/15)*15 :REM finds time zone beginning
  34. 430 TD=(D2-LO)/15
  35. 440 INPUT"ENTER MONTH,DAY (11,25)";M,DA
  36. 450 FOR I=1 TO 12: READ N(I):NEXT I
  37. 460 DATA 0,31,59,90,120,151
  38. 470 DATA 181,212,243,273,304,334
  39. 480 X=(N(M)+DA)/7
  40. 490 REM
  41. 500 D=.456-22.195*COS(PL*X)-.43*COS(2*PL*X)-.156*COS(3*PL*X)+3.83*SIN(PL*X)+.06*SIN(2*PL*X)-.082*SIN(3*PL*X)
  42. 510 REM
  43. 520 PRINT
  44. 530 PRINT"DECLINATION OF SUN:";
  45. 540 PRINT USING"###.#";D;
  46. 550 PRINT" DEGREES"
  47. 560 E=.008+.51*COS(PL*X)-3.197*COS(2*PL*X)-.106*COS(3*PL*X)-.15*COS(4*PL*X)-7.317001*SIN(PL*X)-9.471001*SIN(2*PL*X)-.391*SIN(3*PL*X)-.242*SIN(4*PL*X)
  48. 570 PRINT"EQUATION OF TIME:";
  49. 580 PRINT USING"###.#";E;
  50. 590 PRINT" MINUTES"
  51. 600 CL=COS(LA/J):SD=SIN(D/J):CD=COS(D/J):Y=SD/CL
  52. 610 IF ABS(Y)=>1 THEN PRINT"NO SUNRISE OR SUNSET":END
  53. 620 Z = 90 - J*ATN(Y/SQR(1-Y*Y))
  54. 630 PRINT"AZIMUTH OF SUNRISE:";
  55. 640 PRINT USING"####.#";ABS(Z);
  56. 650 PRINT" DEGREES"
  57. 660 PRINT"AZIMUTH OF SUNSET: ";
  58. 670 PRINT USING"####.#";360-ABS(Z);
  59. 680 PRINT" DEGREES"
  60. 690 ST=SIN(Z/J)/CD
  61. 700 IF ABS(ST)>=1 THEN T=6:TT=6:GOTO 740
  62. 710 CT=SQR(1-ST*ST)
  63. 720 T=J/15*ATN(ST/CT)
  64. 730 TT=T
  65. 740 IF D<0 AND LA<90 THEN T=12-T:TT=T
  66. 750 IF D>0 AND LA>90 THEN T=12-T: TT=T
  67. 760 T=T+TD-E/60-.04
  68. 770 GOSUB 840
  69. 780 PRINT"TIME OF SUNRISE:";T1$;":";T2$;" ";T$;"L.T. ";GM$;":";T2$;" GMT"
  70. 790 T=12-TT:T=T+TD-E/60+.04
  71. 800 CNT=1
  72. 810 GOSUB 840
  73. 820 PRINT"TIME OF SUNSET: ";T1$;":";T2$;" ";T$;"L.T. ";GM$;":";T2$;" GMT"
  74. 830 END
  75. 840 T1=INT(T):T2=T-T1:T1$=STR$(T1):T2=INT((T2*600+5)/10)
  76. 850 T2$=STR$(T2):T2$=RIGHT$(T2$,LEN(T2$)-1)
  77. 860 IF INT(T2)<10 THEN T2$="0"+T2$
  78. 870 GM = FIX(D2/15) :REM calculate difference between GMT and local time
  79. 880 IF CNT = 0 THEN GM = VAL(T1$)+GM :REM GMT for sunrise
  80. 890 IF CNT > 0 THEN GM = VAL(T1$)+12+GM :REM GMT for sunset
  81. 900 IF GM +(VAL(T2$)/60)> 24 THEN GM = GM - 24
  82. 910 GM$ = STR$(GM) :GM$ = RIGHT$("0"+GM$,2)
  83. 920 RETURN
  84. 930 REM This subroutine converts DD.MM input to DD.DD
  85. 940 DEGTMP = (ABS(D1)-ABS(FIX(D1))) *100/60
  86. 950 D1 = (FIX(ABS(D1))+DEGTMP)*SGN(D1)
  87. 960 DEGTMP = (ABS(D2)-ABS(FIX(D2))) *100/60
  88. 970 D2 = (FIX(ABS(D2))+DEGTMP)*SGN(D2)
  89. 980 RETURN
  90. 990 END
  91. 1))+DEGTMP)*SGN(D1)
  92. 960 DEGTMP = (ABS(D2)-ABS(FIX(D2))) *100/60
  93. 970 D2 = (FIX(ABS(D2))+DEGTMP)*SGN(D2)
  94. 980 RET