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