]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGAtmosphere.cpp
Sync. w. JSB CVS as of 15/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
93   bind();
94   Debug(0);
95 }
96
97 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98
99 FGAtmosphere::~FGAtmosphere()
100 {
101   unbind();
102   Debug(1);
103 }
104
105 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106
107 bool FGAtmosphere::InitModel(void)
108 {
109   FGModel::InitModel();
110
111   UseInternal();  // this is the default
112
113   Calculate(h);
114   StdSLtemperature = SLtemperature = 518.67;
115   StdSLpressure    = SLpressure = 2116.22;
116   StdSLdensity     = SLdensity = 0.00237767;
117   StdSLsoundspeed  = SLsoundspeed = sqrt(SHRatio*Reng*StdSLtemperature);
118   rSLtemperature = 1.0/StdSLtemperature;
119   rSLpressure    = 1.0/StdSLpressure;
120   rSLdensity     = 1.0/StdSLdensity;
121   rSLsoundspeed  = 1.0/StdSLsoundspeed;
122
123   return true;
124 }
125
126 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127
128 bool FGAtmosphere::Run(void)
129 {
130   if (FGModel::Run()) return true;
131   if (FDMExec->Holding()) return false;
132
133   T_dev = 0.0;
134   h = Propagate->Geth();
135
136   if (!useExternal) {
137     Calculate(h);
138     CalculateDerived();
139   } else {
140     CalculateDerived();
141   }
142
143   Debug(2);
144   return false;
145 }
146
147 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 //
149 // See reference 1
150
151 void FGAtmosphere::Calculate(double altitude)
152 {
153   double slope, reftemp, refpress;
154   int i = 0;
155
156   i = lastIndex;
157   if (altitude < htab[lastIndex]) {
158     if (altitude <= 0) {
159       i = 0;
160       altitude=0;
161     } else {
162        i = lastIndex-1;
163        while (htab[i] > altitude) i--;
164     }
165   } else if (altitude > htab[lastIndex+1]) {
166     if (altitude >= htab[7]) {
167       i = 7;
168       altitude = htab[7];
169     } else {
170       i = lastIndex+1;
171       while (htab[i+1] < altitude) i++;
172     }
173   }
174
175   switch(i) {
176   case 1:     // 36089 ft.
177     slope     = 0;
178     reftemp   = 389.97;
179     refpress  = 472.452;
180     //refdens   = 0.000706032;
181     break;
182   case 2:     // 65616 ft.
183     slope     = 0.00054864;
184     reftemp   = 389.97;
185     refpress  = 114.636;
186     //refdens   = 0.000171306;
187     break;
188   case 3:     // 104986 ft.
189     slope     = 0.00153619;
190     reftemp   = 411.57;
191     refpress  = 8.36364;
192     //refdens   = 1.18422e-05;
193     break;
194   case 4:     // 154199 ft.
195     slope     = 0;
196     reftemp   = 487.17;
197     refpress  = 0.334882;
198     //refdens   = 4.00585e-7;
199     break;
200   case 5:     // 170603 ft.
201     slope     = -0.00109728;
202     reftemp   = 487.17;
203     refpress  = 0.683084;
204     //refdens   = 8.17102e-7;
205     break;
206   case 6:     // 200131 ft.
207     slope     = -0.00219456;
208     reftemp   = 454.17;
209     refpress  = 0.00684986;
210     //refdens   = 8.77702e-9;
211     break;
212   case 7:     // 259186 ft.
213     slope     = 0;
214     reftemp   = 325.17;
215     refpress  = 0.000122276;
216     //refdens   = 2.19541e-10;
217     break;
218   case 0:
219   default:     // sea level
220     slope     = -0.00356616; // R/ft.
221     reftemp   = 518.67;    // R
222     refpress  = 2116.22;    // psf
223     //refdens   = 0.00237767;  // slugs/cubic ft.
224     break;
225
226   }
227
228   // If delta_T is set, then that is our temperature deviation at any altitude.
229   // If not, then we'll estimate a deviation based on the sea level deviation (if set).
230
231   if(!StandardTempOnly) {
232     T_dev = 0.0;
233     if (delta_T != 0.0) {
234       T_dev = delta_T;
235     } else {
236       if ((altitude < 36089.239) && (T_dev_sl != 0.0)) {
237         T_dev = T_dev_sl * ( 1.0 - (altitude/36089.239));
238       }
239     }
240     reftemp+=T_dev;
241   }
242
243   if (slope == 0) {
244     intTemperature = reftemp;
245     intPressure = refpress*exp(-Inertial->SLgravity()/(reftemp*Reng)*(altitude-htab[i]));
246     intDensity = intPressure/(Reng*intTemperature);
247   } else {
248     intTemperature = reftemp+slope*(altitude-htab[i]);
249     intPressure = refpress*pow(intTemperature/reftemp,-Inertial->SLgravity()/(slope*Reng));
250     intDensity = intPressure/(Reng*intTemperature);
251   }
252
253   lastIndex=i;
254 }
255
256 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257 // Calculate parameters derived from T, P and rho
258
259 void FGAtmosphere::CalculateDerived(void)
260 {
261   T_dev = (*temperature) - GetTemperature(h);
262   density_altitude = h + T_dev * 66.7;
263
264   if (turbType == ttStandard) {
265     Turbulence();
266     vWindNED += vTurbulence;
267   }
268   if (vWindNED(1) != 0.0) psiw = atan2( vWindNED(2), vWindNED(1) );
269   if (psiw < 0) psiw += 2*M_PI;
270
271   soundspeed = sqrt(SHRatio*Reng*(*temperature));
272 }
273
274
275 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
276 // Get the standard atmospheric properties at a specified altitude
277
278 void FGAtmosphere::GetStdAtmosphere(double altitude) {
279   StandardTempOnly = true;
280   Calculate(altitude);
281   StandardTempOnly = false;
282   atmosphere.Temperature = intTemperature;
283   atmosphere.Pressure = intPressure;
284   atmosphere.Density = intDensity;
285
286   // Reset the internal atmospheric state
287   Calculate(h);
288 }
289
290 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
291 // Get the standard pressure at a specified altitude
292
293 double FGAtmosphere::GetPressure(double altitude) {
294   GetStdAtmosphere(altitude);
295   return atmosphere.Pressure;
296 }
297
298 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
299 // Get the standard temperature at a specified altitude
300
301 double FGAtmosphere::GetTemperature(double altitude) {
302   GetStdAtmosphere(altitude);
303   return atmosphere.Temperature;
304 }
305
306 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
307 // Get the standard density at a specified altitude
308
309 double FGAtmosphere::GetDensity(double altitude) {
310   GetStdAtmosphere(altitude);
311   return atmosphere.Density;
312 }
313
314
315 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
316 // square a value, but preserve the original sign
317
318 static inline double square_signed (double value)
319 {
320     if (value < 0)
321         return value * value * -1;
322     else
323         return value * value;
324 }
325
326 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
327
328 void FGAtmosphere::Turbulence(void)
329 {
330   switch (turbType) {
331   case ttStandard: {
332     vDirectiondAccelDt(eX) = 1 - 2.0*(double(rand())/double(RAND_MAX));
333     vDirectiondAccelDt(eY) = 1 - 2.0*(double(rand())/double(RAND_MAX));
334     vDirectiondAccelDt(eZ) = 1 - 2.0*(double(rand())/double(RAND_MAX));
335
336     MagnitudedAccelDt = 1 - 2.0*(double(rand())/double(RAND_MAX)) - Magnitude;
337                                 // Scale the magnitude so that it moves
338                                 // away from the peaks
339     MagnitudedAccelDt = ((MagnitudedAccelDt - Magnitude) /
340                          (1 + fabs(Magnitude)));
341     MagnitudeAccel    += MagnitudedAccelDt*rate*TurbRate*State->Getdt();
342     Magnitude         += MagnitudeAccel*rate*State->Getdt();
343
344     vDirectiondAccelDt.Normalize();
345
346                                 // deemphasise non-vertical forces
347     vDirectiondAccelDt(eX) = square_signed(vDirectiondAccelDt(eX));
348     vDirectiondAccelDt(eY) = square_signed(vDirectiondAccelDt(eY));
349
350     vDirectionAccel += vDirectiondAccelDt*rate*TurbRate*State->Getdt();
351     vDirectionAccel.Normalize();
352     vDirection      += vDirectionAccel*rate*State->Getdt();
353
354     vDirection.Normalize();
355
356                                 // Diminish turbulence within three wingspans
357                                 // of the ground
358     vTurbulence = TurbGain * Magnitude * vDirection;
359     double HOverBMAC = Auxiliary->GetHOverBMAC();
360     if (HOverBMAC < 3.0)
361         vTurbulence *= (HOverBMAC / 3.0) * (HOverBMAC / 3.0);
362
363     vTurbulenceGrad = TurbGain*MagnitudeAccel * vDirection;
364
365     vBodyTurbGrad = Propagate->GetTl2b()*vTurbulenceGrad;
366
367     if (Aircraft->GetWingSpan() > 0) {
368       vTurbPQR(eP) = vBodyTurbGrad(eY)/Aircraft->GetWingSpan();
369     } else {
370       vTurbPQR(eP) = vBodyTurbGrad(eY)/30.0;
371     }
372 //     if (Aircraft->GetHTailArm() != 0.0)
373 //       vTurbPQR(eQ) = vBodyTurbGrad(eZ)/Aircraft->GetHTailArm();
374 //     else
375 //       vTurbPQR(eQ) = vBodyTurbGrad(eZ)/10.0;
376
377     if (Aircraft->GetVTailArm() > 0)
378       vTurbPQR(eR) = vBodyTurbGrad(eX)/Aircraft->GetVTailArm();
379     else
380       vTurbPQR(eR) = vBodyTurbGrad(eX)/10.0;
381
382                                 // Clear the horizontal forces
383                                 // actually felt by the plane, now
384                                 // that we've used them to calculate
385                                 // moments.
386     vTurbulence(eX) = 0.0;
387     vTurbulence(eY) = 0.0;
388
389     break;
390   }
391   case ttBerndt: {
392     vDirectiondAccelDt(eX) = 1 - 2.0*(double(rand())/double(RAND_MAX));
393     vDirectiondAccelDt(eY) = 1 - 2.0*(double(rand())/double(RAND_MAX));
394     vDirectiondAccelDt(eZ) = 1 - 2.0*(double(rand())/double(RAND_MAX));
395
396
397     MagnitudedAccelDt = 1 - 2.0*(double(rand())/double(RAND_MAX)) - Magnitude;
398     MagnitudeAccel    += MagnitudedAccelDt*rate*State->Getdt();
399     Magnitude         += MagnitudeAccel*rate*State->Getdt();
400
401     vDirectiondAccelDt.Normalize();
402     vDirectionAccel += vDirectiondAccelDt*rate*State->Getdt();
403     vDirectionAccel.Normalize();
404     vDirection      += vDirectionAccel*rate*State->Getdt();
405
406                                 // Diminish z-vector within two wingspans
407                                 // of the ground
408     double HOverBMAC = Auxiliary->GetHOverBMAC();
409     if (HOverBMAC < 2.0)
410         vDirection(eZ) *= HOverBMAC / 2.0;
411
412     vDirection.Normalize();
413
414     vTurbulence = TurbGain*Magnitude * vDirection;
415     vTurbulenceGrad = TurbGain*MagnitudeAccel * vDirection;
416
417     vBodyTurbGrad = Propagate->GetTl2b()*vTurbulenceGrad;
418     vTurbPQR(eP) = vBodyTurbGrad(eY)/Aircraft->GetWingSpan();
419     if (Aircraft->GetHTailArm() > 0)
420       vTurbPQR(eQ) = vBodyTurbGrad(eZ)/Aircraft->GetHTailArm();
421     else
422       vTurbPQR(eQ) = vBodyTurbGrad(eZ)/10.0;
423
424     if (Aircraft->GetVTailArm() > 0)
425       vTurbPQR(eR) = vBodyTurbGrad(eX)/Aircraft->GetVTailArm();
426     else
427       vTurbPQR(eR) = vBodyTurbGrad(eX)/10.0;
428
429     break;
430   }
431   default:
432     break;
433   }
434 }
435
436 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
437
438 void FGAtmosphere::UseExternal(void)
439 {
440   temperature=&exTemperature;
441   pressure=&exPressure;
442   density=&exDensity;
443   useExternal=true;
444 }
445
446 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
447
448 void FGAtmosphere::UseInternal(void)
449 {
450   temperature=&intTemperature;
451   pressure=&intPressure;
452   density=&intDensity;
453   useExternal=false;
454 }
455
456 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
457
458 void FGAtmosphere::bind(void)
459 {
460   typedef double (FGAtmosphere::*PMF)(int) const;
461   typedef double (FGAtmosphere::*PMFv)(void) const;
462   PropertyManager->Tie("atmosphere/T-R", this, (PMFv)&FGAtmosphere::GetTemperature);
463   PropertyManager->Tie("atmosphere/rho-slugs_ft3", this, (PMFv)&FGAtmosphere::GetDensity);
464   PropertyManager->Tie("atmosphere/P-psf", this, (PMFv)&FGAtmosphere::GetPressure);
465   PropertyManager->Tie("atmosphere/a-fps", this, &FGAtmosphere::GetSoundSpeed);
466   PropertyManager->Tie("atmosphere/T-sl-R", this, &FGAtmosphere::GetTemperatureSL);
467   PropertyManager->Tie("atmosphere/rho-sl-slugs_ft3", this, &FGAtmosphere::GetDensitySL);
468   PropertyManager->Tie("atmosphere/P-sl-psf", this, &FGAtmosphere::GetPressureSL);
469   PropertyManager->Tie("atmosphere/a-sl-fps", this, &FGAtmosphere::GetSoundSpeedSL);
470   PropertyManager->Tie("atmosphere/theta", this, &FGAtmosphere::GetTemperatureRatio);
471   PropertyManager->Tie("atmosphere/sigma", this, &FGAtmosphere::GetDensityRatio);
472   PropertyManager->Tie("atmosphere/delta", this, &FGAtmosphere::GetPressureRatio);
473   PropertyManager->Tie("atmosphere/a-ratio", this, &FGAtmosphere::GetSoundSpeedRatio);
474   PropertyManager->Tie("atmosphere/psiw-rad", this, &FGAtmosphere::GetWindPsi);
475   PropertyManager->Tie("atmosphere/delta-T", this, &FGAtmosphere::GetDeltaT, &FGAtmosphere::SetDeltaT);
476   PropertyManager->Tie("atmosphere/T-sl-dev-F", this, &FGAtmosphere::GetSLTempDev, &FGAtmosphere::SetSLTempDev);
477   PropertyManager->Tie("atmosphere/density-altitude", this, &FGAtmosphere::GetDensityAltitude);
478   PropertyManager->Tie("atmosphere/p-turb-rad_sec", this,1, (PMF)&FGAtmosphere::GetTurbPQR);
479   PropertyManager->Tie("atmosphere/q-turb-rad_sec", this,2, (PMF)&FGAtmosphere::GetTurbPQR);
480   PropertyManager->Tie("atmosphere/r-turb-rad_sec", this,3, (PMF)&FGAtmosphere::GetTurbPQR);
481 }
482
483 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
484
485 void FGAtmosphere::unbind(void)
486 {
487   PropertyManager->Untie("atmosphere/T-R");
488   PropertyManager->Untie("atmosphere/rho-slugs_ft3");
489   PropertyManager->Untie("atmosphere/P-psf");
490   PropertyManager->Untie("atmosphere/a-fps");
491   PropertyManager->Untie("atmosphere/T-sl-R");
492   PropertyManager->Untie("atmosphere/rho-sl-slugs_ft3");
493   PropertyManager->Untie("atmosphere/P-sl-psf");
494   PropertyManager->Untie("atmosphere/a-sl-fps");
495   PropertyManager->Untie("atmosphere/delta-T");
496   PropertyManager->Untie("atmosphere/T-sl-dev-F");
497   PropertyManager->Untie("atmosphere/density-altitude");
498   PropertyManager->Untie("atmosphere/theta");
499   PropertyManager->Untie("atmosphere/sigma");
500   PropertyManager->Untie("atmosphere/delta");
501   PropertyManager->Untie("atmosphere/a-ratio");
502   PropertyManager->Untie("atmosphere/psiw-rad");
503   PropertyManager->Untie("atmosphere/p-turb-rad_sec");
504   PropertyManager->Untie("atmosphere/q-turb-rad_sec");
505   PropertyManager->Untie("atmosphere/r-turb-rad_sec");
506 }
507
508 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
509 //    The bitmasked value choices are as follows:
510 //    unset: In this case (the default) JSBSim would only print
511 //       out the normally expected messages, essentially echoing
512 //       the config files as they are read. If the environment
513 //       variable is not set, debug_lvl is set to 1 internally
514 //    0: This requests JSBSim not to output any messages
515 //       whatsoever.
516 //    1: This value explicity requests the normal JSBSim
517 //       startup messages
518 //    2: This value asks for a message to be printed out when
519 //       a class is instantiated
520 //    4: When this value is set, a message is displayed when a
521 //       FGModel object executes its Run() method
522 //    8: When this value is set, various runtime state variables
523 //       are printed out periodically
524 //    16: When set various parameters are sanity checked and
525 //       a message is printed out when they go out of bounds
526
527 void FGAtmosphere::Debug(int from)
528 {
529   if (debug_lvl <= 0) return;
530
531   if (debug_lvl & 1) { // Standard console startup message output
532     if (from == 0) { // Constructor
533     }
534   }
535   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
536     if (from == 0) cout << "Instantiated: FGAtmosphere" << endl;
537     if (from == 1) cout << "Destroyed:    FGAtmosphere" << endl;
538   }
539   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
540   }
541   if (debug_lvl & 8 ) { // Runtime state variables
542   }
543   if (debug_lvl & 16) { // Sanity checking
544   }
545   if (debug_lvl & 128) { // Turbulence
546     if (frame == 0 && from == 2) {
547       cout << "vTurbulence(X), vTurbulence(Y), vTurbulence(Z), "
548            << "vTurbulenceGrad(X), vTurbulenceGrad(Y), vTurbulenceGrad(Z), "
549            << "vDirection(X), vDirection(Y), vDirection(Z), "
550            << "Magnitude, "
551            << "vTurbPQR(P), vTurbPQR(Q), vTurbPQR(R), " << endl;
552     } else if (from == 2) {
553       cout << vTurbulence << ", " << vTurbulenceGrad << ", " << vDirection << ", " << Magnitude << ", " << vTurbPQR << endl;
554     }
555   }
556   if (debug_lvl & 64) {
557     if (from == 0) { // Constructor
558       cout << IdSrc << endl;
559       cout << IdHdr << endl;
560     }
561   }
562 }
563
564 } // namespace JSBSim