'LAT_LONG project - calculate distances

external	vloadif() dpath vunloadif() messboxwait() Background()


public	ptstr


global x1 x2 y2 y1 #d1 #d2 #d3 #d4 #d5 C1 C2 S1 x #rad E Pcode() $d



MAIN
	Background()
  	$d=Pcode("SW17","SM4ÿ")
'  	$d=Pcode("AB10","AB16")
message "distance is:"&str($d)

' *COS(RADIANS(90-57.161))
' +SIN(RADIANS(90-57.135))
' *SIN(RADIANS(90-57.161))
' *COS(RADIANS(-2.117--2.156)))
' *COS(RADIANS(-2.117--2.156)))
'  *3958.756

END MAIN


FUNCTION Pcode(a,b)
' 	x1=57.135
' 	x2=57.161
' 	y2=-2.156
' 	y1=-2.117

	#rad=1/PI*180									'message "#rad is:"&str(x)
	vloadif(dpath|"postcod1.vws")
  	order change key "[Pcode]"
	a=TRIM(a)
message "a) is:"&str(a)
    	data find "[Pcode]" equal a options ""
'      if cerror                               '   if none - then return
'      	x = messboxwait(" No such postcode ",1,0,0)
' 		return (-1)
' 	end if
	x1=dbget("[Lat]")
	y1=dbget("[Long]")
' message "x1) is:"&str(x1)

	b=TRIM(b)
repaint on
repaint
single-step on
message "b) is:"&str(b)
    	data find "[Pcode]" equal b options ""
'      if cerror                               '   if none - then return
'      	x = messboxwait(" No such postcode ",1,0,0)
' 		return (-1)
' 	end if
	x2=dbget("[Lat]")
	y2=dbget("[Long]")
' message "x2) is:"&str(x2)

' message "x1) is:"&str(x1)

 	#d1=COS((90-x1)/#rad)							'message "#d1 is:"&str(#d1)
 	#d2=COS((90-x2)/#rad)							'message "#d2 is:"&str(#d2)
	C1=#d1*#d2									'message "C1 is:"&str(C1)
 	#d3=SIN((90-x1)/#rad)							'message "#d3 is:"&str(#d3)
 	#d4=SIN((90-x2)/#rad)							'message "#d4 is:"&str(#d4)
	S1=#d3*#d4									'message "S1 is:"&str(S1)
 	#d5=COS((y1-y2)/#rad)							'message "#d5 is:"&str(#d5)
	C1=#d1*#d2
	E=round(acos(C1+S1*#d5)*3958.756,2)						'message "E is:"&str(E)
	vunloadif("postcod1.vws")
	return (E)
END FUNCTION' Pcode(a,b)

