	$lib graph on
	dr=180/3.141592654
	baseloc$="SU499126"
	size = val(command$)    'longitude degrees
	if size = 0 then size = 25
	lhs= 2 - size / 2               '-11
	bottom = 52 - size / 3.5
	rhs = 2 + size / 2
	top = 52 + size / 3.5

	dim colour%(15)
	gosub SetUpScreen
	for a%=1 to 3000
		pset (rnd*640+1,rnd*480+1),3
	next a%
	locate 10,20
	color 10
	print "PATHPLOT   ";
	color 12
	print "(c)  A C Talbot  G4JNT    Sept 1992"
	locate 18,20
	color 7
	print          "Type 'END' at  BASE  to finish session
	print tab(20); "Type 'BMP' at  DIST  for  .BMP file"
	locate 29 , 20
	print "Any key to continue ..."
	while inkey$ = "" : wend
	cls
	gosub DrawCoast
do
	locate lastline%-1,1
	print "Base"+space$(15);
	locate lastline%-1,10
	input;,l$
	if l$="" then l$=baseloc$
	if ucase$(l$)="END" then
		locate lastline%,1
		print "Finish session  y / N";
		while not instat:wend
		if ucase$(inkey$)="Y" then
			cls
			end
		else
			locate lastline%,1
			print string$(22," ");
			iterate loop
			end if
		end if
	location$=ucase$(l$)
	locate lastline%-1,10
	print location$;
	gosub HowStored
	if filetype%=0 then iterate loop
	ownlong=long
	ownlat=lat
	line (ownlong-.04,ownlat-.04)-(ownlong+.04,ownlat+.04),colown%
	line (ownlong+.04,ownlat-.04)-(ownlong-.04,ownlat+.04),colown%
	circle (ownlong,ownlat),.04,colown%
	do
		locate lastline%,1
		print "Dist"+space$(17);
		locate lastline%,10
		input;,l$
		l$ = ucase$(l$)
		if l$="" then exit loop
		if l$ = "BMP" then
			window
			DumpVGAToBMP
			window (lhs,bottom)-(rhs,top)
			iterate loop
		end if
		location$ = l$
		locate lastline%,10
		print location$;
		gosub HowStored
		line (ownlong,ownlat)-(long,lat),colpset%
		delay .5
		if instat then ik$ = ucase$(inkey$)
	loop until ik$ = chr$(27)
loop until ik$ = chr$(27)
end


SetUpScreen:
	screen 12
	scratio=1.3
	colcoast%=10
	colown%=15
	colpset%=14
	lastline%=30
return

DrawCoast:
	window (lhs,bottom)-(rhs,top)
	open "r",2,"eucoast.dat",9
	field 2,1 as col$,4 as ml$,4 as ma$
	do
		incr recordno%
		get 2,recordno%
		col%=val(col$)
		if asc(col$)=255 then exit loop
		long=cvs(ml$)
		lat=cvs(ma$)
		if col%=0 then
			pset (long,lat),colcoast%
		else
			line -(long,lat),colcoast%
		end if
	loop
	close 2
	paint (-1,50),1,colcoast%
return


HowStored:
	q1$="AA00AA  "
	q2$="RR99XX99"
	q3$="HA000000"
	q4$="YZ999999"
	filetype%=0:notloc%=0:notngr%=0:found%=0
	for chk%=1 to len(location$)
		a$=mid$(location$,chk%,1)
		if a$ < mid$(q1$,chk%,1) or a$ > mid$(q2$,chk%,1) then notloc%=-1
		if a$ < mid$(q3$,chk%,1) or a$ > mid$(q4$,chk%,1) then notngr%=-1
		next chk%
	if notloc% then filetype%=2
	if notngr% then filetype%=1
	if (notloc% and notngr%) or len(location$) < 6 then filetype%=0

	select case filetype%
	case 1
		IF LEN(location$)<8 or right$(location$,2)="  " THEN LC8%=0 else LC8%=-1
		LAT=10*(ASC(MID$(location$,2,1))-65)+(ASC(MID$(location$,4,1))-48)
		LAT=LAT+(ASC(MID$(location$,6,1))-65)/24-90+1.25/60
		IF LC8% THEN LAT=LAT+(ASC(MID$(location$,8,1))-48)*.25/60-1.125/60
		LONG=20*(ASC(MID$(location$,1,1))-65)+2*(ASC(MID$(location$,3,1))-48)
		LONG=LONG+(ASC(MID$(location$,5,1))-65)/12-180+2.5/60
		IF LC8% THEN LONG=LONG+(ASC(MID$(location$,7,1))-48)*.5/60-2.25/60

	case 2
		N=VAL(MID$(location$,6,3))/10
		E=VAL(MID$(location$,3,3))/10
		T1%=ASC(MID$(location$,1,1))-65
		IF T1%>8 THEN T1%=T1%-1
		T2%=ASC(MID$(location$,2,1))-65
		IF T2%>8 THEN T2%=T2%-1
		E=500* (T1% MOD 5) + 100*(T2% MOD 5)-1000+E
		N=1900-500*(T1% \5)-100*(T2%\5)+N
		T1=(N+5548.79)/6371.28
		T2=2*ATN(EXP((E-400)/6389.7))
		LONGR=ATN(-COS(T2)/(COS(T1)*SIN(T2)))-2/DR
		LA=SIN(T1)*SIN(T2)
		LATR=ATN(LA/SQR(1-LA*LA))
		LAT=LATR*DR
		LONG=LONGR*DR

	case else
		found%=0
		OSITE$=UCASE$(location$)
		searchloop%=0
		close 1
		open "i",1,"sites.dat"
		do
			incr searchloop%
			line input #1,readline$
			posn1%=instr(readline$,"~")
			sitename$=left$(readline$,posn1%-1)
			stloc$=mid$(readline$,posn1%+1,8)
			if instr(stloc$,"~")>0 then stloc$=left$(stloc$,6) '6 digit locator stored
			b%=instr(ucase$(sitename$),osite$)
			IF B%>0 THEN
				found%=-1
				exit loop
			end if
		loop until eof(1)
		close 1
		if not found%  and dir$("auxsites.dat") > ""then
			open "i",1,"auxsites.dat"
			searchloop% = 0
			do
				incr searchloop%
				line input #1,readline$
				posn1%=instr(readline$,"~")
				posn2%=instr(posn1%+7,readline$,"~")
					sitename$=left$(readline$,posn1%-1)
				if posn2%=0 then
					stloc$=mid$(readline$,posn1%+1,8)
				else
					stloc$=mid$(readline$,posn1%+1,posn2%-posn1%-1)
					posnhgt% = instr(posn2% , ucase$(readline$) , "H")
					if posnhgt% > 0 then mastheight = val(mid$(readline$ , posnhgt% + 1))_
								else mastheight = 0
				end if

				stloc$=ucase$(stloc$)
				if instr(stloc$,"~")>0 then stloc$=left$(stloc$,6)  ' 6 Digit loc stored
				b%=instr(ucase$(sitename$),osite$)
				IF B%>0 THEN
					found%=-1
					exit loop
				end if
			loop until eof(1)
		end if
		if found%=0 then
			sound 300 , 1
		else
			location$=ucase$(stloc$)
			filetype%=3
			goto HowStored
		end if
	end select
return



sub DumpVGAToBmp       'Palette table assumes EGA compatibility
	basename$ = "PTHPL"
	filename$ = dir$(basename$ + "???.bmp")
	n% = val(mid$(filename$ , 6, 3))
	do
		f$ = dir$
		n% = max(val(mid$(f$ , 6, 3)) , n%)
	loop until f$ = ""
	n$ = mid$(str$(min(n% + 1, 999)) , 2)
	do while len(n$) < 3
		n$ = "0" + n$
	loop
	f$ = basename$ + n$ + ".BMP"
	bwidth& = 640
	bheight& = 480
	ColoursInTable& = 16
	BitsPerPixel% = 4        '1 / 4 / 8 / 24  only
	NPlanes% = 1             '1 only
	InfoSize& = 40

	ImageSize& = bwidth& * bheight& * BitsperPixel% / 8
	dataoffset& = 54 + ColoursInTable& * 4
	filesize& = dataoffset& + ImageSize&

	t = timer
	if instr(ucase$(f$) , ".BMP") = 0 then f$ = f$ + ".BMP"
	fi% = freefile
	open "b" , fi% , f$
	i1% = 0 : i2% = 0 : compression& = 0
	bm$ = "BM"
	put$ fi% , bm$
	put fi% , 2 , filesize&
	put fi% ,, i1%
	put fi% ,, i2%
	put fi% ,, DataOffset&
	put fi% ,, InfoSize&
	put fi% ,, bwidth&
	put fi% ,, bheight&
	put fi% ,, NPlanes%
	put fi% ,, BitsPerPixel%
	put fi% ,, compression&
	put fi% ,, ImageSize&
	put fi% ,, XPelsPerMetre&
	put fi% ,, YPelsPerMetre&
	put fi% ,, ColoursInTable&
	put fi% ,, ImportantColours&

	seek fi% , 54
	for rgb% = 0 to 15
		reg 1 , &h1015
		reg 2 , rgb%
		call interrupt &h10
		b% = (reg(3) mod 256) * 4
		g% = (reg(3) \ 256) * 4
		r% = (reg(4) \ 256) * 4
		pa$ = chr$(b%) + chr$(g%) + chr$(r%) + chr$(0)
		put$ fi% , pa$
	next rgb%

	seek fi% , dataoffset&         'data starts at bottom left of picture
	nibble% = 0
	for y% = bheight& - 1 to 0 step -1
		dat$ = ""
		for x% = 0 to bwidth& - 2 step 2
				d% = 16 * point (x% , y%) + point (x% + 1 , y%)
				dat$ = dat$ + chr$(d%)
		next x%
      put$ fi% , dat$
	next y%
	close fi%
	sound 1750 , 2
end sub
