#include <simgear/compiler.h>
#include <stdlib.h> // atoi()
+#include <stdio.h> // sprintf
#include <string>
SG_USING_STD(string);
//#include <simgear/misc/sgstream.hxx>
#include <simgear/misc/sg_path.hxx>
-//#ifndef FG_OLD_WEATHER
-//#include <WeatherCM/FGLocalWeatherDatabase.h>
+//#ifndef FG_NEW_ENVIRONMENT
+//sorry, that works only with the new weather system
+#include <WeatherCM/FGLocalWeatherDatabase.h>
//#else
-//# include <Weather/weather.hxx>
+//# include <Environment/environment.hxx>
//#endif
#include <Main/fg_props.hxx>
string FGATIS::get_transmission() {
//void FGATIS::get_transmission() {
+#if !defined(FG_NEW_ENVIRONMENT)
string transmission = "";
double visibility;
- double temperature;
char buf[10];
int phonetic_id;
string phonetic_id_string;
string time_str = fgGetString("sim/time/gmt-string");
int hours;
- int minutes;
+ // int minutes;
+ sgVec3 position = { lat, lon, elev };
+ FGPhysicalProperty stationweather = WeatherDatabase->get(position);
// Only update every so-many loops - FIXME - possibly register this with the event scheduler
// Ack this doesn't work since the static counter is shared between all instances of FGATIS
// Start with the transmitted station name.
transmission += name;
+ // Add "Information"
+ transmission += " Information";
//cout << "In atis.cxx, time_str = " << time_str << '\n';
// Add the recording identifier
transmission = transmission + " Weather " + time_str.substr(0,3) + "00 hours Zulu";
// Get the temperature
- temperature = fgGetDouble("/environment/weather/temperature-K");
- sprintf(buf, "%i", int(temperature - 273.15));
+ // (Hardwire it for now since the global property returns the temperature at the current altitude
+ //temperature = fgGetDouble("/environment/weather/temperature-K");
+ sprintf(buf, "%i", int(stationweather.Temperature - 273.15));
transmission += " Temperature ";
transmission += buf;
- transmission += " degrees Celcius";
+ transmission += " degrees Celsius";
// Get the pressure / altimeter
+ // pressure is: stationweather.AirPressure in Pascal
// Get the visibility
visibility = fgGetDouble("/environment/visibility-m");
double cloudbase = fgGetDouble("/environment/clouds/altitude-ft");
// For some reason the altitude returned doesn't seem to correspond to the actual cloud altitude.
char buf3[10];
- cout << "cloudbase = " << cloudbase << endl;
+ // cout << "cloudbase = " << cloudbase << endl;
sprintf(buf3, "%i", int(cloudbase));
transmission = transmission + " Cloudbase " + buf3 + " feet";
}
FGRunways runways( path.c_str() );
//Set the heading to into the wind
- double hdg = fgGetDouble("/environment/wind-from-heading-deg");
- double speed = fgGetDouble("/environment/wind-speed-knots");
+ double wind_x = stationweather.Wind[0];
+ double wind_y = stationweather.Wind[1];
- //cout << "in atis.cxx, hdg = " << hdg << " speed = " << speed << endl;
+ double speed = sqrt( wind_x*wind_x + wind_y*wind_y ) * SG_METER_TO_NM / (60.0*60.0);
+ double hdg;
//If no wind use 270degrees
if(speed == 0) {
hdg = 270;
transmission += " Winds light and variable";
} else {
+ // //normalize the wind to get the direction
+ //wind_x /= speed; wind_y /= speed;
+
+ hdg = - atan2 ( wind_x, wind_y ) * SG_RADIANS_TO_DEGREES ;
+ if (hdg < 0.0)
+ hdg += 360.0;
+
//add a description of the wind to the transmission
char buf2[72];
sprintf(buf2, "%s %i %s %i %s", " Winds ", int(speed), " knots from ", int(hdg), " degrees");
transmission += buf2;
}
- string rwy_no = runways.search(ident, hdg);
- if(rwy_no != "NN") {
+ string rwy_no = runways.search(ident, int(hdg));
+ if(rwy_no != (string)"NN") {
transmission += " Landing and departing runway ";
transmission += rwy_no;
//cout << "in atis.cxx, r.rwy_no = " << rwy_no << " r.id = " << r->id << " r.heading = " << r->heading << endl;
// }
return(transmission);
+#else
+ return "Station unavailable (not supported by FG_NEW_ENVIRONMENT)";
+#endif // FG_NEW_ENVIRONMENT
}