1 // environment.cxx -- routines to model the natural environment
3 // Written by David Megginson, started February 2002.
5 // Copyright (C) 2002 David Megginson - david@megginson.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #include <boost/tuple/tuple.hpp>
30 #include <simgear/props/props.hxx>
31 #include <simgear/math/SGMath.hxx>
33 #include <Main/fg_props.hxx>
35 #include "environment.hxx"
36 #include "atmosphere.hxx"
39 ////////////////////////////////////////////////////////////////////////
41 ////////////////////////////////////////////////////////////////////////
45 // Calculated based on the ISA standard day, as found at e.g.
46 // http://www.av8n.com/physics/altimetry.htm
48 // Each line of data has 3 elements:
50 // temperature factor (dimensionless ratio of absolute temp),
51 // pressure factor (dimensionless ratio)
52 static double atmosphere_data[][3] = {
53 { -3000.00, 1.021, 1.1133 },
54 { 0.00, 1.000, 1.0000 },
55 { 2952.76, 0.980, 0.8978 },
56 { 5905.51, 0.959, 0.8042 },
57 { 8858.27, 0.939, 0.7187 },
58 { 11811.02, 0.919, 0.6407 },
59 { 14763.78, 0.898, 0.5697 },
60 { 17716.54, 0.878, 0.5052 },
61 { 20669.29, 0.858, 0.4468 },
62 { 23622.05, 0.838, 0.3940 },
63 { 26574.80, 0.817, 0.3463 },
64 { 29527.56, 0.797, 0.3034 },
65 { 32480.31, 0.777, 0.2649 },
66 { 35433.07, 0.756, 0.2305 },
67 { 38385.83, 0.752, 0.2000 },
68 { 41338.58, 0.752, 0.1736 },
69 { 44291.34, 0.752, 0.1506 },
70 { 47244.09, 0.752, 0.1307 },
71 { 50196.85, 0.752, 0.1134 },
72 { 53149.61, 0.752, 0.0984 },
73 { 56102.36, 0.752, 0.0854 },
74 { 59055.12, 0.752, 0.0741 },
75 { 62007.87, 0.752, 0.0643 },
76 { 65000.00, 0.752, 0.0557 },
77 { 68000.00, 0.754, 0.0482 },
78 { 71000.00, 0.758, 0.0418 },
79 { 74000.00, 0.761, 0.0362 },
80 { 77000.00, 0.764, 0.0314 },
81 { 80000.00, 0.767, 0.0273 },
82 { 83000.00, 0.770, 0.0237 },
83 { 86000.00, 0.773, 0.0206 },
84 { 89000.00, 0.777, 0.0179 },
85 { 92000.00, 0.780, 0.0156 },
86 { 95000.00, 0.783, 0.0135 },
87 { 98000.00, 0.786, 0.0118 },
88 { 101000.00, 0.789, 0.0103 },
92 static SGInterpTable * _temperature_degc_table = 0;
93 static SGInterpTable * _pressure_inhg_table = 0;
98 if (_temperature_degc_table != 0)
101 _temperature_degc_table = new SGInterpTable;
102 _pressure_inhg_table = new SGInterpTable;
104 for (int i = 0; atmosphere_data[i][0] != -1; i++) {
105 _temperature_degc_table->addEntry(atmosphere_data[i][0],
106 atmosphere_data[i][1]);
107 _pressure_inhg_table->addEntry(atmosphere_data[i][0],
108 atmosphere_data[i][2]);
114 ////////////////////////////////////////////////////////////////////////
115 // Implementation of FGEnvironment.
116 ////////////////////////////////////////////////////////////////////////
118 void FGEnvironment::_init()
121 visibility_m = 32000;
122 temperature_sea_level_degc = 15;
123 temperature_degc = 15;
124 dewpoint_sea_level_degc = 5; // guess
126 pressure_sea_level_inhg = 29.92;
127 pressure_inhg = 29.92;
128 turbulence_magnitude_norm = 0;
129 turbulence_rate_hz = 1;
130 wind_from_heading_deg = 0;
132 wind_from_north_fps = 0;
133 wind_from_east_fps = 0;
134 wind_from_down_fps = 0;
135 altitude_half_to_sun_m = 1000;
136 altitude_tropo_top_m = 10000;
141 _recalc_relative_humidity();
145 FGEnvironment::FGEnvironment()
150 FGEnvironment::FGEnvironment (const FGEnvironment &env)
156 FGEnvironment::~FGEnvironment()
161 FGEnvironment & FGEnvironment::operator = ( const FGEnvironment & other )
168 FGEnvironment::copy (const FGEnvironment &env)
170 elevation_ft = env.elevation_ft;
171 visibility_m = env.visibility_m;
172 temperature_sea_level_degc = env.temperature_sea_level_degc;
173 temperature_degc = env.temperature_degc;
174 dewpoint_sea_level_degc = env.dewpoint_sea_level_degc;
175 dewpoint_degc = env.dewpoint_degc;
176 pressure_sea_level_inhg = env.pressure_sea_level_inhg;
177 wind_from_heading_deg = env.wind_from_heading_deg;
178 wind_speed_kt = env.wind_speed_kt;
179 wind_from_north_fps = env.wind_from_north_fps;
180 wind_from_east_fps = env.wind_from_east_fps;
181 wind_from_down_fps = env.wind_from_down_fps;
182 turbulence_magnitude_norm = env.turbulence_magnitude_norm;
183 turbulence_rate_hz = env.turbulence_rate_hz;
184 pressure_inhg = env.pressure_inhg;
185 density_slugft3 = env.density_slugft3;
186 density_tropo_avg_kgm3 = env.density_tropo_avg_kgm3;
187 relative_humidity = env.relative_humidity;
188 altitude_half_to_sun_m = env.altitude_half_to_sun_m;
189 altitude_tropo_top_m = env.altitude_tropo_top_m;
190 live_update = env.live_update;
194 maybe_copy_value (FGEnvironment * env, const SGPropertyNode * node,
195 const char * name, void (FGEnvironment::*setter)(double))
197 const SGPropertyNode * child = node->getNode(name);
198 // fragile: depends on not being typed
200 if (child != 0 && child->hasValue() &&
201 child->getStringValue()[0] != '\0') {
202 (env->*setter)(child->getDoubleValue());
210 FGEnvironment::read (const SGPropertyNode * node)
212 bool live_update = set_live_update( false );
213 maybe_copy_value(this, node, "visibility-m",
214 &FGEnvironment::set_visibility_m);
216 maybe_copy_value(this, node, "elevation-ft",
217 &FGEnvironment::set_elevation_ft);
219 if (!maybe_copy_value(this, node, "temperature-sea-level-degc",
220 &FGEnvironment::set_temperature_sea_level_degc)) {
221 if( maybe_copy_value(this, node, "temperature-degc",
222 &FGEnvironment::set_temperature_degc)) {
223 _recalc_sl_temperature();
227 if (!maybe_copy_value(this, node, "dewpoint-sea-level-degc",
228 &FGEnvironment::set_dewpoint_sea_level_degc)) {
229 if( maybe_copy_value(this, node, "dewpoint-degc",
230 &FGEnvironment::set_dewpoint_degc)) {
231 _recalc_sl_dewpoint();
235 if (!maybe_copy_value(this, node, "pressure-sea-level-inhg",
236 &FGEnvironment::set_pressure_sea_level_inhg)) {
237 if( maybe_copy_value(this, node, "pressure-inhg",
238 &FGEnvironment::set_pressure_inhg)) {
239 _recalc_sl_pressure();
243 maybe_copy_value(this, node, "wind-from-heading-deg",
244 &FGEnvironment::set_wind_from_heading_deg);
246 maybe_copy_value(this, node, "wind-speed-kt",
247 &FGEnvironment::set_wind_speed_kt);
249 maybe_copy_value(this, node, "turbulence/magnitude-norm",
250 &FGEnvironment::set_turbulence_magnitude_norm);
252 maybe_copy_value(this, node, "turbulence/rate-hz",
253 &FGEnvironment::set_turbulence_rate_hz);
255 // calculate derived properties here to avoid duplicate expensive computations
258 _recalc_alt_dewpoint();
260 _recalc_relative_humidity();
262 set_live_update(live_update);
265 void FGEnvironment::Tie( SGPropertyNode_ptr base, bool archivable )
267 _tiedProperties.setRoot( base );
269 _tiedProperties.Tie( "visibility-m", this,
270 &FGEnvironment::get_visibility_m,
271 &FGEnvironment::set_visibility_m)
272 ->setAttribute( SGPropertyNode::ARCHIVE, archivable );
274 _tiedProperties.Tie("temperature-sea-level-degc", this,
275 &FGEnvironment::get_temperature_sea_level_degc,
276 &FGEnvironment::set_temperature_sea_level_degc)
277 ->setAttribute( SGPropertyNode::ARCHIVE, archivable );
279 _tiedProperties.Tie("temperature-degc", this,
280 &FGEnvironment::get_temperature_degc,
281 &FGEnvironment::set_temperature_degc)
282 ->setAttribute( SGPropertyNode::ARCHIVE, archivable );
284 _tiedProperties.Tie("temperature-degf", this,
285 &FGEnvironment::get_temperature_degf);
287 _tiedProperties.Tie("dewpoint-sea-level-degc", this,
288 &FGEnvironment::get_dewpoint_sea_level_degc,
289 &FGEnvironment::set_dewpoint_sea_level_degc)
290 ->setAttribute( SGPropertyNode::ARCHIVE, archivable );
292 _tiedProperties.Tie("dewpoint-degc", this,
293 &FGEnvironment::get_dewpoint_degc,
294 &FGEnvironment::set_dewpoint_degc)
295 ->setAttribute( SGPropertyNode::ARCHIVE, archivable );
297 _tiedProperties.Tie("pressure-sea-level-inhg", this,
298 &FGEnvironment::get_pressure_sea_level_inhg,
299 &FGEnvironment::set_pressure_sea_level_inhg)
300 ->setAttribute( SGPropertyNode::ARCHIVE, archivable );
302 _tiedProperties.Tie("pressure-inhg", this,
303 &FGEnvironment::get_pressure_inhg,
304 &FGEnvironment::set_pressure_inhg)
305 ->setAttribute( SGPropertyNode::ARCHIVE, archivable );
307 _tiedProperties.Tie("density-slugft3", this,
308 &FGEnvironment::get_density_slugft3); // read-only
310 _tiedProperties.Tie("relative-humidity", this,
311 &FGEnvironment::get_relative_humidity); //ro
313 _tiedProperties.Tie("atmosphere/density-tropo-avg", this,
314 &FGEnvironment::get_density_tropo_avg_kgm3); //ro
316 _tiedProperties.Tie("atmosphere/altitude-half-to-sun", this,
317 &FGEnvironment::get_altitude_half_to_sun_m,
318 &FGEnvironment::set_altitude_half_to_sun_m)
319 ->setAttribute( SGPropertyNode::ARCHIVE, archivable );
321 _tiedProperties.Tie("atmosphere/altitude-troposphere-top", this,
322 &FGEnvironment::get_altitude_tropo_top_m,
323 &FGEnvironment::set_altitude_tropo_top_m)
324 ->setAttribute( SGPropertyNode::ARCHIVE, archivable );
326 _tiedProperties.Tie("wind-from-heading-deg", this,
327 &FGEnvironment::get_wind_from_heading_deg,
328 &FGEnvironment::set_wind_from_heading_deg)
329 ->setAttribute( SGPropertyNode::ARCHIVE, archivable );
331 _tiedProperties.Tie("wind-speed-kt", this,
332 &FGEnvironment::get_wind_speed_kt,
333 &FGEnvironment::set_wind_speed_kt)
334 ->setAttribute( SGPropertyNode::ARCHIVE, archivable );
336 _tiedProperties.Tie("wind-from-north-fps", this,
337 &FGEnvironment::get_wind_from_north_fps,
338 &FGEnvironment::set_wind_from_north_fps)
339 ->setAttribute( SGPropertyNode::ARCHIVE, archivable );
341 _tiedProperties.Tie("wind-from-east-fps", this,
342 &FGEnvironment::get_wind_from_east_fps,
343 &FGEnvironment::set_wind_from_east_fps)
344 ->setAttribute( SGPropertyNode::ARCHIVE, archivable );
346 _tiedProperties.Tie("wind-from-down-fps", this,
347 &FGEnvironment::get_wind_from_down_fps,
348 &FGEnvironment::set_wind_from_down_fps)
349 ->setAttribute( SGPropertyNode::ARCHIVE, archivable );
351 _tiedProperties.Tie("turbulence/magnitude-norm", this,
352 &FGEnvironment::get_turbulence_magnitude_norm,
353 &FGEnvironment::set_turbulence_magnitude_norm)
354 ->setAttribute( SGPropertyNode::ARCHIVE, archivable );
356 _tiedProperties.Tie("turbulence/rate-hz", this,
357 &FGEnvironment::get_turbulence_rate_hz,
358 &FGEnvironment::set_turbulence_rate_hz)
359 ->setAttribute( SGPropertyNode::ARCHIVE, archivable );
362 void FGEnvironment::Untie()
364 _tiedProperties.Untie();
368 FGEnvironment::get_visibility_m () const
374 FGEnvironment::get_temperature_sea_level_degc () const
376 return temperature_sea_level_degc;
380 FGEnvironment::get_temperature_degc () const
382 return temperature_degc;
386 FGEnvironment::get_temperature_degf () const
388 return (temperature_degc * 9.0 / 5.0) + 32.0;
392 FGEnvironment::get_dewpoint_sea_level_degc () const
394 return dewpoint_sea_level_degc;
398 FGEnvironment::get_dewpoint_degc () const
400 return dewpoint_degc;
404 FGEnvironment::get_pressure_sea_level_inhg () const
406 return pressure_sea_level_inhg;
410 FGEnvironment::get_pressure_inhg () const
412 return pressure_inhg;
416 FGEnvironment::get_density_slugft3 () const
418 return density_slugft3;
422 FGEnvironment::get_relative_humidity () const
424 return relative_humidity;
428 FGEnvironment::get_density_tropo_avg_kgm3 () const
430 return density_tropo_avg_kgm3;
434 FGEnvironment::get_altitude_half_to_sun_m () const
436 return altitude_half_to_sun_m;
440 FGEnvironment::get_altitude_tropo_top_m () const
442 return altitude_tropo_top_m;
446 FGEnvironment::get_wind_from_heading_deg () const
448 return wind_from_heading_deg;
452 FGEnvironment::get_wind_speed_kt () const
454 return wind_speed_kt;
458 FGEnvironment::get_wind_from_north_fps () const
460 return wind_from_north_fps;
464 FGEnvironment::get_wind_from_east_fps () const
466 return wind_from_east_fps;
470 FGEnvironment::get_wind_from_down_fps () const
472 return wind_from_down_fps;
476 FGEnvironment::get_turbulence_magnitude_norm () const
478 return turbulence_magnitude_norm;
482 FGEnvironment::get_turbulence_rate_hz () const
484 return turbulence_rate_hz;
488 FGEnvironment::get_elevation_ft () const
494 FGEnvironment::set_visibility_m (double v)
500 FGEnvironment::set_temperature_sea_level_degc (double t)
502 temperature_sea_level_degc = t;
503 if (dewpoint_sea_level_degc > t)
504 dewpoint_sea_level_degc = t;
512 FGEnvironment::set_temperature_degc (double t)
514 temperature_degc = t;
516 _recalc_sl_temperature();
517 _recalc_sl_pressure();
520 _recalc_relative_humidity();
525 FGEnvironment::set_dewpoint_sea_level_degc (double t)
527 dewpoint_sea_level_degc = t;
528 if (temperature_sea_level_degc < t)
529 temperature_sea_level_degc = t;
531 _recalc_alt_dewpoint();
537 FGEnvironment::set_dewpoint_degc (double t)
541 _recalc_sl_dewpoint();
543 _recalc_relative_humidity();
548 FGEnvironment::set_pressure_sea_level_inhg (double p)
550 pressure_sea_level_inhg = p;
558 FGEnvironment::set_pressure_inhg (double p)
562 _recalc_sl_pressure();
568 FGEnvironment::set_wind_from_heading_deg (double h)
570 wind_from_heading_deg = h;
577 FGEnvironment::set_wind_speed_kt (double s)
586 FGEnvironment::set_wind_from_north_fps (double n)
588 wind_from_north_fps = n;
595 FGEnvironment::set_wind_from_east_fps (double e)
597 wind_from_east_fps = e;
604 FGEnvironment::set_wind_from_down_fps (double d)
606 wind_from_down_fps = d;
613 FGEnvironment::set_turbulence_magnitude_norm (double t)
615 turbulence_magnitude_norm = t;
619 FGEnvironment::set_turbulence_rate_hz (double r)
621 turbulence_rate_hz = r;
625 FGEnvironment::set_elevation_ft (double e)
630 _recalc_alt_dewpoint();
632 _recalc_relative_humidity();
637 FGEnvironment::set_altitude_half_to_sun_m (double alt)
639 altitude_half_to_sun_m = alt;
641 _recalc_density_tropo_avg_kgm3();
646 FGEnvironment::set_altitude_tropo_top_m (double alt)
648 altitude_tropo_top_m = alt;
650 _recalc_density_tropo_avg_kgm3();
656 FGEnvironment::_recalc_hdgspd ()
658 wind_from_heading_deg =
659 atan2(wind_from_east_fps, wind_from_north_fps) * SGD_RADIANS_TO_DEGREES;
661 if( wind_from_heading_deg < 0 )
662 wind_from_heading_deg += 360.0;
664 wind_speed_kt = sqrt(wind_from_north_fps * wind_from_north_fps +
665 wind_from_east_fps * wind_from_east_fps)
666 * SG_METER_TO_NM * SG_FEET_TO_METER * 3600;
670 FGEnvironment::_recalc_ne ()
673 wind_speed_kt * SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
675 wind_from_north_fps = speed_fps *
676 cos(wind_from_heading_deg * SGD_DEGREES_TO_RADIANS);
677 wind_from_east_fps = speed_fps *
678 sin(wind_from_heading_deg * SGD_DEGREES_TO_RADIANS);
681 // Intended to help with the interpretation of METAR data,
682 // not for random in-flight outside-air temperatures.
684 FGEnvironment::_recalc_sl_temperature ()
689 SG_LOG(SG_ENVIRONMENT, SG_DEBUG, "recalc_sl_temperature: using "
690 << temperature_degc << " @ " << elevation_ft << " :: " << this);
694 if (elevation_ft * atmodel::foot >= ISA_def[1].height) {
695 SG_LOG(SG_ENVIRONMENT, SG_ALERT, "recalc_sl_temperature: "
696 << "valid only in troposphere, not " << elevation_ft);
700 // Clamp: temperature of the stratosphere, in degrees C:
701 double t_strato = ISA_def[1].temp - atmodel::freezing;
702 if (temperature_degc < t_strato) temperature_sea_level_degc = t_strato;
703 else temperature_sea_level_degc =
704 temperature_degc + elevation_ft * atmodel::foot * ISA_def[0].lapse;
706 // Alternative implemenation:
707 // else temperature_sea_level_inhg = T_layer(0., elevation_ft * foot,
708 // pressure_inhg * inHg, temperature_degc + freezing, ISA_def[0].lapse) - freezing;
712 FGEnvironment::_recalc_sl_dewpoint ()
715 // FIXME: this will work only for low
717 dewpoint_sea_level_degc = dewpoint_degc + (elevation_ft * .0002);
718 if (dewpoint_sea_level_degc > temperature_sea_level_degc)
719 dewpoint_sea_level_degc = temperature_sea_level_degc;
723 FGEnvironment::_recalc_alt_dewpoint ()
726 // FIXME: this will work only for low
728 dewpoint_degc = dewpoint_sea_level_degc + (elevation_ft * .0002);
729 if (dewpoint_degc > temperature_degc)
730 dewpoint_degc = temperature_degc;
734 FGEnvironment::_recalc_sl_pressure ()
736 using namespace atmodel;
739 SG_LOG(SG_ENVIRONMENT, SG_ALERT, "recalc_sl_pressure: using "
740 << pressure_inhg << " and "
741 << temperature_degc << " @ " << elevation_ft << " :: " << this);
744 pressure_sea_level_inhg = P_layer(0., elevation_ft * foot,
745 pressure_inhg * inHg, temperature_degc + freezing, ISA_def[0].lapse) / inHg;
748 // This gets called at frame rate, to account for the aircraft's
749 // changing altitude.
750 // Called by set_elevation_ft() which is called by FGEnvironmentMgr::update
753 FGEnvironment::_recalc_alt_pt ()
755 using namespace atmodel;
759 if (++count % 1000 == 0) {
760 SG_LOG(SG_ENVIRONMENT, SG_ALERT,
761 "recalc_alt_pt for: " << elevation_ft
762 << " using " << pressure_sea_level_inhg
763 << " and " << temperature_sea_level_degc
769 double press = pressure_inhg * inHg;
770 double temp = temperature_degc + freezing;
771 boost::tie(press, temp) = PT_vs_hpt(elevation_ft * foot,
772 pressure_sea_level_inhg * inHg, temperature_sea_level_degc + freezing);
773 temperature_degc = temp - freezing;
774 pressure_inhg = press / inHg;
778 FGEnvironment::_recalc_density ()
780 double pressure_psf = pressure_inhg * 70.7487;
782 // adjust for humidity
783 // calculations taken from USA Today (oops!) at
784 // http://www.usatoday.com/weather/basics/density-calculations.htm
785 double temperature_degk = temperature_degc + 273.15;
786 double pressure_mb = pressure_inhg * 33.86;
787 double vapor_pressure_mb =
788 6.11 * pow(10.0, 7.5 * dewpoint_degc / (237.7 + dewpoint_degc));
789 double virtual_temperature_degk = temperature_degk / (1 - (vapor_pressure_mb / pressure_mb) * (1.0 - 0.622));
790 double virtual_temperature_degr = virtual_temperature_degk * 1.8;
792 density_slugft3 = pressure_psf / (virtual_temperature_degr * 1718);
793 _recalc_density_tropo_avg_kgm3();
796 // This is used to calculate the average density on the path
797 // of sunlight to the observer for calculating sun-color
799 FGEnvironment::_recalc_density_tropo_avg_kgm3 ()
801 double pressure_mb = pressure_inhg * 33.86;
802 double vaporpressure = 6.11 * pow(10.0, ((7.5 * dewpoint_degc) / (237.7 + dewpoint_degc)));
804 double virtual_temp = (temperature_degc + 273.15) / (1 - 0.379 * (vaporpressure/pressure_mb));
806 double density_half = (100 * pressure_mb * exp(-altitude_half_to_sun_m / 8000))
807 / (287.05 * virtual_temp);
808 double density_tropo = (100 * pressure_mb * exp((-1 * altitude_tropo_top_m) / 8000))
809 / ( 287.05 * virtual_temp);
811 density_tropo_avg_kgm3 = ((density_slugft3 * 515.379) + density_half + density_tropo) / 3;
815 FGEnvironment::_recalc_relative_humidity ()
818 double vaporpressure = 6.11 * pow(10.0, ((7.5 * dewpoint_degc) / ( 237.7 + dewpoint_degc)));
819 double sat_vaporpressure = 6.11 * pow(10.0, ((7.5 * temperature_degc)
820 / ( 237.7 + temperature_degc)) );
821 relative_humidity = 100 * vaporpressure / sat_vaporpressure ;
823 with a little algebra, this gets the same result and spares two multiplications and one pow()
825 double a = (7.5 * dewpoint_degc) / ( 237.7 + dewpoint_degc);
826 double b = (7.5 * temperature_degc) / ( 237.7 + temperature_degc);
827 relative_humidity = 100 * pow(10.0,a-b);
831 FGEnvironment::set_live_update( bool _live_update )
833 bool b = live_update;
834 live_update = _live_update;
839 ////////////////////////////////////////////////////////////////////////
841 ////////////////////////////////////////////////////////////////////////
844 do_interp (double a, double b, double fraction)
846 double retval = (a + ((b - a) * fraction));
851 do_interp_deg (double a, double b, double fraction)
855 if (fabs(b-a) > 180) {
861 return fmod(do_interp(a, b, fraction), 360);
865 FGEnvironment::interpolate( const FGEnvironment & env2,
866 double fraction, FGEnvironment * result) const
868 // don't calculate each internal property every time we set a single value
869 // we trigger that at the end of the interpolation process
870 bool live_update = result->set_live_update( false );
872 result->set_visibility_m
873 (do_interp(get_visibility_m(),
874 env2.get_visibility_m(),
877 result->set_temperature_sea_level_degc
878 (do_interp(get_temperature_sea_level_degc(),
879 env2.get_temperature_sea_level_degc(),
882 result->set_dewpoint_sea_level_degc
883 (do_interp(get_dewpoint_sea_level_degc(),
884 env2.get_dewpoint_sea_level_degc(),
887 result->set_pressure_sea_level_inhg
888 (do_interp(get_pressure_sea_level_inhg(),
889 env2.get_pressure_sea_level_inhg(),
892 result->set_wind_from_heading_deg
893 (do_interp_deg(get_wind_from_heading_deg(),
894 env2.get_wind_from_heading_deg(),
897 result->set_wind_speed_kt
898 (do_interp(get_wind_speed_kt(),
899 env2.get_wind_speed_kt(),
902 result->set_elevation_ft
903 (do_interp(get_elevation_ft(),
904 env2.get_elevation_ft(),
907 result->set_turbulence_magnitude_norm
908 (do_interp(get_turbulence_magnitude_norm(),
909 env2.get_turbulence_magnitude_norm(),
912 result->set_turbulence_rate_hz
913 (do_interp(get_turbulence_rate_hz(),
914 env2.get_turbulence_rate_hz(),
917 // calculate derived properties here to avoid duplicate expensive computations
918 result->_recalc_ne();
919 result->_recalc_alt_pt();
920 result->_recalc_alt_dewpoint();
921 result->_recalc_density();
922 result->_recalc_relative_humidity();
924 result->set_live_update(live_update);
929 // end of environment.cxx