-
Notifications
You must be signed in to change notification settings - Fork 0
/
atsreader.py
131 lines (88 loc) · 4.19 KB
/
atsreader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# This file parses the vasFMC format ATS.txt file
# ATS.txt file must be in AIRAC directory
from objects import Airway
from objects import PointInSpace
from objects import AmbiguousAirway
from objects import Coordinates
def airway_lat_long_maker(input_string) -> str:
input_was_negative = False # fill it with something
if input_string.startswith('-'):
input_was_negative = True
# remove the negative, if necessary
if input_was_negative:
input_string = input_string[1:]
degrees = input_string[:-6]
# remove leading zeroes
degrees = degrees.lstrip('0')
if degrees == "":
degrees = "0"
decimal = input_string[-6:] # 6 decimal places
input_with_decimal = degrees + '.' + decimal
if input_was_negative:
# put the negative sign back if needed
input_with_decimal = '-' + input_with_decimal
output = input_with_decimal
return output
def airway_dict_maker():
ats_file = open("AIRAC/ATS.txt")
airway_dict = {}
contents = ats_file.read()
paragraphs = contents.split("\n\n") # each paragraph should be an airway
# remove blank strings that will occur at end of list
while "" in paragraphs:
paragraphs.remove("")
split_paragraphs = []
for paragraph in paragraphs:
split_paragraphs.append(paragraph.split('\n'))
# each split paragraph is an airway with lines in a list
for split_paragraph in split_paragraphs:
for line in split_paragraph:
if line.startswith("A"): # this is the beginning of an airway
current_line = line.rstrip().split("|")
route_id = current_line[1]
currentairway = Airway(route_id)
airwaylist = []
simpleairwaylist = []
elif line.startswith("S"):
current_line = line.rstrip().split("|")
firstid = current_line[1]
firstlat = current_line[2]
firstlong = current_line[3]
secondid = current_line[4]
secondlat = current_line[5]
secondlong = current_line[6]
firstlat = airway_lat_long_maker(firstlat)
firstlong = airway_lat_long_maker(firstlong)
secondlat = airway_lat_long_maker(secondlat)
secondlong = airway_lat_long_maker(secondlong)
firstwaypoint = [firstid, firstlat, firstlong]
secondwaypoint = [secondid, secondlat, secondlong]
#for debug, has to do with crossing equator/prime meridian
if firstlat == '.':
print("bogus value for waypoint", firstwaypoint)
if firstlong == '.':
print("bogus value for waypoint", firstwaypoint)
if secondlat == '.':
print("bogus value for waypoint", secondwaypoint)
if secondlong == '.':
print("bogus value for waypoint", secondwaypoint)
# this is asking if an object is already in the list. comparing an object to an object is bad news.
if firstwaypoint not in simpleairwaylist:
airwaylist.append(PointInSpace(firstwaypoint[0], Coordinates(firstwaypoint[1], firstwaypoint[2]),
'airwaywaypoint'))
simpleairwaylist.append(firstwaypoint)
if secondwaypoint not in simpleairwaylist:
airwaylist.append(PointInSpace(secondwaypoint[0], Coordinates(secondwaypoint[1], secondwaypoint[2]),
'airwaywaypoint'))
simpleairwaylist.append(secondwaypoint)
currentairway.set_waypoints(airwaylist)
if route_id in airway_dict:
if type(airway_dict[route_id]) is AmbiguousAirway:
airway_dict[route_id].add_possibility(currentairway)
else:
airway_dict[route_id] = AmbiguousAirway(route_id, airway_dict[route_id])
airway_dict[route_id].add_possibility(currentairway)
else:
airway_dict[route_id] = currentairway
ats_file.close()
return airway_dict