#!/usr/bin/env python import string import sys null_trans = string.maketrans('', '') results = [] airports_file = open('../raw_data/FAA_ATA-100/APT.del', 'r') for line in airports_file.readlines(): fields = string.split(line, '|') entry_type = fields[0] if entry_type == 'APT': site_number = fields[1] landing_facility = fields[2] identifier = fields[3] state = fields[8] county = fields[9] state_abbrev = fields[10] usage = fields[13] #if not usage == 'PU': # continue county = string.translate(county, null_trans, ". '") #if not landing_facility == 'AIRPORT': # continue #print identifier elif entry_type == 'RWY': #RWY|50877.29*C|AK|15W/33W|5000|600|WATER||||15W||||||||||||||||||||||||||||||||||A(V)|||||33W|||Y|||||||||||||||||||||||||||||||A(V)|||||||||||||||||||||||||||||||||||| if not fields[1] == site_number: raise Exception, 'unmatched runway' #print line runway_ident = fields[3] runway_length = int(fields[4] or '0') runway_width = fields[5] runway_surface_type = fields[6] runway_surface_treatment = fields[7] runway_surface_pcn = fields[8] runway_lights = fields[9] runway_end_ident = fields[10] runway_alignment = fields[11] runway_ils = fields[12] runway_dthreshold = int(fields[29] or '0') #for (i, field) in enumerate(fields): # print i, field #if 'ILS' in runway_ils or 'LOC' in runway_ils: if not runway_ils == '': runway_ldistance = runway_length - runway_dthreshold results.append((identifier, runway_end_ident, runway_length, runway_width, runway_surface_type, runway_ils, runway_dthreshold, runway_ldistance, state)) # Do reciprocol end. runway_end_ident = fields[49] runway_ils = fields[51] runway_dthreshold = int(fields[68] or '0') #if 'ILS' in runway_ils or 'LOC' in runway_ils: if not runway_ils == '': runway_ldistance = runway_length - runway_dthreshold results.append((identifier, runway_end_ident, runway_length, runway_width, runway_surface_type, runway_ils, runway_dthreshold, runway_ldistance, state)) print len(results) def sortby_runway_length(a, b): return(cmp(a[2], b[2])) def sortby_runway_ldistance(a, b): return(cmp(a[7], b[7])) def sortby_runway_dthreshold(a, b): #return(cmp(a[6], b[6])) return(cmp(b[6], a[6])) results.sort(sortby_runway_length) #results.sort(sortby_runway_ldistance) #results.sort(sortby_runway_dthreshold) for result in results: print string.join(map(str, result), ', ')