home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HAM Radio 3
/
hamradioversion3.0examsandprograms1992.iso
/
math
/
sun
/
sun.bas
next >
Wrap
BASIC Source File
|
1986-10-29
|
11KB
|
347 lines
10 ' Program to calculate sunrise and sunset times by N4TL
20 ' file name = sun.bas
30 '
40 ' Algorithm from June 84 QST page 56
50 ' Calculation section by WS4G and SM0CCM
60 ' If any errors are found please send the information to N4TL
70 '
80 ' This program will compile using the IBM BASIC compiler ver 1.00
90 '
100 ' LATITUDE : N = + , S = - Degrees
110 ' LONGITUDE : W = + , E = - Degrees
120 '
130 ' Arrays used
140 '
150 ' P$ Prefix and Country name
160 ' LA$ Latitude
170 ' LO$ Longitude
180 ' SR$ Sunrise time
190 ' SS$ Sunset time
200 ' LD length of day
210 ' PA A index for sort routine
220 ' PB B index for sort routine
230 '
240 DIM P$(500),LA(500),LO(500),SR$(500),SS$(500),LD$(500),PA(500),PB(500)
250 KEY OFF : COLOR 7,1 ' turn color off for the portable pc
260 DEF FNACS(XX) = 1.570796 - ATN(XX/SQR(1-XX*XX))
270 '
280 N=500 ' Maximum number of countries
290 '
300 VERSION = 1.8
310 DATEV$ = " Oct 29, 1986 "
320 '
330 CLS ' restart entry point
340 '
350 PRINT
360 PRINT " Sunrise and Sunset Program. Useful for radio communications."
370 PRINT " Version "VERSION DATEV$" by N4TL."
380 GOTO 670 ' first menu
390 '
400 ' start of information
410 '
420 PRINT
430 PRINT" This program will calculate the sunrise, sunset, and length
440 PRINT" of the day for all the countries listed in the SUN.DAT
450 PRINT" file, or for a single location. the SUN.DAT file has
460 PRINT" to be on the same disk as the default disk.
470 PRINT" Times are in hours and minutes UTC.
480 PRINT"
490 PRINT" When the file input is used the times are calculated and
500 PRINT" displayed on the screen. The times are saved in the program,
510 PRINT" and can be sorted and printed.
520 PRINT" Compressed print can be used (for the IBM Graphics Printer).
530 PRINT
540 PRINT" If the SUN.DAT file is edited its format has to remain
550 PRINT" unchanged. It also has to be saved without compressed
560 PRINT" characters. If the Personal editor is used, use the NOTABS
570 PRINT" option when saving the file. The maximum number of countries
580 PRINT" is 500.
590 PRINT
600 PRINT " more ";:INPUT IN
610 GOTO 330
620 ' end of information
630 '
640 '
650 ' what does the user want to do? first menu
660 '
670 PRINT
680 PRINT " Enter 1 for a single calculation "
690 PRINT " Enter 2 for the full file "
700 PRINT " Enter 3 for information "
710 PRINT " Enter 4 to exit the program ";: INPUT IN
720 '
730 IF IN=1 GOTO 790
740 IF IN=2 GOTO 1290
750 IF IN=3 GOTO 420
760 IF IN=4 THEN END
770 GOTO 670
780 '
790 GOSUB 2000 ' get month and day
800 GOSUB 2110 ' sun declination
810 '
820 X=1
830 PRINT
840 PRINT " N = +, S = -"
850 PRINT " enter latitude -90 to +90 degrees ";: INPUT LA(X)
860 IF LA(X) > 90 OR LA(X) < -90 THEN GOTO 850
870 PRINT " W = +, E = -"
880 PRINT " enter longitude -180 to +180 degrees ";: INPUT LO(X)
890 IF LO(X) >180 OR LO(X) < -180 THEN GOTO 880
900 PRINT " Calculate sunrise and sunset time"
910 '
920 ' ------------------------------------
930 ' Calculate sunrise and sunset times
940 ' ------------------------------------
950 XX=LO(X)/15
960 Y1=(TAN(DEC*3.141593/180)*TAN(LA(X)*3.141593/180))
970 IF Y1>1 OR Y1<-1 THEN GOTO 1210 ' jump if none
980 Z=((FNACS (Y1))*180/3.141593)/15
990 T=XX+Z ' sunrise
1000 TT=XX-Z ' sunset
1010 LD=TT-T ' length of day
1020 ' ------------------------------------
1030 GOSUB 2190 ' time check
1040 GOSUB 2260 ' convert decimals to hour and minutes
1050 '
1060 PRINT
1070 PRINT " Sunrise time = " TIM$ " hours and minutes UTC"
1080 T=TT
1090 GOSUB 2190 ' time check
1100 GOSUB 2260 ' convert decimals to hour and minutes
1110 PRINT " Sunset time = " TIM$ " hours and minutes UTC"
1120 '
1130 ' Length of day
1140 '
1150 T=LD
1160 GOSUB 2190 ' time check
1170 GOSUB 2260 ' convert decimals to hour and minutes
1180 PRINT " Length of day= " TIM$ " hours and minutes UTC"
1190 GOTO 670
1200 '
1210 PRINT
1220 PRINT " No sunrise or sunset"
1230 GOTO 670
1240 '
1250 ' end of single calculation
1260 '--------------------------------------------
1270 ' start of full file calculation section
1280 '
1290 PRINT
1300 GOSUB 2000 ' get month and day
1310 GOSUB 2110 ' sun declination
1320 '
1330 PRINT " Calculate sunrise and sunset times"
1340 PRINT
1350 '
1360 ' data for each country is in the sun.dat file
1370 ' prefix,country name, latitude,longitude
1380 ' (N=+,S=-,W=+,E=-)
1390 '
1400 OPEN "sun.dat" FOR INPUT AS #1
1410 '
1420 PRINT "Calculations for Day = "D " Month = "M
1430 PRINT "Prefix, Country, Latitude, Longitude, Sunrise,Sunset,length of day"
1440 PRINT " UTC UTC"
1450 '
1460 ' read country file, "sun.dat"
1470 '
1480 ZC=0
1490 FOR X=1 TO N
1500 IF EOF(1) THEN 1940
1510 LINE INPUT#1,P$(X) ' country
1520 INPUT#1,LA(X),LO(X)
1530 '
1540 ' Calculate sunrise and sunset times
1550 ' ------------------------------------
1560 XX=LO(X)/15
1570 Y1=(TAN(DEC*3.141593/180)*TAN(LA(X)*3.141593/180))
1580 IF Y1>1 OR Y1<-1 THEN GOTO 1850 ' jump if none
1590 Z=((FNACS (Y1))*180/3.141593)/15
1600 T=XX+Z ' sunrise
1610 ' ------------------------------------
1620 GOSUB 2190 ' time check
1630 LDSR=T ' save for length of day
1640 GOSUB 2260 ' convert decimals to hour and minutes
1650 SR$(X) = TIM$ ' sunrise
1660 '
1670 ' sunset
1680 '
1690 T=XX-Z ' sunset
1700 GOSUB 2190 ' time check
1710 LDSS=T ' save for length of day
1720 GOSUB 2260 ' convert decimals to hour and minutes
1730 SS$(X) = TIM$ ' sunset
1740 '
1750 ' length of day
1760 '
1770 T=LDSS-LDSR
1780 GOSUB 2190 ' time check
1790 GOSUB 2260 ' convert decimals to hour and minutes
1800 LD$(X)=TIM$ ' length of day
1810 GOTO 1870
1820 '
1830 ' Set sunrise and sunset to none
1840 '
1850 SR$(X) ="none" : SS$(X) = "none" : LD$(X) = " "
1860 '
1870 PRINT USING "\ \####.## ####.## \ \\ \\ \";P$(X),LA(X),LO(X),SR$(X),SS$(X),LD$(X)
1880 '
1890 ZC=ZC+1
1900 NEXT X
1910 '
1920 PRINT "Number of countries = " ZC
1930 '
1940 N = X-1 ' set number of countries in data file
1950 PRINT "end of country data "
1960 CLOSE #1
1970 GOTO 2380 ' goto output section
1980 '
1990 ' ------subroutine--------------------
2000 ' Input correct date
2010 ' ------------------------------------
2020 PRINT
2030 INPUT " Month? (1-12)";M
2040 IF M<1 OR M>12 THEN GOTO 2030
2050 INPUT " Day? (1-31)";D
2060 IF D<1 OR D>31 THEN GOTO 2050
2070 GOSUB 2110 ' sun declination
2080 RETURN
2090 '
2100 ' ------subroutine--------------------
2110 ' Approximation for sun declination
2120 '
2130 DEC = D+(30.3 * (M-1))
2140 DEC = 10+(.988*DEC)
2150 DEC = -23.5 * COS (DEC*3.141593/180)
2160 RETURN
2170 '
2180 ' ------subroutine--------------------
2190 ' Check for correct time
2200 ' ------------------------------------
2210 IF T<0 THEN LET T=T+24
2220 IF T>24 THEN T=T-24
2230 RETURN
2240 '
2250 ' ------subroutine--------------------
2260 ' Convert decimal time to hours and minutes
2270 ' ------------------------------------
2280 HR = INT(T)
2290 MN=INT((T-HR)*60+.5)
2300 IF MN = 60 THEN MN = 0 : HR=HR+1
2310 HT=HR*100+MN
2320 HDR$=""
2330 IF HR=0 AND MN<10 THEN HDR$="000" ELSE IF HT < 100 THEN HDR$="00" ELSE IF HT < 1000 THEN HDR$="0"
2340 TIM$=HDR$ + MID$(STR$(HT),2)
2350 RETURN
2360 ' ------------------------------------
2370 '
2380 ' init pa(x) index array, for printing and sorting
2390 '
2400 FOR X=1 TO N ' init first index array
2410 PA(X)=X
2420 NEXT X
2430 ' second menu
2440 PRINT
2450 PRINT " Enter 1 to sort list "
2460 PRINT " Enter 2 to print list "
2470 PRINT " Enter 3 to return to main menu ";
2480 ' PRINT " Enter 4 to search list, not done yet"
2490 INPUT IN
2500 IF IN = 1 THEN GOTO 2560
2510 IF IN = 2 THEN GOTO 3080
2520 IF IN = 3 THEN GOTO 330
2530 IF IN = 4 THEN GOTO 2440 ' reserved for search +/- 15 minutes
2540 GOTO 2440
2550 '
2560 PRINT
2570 PRINT " Sort output on sunrise, sunset or length of day (SR/SS/LD) ";:INPUT IN$
2580 SORTFLAG=0
2590 IF IN$="sr" OR IN$="SR" THEN SORTFLAG=1 : GOTO 2620
2600 IF IN$="ld" OR IN$="LD" THEN SORTFLAG=2 : GOTO 2620
2610 IF IN$<>"ss" AND IN$<>"SS" THEN GOTO 2570
2620 PRINT
2630 PRINT "Sort data, Pass counter" ;
2640 '
2650 ' fast sort
2660 ' four passes, move indexes not data
2670 '
2680 K=0
2690 FOR P = 4 TO 1 STEP -1 ' POSITION
2700 B=1
2710 FOR NUM = 0 TO 9
2720 FOR X = 1 TO N
2730 IF SORTFLAG = 0 THEN GOTO 2760 ELSE IF SORTFLAG = 1 THEN GOTO 2750
2740 TEMP$ = MID$(LD$(PA(X)),P,1) : GOTO 2770
2750 TEMP$ = MID$(SR$(PA(X)),P,1) : GOTO 2770
2760 TEMP$ = MID$(SS$(PA(X)),P,1)
2770 IF (VAL(TEMP$)= NUM) THEN PB(B) = PA(X) : B=B+1
2780 NEXT X
2790 LOCATE 24,25 : K = K + 1 : PRINT K;
2800 NEXT NUM
2810 '
2820 ' move pb index to pa index
2830 '
2840 FOR X=1 TO N
2850 PA(X) =PB(X)
2860 NEXT X
2870 NEXT P
2880 '
2890 PRINT "sort done" : PRINT
2900 '
2910 '--------------------------------------------
2920 ' display results to the screen
2930 '
2940 Z=0
2950 PRINT "Calculations for Day = "D " Month = "M
2960 PRINT "Prefix, Country, Latitude, Longitude, Sunrise,Sunset,length of day"
2970 PRINT " UTC UTC"
2980 FOR Y=1 TO N
2990 X=PA(Y)
3000 PRINT USING "\ \####.## ####.## \ \\ \\ \";P$(X),LA(X),LO(X),SR$(X),SS$(X),LD$(X)
3010 Z=Z+1
3020 NEXT Y
3030 PRINT "Number of countries = " Z
3040 PRINT
3050 GOTO 2440 ' go back to second menu
3060 '-------------------------------------------
3070 '
3080 ' Print output to printer
3090 '
3100 PRINT
3110 PRINT " Use compressed print (Y/N) ";:INPUT IN$
3120 IF IN$="N" OR IN$="n" THEN GOTO 3220
3130 IF IN$<>"Y" AND IN$<>"y" THEN GOTO 3110
3140 ' printer control compressed on
3150 ' paper feed to 1/8 inch
3160 LPRINT CHR$(27);CHR$(48)
3170 '
3180 ' compressed characters
3190 LPRINT CHR$(15)
3200 GOTO 3280
3210 '
3220 ' reset line feed compressed off
3230 LPRINT CHR$(27);CHR$(50)
3240 '
3250 ' compressed characters off
3260 LPRINT CHR$(18)
3270 '
3280 ' perforation skip, 5 lines
3290 LPRINT CHR$(27);CHR$(78);CHR$(5)
3300 '
3310 Z=0
3320 LPRINT "Sunrise and Sunset Program. "
3330 LPRINT "Version "VERSION DATEV$ " By N4TL."
3340 LPRINT
3350 LPRINT "Calculations for Day = "D " Month = "M
3360 LPRINT "Prefix, Country, Latitude, Longitude, Sunrise,Sunset,length of day"
3370 LPRINT " UTC UTC"
3380 FOR Y=1 TO N
3390 X=PA(Y)
3400 LPRINT USING "\ \####.## ####.## \ \\ \\ \";P$(X),LA(X),LO(X),SR$(X),SS$(X),LD$(X)
3410 Z=Z+1
3420 NEXT Y
3430 LPRINT "Number of countries = " Z
3440 '
3450 GOTO 2440 ' go back to second menu
3460 END