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