]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFDMExec.cpp
JSBSim updates, including MSVC fixes from Bernie Bright
[flightgear.git] / src / FDM / JSBSim / FGFDMExec.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGFDMExec.cpp
4  Author:       Jon S. Berndt
5  Date started: 11/17/98
6  Purpose:      Schedules and runs the model routines.
7
8  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
9
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  details.
19
20  You should have received a copy of the GNU General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA  02111-1307, USA.
23
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29
30 This class wraps up the simulation scheduling routines.
31
32 HISTORY
33 --------------------------------------------------------------------------------
34 11/17/98   JSB   Created
35
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 COMMENTS, REFERENCES,  and NOTES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 INCLUDES
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43
44 #ifdef FGFS
45 #  include <simgear/compiler.h>
46 #  include STL_IOSTREAM
47 #  include STL_ITERATOR
48 #else
49 #  if defined(sgi) && !defined(__GNUC__)
50 #    include <iostream.h>
51 #  else
52 #    include <iostream>
53 #  endif
54 #  include <iterator>
55 #endif
56
57 #include "FGFDMExec.h"
58 #include "FGState.h"
59 #include "FGAtmosphere.h"
60 #include "FGFCS.h"
61 #include "FGPropulsion.h"
62 #include "FGMassBalance.h"
63 #include "FGGroundReactions.h"
64 #include "FGAerodynamics.h"
65 #include "FGInertial.h"
66 #include "FGAircraft.h"
67 #include "FGTranslation.h"
68 #include "FGRotation.h"
69 #include "FGPosition.h"
70 #include "FGAuxiliary.h"
71 #include "FGOutput.h"
72 #include "FGConfigFile.h"
73 #include "FGInitialCondition.h"
74 #include "FGPropertyManager.h"
75
76 static const char *IdSrc = "$Id$";
77 static const char *IdHdr = ID_FDMEXEC;
78
79 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 GLOBAL DECLARATIONS
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
82
83 unsigned int FGFDMExec::FDMctr = 0;
84 FGPropertyManager* FGFDMExec::master=0;
85
86 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 CLASS IMPLEMENTATION
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
89
90 // Constructor
91
92 FGFDMExec::FGFDMExec(FGPropertyManager* root)
93 {
94   
95   Frame           = 0;
96   FirstModel      = 0;
97   Error           = 0;
98   State           = 0;
99   Atmosphere      = 0;
100   FCS             = 0;
101   Propulsion      = 0;
102   MassBalance     = 0;
103   Aerodynamics    = 0;
104   Inertial        = 0;
105   GroundReactions = 0;
106   Aircraft        = 0;
107   Translation     = 0;
108   Rotation        = 0;
109   Position        = 0;
110   Auxiliary       = 0;
111   Output          = 0;
112
113   terminate = false;
114   frozen = false;
115   modelLoaded = false;
116   IsSlave = false;
117
118   IdFDM = FDMctr;
119   FDMctr++;
120   
121   try {
122     char* num = getenv("JSBSIM_DEBUG");
123     if (!num) debug_lvl = 1;
124     else debug_lvl = atoi(num); // set debug level
125   } catch (...) {               // if error set to 1
126     debug_lvl = 1;
127   }
128
129   if (root == 0)  master= new FGPropertyManager;
130   else            master = root;
131
132   instance = master->GetNode("/fdm/jsbsim",IdFDM,true);
133   instance->SetDouble("zero",0);  
134   
135   Debug(0);
136   
137   // this is here to catch errors in binding member functions
138   // to the property tree.
139   try {
140     Allocate();
141   } catch ( string msg ) {
142     cout << "Caught error: " << msg << endl;
143     exit(1);
144   }    
145 }
146
147 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148
149 FGFDMExec::~FGFDMExec()
150 {
151   try {
152     DeAllocate();
153   } catch ( string msg ) {
154     cout << "Caught error: " << msg << endl;
155   }    
156
157   for (unsigned int i=1; i<SlaveFDMList.size(); i++) delete SlaveFDMList[i]->exec;
158   SlaveFDMList.clear();
159  
160   Debug(1);
161 }
162
163 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164
165 bool FGFDMExec::Allocate(void)
166 {
167   bool result=true;
168
169   Atmosphere      = new FGAtmosphere(this);
170   FCS             = new FGFCS(this);
171   Propulsion      = new FGPropulsion(this);
172   MassBalance     = new FGMassBalance(this);
173   Aerodynamics    = new FGAerodynamics (this);
174   Inertial        = new FGInertial(this);
175   GroundReactions = new FGGroundReactions(this);
176   Aircraft        = new FGAircraft(this);
177   Translation     = new FGTranslation(this);
178   Rotation        = new FGRotation(this);
179   Position        = new FGPosition(this);
180   Auxiliary       = new FGAuxiliary(this);
181   Output          = new FGOutput(this);
182
183   State        = new FGState(this); // This must be done here, as the FGState
184                                     // class needs valid pointers to the above
185                                     // model classes
186   
187   // Initialize models so they can communicate with each other
188
189   if (!Atmosphere->InitModel()) {
190     cerr << fgred << "Atmosphere model init failed" << fgdef << endl;
191     Error+=1;}
192   if (!FCS->InitModel())        {
193     cerr << fgred << "FCS model init failed" << fgdef << endl;
194     Error+=2;}
195   if (!Propulsion->InitModel()) {
196     cerr << fgred << "FGPropulsion model init failed" << fgdef << endl;
197     Error+=4;}
198   if (!MassBalance->InitModel()) {
199     cerr << fgred << "FGMassBalance model init failed" << fgdef << endl;
200     Error+=8;}
201   if (!Aerodynamics->InitModel()) {
202     cerr << fgred << "FGAerodynamics model init failed" << fgdef << endl;
203     Error+=16;}
204   if (!Inertial->InitModel()) {
205     cerr << fgred << "FGInertial model init failed" << fgdef << endl;
206     Error+=32;}
207   if (!GroundReactions->InitModel())   {
208     cerr << fgred << "Ground Reactions model init failed" << fgdef << endl;
209     Error+=64;}
210   if (!Aircraft->InitModel())   {
211     cerr << fgred << "Aircraft model init failed" << fgdef << endl;
212     Error+=128;}
213   if (!Translation->InitModel()) {
214     cerr << fgred << "Translation model init failed" << fgdef << endl;
215     Error+=256;}
216   if (!Rotation->InitModel())   {
217     cerr << fgred << "Rotation model init failed" << fgdef << endl;
218     Error+=512;}
219   if (!Position->InitModel())   {
220     cerr << fgred << "Position model init failed" << fgdef << endl;
221     Error+=1024;}
222   if (!Auxiliary->InitModel())  {
223     cerr << fgred << "Auxiliary model init failed" << fgdef << endl;
224     Error+=2058;}
225   if (!Output->InitModel())     {
226     cerr << fgred << "Output model init failed" << fgdef << endl;
227     Error+=4096;}
228
229   if (Error > 0) result = false;
230
231   // Schedule a model. The second arg (the integer) is the pass number. For
232   // instance, the atmosphere model gets executed every fifth pass it is called
233   // by the executive. Everything else here gets executed each pass.
234
235   Schedule(Atmosphere,      1);
236   Schedule(FCS,             1);
237   Schedule(Propulsion,      1);
238   Schedule(MassBalance,     1);
239   Schedule(Aerodynamics,    1);
240   Schedule(Inertial,        1);
241   Schedule(GroundReactions, 1);
242   Schedule(Aircraft,        1);
243   Schedule(Rotation,        1);
244   Schedule(Translation,     1);
245   Schedule(Position,        1);
246   Schedule(Auxiliary,       1);
247   Schedule(Output,          1);
248
249   modelLoaded = false;
250
251   return result;
252 }
253
254 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
255
256 bool FGFDMExec::DeAllocate(void) {
257
258   if ( Atmosphere != 0 )     delete Atmosphere;
259   if ( FCS != 0 )            delete FCS;
260   if ( Propulsion != 0)      delete Propulsion;
261   if ( MassBalance != 0)     delete MassBalance;
262   if ( Aerodynamics != 0)    delete Aerodynamics;
263   if ( Inertial != 0)        delete Inertial;
264   if ( GroundReactions != 0) delete GroundReactions;
265   if ( Aircraft != 0 )       delete Aircraft;
266   if ( Translation != 0 )    delete Translation;
267   if ( Rotation != 0 )       delete Rotation;
268   if ( Position != 0 )       delete Position;
269   if ( Auxiliary != 0 )      delete Auxiliary;
270   if ( Output != 0 )         delete Output;
271   if ( State != 0 )          delete State;
272
273   FirstModel  = 0L;
274   Error       = 0;
275
276   State           = 0;
277   Atmosphere      = 0;
278   FCS             = 0;
279   Propulsion      = 0;
280   MassBalance     = 0;
281   Aerodynamics    = 0;
282   Inertial        = 0;
283   GroundReactions = 0;
284   Aircraft        = 0;
285   Translation     = 0;
286   Rotation        = 0;
287   Position        = 0;
288   Auxiliary       = 0;
289   Output          = 0;
290
291   modelLoaded = false;
292   return modelLoaded;
293 }
294
295 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296
297 int FGFDMExec::Schedule(FGModel* model, int rate)
298 {
299   FGModel* model_iterator;
300
301   model_iterator = FirstModel;
302
303   if (model_iterator == 0L) {                  // this is the first model
304
305     FirstModel = model;
306     FirstModel->NextModel = 0L;
307     FirstModel->SetRate(rate);
308
309   } else {                                     // subsequent model
310
311     while (model_iterator->NextModel != 0L) {
312       model_iterator = model_iterator->NextModel;
313     }
314     model_iterator->NextModel = model;
315     model_iterator->NextModel->SetRate(rate);
316
317   }
318   
319   return 0;
320 }
321
322 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
323
324 bool FGFDMExec::Run(void)
325 {
326   FGModel* model_iterator;
327
328   if (frozen) return true;
329
330   model_iterator = FirstModel;
331   if (model_iterator == 0L) return false;
332
333   Debug(2);
334
335   for (unsigned int i=0; i<SlaveFDMList.size(); i++) {
336     // TransferState(i);
337     // Run(i)
338   }
339
340   while (!model_iterator->Run()) {
341     model_iterator = model_iterator->NextModel;
342     if (model_iterator == 0L) break;
343   }
344
345   frame = Frame++;
346   State->IncrTime();
347   return true;
348 }
349
350 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
351
352 bool FGFDMExec::RunIC(FGInitialCondition *fgic)
353 {
354   State->Suspend();
355   State->Initialize(fgic);
356   Run();
357   State->Resume();
358   return true;
359 }
360
361 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
362
363 void FGFDMExec::TransferState(int idxFDM)
364 {
365   SlaveFDMList[idxFDM]->exec->GetRotation()->SetEuler(Rotation->GetEuler());
366   SlaveFDMList[idxFDM]->exec->GetRotation()->SetAeroPQR(Rotation->GetAeroPQR());
367   SlaveFDMList[idxFDM]->exec->GetTranslation()->SetAeroUVW(Translation->GetAeroUVW());
368   SlaveFDMList[idxFDM]->exec->GetRotation()->SetEuler(Rotation->GetEuler());
369 }
370
371 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
372
373 vector <string> FGFDMExec::EnumerateFDMs(void)
374 {
375   vector <string> FDMList;
376
377   FDMList.push_back(Aircraft->GetAircraftName());
378
379   for (unsigned int i=1; i<SlaveFDMList.size(); i++) {
380     FDMList.push_back(SlaveFDMList[i]->exec->GetAircraft()->GetAircraftName());
381   }
382
383   return FDMList;
384 }
385
386 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387
388 bool FGFDMExec::LoadModel(string APath, string EPath, string model)
389 {
390   bool result = true;
391   string token;
392   string aircraftCfgFileName;
393
394   AircraftPath = APath;
395   EnginePath   = EPath;
396
397 # ifndef macintosh
398   aircraftCfgFileName = AircraftPath + "/" + model + "/" + model + ".xml";
399 # else
400   aircraftCfgFileName = AircraftPath + ";" + model + ";" + model + ".xml";
401 # endif
402
403   FGConfigFile AC_cfg(aircraftCfgFileName);
404   if (!AC_cfg.IsOpen()) return false;
405
406   if (modelLoaded) {
407     DeAllocate();
408     Allocate();
409   }
410
411   if (!ReadPrologue(&AC_cfg)) return false;
412
413   while ((AC_cfg.GetNextConfigLine() != string("EOF")) &&
414          (token = AC_cfg.GetValue()) != string("/FDM_CONFIG")) {
415     if (token == "METRICS") {
416       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Metrics" << fgdef << endl;
417       if (!ReadMetrics(&AC_cfg)) result = false;
418     } else if (token == "SLAVE") {
419       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Slave flight vehicle: " << fgdef
420                                         << AC_cfg.GetValue("NAME") << endl;
421       if (!ReadSlave(&AC_cfg)) result = false;
422     } else if (token == "AERODYNAMICS") {
423       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Aerodynamics" << fgdef << endl;
424       if (!ReadAerodynamics(&AC_cfg)) result = false;
425     } else if (token == "UNDERCARRIAGE") {
426       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Landing Gear" << fgdef << endl;
427       if (!ReadUndercarriage(&AC_cfg)) result = false;
428     } else if (token == "PROPULSION") {
429       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Propulsion" << fgdef << endl;
430       if (!ReadPropulsion(&AC_cfg)) result = false;
431     } else if (token == "FLIGHT_CONTROL") {
432       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Flight Control" << fgdef << endl;
433       if (!ReadFlightControls(&AC_cfg)) result = false;
434     } else if (token == "OUTPUT") {
435       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Output directives" << fgdef << endl;
436       if (!ReadOutput(&AC_cfg)) result = false;
437     }
438   }
439
440   if (result) {
441     modelLoaded = true;
442     Debug(3);
443   } else {
444     cerr << fgred
445          << "  FGFDMExec: Failed to load aircraft and/or engine model"
446          << fgdef << endl;
447   }
448
449   return result;
450 }
451
452 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
453
454 bool FGFDMExec::ReadPrologue(FGConfigFile* AC_cfg)
455 {
456   string token = AC_cfg->GetValue();
457   string scratch;
458   string AircraftName;
459
460   AircraftName = AC_cfg->GetValue("NAME");
461   Aircraft->SetAircraftName(AircraftName);
462
463   if (debug_lvl > 0) cout << underon << "Reading Aircraft Configuration File"
464             << underoff << ": " << highint << AircraftName << normint << endl;
465   scratch = AC_cfg->GetValue("VERSION").c_str();
466
467   CFGVersion = AC_cfg->GetValue("VERSION");
468
469   if (debug_lvl > 0)
470     cout << "                            Version: " << highint << CFGVersion
471                                                     << normint << endl;
472   if (CFGVersion != needed_cfg_version) {
473     cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
474             " RESULTS WILL BE UNPREDICTABLE !!" << endl;
475     cerr << "Current version needed is: " << needed_cfg_version << endl;
476     cerr << "         You have version: " << CFGVersion << endl << fgdef << endl;
477     return false;
478   }
479
480   return true;
481 }
482
483 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
484
485 bool FGFDMExec::ReadSlave(FGConfigFile* AC_cfg)
486 {
487   // Add a new slaveData object to the slave FDM list
488   // Populate that slaveData element with a new FDMExec object
489   // Set the IsSlave flag for that FDMExec object
490   // Get the aircraft name
491   // set debug level to print out no additional data for slave objects
492   // Load the model given the aircraft name
493   // reset debug level to prior setting
494
495   int saved_debug_lvl = debug_lvl;
496
497   SlaveFDMList.push_back(new slaveData);
498   SlaveFDMList.back()->exec = new FGFDMExec();
499   SlaveFDMList.back()->exec->SetSlave();
500
501   string AircraftName = AC_cfg->GetValue("FILE");
502
503   debug_lvl = 0;
504   SlaveFDMList.back()->exec->LoadModel("aircraft", "engine", AircraftName);
505   debug_lvl = saved_debug_lvl;
506
507   return true;
508 }
509
510 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
511
512 bool FGFDMExec::ReadPropulsion(FGConfigFile* AC_cfg)
513 {
514   if (!Propulsion->Load(AC_cfg)) {
515     cerr << "  Propulsion not successfully loaded" << endl;
516     return false;
517   }
518   return true;
519 }
520
521 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
522
523 bool FGFDMExec::ReadFlightControls(FGConfigFile* AC_cfg)
524 {
525   if (!FCS->Load(AC_cfg)) {
526     cerr << "  Flight Controls not successfully loaded" << endl;
527     return false;
528   }
529   return true;
530 }
531
532 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
533
534 bool FGFDMExec::ReadAerodynamics(FGConfigFile* AC_cfg)
535 {
536   if (!Aerodynamics->Load(AC_cfg)) {
537     cerr << "  Aerodynamics not successfully loaded" << endl;
538     return false;
539   }
540   return true;
541 }
542
543 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
544
545 bool FGFDMExec::ReadUndercarriage(FGConfigFile* AC_cfg)
546 {
547   if (!GroundReactions->Load(AC_cfg)) {
548     cerr << "  Ground Reactions not successfully loaded" << endl;
549     return false;
550   }
551   return true;
552 }
553
554 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
555
556 bool FGFDMExec::ReadMetrics(FGConfigFile* AC_cfg)
557 {
558   if (!Aircraft->Load(AC_cfg)) {
559     cerr << "  Aircraft metrics not successfully loaded" << endl;
560     return false;
561   }
562   return true;
563 }
564
565 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
566
567 bool FGFDMExec::ReadOutput(FGConfigFile* AC_cfg)
568 {
569   if (!Output->Load(AC_cfg)) {
570     cerr << "  Output not successfully loaded" << endl;
571     return false;
572   }
573   return true;
574 }
575
576 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
577
578 FGPropertyManager* FGFDMExec::GetPropertyManager(void) { 
579   return instance;
580 }
581
582 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
583 //    The bitmasked value choices are as follows:
584 //    unset: In this case (the default) JSBSim would only print
585 //       out the normally expected messages, essentially echoing
586 //       the config files as they are read. If the environment
587 //       variable is not set, debug_lvl is set to 1 internally
588 //    0: This requests JSBSim not to output any messages
589 //       whatsoever.
590 //    1: This value explicity requests the normal JSBSim
591 //       startup messages
592 //    2: This value asks for a message to be printed out when
593 //       a class is instantiated
594 //    4: When this value is set, a message is displayed when a
595 //       FGModel object executes its Run() method
596 //    8: When this value is set, various runtime state variables
597 //       are printed out periodically
598 //    16: When set various parameters are sanity checked and
599 //       a message is printed out when they go out of bounds
600
601 void FGFDMExec::Debug(int from)
602 {
603   if (debug_lvl <= 0) return;
604
605   if (debug_lvl & 1) { // Standard console startup message output
606     if (from == 0) { // Constructor
607       cout << "\n\n     " << highint << underon << "JSBSim Flight Dynamics Model v"
608                                      << JSBSim_version << underoff << normint << endl;
609       cout << halfint << "            [cfg file spec v" << needed_cfg_version << "]\n\n";
610       cout << normint << "JSBSim startup beginning ...\n\n";
611     } else if (from == 3) {
612       cout << "\n\nJSBSim startup complete\n\n";
613     }
614   }
615   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
616     if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
617     if (from == 1) cout << "Destroyed:    FGFDMExec" << endl;
618   }
619   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
620     if (from == 2) {
621       cout << "================== Frame: " << Frame << "  Time: "
622            << State->Getsim_time() << endl;
623     }
624   }
625   if (debug_lvl & 8 ) { // Runtime state variables
626   }
627   if (debug_lvl & 16) { // Sanity checking
628   }
629   if (debug_lvl & 64) {
630     if (from == 0) { // Constructor
631       cout << IdSrc << endl;
632       cout << IdHdr << endl;
633     }
634   }
635 }
636