Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function read_apt_dat()
- local ii = 0
- local jj = 0
- local kk = 0
- local line_trim = ""
- local line_char = ""
- local line_lenght = 0
- local apt_line = ""
- local apt_word = {}
- local mm = 0
- local apt_first = 0
- apt_data_num = 0
- apt_data = {}
- local file_navdata2 = io.open(current_dir .. "B738X_apt.dat", "r")
- if file_navdata2 ~= nil then
- apt_line = file_navdata2:read()
- if string.sub(apt_line, 1, 7) == "log.txt" then
- apt_line = file_navdata2:read()
- end
- while apt_line do
- if apt_first ~= 0 then
- ii = 0
- jj = 0
- line_trim = ""
- line_char = ""
- line_lenght = string.len(apt_line)
- if line_lenght > 0 then
- for kk = 1, line_lenght do
- line_char = string.sub(apt_line, kk, kk)
- if line_char == " " then
- if ii == 1 then
- jj = jj + 1
- apt_word[jj] = line_trim
- ii = 0
- line_trim = ""
- end
- else
- line_trim = line_trim .. line_char
- ii = 1
- end
- end
- if string.len(line_trim) > 0 then
- jj = jj + 1
- apt_word[jj] = line_trim
- end
- if jj > 0 then
- if string.len(apt_word[jj]) > 1 and string.byte(apt_word[jj], -1) == 13 then -- CR
- apt_word[jj] = string.sub(apt_word[jj], 1, -2)
- end
- end
- if jj == 6 then
- apt_data_num = apt_data_num + 1
- apt_data[apt_data_num] = {}
- apt_data[apt_data_num][1] = apt_word[1] -- ICAO
- apt_data[apt_data_num][2] = tonumber(apt_word[2]) -- lat
- apt_data[apt_data_num][3] = tonumber(apt_word[3]) -- lon
- mm = tonumber(apt_word[4]) -- trans alt
- if mm == nil then
- apt_data[apt_data_num][4] = 0 -- trans alt
- else
- apt_data[apt_data_num][4] = mm -- trans alt
- end
- mm = tonumber(apt_word[5]) -- trans lvl
- if mm == nil then
- mm = tonumber(string.sub(apt_word[5], 3, -1))
- if mm == nil then
- apt_data[apt_data_num][5] = 0 -- trans lvl
- else
- apt_data[apt_data_num][5] = mm * 100 -- trans lvl
- end
- else
- if mm < 1000 then
- apt_data[apt_data_num][5] = mm * 100 -- trans lvl
- else
- apt_data[apt_data_num][5] = mm -- trans lvl
- end
- end
- apt_data[apt_data_num][6] = tonumber(apt_word[6]) -- longest rnw
- end
- end
- end
- apt_first = 1
- apt_line = file_navdata2:read()
- end
- file_navdata2:close()
- end
- end
- function create_idx_table()
- local ii = 0
- local tmp_byte = 0
- local tmp_idx = 0
- -- clear idx tables
- idx_earth_nav = {}
- idx_apt = {}
- idx_ils = {}
- idx_ils_icao = {}
- idx_rnw = {}
- idx_awy = {}
- for ii = 48, 57 do
- idx_earth_nav[ii] = {}
- idx_earth_nav[ii][99999] = 0
- idx_apt[ii] = {}
- idx_apt[ii][99999] = 0
- idx_ils[ii] = {}
- idx_ils[ii][99999] = 0
- idx_ils_icao[ii] = {}
- idx_ils_icao[ii][99999] = 0
- idx_rnw[ii] = {}
- idx_rnw[ii][99999] = 0
- idx_awy[ii] = {}
- idx_awy[ii][99999] = 0
- end
- for ii = 65, 90 do
- idx_earth_nav[ii] = {}
- idx_earth_nav[ii][99999] = 0
- idx_apt[ii] = {}
- idx_apt[ii][99999] = 0
- idx_ils[ii] = {}
- idx_ils[ii][99999] = 0
- idx_ils_icao[ii] = {}
- idx_ils_icao[ii][99999] = 0
- idx_rnw[ii] = {}
- idx_rnw[ii][99999] = 0
- idx_awy[ii] = {}
- idx_awy[ii][99999] = 0
- end
- if earth_nav_num > 0 then
- for ii = 1, earth_nav_num do
- tmp_byte = string.byte(string.sub(earth_nav[ii][4], 1, 1))
- if (tmp_byte >= 48 and tmp_byte <= 57) or (tmp_byte >= 65 and tmp_byte <= 90) then
- tmp_idx = idx_earth_nav[tmp_byte][99999]
- if tmp_idx < 99998 then
- tmp_idx = tmp_idx + 1
- idx_earth_nav[tmp_byte][99999] = tmp_idx
- idx_earth_nav[tmp_byte][tmp_idx] = ii
- end
- end
- end
- end
- if apt_data_num > 0 then
- for ii = 1, apt_data_num do
- tmp_byte = string.byte(string.sub(apt_data[ii][1], 1, 1))
- if (tmp_byte >= 48 and tmp_byte <= 57) or (tmp_byte >= 65 and tmp_byte <= 90) then
- tmp_idx = idx_apt[tmp_byte][99999]
- if tmp_idx < 99998 then
- tmp_idx = tmp_idx + 1
- idx_apt[tmp_byte][99999] = tmp_idx
- idx_apt[tmp_byte][tmp_idx] = ii
- end
- end
- end
- end
- if ils_nav_num > 0 then
- for ii = 1, ils_nav_num do
- tmp_byte = string.byte(string.sub(ils_nav[ii][1], 1, 1))
- if (tmp_byte >= 48 and tmp_byte <= 57) or (tmp_byte >= 65 and tmp_byte <= 90) then
- tmp_idx = idx_ils[tmp_byte][99999]
- if tmp_idx < 99998 then
- tmp_idx = tmp_idx + 1
- idx_ils[tmp_byte][99999] = tmp_idx
- idx_ils[tmp_byte][tmp_idx] = ii
- end
- end
- tmp_byte = string.byte(string.sub(ils_nav[ii][7], 1, 1))
- if (tmp_byte >= 48 and tmp_byte <= 57) or (tmp_byte >= 65 and tmp_byte <= 90) then
- tmp_idx = idx_ils_icao[tmp_byte][99999]
- if tmp_idx < 99998 then
- tmp_idx = tmp_idx + 1
- idx_ils_icao[tmp_byte][99999] = tmp_idx
- idx_ils_icao[tmp_byte][tmp_idx] = ii
- end
- end
- end
- end
- if awy_data_num > 0 then
- for ii = 1, awy_data_num do
- tmp_byte = string.byte(string.sub(awy_data[ii][1], 1, 1))
- if (tmp_byte >= 48 and tmp_byte <= 57) or (tmp_byte >= 65 and tmp_byte <= 90) then
- tmp_idx = idx_awy[tmp_byte][99999]
- if tmp_idx < 99998 then
- tmp_idx = tmp_idx + 1
- idx_awy[tmp_byte][99999] = tmp_idx
- idx_awy[tmp_byte][tmp_idx] = ii
- end
- end
- end
- end
- --dump_idx_table()
- end
- function apt_exist(eee)
- local ii = 0
- local res = false
- local nd_x = 0
- local idx_rec = 0
- icao_latitude = 0
- icao_longitude = 0
- if apt_data_num > 0 then
- nd_x = string.byte(string.sub(eee, 1, 1))
- if (nd_x >= 48 and nd_x <= 57) or (nd_x >= 65 and nd_x <= 90) then
- if idx_apt[nd_x][99999] > 0 then
- for ii = 1, idx_apt[nd_x][99999] do
- idx_rec = idx_apt[nd_x][ii]
- if eee == apt_data[idx_rec][1] then
- icao_latitude = apt_data[idx_rec][2]
- icao_longitude = apt_data[idx_rec][3]
- icao_tns_alt = apt_data[idx_rec][4]
- icao_tns_lvl = apt_data[idx_rec][5]
- res = true
- break
- end
- end
- end
- end
- end
- return res
- end
Add Comment
Please, Sign In to add comment