//
// simple.cxx -- a really simplistic class to manage airport ID,
-// lat, lon of the center of one of it's runways, and
+// lat, lon of the center of one of it's runways, and
// elevation in feet.
//
// Written by Curtis Olson, started April 1998.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
# include <config.h>
#endif
-#ifdef _MSC_VER
-# define _USE_MATH_DEFINES
-#endif
-#include <math.h>
-#include <algorithm>
-
-#include <simgear/compiler.h>
-
-#include <plib/sg.h>
+#include "simple.hxx"
-#include <Environment/environment_mgr.hxx>
-#include <Environment/environment.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/props/props.hxx>
-#include <simgear/structure/subsystem_mgr.hxx>
+#include <simgear/props/props_io.hxx>
#include <simgear/debug/logstream.hxx>
-#include <Main/globals.hxx>
+#include <simgear/sg_inlines.h>
+
+#include <Environment/environment_mgr.hxx>
+#include <Environment/environment.hxx>
#include <Main/fg_props.hxx>
#include <Airports/runways.hxx>
+#include <Airports/pavement.hxx>
+#include <Airports/dynamics.hxx>
+#include <Airports/xmlloader.hxx>
-#include STL_STRING
-
-#include "simple.hxx"
-
-SG_USING_STD(sort);
-
-/******************************************************************************
- * ScheduleTime
- ***************e*************************************************************/
-void ScheduleTime::clear()
-{
- start.clear();
- end.clear();
- scheduleNames.clear();
-}
+// magic import of a helper which uses FGPositioned internals
+extern char** searchAirportNamesAndIdents(const std::string& aFilter);
+/***************************************************************************
+ * FGAirport
+ ***************************************************************************/
-ScheduleTime::ScheduleTime(const ScheduleTime &other)
+FGAirport::FGAirport(const string &id, const SGGeod& location, const SGGeod& tower_location,
+ const string &name, bool has_metar, Type aType) :
+ FGPositioned(aType, id, location),
+ _tower_location(tower_location),
+ _name(name),
+ _has_metar(has_metar),
+ _dynamics(0),
+ mRunwaysLoaded(false),
+ mTaxiwaysLoaded(true)
{
- //timeVec start;
- timeVecConstIterator i;
- for (i = other.start.begin(); i != other.start.end(); i++)
- start.push_back(*i);
- for (i = other.end.begin(); i != other.end.end(); i++)
- end.push_back(*i);
- stringVecConstIterator k;
- for (k = other.scheduleNames.begin(); k != other.scheduleNames.end(); k++)
- scheduleNames.push_back(*k);
-
- //timeVec end;
- //stringVec scheduleNames;
- tailWind = other.tailWind;
- crssWind = other.tailWind;
}
-ScheduleTime & ScheduleTime::operator= (const ScheduleTime &other)
+FGAirport::~FGAirport()
{
- //timeVec start;
- clear();
- timeVecConstIterator i;
- for (i = other.start.begin(); i != other.start.end(); i++)
- start.push_back(*i);
- for (i = other.end.begin(); i != other.end.end(); i++)
- end.push_back(*i);
- stringVecConstIterator k;
- for (k = other.scheduleNames.begin(); k != other.scheduleNames.end(); k++)
- scheduleNames.push_back(*k);
-
- //timeVec end;
- //stringVec scheduleNames;
- tailWind = other.tailWind;
- crssWind = other.tailWind;
- return *this;
+ delete _dynamics;
}
-string ScheduleTime::getName(time_t dayStart)
-{
- if ((start.size() != end.size()) || (start.size() != scheduleNames.size()))
- {
- cerr << "Unable to parse schedule times" << endl;
- exit(1);
- }
- else
- {
- int nrItems = start.size();
- //cerr << "Nr of items to process: " << nrItems << endl;
- if (nrItems > 0)
- {
- for (unsigned int i = 0; i < start.size(); i++)
- {
- //cerr << i << endl;
- if ((dayStart >= start[i]) && (dayStart <= end[i]))
- return scheduleNames[i];
- }
- }
- //couldn't find one so return 0;
- //cerr << "Returning 0 " << endl;
- return string(0);
- }
-}
-/******************************************************************************
- * RunwayList
- *****************************************************************************/
-RunwayList::RunwayList(const RunwayList &other)
+bool FGAirport::isAirport() const
{
- type = other.type;
- stringVecConstIterator i;
- for (i = other.preferredRunways.begin(); i != other.preferredRunways.end(); i++)
- preferredRunways.push_back(*i);
-}
-RunwayList& RunwayList::operator= (const RunwayList &other)
-{
- type = other.type;
- preferredRunways.clear();
- stringVecConstIterator i;
- for (i = other.preferredRunways.begin(); i != other.preferredRunways.end(); i++)
- preferredRunways.push_back(*i);
- return *this;
-}
-void RunwayList::set(string tp, string lst)
-{
- //weekday = atoi(timeCopy.substr(0,1).c_str());
- // timeOffsetInDays = weekday - currTimeDate->getGmt()->tm_wday;
- // timeCopy = timeCopy.substr(2,timeCopy.length());
- type = tp;
- string rwys = lst;
- string rwy;
- while (rwys.find(",") != string::npos)
- {
- rwy = rwys.substr(0, rwys.find(",",0));
- //cerr << "adding runway [" << rwy << "] to the list " << endl;
- preferredRunways.push_back(rwy);
- rwys.erase(0, rwys.find(",",0)+1); // erase until after the first whitspace
- while (rwys[0] == ' ')
- rwys.erase(0, 1); // Erase any leading whitespaces.
- //cerr << "Remaining runway list " << rwys;
- }
- preferredRunways.push_back(rwys);
- //exit(1);
+ return type() == AIRPORT;
}
-void RunwayList::clear()
+bool FGAirport::isSeaport() const
{
- type = "";
- preferredRunways.clear();
+ return type() == SEAPORT;
}
-/****************************************************************************
- *
- ***************************************************************************/
-RunwayGroup::RunwayGroup(const RunwayGroup &other)
+bool FGAirport::isHeliport() const
{
- name = other.name;
- RunwayListVecConstIterator i;
- for (i = other.rwyList.begin(); i != other.rwyList.end(); i++)
- rwyList.push_back(*i);
- choice[0] = other.choice[0];
- choice[1] = other.choice[1];
- nrActive = other.nrActive;
-}
-RunwayGroup& RunwayGroup:: operator= (const RunwayGroup &other)
-{
- rwyList.clear();
- name = other.name;
- RunwayListVecConstIterator i;
- for (i = other.rwyList.begin(); i != other.rwyList.end(); i++)
- rwyList.push_back(*i);
- choice[0] = other.choice[0];
- choice[1] = other.choice[1];
- nrActive = other.nrActive;
- return *this;
+ return type() == HELIPORT;
}
-void RunwayGroup::setActive(string aptId,
- double windSpeed,
- double windHeading,
- double maxTail,
- double maxCross)
+FGAirportDynamics * FGAirport::getDynamics()
{
+ if (_dynamics != 0) {
+ return _dynamics;
+ } else {
+ //cerr << "Trying to load dynamics for " << _id << endl;
+ _dynamics = new FGAirportDynamics(this);
+ XMLLoader::load(_dynamics);
- FGRunway rwy;
- int activeRwys = rwyList.size(); // get the number of runways active
- int nrOfPreferences;
- // bool found = true;
- // double heading;
- double hdgDiff;
- double crossWind;
- double tailWind;
- string name;
-
- if (activeRwys > 0)
- {
- nrOfPreferences = rwyList[0].getRwyList()->size();
- for (int i = 0; i < nrOfPreferences; i++)
- {
- bool validSelection = true;
- for (int j = 0; j < activeRwys; j++)
- {
- //cerr << "I J " << i << " " << j << endl;
- name = rwyList[j].getRwyList(i);
- //cerr << "Name of Runway: " << name << endl;
- if (globals->get_runways()->search( aptId,
- name,
- &rwy))
- {
- //cerr << "Succes" << endl;
- hdgDiff = fabs(windHeading - rwy._heading);
- //cerr << "Wind Heading: " << windHeading << "Runway Heading: " <<rwy._heading << endl;
- //cerr << "Wind Speed : " << windSpeed << endl;
- if (hdgDiff > 180)
- hdgDiff = 360 - hdgDiff;
- //cerr << "Heading diff: " << hdgDiff << endl;
- hdgDiff *= ((2*M_PI)/360.0); // convert to radians
- crossWind = windSpeed * sin(hdgDiff);
- tailWind = -windSpeed * cos(hdgDiff);
- //cerr << "Tailwind : " << tailWind << endl;
- //cerr << "Crosswnd : " << crossWind << endl;
- if ((tailWind > maxTail) || (crossWind > maxCross))
- validSelection = false;
- }else {
- cerr << "Failed to find runway " << name << " at " << aptId << endl;
- exit(1);
- }
-
- }
- if (validSelection)
- {
- //cerr << "Valid runay selection : " << i << endl;
- nrActive = activeRwys;
- active = i;
- return;
- }
- }
- // If this didn't work, due to heavy winds, try again
- // but select only one landing and one takeoff runway.
- choice[0] = 0;
- choice[1] = 0;
- for (int i = activeRwys-1; i; i--)
- {
- if (rwyList[i].getType() == string("landing"))
- choice[0] = i;
- if (rwyList[i].getType() == string("takeoff"))
- choice[1] = i;
- }
- //cerr << "Choosing " << choice[0] << " for landing and " << choice[1] << "for takeoff" << endl;
- nrOfPreferences = rwyList[0].getRwyList()->size();
- for (int i = 0; i < nrOfPreferences; i++)
- {
- bool validSelection = true;
- for (int j = 0; j < 2; j++)
- {
- //cerr << "I J " << i << " " << j << endl;
- name = rwyList[choice[j]].getRwyList(i);
- //cerr << "Name of Runway: " << name << endl;
- if (globals->get_runways()->search( aptId,
- name,
- &rwy))
- {
- //cerr << "Succes" << endl;
- hdgDiff = fabs(windHeading - rwy._heading);
- //cerr << "Wind Heading: " << windHeading << "Runway Heading: " <<rwy._heading << endl;
- //cerr << "Wind Speed : " << windSpeed << endl;
- if (hdgDiff > 180)
- hdgDiff = 360 - hdgDiff;
- //cerr << "Heading diff: " << hdgDiff << endl;
- hdgDiff *= ((2*M_PI)/360.0); // convert to radians
- crossWind = windSpeed * sin(hdgDiff);
- tailWind = -windSpeed * cos(hdgDiff);
- //cerr << "Tailwind : " << tailWind << endl;
- //cerr << "Crosswnd : " << crossWind << endl;
- if ((tailWind > maxTail) || (crossWind > maxCross))
- validSelection = false;
- }else {
- cerr << "Failed to find runway " << name << " at " << aptId << endl;
- exit(1);
- }
-
- }
- if (validSelection)
- {
- //cerr << "Valid runay selection : " << i << endl;
- active = i;
- nrActive = 2;
- return;
- }
- }
- }
- active = -1;
- //RunwayListVectorIterator i; // = rwlist.begin();
- //stringVecIterator j;
- //for (i = rwyList.begin(); i != rwyList.end(); i++)
- // {
- // cerr << i->getType();
- // for (j = i->getRwyList()->begin(); j != i->getRwyList()->end(); j++)
- // {
- // cerr << (*j);
- // }
- // cerr << endl;
- // }
- //for (int
+ FGRunwayPreference rwyPrefs(this);
+ XMLLoader::load(&rwyPrefs);
+ _dynamics->setRwyUse(rwyPrefs);
+ //FGSidStar SIDs(this);
+ XMLLoader::load(_dynamics->getSIDs());
+ }
+ return _dynamics;
}
-void RunwayGroup::getActive(int i, string *name, string *type)
-{
- if (i == -1)
- {
- return;
- }
- if (nrActive == (int)rwyList.size())
- {
- *name = rwyList[i].getRwyList(active);
- *type = rwyList[i].getType();
- }
- else
- {
- *name = rwyList[choice[i]].getRwyList(active);
- *type = rwyList[choice[i]].getType();
- }
-}
-/*****************************************************************************
- * FGRunway preference
- ****************************************************************************/
-FGRunwayPreference::FGRunwayPreference()
+unsigned int FGAirport::numRunways() const
{
- //cerr << "Running default Constructor" << endl;
- initialized = false;
+ loadRunways();
+ return mRunways.size();
}
-FGRunwayPreference::FGRunwayPreference(const FGRunwayPreference &other)
-{
- initialized = other.initialized;
- value = other.value;
- scheduleName = other.scheduleName;
-
- comTimes = other.comTimes; // Commercial Traffic;
- genTimes = other.genTimes; // General Aviation;
- milTimes = other.milTimes; // Military Traffic;
- currTimes= other.currTimes; // Needed for parsing;
-
- rwyList = other.rwyList;
- rwyGroup = other.rwyGroup;
- PreferenceListConstIterator i;
- for (i = other.preferences.begin(); i != other.preferences.end(); i++)
- preferences.push_back(*i);
-}
-
-FGRunwayPreference & FGRunwayPreference::operator= (const FGRunwayPreference &other)
+FGRunway* FGAirport::getRunwayByIndex(unsigned int aIndex) const
{
- initialized = other.initialized;
- value = other.value;
- scheduleName = other.scheduleName;
+ loadRunways();
- comTimes = other.comTimes; // Commercial Traffic;
- genTimes = other.genTimes; // General Aviation;
- milTimes = other.milTimes; // Military Traffic;
- currTimes= other.currTimes; // Needed for parsing;
-
- rwyList = other.rwyList;
- rwyGroup = other.rwyGroup;
- PreferenceListConstIterator i;
- preferences.clear();
- for (i = other.preferences.begin(); i != other.preferences.end(); i++)
- preferences.push_back(*i);
- return *this;
+ assert(aIndex >= 0 && aIndex < mRunways.size());
+ return mRunways[aIndex];
}
-ScheduleTime *FGRunwayPreference::getSchedule(const char *trafficType)
+bool FGAirport::hasRunwayWithIdent(const string& aIdent) const
{
- if (!(strcmp(trafficType, "com"))) {
- return &comTimes;
- }
- if (!(strcmp(trafficType, "gen"))) {
- return &genTimes;
- }
- if (!(strcmp(trafficType, "mil"))) {
- return &milTimes;
- }
- return 0;
+ return (getIteratorForRunwayIdent(aIdent) != mRunways.end());
}
-RunwayGroup *FGRunwayPreference::getGroup(const string groupName)
+FGRunway* FGAirport::getRunwayByIdent(const string& aIdent) const
{
- PreferenceListIterator i = preferences.begin();
- if (preferences.begin() == preferences.end())
- return 0;
- while (!(i == preferences.end() || i->getName() == groupName))
- i++;
- if (i != preferences.end())
- return &(*i);
- else
- return 0;
-}
-
-void FGRunwayPreference::startXML () {
- // cout << "Start XML" << endl;
-}
-
-void FGRunwayPreference::endXML () {
- cout << "End XML" << endl;
+ Runway_iterator it = getIteratorForRunwayIdent(aIdent);
+ if (it == mRunways.end()) {
+ SG_LOG(SG_GENERAL, SG_ALERT, "no such runway '" << aIdent << "' at airport " << ident());
+ throw sg_range_exception("unknown runway " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
+ }
+
+ return *it;
}
-void FGRunwayPreference::startElement (const char * name, const XMLAttributes &atts) {
- //cout << "StartElement " << name << endl;
- value = string("");
- if (!(strcmp(name, "wind"))) {
- //cerr << "Will be processing Wind" << endl;
- for (int i = 0; i < atts.size(); i++)
- {
- //cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl;
- //attname = atts.getName(i);
- if (atts.getName(i) == string("tail")) {
- //cerr << "Tail Wind = " << atts.getValue(i) << endl;
- currTimes.setTailWind(atof(atts.getValue(i)));
- }
- if (atts.getName(i) == string("cross")) {
- //cerr << "Cross Wind = " << atts.getValue(i) << endl;
- currTimes.setCrossWind(atof(atts.getValue(i)));
- }
- }
- }
- if (!(strcmp(name, "time"))) {
- //cerr << "Will be processing time" << endl;
- for (int i = 0; i < atts.size(); i++)
- {
- if (atts.getName(i) == string("start")) {
- //cerr << "Start Time = " << atts.getValue(i) << endl;
- currTimes.addStartTime(processTime(atts.getValue(i)));
- }
- if (atts.getName(i) == string("end")) {
- //cerr << "End time = " << atts.getValue(i) << endl;
- currTimes.addEndTime(processTime(atts.getValue(i)));
- }
- if (atts.getName(i) == string("schedule")) {
- //cerr << "Schedule Name = " << atts.getValue(i) << endl;
- currTimes.addScheduleName(atts.getValue(i));
- }
- }
- }
- if (!(strcmp(name, "takeoff"))) {
- rwyList.clear();
+FGAirport::Runway_iterator
+FGAirport::getIteratorForRunwayIdent(const string& aIdent) const
+{
+ loadRunways();
+
+ string ident(aIdent);
+ if ((aIdent.size() == 1) || !isdigit(aIdent[1])) {
+ ident = "0" + aIdent;
}
- if (!(strcmp(name, "landing")))
- {
- rwyList.clear();
+
+ Runway_iterator it = mRunways.begin();
+ for (; it != mRunways.end(); ++it) {
+ if ((*it)->ident() == ident) {
+ return it;
}
- if (!(strcmp(name, "schedule"))) {
- for (int i = 0; i < atts.size(); i++)
- {
- //cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl;
- //attname = atts.getName(i);
- if (atts.getName(i) == string("name")) {
- //cerr << "Schedule name = " << atts.getValue(i) << endl;
- scheduleName = atts.getValue(i);
- }
- }
}
-}
-//based on a string containing hour and minute, return nr seconds since day start.
-time_t FGRunwayPreference::processTime(string tme)
-{
- string hour = tme.substr(0, tme.find(":",0));
- string minute = tme.substr(tme.find(":",0)+1, tme.length());
-
- //cerr << "hour = " << hour << " Minute = " << minute << endl;
- return (atoi(hour.c_str()) * 3600 + atoi(minute.c_str()) * 60);
+ return it; // end()
}
-void FGRunwayPreference::endElement (const char * name) {
- //cout << "End element " << name << endl;
- if (!(strcmp(name, "rwyuse"))) {
- initialized = true;
- }
- if (!(strcmp(name, "com"))) { // Commercial Traffic
- //cerr << "Setting time table for commerical traffic" << endl;
- comTimes = currTimes;
- currTimes.clear();
- }
- if (!(strcmp(name, "gen"))) { // General Aviation
- //cerr << "Setting time table for general aviation" << endl;
- genTimes = currTimes;
- currTimes.clear();
- }
- if (!(strcmp(name, "mil"))) { // Military Traffic
- //cerr << "Setting time table for military traffic" << endl;
- genTimes = currTimes;
- currTimes.clear();
- }
-
- if (!(strcmp(name, "takeoff"))) {
- //cerr << "Adding takeoff: " << value << endl;
- rwyList.set(name, value);
- rwyGroup.add(rwyList);
- }
- if (!(strcmp(name, "landing"))) {
- //cerr << "Adding landing: " << value << endl;
- rwyList.set(name, value);
- rwyGroup.add(rwyList);
- }
- if (!(strcmp(name, "schedule"))) {
- //cerr << "Adding schedule" << scheduleName << endl;
- rwyGroup.setName(scheduleName);
- //rwyGroup.addRunways(rwyList);
- preferences.push_back(rwyGroup);
- rwyGroup.clear();
- //exit(1);
+FGRunway* FGAirport::findBestRunwayForHeading(double aHeading) const
+{
+ loadRunways();
+
+ Runway_iterator it = mRunways.begin();
+ FGRunway* result = NULL;
+ double currentBestQuality = 0.0;
+
+ SGPropertyNode *param = fgGetNode("/sim/airport/runways/search", true);
+ double lengthWeight = param->getDoubleValue("length-weight", 0.01);
+ double widthWeight = param->getDoubleValue("width-weight", 0.01);
+ double surfaceWeight = param->getDoubleValue("surface-weight", 10);
+ double deviationWeight = param->getDoubleValue("deviation-weight", 1);
+
+ for (; it != mRunways.end(); ++it) {
+ double good = (*it)->score(lengthWeight, widthWeight, surfaceWeight);
+
+ double dev = aHeading - (*it)->headingDeg();
+ SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
+ double bad = fabs(deviationWeight * dev) + 1e-20;
+ double quality = good / bad;
+
+ if (quality > currentBestQuality) {
+ currentBestQuality = quality;
+ result = *it;
+ }
}
-}
-void FGRunwayPreference::data (const char * s, int len) {
- string token = string(s,len);
- //cout << "Character data " << string(s,len) << endl;
- //if ((token.find(" ") == string::npos && (token.find('\n')) == string::npos))
- // value += token;
- //else
- // value = string("");
- value += token;
+ return result;
}
-void FGRunwayPreference::pi (const char * target, const char * data) {
- //cout << "Processing instruction " << target << ' ' << data << endl;
-}
+bool FGAirport::hasHardRunwayOfLengthFt(double aLengthFt) const
+{
+ loadRunways();
+
+ unsigned int numRunways(mRunways.size());
+ for (unsigned int r=0; r<numRunways; ++r) {
+ FGRunway* rwy = mRunways[r];
+ if (rwy->isReciprocal()) {
+ continue; // we only care about lengths, so don't do work twice
+ }
-void FGRunwayPreference::warning (const char * message, int line, int column) {
- cout << "Warning: " << message << " (" << line << ',' << column << ')'
- << endl;
-}
+ if (rwy->isHardSurface() && (rwy->lengthFt() >= aLengthFt)) {
+ return true; // we're done!
+ }
+ } // of runways iteration
-void FGRunwayPreference::error (const char * message, int line, int column) {
- cout << "Error: " << message << " (" << line << ',' << column << ')'
- << endl;
+ return false;
}
-/*********************************************************************************
- * FGParking
- ********************************************************************************/
-FGParking::FGParking(double lat,
- double lon,
- double hdg,
- double rad,
- int idx,
- string name,
- string tpe,
- string codes)
+unsigned int FGAirport::numTaxiways() const
{
- latitude = lat;
- longitude = lon;
- heading = hdg;
- parkingName = name;
- index = idx;
- type = tpe;
- airlineCodes = codes;
+ loadTaxiways();
+ return mTaxiways.size();
}
-double FGParking::processPosition(string pos)
+FGTaxiway* FGAirport::getTaxiwayByIndex(unsigned int aIndex) const
{
- string prefix;
- string subs;
- string degree;
- string decimal;
- int sign = 1;
- double value;
- subs = pos;
- prefix= subs.substr(0,1);
- if (prefix == string("S") || (prefix == string("W")))
- sign = -1;
- subs = subs.substr(1, subs.length());
- degree = subs.substr(0, subs.find(" ",0));
- decimal = subs.substr(subs.find(" ",0), subs.length());
-
-
- //cerr << sign << " "<< degree << " " << decimal << endl;
- value = sign * (atof(degree.c_str()) + atof(decimal.c_str())/60.0);
- //cerr << value <<endl;
- //exit(1);
- return value;
+ loadTaxiways();
+ assert(aIndex >= 0 && aIndex < mTaxiways.size());
+ return mTaxiways[aIndex];
}
-/***************************************************************************
- * FGAirport
- ***************************************************************************/
-FGAirport::FGAirport() : _longitude(0), _latitude(0), _elevation(0)
+unsigned int FGAirport::numPavements() const
{
- lastUpdate = 0;
- for (int i = 0; i < 10; i++)
- {
- avWindHeading [i] = 0;
- avWindSpeed [i] = 0;
- }
+ loadTaxiways();
+ return mPavements.size();
}
-FGAirport::FGAirport(const FGAirport& other)
+FGPavement* FGAirport::getPavementByIndex(unsigned int aIndex) const
{
- _id = other._id;
- _longitude = other._longitude;
- _latitude = other._latitude;
- _elevation = other._elevation;
- _name = other._name;
- _has_metar = other._has_metar;
- for (FGParkingVecConstIterator ip= other.parkings.begin(); ip != other.parkings.end(); ip++)
- parkings.push_back(*(ip));
- rwyPrefs = other.rwyPrefs;
- lastUpdate = other.lastUpdate;
-
- stringVecConstIterator il;
- for (il = other.landing.begin(); il != other.landing.end(); il++)
- landing.push_back(*il);
- for (il = other.takeoff.begin(); il != other.takeoff.end(); il++)
- takeoff.push_back(*il);
- lastUpdate = other.lastUpdate;
- for (int i = 0; i < 10; i++)
- {
- avWindHeading [i] = other.avWindHeading[i];
- avWindSpeed [i] = other.avWindSpeed [i];
- }
+ loadTaxiways();
+ assert(aIndex >= 0 && aIndex < mPavements.size());
+ return mPavements[aIndex];
}
-FGAirport::FGAirport(string id, double lon, double lat, double elev, string name, bool has_metar)
+void FGAirport::setRunwaysAndTaxiways(vector<FGRunwayPtr>& rwys,
+ vector<FGTaxiwayPtr>& txwys,
+ vector<FGPavementPtr>& pvts)
{
- _id = id;
- _longitude = lon;
- _latitude = lat;
- _elevation = elev;
- _name = name;
- _has_metar = has_metar;
- lastUpdate = 0;
- for (int i = 0; i < 10; i++)
- {
- avWindHeading [i] = 0;
- avWindSpeed [i] = 0;
- }
-
+ mRunways.swap(rwys);
+ Runway_iterator it = mRunways.begin();
+ for (; it != mRunways.end(); ++it) {
+ (*it)->setAirport(this);
+ }
+
+ mTaxiways.swap(txwys);
+ mPavements.swap(pvts);
}
-bool FGAirport::getAvailableParking(double *lat, double *lon, double *heading, int *gateId, double rad, string flType, string acType, string airline)
+FGRunway* FGAirport::getActiveRunwayForUsage() const
{
- bool found = false;
- bool available = false;
- //string gateType;
-
- FGParkingVecIterator i;
-// if (flType == "cargo")
-// {
-// gateType = "RAMP_CARGO";
-// }
-// else if (flType == "ga")
-// {
-// gateType = "RAMP_GA";
-// }
-// else gateType = "GATE";
+ static FGEnvironmentMgr* envMgr = NULL;
+ if (!envMgr) {
+ envMgr = (FGEnvironmentMgr *) globals->get_subsystem("environment");
+ }
- if (parkings.begin() == parkings.end())
- {
- //cerr << "Could not find parking spot at " << _id << endl;
- *lat = _latitude;
- *lon = _longitude;
- *heading = 0;
- found = true;
- }
- else
- {
- // First try finding a parking with a designated airline code
- for (i = parkings.begin(); !(i == parkings.end() || found); i++)
- {
- //cerr << "Gate Id: " << i->getIndex()
- // << " Type : " << i->getType()
- // << " Codes : " << i->getCodes()
- // << " Radius: " << i->getRadius()
- // << " Name : " << i->getName()
- // << " Available: " << i->isAvailable() << endl;
- available = true;
- // Taken by another aircraft
- if (!(i->isAvailable()))
- {
- available = false;
- continue;
- }
- // No airline codes, so skip
- if (i->getCodes().empty())
- {
- available = false;
- continue;
- }
- else // Airline code doesn't match
- if (i->getCodes().find(airline, 0) == string::npos)
- {
- available = false;
- continue;
- }
- // Type doesn't match
- if (i->getType() != flType)
- {
- available = false;
- continue;
- }
- // too small
- if (i->getRadius() < rad)
- {
- available = false;
- continue;
- }
-
- if (available)
- {
- *lat = i->getLatitude ();
- *lon = i->getLongitude();
- *heading = i->getHeading ();
- *gateId = i->getIndex ();
- i->setAvailable(false);
- found = true;
- }
- }
- // then try again for those without codes.
- for (i = parkings.begin(); !(i == parkings.end() || found); i++)
- {
- available = true;
- if (!(i->isAvailable()))
- {
- available = false;
- continue;
- }
- if (!(i->getCodes().empty()))
- {
- if ((i->getCodes().find(airline,0) == string::npos))
- {
- available = false;
- continue;
- }
- }
- if (i->getType() != flType)
- {
- available = false;
- continue;
- }
-
- if (i->getRadius() < rad)
- {
- available = false;
- continue;
- }
-
- if (available)
- {
- *lat = i->getLatitude ();
- *lon = i->getLongitude();
- *heading = i->getHeading ();
- *gateId = i->getIndex ();
- i->setAvailable(false);
- found = true;
- }
- }
- // And finally once more if that didn't work. Now ignore the airline codes, as a last resort
- for (i = parkings.begin(); !(i == parkings.end() || found); i++)
- {
- available = true;
- if (!(i->isAvailable()))
- {
- available = false;
- continue;
- }
- if (i->getType() != flType)
- {
- available = false;
- continue;
- }
-
- if (i->getRadius() < rad)
- {
- available = false;
- continue;
- }
-
- if (available)
- {
- *lat = i->getLatitude ();
- *lon = i->getLongitude();
- *heading = i->getHeading ();
- *gateId = i->getIndex ();
- i->setAvailable(false);
- found = true;
- }
- }
- }
- if (!found)
- {
- //cerr << "Traffic overflow at" << _id
- // << ". flType = " << flType
- // << ". airline = " << airline
- // << " Radius = " <<rad
- // << endl;
- *lat = _latitude;
- *lon = _longitude;
- *heading = 0;
- *gateId = -1;
- //exit(1);
+ // This forces West-facing rwys to be used in no-wind situations
+ // which is consistent with Flightgear's initial setup.
+ double hdg = 270;
+
+ if (envMgr) {
+ FGEnvironment stationWeather(envMgr->getEnvironment(mPosition));
+
+ double windSpeed = stationWeather.get_wind_speed_kt();
+ if (windSpeed > 0.0) {
+ hdg = stationWeather.get_wind_from_heading_deg();
}
- return found;
+ }
+
+ return findBestRunwayForHeading(hdg);
}
-void FGAirport::getParking (int id, double *lat, double* lon, double *heading)
+FGAirport* FGAirport::findClosest(const SGGeod& aPos, double aCuttofNm, Filter* filter)
{
- if (id < 0)
- {
- *lat = _latitude;
- *lon = _longitude;
- *heading = 0;
- }
- else
- {
- FGParkingVecIterator i = parkings.begin();
- for (i = parkings.begin(); i != parkings.end(); i++)
- {
- if (id == i->getIndex())
- {
- *lat = i->getLatitude();
- *lon = i->getLongitude();
- *heading = i->getLongitude();
- }
- }
- }
-}
-
-FGParking *FGAirport::getParking(int i)
-{
- if (i < (int)parkings.size())
- return &(parkings[i]);
- else
- return 0;
-}
-string FGAirport::getParkingName(int i)
-{
- if (i < (int)parkings.size() && i >= 0)
- return (parkings[i].getName());
- else
- return string("overflow");
-}
-void FGAirport::releaseParking(int id)
-{
- if (id >= 0)
- {
-
- FGParkingVecIterator i = parkings.begin();
- for (i = parkings.begin(); i != parkings.end(); i++)
- {
- if (id == i->getIndex())
- {
- i -> setAvailable(true);
- }
- }
- }
-}
+ AirportFilter aptFilter;
+ if (filter == NULL) {
+ filter = &aptFilter;
+ }
-void FGAirport::startXML () {
- //cout << "Start XML" << endl;
-}
-
-void FGAirport::endXML () {
- //cout << "End XML" << endl;
-}
-
-void FGAirport::startElement (const char * name, const XMLAttributes &atts) {
- // const char *attval;
- FGParking park;
- //cout << "Start element " << name << endl;
- string attname;
- string value;
- string gateName;
- string gateNumber;
- string lat;
- string lon;
- if (name == string("Parking"))
- {
- for (int i = 0; i < atts.size(); i++)
- {
- //cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl;
- attname = atts.getName(i);
- if (attname == string("index"))
- park.setIndex(atoi(atts.getValue(i)));
- else if (attname == string("type"))
- park.setType(atts.getValue(i));
- else if (attname == string("name"))
- gateName = atts.getValue(i);
- else if (attname == string("number"))
- gateNumber = atts.getValue(i);
- else if (attname == string("lat"))
- park.setLatitude(atts.getValue(i));
- else if (attname == string("lon"))
- park.setLongitude(atts.getValue(i));
- else if (attname == string("heading"))
- park.setHeading(atof(atts.getValue(i)));
- else if (attname == string("radius")) {
- string radius = atts.getValue(i);
- if (radius.find("M") != string::npos)
- radius = radius.substr(0, radius.find("M",0));
- //cerr << "Radius " << radius <<endl;
- park.setRadius(atof(radius.c_str()));
- }
- else if (attname == string("airlineCodes"))
- park.setCodes(atts.getValue(i));
- }
- park.setName((gateName+gateNumber));
- parkings.push_back(park);
- }
- // sort by radius, in asending order, so that smaller gates are first in the list
- sort(parkings.begin(), parkings.end());
-}
-
-void FGAirport::endElement (const char * name) {
- //cout << "End element " << name << endl;
-
+ FGPositionedRef r = FGPositioned::findClosest(aPos, aCuttofNm, filter);
+ if (!r) {
+ return NULL;
+ }
+
+ return static_cast<FGAirport*>(r.ptr());
}
-void FGAirport::data (const char * s, int len) {
- string token = string(s,len);
- //cout << "Character data " << string(s,len) << endl;
- //if ((token.find(" ") == string::npos && (token.find('\n')) == string::npos))
- //value += token;
- //else
- //value = string("");
+FGAirport::HardSurfaceFilter::HardSurfaceFilter(double minLengthFt) :
+ mMinLengthFt(minLengthFt)
+{
}
-
-void FGAirport::pi (const char * target, const char * data) {
- //cout << "Processing instruction " << target << ' ' << data << endl;
+
+bool FGAirport::HardSurfaceFilter::passAirport(FGAirport* aApt) const
+{
+ return aApt->hasHardRunwayOfLengthFt(mMinLengthFt);
}
-void FGAirport::warning (const char * message, int line, int column) {
- cout << "Warning: " << message << " (" << line << ',' << column << ')'
- << endl;
+FGAirport* FGAirport::findByIdent(const std::string& aIdent)
+{
+ FGPositionedRef r;
+ AirportFilter filter;
+ r = FGPositioned::findNextWithPartialId(r, aIdent, &filter);
+ if (!r) {
+ return NULL; // we don't warn here, let the caller do that
+ }
+ return static_cast<FGAirport*>(r.ptr());
}
-void FGAirport::error (const char * message, int line, int column) {
- cout << "Error: " << message << " (" << line << ',' << column << ')'
- << endl;
+FGAirport* FGAirport::getByIdent(const std::string& aIdent)
+{
+ FGPositionedRef r;
+ AirportFilter filter;
+ r = FGPositioned::findNextWithPartialId(r, aIdent, &filter);
+ if (!r) {
+ throw sg_range_exception("No such airport with ident: " + aIdent);
+ }
+ return static_cast<FGAirport*>(r.ptr());
}
-void FGAirport::setRwyUse(FGRunwayPreference& ref)
+char** FGAirport::searchNamesAndIdents(const std::string& aFilter)
{
- rwyPrefs = ref;
- //cerr << "Exiting due to not implemented yet" << endl;
- //exit(1);
+ // we delegate all the work to a horrible helper in FGPositioned, which can
+ // access the (private) index data.
+ return searchAirportNamesAndIdents(aFilter);
}
-void FGAirport::getActiveRunway(string trafficType, int action, string *runway)
-{
- double windSpeed;
- double windHeading;
- double maxTail;
- double maxCross;
- string name;
- string type;
-
- if (!(rwyPrefs.available()))
- {
- chooseRunwayFallback(runway);
- return; // generic fall back goes here
- }
- else
- {
- RunwayGroup *currRunwayGroup = 0;
- int nrActiveRunways = 0;
- time_t dayStart = fgGetLong("/sim/time/utc/day-seconds");
- if (((dayStart - lastUpdate) > 600) || trafficType != prevTrafficType)
- {
- landing.clear();
- takeoff.clear();
- //lastUpdate = dayStart;
- prevTrafficType = trafficType;
- FGEnvironment
- stationweather = ((FGEnvironmentMgr *) globals->get_subsystem("environment"))
- ->getEnvironment(getLatitude(),
- getLongitude(),
- getElevation());
-
- windSpeed = stationweather.get_wind_speed_kt();
- windHeading = stationweather.get_wind_from_heading_deg();
- double averageWindSpeed = 0;
- double averageWindHeading = 0;
- double cosHeading = 0;
- double sinHeading = 0;
- // Initialize at the beginning of the next day or startup
- if ((lastUpdate == 0) || (dayStart < lastUpdate))
- {
- for (int i = 0; i < 10; i++)
- {
- avWindHeading [i] = windHeading;
- avWindSpeed [i] = windSpeed;
- }
- }
- else
- {
- if (windSpeed != avWindSpeed[9]) // update if new metar data
- {
- // shift the running average
- for (int i = 0; i < 9 ; i++)
- {
- avWindHeading[i] = avWindHeading[i+1];
- avWindSpeed [i] = avWindSpeed [i+1];
- }
- }
- avWindHeading[9] = windHeading;
- avWindSpeed [9] = windSpeed;
- }
-
- for (int i = 0; i < 10; i++)
- {
- averageWindSpeed += avWindSpeed [i];
- //averageWindHeading += avWindHeading [i];
- cosHeading += cos(avWindHeading[i] * SG_DEGREES_TO_RADIANS);
- sinHeading += sin(avWindHeading[i] * SG_DEGREES_TO_RADIANS);
- }
- averageWindSpeed /= 10;
- //averageWindHeading /= 10;
- cosHeading /= 10;
- sinHeading /= 10;
- averageWindHeading = atan2(sinHeading, cosHeading) *SG_RADIANS_TO_DEGREES;
- if (averageWindHeading < 0)
- averageWindHeading += 360.0;
- //cerr << "Wind Heading " << windHeading << " average " << averageWindHeading << endl;
- //cerr << "Wind Speed " << windSpeed << " average " << averageWindSpeed << endl;
- lastUpdate = dayStart;
- //if (wind_speed == 0) {
- // wind_heading = 270; This forces West-facing rwys to be used in no-wind situations
- // which is consistent with Flightgear's initial setup.
- //}
-
- //string rwy_no = globals->get_runways()->search(apt->getId(), int(wind_heading));
- string scheduleName;
- //cerr << "finding active Runway for" << _id << endl;
- //cerr << "Nr of seconds since day start << " << dayStart << endl;
- ScheduleTime *currSched;
- //cerr << "A"<< endl;
- currSched = rwyPrefs.getSchedule(trafficType.c_str());
- if (!(currSched))
- return;
- //cerr << "B"<< endl;
- scheduleName = currSched->getName(dayStart);
- maxTail = currSched->getTailWind ();
- maxCross = currSched->getCrossWind ();
- //cerr << "SChedule anme = " << scheduleName << endl;
- if (scheduleName.empty())
- return;
- //cerr << "C"<< endl;
- currRunwayGroup = rwyPrefs.getGroup(scheduleName);
- //cerr << "D"<< endl;
- if (!(currRunwayGroup))
- return;
- nrActiveRunways = currRunwayGroup->getNrActiveRunways();
- //cerr << "Nr of Active Runways = " << nrActiveRunways << endl;
- currRunwayGroup->setActive(_id, averageWindSpeed, averageWindHeading, maxTail, maxCross);
- nrActiveRunways = currRunwayGroup->getNrActiveRunways();
- for (int i = 0; i < nrActiveRunways; i++)
- {
- type = "unknown"; // initialize to something other than landing or takeoff
- currRunwayGroup->getActive(i, &name, &type);
- if (type == "landing")
- {
- landing.push_back(name);
- //cerr << "Landing " << name << endl;
- }
- if (type == "takeoff")
- {
- takeoff.push_back(name);
- //cerr << "takeoff " << name << endl;
- }
- }
- }
- if (action == 1) // takeoff
- {
- int nr = takeoff.size();
- if (nr)
- {
- *runway = takeoff[(rand() % nr)];
- }
- else
- { // Fallback
- chooseRunwayFallback(runway);
- }
- }
- if (action == 2) // landing
- {
- int nr = landing.size();
- if (nr)
- {
- *runway = landing[(rand() % nr)];
- }
- else
- { //fallback
- chooseRunwayFallback(runway);
- }
- }
-
- //*runway = globals->get_runways()->search(_id, int(windHeading));
- //cerr << "Seleceted runway: " << *runway << endl;
+// find basic airport location info from airport database
+const FGAirport *fgFindAirportID( const string& id)
+{
+ if ( id.empty() ) {
+ return NULL;
}
+
+ return FGAirport::findByIdent(id);
}
-void FGAirport::chooseRunwayFallback(string *runway)
-{
- FGEnvironment
- stationweather = ((FGEnvironmentMgr *) globals->get_subsystem("environment"))
- ->getEnvironment(getLatitude(),
- getLongitude(),
- getElevation());
-
- double windSpeed = stationweather.get_wind_speed_kt();
- double windHeading = stationweather.get_wind_from_heading_deg();
- if (windSpeed == 0) {
- windHeading = 270; // This forces West-facing rwys to be used in no-wind situations
- //which is consistent with Flightgear's initial setup.
+void FGAirport::loadRunways() const
+{
+ if (mRunwaysLoaded) {
+ return; // already loaded, great
}
- *runway = globals->get_runways()->search(_id, int(windHeading));
- return; // generic fall back goes here
+ mRunwaysLoaded = true;
+ loadSceneryDefintions();
}
-/******************************************************************************
- * FGAirportList
- *****************************************************************************/
-
-// Populates a list of subdirectories of $FG_ROOT/Airports/AI so that
-// the add() method doesn't have to try opening 2 XML files in each of
-// thousands of non-existent directories. FIXME: should probably add
-// code to free this list after parsing of apt.dat is finished;
-// non-issue at the moment, however, as there are no AI subdirectories
-// in the base package.
-FGAirportList::FGAirportList()
+void FGAirport::loadTaxiways() const
{
- ulDir* d;
- ulDirEnt* dent;
- SGPath aid( globals->get_fg_root() );
- aid.append( "/Airports/AI" );
- if((d = ulOpenDir(aid.c_str())) == NULL)
- return;
- while((dent = ulReadDir(d)) != NULL) {
- cerr << "Dent: " << dent->d_name; // DEBUG
- ai_dirs.insert(dent->d_name);
- }
- ulCloseDir(d);
+ if (mTaxiwaysLoaded) {
+ return; // already loaded, great
+ }
}
-
-FGAirportList::~FGAirportList( void ) {
- for(unsigned int i = 0; i < airports_array.size(); ++i) {
- delete airports_array[i];
- }
+void FGAirport::loadSceneryDefintions() const
+{
+ // allow users to disable the scenery data in the short-term
+ // longer term, this option can probably disappear
+ if (!fgGetBool("/sim/use-scenery-airport-data")) {
+ return;
+ }
+
+ SGPath path;
+ SGPropertyNode_ptr rootNode = new SGPropertyNode;
+ if (XMLLoader::findAirportData(ident(), "threshold", path)) {
+ readProperties(path.str(), rootNode);
+ const_cast<FGAirport*>(this)->readThresholdData(rootNode);
+ }
+
+ // repeat for the tower data
+ rootNode = new SGPropertyNode;
+ if (XMLLoader::findAirportData(ident(), "twr", path)) {
+ readProperties(path.str(), rootNode);
+ const_cast<FGAirport*>(this)->readTowerData(rootNode);
+ }
}
-
-// add an entry to the list
-void FGAirportList::add( const string id, const double longitude,
- const double latitude, const double elevation,
- const string name, const bool has_metar )
+void FGAirport::readThresholdData(SGPropertyNode* aRoot)
{
- FGRunwayPreference rwyPrefs;
- FGAirport* a = new FGAirport(id, longitude, latitude, elevation, name, has_metar);
- SGPath parkpath( globals->get_fg_root() );
- parkpath.append( "/Airports/AI/" );
- parkpath.append(id);
- parkpath.append("parking.xml");
+ SGPropertyNode* runway;
+ int runwayIndex = 0;
+ for (; (runway = aRoot->getChild("runway", runwayIndex)) != NULL; ++runwayIndex) {
+ SGPropertyNode* t0 = runway->getChild("threshold", 0),
+ *t1 = runway->getChild("threshold", 1);
+ assert(t0);
+ assert(t1); // too strict? mayeb we should finally allow single-ended runways
- SGPath rwyPrefPath( globals->get_fg_root() );
- rwyPrefPath.append( "/Airports/AI/" );
- rwyPrefPath.append(id);
- rwyPrefPath.append("rwyuse.xml");
- if (ai_dirs.find(id.c_str()) != ai_dirs.end()
- && parkpath.exists())
- {
- try {
- readXML(parkpath.str(),*a);
- }
- catch (const sg_exception &e) {
- //cerr << "unable to read " << parkpath.str() << endl;
- }
- }
- if (ai_dirs.find(id.c_str()) != ai_dirs.end()
- && rwyPrefPath.exists())
- {
- try {
- readXML(rwyPrefPath.str(), rwyPrefs);
- a->setRwyUse(rwyPrefs);
- }
- catch (const sg_exception &e) {
- //cerr << "unable to read " << rwyPrefPath.str() << endl;
- //exit(1);
- }
- }
-
- airports_by_id[a->getId()] = a;
- // try and read in an auxilary file
-
- airports_array.push_back( a );
- SG_LOG( SG_GENERAL, SG_BULK, "Adding " << id << " pos = " << longitude
- << ", " << latitude << " elev = " << elevation );
-}
-
-
-// search for the specified id
-FGAirport* FGAirportList::search( const string& id) {
- airport_map_iterator itr = airports_by_id.find(id);
- return(itr == airports_by_id.end() ? NULL : itr->second);
+ processThreshold(t0);
+ processThreshold(t1);
+ } // of runways iteration
}
-
-// search for first subsequent alphabetically to supplied id
-const FGAirport* FGAirportList::findFirstById( const string& id, bool exact ) {
- airport_map_iterator itr;
- if(exact) {
- itr = airports_by_id.find(id);
- } else {
- itr = airports_by_id.lower_bound(id);
- }
- if(itr == airports_by_id.end()) {
- return(NULL);
- } else {
- return(itr->second);
- }
-}
-
-
-// search for the airport nearest the specified position
-FGAirport* FGAirportList::search( double lon_deg, double lat_deg,
- bool with_metar ) {
- int closest = -1;
- double min_dist = 360.0;
- unsigned int i;
- for ( i = 0; i < airports_array.size(); ++i ) {
- // crude manhatten distance based on lat/lon difference
- double d = fabs(lon_deg - airports_array[i]->getLongitude())
- + fabs(lat_deg - airports_array[i]->getLatitude());
- if ( d < min_dist ) {
- if ( !with_metar || (with_metar&&airports_array[i]->getMetar()) ) {
- closest = i;
- min_dist = d;
- }
- }
- }
-
- return ( closest > -1 ? airports_array[closest] : NULL );
+void FGAirport::processThreshold(SGPropertyNode* aThreshold)
+{
+ // first, let's identify the current runway
+ string id(aThreshold->getStringValue("rwy"));
+ if (!hasRunwayWithIdent(id)) {
+ SG_LOG(SG_GENERAL, SG_WARN, "FGAirport::processThreshold: "
+ "found runway not defined in the global data:" << ident() << "/" << id);
+ return;
+ }
+
+ FGRunway* rwy = getRunwayByIdent(id);
+ rwy->processThreshold(aThreshold);
}
-
-int
-FGAirportList::size () const
+void FGAirport::readTowerData(SGPropertyNode* aRoot)
{
- return airports_array.size();
+ SGPropertyNode* twrNode = aRoot->getChild("tower")->getChild("twr");
+ double lat = twrNode->getDoubleValue("lat"),
+ lon = twrNode->getDoubleValue("lon"),
+ elevM = twrNode->getDoubleValue("elev-m");
+
+ _tower_location = SGGeod::fromDegM(lon, lat, elevM);
}
-const FGAirport *FGAirportList::getAirport( unsigned int index ) const
+// get airport elevation
+double fgGetAirportElev( const string& id )
{
- if(index < airports_array.size()) {
- return(airports_array[index]);
+ const FGAirport *a=fgFindAirportID( id);
+ if (a) {
+ return a->getElevation();
} else {
- return(NULL);
+ return -9999.0;
}
}
-/**
- * Mark the specified airport record as not having metar
- */
-void FGAirportList::no_metar( const string &id ) {
- if(airports_by_id.find(id) != airports_by_id.end()) {
- airports_by_id[id]->setMetar(false);
- }
-}
-
+// get airport position
+SGGeod fgGetAirportPos( const string& id )
+{
+ const FGAirport *a = fgFindAirportID( id);
-/**
- * Mark the specified airport record as (yes) having metar
- */
-void FGAirportList::has_metar( const string &id ) {
- if(airports_by_id.find(id) != airports_by_id.end()) {
- airports_by_id[id]->setMetar(true);
+ if (a) {
+ return SGGeod::fromDegM(a->getLongitude(), a->getLatitude(), a->getElevation());
+ } else {
+ return SGGeod::fromDegM(0.0, 0.0, -9999.0);
}
}