]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFDMExec.cpp
3002ec56bdc2f44175b5eeba46acd7ccbaef58ac
[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__) && (_COMPILER_VERSION < 740)
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 "FGPropagate.h"
68 #include "FGAuxiliary.h"
69 #include "FGOutput.h"
70 #include "FGConfigFile.h"
71 #include "FGInitialCondition.h"
72 #include "FGPropertyManager.h"
73
74 namespace JSBSim {
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 void checkTied ( FGPropertyManager *node )
91 {
92   int N = node->nChildren();
93   string name;
94
95   for (int i=0; i<N; i++) {
96     if (node->getChild(i)->nChildren() ) {
97       checkTied( (FGPropertyManager*)node->getChild(i) );
98     } else if ( node->getChild(i)->isTied() ) {
99       name = ((FGPropertyManager*)node->getChild(i))->GetFullyQualifiedName();
100       cerr << name << " is tied" << endl;
101     }
102   }
103 }
104
105 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 // Constructor
107
108 FGFDMExec::FGFDMExec(FGPropertyManager* root)
109 {
110
111   Frame           = 0;
112   FirstModel      = 0;
113   Error           = 0;
114   State           = 0;
115   Atmosphere      = 0;
116   FCS             = 0;
117   Propulsion      = 0;
118   MassBalance     = 0;
119   Aerodynamics    = 0;
120   Inertial        = 0;
121   GroundReactions = 0;
122   Aircraft        = 0;
123   Propagate       = 0;
124   Auxiliary       = 0;
125   Output          = 0;
126   IC              = 0;
127   Trim            = 0;
128
129   terminate = false;
130   frozen = false;
131   modelLoaded = false;
132   IsSlave = false;
133
134   IdFDM = FDMctr;
135   FDMctr++;
136
137   try {
138     char* num = getenv("JSBSIM_DEBUG");
139     if (num) debug_lvl = atoi(num); // set debug level
140   } catch (...) {               // if error set to 1
141     debug_lvl = 1;
142   }
143
144   if (root == 0)  master= new FGPropertyManager;
145   else            master = root;
146
147   instance = master->GetNode("/fdm/jsbsim",IdFDM,true);
148
149
150   Debug(0);
151
152   // this is here to catch errors in binding member functions
153   // to the property tree.
154   try {
155     Allocate();
156   } catch ( string msg ) {
157     cout << "Caught error: " << msg << endl;
158     exit(1);
159   }
160 }
161
162 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163
164 FGFDMExec::~FGFDMExec()
165 {
166   try {
167     DeAllocate();
168     checkTied( instance );
169   } catch ( string msg ) {
170     cout << "Caught error: " << msg << endl;
171   }
172
173   for (unsigned int i=1; i<SlaveFDMList.size(); i++) delete SlaveFDMList[i]->exec;
174   SlaveFDMList.clear();
175
176   Debug(1);
177 }
178
179 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180
181 bool FGFDMExec::Allocate(void)
182 {
183   bool result=true;
184
185   Atmosphere      = new FGAtmosphere(this);
186   FCS             = new FGFCS(this);
187   Propulsion      = new FGPropulsion(this);
188   MassBalance     = new FGMassBalance(this);
189   Aerodynamics    = new FGAerodynamics (this);
190   Inertial        = new FGInertial(this);
191   GroundReactions = new FGGroundReactions(this);
192   Aircraft        = new FGAircraft(this);
193   Propagate       = new FGPropagate(this);
194   Auxiliary       = new FGAuxiliary(this);
195   Output          = new FGOutput(this);
196
197   State        = new FGState(this); // This must be done here, as the FGState
198                                     // class needs valid pointers to the above
199                                     // model classes
200
201   // Initialize models so they can communicate with each other
202
203   if (!Atmosphere->InitModel()) {
204     cerr << fgred << "Atmosphere model init failed" << fgdef << endl;
205     Error+=1;}
206   if (!FCS->InitModel())        {
207     cerr << fgred << "FCS model init failed" << fgdef << endl;
208     Error+=2;}
209   if (!Propulsion->InitModel()) {
210     cerr << fgred << "FGPropulsion model init failed" << fgdef << endl;
211     Error+=4;}
212   if (!MassBalance->InitModel()) {
213     cerr << fgred << "FGMassBalance model init failed" << fgdef << endl;
214     Error+=8;}
215   if (!Aerodynamics->InitModel()) {
216     cerr << fgred << "FGAerodynamics model init failed" << fgdef << endl;
217     Error+=16;}
218   if (!Inertial->InitModel()) {
219     cerr << fgred << "FGInertial model init failed" << fgdef << endl;
220     Error+=32;}
221   if (!GroundReactions->InitModel())   {
222     cerr << fgred << "Ground Reactions model init failed" << fgdef << endl;
223     Error+=64;}
224   if (!Aircraft->InitModel())   {
225     cerr << fgred << "Aircraft model init failed" << fgdef << endl;
226     Error+=128;}
227   if (!Propagate->InitModel())   {
228     cerr << fgred << "Propagate model init failed" << fgdef << endl;
229     Error+=512;}
230   if (!Auxiliary->InitModel())  {
231     cerr << fgred << "Auxiliary model init failed" << fgdef << endl;
232     Error+=2058;}
233   if (!Output->InitModel())     {
234     cerr << fgred << "Output model init failed" << fgdef << endl;
235     Error+=4096;}
236
237   if (Error > 0) result = false;
238
239   IC = new FGInitialCondition(this);
240
241   // Schedule a model. The second arg (the integer) is the pass number. For
242   // instance, the atmosphere model gets executed every fifth pass it is called
243   // by the executive. Everything else here gets executed each pass.
244   // IC and Trim objects are NOT scheduled.
245
246   Schedule(Atmosphere,      1);
247   Schedule(FCS,             1);
248   Schedule(Propulsion,      1);
249   Schedule(MassBalance,     1);
250   Schedule(Aerodynamics,    1);
251   Schedule(Inertial,        1);
252   Schedule(GroundReactions, 1);
253   Schedule(Aircraft,        1);
254   Schedule(Propagate,       1);
255   Schedule(Auxiliary,       1);
256   Schedule(Output,          1);
257
258   modelLoaded = false;
259
260   return result;
261 }
262
263 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264
265 bool FGFDMExec::DeAllocate(void)
266 {
267   delete Atmosphere;
268   delete FCS;
269   delete Propulsion;
270   delete MassBalance;
271   delete Aerodynamics;
272   delete Inertial;
273   delete GroundReactions;
274   delete Aircraft;
275   delete Propagate;
276   delete Auxiliary;
277   delete Output;
278   delete State;
279
280   delete IC;
281   delete Trim;
282
283   FirstModel  = 0L;
284   Error       = 0;
285
286   State           = 0;
287   Atmosphere      = 0;
288   FCS             = 0;
289   Propulsion      = 0;
290   MassBalance     = 0;
291   Aerodynamics    = 0;
292   Inertial        = 0;
293   GroundReactions = 0;
294   Aircraft        = 0;
295   Propagate       = 0;
296   Auxiliary       = 0;
297   Output          = 0;
298
299   modelLoaded = false;
300   return modelLoaded;
301 }
302
303 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304
305 int FGFDMExec::Schedule(FGModel* model, int rate)
306 {
307   FGModel* model_iterator;
308
309   model_iterator = FirstModel;
310
311   if (model_iterator == 0L) {                  // this is the first model
312
313     FirstModel = model;
314     FirstModel->NextModel = 0L;
315     FirstModel->SetRate(rate);
316
317   } else {                                     // subsequent model
318
319     while (model_iterator->NextModel != 0L) {
320       model_iterator = model_iterator->NextModel;
321     }
322     model_iterator->NextModel = model;
323     model_iterator->NextModel->SetRate(rate);
324
325   }
326
327   return 0;
328 }
329
330 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331
332 bool FGFDMExec::Run(void)
333 {
334   FGModel* model_iterator;
335
336   if (frozen) return true;
337
338   model_iterator = FirstModel;
339   if (model_iterator == 0L) return false;
340
341   Debug(2);
342
343   for (unsigned int i=1; i<SlaveFDMList.size(); i++) {
344 //    SlaveFDMList[i]->exec->State->Initialize(); // Transfer state to the slave FDM
345 //    SlaveFDMList[i]->exec->Run();
346   }
347
348   while (model_iterator != 0L) {
349     model_iterator->Run();
350     model_iterator = model_iterator->NextModel;
351   }
352
353   frame = Frame++;
354   State->IncrTime();
355   return true;
356 }
357
358 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
359
360 bool FGFDMExec::RunIC(void)
361 {
362   State->Suspend();
363   State->Initialize(IC);
364   Run();
365   State->Resume();
366
367   return true;
368 }
369
370 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
371
372 vector <string> FGFDMExec::EnumerateFDMs(void)
373 {
374   vector <string> FDMList;
375
376   FDMList.push_back(Aircraft->GetAircraftName());
377
378   for (unsigned int i=1; i<SlaveFDMList.size(); i++) {
379     FDMList.push_back(SlaveFDMList[i]->exec->GetAircraft()->GetAircraftName());
380   }
381
382   return FDMList;
383 }
384
385 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
386
387 bool FGFDMExec::LoadModel(string AircraftPath, string EnginePath, string model)
388 {
389   FGFDMExec::AircraftPath = AircraftPath;
390   FGFDMExec::EnginePath = EnginePath;
391
392   return LoadModel(model);
393 }
394
395 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
396
397 bool FGFDMExec::LoadModel(string model)
398 {
399   bool result = true;
400   string token;
401   string aircraftCfgFileName;
402
403   if( AircraftPath.empty() || EnginePath.empty() ) {
404     cerr << "Error: attempted to load aircraft with undefined ";
405     cerr << "aircraft and engine paths" << endl;
406     return false;
407   }
408
409 # ifndef macintosh
410   aircraftCfgFileName = AircraftPath + "/"  + model + ".xml";
411 # else
412   aircraftCfgFileName = AircraftPath + ";"  + model + ".xml";
413 # endif
414
415   FGConfigFile AC_cfg(aircraftCfgFileName);
416   if (!AC_cfg.IsOpen()) return false;
417
418   modelName = model;
419
420   if (modelLoaded) {
421     DeAllocate();
422     Allocate();
423   }
424
425   if (!ReadPrologue(&AC_cfg)) return false;
426
427   while ((AC_cfg.GetNextConfigLine() != string("EOF")) &&
428          (token = AC_cfg.GetValue()) != string("/FDM_CONFIG")) {
429     if (token == "METRICS") {
430       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Metrics" << fgdef << endl;
431       if (!ReadMetrics(&AC_cfg)) result = false;
432     } else if (token == "SLAVE") {
433       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Slave flight vehicle: " << fgdef
434                                         << AC_cfg.GetValue("NAME") << endl;
435       if (!ReadSlave(&AC_cfg)) result = false;
436     } else if (token == "AERODYNAMICS") {
437       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Aerodynamics" << fgdef << endl;
438       if (!ReadAerodynamics(&AC_cfg)) result = false;
439     } else if (token == "UNDERCARRIAGE") {
440       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Landing Gear" << fgdef << endl;
441       if (!ReadUndercarriage(&AC_cfg)) result = false;
442     } else if (token == "PROPULSION") {
443       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Propulsion" << fgdef << endl;
444       if (!ReadPropulsion(&AC_cfg)) result = false;
445     } else if (token == "FLIGHT_CONTROL") {
446       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Flight Control" << fgdef << endl;
447       if (!ReadFlightControls(&AC_cfg)) result = false;
448     } else if (token == "AUTOPILOT") {
449       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Autopilot" << fgdef << endl;
450       if (!ReadFlightControls(&AC_cfg)) result = false;
451     } else if (token == "OUTPUT") {
452       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Output directives" << fgdef << endl;
453       if (!ReadOutput(&AC_cfg)) result = false;
454     }
455   }
456
457   if (result) {
458     modelLoaded = true;
459     Debug(3);
460   } else {
461     cerr << fgred
462          << "  FGFDMExec: Failed to load aircraft and/or engine model"
463          << fgdef << endl;
464   }
465
466   return result;
467 }
468
469 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
470
471 bool FGFDMExec::ReadPrologue(FGConfigFile* AC_cfg)
472 {
473   string token = AC_cfg->GetValue();
474   string scratch;
475   string AircraftName;
476
477   AircraftName = AC_cfg->GetValue("NAME");
478   Aircraft->SetAircraftName(AircraftName);
479
480   if (debug_lvl > 0) cout << underon << "Reading Aircraft Configuration File"
481             << underoff << ": " << highint << AircraftName << normint << endl;
482   scratch = AC_cfg->GetValue("VERSION").c_str();
483
484   CFGVersion = AC_cfg->GetValue("VERSION");
485   Release    = AC_cfg->GetValue("RELEASE");
486
487   if (debug_lvl > 0)
488     cout << "                            Version: " << highint << CFGVersion
489                                                     << normint << endl;
490   if (CFGVersion != needed_cfg_version) {
491     cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
492             " RESULTS WILL BE UNPREDICTABLE !!" << endl;
493     cerr << "Current version needed is: " << needed_cfg_version << endl;
494     cerr << "         You have version: " << CFGVersion << endl << fgdef << endl;
495     return false;
496   }
497
498   if (Release == "ALPHA") {
499     system("banner ALPHA");
500     cout << endl << endl
501          << highint << "This aircraft model is an " << fgred << Release
502          << reset << highint << " release!!!" << endl << endl << reset
503          << "This aircraft model may not even properly load, and probably"
504          << " will not fly as expected." << endl << endl
505          << fgred << highint << "Use this model for development purposes ONLY!!!"
506          << normint << reset << endl << endl;
507   } else if (Release == "BETA") {
508     system("banner BETA");
509     cout << endl << endl
510          << highint << "This aircraft model is a " << fgred << Release
511          << reset << highint << " release!!!" << endl << endl << reset
512          << "This aircraft model probably will not fly as expected." << endl << endl
513          << fgblue << highint << "Use this model for development purposes ONLY!!!"
514          << normint << reset << endl << endl;
515   }
516
517   return true;
518 }
519
520 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
521
522 bool FGFDMExec::ReadSlave(FGConfigFile* AC_cfg)
523 {
524   // Add a new slaveData object to the slave FDM list
525   // Populate that slaveData element with a new FDMExec object
526   // Set the IsSlave flag for that FDMExec object
527   // Get the aircraft name
528   // set debug level to print out no additional data for slave objects
529   // Load the model given the aircraft name
530   // reset debug level to prior setting
531
532   int saved_debug_lvl = debug_lvl;
533   string token;
534
535   SlaveFDMList.push_back(new slaveData);
536   SlaveFDMList.back()->exec = new FGFDMExec();
537   SlaveFDMList.back()->exec->SetSlave();
538
539   string AircraftName = AC_cfg->GetValue("FILE");
540
541   debug_lvl = 0;                 // turn off debug output for slave vehicle
542
543   SlaveFDMList.back()->exec->SetAircraftPath( AircraftPath );
544   SlaveFDMList.back()->exec->SetEnginePath( EnginePath );
545   SlaveFDMList.back()->exec->LoadModel(AircraftName);
546   debug_lvl = saved_debug_lvl;   // turn debug output back on for master vehicle
547
548   AC_cfg->GetNextConfigLine();
549   while ((token = AC_cfg->GetValue()) != string("/SLAVE")) {
550     *AC_cfg >> token;
551     if      (token == "XLOC")  { *AC_cfg >> SlaveFDMList.back()->x;    }
552     else if (token == "YLOC")  { *AC_cfg >> SlaveFDMList.back()->y;    }
553     else if (token == "ZLOC")  { *AC_cfg >> SlaveFDMList.back()->z;    }
554     else if (token == "PITCH") { *AC_cfg >> SlaveFDMList.back()->pitch;}
555     else if (token == "YAW")   { *AC_cfg >> SlaveFDMList.back()->yaw;  }
556     else if (token == "ROLL")  { *AC_cfg >> SlaveFDMList.back()->roll;  }
557     else cerr << "Unknown identifier: " << token << " in slave vehicle definition" << endl;
558   }
559
560   if (debug_lvl > 0)  {
561     cout << "      X = " << SlaveFDMList.back()->x << endl;
562     cout << "      Y = " << SlaveFDMList.back()->y << endl;
563     cout << "      Z = " << SlaveFDMList.back()->z << endl;
564     cout << "      Pitch = " << SlaveFDMList.back()->pitch << endl;
565     cout << "      Yaw = " << SlaveFDMList.back()->yaw << endl;
566     cout << "      Roll = " << SlaveFDMList.back()->roll << endl;
567   }
568
569   return true;
570 }
571
572 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
573
574 bool FGFDMExec::ReadPropulsion(FGConfigFile* AC_cfg)
575 {
576   if (!Propulsion->Load(AC_cfg)) {
577     cerr << "  Propulsion not successfully loaded" << endl;
578     return false;
579   }
580   return true;
581 }
582
583 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
584
585 bool FGFDMExec::ReadFlightControls(FGConfigFile* AC_cfg)
586 {
587   if (!FCS->Load(AC_cfg)) {
588     cerr << "  Flight Controls not successfully loaded" << endl;
589     return false;
590   }
591   return true;
592 }
593
594 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
595
596 bool FGFDMExec::ReadAerodynamics(FGConfigFile* AC_cfg)
597 {
598   if (!Aerodynamics->Load(AC_cfg)) {
599     cerr << "  Aerodynamics not successfully loaded" << endl;
600     return false;
601   }
602   return true;
603 }
604
605 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
606
607 bool FGFDMExec::ReadUndercarriage(FGConfigFile* AC_cfg)
608 {
609   if (!GroundReactions->Load(AC_cfg)) {
610     cerr << "  Ground Reactions not successfully loaded" << endl;
611     return false;
612   }
613   return true;
614 }
615
616 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
617
618 bool FGFDMExec::ReadMetrics(FGConfigFile* AC_cfg)
619 {
620   if (!Aircraft->Load(AC_cfg)) {
621     cerr << "  Aircraft metrics not successfully loaded" << endl;
622     return false;
623   }
624   return true;
625 }
626
627 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
628
629 bool FGFDMExec::ReadOutput(FGConfigFile* AC_cfg)
630 {
631   if (!Output->Load(AC_cfg)) {
632     cerr << "  Output not successfully loaded" << endl;
633     return false;
634   }
635   return true;
636 }
637
638 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
639
640 FGPropertyManager* FGFDMExec::GetPropertyManager(void) {
641   return instance;
642 }
643
644 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
645
646 FGTrim* FGFDMExec::GetTrim(void) {
647   delete Trim;
648   Trim = new FGTrim(this,tNone);
649   return Trim;
650 }
651
652 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
653 //    The bitmasked value choices are as follows:
654 //    unset: In this case (the default) JSBSim would only print
655 //       out the normally expected messages, essentially echoing
656 //       the config files as they are read. If the environment
657 //       variable is not set, debug_lvl is set to 1 internally
658 //    0: This requests JSBSim not to output any messages
659 //       whatsoever.
660 //    1: This value explicity requests the normal JSBSim
661 //       startup messages
662 //    2: This value asks for a message to be printed out when
663 //       a class is instantiated
664 //    4: When this value is set, a message is displayed when a
665 //       FGModel object executes its Run() method
666 //    8: When this value is set, various runtime state variables
667 //       are printed out periodically
668 //    16: When set various parameters are sanity checked and
669 //       a message is printed out when they go out of bounds
670
671 void FGFDMExec::Debug(int from)
672 {
673   if (debug_lvl <= 0) return;
674
675   if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output
676     if (from == 0) { // Constructor
677       cout << "\n\n     " << highint << underon << "JSBSim Flight Dynamics Model v"
678                                      << JSBSim_version << underoff << normint << endl;
679       cout << halfint << "            [cfg file spec v" << needed_cfg_version << "]\n\n";
680       cout << normint << "JSBSim startup beginning ...\n\n";
681     } else if (from == 3) {
682       cout << "\n\nJSBSim startup complete\n\n";
683     }
684   }
685   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
686     if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
687     if (from == 1) cout << "Destroyed:    FGFDMExec" << endl;
688   }
689   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
690     if (from == 2) {
691       cout << "================== Frame: " << Frame << "  Time: "
692            << State->Getsim_time() << endl;
693     }
694   }
695   if (debug_lvl & 8 ) { // Runtime state variables
696   }
697   if (debug_lvl & 16) { // Sanity checking
698   }
699   if (debug_lvl & 64) {
700     if (from == 0) { // Constructor
701       cout << IdSrc << endl;
702       cout << IdHdr << endl;
703     }
704   }
705 }
706 }
707