home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 471 / RealMapsSIS.sis / UserInput (.txt) < prev   
Encoding:
EPOC OPL Source  |  2001-10-18  |  1.3 KB  |  64 lines

  1.  
  2.  
  3. REM Rough OSGB Grid to Lat/Long Conversion
  4. REM Example UserInput.OPO Source Code
  5. REM By Kevin Millican
  6.  
  7. PROC userinp$:(os$)
  8.   LOCAL t$(20),e1,n1,t1,t2
  9.   LOCAL E,N,res$(40),c%,d
  10.  
  11. ONERR handerr
  12.   t$=UPPER$(os$)
  13.  
  14. REM Get the eastings and northings allowing for the
  15. REM possibility that the grid reference may be entered
  16. REM as AAnnnnnn AAnnnnnnnn etc
  17.   c%=(LEN(t$)-2)/2
  18.   d=10**(c%-2)
  19.   e1=VAL(MID$(t$,3,c%))/d
  20.   n1=VAL(MID$(t$,3+c%,c%))/d
  21.  
  22. REM calculate grid square offsets  
  23.   t1=ASC(LEFT$(t$,1))-ASC("A")
  24.   IF t1>8
  25.     t1=t1-1
  26.   ENDIF
  27.   t2=INT(t1/5)
  28.   n1=n1+500*(3-t2)
  29.   e1=e1+500*(t1-5*t2-2)
  30.   t1=ASC(MID$(t$,2,1))-ASC("A")
  31.   IF t1>8
  32.     t1=t1-1
  33.   ENDIF
  34.   t2=INT(t1/5)
  35.   n1=n1+100*(4-t2)
  36.   e1=e1+100*(t1-5*t2)
  37.  
  38. REM Do the grid conversion  
  39.   t1=(n1+5548.79)/6371.28
  40.   t2=2*(ATAN(EXP((e1-400)/6389.7)))
  41.   E=ATAN(-COS(t2)/(COS(t1)*SIN(t2)))-0.0349066
  42.   N=SIN(t2)*SIN(t1)
  43.   N=ATAN(N/(SQR(1-N*N)))
  44.  
  45. REM return the result as a tab-delimited string
  46.   
  47.   res$=GEN$(DEG(N),14)+CHR$(9)+GEN$(DEG(E),15)
  48.   
  49.   RETURN res$
  50.  
  51. REM or return Error if a problem occurs  
  52. handerr::
  53. ONERR OFF
  54. RETURN "Error"  
  55. ENDP
  56.  
  57. PROC UserDesc$:
  58. RETURN "OS Grid Ref"
  59. ENDP
  60.  
  61.  
  62.  
  63.  
  64.