]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFDMExec.cpp
Fix line endings
[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 <models/FGAtmosphere.h>
60 #include <models/atmosphere/FGMSIS.h>
61 #include <models/atmosphere/FGMars.h>
62 #include <models/FGFCS.h>
63 #include <models/FGPropulsion.h>
64 #include <models/FGMassBalance.h>
65 #include <models/FGGroundReactions.h>
66 #include <models/FGAerodynamics.h>
67 #include <models/FGInertial.h>
68 #include <models/FGAircraft.h>
69 #include <models/FGPropagate.h>
70 #include <models/FGAuxiliary.h>
71 #include <models/FGInput.h>
72 #include <models/FGOutput.h>
73 #include <initialization/FGInitialCondition.h>
74 #include <input_output/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) : Root(root)
111 {
112
113   Frame           = 0;
114   FirstModel      = 0;
115   Error           = 0;
116   GroundCallback  = 0;
117   State           = 0;
118   Atmosphere      = 0;
119   FCS             = 0;
120   Propulsion      = 0;
121   MassBalance     = 0;
122   Aerodynamics    = 0;
123   Inertial        = 0;
124   GroundReactions = 0;
125   Aircraft        = 0;
126   Propagate       = 0;
127   Auxiliary       = 0;
128   Input           = 0;
129   IC              = 0;
130   Trim            = 0;
131
132   terminate = false;
133   modelLoaded = false;
134   IsSlave = false;
135   holding = false;
136
137
138   // Multiple FDM's are stopped for now.  We need to ensure that
139   // the "user" instance always gets the zeroeth instance number,
140   // because there may be instruments or scripts tied to properties
141   // in the jsbsim[0] node.
142   // ToDo: it could be that when JSBSim is reset and a new FDM is wanted, that
143   // process might try setting FDMctr = 0. Then the line below would not need
144   // to be commented out.
145   IdFDM = FDMctr;
146   //FDMctr++;
147
148   try {
149     char* num = getenv("JSBSIM_DEBUG");
150     if (num) debug_lvl = atoi(num); // set debug level
151   } catch (...) {               // if error set to 1
152     debug_lvl = 1;
153   }
154
155   if (Root == 0)  master= new FGPropertyManager;
156   else            master = Root;
157
158   instance = master->GetNode("/fdm/jsbsim",IdFDM,true);
159   Debug(0);
160   // this is to catch errors in binding member functions to the property tree.
161   try {
162     Allocate();
163   } catch ( string msg ) {
164     cout << "Caught error: " << msg << endl;
165     exit(1);
166   }
167
168   Constructing = true;
169   typedef int (FGFDMExec::*iPMF)(void) const;
170   instance->Tie("simulation/do_trim", this, (iPMF)0, &FGFDMExec::DoTrim);
171   Constructing = false;
172 }
173
174 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175
176 FGFDMExec::~FGFDMExec()
177 {
178   instance->Untie("simulation/do_trim");
179
180   try {
181     DeAllocate();
182     checkTied( instance );
183     if (Root == 0)  delete master;
184   } catch ( string msg ) {
185     cout << "Caught error: " << msg << endl;
186   }
187
188   for (unsigned int i=1; i<SlaveFDMList.size(); i++) delete SlaveFDMList[i]->exec;
189   SlaveFDMList.clear();
190
191   Debug(1);
192 }
193
194 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195
196 bool FGFDMExec::Allocate(void)
197 {
198   bool result=true;
199
200   Atmosphere      = new FGAtmosphere(this);
201   FCS             = new FGFCS(this);
202   Propulsion      = new FGPropulsion(this);
203   MassBalance     = new FGMassBalance(this);
204   Aerodynamics    = new FGAerodynamics (this);
205   Inertial        = new FGInertial(this);
206   GroundReactions = new FGGroundReactions(this);
207   Aircraft        = new FGAircraft(this);
208   Propagate       = new FGPropagate(this);
209   Auxiliary       = new FGAuxiliary(this);
210   Input           = new FGInput(this);
211
212   GroundCallback  = new FGGroundCallback();
213   State           = new FGState(this); // This must be done here, as the FGState
214                                        // class needs valid pointers to the above
215                                        // model classes
216
217   // Initialize models so they can communicate with each other
218
219   if (!Atmosphere->InitModel()) {
220     cerr << fgred << "Atmosphere model init failed" << fgdef << endl;
221     Error+=1;}
222   if (!FCS->InitModel())        {
223     cerr << fgred << "FCS model init failed" << fgdef << endl;
224     Error+=2;}
225   if (!Propulsion->InitModel()) {
226     cerr << fgred << "FGPropulsion model init failed" << fgdef << endl;
227     Error+=4;}
228   if (!MassBalance->InitModel()) {
229     cerr << fgred << "FGMassBalance model init failed" << fgdef << endl;
230     Error+=8;}
231   if (!Aerodynamics->InitModel()) {
232     cerr << fgred << "FGAerodynamics model init failed" << fgdef << endl;
233     Error+=16;}
234   if (!Inertial->InitModel()) {
235     cerr << fgred << "FGInertial model init failed" << fgdef << endl;
236     Error+=32;}
237   if (!GroundReactions->InitModel())   {
238     cerr << fgred << "Ground Reactions model init failed" << fgdef << endl;
239     Error+=64;}
240   if (!Aircraft->InitModel())   {
241     cerr << fgred << "Aircraft model init failed" << fgdef << endl;
242     Error+=128;}
243   if (!Propagate->InitModel())   {
244     cerr << fgred << "Propagate model init failed" << fgdef << endl;
245     Error+=256;}
246   if (!Auxiliary->InitModel())  {
247     cerr << fgred << "Auxiliary model init failed" << fgdef << endl;
248     Error+=512;}
249   if (!Input->InitModel())  {
250     cerr << fgred << "Input model init failed" << fgdef << endl;
251     Error+=1024;}
252
253   if (Error > 0) result = false;
254
255   IC = new FGInitialCondition(this);
256
257   // Schedule a model. The second arg (the integer) is the pass number. For
258   // instance, the atmosphere model could get executed every fifth pass it is called
259   // by the executive. IC and Trim objects are NOT scheduled.
260
261   Schedule(Input,           1);
262   Schedule(Atmosphere,      1);
263   Schedule(FCS,             1);
264   Schedule(Propulsion,      1);
265   Schedule(MassBalance,     1);
266   Schedule(Aerodynamics,    1);
267   Schedule(Inertial,        1);
268   Schedule(GroundReactions, 1);
269   Schedule(Aircraft,        1);
270   Schedule(Propagate,       1);
271   Schedule(Auxiliary,       1);
272
273   modelLoaded = false;
274
275   return result;
276 }
277
278 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
279
280 bool FGFDMExec::DeAllocate(void)
281 {
282   delete Input;
283   delete Atmosphere;
284   delete FCS;
285   delete Propulsion;
286   delete MassBalance;
287   delete Aerodynamics;
288   delete Inertial;
289   delete GroundReactions;
290   delete Aircraft;
291   delete Propagate;
292   delete Auxiliary;
293   delete State;
294
295   for (int i=0; i<Outputs.size(); i++) {
296     if (Outputs[i]) delete Outputs[i];
297   }
298
299   Outputs.clear();
300
301   delete IC;
302   delete Trim;
303
304   delete GroundCallback;
305
306   FirstModel  = 0L;
307   Error       = 0;
308
309   State           = 0;
310   Input           = 0;
311   Atmosphere      = 0;
312   FCS             = 0;
313   Propulsion      = 0;
314   MassBalance     = 0;
315   Aerodynamics    = 0;
316   Inertial        = 0;
317   GroundReactions = 0;
318   Aircraft        = 0;
319   Propagate       = 0;
320   Auxiliary       = 0;
321
322   modelLoaded = false;
323   return modelLoaded;
324 }
325
326 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
327
328 int FGFDMExec::Schedule(FGModel* model, int rate)
329 {
330   FGModel* model_iterator;
331
332   model_iterator = FirstModel;
333
334   if (model_iterator == 0L) {                  // this is the first model
335
336     FirstModel = model;
337     FirstModel->NextModel = 0L;
338     FirstModel->SetRate(rate);
339
340   } else {                                     // subsequent model
341
342     while (model_iterator->NextModel != 0L) {
343       model_iterator = model_iterator->NextModel;
344     }
345     model_iterator->NextModel = model;
346     model_iterator->NextModel->SetRate(rate);
347
348   }
349
350   return 0;
351 }
352
353 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
354
355 bool FGFDMExec::Run(void)
356 {
357   FGModel* model_iterator;
358
359   model_iterator = FirstModel;
360   if (model_iterator == 0L) return false;
361
362   Debug(2);
363
364   for (unsigned int i=1; i<SlaveFDMList.size(); i++) {
365 //    SlaveFDMList[i]->exec->State->Initialize(); // Transfer state to the slave FDM
366 //    SlaveFDMList[i]->exec->Run();
367   }
368
369   while (model_iterator != 0L) {
370     model_iterator->Run();
371     model_iterator = model_iterator->NextModel;
372   }
373
374   frame = Frame++;
375   if (!Holding()) State->IncrTime();
376   return true;
377 }
378
379 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380 // This call will cause the sim time to reset to 0.0
381
382 bool FGFDMExec::RunIC(void)
383 {
384   State->SuspendIntegration();
385   State->Initialize(IC);
386   Run();
387   State->ResumeIntegration();
388
389   return true;
390 }
391
392 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
393
394 void FGFDMExec::SetGroundCallback(FGGroundCallback* p)
395 {
396   if (GroundCallback) delete GroundCallback;
397
398   GroundCallback = p;
399 }
400
401 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402
403 vector <string> FGFDMExec::EnumerateFDMs(void)
404 {
405   vector <string> FDMList;
406
407   FDMList.push_back(Aircraft->GetAircraftName());
408
409   for (unsigned int i=1; i<SlaveFDMList.size(); i++) {
410     FDMList.push_back(SlaveFDMList[i]->exec->GetAircraft()->GetAircraftName());
411   }
412
413   return FDMList;
414 }
415
416 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
417
418 bool FGFDMExec::LoadModel(string AircraftPath, string EnginePath, string model,
419                 bool addModelToPath)
420 {
421   FGFDMExec::AircraftPath = AircraftPath;
422   FGFDMExec::EnginePath = EnginePath;
423
424   return LoadModel(model, addModelToPath);
425 }
426
427 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
428
429 bool FGFDMExec::LoadModel(string model, bool addModelToPath)
430 {
431   string token;
432   string aircraftCfgFileName;
433   string separator = "/";
434
435 # ifdef macintosh
436     separator = ";";
437 # endif
438
439   if( AircraftPath.empty() || EnginePath.empty() ) {
440     cerr << "Error: attempted to load aircraft with undefined ";
441     cerr << "aircraft and engine paths" << endl;
442     return false;
443   }
444
445   aircraftCfgFileName = AircraftPath;
446   if (addModelToPath) aircraftCfgFileName += separator + model;
447   aircraftCfgFileName += separator + model + ".xml";
448
449   FGXMLParse *XMLParse = new FGXMLParse();
450   Element* element = 0L;
451   Element* document;
452
453   ifstream input_file(aircraftCfgFileName.c_str());
454
455   if (!input_file.is_open()) { // file open failed
456     cerr << "Could not open file " << aircraftCfgFileName.c_str() << endl;
457     return false;
458   }
459
460   readXML(input_file, *XMLParse);
461   document = XMLParse->GetDocument();
462
463   modelName = model;
464
465   if (modelLoaded) {
466     DeAllocate();
467     Allocate();
468   }
469
470   ReadPrologue(document);
471   element = document->GetElement();
472
473   bool result = true;
474   while (element && result) {
475     string element_name = element->GetName();
476     if (element_name == "fileheader" )           result = ReadFileHeader(element);
477     else if (element_name == "slave")            result = ReadSlave(element);
478     else if (element_name == "metrics")          result = Aircraft->Load(element);
479     else if (element_name == "mass_balance")     result = MassBalance->Load(element);
480     else if (element_name == "ground_reactions") result = GroundReactions->Load(element);
481     else if (element_name == "propulsion")       result = Propulsion->Load(element);
482     else if (element_name == "autopilot")        result = FCS->Load(element);
483     else if (element_name == "flight_control")   result = FCS->Load(element);
484     else if (element_name == "aerodynamics")     result = Aerodynamics->Load(element);
485     else if (element_name == "input")            result = Input->Load(element);
486     else if (element_name == "output")           {
487         FGOutput* Output = new FGOutput(this);
488         Output->InitModel();
489         Schedule(Output,       1);
490         Outputs.push_back(Output);
491         result = Output->Load(element);
492     }
493     else {
494       cerr << "Found unexpected subsystem: " << element_name << ", exiting." << endl;
495       result = false;
496       break;
497     }
498     element = document->GetNextElement();
499   }
500
501   if (result) {
502     modelLoaded = true;
503     Debug(3);
504   } else {
505     cerr << fgred
506          << "  JSBSim failed to load aircraft and/or engine model"
507          << fgdef << endl;
508     return false;
509   }
510
511   struct PropertyCatalogStructure masterPCS;
512   masterPCS.base_string = "";
513   masterPCS.node = (FGPropertyManager*)master;
514
515   BuildPropertyCatalog(&masterPCS);
516
517   return result;
518 }
519
520 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
521
522 void FGFDMExec::BuildPropertyCatalog(struct PropertyCatalogStructure* pcs)
523 {
524   struct PropertyCatalogStructure* pcsNew = new struct PropertyCatalogStructure;
525   int node_idx = 0;
526   char int_buf[10];
527
528   for (int i=0; i<pcs->node->nChildren(); i++) {
529     pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getName();
530     node_idx = pcs->node->getChild(i)->getIndex();
531     sprintf(int_buf, "[%d]", node_idx);
532     if (node_idx != 0) pcsNew->base_string += string(int_buf);
533     if (pcs->node->getChild(i)->nChildren() == 0) {
534       PropertyCatalog.push_back(pcsNew->base_string);
535     } else {
536       pcsNew->node = (FGPropertyManager*)pcs->node->getChild(i);
537       BuildPropertyCatalog(pcsNew);
538     }
539   }
540   delete pcsNew;
541 }
542
543 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
544
545 string FGFDMExec::QueryPropertyCatalog(string in)
546 {
547   string results="";
548   for (int i=0; i<PropertyCatalog.size(); i++) {
549     if (PropertyCatalog[i].find(in) != string::npos) results += PropertyCatalog[i] + "\n";
550   }
551   if (results.empty()) return "No matches found\n";
552   return results;
553 }
554
555 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
556
557 bool FGFDMExec::ReadFileHeader(Element* el)
558 {
559   bool result = true; // true for success
560
561   if (debug_lvl & ~1) return result;
562
563   if (el->FindElement("author"))
564     cout << "  Model Author:  " << el->FindElement("author")->GetDataLine() << endl;
565   if (el->FindElement("filecreationdate"))
566     cout << "  Creation Date: " << el->FindElement("filecreationdate")->GetDataLine() << endl;
567   if (el->FindElement("version"))
568     cout << "  Version:       " << el->FindElement("version")->GetDataLine() << endl;
569   if (el->FindElement("description"))
570     cout << "  Description:   " << el->FindElement("description")->GetDataLine() << endl;
571
572   return result;
573 }
574
575 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
576
577 bool FGFDMExec::ReadPrologue(Element* el) // el for ReadPrologue is the document element
578 {
579   bool result = true; // true for success
580
581   if (!el) return false;
582
583   string AircraftName = el->GetAttributeValue("name");
584   Aircraft->SetAircraftName(AircraftName);
585
586   if (debug_lvl & 1) cout << underon << "Reading Aircraft Configuration File"
587             << underoff << ": " << highint << AircraftName << normint << endl;
588
589   CFGVersion = el->GetAttributeValue("version");
590   Release    = el->GetAttributeValue("release");
591
592   if (debug_lvl & 1)
593     cout << "                            Version: " << highint << CFGVersion
594                                                     << normint << endl;
595   if (CFGVersion != needed_cfg_version) {
596     cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
597             " RESULTS WILL BE UNPREDICTABLE !!" << endl;
598     cerr << "Current version needed is: " << needed_cfg_version << endl;
599     cerr << "         You have version: " << CFGVersion << endl << fgdef << endl;
600     return false;
601   }
602
603   if (Release == "ALPHA" && (debug_lvl & 1)) {
604     cout << endl << endl
605          << highint << "This aircraft model is an " << fgred << Release
606          << reset << highint << " release!!!" << endl << endl << reset
607          << "This aircraft model may not even properly load, and probably"
608          << " will not fly as expected." << endl << endl
609          << fgred << highint << "Use this model for development purposes ONLY!!!"
610          << normint << reset << endl << endl;
611   } else if (Release == "BETA" && (debug_lvl & 1)) {
612     cout << endl << endl
613          << highint << "This aircraft model is a " << fgred << Release
614          << reset << highint << " release!!!" << endl << endl << reset
615          << "This aircraft model probably will not fly as expected." << endl << endl
616          << fgblue << highint << "Use this model for development purposes ONLY!!!"
617          << normint << reset << endl << endl;
618   } else if (Release == "PRODUCTION" && (debug_lvl & 1)) {
619     cout << endl << endl
620          << highint << "This aircraft model is a " << fgblue << Release
621          << reset << highint << " release." << endl << endl << reset;
622   } else if (debug_lvl & 1) {
623     cout << endl << endl
624          << highint << "This aircraft model is an " << fgred << Release
625          << reset << highint << " release!!!" << endl << endl << reset
626          << "This aircraft model may not even properly load, and probably"
627          << " will not fly as expected." << endl << endl
628          << fgred << highint << "Use this model for development purposes ONLY!!!"
629          << normint << reset << endl << endl;
630   }
631
632   return result;
633 }
634
635 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
636
637 bool FGFDMExec::ReadSlave(Element* el)
638 {
639   // Add a new slaveData object to the slave FDM list
640   // Populate that slaveData element with a new FDMExec object
641   // Set the IsSlave flag for that FDMExec object
642   // Get the aircraft name
643   // set debug level to print out no additional data for slave objects
644   // Load the model given the aircraft name
645   // reset debug level to prior setting
646
647   int saved_debug_lvl = debug_lvl;
648   string token;
649
650   SlaveFDMList.push_back(new slaveData);
651   SlaveFDMList.back()->exec = new FGFDMExec();
652   SlaveFDMList.back()->exec->SetSlave();
653 /*
654   string AircraftName = AC_cfg->GetValue("file");
655
656   debug_lvl = 0;                 // turn off debug output for slave vehicle
657
658   SlaveFDMList.back()->exec->SetAircraftPath( AircraftPath );
659   SlaveFDMList.back()->exec->SetEnginePath( EnginePath );
660   SlaveFDMList.back()->exec->LoadModel(AircraftName);
661   debug_lvl = saved_debug_lvl;   // turn debug output back on for master vehicle
662
663   AC_cfg->GetNextConfigLine();
664   while ((token = AC_cfg->GetValue()) != string("/SLAVE")) {
665     *AC_cfg >> token;
666     if      (token == "xloc")  { *AC_cfg >> SlaveFDMList.back()->x;    }
667     else if (token == "yloc")  { *AC_cfg >> SlaveFDMList.back()->y;    }
668     else if (token == "zloc")  { *AC_cfg >> SlaveFDMList.back()->z;    }
669     else if (token == "pitch") { *AC_cfg >> SlaveFDMList.back()->pitch;}
670     else if (token == "yaw")   { *AC_cfg >> SlaveFDMList.back()->yaw;  }
671     else if (token == "roll")  { *AC_cfg >> SlaveFDMList.back()->roll;  }
672     else cerr << "Unknown identifier: " << token << " in slave vehicle definition" << endl;
673   }
674 */
675   if (debug_lvl > 0)  {
676     cout << "      X = " << SlaveFDMList.back()->x << endl;
677     cout << "      Y = " << SlaveFDMList.back()->y << endl;
678     cout << "      Z = " << SlaveFDMList.back()->z << endl;
679     cout << "      Pitch = " << SlaveFDMList.back()->pitch << endl;
680     cout << "      Yaw = " << SlaveFDMList.back()->yaw << endl;
681     cout << "      Roll = " << SlaveFDMList.back()->roll << endl;
682   }
683
684   return true;
685 }
686
687 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
688
689 FGPropertyManager* FGFDMExec::GetPropertyManager(void)
690 {
691   return instance;
692 }
693
694 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
695
696 FGTrim* FGFDMExec::GetTrim(void)
697 {
698   delete Trim;
699   Trim = new FGTrim(this,tNone);
700   return Trim;
701 }
702
703 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
704
705 void FGFDMExec::DisableOutput(void)
706 {
707   for (int i=0; i<Outputs.size(); i++) {
708     Outputs[i]->Disable();
709   }
710 }
711
712 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
713
714 void FGFDMExec::EnableOutput(void)
715 {
716   for (int i=0; i<Outputs.size(); i++) {
717     Outputs[i]->Enable();
718   }
719 }
720
721 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
722
723 void FGFDMExec::DoTrim(int mode)
724 {
725   double saved_time;
726
727   if (Constructing) return;
728
729   if (mode < 0 || mode > JSBSim::tNone) {
730     cerr << endl << "Illegal trimming mode!" << endl << endl;
731     return;
732   }
733   saved_time = State->Getsim_time();
734   FGTrim trim(this, (JSBSim::TrimMode)mode);
735   if ( !trim.DoTrim() ) cerr << endl << "Trim Failed" << endl << endl;
736   trim.Report();
737   State->Setsim_time(saved_time);
738 }
739
740 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
741
742 void FGFDMExec::UseAtmosphereMSIS(void)
743 {
744   FGAtmosphere *oldAtmosphere = Atmosphere;
745   Atmosphere = new MSIS(this);
746   if (!Atmosphere->InitModel()) {
747     cerr << fgred << "MSIS Atmosphere model init failed" << fgdef << endl;
748     Error+=1;
749   }
750   delete oldAtmosphere;
751 }
752
753 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
754
755 void FGFDMExec::UseAtmosphereMars(void)
756 {
757 /*
758   FGAtmosphere *oldAtmosphere = Atmosphere;
759   Atmosphere = new FGMars(this);
760   if (!Atmosphere->InitModel()) {
761     cerr << fgred << "Mars Atmosphere model init failed" << fgdef << endl;
762     Error+=1;
763   }
764   delete oldAtmosphere;
765 */
766 }
767
768 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
769 //    The bitmasked value choices are as follows:
770 //    unset: In this case (the default) JSBSim would only print
771 //       out the normally expected messages, essentially echoing
772 //       the config files as they are read. If the environment
773 //       variable is not set, debug_lvl is set to 1 internally
774 //    0: This requests JSBSim not to output any messages
775 //       whatsoever.
776 //    1: This value explicity requests the normal JSBSim
777 //       startup messages
778 //    2: This value asks for a message to be printed out when
779 //       a class is instantiated
780 //    4: When this value is set, a message is displayed when a
781 //       FGModel object executes its Run() method
782 //    8: When this value is set, various runtime state variables
783 //       are printed out periodically
784 //    16: When set various parameters are sanity checked and
785 //       a message is printed out when they go out of bounds
786
787 void FGFDMExec::Debug(int from)
788 {
789   if (debug_lvl <= 0) return;
790
791   if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output
792     if (from == 0) { // Constructor
793       cout << "\n\n     " << highint << underon << "JSBSim Flight Dynamics Model v"
794                                      << JSBSim_version << underoff << normint << endl;
795       cout << halfint << "            [cfg file spec v" << needed_cfg_version << "]\n\n";
796       cout << normint << "JSBSim startup beginning ...\n\n";
797     } else if (from == 3) {
798       cout << "\n\nJSBSim startup complete\n\n";
799     }
800   }
801   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
802     if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
803     if (from == 1) cout << "Destroyed:    FGFDMExec" << endl;
804   }
805   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
806     if (from == 2) {
807       cout << "================== Frame: " << Frame << "  Time: "
808            << State->Getsim_time() << " dt: " << State->Getdt() << endl;
809     }
810   }
811   if (debug_lvl & 8 ) { // Runtime state variables
812   }
813   if (debug_lvl & 16) { // Sanity checking
814   }
815   if (debug_lvl & 64) {
816     if (from == 0) { // Constructor
817       cout << IdSrc << endl;
818       cout << IdHdr << endl;
819     }
820   }
821 }
822 }
823
824