Guest User

Untitled

a guest
Jan 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.47 KB | None | 0 0
  1. function read_apt_dat()
  2.  
  3. local ii = 0
  4. local jj = 0
  5. local kk = 0
  6. local line_trim = ""
  7. local line_char = ""
  8. local line_lenght = 0
  9. local apt_line = ""
  10. local apt_word = {}
  11. local mm = 0
  12.  
  13. local apt_first = 0
  14.  
  15. apt_data_num = 0
  16. apt_data = {}
  17.  
  18. local file_navdata2 = io.open(current_dir .. "B738X_apt.dat", "r")
  19. if file_navdata2 ~= nil then
  20. apt_line = file_navdata2:read()
  21. if string.sub(apt_line, 1, 7) == "log.txt" then
  22. apt_line = file_navdata2:read()
  23. end
  24. while apt_line do
  25. if apt_first ~= 0 then
  26. ii = 0
  27. jj = 0
  28. line_trim = ""
  29. line_char = ""
  30. line_lenght = string.len(apt_line)
  31. if line_lenght > 0 then
  32. for kk = 1, line_lenght do
  33. line_char = string.sub(apt_line, kk, kk)
  34. if line_char == " " then
  35. if ii == 1 then
  36. jj = jj + 1
  37. apt_word[jj] = line_trim
  38. ii = 0
  39. line_trim = ""
  40. end
  41. else
  42. line_trim = line_trim .. line_char
  43. ii = 1
  44. end
  45. end
  46. if string.len(line_trim) > 0 then
  47. jj = jj + 1
  48. apt_word[jj] = line_trim
  49. end
  50.  
  51. if jj > 0 then
  52. if string.len(apt_word[jj]) > 1 and string.byte(apt_word[jj], -1) == 13 then -- CR
  53. apt_word[jj] = string.sub(apt_word[jj], 1, -2)
  54. end
  55. end
  56.  
  57.  
  58. if jj == 6 then
  59. apt_data_num = apt_data_num + 1
  60. apt_data[apt_data_num] = {}
  61. apt_data[apt_data_num][1] = apt_word[1] -- ICAO
  62. apt_data[apt_data_num][2] = tonumber(apt_word[2]) -- lat
  63. apt_data[apt_data_num][3] = tonumber(apt_word[3]) -- lon
  64. mm = tonumber(apt_word[4]) -- trans alt
  65. if mm == nil then
  66. apt_data[apt_data_num][4] = 0 -- trans alt
  67. else
  68. apt_data[apt_data_num][4] = mm -- trans alt
  69. end
  70. mm = tonumber(apt_word[5]) -- trans lvl
  71. if mm == nil then
  72. mm = tonumber(string.sub(apt_word[5], 3, -1))
  73. if mm == nil then
  74. apt_data[apt_data_num][5] = 0 -- trans lvl
  75. else
  76. apt_data[apt_data_num][5] = mm * 100 -- trans lvl
  77. end
  78. else
  79. if mm < 1000 then
  80. apt_data[apt_data_num][5] = mm * 100 -- trans lvl
  81. else
  82. apt_data[apt_data_num][5] = mm -- trans lvl
  83. end
  84. end
  85. apt_data[apt_data_num][6] = tonumber(apt_word[6]) -- longest rnw
  86. end
  87. end
  88. end
  89. apt_first = 1
  90. apt_line = file_navdata2:read()
  91. end
  92. file_navdata2:close()
  93. end
  94.  
  95. end
  96.  
  97. function create_idx_table()
  98.  
  99. local ii = 0
  100. local tmp_byte = 0
  101. local tmp_idx = 0
  102.  
  103. -- clear idx tables
  104. idx_earth_nav = {}
  105. idx_apt = {}
  106. idx_ils = {}
  107. idx_ils_icao = {}
  108. idx_rnw = {}
  109. idx_awy = {}
  110.  
  111. for ii = 48, 57 do
  112. idx_earth_nav[ii] = {}
  113. idx_earth_nav[ii][99999] = 0
  114. idx_apt[ii] = {}
  115. idx_apt[ii][99999] = 0
  116. idx_ils[ii] = {}
  117. idx_ils[ii][99999] = 0
  118. idx_ils_icao[ii] = {}
  119. idx_ils_icao[ii][99999] = 0
  120. idx_rnw[ii] = {}
  121. idx_rnw[ii][99999] = 0
  122. idx_awy[ii] = {}
  123. idx_awy[ii][99999] = 0
  124. end
  125. for ii = 65, 90 do
  126. idx_earth_nav[ii] = {}
  127. idx_earth_nav[ii][99999] = 0
  128. idx_apt[ii] = {}
  129. idx_apt[ii][99999] = 0
  130. idx_ils[ii] = {}
  131. idx_ils[ii][99999] = 0
  132. idx_ils_icao[ii] = {}
  133. idx_ils_icao[ii][99999] = 0
  134. idx_rnw[ii] = {}
  135. idx_rnw[ii][99999] = 0
  136. idx_awy[ii] = {}
  137. idx_awy[ii][99999] = 0
  138. end
  139.  
  140. if earth_nav_num > 0 then
  141. for ii = 1, earth_nav_num do
  142. tmp_byte = string.byte(string.sub(earth_nav[ii][4], 1, 1))
  143. if (tmp_byte >= 48 and tmp_byte <= 57) or (tmp_byte >= 65 and tmp_byte <= 90) then
  144. tmp_idx = idx_earth_nav[tmp_byte][99999]
  145. if tmp_idx < 99998 then
  146. tmp_idx = tmp_idx + 1
  147. idx_earth_nav[tmp_byte][99999] = tmp_idx
  148. idx_earth_nav[tmp_byte][tmp_idx] = ii
  149. end
  150. end
  151. end
  152. end
  153.  
  154. if apt_data_num > 0 then
  155. for ii = 1, apt_data_num do
  156. tmp_byte = string.byte(string.sub(apt_data[ii][1], 1, 1))
  157. if (tmp_byte >= 48 and tmp_byte <= 57) or (tmp_byte >= 65 and tmp_byte <= 90) then
  158. tmp_idx = idx_apt[tmp_byte][99999]
  159. if tmp_idx < 99998 then
  160. tmp_idx = tmp_idx + 1
  161. idx_apt[tmp_byte][99999] = tmp_idx
  162. idx_apt[tmp_byte][tmp_idx] = ii
  163. end
  164. end
  165. end
  166. end
  167.  
  168. if ils_nav_num > 0 then
  169. for ii = 1, ils_nav_num do
  170. tmp_byte = string.byte(string.sub(ils_nav[ii][1], 1, 1))
  171. if (tmp_byte >= 48 and tmp_byte <= 57) or (tmp_byte >= 65 and tmp_byte <= 90) then
  172. tmp_idx = idx_ils[tmp_byte][99999]
  173. if tmp_idx < 99998 then
  174. tmp_idx = tmp_idx + 1
  175. idx_ils[tmp_byte][99999] = tmp_idx
  176. idx_ils[tmp_byte][tmp_idx] = ii
  177. end
  178. end
  179. tmp_byte = string.byte(string.sub(ils_nav[ii][7], 1, 1))
  180. if (tmp_byte >= 48 and tmp_byte <= 57) or (tmp_byte >= 65 and tmp_byte <= 90) then
  181. tmp_idx = idx_ils_icao[tmp_byte][99999]
  182. if tmp_idx < 99998 then
  183. tmp_idx = tmp_idx + 1
  184. idx_ils_icao[tmp_byte][99999] = tmp_idx
  185. idx_ils_icao[tmp_byte][tmp_idx] = ii
  186. end
  187. end
  188. end
  189. end
  190.  
  191. if awy_data_num > 0 then
  192. for ii = 1, awy_data_num do
  193. tmp_byte = string.byte(string.sub(awy_data[ii][1], 1, 1))
  194. if (tmp_byte >= 48 and tmp_byte <= 57) or (tmp_byte >= 65 and tmp_byte <= 90) then
  195. tmp_idx = idx_awy[tmp_byte][99999]
  196. if tmp_idx < 99998 then
  197. tmp_idx = tmp_idx + 1
  198. idx_awy[tmp_byte][99999] = tmp_idx
  199. idx_awy[tmp_byte][tmp_idx] = ii
  200. end
  201. end
  202. end
  203. end
  204. --dump_idx_table()
  205. end
  206.  
  207. function apt_exist(eee)
  208.  
  209. local ii = 0
  210. local res = false
  211. local nd_x = 0
  212. local idx_rec = 0
  213.  
  214. icao_latitude = 0
  215. icao_longitude = 0
  216.  
  217. if apt_data_num > 0 then
  218. nd_x = string.byte(string.sub(eee, 1, 1))
  219. if (nd_x >= 48 and nd_x <= 57) or (nd_x >= 65 and nd_x <= 90) then
  220. if idx_apt[nd_x][99999] > 0 then
  221. for ii = 1, idx_apt[nd_x][99999] do
  222. idx_rec = idx_apt[nd_x][ii]
  223. if eee == apt_data[idx_rec][1] then
  224. icao_latitude = apt_data[idx_rec][2]
  225. icao_longitude = apt_data[idx_rec][3]
  226. icao_tns_alt = apt_data[idx_rec][4]
  227. icao_tns_lvl = apt_data[idx_rec][5]
  228. res = true
  229. break
  230. end
  231. end
  232. end
  233. end
  234. end
  235. return res
  236.  
  237. end
Add Comment
Please, Sign In to add comment