]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFDMExec.cpp
dac9eedacb1701d38a4963e597feea5c2c557ac1
[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                 bool addModelToPath)
389 {
390
391   FGFDMExec::AircraftPath = AircraftPath;
392   FGFDMExec::EnginePath = EnginePath;
393
394   return LoadModel(model, addModelToPath);
395 }
396
397 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
398
399
400 bool FGFDMExec::LoadModel(string model, bool addModelToPath)
401 {
402   
403   bool result = true;
404   string token;
405   string aircraftCfgFileName;
406
407   if( AircraftPath.empty() || EnginePath.empty() ) {
408     cerr << "Error: attempted to load aircraft with undefined ";
409     cerr << "aircraft and engine paths" << endl;
410     return false;
411   }
412
413   aircraftCfgFileName = AircraftPath;
414 # ifndef macintosh
415   if (addModelToPath) aircraftCfgFileName += "/" + model;
416   aircraftCfgFileName += "/" + model + ".xml";
417 # else
418   if (addModelToPath) aircraftCfgFileName += ";"  + model;
419   aircraftCfgFileName += ";"  + model + ".xml";
420 # endif
421
422   FGConfigFile AC_cfg(aircraftCfgFileName);
423   if (!AC_cfg.IsOpen()) return false;
424
425   modelName = model;
426
427   if (modelLoaded) {
428     DeAllocate();
429     Allocate();
430   }
431
432   if (!ReadPrologue(&AC_cfg)) return false;
433
434   while ((AC_cfg.GetNextConfigLine() != string("EOF")) &&
435          (token = AC_cfg.GetValue()) != string("/FDM_CONFIG")) {
436     if (token == "METRICS") {
437       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Metrics" << fgdef << endl;
438       if (!ReadMetrics(&AC_cfg)) result = false;
439     } else if (token == "SLAVE") {
440       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Slave flight vehicle: " << fgdef
441                                         << AC_cfg.GetValue("NAME") << endl;
442       if (!ReadSlave(&AC_cfg)) result = false;
443     } else if (token == "AERODYNAMICS") {
444       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Aerodynamics" << fgdef << endl;
445       if (!ReadAerodynamics(&AC_cfg)) result = false;
446     } else if (token == "UNDERCARRIAGE") {
447       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Landing Gear" << fgdef << endl;
448       if (!ReadUndercarriage(&AC_cfg)) result = false;
449     } else if (token == "PROPULSION") {
450       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Propulsion" << fgdef << endl;
451       if (!ReadPropulsion(&AC_cfg)) result = false;
452     } else if (token == "FLIGHT_CONTROL") {
453       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Flight Control" << fgdef << endl;
454       if (!ReadFlightControls(&AC_cfg)) result = false;
455     } else if (token == "AUTOPILOT") {
456       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Autopilot" << fgdef << endl;
457       if (!ReadFlightControls(&AC_cfg)) result = false;
458     } else if (token == "OUTPUT") {
459       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Output directives" << fgdef << endl;
460       if (!ReadOutput(&AC_cfg)) result = false;
461     }
462   }
463
464   if (result) {
465     modelLoaded = true;
466     Debug(3);
467   } else {
468     cerr << fgred
469          << "  FGFDMExec: Failed to load aircraft and/or engine model"
470          << fgdef << endl;
471   }
472
473   return result;
474 }
475
476 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
477
478 bool FGFDMExec::ReadPrologue(FGConfigFile* AC_cfg)
479 {
480   string token = AC_cfg->GetValue();
481   string scratch;
482   string AircraftName;
483
484   AircraftName = AC_cfg->GetValue("NAME");
485   Aircraft->SetAircraftName(AircraftName);
486
487   if (debug_lvl > 0) cout << underon << "Reading Aircraft Configuration File"
488             << underoff << ": " << highint << AircraftName << normint << endl;
489   scratch = AC_cfg->GetValue("VERSION").c_str();
490
491   CFGVersion = AC_cfg->GetValue("VERSION");
492   Release    = AC_cfg->GetValue("RELEASE");
493
494   if (debug_lvl > 0)
495     cout << "                            Version: " << highint << CFGVersion
496                                                     << normint << endl;
497   if (CFGVersion != needed_cfg_version) {
498     cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
499             " RESULTS WILL BE UNPREDICTABLE !!" << endl;
500     cerr << "Current version needed is: " << needed_cfg_version << endl;
501     cerr << "         You have version: " << CFGVersion << endl << fgdef << endl;
502     return false;
503   }
504
505   if (Release == "ALPHA") {
506     system("banner ALPHA");
507     cout << endl << endl
508          << highint << "This aircraft model is an " << fgred << Release
509          << reset << highint << " release!!!" << endl << endl << reset
510          << "This aircraft model may not even properly load, and probably"
511          << " will not fly as expected." << endl << endl
512          << fgred << highint << "Use this model for development purposes ONLY!!!"
513          << normint << reset << endl << endl;
514   } else if (Release == "BETA") {
515     system("banner BETA");
516     cout << endl << endl
517          << highint << "This aircraft model is a " << fgred << Release
518          << reset << highint << " release!!!" << endl << endl << reset
519          << "This aircraft model probably will not fly as expected." << endl << endl
520          << fgblue << highint << "Use this model for development purposes ONLY!!!"
521          << normint << reset << endl << endl;
522   }
523
524   return true;
525 }
526
527 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
528
529 bool FGFDMExec::ReadSlave(FGConfigFile* AC_cfg)
530 {
531   // Add a new slaveData object to the slave FDM list
532   // Populate that slaveData element with a new FDMExec object
533   // Set the IsSlave flag for that FDMExec object
534   // Get the aircraft name
535   // set debug level to print out no additional data for slave objects
536   // Load the model given the aircraft name
537   // reset debug level to prior setting
538
539   int saved_debug_lvl = debug_lvl;
540   string token;
541
542   SlaveFDMList.push_back(new slaveData);
543   SlaveFDMList.back()->exec = new FGFDMExec();
544   SlaveFDMList.back()->exec->SetSlave();
545
546   string AircraftName = AC_cfg->GetValue("FILE");
547
548   debug_lvl = 0;                 // turn off debug output for slave vehicle
549
550   SlaveFDMList.back()->exec->SetAircraftPath( AircraftPath );
551   SlaveFDMList.back()->exec->SetEnginePath( EnginePath );
552   SlaveFDMList.back()->exec->LoadModel(AircraftName);
553   debug_lvl = saved_debug_lvl;   // turn debug output back on for master vehicle
554
555   AC_cfg->GetNextConfigLine();
556   while ((token = AC_cfg->GetValue()) != string("/SLAVE")) {
557     *AC_cfg >> token;
558     if      (token == "XLOC")  { *AC_cfg >> SlaveFDMList.back()->x;    }
559     else if (token == "YLOC")  { *AC_cfg >> SlaveFDMList.back()->y;    }
560     else if (token == "ZLOC")  { *AC_cfg >> SlaveFDMList.back()->z;    }
561     else if (token == "PITCH") { *AC_cfg >> SlaveFDMList.back()->pitch;}
562     else if (token == "YAW")   { *AC_cfg >> SlaveFDMList.back()->yaw;  }
563     else if (token == "ROLL")  { *AC_cfg >> SlaveFDMList.back()->roll;  }
564     else cerr << "Unknown identifier: " << token << " in slave vehicle definition" << endl;
565   }
566
567   if (debug_lvl > 0)  {
568     cout << "      X = " << SlaveFDMList.back()->x << endl;
569     cout << "      Y = " << SlaveFDMList.back()->y << endl;
570     cout << "      Z = " << SlaveFDMList.back()->z << endl;
571     cout << "      Pitch = " << SlaveFDMList.back()->pitch << endl;
572     cout << "      Yaw = " << SlaveFDMList.back()->yaw << endl;
573     cout << "      Roll = " << SlaveFDMList.back()->roll << endl;
574   }
575
576   return true;
577 }
578
579 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
580
581 bool FGFDMExec::ReadPropulsion(FGConfigFile* AC_cfg)
582 {
583   if (!Propulsion->Load(AC_cfg)) {
584     cerr << "  Propulsion not successfully loaded" << endl;
585     return false;
586   }
587   return true;
588 }
589
590 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
591
592 bool FGFDMExec::ReadFlightControls(FGConfigFile* AC_cfg)
593 {
594   if (!FCS->Load(AC_cfg)) {
595     cerr << "  Flight Controls not successfully loaded" << endl;
596     return false;
597   }
598   return true;
599 }
600
601 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
602
603 bool FGFDMExec::ReadAerodynamics(FGConfigFile* AC_cfg)
604 {
605   if (!Aerodynamics->Load(AC_cfg)) {
606     cerr << "  Aerodynamics not successfully loaded" << endl;
607     return false;
608   }
609   return true;
610 }
611
612 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
613
614 bool FGFDMExec::ReadUndercarriage(FGConfigFile* AC_cfg)
615 {
616   if (!GroundReactions->Load(AC_cfg)) {
617     cerr << "  Ground Reactions not successfully loaded" << endl;
618     return false;
619   }
620   return true;
621 }
622
623 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
624
625 bool FGFDMExec::ReadMetrics(FGConfigFile* AC_cfg)
626 {
627   if (!Aircraft->Load(AC_cfg)) {
628     cerr << "  Aircraft metrics not successfully loaded" << endl;
629     return false;
630   }
631   return true;
632 }
633
634 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
635
636 bool FGFDMExec::ReadOutput(FGConfigFile* AC_cfg)
637 {
638   if (!Output->Load(AC_cfg)) {
639     cerr << "  Output not successfully loaded" << endl;
640     return false;
641   }
642   return true;
643 }
644
645 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
646
647 FGPropertyManager* FGFDMExec::GetPropertyManager(void) {
648   return instance;
649 }
650
651 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
652
653 FGTrim* FGFDMExec::GetTrim(void) {
654   delete Trim;
655   Trim = new FGTrim(this,tNone);
656   return Trim;
657 }
658
659 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
660 //    The bitmasked value choices are as follows:
661 //    unset: In this case (the default) JSBSim would only print
662 //       out the normally expected messages, essentially echoing
663 //       the config files as they are read. If the environment
664 //       variable is not set, debug_lvl is set to 1 internally
665 //    0: This requests JSBSim not to output any messages
666 //       whatsoever.
667 //    1: This value explicity requests the normal JSBSim
668 //       startup messages
669 //    2: This value asks for a message to be printed out when
670 //       a class is instantiated
671 //    4: When this value is set, a message is displayed when a
672 //       FGModel object executes its Run() method
673 //    8: When this value is set, various runtime state variables
674 //       are printed out periodically
675 //    16: When set various parameters are sanity checked and
676 //       a message is printed out when they go out of bounds
677
678 void FGFDMExec::Debug(int from)
679 {
680   if (debug_lvl <= 0) return;
681
682   if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output
683     if (from == 0) { // Constructor
684       cout << "\n\n     " << highint << underon << "JSBSim Flight Dynamics Model v"
685                                      << JSBSim_version << underoff << normint << endl;
686       cout << halfint << "            [cfg file spec v" << needed_cfg_version << "]\n\n";
687       cout << normint << "JSBSim startup beginning ...\n\n";
688     } else if (from == 3) {
689       cout << "\n\nJSBSim startup complete\n\n";
690     }
691   }
692   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
693     if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
694     if (from == 1) cout << "Destroyed:    FGFDMExec" << endl;
695   }
696   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
697     if (from == 2) {
698       cout << "================== Frame: " << Frame << "  Time: "
699            << State->Getsim_time() << endl;
700     }
701   }
702   if (debug_lvl & 8 ) { // Runtime state variables
703   }
704   if (debug_lvl & 16) { // Sanity checking
705   }
706   if (debug_lvl & 64) {
707     if (from == 0) { // Constructor
708       cout << IdSrc << endl;
709       cout << IdHdr << endl;
710     }
711   }
712 }
713 }
714