+/*
+void FGTrafficManager::readTimeTableFromFile(SGPath infileName)
+{
+ string model;
+ string livery;
+ string homePort;
+ string registration;
+ string flightReq;
+ bool isHeavy;
+ string acType;
+ string airline;
+ string m_class;
+ string FlightType;
+ double radius;
+ double offset;
+
+ char buffer[256];
+ string buffString;
+ vector <string> tokens, depTime,arrTime;
+ vector <string>::iterator it;
+ ifstream infile(infileName.str().c_str());
+ while (1) {
+ infile.getline(buffer, 256);
+ if (infile.eof()) {
+ break;
+ }
+ //cerr << "Read line : " << buffer << endl;
+ buffString = string(buffer);
+ tokens.clear();
+ Tokenize(buffString, tokens, " \t");
+ //for (it = tokens.begin(); it != tokens.end(); it++) {
+ // cerr << "Tokens: " << *(it) << endl;
+ //}
+ //cerr << endl;
+ if (!tokens.empty()) {
+ if (tokens[0] == string("AC")) {
+ if (tokens.size() != 13) {
+ SG_LOG(SG_GENERAL, SG_ALERT, "Error parsing traffic file " << infileName.str() << " at " << buffString);
+ exit(1);
+ }
+ model = tokens[12];
+ livery = tokens[6];
+ homePort = tokens[1];
+ registration = tokens[2];
+ if (tokens[11] == string("false")) {
+ isHeavy = false;
+ } else {
+ isHeavy = true;
+ }
+ acType = tokens[4];
+ airline = tokens[5];
+ flightReq = tokens[3] + tokens[5];
+ m_class = tokens[10];
+ FlightType = tokens[9];
+ radius = atof(tokens[8].c_str());
+ offset = atof(tokens[7].c_str());;
+ //cerr << "Found AC string " << model << " " << livery << " " << homePort << " "
+ // << registration << " " << flightReq << " " << isHeavy << " " << acType << " " << airline << " " << m_class
+ // << " " << FlightType << " " << radius << " " << offset << endl;
+ scheduledAircraft.push_back(new FGAISchedule(model,
+ livery,
+ homePort,
+ registration,
+ flightReq,
+ isHeavy,
+ acType,
+ airline,
+ m_class,
+ FlightType,
+ radius,
+ offset));
+ }
+ if (tokens[0] == string("FLIGHT")) {
+ //cerr << "Found flight " << buffString << " size is : " << tokens.size() << endl;
+ if (tokens.size() != 10) {
+ SG_LOG(SG_GENERAL, SG_ALERT, "Error parsing traffic file " << infileName.str() << " at " << buffString);
+ exit(1);
+ }
+ string callsign = tokens[1];
+ string fltrules = tokens[2];
+ string weekdays = tokens[3];
+ string departurePort = tokens[5];
+ string arrivalPort = tokens[7];
+ int cruiseAlt = atoi(tokens[8].c_str());
+ string depTimeGen = tokens[4];
+ string arrTimeGen = tokens[6];
+ string repeat = "WEEK";
+ string requiredAircraft = tokens[9];
+
+ if (weekdays.size() != 7) {
+ cerr << "Found misconfigured weekdays string" << weekdays << endl;
+ exit(1);
+ }
+ depTime.clear();
+ arrTime.clear();
+ Tokenize(depTimeGen, depTime, ":");
+ Tokenize(arrTimeGen, arrTime, ":");
+ double dep = atof(depTime[0].c_str()) + (atof(depTime[1].c_str()) / 60.0);
+ double arr = atof(arrTime[0].c_str()) + (atof(arrTime[1].c_str()) / 60.0);
+ //cerr << "Using " << dep << " " << arr << endl;
+ bool arrivalWeekdayNeedsIncrement = false;
+ if (arr < dep) {
+ arrivalWeekdayNeedsIncrement = true;
+ }
+ for (int i = 0; i < 7; i++) {
+ if (weekdays[i] != '.') {
+ char buffer[4];
+ snprintf(buffer, 4, "%d/", i);
+ string departureTime = string(buffer) + depTimeGen + string(":00");
+ string arrivalTime;
+ if (!arrivalWeekdayNeedsIncrement) {
+ arrivalTime = string(buffer) + arrTimeGen + string(":00");
+ }
+ if (arrivalWeekdayNeedsIncrement && i != 6 ) {
+ snprintf(buffer, 4, "%d/", i+1);
+ arrivalTime = string(buffer) + arrTimeGen + string(":00");
+ }
+ if (arrivalWeekdayNeedsIncrement && i == 6 ) {
+ snprintf(buffer, 4, "%d/", 0);
+ arrivalTime = string(buffer) + arrTimeGen + string(":00");
+ }
+ cerr << "Adding flight: " << callsign << " "
+ << fltrules << " "
+ << departurePort << " "
+ << arrivalPort << " "
+ << cruiseAlt << " "
+ << departureTime << " "
+ << arrivalTime << " "
+ << repeat << " "
+ << requiredAircraft << endl;
+
+ flights[requiredAircraft].push_back(new FGScheduledFlight(callsign,
+ fltrules,
+ departurePort,
+ arrivalPort,
+ cruiseAlt,
+ departureTime,
+ arrivalTime,
+ repeat,
+ requiredAircraft));
+ }
+ }
+ }
+ }
+
+ }
+ //exit(1);
+}*/
+
+/*
+void FGTrafficManager::Tokenize(const string& str,
+ vector<string>& tokens,
+ const string& delimiters)
+{
+ // Skip delimiters at beginning.
+ string::size_type lastPos = str.find_first_not_of(delimiters, 0);
+ // Find first "non-delimiter".
+ string::size_type pos = str.find_first_of(delimiters, lastPos);
+
+ while (string::npos != pos || string::npos != lastPos)
+ {
+ // Found a token, add it to the vector.
+ tokens.push_back(str.substr(lastPos, pos - lastPos));
+ // Skip delimiters. Note the "not_of"
+ lastPos = str.find_first_not_of(delimiters, pos);
+ // Find next "non-delimiter"
+ pos = str.find_first_of(delimiters, lastPos);
+ }
+}
+*/