]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGAtmosphere.cpp
Sync w. JSBSim as of 20/01/2007
[flightgear.git] / src / FDM / JSBSim / models / FGAtmosphere.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGAtmosphere.cpp
4  Author:       Jon Berndt
5                Implementation of 1959 Standard Atmosphere added by Tony Peden
6  Date started: 11/24/98
7  Purpose:      Models the atmosphere
8  Called by:    FGSimExec
9
10  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
11
12  This program is free software; you can redistribute it and/or modify it under
13  the terms of the GNU Lesser General Public License as published by the Free Software
14  Foundation; either version 2 of the License, or (at your option) any later
15  version.
16
17  This program is distributed in the hope that it will be useful, but WITHOUT
18  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
20  details.
21
22  You should have received a copy of the GNU Lesser General Public License along with
23  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
24  Place - Suite 330, Boston, MA  02111-1307, USA.
25
26  Further information about the GNU Lesser General Public License can also be found on
27  the world wide web at http://www.gnu.org.
28
29 FUNCTIONAL DESCRIPTION
30 --------------------------------------------------------------------------------
31 Models the atmosphere. The equation used below was determined by a third order
32 curve fit using Excel. The data is from the ICAO atmosphere model.
33
34 HISTORY
35 --------------------------------------------------------------------------------
36 11/24/98   JSB   Created
37 07/23/99   TP    Added implementation of 1959 Standard Atmosphere
38                  Moved calculation of Mach number to FGPropagate
39                  Later updated to '76 model
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 COMMENTS, REFERENCES,  and NOTES
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 [1]   Anderson, John D. "Introduction to Flight, Third Edition", McGraw-Hill,
44       1989, ISBN 0-07-001641-0
45
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 INCLUDES
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
49
50 #include "FGAtmosphere.h"
51 #include <FGState.h>
52 #include <FGFDMExec.h>
53 #include "FGAircraft.h"
54 #include "FGPropagate.h"
55 #include "FGInertial.h"
56 #include <input_output/FGPropertyManager.h>
57
58 namespace JSBSim {
59
60 static const char *IdSrc = "$Id$";
61 static const char *IdHdr = ID_ATMOSPHERE;
62
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 CLASS IMPLEMENTATION
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66
67
68 FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex) : FGModel(fdmex)
69 {
70   Name = "FGAtmosphere";
71   lastIndex = 0;
72   h = 0.0;
73   psiw = 0.0;
74   htab[0]=0;
75   htab[1]=36089.239;
76   htab[2]=65616.798;
77   htab[3]=104986.878;
78   htab[4]=154199.475;
79   htab[5]=170603.675;
80   htab[6]=200131.234;
81   htab[7]=259186.352; //ft.
82
83   MagnitudedAccelDt = MagnitudeAccel = Magnitude = 0.0;
84 //   turbType = ttNone;
85   turbType = ttStandard;
86 //   turbType = ttBerndt;
87   TurbGain = 0.0;
88   TurbRate = 1.0;
89
90   T_dev_sl = T_dev = delta_T = 0.0;
91   StandardTempOnly = false;
92   first_pass = true;
93
94   bind();
95   Debug(0);
96 }
97
98 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99
100 FGAtmosphere::~FGAtmosphere()
101 {
102   unbind();
103   Debug(1);
104 }
105
106 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107
108 bool FGAtmosphere::InitModel(void)
109 {
110   FGModel::InitModel();
111
112   UseInternal();  // this is the default
113
114   Calculate(h);
115   StdSLtemperature = SLtemperature = 518.67;
116   StdSLpressure    = SLpressure = 2116.22;
117   StdSLdensity     = SLdensity = 0.00237767;
118   StdSLsoundspeed  = SLsoundspeed = sqrt(SHRatio*Reng*StdSLtemperature);
119   rSLtemperature = 1.0/StdSLtemperature;
120   rSLpressure    = 1.0/StdSLpressure;
121   rSLdensity     = 1.0/StdSLdensity;
122   rSLsoundspeed  = 1.0/StdSLsoundspeed;
123
124   return true;
125 }
126
127 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128
129 bool FGAtmosphere::Run(void)
130 {
131   if (FGModel::Run()) return true;
132   if (FDMExec->Holding()) return false;
133
134   T_dev = 0.0;
135   h = Propagate->Geth();
136
137   if (!useExternal) {
138     Calculate(h);
139     CalculateDerived();
140   } else {
141     CalculateDerived();
142   }
143
144   Debug(2);
145   return false;
146 }
147
148 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 //
150 // See reference 1
151
152 void FGAtmosphere::Calculate(double altitude)
153 {
154   double slope, reftemp, refpress;
155   int i = 0;
156
157   i = lastIndex;
158   if (altitude < htab[lastIndex]) {
159     if (altitude <= 0) {
160       i = 0;
161       altitude=0;
162     } else {
163        i = lastIndex-1;
164        while (htab[i] > altitude) i--;
165     }
166   } else if (altitude > htab[lastIndex+1]) {
167     if (altitude >= htab[7]) {
168       i = 7;
169       altitude = htab[7];
170     } else {
171       i = lastIndex+1;
172       while (htab[i+1] < altitude) i++;
173     }
174   }
175
176   switch(i) {
177   case 1:     // 36089 ft.
178     slope     = 0;
179     reftemp   = 389.97;
180     refpress  = 472.452;
181     //refdens   = 0.000706032;
182     break;
183   case 2:     // 65616 ft.
184     slope     = 0.00054864;
185     reftemp   = 389.97;
186     refpress  = 114.636;
187     //refdens   = 0.000171306;
188     break;
189   case 3:     // 104986 ft.
190     slope     = 0.00153619;
191     reftemp   = 411.57;
192     refpress  = 8.36364;
193     //refdens   = 1.18422e-05;
194     break;
195   case 4:     // 154199 ft.
196     slope     = 0;
197     reftemp   = 487.17;
198     refpress  = 0.334882;
199     //refdens   = 4.00585e-7;
200     break;
201   case 5:     // 170603 ft.
202     slope     = -0.00109728;
203     reftemp   = 487.17;
204     refpress  = 0.683084;
205     //refdens   = 8.17102e-7;
206     break;
207   case 6:     // 200131 ft.
208     slope     = -0.00219456;
209     reftemp   = 454.17;
210     refpress  = 0.00684986;
211     //refdens   = 8.77702e-9;
212     break;
213   case 7:     // 259186 ft.
214     slope     = 0;
215     reftemp   = 325.17;
216     refpress  = 0.000122276;
217     //refdens   = 2.19541e-10;
218     break;
219   case 0:
220   default:     // sea level
221     slope     = -0.00356616; // R/ft.
222     reftemp   = 518.67;    // R
223     refpress  = 2116.22;    // psf
224     //refdens   = 0.00237767;  // slugs/cubic ft.
225     break;
226
227   }
228
229   // If delta_T is set, then that is our temperature deviation at any altitude.
230   // If not, then we'll estimate a deviation based on the sea level deviation (if set).
231
232   if(!StandardTempOnly) {
233     T_dev = 0.0;
234     if (delta_T != 0.0) {
235       T_dev = delta_T;
236     } else {
237       if ((altitude < 36089.239) && (T_dev_sl != 0.0)) {
238         T_dev = T_dev_sl * ( 1.0 - (altitude/36089.239));
239       }
240     }
241     reftemp+=T_dev;
242   }
243
244   if (slope == 0) {
245     intTemperature = reftemp;
246     intPressure = refpress*exp(-Inertial->SLgravity()/(reftemp*Reng)*(altitude-htab[i]));
247     intDensity = intPressure/(Reng*intTemperature);
248   } else {
249     intTemperature = reftemp+slope*(altitude-htab[i]);
250     intPressure = refpress*pow(intTemperature/reftemp,-Inertial->SLgravity()/(slope*Reng));
251     intDensity = intPressure/(Reng*intTemperature);
252   }
253
254   lastIndex=i;
255 }
256
257 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
258 // Calculate parameters derived from T, P and rho
259
260 void FGAtmosphere::CalculateDerived(void)
261 {
262   T_dev = (*temperature) - GetTemperature(h);
263   density_altitude = h + T_dev * 66.7;
264
265   if (turbType == ttStandard) {
266     Turbulence();
267     vWindNED += vTurbulence;
268   }
269   if (vWindNED(1) != 0.0) psiw = atan2( vWindNED(2), vWindNED(1) );
270   if (psiw < 0) psiw += 2*M_PI;
271
272   soundspeed = sqrt(SHRatio*Reng*(*temperature));
273 }
274
275
276 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
277 // Get the standard atmospheric properties at a specified altitude
278
279 void FGAtmosphere::GetStdAtmosphere(double altitude) {
280   StandardTempOnly = true;
281   Calculate(altitude);
282   StandardTempOnly = false;
283   atmosphere.Temperature = intTemperature;
284   atmosphere.Pressure = intPressure;
285   atmosphere.Density = intDensity;
286
287   // Reset the internal atmospheric state
288   Calculate(h);
289 }
290
291 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
292 // Get the standard pressure at a specified altitude
293
294 double FGAtmosphere::GetPressure(double altitude) {
295   GetStdAtmosphere(altitude);
296   return atmosphere.Pressure;
297 }
298
299 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300 // Get the standard temperature at a specified altitude
301
302 double FGAtmosphere::GetTemperature(double altitude) {
303   GetStdAtmosphere(altitude);
304   return atmosphere.Temperature;
305 }
306
307 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
308 // Get the standard density at a specified altitude
309
310 double FGAtmosphere::GetDensity(double altitude) {
311   GetStdAtmosphere(altitude);
312   return atmosphere.Density;
313 }
314
315
316 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
317 // square a value, but preserve the original sign
318
319 static inline double square_signed (double value)
320 {
321     if (value < 0)
322         return value * value * -1;
323     else
324         return value * value;
325 }
326
327 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328
329 void FGAtmosphere::Turbulence(void)
330 {
331   switch (turbType) {
332   case ttStandard: {
333     vDirectiondAccelDt(eX) = 1 - 2.0*(double(rand())/double(RAND_MAX));
334     vDirectiondAccelDt(eY) = 1 - 2.0*(double(rand())/double(RAND_MAX));
335     vDirectiondAccelDt(eZ) = 1 - 2.0*(double(rand())/double(RAND_MAX));
336
337     MagnitudedAccelDt = 1 - 2.0*(double(rand())/double(RAND_MAX)) - Magnitude;
338                                 // Scale the magnitude so that it moves
339                                 // away from the peaks
340     MagnitudedAccelDt = ((MagnitudedAccelDt - Magnitude) /
341                          (1 + fabs(Magnitude)));
342     MagnitudeAccel    += MagnitudedAccelDt*rate*TurbRate*State->Getdt();
343     Magnitude         += MagnitudeAccel*rate*State->Getdt();
344
345     vDirectiondAccelDt.Normalize();
346
347                                 // deemphasise non-vertical forces
348     vDirectiondAccelDt(eX) = square_signed(vDirectiondAccelDt(eX));
349     vDirectiondAccelDt(eY) = square_signed(vDirectiondAccelDt(eY));
350
351     vDirectionAccel += vDirectiondAccelDt*rate*TurbRate*State->Getdt();
352     vDirectionAccel.Normalize();
353     vDirection      += vDirectionAccel*rate*State->Getdt();
354
355     vDirection.Normalize();
356
357                                 // Diminish turbulence within three wingspans
358                                 // of the ground
359     vTurbulence = TurbGain * Magnitude * vDirection;
360     double HOverBMAC = Auxiliary->GetHOverBMAC();
361     if (HOverBMAC < 3.0)
362         vTurbulence *= (HOverBMAC / 3.0) * (HOverBMAC / 3.0);
363
364     vTurbulenceGrad = TurbGain*MagnitudeAccel * vDirection;
365
366     vBodyTurbGrad = Propagate->GetTl2b()*vTurbulenceGrad;
367
368     if (Aircraft->GetWingSpan() > 0) {
369       vTurbPQR(eP) = vBodyTurbGrad(eY)/Aircraft->GetWingSpan();
370     } else {
371       vTurbPQR(eP) = vBodyTurbGrad(eY)/30.0;
372     }
373 //     if (Aircraft->GetHTailArm() != 0.0)
374 //       vTurbPQR(eQ) = vBodyTurbGrad(eZ)/Aircraft->GetHTailArm();
375 //     else
376 //       vTurbPQR(eQ) = vBodyTurbGrad(eZ)/10.0;
377
378     if (Aircraft->GetVTailArm() > 0)
379       vTurbPQR(eR) = vBodyTurbGrad(eX)/Aircraft->GetVTailArm();
380     else
381       vTurbPQR(eR) = vBodyTurbGrad(eX)/10.0;
382
383                                 // Clear the horizontal forces
384                                 // actually felt by the plane, now
385                                 // that we've used them to calculate
386                                 // moments.
387     vTurbulence(eX) = 0.0;
388     vTurbulence(eY) = 0.0;
389
390     break;
391   }
392   case ttBerndt: {
393     vDirectiondAccelDt(eX) = 1 - 2.0*(double(rand())/double(RAND_MAX));
394     vDirectiondAccelDt(eY) = 1 - 2.0*(double(rand())/double(RAND_MAX));
395     vDirectiondAccelDt(eZ) = 1 - 2.0*(double(rand())/double(RAND_MAX));
396
397
398     MagnitudedAccelDt = 1 - 2.0*(double(rand())/double(RAND_MAX)) - Magnitude;
399     MagnitudeAccel    += MagnitudedAccelDt*rate*State->Getdt();
400     Magnitude         += MagnitudeAccel*rate*State->Getdt();
401
402     vDirectiondAccelDt.Normalize();
403     vDirectionAccel += vDirectiondAccelDt*rate*State->Getdt();
404     vDirectionAccel.Normalize();
405     vDirection      += vDirectionAccel*rate*State->Getdt();
406
407                                 // Diminish z-vector within two wingspans
408                                 // of the ground
409     double HOverBMAC = Auxiliary->GetHOverBMAC();
410     if (HOverBMAC < 2.0)
411         vDirection(eZ) *= HOverBMAC / 2.0;
412
413     vDirection.Normalize();
414
415     vTurbulence = TurbGain*Magnitude * vDirection;
416     vTurbulenceGrad = TurbGain*MagnitudeAccel * vDirection;
417
418     vBodyTurbGrad = Propagate->GetTl2b()*vTurbulenceGrad;
419     vTurbPQR(eP) = vBodyTurbGrad(eY)/Aircraft->GetWingSpan();
420     if (Aircraft->GetHTailArm() > 0)
421       vTurbPQR(eQ) = vBodyTurbGrad(eZ)/Aircraft->GetHTailArm();
422     else
423       vTurbPQR(eQ) = vBodyTurbGrad(eZ)/10.0;
424
425     if (Aircraft->GetVTailArm() > 0)
426       vTurbPQR(eR) = vBodyTurbGrad(eX)/Aircraft->GetVTailArm();
427     else
428       vTurbPQR(eR) = vBodyTurbGrad(eX)/10.0;
429
430     break;
431   }
432   default:
433     break;
434   }
435 }
436
437 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
438
439 void FGAtmosphere::UseExternal(void)
440 {
441   temperature=&exTemperature;
442   pressure=&exPressure;
443   density=&exDensity;
444   useExternal=true;
445 }
446
447 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
448
449 void FGAtmosphere::UseInternal(void)
450 {
451   temperature=&intTemperature;
452   pressure=&intPressure;
453   density=&intDensity;
454   useExternal=false;
455 }
456
457 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
458
459 void FGAtmosphere::bind(void)
460 {
461   typedef double (FGAtmosphere::*PMF)(int) const;
462   typedef double (FGAtmosphere::*PMFv)(void) const;
463   PropertyManager->Tie("atmosphere/T-R", this, (PMFv)&FGAtmosphere::GetTemperature);
464   PropertyManager->Tie("atmosphere/rho-slugs_ft3", this, (PMFv)&FGAtmosphere::GetDensity);
465   PropertyManager->Tie("atmosphere/P-psf", this, (PMFv)&FGAtmosphere::GetPressure);
466   PropertyManager->Tie("atmosphere/a-fps", this, &FGAtmosphere::GetSoundSpeed);
467   PropertyManager->Tie("atmosphere/T-sl-R", this, &FGAtmosphere::GetTemperatureSL);
468   PropertyManager->Tie("atmosphere/rho-sl-slugs_ft3", this, &FGAtmosphere::GetDensitySL);
469   PropertyManager->Tie("atmosphere/P-sl-psf", this, &FGAtmosphere::GetPressureSL);
470   PropertyManager->Tie("atmosphere/a-sl-fps", this, &FGAtmosphere::GetSoundSpeedSL);
471   PropertyManager->Tie("atmosphere/theta", this, &FGAtmosphere::GetTemperatureRatio);
472   PropertyManager->Tie("atmosphere/sigma", this, &FGAtmosphere::GetDensityRatio);
473   PropertyManager->Tie("atmosphere/delta", this, &FGAtmosphere::GetPressureRatio);
474   PropertyManager->Tie("atmosphere/a-ratio", this, &FGAtmosphere::GetSoundSpeedRatio);
475   PropertyManager->Tie("atmosphere/psiw-rad", this, &FGAtmosphere::GetWindPsi);
476   PropertyManager->Tie("atmosphere/delta-T", this, &FGAtmosphere::GetDeltaT, &FGAtmosphere::SetDeltaT);
477   PropertyManager->Tie("atmosphere/T-sl-dev-F", this, &FGAtmosphere::GetSLTempDev, &FGAtmosphere::SetSLTempDev);
478   PropertyManager->Tie("atmosphere/density-altitude", this, &FGAtmosphere::GetDensityAltitude);
479   PropertyManager->Tie("atmosphere/p-turb-rad_sec", this,1, (PMF)&FGAtmosphere::GetTurbPQR);
480   PropertyManager->Tie("atmosphere/q-turb-rad_sec", this,2, (PMF)&FGAtmosphere::GetTurbPQR);
481   PropertyManager->Tie("atmosphere/r-turb-rad_sec", this,3, (PMF)&FGAtmosphere::GetTurbPQR);
482 }
483
484 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
485
486 void FGAtmosphere::unbind(void)
487 {
488   PropertyManager->Untie("atmosphere/T-R");
489   PropertyManager->Untie("atmosphere/rho-slugs_ft3");
490   PropertyManager->Untie("atmosphere/P-psf");
491   PropertyManager->Untie("atmosphere/a-fps");
492   PropertyManager->Untie("atmosphere/T-sl-R");
493   PropertyManager->Untie("atmosphere/rho-sl-slugs_ft3");
494   PropertyManager->Untie("atmosphere/P-sl-psf");
495   PropertyManager->Untie("atmosphere/a-sl-fps");
496   PropertyManager->Untie("atmosphere/delta-T");
497   PropertyManager->Untie("atmosphere/T-sl-dev-F");
498   PropertyManager->Untie("atmosphere/density-altitude");
499   PropertyManager->Untie("atmosphere/theta");
500   PropertyManager->Untie("atmosphere/sigma");
501   PropertyManager->Untie("atmosphere/delta");
502   PropertyManager->Untie("atmosphere/a-ratio");
503   PropertyManager->Untie("atmosphere/psiw-rad");
504   PropertyManager->Untie("atmosphere/p-turb-rad_sec");
505   PropertyManager->Untie("atmosphere/q-turb-rad_sec");
506   PropertyManager->Untie("atmosphere/r-turb-rad_sec");
507 }
508
509 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
510 //    The bitmasked value choices are as follows:
511 //    unset: In this case (the default) JSBSim would only print
512 //       out the normally expected messages, essentially echoing
513 //       the config files as they are read. If the environment
514 //       variable is not set, debug_lvl is set to 1 internally
515 //    0: This requests JSBSim not to output any messages
516 //       whatsoever.
517 //    1: This value explicity requests the normal JSBSim
518 //       startup messages
519 //    2: This value asks for a message to be printed out when
520 //       a class is instantiated
521 //    4: When this value is set, a message is displayed when a
522 //       FGModel object executes its Run() method
523 //    8: When this value is set, various runtime state variables
524 //       are printed out periodically
525 //    16: When set various parameters are sanity checked and
526 //       a message is printed out when they go out of bounds
527
528 void FGAtmosphere::Debug(int from)
529 {
530   if (debug_lvl <= 0) return;
531
532   if (debug_lvl & 1) { // Standard console startup message output
533     if (from == 0) { // Constructor
534     }
535   }
536   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
537     if (from == 0) cout << "Instantiated: FGAtmosphere" << endl;
538     if (from == 1) cout << "Destroyed:    FGAtmosphere" << endl;
539   }
540   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
541   }
542   if (debug_lvl & 8 ) { // Runtime state variables
543   }
544   if (debug_lvl & 16) { // Sanity checking
545   }
546   if (debug_lvl & 128) { // Turbulence
547     if (first_pass && from == 2) {
548       first_pass = false;
549       cout << "vTurbulence(X), vTurbulence(Y), vTurbulence(Z), "
550            << "vTurbulenceGrad(X), vTurbulenceGrad(Y), vTurbulenceGrad(Z), "
551            << "vDirection(X), vDirection(Y), vDirection(Z), "
552            << "Magnitude, "
553            << "vTurbPQR(P), vTurbPQR(Q), vTurbPQR(R), " << endl;
554     } 
555     if (from == 2) {
556       cout << vTurbulence << ", " << vTurbulenceGrad << ", " << vDirection << ", " << Magnitude << ", " << vTurbPQR << endl;
557     }
558   }
559   if (debug_lvl & 64) {
560     if (from == 0) { // Constructor
561       cout << IdSrc << endl;
562       cout << IdHdr << endl;
563     }
564   }
565 }
566
567 } // namespace JSBSim