> NGRCalc 1.01 A Program written by Len Killip, G0APZ, for his own interest.  This version dated 280297. ( 2D This program converts National Grid References to latitude and  :  choice1  :''  10)"DO YOU REQUIRE"' A 10)"(A) CONVERT GRID REFERENCE TO LATITUDE AND LONGITUDE"' 8 10)"(B) BEARING AND DISTANCE BETWEEN TWO POINTS"' A 10)"(C) CONVERT LATITUDE AND LONGITUDE TO GRID REFERENCE"' &! 10)"(D) END THIS SESSION"' 0 10)"KEY A, B, C OR D"' :Ȏ answer("ABCD") D 1 Nlatlongrepeat= Xȕ latlongrepeat= b :'' l latlong v  2 bdrepeat= ȕ bdrepeat=  :'' _bd   3  lltongr= ȕ lltongr=  :''  _lltongr   4 quit%=: quit%=  quit%:Ș    * 4: > latlong H choice2 R :'' \ 10)"GRID REFERENCE: "G$' f_Mvrho(E,N) p _toll z _C_EN output(lambda,phi,C) < '10) "Do you want another Lat Long calculation? Y/N"; & answer("YN")<>1 latlongrepeat=  :  _bd  20)"FIRST POSITION"'  choice2  E1=E:N1=N _Mvrho(E1,N1):y1%=y:F1=F  _toll  _C_EN  20)"SECOND POSITION"'  choice2  E2=E:N2=N _Mvrho(E2,N2):y2%=y:F2=F $ _toll . Ȏ N2 8 N1 B alpha=/2 L Valpha=((E2-E1)/(N2-N1)) ` j Ȏ E2 t E1 ~ alpha=0   N2N1 alpha=alpha+2*   %Nm=(N1+N2)/2:q=N1-N2:Em=(E1+E2)/2  y1%<0 y2%<0 alphasplit  _converge   _distance _bd_output 6 15)"Another bearing/dist calculation? Key Y/N"; (! answer("YN")<>1 bdrepeat= 2 <: F _lltongr P _lltoEN Z :'' d= 15) "Latitude "; deg1; " Degs "; min1; " Mins "; sec1; n " Secs North"' x> 15) "Longitude "; deg2; " Degs "; min2; " Mins "; sec2;  " Secs "; ew$' _ENtongr(E,N)  :  _lltoEN 1 15)"Enter latitude in form deg, min, sec"' 6 15)deg%, min%,sec':deg1=deg%:min1=min%:sec1=sec *phi=convert(deg%,min%,sec):phi=(phi)  v=A(phi) rho=B(phi) itasqd=v/rho-1 7 15)"Enter longitude in form deg, min, sec, E/W"' ; 15)deg%, min%, sec,ew$':deg2=deg%:min2=min%:sec2=sec 5lambda=convert(deg%, min%, sec):lambda=(lambda) ( ew$="W" ew$="w" lambda=-lambda P=lambda-lambda0 " phip=phi ,M=M(b,n,phip,phi0) 6 I=M+N0 @II=(v/2)*(phi)*(phi) J8III=(v/24)*(phi)*((phi))^3*(5-((phi))^2+9*itasqd) T@IIIA=(v/720)*(phi)*((phi)^5)*(61-58*((phi)^2)+((phi)^4)) ^N=I+P^2*II+P^4*III+P^6*IIIA hIV=v*(phi) r)V=(v/6)*((phi))^3*(v/rho-((phi)^2)) |VI=(v/120) * ((phi)^5) EVI=VI*(5-18*((phi)^2)+((phi)^4)+14*itasqd-58*((phi)^2)*itasqd) E=E0+P*IV+P^3*V+P^5*VI ( 15)"Easting= ";E;" Northing= ";N'  :  _ENtongr(E,N)  E<0 E=E-1  N<0 N=N-1 en_string(E)  east$=en$ en_string(N) north$=en$ : first_letter(east$,north$) read_letter  A$=(a%) & second_letter(east$,north$) 0read_letter : B$=(a%) D,easting$=east$,5): northing$=north$,5) N E<0 X(easting$=(1000000-(east$,2))),5) b l N<0 v)northing$=(500000-(north$,2))),5)  !NGR$=A$+B$+easting$+northing$ 6 15)"10-digit National Grid Reference is ";NGR$' curtail(easting$) easting$=en$ curtail(northing$) northing$=en$ !NGR$=A$+B$+easting$+northing$ 5 15)"6-digit National Grid Reference is ";NGR$' : : '15)"Another lat/long to NGR calculation? Key Y/N"; :  answer("YN")<>1 lltongr=   :  curtail(EN$)  en%=((EN$)/100) *en$="0000"+(en%),3) 4 >: H choice2 R$ 15)"DO YOU WISH TO ENTER AS"' \, 15)"(A) NATIONAL GRID REFERENCE, OR"' f& 15)"(B) EASTING AND NORTHING?"' p 15)"KEY A OR B"' zȎ answer("AB")  1 ngr  2 : 10) "ENTER FULL EASTING AND NORTHING, IN FORM E,N"' F 5 ) "(six or seven figures in each, plus decimals if need be)"'  20) E,N' G$=E+","+N   : - This puts NGR into easting and northing  ngr ? 2)"Enter the NGR, with grid letters, in 10, 8, 6 or 4 ";  "numeral form "'  15) G$' X% = ((G$) - 2) / 2 $Y% = 10^(5-X%) .!X$ = G$, 1): Y$ = G$, 2, 1) 81E = (G$, 3, X%)) * Y%: N = (G$, X%)) * Y% B_div(X$,500000,2,4) L_div(Y$,100000,0,5) V `: j@ columns count from 0 to 4 from left, rows 1 to 5 from top. t _div(Q$,m%,c%,r%) ~0a%=((Q$) &DF)-("A")+5: a%>13 a%=a%-1 row%=a% 5: column%=a% 5 *E=E+(column%-c%)*m% : N=N+(r%-row%)*m%  : O A(phip)=a/(1-esqd*((phip))^2) : rad of curv of lat at lat phip L B(phip)=v*(1-esqd)/(1-esqd*((phip))^2) : same for long at lat phip : ݤM(b,n,phip,phi0)=b*(((1+n+(5/4)*n^2+(5/4)*n^3)*(phip-phi0))-((3*n+3*n^2+(21/8)*n^3)*(phip-phi0)*(phip+phi0))+(((15/8)*n^2+(15/8)*n^3)*(2*(phip-phi0))*(2*(phip+phi0)))-((35/24)*n^3*(3*(phip-phi0))*(3*(phip+phi0)))) tmp=b * (((1+n+(5/4)*n^2+(5/4)*n^3)*(phip-phi0))-((3*n+3*n^2+(21/8)*n^3)*(phip-phi0)*(phip+phi0))+(((15/8)*n^2+(15/8)*n^3)*(2*(phip-phi0))*(2*(phip+phi0)))-((35/24)*n^3*(3*(phip-phi0))*(3*(phip+phi0)))) =tmp : J This takes easting and northing, does iteration for M, returns phip,  v, rho, y, and itasqd. :  _Mvrho(E,N)  y=E-E0 (phip=(N-N0)/a+phi0 2M=M(b,n,phip,phi0) < Fphin=(N-N0-M)/a+phip P phip=phin ZM=M(b,n,phip,phi0) d (N-N0-M)<.0015 n: xv=A(phip) rho=B(phip) itasqd=v/rho-1 _F  : G This contains equations leading to phi, lambda. For equation IX I D need to divide (720*rho*v^5) by v^2 to get within range, which I multiplies IX by v^2. So then divide IX by v^2. Similarly for XIIA; I v^7 outside number range. In XIIA reduce v^7 to v^3 and divide XIIA by v^4 : _toll VII=(phip)/(2*rho*v) IVIII=((phip)/(24*rho*v^3))*(5+3*(phip)^2+itasqd-9*(phip)^2*itasqd) >IX= ((phip)/(720*rho*v^3))*(61+90*(phip)^2+45*(phip)^4)  IX=IX/v^2 "$phi=phip-y^2*VII+y^4*VIII-y^6*IX ,X=1/(v*(phip)) 6.XI=1/(6*v^3*(phip))*(v/rho+2*((phip))^2) @?XII=(1/(120*v^5*(phip)))*(5+28*((phip))^2+24*((phip))^4) JUXIIA=(1/(5040*v^3*(phip)))*(61+662*((phip))^2+1320*((phip))^4+720*((phip))^6) TXIIA=XIIA/v^4 ^2lambda=lambda0+y*X-y^3*XI+y^5*XII-y^5*XIIA*y^2 hP=lambda-lambda0 r |: G This derives deviation (C) between true north and grid north from C phi and lambda (PROC_toll) and itasqd (PROC_Mvrho). When C is - negative, true N is East of grid north. _C XIII=(phi) 7XIV=(((phi)*((phi))^2)/3)*(1+3*itasqd+2*itasqd^2) .XV=(((phi)*((phi))^4)/15)*(2-((phi))^2) #C=(P*(XIII)+P^3*(XIV)+P^5*(XV))  : - This derives deviation (C) from E and N _C_EN XVI=(phip)/v 8XVII=(phip)/(3*v^3)*(1+(phip)^2-itasqd-2*itasqd^2) 6XVIII=(phip)/(15*v^5)*(2+5*(phip)^2+3*(phip)^4) C=y*XVI-y^3*XVII+y^5*XVIII & 0: : output(lambda,phi,C) D lambda=(lambda): phi=(phi) New$ = "East" X+ lambda <=0 ew$="West": lambda=-lambda b ldegminsec(phi) v deg1=deg: min1=min: sec1=sec degminsec(lambda) deg2=deg: min2=min: sec2=sec D 10) "The Latitude is "; deg1; " Degs "; min1; " Mins "; sec1;  " Secs North"' E 10) "The Longitude is "; deg2; " Degs "; min2; " Mins "; sec2;  " Secs "; ew$' C=(C) % C>0 C$="West" C$="East": C=-C degminsec(C) W 10) "True North is ";deg " Degs ";min " Mins ";sec;" Secs ";C$;" of grid North"' ( 10) "easting= ";E;" northing=";N'  :  _bd_output G=(alpha) degminsec(G) numplace(sec," ") * sec=num 4= 15)"Grid bearing is ";deg" deg ";min" min ";sec" sec"' >) C<0 alpha<=(C) alpha=alpha+2* HTBg=(alpha+C-convangle) Rdegminsec(TBg) \numplace(sec," ") f sec=num p> 15)"True bearing is ";deg;" deg ";min" min ";sec" sec"' znumplace(s," ") s=num * 15)"Grid distance is ";s;" metres"' numplace(dist," ") dist=num - 15)"True distance is ";dist;" metres"'  20)"Print vars? Y/N"; ! answer("YN")=1 _variables  : error ! =17 : REPORT:PRINT:END <>1240 :" at line ";   13)"Press any key";   $: .4 This draws yellow border, with blue background 8 border B119,0,4,0,0;19,3,3,0,0; : select yellow/blue L+ 0,0: 0,959: 1279,959 : draw border V! 1279,0: 0,0 : draw border `. VDU 28,4,58,78,4 :REM set up text window j8 VDU 24,10;10;1269;949; :REM set up graphics window t ~:  answer(alternatives$)  *FX 15,1  "A%=alternatives$, ( &DF))  A%>0 =A% : ; converts decimal degrees to degrees, minutes, seconds  degminsec(theta) 6ang=theta*3600+0.0005 : sec=(ang*1000)60000 /1000 +deg=ang 60 : min=deg 60 : deg=deg 60  :  6 removes last j$ sig figs.Pass space string to j$  numplace(Y,j$)  num$=(Y) ( num$)=j$ 2num=(num$) < F: PG Corrects for convergence as in navigation,and checks with OS calc Z page 18 d _converge nf=2*y1%+y2% x_Mvrho(E1,Nm) XXIII=1/(6*rho*v) convangle=(f*q*XXIII)  : I Case when E1 and E2 opposite sides central meridian. Nc is point of  crossing central meridian  alphasplit ratio=((y1%)/(E2-E1)) Nc=N1+ratio*(N2-N1)  Nm1=(Nc+N1)/2: Nm2=(Nc+N2)/2 Nm=Nm1: y2%=0: q=N1-Nc _converge convangle1=convangle "Nm=Nm2:y1%=0:y2%=E2-E0:q=Nc-N2 _converge convangle2=convangle "#convangle=convangle1+convangle2 , 6: @ _F JXXI=1/(2*rho*v) T$XXII=(1-4*itasqd)/(24*rho^2*v^2) ^F=F0*(1+y^2*XXI+y^4*XXII) h r: |/ s is grid distance; dist is True distance  _distance s=((E2-E1)^2+(N2-N1)^2) _Mvrho(Em,Nm):Fm=F X=(1/6)*(1/F1+4/Fm+1/F2)  F=1/X  dist=s/F  :  _variables  "F= ";F "phip= ";phip  "v= ";v "rho= ";rho "itasqd= ";itasqd  "M= ";M  "y= ";y &"VII= ";VII 0"VIII= ";VIII :"IX= ";IX D "X= ";X N"XI= ";XI X"XII= ";XII b"XIIA= ";XIIA l"XIII= ";XIII v"XIV= ";XIV "XV= ";XV "XXI= ";XXI "XXII= ";XXII "XXIII= ";XXIII  : 5 convert(deg%,min%,sec)=(min%*60+sec)/3600+deg% :  first_letter(E$,N$) column=0:row=0 column_row(E$)  E<0 column=init 5 + 2   column=init 5 + 3   column_row(N$) * N<0 4 row=4 > Hrow=3-init 5 R \read_letter f p: z second_letter(E$,N$) column_row(E$)  E<0 column=5+init 5  column=1+init 5  column_row(N$)  N<0 row= -init 5  row=4-init 5  read_letter  : C "column_row" returns the initial one or two numbers, with "-" $ if present, as "init". .: 8 column_row(EN$) Bneg$=EN$,1) L M%=(EN$) V neg$="-" ` M% =8 jleft(EN$,3) t ~ M% =7 left(EN$,2)    M%=7 left(EN$,2)   M%=6 left(EN$,1)    : B Preserves leading zeros, and repositions "-" when necessary.   en_string(EN) EN$=(((EN+0.5)*10/10))  L%=(EN$) ( EN<0 2 L%=L%-1 < neg$="-" F L%>7 PEN$=EN$,7) Zen$="0000000"+EN$,7) d nEN$=EN$,L%) xen$="000000"+EN$,6)  en$=("-"+en$)   EN>=0  L%>6 en$="0000000"+EN$,7)  en$="000000"+EN$,6)    :  left(x$,y)  (x$)<0 y=2  init=(x$,y)) " ,: 6 read_letter @a%=5*row+column J a%<9 a%=a%-1 T a%=a%+65 ^ h