]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFDMExec.cpp
Pull Sound-manager out of FGGlobals
[flightgear.git] / src / FDM / JSBSim / FGFDMExec.cpp
1
2 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3
4  Module:       FGFDMExec.cpp
5  Author:       Jon S. Berndt
6  Date started: 11/17/98
7  Purpose:      Schedules and runs the model routines.
8
9  ------------- Copyright (C) 1999  Jon S. Berndt (jon@jsbsim.org) -------------
10
11  This program is free software; you can redistribute it and/or modify it under
12  the terms of the GNU Lesser General Public License as published by the Free Software
13  Foundation; either version 2 of the License, or (at your option) any later
14  version.
15
16  This program is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
19  details.
20
21  You should have received a copy of the GNU Lesser General Public License along with
22  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23  Place - Suite 330, Boston, MA  02111-1307, USA.
24
25  Further information about the GNU Lesser General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30
31 This class wraps up the simulation scheduling routines.
32
33 HISTORY
34 --------------------------------------------------------------------------------
35 11/17/98   JSB   Created
36
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 COMMENTS, REFERENCES,  and NOTES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 INCLUDES
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44
45 #include <iostream>
46 #include <iterator>
47 #include <cstdlib>
48 #include <iomanip>
49
50 #include "FGFDMExec.h"
51 #include "models/atmosphere/FGStandardAtmosphere.h"
52 #include "models/atmosphere/FGWinds.h"
53 #include "models/FGFCS.h"
54 #include "models/FGPropulsion.h"
55 #include "models/FGMassBalance.h"
56 #include "models/FGGroundReactions.h"
57 #include "models/FGExternalReactions.h"
58 #include "models/FGBuoyantForces.h"
59 #include "models/FGAerodynamics.h"
60 #include "models/FGInertial.h"
61 #include "models/FGAircraft.h"
62 #include "models/FGAccelerations.h"
63 #include "models/FGPropagate.h"
64 #include "models/FGAuxiliary.h"
65 #include "models/FGInput.h"
66 #include "models/FGOutput.h"
67 #include "initialization/FGTrim.h"
68 #include "input_output/FGScript.h"
69 #include "input_output/FGXMLFileRead.h"
70
71 using namespace std;
72
73 namespace JSBSim {
74
75 IDENT(IdSrc,"$Id: FGFDMExec.cpp,v 1.185 2015/12/13 08:01:50 bcoconni Exp $");
76 IDENT(IdHdr,ID_FDMEXEC);
77
78 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 CLASS IMPLEMENTATION
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
81
82 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83 // Constructor
84
85 FGFDMExec::FGFDMExec(FGPropertyManager* root, unsigned int* fdmctr) : Root(root), FDMctr(fdmctr)
86 {
87   Frame           = 0;
88   Error           = 0;
89   IC              = 0;
90   Trim            = 0;
91   Script          = 0;
92   disperse        = 0;
93
94   RootDir = "";
95
96   modelLoaded = false;
97   IsChild = false;
98   holding = false;
99   Terminate = false;
100   StandAlone = false;
101   ResetMode = 0;
102   RandomSeed = 0;
103
104   IncrementThenHolding = false;  // increment then hold is off by default
105   TimeStepsUntilHold = -1;
106
107   sim_time = 0.0;
108   dT = 1.0/120.0; // a default timestep size. This is needed for when JSBSim is
109                   // run in standalone mode with no initialization file.
110
111   AircraftPath = "aircraft";
112   EnginePath = "engine";
113   SystemsPath = "systems";
114
115   try {
116     char* num = getenv("JSBSIM_DEBUG");
117     if (num) debug_lvl = atoi(num); // set debug level
118   } catch (...) {                   // if error set to 1
119     debug_lvl = 1;
120   }
121
122   if (Root == 0) {                 // Then this is the root FDM
123     Root = new FGPropertyManager;  // Create the property manager
124     StandAlone = true;
125   }
126
127   if (FDMctr == 0) {
128     FDMctr = new unsigned int;     // Create and initialize the child FDM counter
129     (*FDMctr) = 0;
130   }
131
132   // Store this FDM's ID
133   IdFDM = (*FDMctr); // The main (parent) JSBSim instance is always the "zeroth"
134
135   // Prepare FDMctr for the next child FDM id
136   (*FDMctr)++;       // instance. "child" instances are loaded last.
137
138   FGPropertyNode* instanceRoot = Root->GetNode("/fdm/jsbsim",IdFDM,true);
139   instance = new FGPropertyManager(instanceRoot);
140
141   try {
142     char* num = getenv("JSBSIM_DISPERSE");
143     if (num) {
144       if (atoi(num) != 0) disperse = 1;  // set dispersions on
145     }
146   } catch (...) {                        // if error set to false
147     disperse = 0;
148     std::cerr << "Could not process JSBSIM_DISPERSIONS environment variable: Assumed NO dispersions." << endl;
149   }
150
151   Debug(0);
152   // this is to catch errors in binding member functions to the property tree.
153   try {
154     Allocate();
155   } catch (const string& msg ) {
156     cout << "Caught error: " << msg << endl;
157     exit(1);
158   }
159
160   trim_status = false;
161   ta_mode     = 99;
162   trim_completed = 0;
163
164   Constructing = true;
165   typedef int (FGFDMExec::*iPMF)(void) const;
166   instance->Tie("simulation/do_simple_trim", this, (iPMF)0, &FGFDMExec::DoTrim, false);
167   instance->Tie("simulation/reset", this, (iPMF)0, &FGFDMExec::ResetToInitialConditions, false);
168   instance->Tie("simulation/disperse", this, &FGFDMExec::GetDisperse);
169   instance->Tie("simulation/randomseed", this, (iPMF)&FGFDMExec::SRand, &FGFDMExec::SRand, false);
170   instance->Tie("simulation/terminate", (int *)&Terminate);
171   instance->Tie("simulation/sim-time-sec", this, &FGFDMExec::GetSimTime);
172   instance->Tie("simulation/dt", this, &FGFDMExec::GetDeltaT);
173   instance->Tie("simulation/jsbsim-debug", this, &FGFDMExec::GetDebugLevel, &FGFDMExec::SetDebugLevel);
174   instance->Tie("simulation/frame", (int *)&Frame, false);
175   instance->Tie("simulation/trim-completed", (int *)&trim_completed, false);
176
177   Constructing = false;
178 }
179
180 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181
182 FGFDMExec::~FGFDMExec()
183 {
184   try {
185     Unbind();
186     DeAllocate();
187
188     delete instance;
189
190     if (IdFDM == 0) { // Meaning this is no child FDM
191       if(Root != 0) {
192          if(StandAlone)
193             delete Root;
194          Root = 0;
195       }
196       if(FDMctr != 0) {
197          delete FDMctr;
198          FDMctr = 0;
199       }
200     }
201   } catch (const string& msg ) {
202     cout << "Caught error: " << msg << endl;
203   }
204
205   for (unsigned int i=1; i<ChildFDMList.size(); i++) delete ChildFDMList[i]->exec;
206   ChildFDMList.clear();
207
208   PropertyCatalog.clear();
209   
210   SetGroundCallback(0);
211
212   if (FDMctr > 0) (*FDMctr)--;
213
214   Debug(1);
215 }
216
217 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218
219 bool FGFDMExec::Allocate(void)
220 {
221   bool result=true;
222
223   Models.resize(eNumStandardModels);
224
225   // First build the inertial model since some other models are relying on
226   // the inertial model and the ground callback to build themselves.
227   // Note that this does not affect the order in which the models will be
228   // executed later.
229   Models[eInertial]          = new FGInertial(this);
230   SetGroundCallback(new FGDefaultGroundCallback(static_cast<FGInertial*>(Models[eInertial])->GetRefRadius()));
231
232   // See the eModels enum specification in the header file. The order of the
233   // enums specifies the order of execution. The Models[] vector is the primary
234   // storage array for the list of models.
235   Models[ePropagate]         = new FGPropagate(this);
236   Models[eInput]             = new FGInput(this);
237   Models[eAtmosphere]        = new FGStandardAtmosphere(this);
238   Models[eWinds]             = new FGWinds(this);
239   Models[eSystems]           = new FGFCS(this);
240   Models[eMassBalance]       = new FGMassBalance(this);
241   Models[eAuxiliary]         = new FGAuxiliary(this);
242   Models[ePropulsion]        = new FGPropulsion(this);
243   Models[eAerodynamics]      = new FGAerodynamics (this);
244   Models[eGroundReactions]   = new FGGroundReactions(this);
245   Models[eExternalReactions] = new FGExternalReactions(this);
246   Models[eBuoyantForces]     = new FGBuoyantForces(this);
247   Models[eAircraft]          = new FGAircraft(this);
248   Models[eAccelerations]     = new FGAccelerations(this);
249   Models[eOutput]            = new FGOutput(this);
250
251   // Assign the Model shortcuts for internal executive use only.
252   Propagate = (FGPropagate*)Models[ePropagate];
253   Inertial = (FGInertial*)Models[eInertial];
254   Atmosphere = (FGAtmosphere*)Models[eAtmosphere];
255   Winds = (FGWinds*)Models[eWinds];
256   FCS = (FGFCS*)Models[eSystems];
257   MassBalance = (FGMassBalance*)Models[eMassBalance];
258   Auxiliary = (FGAuxiliary*)Models[eAuxiliary];
259   Propulsion = (FGPropulsion*)Models[ePropulsion];
260   Aerodynamics = (FGAerodynamics*)Models[eAerodynamics];
261   GroundReactions = (FGGroundReactions*)Models[eGroundReactions];
262   ExternalReactions = (FGExternalReactions*)Models[eExternalReactions];
263   BuoyantForces = (FGBuoyantForces*)Models[eBuoyantForces];
264   Aircraft = (FGAircraft*)Models[eAircraft];
265   Accelerations = (FGAccelerations*)Models[eAccelerations];
266   Output = (FGOutput*)Models[eOutput];
267
268   // Initialize planet (environment) constants
269   LoadPlanetConstants();
270
271   // Initialize models
272   for (unsigned int i = 0; i < Models.size(); i++) {
273     // The Input/Output models must not be initialized prior to IC loading
274     if (i == eInput || i == eOutput) continue;
275
276     LoadInputs(i);
277     Models[i]->InitModel();
278   }
279
280   IC = new FGInitialCondition(this);
281   IC->bind(instance);
282
283   modelLoaded = false;
284
285   return result;
286 }
287
288 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
289
290 bool FGFDMExec::DeAllocate(void)
291 {
292
293   for (unsigned int i=0; i<eNumStandardModels; i++) delete Models[i];
294   Models.clear();
295
296   delete Script;
297   delete IC;
298   delete Trim;
299
300   Error       = 0;
301
302   modelLoaded = false;
303   return modelLoaded;
304 }
305
306 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
307
308 bool FGFDMExec::Run(void)
309 {
310   bool success=true;
311
312   Debug(2);
313
314   for (unsigned int i=1; i<ChildFDMList.size(); i++) {
315     ChildFDMList[i]->AssignState( (FGPropagate*)Models[ePropagate] ); // Transfer state to the child FDM
316     ChildFDMList[i]->Run();
317   }
318
319   IncrTime();
320
321   // returns true if success, false if complete
322   if (Script != 0 && !IntegrationSuspended()) success = Script->RunScript();
323
324   for (unsigned int i = 0; i < Models.size(); i++) {
325     LoadInputs(i);
326     Models[i]->Run(holding);
327   }
328
329   if (ResetMode) {
330     unsigned int mode = ResetMode;
331
332     ResetMode = 0;
333     ResetToInitialConditions(mode);
334   }
335
336   if (Terminate) success = false;
337
338   return success;
339 }
340
341 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
342
343 void FGFDMExec::LoadInputs(unsigned int idx)
344 {
345   switch(idx) {
346   case ePropagate:
347     Propagate->in.vPQRidot     = Accelerations->GetPQRidot();
348     Propagate->in.vQtrndot     = Accelerations->GetQuaterniondot();
349     Propagate->in.vUVWidot     = Accelerations->GetUVWidot();
350     Propagate->in.DeltaT       = dT;
351     break;
352   case eInput:
353     break;
354   case eInertial:
355     Inertial->in.Radius        = Propagate->GetRadius();
356     Inertial->in.Latitude      = Propagate->GetLatitude();
357     break;
358   case eAtmosphere:
359     Atmosphere->in.altitudeASL = Propagate->GetAltitudeASL();
360     break;
361   case eWinds:
362     Winds->in.AltitudeASL      = Propagate->GetAltitudeASL();
363     Winds->in.DistanceAGL      = Propagate->GetDistanceAGL();
364     Winds->in.Tl2b             = Propagate->GetTl2b();
365     Winds->in.Tw2b             = Auxiliary->GetTw2b();
366     Winds->in.V                = Auxiliary->GetVt();
367     Winds->in.totalDeltaT      = dT * Winds->GetRate();
368     break;
369   case eAuxiliary:
370     Auxiliary->in.Pressure     = Atmosphere->GetPressure();
371     Auxiliary->in.Density      = Atmosphere->GetDensity();
372     Auxiliary->in.DensitySL    = Atmosphere->GetDensitySL();
373     Auxiliary->in.PressureSL   = Atmosphere->GetPressureSL();
374     Auxiliary->in.Temperature  = Atmosphere->GetTemperature();
375     Auxiliary->in.SoundSpeed   = Atmosphere->GetSoundSpeed();
376     Auxiliary->in.KinematicViscosity = Atmosphere->GetKinematicViscosity();
377     Auxiliary->in.DistanceAGL  = Propagate->GetDistanceAGL();
378     Auxiliary->in.Mass         = MassBalance->GetMass();
379     Auxiliary->in.Tl2b         = Propagate->GetTl2b();
380     Auxiliary->in.Tb2l         = Propagate->GetTb2l();
381     Auxiliary->in.vPQR         = Propagate->GetPQR();
382     Auxiliary->in.vPQRi        = Propagate->GetPQRi();
383     Auxiliary->in.vPQRidot     = Accelerations->GetPQRidot();
384     Auxiliary->in.vUVW         = Propagate->GetUVW();
385     Auxiliary->in.vUVWdot      = Accelerations->GetUVWdot();
386     Auxiliary->in.vVel         = Propagate->GetVel();
387     Auxiliary->in.vBodyAccel   = Accelerations->GetBodyAccel();
388     Auxiliary->in.ToEyePt      = MassBalance->StructuralToBody(Aircraft->GetXYZep());
389     Auxiliary->in.VRPBody      = MassBalance->StructuralToBody(Aircraft->GetXYZvrp());
390     Auxiliary->in.RPBody       = MassBalance->StructuralToBody(Aircraft->GetXYZrp());
391     Auxiliary->in.vFw          = Aerodynamics->GetvFw();
392     Auxiliary->in.vLocation    = Propagate->GetLocation();
393     Auxiliary->in.CosTht       = Propagate->GetCosEuler(eTht);
394     Auxiliary->in.SinTht       = Propagate->GetSinEuler(eTht);
395     Auxiliary->in.CosPhi       = Propagate->GetCosEuler(ePhi);
396     Auxiliary->in.SinPhi       = Propagate->GetSinEuler(ePhi);
397     Auxiliary->in.Psi          = Propagate->GetEuler(ePsi);
398     Auxiliary->in.TotalWindNED = Winds->GetTotalWindNED();
399     Auxiliary->in.TurbPQR      = Winds->GetTurbPQR();
400     Auxiliary->in.WindPsi      = Winds->GetWindPsi();
401     Auxiliary->in.Vwind        = Winds->GetTotalWindNED().Magnitude();
402     Auxiliary->in.PitotAngle   = Aircraft->GetPitotAngle();
403     break;
404   case eSystems:
405     // Dynamic inputs come into the components that FCS manages through properties
406     break;
407   case ePropulsion:
408     Propulsion->in.Pressure         = Atmosphere->GetPressure();
409     Propulsion->in.PressureRatio    = Atmosphere->GetPressureRatio();
410     Propulsion->in.Temperature      = Atmosphere->GetTemperature();
411     Propulsion->in.DensityRatio     = Atmosphere->GetDensityRatio();
412     Propulsion->in.Density          = Atmosphere->GetDensity();
413     Propulsion->in.Soundspeed       = Atmosphere->GetSoundSpeed();
414     Propulsion->in.TotalPressure    = Auxiliary->GetTotalPressure();
415     Propulsion->in.Vc               = Auxiliary->GetVcalibratedKTS();
416     Propulsion->in.Vt               = Auxiliary->GetVt();
417     Propulsion->in.qbar             = Auxiliary->Getqbar();
418     Propulsion->in.TAT_c            = Auxiliary->GetTAT_C();
419     Propulsion->in.AeroUVW          = Auxiliary->GetAeroUVW();
420     Propulsion->in.AeroPQR          = Auxiliary->GetAeroPQR();
421     Propulsion->in.alpha            = Auxiliary->Getalpha();
422     Propulsion->in.beta             = Auxiliary->Getbeta();
423     Propulsion->in.TotalDeltaT      = dT * Propulsion->GetRate();
424     Propulsion->in.ThrottlePos      = FCS->GetThrottlePos();
425     Propulsion->in.MixturePos       = FCS->GetMixturePos();
426     Propulsion->in.ThrottleCmd      = FCS->GetThrottleCmd();
427     Propulsion->in.MixtureCmd       = FCS->GetMixtureCmd();
428     Propulsion->in.PropAdvance      = FCS->GetPropAdvance();
429     Propulsion->in.PropFeather      = FCS->GetPropFeather();
430     Propulsion->in.H_agl            = Propagate->GetDistanceAGL();
431     Propulsion->in.PQR              = Propagate->GetPQR();
432
433     break;
434   case eAerodynamics:
435     Aerodynamics->in.Alpha     = Auxiliary->Getalpha();
436     Aerodynamics->in.Beta      = Auxiliary->Getbeta();
437     Aerodynamics->in.Qbar      = Auxiliary->Getqbar();
438     Aerodynamics->in.Vt        = Auxiliary->GetVt();
439     Aerodynamics->in.Tb2w      = Auxiliary->GetTb2w();
440     Aerodynamics->in.Tw2b      = Auxiliary->GetTw2b();
441     Aerodynamics->in.RPBody    = MassBalance->StructuralToBody(Aircraft->GetXYZrp());
442     break;
443   case eGroundReactions:
444     // There are no external inputs to this model.
445     GroundReactions->in.Vground         = Auxiliary->GetVground();
446     GroundReactions->in.VcalibratedKts  = Auxiliary->GetVcalibratedKTS();
447     GroundReactions->in.Temperature     = Atmosphere->GetTemperature();
448     GroundReactions->in.TakeoffThrottle = (FCS->GetThrottlePos().size() > 0) ? (FCS->GetThrottlePos(0) > 0.90) : false;
449     GroundReactions->in.SteerPosDeg     = FCS->GetSteerPosDeg();
450     GroundReactions->in.BrakePos        = FCS->GetBrakePos();
451     GroundReactions->in.FCSGearPos      = FCS->GetGearPos();
452     GroundReactions->in.EmptyWeight     = MassBalance->GetEmptyWeight();
453     GroundReactions->in.Tb2l            = Propagate->GetTb2l();
454     GroundReactions->in.Tec2l           = Propagate->GetTec2l();
455     GroundReactions->in.Tec2b           = Propagate->GetTec2b();
456     GroundReactions->in.PQR             = Propagate->GetPQR();
457     GroundReactions->in.UVW             = Propagate->GetUVW();
458     GroundReactions->in.DistanceAGL     = Propagate->GetDistanceAGL();
459     GroundReactions->in.DistanceASL     = Propagate->GetAltitudeASL();
460     GroundReactions->in.TotalDeltaT     = dT * GroundReactions->GetRate();
461     GroundReactions->in.WOW             = GroundReactions->GetWOW();
462     GroundReactions->in.Location        = Propagate->GetLocation();
463     GroundReactions->in.vXYZcg          = MassBalance->GetXYZcg();
464     break;
465   case eExternalReactions:
466     // There are no external inputs to this model.
467     break;
468   case eBuoyantForces:
469     BuoyantForces->in.Density     = Atmosphere->GetDensity();
470     BuoyantForces->in.Pressure    = Atmosphere->GetPressure();
471     BuoyantForces->in.Temperature = Atmosphere->GetTemperature();
472     BuoyantForces->in.gravity     = Inertial->gravity();
473     break;
474   case eMassBalance:
475     MassBalance->in.GasInertia  = BuoyantForces->GetGasMassInertia();
476     MassBalance->in.GasMass     = BuoyantForces->GetGasMass();
477     MassBalance->in.GasMoment   = BuoyantForces->GetGasMassMoment();
478     MassBalance->in.TanksWeight = Propulsion->GetTanksWeight();
479     MassBalance->in.TanksMoment = Propulsion->GetTanksMoment();
480     MassBalance->in.TankInertia = Propulsion->CalculateTankInertias();
481     break;
482   case eAircraft:
483     Aircraft->in.AeroForce     = Aerodynamics->GetForces();
484     Aircraft->in.PropForce     = Propulsion->GetForces();
485     Aircraft->in.GroundForce   = GroundReactions->GetForces();
486     Aircraft->in.ExternalForce = ExternalReactions->GetForces();
487     Aircraft->in.BuoyantForce  = BuoyantForces->GetForces();
488     Aircraft->in.AeroMoment    = Aerodynamics->GetMoments();
489     Aircraft->in.PropMoment    = Propulsion->GetMoments();
490     Aircraft->in.GroundMoment  = GroundReactions->GetMoments();
491     Aircraft->in.ExternalMoment = ExternalReactions->GetMoments();
492     Aircraft->in.BuoyantMoment = BuoyantForces->GetMoments();
493     break;
494   case eAccelerations:
495     Accelerations->in.J        = MassBalance->GetJ();
496     Accelerations->in.Jinv     = MassBalance->GetJinv();
497     Accelerations->in.Ti2b     = Propagate->GetTi2b();
498     Accelerations->in.Tb2i     = Propagate->GetTb2i();
499     Accelerations->in.Tec2b    = Propagate->GetTec2b();
500     Accelerations->in.Tec2i    = Propagate->GetTec2i();
501     Accelerations->in.qAttitudeECI = Propagate->GetQuaternionECI();
502     Accelerations->in.Moment   = Aircraft->GetMoments();
503     Accelerations->in.GroundMoment  = GroundReactions->GetMoments();
504     Accelerations->in.Force    = Aircraft->GetForces();
505     Accelerations->in.GroundForce   = GroundReactions->GetForces();
506     Accelerations->in.GAccel   = Inertial->GetGAccel(Propagate->GetRadius());
507     Accelerations->in.J2Grav  = Inertial->GetGravityJ2(Propagate->GetLocation());
508     Accelerations->in.vPQRi    = Propagate->GetPQRi();
509     Accelerations->in.vPQR     = Propagate->GetPQR();
510     Accelerations->in.vUVW     = Propagate->GetUVW();
511     Accelerations->in.vInertialPosition = Propagate->GetInertialPosition();
512     Accelerations->in.DeltaT   = dT;
513     Accelerations->in.Mass     = MassBalance->GetMass();
514     Accelerations->in.MultipliersList = GroundReactions->GetMultipliersList();
515     Accelerations->in.TerrainVelocity = Propagate->GetTerrainVelocity();
516     Accelerations->in.TerrainAngularVel = Propagate->GetTerrainAngularVelocity();
517     break;
518   default:
519     break;
520   }
521 }
522
523 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
524
525 void FGFDMExec::LoadPlanetConstants(void)
526 {
527   Propagate->in.vOmegaPlanet     = Inertial->GetOmegaPlanet();
528   Accelerations->in.vOmegaPlanet = Inertial->GetOmegaPlanet();
529   Propagate->in.SemiMajor        = Inertial->GetSemimajor();
530   Propagate->in.SemiMinor        = Inertial->GetSemiminor();
531   Auxiliary->in.SLGravity        = Inertial->SLgravity();
532 }
533
534 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
535
536 void FGFDMExec::LoadModelConstants(void)
537 {
538   Winds->in.wingspan             = Aircraft->GetWingSpan();
539   Aerodynamics->in.Wingarea      = Aircraft->GetWingArea();
540   Aerodynamics->in.Wingchord     = Aircraft->Getcbar();
541   Aerodynamics->in.Wingincidence = Aircraft->GetWingIncidence();
542   Aerodynamics->in.Wingspan      = Aircraft->GetWingSpan();
543   Auxiliary->in.Wingspan         = Aircraft->GetWingSpan();
544   Auxiliary->in.Wingchord        = Aircraft->Getcbar();
545   GroundReactions->in.vXYZcg     = MassBalance->GetXYZcg();
546
547   LoadPlanetConstants();
548 }
549
550 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
551 // This call will cause the sim time to reset to 0.0
552
553 bool FGFDMExec::RunIC(void)
554 {
555   FGPropulsion* propulsion = (FGPropulsion*)Models[ePropulsion];
556
557   SuspendIntegration(); // saves the integration rate, dt, then sets it to 0.0.
558   Initialize(IC);
559
560   Models[eInput]->InitModel();
561   Models[eOutput]->InitModel();
562
563   Run();
564   ResumeIntegration(); // Restores the integration rate to what it was.
565
566   if (debug_lvl > 0) {
567     MassBalance->GetMassPropertiesReport(0);
568
569     cout << endl << fgblue << highint
570          << "End of vehicle configuration loading." << endl
571          << "-------------------------------------------------------------------------------"
572          << reset << std::setprecision(6) << endl;
573   }
574
575   for (unsigned int n=0; n < propulsion->GetNumEngines(); ++n) {
576     if (IC->IsEngineRunning(n)) {
577       try {
578         propulsion->InitRunning(n);
579       } catch (const string& str) {
580         cerr << str << endl;
581         return false;
582       }
583     }
584   }
585
586   return true;
587 }
588
589 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
590
591 void FGFDMExec::Initialize(FGInitialCondition* FGIC)
592 {
593   Propagate->SetInitialState(FGIC);
594   Winds->SetWindNED(FGIC->GetWindNEDFpsIC());
595   Run();
596   Propagate->InitializeDerivatives();
597 }
598
599 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
600
601 void FGFDMExec::ResetToInitialConditions(int mode)
602 {
603   if (Constructing) return;
604
605   if (mode == 1) Output->SetStartNewOutput();
606
607   for (unsigned int i = 0; i < Models.size(); i++) {
608     // The Input/Output models will be initialized during the RunIC() execution
609     if (i == eInput || i == eOutput) continue;
610
611     LoadInputs(i);
612     Models[i]->InitModel();
613   }
614
615   RunIC();
616
617   if (Script)
618     Script->ResetEvents();
619   else
620     Setsim_time(0.0);
621 }
622
623 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
624
625 vector <string> FGFDMExec::EnumerateFDMs(void)
626 {
627   vector <string> FDMList;
628   FGAircraft* Aircraft = (FGAircraft*)Models[eAircraft];
629
630   FDMList.push_back(Aircraft->GetAircraftName());
631
632   for (unsigned int i=1; i<ChildFDMList.size(); i++) {
633     FDMList.push_back(ChildFDMList[i]->exec->GetAircraft()->GetAircraftName());
634   }
635
636   return FDMList;
637 }
638
639 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
640
641 bool FGFDMExec::LoadScript(const string& script, double deltaT, const string& initfile)
642 {
643   bool result;
644
645   Script = new FGScript(this);
646   result = Script->LoadScript(RootDir + script, deltaT, initfile);
647
648   return result;
649 }
650
651 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
652
653 bool FGFDMExec::LoadModel(const string& AircraftPath, const string& EnginePath, const string& SystemsPath,
654                 const string& model, bool addModelToPath)
655 {
656   FGFDMExec::AircraftPath = RootDir + AircraftPath;
657   FGFDMExec::EnginePath = RootDir + EnginePath;
658   FGFDMExec::SystemsPath = RootDir + SystemsPath;
659
660   return LoadModel(model, addModelToPath);
661 }
662
663 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
664
665 bool FGFDMExec::LoadModel(const string& model, bool addModelToPath)
666 {
667   string aircraftCfgFileName;
668   bool result = false; // initialize result to false, indicating input file not yet read
669
670   modelName = model; // Set the class modelName attribute
671
672   if( AircraftPath.empty() || EnginePath.empty() || SystemsPath.empty()) {
673     cerr << "Error: attempted to load aircraft with undefined ";
674     cerr << "aircraft, engine, and system paths" << endl;
675     return false;
676   }
677
678   FullAircraftPath = AircraftPath;
679   if (addModelToPath) FullAircraftPath += "/" + model;
680   aircraftCfgFileName = FullAircraftPath + "/" + model + ".xml";
681
682   if (modelLoaded) {
683     DeAllocate();
684     Allocate();
685   }
686
687   int saved_debug_lvl = debug_lvl;
688   FGXMLFileRead XMLFileRead;
689   Element *document = XMLFileRead.LoadXMLDocument(aircraftCfgFileName); // "document" is a class member
690
691   if (document) {
692     if (IsChild) debug_lvl = 0;
693
694     ReadPrologue(document);
695
696     if (IsChild) debug_lvl = saved_debug_lvl;
697
698     // Process the fileheader element in the aircraft config file. This element is OPTIONAL.
699     Element* element = document->FindElement("fileheader");
700     if (element) {
701       result = ReadFileHeader(element);
702       if (!result) {
703         cerr << endl << "Aircraft fileheader element has problems in file " << aircraftCfgFileName << endl;
704         return result;
705       }
706     }
707
708     if (IsChild) debug_lvl = 0;
709
710     // Process the metrics element. This element is REQUIRED.
711     element = document->FindElement("metrics");
712     if (element) {
713       result = ((FGAircraft*)Models[eAircraft])->Load(element);
714       if (!result) {
715         cerr << endl << "Aircraft metrics element has problems in file " << aircraftCfgFileName << endl;
716         return result;
717       }
718     } else {
719       cerr << endl << "No metrics element was found in the aircraft config file." << endl;
720       return false;
721     }
722
723     // Process the mass_balance element. This element is REQUIRED.
724     element = document->FindElement("mass_balance");
725     if (element) {
726       result = ((FGMassBalance*)Models[eMassBalance])->Load(element);
727       if (!result) {
728         cerr << endl << "Aircraft mass_balance element has problems in file " << aircraftCfgFileName << endl;
729         return result;
730       }
731     } else {
732       cerr << endl << "No mass_balance element was found in the aircraft config file." << endl;
733       return false;
734     }
735
736     // Process the ground_reactions element. This element is REQUIRED.
737     element = document->FindElement("ground_reactions");
738     if (element) {
739       result = ((FGGroundReactions*)Models[eGroundReactions])->Load(element);
740       if (!result) {
741         cerr << endl << "Aircraft ground_reactions element has problems in file " << aircraftCfgFileName << endl;
742         return result;
743       }
744       ((FGFCS*)Models[eSystems])->AddGear(((FGGroundReactions*)Models[eGroundReactions])->GetNumGearUnits());
745     } else {
746       cerr << endl << "No ground_reactions element was found in the aircraft config file." << endl;
747       return false;
748     }
749
750     // Process the external_reactions element. This element is OPTIONAL.
751     element = document->FindElement("external_reactions");
752     if (element) {
753       result = ((FGExternalReactions*)Models[eExternalReactions])->Load(element);
754       if (!result) {
755         cerr << endl << "Aircraft external_reactions element has problems in file " << aircraftCfgFileName << endl;
756         return result;
757       }
758     }
759
760     // Process the buoyant_forces element. This element is OPTIONAL.
761     element = document->FindElement("buoyant_forces");
762     if (element) {
763       result = ((FGBuoyantForces*)Models[eBuoyantForces])->Load(element);
764       if (!result) {
765         cerr << endl << "Aircraft buoyant_forces element has problems in file " << aircraftCfgFileName << endl;
766         return result;
767       }
768     }
769
770     // Process the propulsion element. This element is OPTIONAL.
771     element = document->FindElement("propulsion");
772     if (element) {
773       result = ((FGPropulsion*)Models[ePropulsion])->Load(element);
774       if (!result) {
775         cerr << endl << "Aircraft propulsion element has problems in file " << aircraftCfgFileName << endl;
776         return result;
777       }
778       for (unsigned int i=0; i<((FGPropulsion*)Models[ePropulsion])->GetNumEngines(); i++)
779         ((FGFCS*)Models[eSystems])->AddThrottle();
780     }
781
782     // Process the system element[s]. This element is OPTIONAL, and there may be more than one.
783     element = document->FindElement("system");
784     while (element) {
785       result = ((FGFCS*)Models[eSystems])->Load(element);
786       if (!result) {
787         cerr << endl << "Aircraft system element has problems in file " << aircraftCfgFileName << endl;
788         return result;
789       }
790       element = document->FindNextElement("system");
791     }
792
793     // Process the autopilot element. This element is OPTIONAL.
794     element = document->FindElement("autopilot");
795     if (element) {
796       result = ((FGFCS*)Models[eSystems])->Load(element);
797       if (!result) {
798         cerr << endl << "Aircraft autopilot element has problems in file " << aircraftCfgFileName << endl;
799         return result;
800       }
801     }
802
803     // Process the flight_control element. This element is OPTIONAL.
804     element = document->FindElement("flight_control");
805     if (element) {
806       result = ((FGFCS*)Models[eSystems])->Load(element);
807       if (!result) {
808         cerr << endl << "Aircraft flight_control element has problems in file " << aircraftCfgFileName << endl;
809         return result;
810       }
811     }
812
813     // Process the aerodynamics element. This element is OPTIONAL, but almost always expected.
814     element = document->FindElement("aerodynamics");
815     if (element) {
816       result = ((FGAerodynamics*)Models[eAerodynamics])->Load(element);
817       if (!result) {
818         cerr << endl << "Aircraft aerodynamics element has problems in file " << aircraftCfgFileName << endl;
819         return result;
820       }
821     } else {
822       cerr << endl << "No expected aerodynamics element was found in the aircraft config file." << endl;
823     }
824
825     // Process the input element. This element is OPTIONAL, and there may be more than one.
826     element = document->FindElement("input");
827     while (element) {
828       if (!static_cast<FGInput*>(Models[eInput])->Load(element))
829         return false;
830
831       element = document->FindNextElement("input");
832     }
833
834     // Process the output element[s]. This element is OPTIONAL, and there may be
835     // more than one.
836     element = document->FindElement("output");
837     while (element) {
838       if (!static_cast<FGOutput*>(Models[eOutput])->Load(element))
839         return false;
840
841       element = document->FindNextElement("output");
842     }
843
844     // Lastly, process the child element. This element is OPTIONAL - and NOT YET SUPPORTED.
845     element = document->FindElement("child");
846     if (element) {
847       result = ReadChild(element);
848       if (!result) {
849         cerr << endl << "Aircraft child element has problems in file " << aircraftCfgFileName << endl;
850         return result;
851       }
852     }
853
854     // Since all vehicle characteristics have been loaded, place the values in the Inputs
855     // structure for the FGModel-derived classes.
856     LoadModelConstants();
857
858     modelLoaded = true;
859
860     if (IsChild) debug_lvl = saved_debug_lvl;
861
862   } else {
863     cerr << fgred
864          << "  JSBSim failed to open the configuration file: " << aircraftCfgFileName
865          << fgdef << endl;
866   }
867
868   for (unsigned int i=0; i< Models.size(); i++) LoadInputs(i);
869
870   if (result) {
871     struct PropertyCatalogStructure masterPCS;
872     masterPCS.base_string = "";
873     masterPCS.node = Root->GetNode();
874     BuildPropertyCatalog(&masterPCS);
875   }
876
877   return result;
878 }
879
880 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
881
882 string FGFDMExec::GetPropulsionTankReport()
883 {
884   return ((FGPropulsion*)Models[ePropulsion])->GetPropulsionTankReport();
885 }
886
887 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
888
889 void FGFDMExec::BuildPropertyCatalog(struct PropertyCatalogStructure* pcs)
890 {
891   struct PropertyCatalogStructure* pcsNew = new struct PropertyCatalogStructure;
892
893   for (int i=0; i<pcs->node->nChildren(); i++) {
894     string access="";
895     pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getName();
896     int node_idx = pcs->node->getChild(i)->getIndex();
897     if (node_idx != 0) {
898       pcsNew->base_string = CreateIndexedPropertyName(pcsNew->base_string, node_idx);
899     }
900     if (pcs->node->getChild(i)->nChildren() == 0) {
901       if (pcsNew->base_string.substr(0,12) == string("/fdm/jsbsim/")) {
902         pcsNew->base_string = pcsNew->base_string.erase(0,12);
903       }
904       if (pcs->node->getChild(i)->getAttribute(SGPropertyNode::READ)) access="R";
905       if (pcs->node->getChild(i)->getAttribute(SGPropertyNode::WRITE)) access+="W";
906       PropertyCatalog.push_back(pcsNew->base_string+" ("+access+")");
907     } else {
908       pcsNew->node = (FGPropertyNode*)pcs->node->getChild(i);
909       BuildPropertyCatalog(pcsNew);
910     }
911   }
912   delete pcsNew;
913 }
914
915 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
916
917 string FGFDMExec::QueryPropertyCatalog(const string& in)
918 {
919   string results="";
920   for (unsigned i=0; i<PropertyCatalog.size(); i++) {
921     if (PropertyCatalog[i].find(in) != string::npos) results += PropertyCatalog[i] + "\n";
922   }
923   if (results.empty()) return "No matches found\n";
924   return results;
925 }
926
927 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
928
929 void FGFDMExec::PrintPropertyCatalog(void)
930 {
931   cout << endl;
932   cout << "  " << fgblue << highint << underon << "Property Catalog for "
933        << modelName << reset << endl << endl;
934   for (unsigned i=0; i<PropertyCatalog.size(); i++) {
935     cout << "    " << PropertyCatalog[i] << endl;
936   }
937 }
938
939 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
940
941 void FGFDMExec::PrintSimulationConfiguration(void) const
942 {
943   cout << endl << "Simulation Configuration" << endl << "------------------------" << endl;
944   cout << MassBalance->Name << endl;
945   cout << GroundReactions->Name << endl;
946   cout << Aerodynamics->Name << endl;
947   cout << Propulsion->Name << endl;
948 }
949
950 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
951
952 bool FGFDMExec::ReadFileHeader(Element* el)
953 {
954   bool result = true; // true for success
955
956   if (debug_lvl == 0) return result;
957
958   if (IsChild) {
959     cout << endl <<highint << fgblue << "Reading child model: " << IdFDM << reset << endl << endl;
960   }
961
962   if (el->FindElement("description"))
963     cout << "  Description:   " << el->FindElement("description")->GetDataLine() << endl;
964   if (el->FindElement("author"))
965     cout << "  Model Author:  " << el->FindElement("author")->GetDataLine() << endl;
966   if (el->FindElement("filecreationdate"))
967     cout << "  Creation Date: " << el->FindElement("filecreationdate")->GetDataLine() << endl;
968   if (el->FindElement("version"))
969     cout << "  Version:       " << el->FindElement("version")->GetDataLine() << endl;
970
971   return result;
972 }
973
974 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
975
976 bool FGFDMExec::ReadPrologue(Element* el) // el for ReadPrologue is the document element
977 {
978   bool result = true; // true for success
979
980   if (!el) return false;
981
982   string AircraftName = el->GetAttributeValue("name");
983   ((FGAircraft*)Models[eAircraft])->SetAircraftName(AircraftName);
984
985   if (debug_lvl & 1) cout << underon << "Reading Aircraft Configuration File"
986             << underoff << ": " << highint << AircraftName << normint << endl;
987
988   CFGVersion = el->GetAttributeValue("version");
989   Release    = el->GetAttributeValue("release");
990
991   if (debug_lvl & 1)
992     cout << "                            Version: " << highint << CFGVersion
993                                                     << normint << endl;
994   if (CFGVersion != needed_cfg_version) {
995     cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
996             " RESULTS WILL BE UNPREDICTABLE !!" << endl;
997     cerr << "Current version needed is: " << needed_cfg_version << endl;
998     cerr << "         You have version: " << CFGVersion << endl << fgdef << endl;
999     return false;
1000   }
1001
1002   if (Release == "ALPHA" && (debug_lvl & 1)) {
1003     cout << endl << endl
1004          << highint << "This aircraft model is an " << fgred << Release
1005          << reset << highint << " release!!!" << endl << endl << reset
1006          << "This aircraft model may not even properly load, and probably"
1007          << " will not fly as expected." << endl << endl
1008          << fgred << highint << "Use this model for development purposes ONLY!!!"
1009          << normint << reset << endl << endl;
1010   } else if (Release == "BETA" && (debug_lvl & 1)) {
1011     cout << endl << endl
1012          << highint << "This aircraft model is a " << fgred << Release
1013          << reset << highint << " release!!!" << endl << endl << reset
1014          << "This aircraft model probably will not fly as expected." << endl << endl
1015          << fgblue << highint << "Use this model for development purposes ONLY!!!"
1016          << normint << reset << endl << endl;
1017   } else if (Release == "PRODUCTION" && (debug_lvl & 1)) {
1018     cout << endl << endl
1019          << highint << "This aircraft model is a " << fgblue << Release
1020          << reset << highint << " release." << endl << endl << reset;
1021   } else if (debug_lvl & 1) {
1022     cout << endl << endl
1023          << highint << "This aircraft model is an " << fgred << Release
1024          << reset << highint << " release!!!" << endl << endl << reset
1025          << "This aircraft model may not even properly load, and probably"
1026          << " will not fly as expected." << endl << endl
1027          << fgred << highint << "Use this model for development purposes ONLY!!!"
1028          << normint << reset << endl << endl;
1029   }
1030
1031   return result;
1032 }
1033
1034 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1035
1036 bool FGFDMExec::ReadChild(Element* el)
1037 {
1038   // Add a new childData object to the child FDM list
1039   // Populate that childData element with a new FDMExec object
1040   // Set the IsChild flag for that FDMExec object
1041   // Get the aircraft name
1042   // set debug level to print out no additional data for child objects
1043   // Load the model given the aircraft name
1044   // reset debug level to prior setting
1045
1046   struct childData* child = new childData;
1047
1048   child->exec = new FGFDMExec(Root, FDMctr);
1049   child->exec->SetChild(true);
1050
1051   string childAircraft = el->GetAttributeValue("name");
1052   string sMated = el->GetAttributeValue("mated");
1053   if (sMated == "false") child->mated = false; // child objects are mated by default.
1054   string sInternal = el->GetAttributeValue("internal");
1055   if (sInternal == "true") child->internal = true; // child objects are external by default.
1056
1057   child->exec->SetAircraftPath( AircraftPath );
1058   child->exec->SetEnginePath( EnginePath );
1059   child->exec->SetSystemsPath( SystemsPath );
1060   child->exec->LoadModel(childAircraft);
1061
1062   Element* location = el->FindElement("location");
1063   if (location) {
1064     child->Loc = location->FindElementTripletConvertTo("IN");
1065   } else {
1066     cerr << endl << highint << fgred << "  No location was found for this child object!" << reset << endl;
1067     exit(-1);
1068   }
1069
1070   Element* orientation = el->FindElement("orient");
1071   if (orientation) {
1072     child->Orient = orientation->FindElementTripletConvertTo("RAD");
1073   } else if (debug_lvl > 0) {
1074     cerr << endl << highint << "  No orientation was found for this child object! Assuming 0,0,0." << reset << endl;
1075   }
1076
1077   ChildFDMList.push_back(child);
1078
1079   return true;
1080 }
1081
1082 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1083
1084 FGPropertyManager* FGFDMExec::GetPropertyManager(void)
1085 {
1086   return instance;
1087 }
1088
1089 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1090
1091 FGTrim* FGFDMExec::GetTrim(void)
1092 {
1093   delete Trim;
1094   Trim = new FGTrim(this,tNone);
1095   return Trim;
1096 }
1097
1098 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1099
1100 void FGFDMExec::CheckIncrementalHold(void)
1101 {
1102   // Only check if increment then hold is on
1103   if( IncrementThenHolding ) {
1104
1105     if (TimeStepsUntilHold == 0) {
1106
1107       // Should hold simulation if TimeStepsUntilHold has reached zero
1108       holding = true;
1109
1110       // Still need to decrement TimeStepsUntilHold as value of -1
1111       // indicates that incremental then hold is turned off
1112       IncrementThenHolding = false;
1113       TimeStepsUntilHold--;
1114
1115     } else if ( TimeStepsUntilHold > 0 ) {
1116       // Keep decrementing until 0 is reached
1117       TimeStepsUntilHold--;
1118     }
1119   }
1120 }
1121
1122 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1123
1124 void FGFDMExec::DoTrim(int mode)
1125 {
1126   if (Constructing) return;
1127
1128   if (mode < 0 || mode > JSBSim::tNone)
1129     throw("Illegal trimming mode!");
1130
1131   FGTrim trim(this, (JSBSim::TrimMode)mode);
1132   bool success = trim.DoTrim();
1133   trim.Report();
1134
1135   if (!success)
1136     throw("Trim Failed");
1137
1138   trim_completed = 1;
1139 }
1140
1141 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1142
1143 void FGFDMExec::SRand(int sr)
1144 {
1145   RandomSeed = sr;
1146   gaussian_random_number_phase = 0;
1147   srand(RandomSeed);
1148 }
1149
1150 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1151 //    The bitmasked value choices are as follows:
1152 //    unset: In this case (the default) JSBSim would only print
1153 //       out the normally expected messages, essentially echoing
1154 //       the config files as they are read. If the environment
1155 //       variable is not set, debug_lvl is set to 1 internally
1156 //    0: This requests JSBSim not to output any messages
1157 //       whatsoever.
1158 //    1: This value explicity requests the normal JSBSim
1159 //       startup messages
1160 //    2: This value asks for a message to be printed out when
1161 //       a class is instantiated
1162 //    4: When this value is set, a message is displayed when a
1163 //       FGModel object executes its Run() method
1164 //    8: When this value is set, various runtime state variables
1165 //       are printed out periodically
1166 //    16: When set various parameters are sanity checked and
1167 //       a message is printed out when they go out of bounds
1168
1169 void FGFDMExec::Debug(int from)
1170 {
1171   if (debug_lvl <= 0) return;
1172
1173   if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output
1174     if (from == 0) { // Constructor
1175       cout << "\n\n     "
1176            << "JSBSim Flight Dynamics Model v" << JSBSim_version << endl;
1177       cout << "            [JSBSim-ML v" << needed_cfg_version << "]\n\n";
1178       cout << "JSBSim startup beginning ...\n\n";
1179       if (disperse == 1) cout << "Dispersions are ON." << endl << endl;
1180     } else if (from == 3) {
1181       cout << "\n\nJSBSim startup complete\n\n";
1182     }
1183   }
1184   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
1185     if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
1186     if (from == 1) cout << "Destroyed:    FGFDMExec" << endl;
1187   }
1188   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
1189     if (from == 2) {
1190       cout << "================== Frame: " << Frame << "  Time: "
1191            << sim_time << " dt: " << dT << endl;
1192     }
1193   }
1194   if (debug_lvl & 8 ) { // Runtime state variables
1195   }
1196   if (debug_lvl & 16) { // Sanity checking
1197   }
1198   if (debug_lvl & 64) {
1199     if (from == 0) { // Constructor
1200       cout << IdSrc << endl;
1201       cout << IdHdr << endl;
1202     }
1203   }
1204 }
1205 }
1206
1207