1
0
Fork 0

A first stab at limiting the noaa.gov query to only valid stations. There

are many recognized limitations and inefficiencies with this entire approach,
however, it's a quick and dirty way to get something working, where before
we didn't.
This commit is contained in:
curt 2004-02-23 18:25:29 +00:00
parent 86345b961e
commit 31e563c2a4
3 changed files with 46 additions and 14 deletions

View file

@ -54,35 +54,65 @@ operator >> ( istream& in, FGAirport& a )
in.getline( name, 256 ); in.getline( name, 256 );
a.name = name; a.name = name;
// a.has_metar = true; // assume true a.has_metar = false;
// only airports with four-letter codes can have metar stations
#if 0
// As a quick seed for the has_metar value, only airports with
// four-letter codes can have metar stations
a.has_metar = (isalpha(a.id[0]) && isalpha(a.id[1]) && isalpha(a.id[2]) a.has_metar = (isalpha(a.id[0]) && isalpha(a.id[1]) && isalpha(a.id[2])
&& isalpha(a.id[3]) && !a.id[4]); && isalpha(a.id[3]) && !a.id[4]);
#endif
return in; return in;
} }
FGAirportList::FGAirportList( const string& file ) { FGAirportList::FGAirportList( const string &airport_file,
SG_LOG( SG_GENERAL, SG_DEBUG, "Reading simple airport list: " << file ); const string &metar_file ) {
SG_LOG( SG_GENERAL, SG_INFO, "Reading simple airport list: "
<< airport_file );
// open the specified file for reading // open the specified file for reading
sg_gzifstream in( file ); sg_gzifstream apt_in( airport_file );
if ( !in.is_open() ) { if ( !apt_in.is_open() ) {
SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << file ); SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << airport_file );
exit(-1); exit(-1);
} }
// skip header line // skip header line
in >> skipeol; apt_in >> skipeol;
FGAirport a; FGAirport a;
int size = 0; while ( apt_in ) {
while ( in ) { apt_in >> a;
in >> a;
airports_by_id[a.id] = a; airports_by_id[a.id] = a;
airports_array.push_back( &airports_by_id[a.id] ); airports_array.push_back( &airports_by_id[a.id] );
size++; }
SG_LOG( SG_GENERAL, SG_INFO, "Reading simple metar station list: "
<< metar_file );
// open the specified file for reading
sg_gzifstream metar_in( metar_file );
if ( !metar_in.is_open() ) {
SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << metar_file );
}
string ident;
while ( metar_in ) {
metar_in >> ident;
if ( ident == "#" || ident == "//" ) {
metar_in >> skipeol;
} else {
airport_map_iterator apt = airports_by_id.find( ident );
if ( apt == airports_by_id.end() ) {
SG_LOG( SG_GENERAL, SG_DEBUG, "no apt = " << ident );
} else {
SG_LOG( SG_GENERAL, SG_DEBUG, "metar = " << ident );
airports_by_id[ident].has_metar = true;
}
}
} }
} }

View file

@ -75,7 +75,7 @@ private:
public: public:
// Constructor // Constructor
FGAirportList( const string& file ); FGAirportList( const string &airport_file, const string &metar_file );
// Destructor // Destructor
~FGAirportList(); ~FGAirportList();

View file

@ -1009,7 +1009,9 @@ fgInitNav ()
SG_LOG(SG_GENERAL, SG_INFO, "Loading Simple Airport List"); SG_LOG(SG_GENERAL, SG_INFO, "Loading Simple Airport List");
SGPath p_simple( globals->get_fg_root() ); SGPath p_simple( globals->get_fg_root() );
p_simple.append( "Airports/basic.dat" ); p_simple.append( "Airports/basic.dat" );
FGAirportList *airports = new FGAirportList( p_simple.str() ); SGPath p_metar( globals->get_fg_root() );
p_metar.append( "Airports/metar.dat" );
FGAirportList *airports = new FGAirportList(p_simple.str(), p_metar.str());
globals->set_airports( airports ); globals->set_airports( airports );
SG_LOG(SG_GENERAL, SG_INFO, "Loading Runway List"); SG_LOG(SG_GENERAL, SG_INFO, "Loading Runway List");