]> git.mxchange.org Git - flightgear.git/blob - src/Environment/environment.cxx
Dave LUFF: Fix buffer overrun with longer runways
[flightgear.git] / src / Environment / environment.cxx
1 // environment.cxx -- routines to model the natural environment
2 //
3 // Written by David Megginson, started February 2002.
4 //
5 // Copyright (C) 2002  David Megginson - david@megginson.com
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #include <math.h>
29
30 #include <simgear/constants.h>
31 #include <simgear/debug/logstream.hxx>
32 #include <simgear/math/interpolater.hxx>
33 #include <simgear/props/props.hxx>
34 #include <simgear/environment/visual_enviro.hxx>
35
36 #include <Main/fg_props.hxx>
37
38 #include "environment.hxx"
39
40
41 \f
42 ////////////////////////////////////////////////////////////////////////
43 // Atmosphere model.
44 ////////////////////////////////////////////////////////////////////////
45
46 // Calculated based on the ISA standard day, as found at e.g.
47 // http://www.av8n.com/physics/altimetry.htm
48
49 // Each line of data has 3 elements:
50 //   Elevation (ft), 
51 //   temperature factor (dimensionless ratio of absolute temp), 
52 //   pressure factor (dimensionless ratio)
53 static double atmosphere_data[][3] = {
54  {  -3000.00,   1.021,  1.1133 },
55  {      0.00,   1.000,  1.0000 },
56  {   2952.76,   0.980,  0.8978 },
57  {   5905.51,   0.959,  0.8042 },
58  {   8858.27,   0.939,  0.7187 },
59  {  11811.02,   0.919,  0.6407 },
60  {  14763.78,   0.898,  0.5697 },
61  {  17716.54,   0.878,  0.5052 },
62  {  20669.29,   0.858,  0.4468 },
63  {  23622.05,   0.838,  0.3940 },
64  {  26574.80,   0.817,  0.3463 },
65  {  29527.56,   0.797,  0.3034 },
66  {  32480.31,   0.777,  0.2649 },
67  {  35433.07,   0.756,  0.2305 },
68  {  38385.83,   0.752,  0.2000 },
69  {  41338.58,   0.752,  0.1736 },
70  {  44291.34,   0.752,  0.1506 },
71  {  47244.09,   0.752,  0.1307 },
72  {  50196.85,   0.752,  0.1134 },
73  {  53149.61,   0.752,  0.0984 },
74  {  56102.36,   0.752,  0.0854 },
75  {  59055.12,   0.752,  0.0741 },
76  {  62007.87,   0.752,  0.0643 },
77  {  65000.00,   0.752,  0.0557 },
78  {  68000.00,   0.754,  0.0482 },
79  {  71000.00,   0.758,  0.0418 },
80  {  74000.00,   0.761,  0.0362 },
81  {  77000.00,   0.764,  0.0314 },
82  {  80000.00,   0.767,  0.0273 },
83  {  83000.00,   0.770,  0.0237 },
84  {  86000.00,   0.773,  0.0206 },
85  {  89000.00,   0.777,  0.0179 },
86  {  92000.00,   0.780,  0.0156 },
87  {  95000.00,   0.783,  0.0135 },
88  {  98000.00,   0.786,  0.0118 },
89  { 101000.00,   0.789,  0.0103 },
90  { -1, -1, -1 }
91 };
92
93 static SGInterpTable * _temperature_degc_table = 0;
94 static SGInterpTable * _pressure_inhg_table = 0;
95
96 static void
97 _setup_tables ()
98 {
99   if (_temperature_degc_table != 0)
100       return;
101
102   _temperature_degc_table = new SGInterpTable;
103   _pressure_inhg_table = new SGInterpTable;
104
105   for (int i = 0; atmosphere_data[i][0] != -1; i++) {
106     _temperature_degc_table->addEntry(atmosphere_data[i][0],
107                                       atmosphere_data[i][1]);
108     _pressure_inhg_table->addEntry(atmosphere_data[i][0],
109                                    atmosphere_data[i][2]);
110   }
111 }
112
113
114 \f
115 ////////////////////////////////////////////////////////////////////////
116 // Implementation of FGEnvironment.
117 ////////////////////////////////////////////////////////////////////////
118
119 void FGEnvironment::_init()
120 {
121     elevation_ft = 0;
122     visibility_m = 32000;
123     temperature_sea_level_degc = 15;
124     temperature_degc = 15;
125     dewpoint_sea_level_degc = 5; // guess
126     dewpoint_degc = 5;
127     pressure_sea_level_inhg = 29.92;
128     pressure_inhg = 29.92;
129     turbulence_magnitude_norm = 0;
130     turbulence_rate_hz = 1;
131     wind_from_heading_deg = 0;
132     wind_speed_kt = 0;
133     wind_from_north_fps = 0;
134     wind_from_east_fps = 0;
135     wind_from_down_fps = 0;
136     thermal_lift_fps = 0;
137     ridge_lift_fps= 0;
138     altitude_half_to_sun_m = 1000;
139     altitude_tropo_top_m = 10000;
140     _setup_tables();
141     _recalc_density();
142     _recalc_relative_humidity();
143     live_update = true;
144 }
145
146 FGEnvironment::FGEnvironment()
147 {
148     _init();
149 }
150
151 FGEnvironment::FGEnvironment (const FGEnvironment &env)
152 {
153     _init();
154     copy(env);
155 }
156
157 FGEnvironment::~FGEnvironment()
158 {
159 }
160
161 void
162 FGEnvironment::copy (const FGEnvironment &env)
163 {
164     elevation_ft = env.elevation_ft;
165     visibility_m = env.visibility_m;
166     temperature_sea_level_degc = env.temperature_sea_level_degc;
167     temperature_degc = env.temperature_degc;
168     dewpoint_sea_level_degc = env.dewpoint_sea_level_degc;
169     dewpoint_degc = env.dewpoint_degc;
170     pressure_sea_level_inhg = env.pressure_sea_level_inhg;
171     wind_from_heading_deg = env.wind_from_heading_deg;
172     wind_speed_kt = env.wind_speed_kt;
173     wind_from_north_fps = env.wind_from_north_fps;
174     wind_from_east_fps = env.wind_from_east_fps;
175     wind_from_down_fps = env.wind_from_down_fps;
176     thermal_lift_fps = env.thermal_lift_fps;
177     ridge_lift_fps= env.ridge_lift_fps;
178     turbulence_magnitude_norm = env.turbulence_magnitude_norm;
179     turbulence_rate_hz = env.turbulence_rate_hz;
180 }
181
182 static inline bool
183 maybe_copy_value (FGEnvironment * env, const SGPropertyNode * node,
184                   const char * name, void (FGEnvironment::*setter)(double))
185 {
186     const SGPropertyNode * child = node->getNode(name);
187                                 // fragile: depends on not being typed
188                                 // as a number
189     if (child != 0 && child->hasValue() &&
190         child->getStringValue()[0] != '\0') {
191         (env->*setter)(child->getDoubleValue());
192         return true;
193     } else {
194         return false;
195     }
196 }
197
198 void
199 FGEnvironment::read (const SGPropertyNode * node)
200 {
201     maybe_copy_value(this, node, "visibility-m",
202                      &FGEnvironment::set_visibility_m);
203
204     if (!maybe_copy_value(this, node, "temperature-sea-level-degc",
205                           &FGEnvironment::set_temperature_sea_level_degc))
206         maybe_copy_value(this, node, "temperature-degc",
207                          &FGEnvironment::set_temperature_degc);
208
209     if (!maybe_copy_value(this, node, "dewpoint-sea-level-degc",
210                           &FGEnvironment::set_dewpoint_sea_level_degc))
211         maybe_copy_value(this, node, "dewpoint-degc",
212                          &FGEnvironment::set_dewpoint_degc);
213
214     if (!maybe_copy_value(this, node, "pressure-sea-level-inhg",
215                           &FGEnvironment::set_pressure_sea_level_inhg))
216         maybe_copy_value(this, node, "pressure-inhg",
217                          &FGEnvironment::set_pressure_inhg);
218
219     maybe_copy_value(this, node, "wind-from-heading-deg",
220                      &FGEnvironment::set_wind_from_heading_deg);
221
222     maybe_copy_value(this, node, "wind-speed-kt",
223                      &FGEnvironment::set_wind_speed_kt);
224
225     maybe_copy_value(this, node, "elevation-ft",
226                      &FGEnvironment::set_elevation_ft);
227
228     maybe_copy_value(this, node, "turbulence/magnitude-norm",
229                      &FGEnvironment::set_turbulence_magnitude_norm);
230
231     maybe_copy_value(this, node, "turbulence/rate-hz",
232                      &FGEnvironment::set_turbulence_rate_hz);
233 }
234
235
236 double
237 FGEnvironment::get_visibility_m () const
238 {
239   return visibility_m;
240 }
241
242 double
243 FGEnvironment::get_temperature_sea_level_degc () const
244 {
245   return temperature_sea_level_degc;
246 }
247
248 double
249 FGEnvironment::get_temperature_degc () const
250 {
251   return temperature_degc;
252 }
253
254 double
255 FGEnvironment::get_temperature_degf () const
256 {
257   return (temperature_degc * 9.0 / 5.0) + 32.0;
258 }
259
260 double
261 FGEnvironment::get_dewpoint_sea_level_degc () const
262 {
263   return dewpoint_sea_level_degc;
264 }
265
266 double
267 FGEnvironment::get_dewpoint_degc () const
268 {
269   return dewpoint_degc;
270 }
271
272 double
273 FGEnvironment::get_pressure_sea_level_inhg () const
274 {
275   return pressure_sea_level_inhg;
276 }
277
278 double
279 FGEnvironment::get_pressure_inhg () const
280 {
281   return pressure_inhg;
282 }
283
284 double
285 FGEnvironment::get_density_slugft3 () const
286 {
287   return density_slugft3;
288 }
289
290 double
291 FGEnvironment::get_relative_humidity () const
292 {
293   return relative_humidity;
294 }
295
296 double
297 FGEnvironment::get_density_tropo_avg_kgm3 () const
298 {
299   return density_tropo_avg_kgm3;
300 }
301
302 double
303 FGEnvironment::get_altitude_half_to_sun_m () const
304 {
305   return altitude_half_to_sun_m;
306 }
307
308 double
309 FGEnvironment::get_altitude_tropo_top_m () const
310 {
311   return altitude_tropo_top_m;
312 }
313
314 double
315 FGEnvironment::get_wind_from_heading_deg () const
316 {
317   return wind_from_heading_deg;
318 }
319
320 double
321 FGEnvironment::get_wind_speed_kt () const
322 {
323   return wind_speed_kt;
324 }
325
326 double
327 FGEnvironment::get_wind_from_north_fps () const
328 {
329   return wind_from_north_fps;
330 }
331
332 double
333 FGEnvironment::get_wind_from_east_fps () const
334 {
335   return wind_from_east_fps;
336 }
337
338 double
339 FGEnvironment::get_wind_from_down_fps () const
340 {
341   return wind_from_down_fps;
342 }
343
344 double
345 FGEnvironment::get_thermal_lift_fps () const
346 {
347   return thermal_lift_fps;
348 }
349
350 double
351 FGEnvironment::get_ridge_lift_fps () const
352 {
353   return ridge_lift_fps;
354 }
355
356 double
357 FGEnvironment::get_turbulence_magnitude_norm () const
358 {
359   if( sgEnviro.get_turbulence_enable_state() )
360     if (fgGetBool("/environment/params/real-world-weather-fetch") == true)
361       return sgEnviro.get_cloud_turbulence();
362   return turbulence_magnitude_norm;
363 }
364
365 double
366 FGEnvironment::get_turbulence_rate_hz () const
367 {
368   return turbulence_rate_hz;
369 }
370
371 double
372 FGEnvironment::get_elevation_ft () const
373 {
374   return elevation_ft;
375 }
376
377 void
378 FGEnvironment::set_visibility_m (double v)
379 {
380   visibility_m = v;
381 }
382
383 void
384 FGEnvironment::set_temperature_sea_level_degc (double t)
385 {
386   temperature_sea_level_degc = t;
387   if (dewpoint_sea_level_degc > t)
388       dewpoint_sea_level_degc = t;
389   if( live_update ) {
390     _recalc_alt_temperature();
391     _recalc_density();
392   }
393 }
394
395 void
396 FGEnvironment::set_temperature_degc (double t)
397 {
398   temperature_degc = t;
399   if( live_update ) {
400     _recalc_sl_temperature();
401     _recalc_density();
402     _recalc_relative_humidity();
403   }
404 }
405
406 void
407 FGEnvironment::set_dewpoint_sea_level_degc (double t)
408 {
409   dewpoint_sea_level_degc = t;
410   if (temperature_sea_level_degc < t)
411       temperature_sea_level_degc = t;
412   if( live_update ) {
413     _recalc_alt_dewpoint();
414     _recalc_density();
415   }
416 }
417
418 void
419 FGEnvironment::set_dewpoint_degc (double t)
420 {
421   dewpoint_degc = t;
422   if( live_update ) {
423     _recalc_sl_dewpoint();
424     _recalc_density();
425     _recalc_relative_humidity();
426   }
427 }
428
429 void
430 FGEnvironment::set_pressure_sea_level_inhg (double p)
431 {
432   pressure_sea_level_inhg = p;
433   if( live_update ) {
434     _recalc_alt_pressure();
435     _recalc_density();
436   }
437 }
438
439 void
440 FGEnvironment::set_pressure_inhg (double p)
441 {
442   pressure_inhg = p;
443   if( live_update ) {
444     _recalc_sl_pressure();
445     _recalc_density();
446   }
447 }
448
449 void
450 FGEnvironment::set_wind_from_heading_deg (double h)
451 {
452   wind_from_heading_deg = h;
453   if( live_update ) {
454     _recalc_ne();
455   }
456 }
457
458 void
459 FGEnvironment::set_wind_speed_kt (double s)
460 {
461   wind_speed_kt = s;
462   if( live_update ) {
463     _recalc_ne();
464   }
465 }
466
467 void
468 FGEnvironment::set_wind_from_north_fps (double n)
469 {
470   wind_from_north_fps = n;
471   if( live_update ) {
472     _recalc_hdgspd();
473   }
474 }
475
476 void
477 FGEnvironment::set_wind_from_east_fps (double e)
478 {
479   wind_from_east_fps = e;
480   if( live_update ) {
481     _recalc_hdgspd();
482   }
483 }
484
485 void
486 FGEnvironment::set_wind_from_down_fps (double d)
487 {
488   wind_from_down_fps = d;
489   if( live_update ) {
490     _recalc_hdgspd();
491   }
492 }
493
494 void
495 FGEnvironment::set_thermal_lift_fps (double th)
496 {
497   thermal_lift_fps = th;
498   if( live_update ) {
499     _recalc_updraft();
500   }
501 }
502
503 void
504 FGEnvironment::set_ridge_lift_fps (double ri)
505 {
506   ridge_lift_fps = ri;
507   if( live_update ) {
508     _recalc_updraft();
509 }
510 }
511
512 void
513 FGEnvironment::set_turbulence_magnitude_norm (double t)
514 {
515   turbulence_magnitude_norm = t;
516 }
517
518 void
519 FGEnvironment::set_turbulence_rate_hz (double r)
520 {
521   turbulence_rate_hz = r;
522 }
523
524 void
525 FGEnvironment::set_elevation_ft (double e)
526 {
527   elevation_ft = e;
528   if( live_update ) {
529     _recalc_alt_temperature();
530     _recalc_alt_dewpoint();
531     _recalc_alt_pressure();
532     _recalc_density();
533     _recalc_relative_humidity();
534   }
535 }
536
537 void
538 FGEnvironment::set_altitude_half_to_sun_m (double alt)
539 {
540   altitude_half_to_sun_m = alt;
541   if( live_update ) {
542     _recalc_density_tropo_avg_kgm3();
543   }
544 }
545
546 void
547 FGEnvironment::set_altitude_tropo_top_m (double alt)
548 {
549   altitude_tropo_top_m = alt;
550   if( live_update ) {
551     _recalc_density_tropo_avg_kgm3();
552   }
553 }
554
555
556 void
557 FGEnvironment::_recalc_hdgspd ()
558 {
559   double angle_rad;
560
561   if (wind_from_east_fps == 0) {
562     angle_rad = (wind_from_north_fps >= 0 ? SGD_PI_2 : -SGD_PI_2);
563   } else {
564     angle_rad = atan(wind_from_north_fps/wind_from_east_fps);
565   }
566   wind_from_heading_deg = angle_rad * SGD_RADIANS_TO_DEGREES;
567   if (wind_from_east_fps >= 0)
568     wind_from_heading_deg = 90 - wind_from_heading_deg;
569   else
570     wind_from_heading_deg = 270 - wind_from_heading_deg;
571
572 #if 0
573   // FIXME: Windspeed can become negative with these formulas.
574   //        which can cause problems for animations that rely
575   //        on the windspeed property.
576   if (angle_rad == 0)
577     wind_speed_kt = fabs(wind_from_east_fps
578                          * SG_METER_TO_NM * SG_FEET_TO_METER * 3600);
579   else
580     wind_speed_kt = (wind_from_north_fps / sin(angle_rad))
581       * SG_METER_TO_NM * SG_FEET_TO_METER * 3600;
582 #else
583   wind_speed_kt = sqrt(wind_from_north_fps * wind_from_north_fps +
584                        wind_from_east_fps * wind_from_east_fps) 
585                   * SG_METER_TO_NM * SG_FEET_TO_METER * 3600;
586 #endif
587 }
588
589 void
590 FGEnvironment::_recalc_ne ()
591 {
592   double speed_fps =
593     wind_speed_kt * SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
594
595   wind_from_north_fps = speed_fps *
596     cos(wind_from_heading_deg * SGD_DEGREES_TO_RADIANS);
597   wind_from_east_fps = speed_fps *
598     sin(wind_from_heading_deg * SGD_DEGREES_TO_RADIANS);
599 }
600
601 void
602 FGEnvironment::_recalc_updraft ()
603 {
604   wind_from_down_fps = thermal_lift_fps + ridge_lift_fps ;
605 }
606
607 void
608 FGEnvironment::_recalc_sl_temperature ()
609 {
610   // If we're in the stratosphere, leave sea-level temp alone
611   if (elevation_ft < 38000) {
612     temperature_sea_level_degc = (temperature_degc + 273.15)
613         / _temperature_degc_table->interpolate(elevation_ft)
614       - 273.15;
615   }
616 }
617
618 void
619 FGEnvironment::_recalc_alt_temperature ()
620 {
621   if (elevation_ft < 38000) {
622     temperature_degc = (temperature_sea_level_degc + 273.15) *
623         _temperature_degc_table->interpolate(elevation_ft) - 273.15;
624   } else {
625     temperature_degc = -56.49;  // Stratosphere is constant
626   }
627 }
628
629 void
630 FGEnvironment::_recalc_sl_dewpoint ()
631 {
632                                 // 0.2degC/1000ft
633                                 // FIXME: this will work only for low
634                                 // elevations
635   dewpoint_sea_level_degc = dewpoint_degc + (elevation_ft * .0002);
636   if (dewpoint_sea_level_degc > temperature_sea_level_degc)
637     dewpoint_sea_level_degc = temperature_sea_level_degc;
638 }
639
640 void
641 FGEnvironment::_recalc_alt_dewpoint ()
642 {
643                                 // 0.2degC/1000ft
644                                 // FIXME: this will work only for low
645                                 // elevations
646   dewpoint_degc = dewpoint_sea_level_degc + (elevation_ft * .0002);
647   if (dewpoint_degc > temperature_degc)
648     dewpoint_degc = temperature_degc;
649 }
650
651 void
652 FGEnvironment::_recalc_sl_pressure ()
653 {
654   pressure_sea_level_inhg =
655     pressure_inhg / _pressure_inhg_table->interpolate(elevation_ft);
656 }
657
658 void
659 FGEnvironment::_recalc_alt_pressure ()
660 {
661   pressure_inhg =
662     pressure_sea_level_inhg * _pressure_inhg_table->interpolate(elevation_ft);
663 }
664
665 void
666 FGEnvironment::_recalc_density ()
667 {
668   double pressure_psf = pressure_inhg * 70.7487;
669   
670   // adjust for humidity
671   // calculations taken from USA Today (oops!) at
672   // http://www.usatoday.com/weather/basics/density-calculations.htm
673   double temperature_degk = temperature_degc + 273.15;
674   double pressure_mb = pressure_inhg * 33.86;
675   double vapor_pressure_mb =
676     6.11 * pow(10.0, 7.5 * dewpoint_degc / (237.7 + dewpoint_degc));
677   double virtual_temperature_degk = temperature_degk / (1 - (vapor_pressure_mb / pressure_mb) * (1.0 - 0.622));
678   double virtual_temperature_degr = virtual_temperature_degk * 1.8;
679
680   density_slugft3 = pressure_psf / (virtual_temperature_degr * 1718);
681   _recalc_density_tropo_avg_kgm3();
682 }
683
684 // This is used to calculate the average density on the path 
685 // of sunlight to the observer for calculating sun-color
686 void
687 FGEnvironment::_recalc_density_tropo_avg_kgm3 ()
688 {
689   double pressure_mb = pressure_inhg * 33.86;
690   double vaporpressure = 6.11 * pow(10.0, ((7.5 * dewpoint_degc) / (237.7 + dewpoint_degc)));
691
692   double virtual_temp = (temperature_degc + 273.15) / (1 - 0.379 * (vaporpressure/pressure_mb));
693
694   double density_half = (100 * pressure_mb * exp(-altitude_half_to_sun_m / 8000))
695       / (287.05 * virtual_temp);
696   double density_tropo = (100 * pressure_mb * exp((-1 * altitude_tropo_top_m) / 8000))
697       / ( 287.05 * virtual_temp);
698
699   density_tropo_avg_kgm3 = ((density_slugft3 * 515.379) + density_half + density_tropo) / 3;
700 }
701
702 void
703 FGEnvironment::_recalc_relative_humidity ()
704 {
705 /*
706   double vaporpressure = 6.11 * pow(10.0, ((7.5 * dewpoint_degc) / ( 237.7 + dewpoint_degc)));
707   double sat_vaporpressure = 6.11 * pow(10.0, ((7.5 * temperature_degc)
708       / ( 237.7 + temperature_degc)) );
709   relative_humidity = 100 * vaporpressure / sat_vaporpressure ;
710
711   with a little algebra, this gets the same result and spares two multiplications and one pow()
712 */
713   double a = (7.5 * dewpoint_degc)    / ( 237.7 + dewpoint_degc);
714   double b = (7.5 * temperature_degc) / ( 237.7 + temperature_degc);
715   relative_humidity = 100 * pow(10,a-b); 
716 }
717
718 bool
719 FGEnvironment::set_live_update( bool _live_update )
720 {
721   bool b = live_update;
722   live_update = _live_update;
723   return b;
724 }
725
726
727 ////////////////////////////////////////////////////////////////////////
728 // Functions.
729 ////////////////////////////////////////////////////////////////////////
730
731 static inline double
732 do_interp (double a, double b, double fraction)
733 {
734     double retval = (a + ((b - a) * fraction));
735     return retval;
736 }
737
738 static inline double
739 do_interp_deg (double a, double b, double fraction)
740 {
741     a = fmod(a, 360);
742     b = fmod(b, 360);
743     if (fabs(b-a) > 180) {
744         if (a < b)
745             a += 360;
746         else
747             b += 360;
748     }
749     return fmod(do_interp(a, b, fraction), 360);
750 }
751
752 void
753 interpolate (const FGEnvironment * env1, const FGEnvironment * env2,
754              double fraction, FGEnvironment * result)
755 {
756     // don't calculate each internal property every time we set a single value
757     // we trigger that at the end of the interpolation process
758     bool live_update = result->set_live_update( false );
759
760     result->set_visibility_m
761         (do_interp(env1->get_visibility_m(),
762                    env2->get_visibility_m(),
763                    fraction));
764
765     result->set_temperature_sea_level_degc
766         (do_interp(env1->get_temperature_sea_level_degc(),
767                    env2->get_temperature_sea_level_degc(),
768                    fraction));
769
770     result->set_dewpoint_degc
771         (do_interp(env1->get_dewpoint_sea_level_degc(),
772                    env2->get_dewpoint_sea_level_degc(),
773                    fraction));
774
775     result->set_pressure_sea_level_inhg
776         (do_interp(env1->get_pressure_sea_level_inhg(),
777                    env2->get_pressure_sea_level_inhg(),
778                    fraction));
779
780     result->set_wind_from_heading_deg
781         (do_interp_deg(env1->get_wind_from_heading_deg(),
782                        env2->get_wind_from_heading_deg(),
783                        fraction));
784
785     result->set_wind_speed_kt
786         (do_interp(env1->get_wind_speed_kt(),
787                    env2->get_wind_speed_kt(),
788                    fraction));
789
790     result->set_elevation_ft
791         (do_interp(env1->get_elevation_ft(),
792                    env2->get_elevation_ft(),
793                    fraction));
794
795     result->set_turbulence_magnitude_norm
796         (do_interp(env1->get_turbulence_magnitude_norm(),
797                    env2->get_turbulence_magnitude_norm(),
798                    fraction));
799
800     result->set_turbulence_rate_hz
801         (do_interp(env1->get_turbulence_rate_hz(),
802                    env2->get_turbulence_rate_hz(),
803                    fraction));
804
805     // calculate derived properties here to avoid duplicate expensive computations
806     result->_recalc_ne();
807     result->_recalc_alt_temperature();
808     result->_recalc_alt_dewpoint();
809     result->_recalc_alt_pressure();
810     result->_recalc_density();
811     result->_recalc_relative_humidity();
812
813     result->set_live_update(live_update);
814 }
815
816 // end of environment.cxx