]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFDMExec.cpp
Remove a bunch of unneede files.
[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   readXML(input_file, *XMLParse);
455   document = XMLParse->GetDocument();
456
457   modelName = model;
458
459   if (modelLoaded) {
460     DeAllocate();
461     Allocate();
462   }
463
464   ReadPrologue(document);
465   element = document->GetElement();
466
467   bool result = true;
468   while (element && result) {
469     string element_name = element->GetName();
470     if (element_name == "fileheader" )           result = ReadFileHeader(element);
471     else if (element_name == "slave")            result = ReadSlave(element);
472     else if (element_name == "metrics")          result = Aircraft->Load(element);
473     else if (element_name == "mass_balance")     result = MassBalance->Load(element);
474     else if (element_name == "ground_reactions") result = GroundReactions->Load(element);
475     else if (element_name == "propulsion")       result = Propulsion->Load(element);
476     else if (element_name == "autopilot")        result = FCS->Load(element);
477     else if (element_name == "flight_control")   result = FCS->Load(element);
478     else if (element_name == "aerodynamics")     result = Aerodynamics->Load(element);
479     else if (element_name == "input")            result = Input->Load(element);
480     else if (element_name == "output")           {
481         FGOutput* Output = new FGOutput(this);
482         Output->InitModel();
483         Schedule(Output,       1);
484         Outputs.push_back(Output);
485         result = Output->Load(element);
486     }
487     else {
488       cerr << "Found unexpected subsystem: " << element_name << ", exiting." << endl;
489       result = false;
490       break;
491     }
492     element = document->GetNextElement();
493   }
494
495   if (result) {
496     modelLoaded = true;
497     Debug(3);
498   } else {
499     cerr << fgred
500          << "  JSBSim failed to load aircraft and/or engine model"
501          << fgdef << endl;
502     return false;
503   }
504
505   struct PropertyCatalogStructure masterPCS;
506   masterPCS.base_string = "";
507   masterPCS.node = (FGPropertyManager*)master;
508
509   BuildPropertyCatalog(&masterPCS);
510
511   return result;
512 }
513
514 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
515
516 void FGFDMExec::BuildPropertyCatalog(struct PropertyCatalogStructure* pcs)
517 {
518   struct PropertyCatalogStructure* pcsNew = new struct PropertyCatalogStructure;
519   int node_idx = 0;
520   char int_buf[10];
521
522   for (int i=0; i<pcs->node->nChildren(); i++) {
523     pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getName();
524     node_idx = pcs->node->getChild(i)->getIndex();
525     sprintf(int_buf, "[%d]", node_idx);
526     if (node_idx != 0) pcsNew->base_string += string(int_buf);
527     if (pcs->node->getChild(i)->nChildren() == 0) {
528       PropertyCatalog.push_back(pcsNew->base_string);
529     } else {
530       pcsNew->node = (FGPropertyManager*)pcs->node->getChild(i);
531       BuildPropertyCatalog(pcsNew);
532     }
533   }
534   delete pcsNew;
535 }
536
537 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
538
539 string FGFDMExec::QueryPropertyCatalog(string in)
540 {
541   string results="";
542   for (int i=0; i<PropertyCatalog.size(); i++) {
543     if (PropertyCatalog[i].find(in) != string::npos) results += PropertyCatalog[i] + "\n";
544   }
545   if (results.empty()) return "No matches found\n";
546   return results;
547 }
548
549 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
550
551 bool FGFDMExec::ReadFileHeader(Element* el)
552 {
553   bool result = true; // true for success
554
555   if (debug_lvl & ~1) return result;
556
557   if (el->FindElement("author"))
558     cout << "  Model Author:  " << el->FindElement("author")->GetDataLine() << endl;
559   if (el->FindElement("filecreationdate"))
560     cout << "  Creation Date: " << el->FindElement("filecreationdate")->GetDataLine() << endl;
561   if (el->FindElement("version"))
562     cout << "  Version:       " << el->FindElement("version")->GetDataLine() << endl;
563   if (el->FindElement("description"))
564     cout << "  Description:   " << el->FindElement("description")->GetDataLine() << endl;
565
566   return result;
567 }
568
569 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
570
571 bool FGFDMExec::ReadPrologue(Element* el) // el for ReadPrologue is the document element
572 {
573   bool result = true; // true for success
574
575   if (!el) return false;
576
577   string AircraftName = el->GetAttributeValue("name");
578   Aircraft->SetAircraftName(AircraftName);
579
580   if (debug_lvl & 1) cout << underon << "Reading Aircraft Configuration File"
581             << underoff << ": " << highint << AircraftName << normint << endl;
582
583   CFGVersion = el->GetAttributeValue("version");
584   Release    = el->GetAttributeValue("release");
585
586   if (debug_lvl & 1)
587     cout << "                            Version: " << highint << CFGVersion
588                                                     << normint << endl;
589   if (CFGVersion != needed_cfg_version) {
590     cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
591             " RESULTS WILL BE UNPREDICTABLE !!" << endl;
592     cerr << "Current version needed is: " << needed_cfg_version << endl;
593     cerr << "         You have version: " << CFGVersion << endl << fgdef << endl;
594     return false;
595   }
596
597   if (Release == "ALPHA" && (debug_lvl & 1)) {
598     cout << endl << endl
599          << highint << "This aircraft model is an " << fgred << Release
600          << reset << highint << " release!!!" << endl << endl << reset
601          << "This aircraft model may not even properly load, and probably"
602          << " will not fly as expected." << endl << endl
603          << fgred << highint << "Use this model for development purposes ONLY!!!"
604          << normint << reset << endl << endl;
605   } else if (Release == "BETA" && (debug_lvl & 1)) {
606     cout << endl << endl
607          << highint << "This aircraft model is a " << fgred << Release
608          << reset << highint << " release!!!" << endl << endl << reset
609          << "This aircraft model probably will not fly as expected." << endl << endl
610          << fgblue << highint << "Use this model for development purposes ONLY!!!"
611          << normint << reset << endl << endl;
612   } else if (Release == "PRODUCTION" && (debug_lvl & 1)) {
613     cout << endl << endl
614          << highint << "This aircraft model is a " << fgblue << Release
615          << reset << highint << " release." << endl << endl << reset;
616   } else if (debug_lvl & 1) {
617     cout << endl << endl
618          << highint << "This aircraft model is an " << fgred << Release
619          << reset << highint << " release!!!" << endl << endl << reset
620          << "This aircraft model may not even properly load, and probably"
621          << " will not fly as expected." << endl << endl
622          << fgred << highint << "Use this model for development purposes ONLY!!!"
623          << normint << reset << endl << endl;
624   }
625
626   return result;
627 }
628
629 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
630
631 bool FGFDMExec::ReadSlave(Element* el)
632 {
633   // Add a new slaveData object to the slave FDM list
634   // Populate that slaveData element with a new FDMExec object
635   // Set the IsSlave flag for that FDMExec object
636   // Get the aircraft name
637   // set debug level to print out no additional data for slave objects
638   // Load the model given the aircraft name
639   // reset debug level to prior setting
640
641   int saved_debug_lvl = debug_lvl;
642   string token;
643
644   SlaveFDMList.push_back(new slaveData);
645   SlaveFDMList.back()->exec = new FGFDMExec();
646   SlaveFDMList.back()->exec->SetSlave();
647 /*
648   string AircraftName = AC_cfg->GetValue("file");
649
650   debug_lvl = 0;                 // turn off debug output for slave vehicle
651
652   SlaveFDMList.back()->exec->SetAircraftPath( AircraftPath );
653   SlaveFDMList.back()->exec->SetEnginePath( EnginePath );
654   SlaveFDMList.back()->exec->LoadModel(AircraftName);
655   debug_lvl = saved_debug_lvl;   // turn debug output back on for master vehicle
656
657   AC_cfg->GetNextConfigLine();
658   while ((token = AC_cfg->GetValue()) != string("/SLAVE")) {
659     *AC_cfg >> token;
660     if      (token == "xloc")  { *AC_cfg >> SlaveFDMList.back()->x;    }
661     else if (token == "yloc")  { *AC_cfg >> SlaveFDMList.back()->y;    }
662     else if (token == "zloc")  { *AC_cfg >> SlaveFDMList.back()->z;    }
663     else if (token == "pitch") { *AC_cfg >> SlaveFDMList.back()->pitch;}
664     else if (token == "yaw")   { *AC_cfg >> SlaveFDMList.back()->yaw;  }
665     else if (token == "roll")  { *AC_cfg >> SlaveFDMList.back()->roll;  }
666     else cerr << "Unknown identifier: " << token << " in slave vehicle definition" << endl;
667   }
668 */
669   if (debug_lvl > 0)  {
670     cout << "      X = " << SlaveFDMList.back()->x << endl;
671     cout << "      Y = " << SlaveFDMList.back()->y << endl;
672     cout << "      Z = " << SlaveFDMList.back()->z << endl;
673     cout << "      Pitch = " << SlaveFDMList.back()->pitch << endl;
674     cout << "      Yaw = " << SlaveFDMList.back()->yaw << endl;
675     cout << "      Roll = " << SlaveFDMList.back()->roll << endl;
676   }
677
678   return true;
679 }
680
681 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
682
683 FGPropertyManager* FGFDMExec::GetPropertyManager(void)
684 {
685   return instance;
686 }
687
688 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
689
690 FGTrim* FGFDMExec::GetTrim(void)
691 {
692   delete Trim;
693   Trim = new FGTrim(this,tNone);
694   return Trim;
695 }
696
697 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
698
699 void FGFDMExec::DisableOutput(void)
700 {
701   for (int i=0; i<Outputs.size(); i++) {
702     Outputs[i]->Disable();
703   }
704 }
705
706 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
707
708 void FGFDMExec::EnableOutput(void)
709 {
710   for (int i=0; i<Outputs.size(); i++) {
711     Outputs[i]->Enable();
712   }
713 }
714
715 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
716
717 void FGFDMExec::DoTrim(int mode)
718 {
719   double saved_time;
720
721 cout << "DoTrim called" << endl;
722
723   if (Constructing) return;
724
725   if (mode < 0 || mode > JSBSim::tNone) {
726     cerr << endl << "Illegal trimming mode!" << endl << endl;
727     return;
728   }
729   saved_time = State->Getsim_time();
730   FGTrim trim(this, (JSBSim::TrimMode)mode);
731   if ( !trim.DoTrim() ) cerr << endl << "Trim Failed" << endl << endl;
732   trim.Report();
733   State->Setsim_time(saved_time);
734 }
735
736 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
737
738 void FGFDMExec::UseAtmosphereMSIS(void)
739 {
740   FGAtmosphere *oldAtmosphere = Atmosphere;
741   Atmosphere = new MSIS(this);
742   if (!Atmosphere->InitModel()) {
743     cerr << fgred << "MSIS Atmosphere model init failed" << fgdef << endl;
744     Error+=1;
745   }
746   delete oldAtmosphere;
747 }
748
749 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
750
751 void FGFDMExec::UseAtmosphereMars(void)
752 {
753 /*
754   FGAtmosphere *oldAtmosphere = Atmosphere;
755   Atmosphere = new FGMars(this);
756   if (!Atmosphere->InitModel()) {
757     cerr << fgred << "Mars Atmosphere model init failed" << fgdef << endl;
758     Error+=1;
759   }
760   delete oldAtmosphere;
761 */
762 }
763
764 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
765 //    The bitmasked value choices are as follows:
766 //    unset: In this case (the default) JSBSim would only print
767 //       out the normally expected messages, essentially echoing
768 //       the config files as they are read. If the environment
769 //       variable is not set, debug_lvl is set to 1 internally
770 //    0: This requests JSBSim not to output any messages
771 //       whatsoever.
772 //    1: This value explicity requests the normal JSBSim
773 //       startup messages
774 //    2: This value asks for a message to be printed out when
775 //       a class is instantiated
776 //    4: When this value is set, a message is displayed when a
777 //       FGModel object executes its Run() method
778 //    8: When this value is set, various runtime state variables
779 //       are printed out periodically
780 //    16: When set various parameters are sanity checked and
781 //       a message is printed out when they go out of bounds
782
783 void FGFDMExec::Debug(int from)
784 {
785   if (debug_lvl <= 0) return;
786
787   if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output
788     if (from == 0) { // Constructor
789       cout << "\n\n     " << highint << underon << "JSBSim Flight Dynamics Model v"
790                                      << JSBSim_version << underoff << normint << endl;
791       cout << halfint << "            [cfg file spec v" << needed_cfg_version << "]\n\n";
792       cout << normint << "JSBSim startup beginning ...\n\n";
793     } else if (from == 3) {
794       cout << "\n\nJSBSim startup complete\n\n";
795     }
796   }
797   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
798     if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
799     if (from == 1) cout << "Destroyed:    FGFDMExec" << endl;
800   }
801   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
802     if (from == 2) {
803       cout << "================== Frame: " << Frame << "  Time: "
804            << State->Getsim_time() << " dt: " << State->Getdt() << endl;
805     }
806   }
807   if (debug_lvl & 8 ) { // Runtime state variables
808   }
809   if (debug_lvl & 16) { // Sanity checking
810   }
811   if (debug_lvl & 64) {
812     if (from == 0) { // Constructor
813       cout << IdSrc << endl;
814       cout << IdHdr << endl;
815     }
816   }
817 }
818 }
819
820