10 '  GREAT CIRCLE DISTANCE AND HEADING
20 '  by Orbra Bliss, version 3.7  3/4/84
30 DEFDBL A,B,C,D,L,M,N,S,X: DEFSTR V,P,Q,Z: V="######.#": V1="###.#"
40 DEFINT I: Z="|":IP=1: V4=" deg."
50 V2="GREAT CIRCLE BEARINGS AND DISTANCES FROM ":V3="Page "
60 V6="    \                    \###.# deg. ###.# deg.| #####.#  | #####.#  | #####.#"
70 V7="\                                        \ \                   \      \    \ ##"
80 D=1: M=57.29577951308254#: N=1.570796326794896#
82 DEF FNCS(X)= COS(X/M): DEF FNSN(X)= SIN(X/M)
85 DEF FNARC(X)= N-2*ATN(X/(1+SQR(1-X*X)))
90 DEF FNDMS(D,M,S)= D+(M/60)+(S/3600):PRINT CHR$(26)
100 DEF FNCR$(YPOS,XPOS)=CHR$(27)+"="+CHR$(YPOS+32)+CHR$(XPOS+32)
110 ' ----- Screen #1, Entry Menu -------
120 PRINT FNCR$(4,8);"GREAT CIRCLE DISTANCE AND HEADINGS"
130 PRINT FNCR$(6,12);"Enter Originating Location"
140 PRINT FNCR$(8,4);"Make entry of City & State using ONE comma."
150 PRINT FNCR$(10,8);"City, State: ____________________"
160 PRINT FNCR$(10,21);:LINE INPUT PL1
165 PRINT FNCR$(14,4);"Do you want a printout now? (Y or N): ";:INPUT Q3
167 IF Q3="y" THEN Q3="Y"
170 PRINT FNCR$(14,4);"Do you want a disk file? (Y or N):    ";:INPUT Q
180 IF Q<>"Y" AND Q<>"y" THEN 200
190 PRINT FNCR$(16,8);"Enter file name: ";:LINE INPUT Q1
200 PRINT FNCR$(14,4);"Do you want a personalized cover? (Y or N): ";:INPUT Q2
210 IF Q2<>"Y" AND Q2<>"y" THEN 230
220 PRINT FNCR$(16,8);"Enter the callsign of the station: ";:LINE INPUT SIGN$
230 PRINT FNCR$(14,4);"   Enter coordinates for ";PL1;"              "
240 PRINT FNCR$(16,0);"Latitude:  Degrees ___, Minutes __, Seconds __, N/S _"
250 PRINT FNCR$(18,0);"Longitude: Degrees ___, Minutes __, Seconds __, E/W _"
260 PRINT FNCR$(16,19);:INPUT"",DEG1:PRINT FNCR$(16,32);:INPUT"",MIN1
270 PRINT FNCR$(16,44);:INPUT"",SEC1:PRINT FNCR$(16,52);:INPUT"",H1$
280 PRINT FNCR$(18,19);:INPUT"",DEG3:PRINT FNCR$(18,32);:INPUT"",MIN3
290 PRINT FNCR$(18,44);:INPUT"",SEC3:PRINT FNCR$(18,52);:INPUT"",H3$
300 LAT1= FNDMS(DEG1,MIN1,SEC1): IF H1$="s" THEN H1$="S"
310 LON1= FNDMS(DEG3,MIN3,SEC3): IF H3$="e" THEN H3$="E"
320 IF H1$="S" AND D=1 THEN LAT1= LAT1*-1
330 IF H3$="E" AND D=1 THEN LON1= LON1*-1
350 PRINT FNCR$(8,4);"                  TO                        "
360 PRINT FNCR$(14,4)"     The"
500 ' ------- Read Data File ------------
510 OPEN "I",1, "GCDATA.SDF"
520 IF Q="Y" OR Q="y" THEN OPEN "O",2,Q1:' Disk File
530 IF Q2="Y" OR Q2="y" THEN GOSUB 3010:' Personalized Cover
540 IF Q="Y" OR Q="y" AND Q2="Y" OR Q2="y" THEN GOSUB 5010 'Disk File Cover
550 IF Q="Y" OR Q="y" THEN GOSUB 4020 'Disk File Page Heading
560 IF Q3="Y" OR Q3="y" THEN GOSUB 2010: ' Line Printer Heading
570 WHILE NOT EOF(1)
580  INPUT #1,PL2$,ST2$,DEG2,MIN2,SEC2,H2$,DEG4,MIN4,SEC4,H4$
590  PLA=PL2$+", "+ST2$:IF PLA=PL1 THEN 740
600  PRINT FNCR$(6,8);"Now calculating for ";PLA;"            "
610  LAT2= FNDMS(DEG2,MIN2,SEC2)
620  LON2= FNDMS(DEG4,MIN4,SEC4)
630  IF H2$="S" THEN LAT2= LAT2*-1
640  IF H4$="E" THEN LON2= LON2*-1
660  GOSUB 1000
670  IL=IL+1: IF IL>54 THEN IL=0:IP=IP+1
680  IF IL=0 AND Q="Y" OR Q="y" THEN PRINT #2, CHR$(12):GOSUB 4020:' File, New Page
690  IF IL=0 AND Q3="Y" OR Q3="y" THEN LPRINT CHR$(12):GOSUB 2010:' Printout, New Page
700  IF Q<>"Y" AND Q<>"y" THEN 720:' File NOT wanted
710    PRINT #2, USING V6;PLA,BA!,BR!,STMI!,NAMI!,KM!
720  IF Q3<>"Y" AND Q3<>"y" THEN 740:' Printout NOT wanted
730    LPRINT TAB(5);PLA;TAB(27);:LPRINT USING V1;BA!;:LPRINT V4;" ";:LPRINT USING V1;BR!;:LPRINT V4;TAB(48);Z;:LPRINT USING V;STMI!;:LPRINT TAB(59);Z;:LPRINT USING V;NAMI!;:LPRINT TAB(70);Z;:LPRINT USING V;KM!
740 WEND
750 IF Q="Y" OR Q="y" THEN PRINT #2, CHR$(12) 
760 PRINT CHR$(26): IF Q3="Y" OR Q3="y" THEN LPRINT CHR$(12)
770 CLOSE: PRINT FNCR$(10,12)"THAT'S ALL!!!"
780 END
1000 ' ------ Distance & Heading SBR ----------
1010 L3=(LON2-LON1)
1020 A=FNSN(LAT1)*FNSN(LAT2)+FNCS(LAT1)*FNCS(LAT2)*FNCS(L3)
1030 IF A=>1 THEN D=0: GOTO 1060
1040 IF A=<-1 THEN D=10800: GOTO 1060
1050 D= FNARC(A)*60*M
1060 B=(FNSN(LAT2)-(FNSN(LAT1)*A))/(FNSN(D/60)*FNCS(LAT1))
1070 IF B=>1 THEN H=0: GOTO 1100
1080 IF B=<-1 THEN H=180: GOTO 1100
1085 H= FNARC(B)*M: IF FNSN(L3)=>0 THEN H= 360-H
1090 ' ---- Round off to one decimal ---
1100 I=D: GOSUB 1310
1110 NAMI!=CSNG(I)
1120 I=D*1.852: GOSUB 1310
1130 KM!=CSNG(I)
1140 I=D*1.15: GOSUB 1310
1150 STMI!=CSNG(I)
1160 I=H: GOSUB 1310
1170 BA!=CSNG(I)
1180 ' ----- Reverse Calculation SBR --------
1190 L3=(LON1-LON2)
1200 A=FNSN(LAT2)*FNSN(LAT1)+FNCS(LAT2)*FNCS(LAT1)*FNCS(L3)
1210 IF A=>1 THEN D=0: GOTO 1240
1220 IF A=<-1 THEN D=10800: GOTO 1240
1230 D= FNARC(A)*60*M
1240 B=(FNSN(LAT1)-(FNSN(LAT2)*A))/(FNSN(D/60)*FNCS(LAT2))
1250 IF B=>1 THEN H=0: GOTO 1270
1260 IF B=<-1 THEN H=180: GOTO 1270
1265 H= FNARC(B)*M: IF FNSN(L3)=>0 THEN H= 360-H
1270 I=H: GOSUB 1310
1280 BR!=CSNG(I)
1290 RETURN
1300 '  ---- Round off to one place ----
1310 I=INT((I)*10+.5)/10
1320 RETURN
2000 ' ------ Line Printer Heading --------
2010 LPRINT STRING$(80,"-")
2020 LPRINT V2;PL1;TAB(72);V3;IP:LPRINT STRING$(80,"-")
2030 LPRINT TAB(28);"BEARING";TAB(39);"BEARING";TAB(49);"---------- DISTANCE ----------"
2040 LPRINT TAB(5);"LOCATION";TAB(30);"TO";TAB(40);"FROM";TAB(48)"|ST. MILES |NAU. MILES|KILOMETERS"
2050 RETURN
3000 ' ------- Personalized Cover SBR ----------
3010 LPRINT CHR$(30);CHR$(31);STRING$(9,10)
3020 LPRINT TAB(9);"G R E A T  C I R C L E";STRING$(3,10)
3030 LPRINT TAB(17);"BEARINGS";CHR$(29);CHR$(31);STRING$(3,10)
3040 LPRINT TAB(32);"AND";CHR$(30);CHR$(31);STRING$(3,10)
3050 LPRINT TAB(16);"DISTANCES";STRING$(3,10)
3060 LPRINT TAB(19);"FROM";STRING$(3,10)
3070 LPRINT TAB(10);"AMATEUR RADIO STATION";STRING$(3,10)
3080 V5$=SPACE$(19-(INT(LEN(SIGN$)/2))):LPRINT V5$;SIGN$;CHR$(29);CHR$(31);STRING$(3,10)
3090 LPRINT TAB(29);"LOCATED AT";CHR$(30);CHR$(31);STRING$(3,10)
3100 V5$=SPACE$(19-(INT(LEN(PL1$)/2))):LPRINT V5$;PL1$;CHR$(29);CHR$(31);STRING$(3,10)
3110 LPRINT TAB(28);"COORDINATES";CHR$(30);STRING$(3,10)
3120 LPRINT TAB(15);"Latitude: ";DEG1;" Degrees,";MIN1;" Minutes,";SEC1;" Seconds ";H1$
3130 LPRINT TAB(15);"Longitude:";DEG3;" Degrees,";MIN3;" Minutes,";SEC3;" Seconds ";H3$
3140 LPRINT STRING$(7,10)
3150 LPRINT TAB(40);"Prepared by Orbra W. Bliss, W9GEK/HC1BW"
3160 LPRINT CHR$(12)
3170 RETURN
4000 ' ----------- File Page Heading -------------
4020 PRINT #2, STRING$(80,"-")
4030 PRINT #2, USING V7;V2,PL1,V3,IP
4040 PRINT #2, STRING$(80,"-")
4050 PRINT #2, "                           BEARING    BEARING  ------------ DISTANCE -----------"
4060 PRINT #2, "                             TO        FROM    |ST. MILES |NAU. MILES|KILOMETERS"
4070 RETURN
4080 ' ------------ File Personalized Cover --------------
5010 PRINT #2, CHR$(30);CHR$(31);STRING$(9,10)
5020 PRINT #2, TAB(9);"G R E A T  C I R C L E";STRING$(3,10)
5030 PRINT #2, TAB(17);"BEARINGS";CHR$(29);CHR$(31);STRING$(3,10)
5040 PRINT #2, TAB(32);"AND";CHR$(30);CHR$(31);STRING$(3,10)
5050 PRINT #2, TAB(16);"DISTANCES";STRING$(3,10)
5060 PRINT #2, TAB(19);"FROM";STRING$(3,10)
5070 PRINT #2, TAB(10);"AMATEUR RADIO STATION";STRING$(3,10)
5080 V5$=SPACE$(19-(INT(LEN(SIGN$)/2))):PRINT #2, V5$;SIGN$;CHR$(29);CHR$(31);STRING$(3,10)
5090 PRINT #2, TAB(29);"LOCATED AT";CHR$(30);CHR$(31);STRING$(3,10)
5100 V5$=SPACE$(19-(INT(LEN(PL1$)/2))):PRINT #2, V5$;PL1$;CHR$(29);CHR$(31);STRING$(3,10)
5110 PRINT #2, TAB(28);"COORDINATES";CHR$(30);STRING$(3,10)
5120 PRINT #2, TAB(15);"Latitude: ";DEG1;" Degrees,";MIN1;" Minutes,";SEC1;" Seconds ";H1$
5130 PRINT #2, TAB(15);"Longitude:";DEG3;" Degrees,";MIN3;" Minutes,";SEC3;" Seconds ";H3$
5140 PRINT #2, STRING$(7,10)
5150 PRINT #2, TAB(40);"Prepared by Orbra W. Bliss, W9GEK/HC1BW"
5160 PRINT #2, CHR$(12)
5170 RETURN
INT #2, 