+ loadProcedures();
+
+ WayptRef enroute;
+ flightgear::SID* sid = NULL;
+ double d = 1e9;
+
+ for (unsigned int i=0; i<mSIDs.size(); ++i) {
+ if (aRwy && !mSIDs[i]->isForRunway(aRwy)) {
+ continue;
+ }
+
+ WayptRef e = mSIDs[i]->findBestTransition(aDest);
+ if (!e) {
+ continue; // strange, but let's not worry about it
+ }
+
+ // assert(e->isFixedPosition());
+ double ed = SGGeodesy::distanceM(aDest, e->position());
+ if (ed < d) { // new best match
+ enroute = e;
+ d = ed;
+ sid = mSIDs[i];
+ }
+ } // of SID iteration
+
+ if (!mSIDs.empty() && !sid) {
+ SG_LOG(SG_GENERAL, SG_INFO, ident() << "selectSID, no SID found (runway="
+ << (aRwy ? aRwy->ident() : "no runway preference"));
+ }
+
+ return make_pair(sid, enroute);
+}
+
+pair<STAR*, WayptRef>
+FGAirport::selectSTAR(const SGGeod& aOrigin, FGRunway* aRwy)
+{
+ loadProcedures();
+
+ WayptRef enroute;
+ STAR* star = NULL;
+ double d = 1e9;
+
+ for (unsigned int i=0; i<mSTARs.size(); ++i) {
+ if (!mSTARs[i]->isForRunway(aRwy)) {
+ continue;
+ }
+
+ SG_LOG(SG_GENERAL, SG_INFO, "STAR " << mSTARs[i]->ident() << " is valid for runway");
+ WayptRef e = mSTARs[i]->findBestTransition(aOrigin);
+ if (!e) {
+ continue; // strange, but let's not worry about it
+ }
+
+ // assert(e->isFixedPosition());
+ double ed = SGGeodesy::distanceM(aOrigin, e->position());
+ if (ed < d) { // new best match
+ enroute = e;
+ d = ed;
+ star = mSTARs[i];
+ }
+ } // of STAR iteration
+
+ return make_pair(star, enroute);