def test_route(self):
     print "=========== Flight Plan start  =========== " + time.strftime("%c")
     
     strRoute = 'ADEP/LFBD/11-COGNAC-FOUCO-DIBAG-LIMOGES-BEBIX-GUERE-LARON-KUKOR-'
     strRoute += 'MOULINS-PIBAT-DIJON-RESPO-DILAB-EPINAL-ADES/LFST/23'
     
     flightPath = FlightPath(route = strRoute, 
                             aircraftICAOcode = 'A320',
                             RequestedFlightLevel = 310, 
                             cruiseMach = 0.78, 
                             takeOffMassKilograms=62000.0)
     '''
     RFL:    FL 310 => 31000 feet
     Cruise Speed    Mach 0.78                                    
     Take Off Weight    62000 kgs    
     '''
     print "=========== Flight Plan compute  =========== " + time.strftime("%c")
     
     t0 = time.clock()
     print 'time zero= ' + str(t0)
     lengthNauticalMiles = flightPath.computeLengthNauticalMiles()
     print 'flight path length= {0:.2f} nautics '.format(lengthNauticalMiles)
     flightPath.computeFlight(deltaTimeSeconds = 1.0)
     print 'simulation duration= ' + str(time.clock()-t0) + ' seconds'
     
     print "=========== Flight Plan create output files  =========== " + time.strftime("%c")
     flightPath.createFlightOutputFiles()
     print "=========== Flight Plan end  =========== " + time.strftime("%c")
    def test_route(self):
#============================================
        
        #sys.stdout = open('log.txt','w') #redirect all prints to this log file
        
        print "=========== Flight Plan start  =========== " + time.strftime("%c")
        
        strRoute = 'ADEP/LEMD-ZMR-BARKO-ADES/LEVX'
        strRoute = 'ADEP/LFBM/27-AGN-TOU-GAI-AMOLO-DEGOL-FJR-MARRI-ADES/LFML/31R'
    
        flightPath = FlightPath(route = strRoute, 
                                aircraftICAOcode = 'A320',
                                RequestedFlightLevel = 270, 
                                cruiseMach = 0.78, 
                                takeOffMassKilograms=62000.0)
        '''
        RFL:    FL 310 => 31000 feet
        Cruise Speed    Mach 0.78                                    
        Take Off Weight    62000 kgs    
        '''
        print "=========== Flight Plan compute  =========== " + time.strftime("%c")
        
        t0 = time.clock()
        print 'time zero= ' + str(t0)
        lengthNauticalMiles = flightPath.computeLengthNauticalMiles()
        print 'flight path length= {0:.2f} nautics '.format(lengthNauticalMiles)
        flightPath.computeFlight(deltaTimeSeconds = 1.0)
        print 'simulation duration= ' + str(time.clock()-t0) + ' seconds'
        
        print "=========== Flight Plan create output files  =========== " + time.strftime("%c")
        flightPath.createFlightOutputFiles()
        print "=========== Flight Plan end  =========== " + time.strftime("%c")
    def test_route(self):
    
    #sys.stdout = open('log.txt','w') #redirect all prints to this log file

        print "=========== Flight Plan start  =========== " + time.strftime("%c")
        
        strRoute = 'ADEP/CYMX/06-TAMKO-MATOR-DICEN-CHARLEVOIX-RIVIEREDULOUP-LOMSI-RESNO-NETKI-'
        strRoute += 'NIBOG-BELFAST-DUFFY-RINGA-SLYDA-ISLEOFMAN-KELLY-PENIL-ASNIP-MANCHESTER-'
        strRoute += 'DISAL-NAPEX-DOLAS-ENITO-DIBAL-BUKUT-LAMSO-EVELI-BASNO-PAMPUS-IVLUT-LUNIX-'
        strRoute += 'RENDI-EDUPO-NAPRO-DEPAD-AMOSU-MISGO-COLA-ROLIS-'
        strRoute += 'ADES/EDDF/25C'
        flightPath = FlightPath(route = strRoute, 
                                aircraftICAOcode = 'A310',
                                RequestedFlightLevel = 390, 
                                cruiseMach = 0.83, 
                                takeOffMassKilograms = 120000.0)
        '''
        RFL:    FL 310 => 31000 feet
        Cruise Speed    Mach 0.78                                    
        Take Off Weight    62000 kgs    
        '''
        print "=========== Flight Plan compute  =========== " + time.strftime("%c")
        
        t0 = time.clock()
        print 'time zero= ' + str(t0)
        lengthNauticalMiles = flightPath.computeLengthNauticalMiles()
        print 'flight path length= {0:.2f} nautics '.format(lengthNauticalMiles)
        flightPath.computeFlight(deltaTimeSeconds = 1.0)
        print 'simulation duration= ' + str(time.clock()-t0) + ' seconds'
        
        print "=========== Flight Plan create output files  =========== " + time.strftime("%c")
        flightPath.createFlightOutputFiles()
        print "=========== Flight Plan end  =========== " + time.strftime("%c")
    def test_route(self):
        print "=========== Flight Plan start  =========== " + time.strftime("%c")

        strRoute = "ADEP/LFBO-MENDE-MEZIN-LATAM-OTROT-ETREK-RUSIT-BULOL-LOGNI-MOKIP-DIJON-RESPO-DILAB-EPINAL-ADES/LFST"
        flightPath = FlightPath(
            route=strRoute,
            aircraftICAOcode="A320",
            RequestedFlightLevel=310,
            cruiseMach=0.78,
            takeOffMassKilograms=62000.0,
        )
        """
        RFL:    FL 310 => 31000 feet
        Cruise Speed    Mach 0.78                                    
        Take Off Weight    62000 kgs    
        """
        print "=========== Flight Plan compute  =========== " + time.strftime("%c")

        t0 = time.clock()
        print "time zero= " + str(t0)
        lengthNauticalMiles = flightPath.computeLengthNauticalMiles()
        print "flight path length= {0:.2f} nautics ".format(lengthNauticalMiles)
        flightPath.computeFlight(deltaTimeSeconds=1.0)
        print "simulation duration= " + str(time.clock() - t0) + " seconds"

        print "=========== Flight Plan create output files  =========== " + time.strftime("%c")
        flightPath.createFlightOutputFiles()
        print "=========== Flight Plan end  =========== " + time.strftime("%c")
 def test_route(self):
 
     print "=========== Flight Plan start  =========== " 
     
     strRoute = 'ADEP/LFPG/26R-LAIGLE-ROLEN-PEPON-KURIS-TERPO-ERIGA-INBAB-ATLEN-DEVAR-ASTURIAS-KUVAN-BISMU-BARKO-FATIMA-ADES/LPPT/03'
     flightPath = FlightPath(route = strRoute, 
                             aircraftICAOcode = 'A320',
                             RequestedFlightLevel = 330, 
                             cruiseMach = 0.82, 
                             takeOffMassKilograms = 68000.0)
     '''
     RFL:    FL 310 => 31000 feet
     Cruise Speed    Mach 0.78                                    
     Take Off Weight    62000 kgs    
     '''
     print "=========== Flight Plan compute  =========== " + time.strftime("%c")
     
     t0 = time.clock()
     print 'time zero= ' + str(t0)
     lengthNauticalMiles = flightPath.computeLengthNauticalMiles()
     print 'flight path length= {0:.2f} nautics '.format(lengthNauticalMiles)
     flightPath.computeFlight(deltaTimeSeconds = 1.0)
     print 'simulation duration= ' + str(time.clock()-t0) + ' seconds'
     
     print "=========== Flight Plan create output files  =========== " + time.strftime("%c")
     flightPath.createFlightOutputFiles()
     print "=========== Flight Plan end  =========== " + time.strftime("%c")
 def test_route(self):
 
     departureAirportICAOcode = 'LFBO'
     arrivalAirportICAOcode = 'EDDK'
 
     print "=========== Flight Plan start  =========== " + time.strftime("%c")
     
     strRoute = 'ADEP/LFBO/32R-'
     strRoute += 'MEN-MEZIN-LATAM-OTROT-ETREK-RUSIT-'
     strRoute += 'BULOL-LOGNI-MOKIP-DJL-RESPO-DILAB-EPL-NANCY-JARNY-ROUSY-'
     strRoute += 'DIK-ADUSU-UNEPI-GEBSO-ERUKI-NOR-'
     strRoute += 'ADES/EDDK/32R'
     flightPath = FlightPath(route = strRoute, 
                             aircraftICAOcode = 'A320',
                             RequestedFlightLevel = 310, 
                             cruiseMach = 0.78, 
                             takeOffMassKilograms=62000.0)
     '''
     RFL:    FL 310 => 31000 feet
     Cruise Speed    Mach 0.78                                    
     Take Off Weight    62000 kgs    
     '''
     print "=========== Flight Plan compute  =========== " + time.strftime("%c")
     
     t0 = time.clock()
     print 'time zero= ' + str(t0)
     lengthNauticalMiles = flightPath.computeLengthNauticalMiles()
     print 'flight path length= {0:.2f} nautics '.format(lengthNauticalMiles)
     flightPath.computeFlight(deltaTimeSeconds = 1.0)
     print 'simulation duration= ' + str(time.clock()-t0) + ' seconds'
     
     print "=========== Flight Plan create output files  =========== " + time.strftime("%c")
     flightPath.createFlightOutputFiles()
     print "=========== Flight Plan end  =========== " + time.strftime("%c")
 def test_route(self):
 
     print "=========== Flight Plan start  =========== " 
     
     strRoute = 'ADEP/EGLL/27L-COMPTON-KENET-GAVGO-DIKAS-STRUMBLE-SLANY-'
     strRoute += 'ABAGU-TIPUR-SHANNON-MALOT-RIKAL-EBONY-SEAER-SCARS-KENNEBUNK-ADES/KJFK/04L'
     
     strRoute = 'ADEP/EGLL/27L-MID-DRAKE-SITET-ETRAT-DVL-LGL-SORAP-BENAR-VANAD-AMB-BALAN-LMG-VELIN-SAU-ENSAC-ADES/LFBM/27'
     
     strRoute = 'ADEP/EGLL/27L-MAY-SFD-BENBO-HAWKE-XAMAB-VEULE-INPAX-RESMI-KOTAP-KETEX-KUSEK-KOTIS-KUKOR-OBEPA-LERGA-LATAM-ARDEG-AVN-MTG-JULEE-ADES/LFMI/33'
     
     flightPath = FlightPath(route = strRoute, 
                             aircraftICAOcode = 'A320',
                             RequestedFlightLevel = 310, 
                             cruiseMach = 0.78, 
                             takeOffMassKilograms = 76000.0)
     '''
     RFL:    FL 310 => 31000 feet
     Cruise Speed    => Mach 0.78                                    
     Take Off Weight    72000 kgs    
     '''
     print "=========== Flight Plan compute  =========== " 
     
     t0 = time.clock()
     print 'time zero= ' + str(t0)
     lengthNauticalMiles = flightPath.computeLengthNauticalMiles()
     print 'flight path length= {0} nautics '.format(lengthNauticalMiles)
     flightPath.computeFlight(deltaTimeSeconds = 1.0)
     print 'simulation duration= ' + str(time.clock()-t0) + ' seconds'
     
     print "=========== Flight Plan create output files  =========== "
     flightPath.createFlightOutputFiles()
     print "=========== Flight Plan end  =========== " 
 def test_Route(self):
 
     print "=========== Flight Plan start  =========== " 
     
     strRoute = 'ADEP/SBGL-ALDEIA-NIKDO-MACAE-GIKPO-MABSI-VITORIA-GIDOD-'
     strRoute += 'ISILA-POSGA-SEGURO-BIDEV-NAXOV-IRUMI-ESLIB-MEDIT-RUBEN-KIBEG-'
     strRoute += 'AMBET-VUKSU-NORONHA-UTRAM-MEDAL-NAMBI-RAKUD-IRAVU-MOGNI-ONOBI-CABRAL-'
     strRoute += 'IPERA-ISOKA-LIMAL-UDATI-ODEGI-LOMAS-CANARIA-VASTO-SULAM-DIMSA-ATLUX-'
     strRoute += 'SUNID-AKUDA-OBOLO-PESAS-EKRIS-LUSEM-LULUT-BORDEAUX-COGNAC-ADABI-BOKNO-'
     strRoute += 'DEVRO-VANAD-KOVAK-ADES/LFPG'
     flightPath = FlightPath(route = strRoute, 
                             aircraftICAOcode = 'A332',
                             RequestedFlightLevel = 350, 
                             cruiseMach = 0.86, 
                             takeOffMassKilograms = 230000.0)
     
     print "=========== Flight Plan compute  =========== " 
     
     t0 = time.clock()
     print 'time zero= ' + str(t0)
     lengthNauticalMiles = flightPath.computeLengthNauticalMiles()
     print 'flight path length= {0} nautics '.format(lengthNauticalMiles)
     flightPath.computeFlight(deltaTimeSeconds = 1.0)
     print 'simulation duration= ' + str(time.clock()-t0) + ' seconds'
     
     print "=========== Flight Plan create output files  =========== "
     flightPath.createFlightOutputFiles()
     print "=========== Flight Plan end  =========== " 
       

#============================================
if __name__ == '__main__':
    
    print "=========== Flight Plan start  =========== " 
    
    strRoute = 'ADEP/EGLL/27L-COMPTON-KENET-GAVGO-DIKAS-STRUMBLE-SLANY-'
    strRoute += 'ABAGU-TIPUR-SHANNON-MALOT-RIKAL-EBONY-SEAER-SCARS-KENNEBUNK-ADES/KJFK/04L'
    
    strRoute = 'ADEP/EGLL/27L-MID-DRAKE-SITET-ETRAT-DVL-LGL-SORAP-BENAR-VANAD-AMB-BALAN-LMG-VELIN-SAU-ENSAC-ADES/LFBM/27'
    
    flightPath = FlightPath(route = strRoute, 
                            aircraftICAOcode = 'A320',
                            RequestedFlightLevel = 310, 
                            cruiseMach = 0.78, 
                            takeOffMassKilograms = 76000.0)
    '''
    RFL:    FL 310 => 31000 feet
    Cruise Speed    => Mach 0.78                                    
    Take Off Weight    72000 kgs    
    '''
    print "=========== Flight Plan compute  =========== " 
    
    t0 = time.clock()
    print 'time zero= ' + str(t0)
    lengthNauticalMiles = flightPath.computeLengthNauticalMiles()
    print 'flight path length= {0} nautics '.format(lengthNauticalMiles)
    flightPath.computeFlight(deltaTimeSeconds = 1.0)
    print 'simulation duration= ' + str(time.clock()-t0) + ' seconds'
    def test_route(self):
    
#     import sys
#     temp = sys.stdout #store original stdout object for later
#     sys.stdout = open('log.txt','w') #redirect all prints to this log file

        wayPointsDb = WayPointsDatabase()
        assert wayPointsDb.read()
            
        t0 = time.clock()
        print ' ========== Airports Direct Route testing ======= '
        
        airportsDb = AirportsDatabase()
        assert  airportsDb.read()
        t1 = time.clock()
        print ' time to read airports database= {0:.2f} seconds'.format(t1-t0)
        
        t2 = time.clock()
        runwaysDb = RunWayDataBase()
        assert runwaysDb.read()
        print ' time to read run-way database= {0:.2f} seconds'.format(t2-t1)
        
        print ' ========== Airports Direct Route testing ======= '
        departureCountry = 'Japan'
        departureCountry = 'United Kingdom'
        departureCountry = 'France'
        departureCountry = 'United States'
        arrivalCountry = 'Canada'
        arrivalCountry = 'France' 
        arrivalCountry = 'United States' 
        for departureAirport in  airportsDb.getAirportsFromCountry(Country = departureCountry):
            departureAirportICAOcode = departureAirport.getICAOcode()
            
            departureRunwayName = ''
            departureRunwayFound = False
            
            for runwayName in runwaysDb.findAirportRunWays(airportICAOcode = departureAirportICAOcode, 
                                                           runwayLengthFeet = 11000.0):
                if not(runwaysDb.getFilteredRunWays(
                                                    airportICAOcode = departureAirportICAOcode, 
                                                    runwayName = runwayName) is None):
                    departureRunwayName  = runwayName
                    departureRunwayFound = True
                    break
                
            if departureRunwayFound:
                
                for arrivalAirport in airportsDb.getAirportsFromCountry(Country = arrivalCountry):
                    
                    arrivalRunwayName = ''
                    arrivalRunwayFound = False
                    arrivalAirportICAOcode =  arrivalAirport.getICAOcode()
                    for runwayName in runwaysDb.findAirportRunWays(airportICAOcode = arrivalAirportICAOcode, 
                                                               runwayLengthFeet = 11000.0):
                        if not(runwaysDb.getFilteredRunWays(
                                                        airportICAOcode = arrivalAirportICAOcode, 
                                                        runwayName = runwayName) is None):
                            arrivalRunwayName = runwayName
                            arrivalRunwayFound = True
                            break
                    ''' we have a pair of airports '''
                    
                    if departureRunwayFound and arrivalRunwayFound:
                        distanceMeters = departureAirport.getDistanceMetersTo(arrivalAirport)
                        if  distanceMeters > 300000.0:
                            print ' ========== Airports Direct Route testing ======= '
                            print '{0} - {1} - distance  = {2} meters'.format(departureAirport.getName(), arrivalAirport.getName(), distanceMeters)
                
                            print departureAirport
                            print arrivalAirport
                            routeFinder = RouteFinder()
                            if routeFinder.isConnected():    
                                RFL = 'FL390'
                        
                                if routeFinder.findRoute(departureAirport.getICAOcode(), arrivalAirport.getICAOcode(), RFL):
                                    routeList = routeFinder.getRouteAsList()
                                    print routeList
                                    routeFinder.insertWayPointsInDatabase(wayPointsDb)
                
                                    strRoute = 'ADEP/' + departureAirport.getICAOcode() + '/' + departureRunwayName + '-'
                                    for fix in routeList:    
                                        strRoute += fix['Name'] + '-'
                                    strRoute += 'ADES/' + arrivalAirport.getICAOcode() + '/' + arrivalRunwayName
                                    
                                    print strRoute
                                    
                                    flightPath = FlightPath(route = strRoute, 
                                                                aircraftICAOcode = 'B744',
                                                                RequestedFlightLevel = 390, 
                                                                cruiseMach = 0.92, 
                                                                takeOffMassKilograms = 280000.0)
        
                                
                                    print "=========== Flight Plan compute  =========== " 
                      
                                    t0 = time.clock()
                                    print 'time zero= ' + str(t0)
                                    lengthNauticalMiles = flightPath.computeLengthNauticalMiles()
                                    print 'flight path length= {0:.2f} nautics '.format(lengthNauticalMiles)
                                    flightPath.computeFlight(deltaTimeSeconds = 1.0)
                                    print 'simulation duration= ' + str(time.clock()-t0) + ' seconds'
                                    print "=========== Flight Plan create output files  =========== "
                                    flightPath.createFlightOutputFiles()