1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 Purpose: Schedules and runs the model routines.
8 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU Lesser General Public License as published by the Free Software
12 Foundation; either version 2 of the License, or (at your option) any later
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 Lesser General Public License for more
20 You should have received a copy of the GNU Lesser 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.
24 Further information about the GNU Lesser General Public License can also be found on
25 the world wide web at http://www.gnu.org.
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
30 This class wraps up the simulation scheduling routines.
33 --------------------------------------------------------------------------------
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 COMMENTS, REFERENCES, and NOTES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45 # include <simgear/compiler.h>
46 # include STL_IOSTREAM
47 # include STL_ITERATOR
49 # if defined(sgi) && !defined(__GNUC__) && (_COMPILER_VERSION < 740)
50 # include <iostream.h>
57 #include "FGFDMExec.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 #include <input_output/FGScript.h>
79 static const char *IdSrc = "$Id$";
80 static const char *IdHdr = ID_FDMEXEC;
82 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
86 unsigned int FGFDMExec::FDMctr = 0;
87 FGPropertyManager* FGFDMExec::master=0;
89 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
93 void checkTied ( FGPropertyManager *node )
95 int N = node->nChildren();
98 for (int i=0; i<N; i++) {
99 if (node->getChild(i)->nChildren() ) {
100 checkTied( (FGPropertyManager*)node->getChild(i) );
101 } else if ( node->getChild(i)->isTied() ) {
102 name = ((FGPropertyManager*)node->getChild(i))->GetFullyQualifiedName();
103 cerr << name << " is tied" << endl;
108 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 FGFDMExec::FGFDMExec(FGPropertyManager* root) : Root(root)
139 // Multiple FDM's are stopped for now. We need to ensure that
140 // the "user" instance always gets the zeroeth instance number,
141 // because there may be instruments or scripts tied to properties
142 // in the jsbsim[0] node.
143 // ToDo: it could be that when JSBSim is reset and a new FDM is wanted, that
144 // process might try setting FDMctr = 0. Then the line below would not need
145 // to be commented out.
150 char* num = getenv("JSBSIM_DEBUG");
151 if (num) debug_lvl = atoi(num); // set debug level
152 } catch (...) { // if error set to 1
156 if (Root == 0) master= new FGPropertyManager;
159 instance = master->GetNode("/fdm/jsbsim",IdFDM,true);
161 // this is to catch errors in binding member functions to the property tree.
164 } catch ( string msg ) {
165 cout << "Caught error: " << msg << endl;
170 typedef int (FGFDMExec::*iPMF)(void) const;
171 instance->Tie("simulation/do_trim", this, (iPMF)0, &FGFDMExec::DoTrim);
172 instance->Tie("simulation/terminate", (int *)&Terminate);
173 Constructing = false;
176 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178 FGFDMExec::~FGFDMExec()
180 instance->Untie("simulation/do_trim");
181 instance->Untie("simulation/terminate");
185 checkTied( instance );
186 if (Root == 0) delete master;
187 } catch ( string msg ) {
188 cout << "Caught error: " << msg << endl;
191 for (unsigned int i=1; i<SlaveFDMList.size(); i++) delete SlaveFDMList[i]->exec;
192 SlaveFDMList.clear();
194 //ToDo remove property catalog.
199 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 bool FGFDMExec::Allocate(void)
205 Atmosphere = new FGAtmosphere(this);
206 FCS = new FGFCS(this);
207 Propulsion = new FGPropulsion(this);
208 MassBalance = new FGMassBalance(this);
209 Aerodynamics = new FGAerodynamics (this);
210 Inertial = new FGInertial(this);
211 GroundReactions = new FGGroundReactions(this);
212 Aircraft = new FGAircraft(this);
213 Propagate = new FGPropagate(this);
214 Auxiliary = new FGAuxiliary(this);
215 Input = new FGInput(this);
217 GroundCallback = new FGGroundCallback();
218 State = new FGState(this); // This must be done here, as the FGState
219 // class needs valid pointers to the above
222 // Initialize models so they can communicate with each other
224 if (!Atmosphere->InitModel()) {
225 cerr << fgred << "Atmosphere model init failed" << fgdef << endl;
227 if (!FCS->InitModel()) {
228 cerr << fgred << "FCS model init failed" << fgdef << endl;
230 if (!Propulsion->InitModel()) {
231 cerr << fgred << "FGPropulsion model init failed" << fgdef << endl;
233 if (!MassBalance->InitModel()) {
234 cerr << fgred << "FGMassBalance model init failed" << fgdef << endl;
236 if (!Aerodynamics->InitModel()) {
237 cerr << fgred << "FGAerodynamics model init failed" << fgdef << endl;
239 if (!Inertial->InitModel()) {
240 cerr << fgred << "FGInertial model init failed" << fgdef << endl;
242 if (!GroundReactions->InitModel()) {
243 cerr << fgred << "Ground Reactions model init failed" << fgdef << endl;
245 if (!Aircraft->InitModel()) {
246 cerr << fgred << "Aircraft model init failed" << fgdef << endl;
248 if (!Propagate->InitModel()) {
249 cerr << fgred << "Propagate model init failed" << fgdef << endl;
251 if (!Auxiliary->InitModel()) {
252 cerr << fgred << "Auxiliary model init failed" << fgdef << endl;
254 if (!Input->InitModel()) {
255 cerr << fgred << "Input model init failed" << fgdef << endl;
258 if (Error > 0) result = false;
260 IC = new FGInitialCondition(this);
262 // Schedule a model. The second arg (the integer) is the pass number. For
263 // instance, the atmosphere model could get executed every fifth pass it is called
264 // by the executive. IC and Trim objects are NOT scheduled.
267 Schedule(Atmosphere, 1);
269 Schedule(Propulsion, 1);
270 Schedule(MassBalance, 1);
271 Schedule(Aerodynamics, 1);
272 Schedule(Inertial, 1);
273 Schedule(GroundReactions, 1);
274 Schedule(Aircraft, 1);
275 Schedule(Propagate, 1);
276 Schedule(Auxiliary, 1);
283 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285 bool FGFDMExec::DeAllocate(void)
294 delete GroundReactions;
301 for (unsigned i=0; i<Outputs.size(); i++) delete Outputs[i];
307 delete GroundCallback;
329 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331 int FGFDMExec::Schedule(FGModel* model, int rate)
333 FGModel* model_iterator;
335 model_iterator = FirstModel;
337 if (model_iterator == 0L) { // this is the first model
340 FirstModel->NextModel = 0L;
341 FirstModel->SetRate(rate);
343 } else { // subsequent model
345 while (model_iterator->NextModel != 0L) {
346 model_iterator = model_iterator->NextModel;
348 model_iterator->NextModel = model;
349 model_iterator->NextModel->SetRate(rate);
356 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
358 bool FGFDMExec::Run(void)
361 FGModel* model_iterator;
363 model_iterator = FirstModel;
364 if (model_iterator == 0L) return false;
368 for (unsigned int i=1; i<SlaveFDMList.size(); i++) {
369 // SlaveFDMList[i]->exec->State->Initialize(); // Transfer state to the slave FDM
370 // SlaveFDMList[i]->exec->Run();
373 if (Script != 0) success = Script->RunScript(); // returns true if success
375 while (model_iterator != 0L) {
376 model_iterator->Run();
377 model_iterator = model_iterator->NextModel;
381 if (!Holding()) State->IncrTime();
382 if (Terminate) success = false;
386 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387 // This call will cause the sim time to reset to 0.0
389 bool FGFDMExec::RunIC(void)
391 State->SuspendIntegration();
392 State->Initialize(IC);
394 State->ResumeIntegration();
399 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
401 void FGFDMExec::SetGroundCallback(FGGroundCallback* p)
403 delete GroundCallback;
407 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
409 double FGFDMExec::GetSimTime(void)
411 return (State->Getsim_time());
414 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
416 double FGFDMExec::GetDeltaT(void)
418 return (State->Getdt());
421 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
423 vector <string> FGFDMExec::EnumerateFDMs(void)
425 vector <string> FDMList;
427 FDMList.push_back(Aircraft->GetAircraftName());
429 for (unsigned int i=1; i<SlaveFDMList.size(); i++) {
430 FDMList.push_back(SlaveFDMList[i]->exec->GetAircraft()->GetAircraftName());
436 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
438 bool FGFDMExec::LoadScript(string script)
442 Script = new FGScript(this);
443 result = Script->LoadScript(script);
448 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
450 bool FGFDMExec::LoadModel(string AircraftPath, string EnginePath, string model,
453 FGFDMExec::AircraftPath = AircraftPath;
454 FGFDMExec::EnginePath = EnginePath;
456 return LoadModel(model, addModelToPath);
459 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
461 bool FGFDMExec::LoadModel(string model, bool addModelToPath)
464 string aircraftCfgFileName;
465 string separator = "/";
466 Element* element = 0L;
468 modelName = model; // Set the class modelName attribute
474 if( AircraftPath.empty() || EnginePath.empty() ) {
475 cerr << "Error: attempted to load aircraft with undefined ";
476 cerr << "aircraft and engine paths" << endl;
480 FullAircraftPath = AircraftPath;
481 if (addModelToPath) FullAircraftPath += separator + model;
482 aircraftCfgFileName = FullAircraftPath + separator + model + ".xml";
489 document = LoadXMLDocument(aircraftCfgFileName); // "document" is a class member
490 ReadPrologue(document);
491 element = document->GetElement();
494 while (element && result) {
495 string element_name = element->GetName();
496 if (element_name == "fileheader" ) result = ReadFileHeader(element);
497 else if (element_name == "slave") result = ReadSlave(element);
498 else if (element_name == "metrics") result = Aircraft->Load(element);
499 else if (element_name == "mass_balance") result = MassBalance->Load(element);
500 else if (element_name == "ground_reactions") result = GroundReactions->Load(element);
501 else if (element_name == "propulsion") result = Propulsion->Load(element);
502 else if (element_name == "autopilot") result = FCS->Load(element);
503 else if (element_name == "flight_control") result = FCS->Load(element);
504 else if (element_name == "aerodynamics") result = Aerodynamics->Load(element);
505 else if (element_name == "input") result = Input->Load(element);
506 else if (element_name == "output") {
507 FGOutput* Output = new FGOutput(this);
510 Outputs.push_back(Output);
511 result = Output->Load(element);
514 cerr << "Found unexpected subsystem: " << element_name << ", exiting." << endl;
518 element = document->GetNextElement();
526 << " JSBSim failed to load aircraft and/or engine model"
531 struct PropertyCatalogStructure masterPCS;
532 masterPCS.base_string = "";
533 masterPCS.node = (FGPropertyManager*)master;
535 BuildPropertyCatalog(&masterPCS);
540 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
542 void FGFDMExec::BuildPropertyCatalog(struct PropertyCatalogStructure* pcs)
544 struct PropertyCatalogStructure* pcsNew = new struct PropertyCatalogStructure;
548 for (unsigned int i=0; i<pcs->node->nChildren(); i++) {
549 pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getName();
550 node_idx = pcs->node->getChild(i)->getIndex();
551 sprintf(int_buf, "[%d]", node_idx);
552 if (node_idx != 0) pcsNew->base_string += string(int_buf);
553 if (pcs->node->getChild(i)->nChildren() == 0) {
554 PropertyCatalog.push_back(pcsNew->base_string);
556 pcsNew->node = (FGPropertyManager*)pcs->node->getChild(i);
557 BuildPropertyCatalog(pcsNew);
563 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
565 string FGFDMExec::QueryPropertyCatalog(string in)
568 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
569 if (PropertyCatalog[i].find(in) != string::npos) results += PropertyCatalog[i] + "\n";
571 if (results.empty()) return "No matches found\n";
575 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
577 void FGFDMExec::PrintPropertyCatalog(void)
580 cout << " " << fgblue << highint << underon << "Property Catalog for "
581 << modelName << reset << endl << endl;
582 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
583 cout << " " << PropertyCatalog[i] << endl;
587 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
589 bool FGFDMExec::ReadFileHeader(Element* el)
591 bool result = true; // true for success
593 if (debug_lvl & ~1) return result;
595 if (el->FindElement("author"))
596 cout << " Model Author: " << el->FindElement("author")->GetDataLine() << endl;
597 if (el->FindElement("filecreationdate"))
598 cout << " Creation Date: " << el->FindElement("filecreationdate")->GetDataLine() << endl;
599 if (el->FindElement("version"))
600 cout << " Version: " << el->FindElement("version")->GetDataLine() << endl;
601 if (el->FindElement("description"))
602 cout << " Description: " << el->FindElement("description")->GetDataLine() << endl;
607 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
609 bool FGFDMExec::ReadPrologue(Element* el) // el for ReadPrologue is the document element
611 bool result = true; // true for success
613 if (!el) return false;
615 string AircraftName = el->GetAttributeValue("name");
616 Aircraft->SetAircraftName(AircraftName);
618 if (debug_lvl & 1) cout << underon << "Reading Aircraft Configuration File"
619 << underoff << ": " << highint << AircraftName << normint << endl;
621 CFGVersion = el->GetAttributeValue("version");
622 Release = el->GetAttributeValue("release");
625 cout << " Version: " << highint << CFGVersion
627 if (CFGVersion != needed_cfg_version) {
628 cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
629 " RESULTS WILL BE UNPREDICTABLE !!" << endl;
630 cerr << "Current version needed is: " << needed_cfg_version << endl;
631 cerr << " You have version: " << CFGVersion << endl << fgdef << endl;
635 if (Release == "ALPHA" && (debug_lvl & 1)) {
637 << highint << "This aircraft model is an " << fgred << Release
638 << reset << highint << " release!!!" << endl << endl << reset
639 << "This aircraft model may not even properly load, and probably"
640 << " will not fly as expected." << endl << endl
641 << fgred << highint << "Use this model for development purposes ONLY!!!"
642 << normint << reset << endl << endl;
643 } else if (Release == "BETA" && (debug_lvl & 1)) {
645 << highint << "This aircraft model is a " << fgred << Release
646 << reset << highint << " release!!!" << endl << endl << reset
647 << "This aircraft model probably will not fly as expected." << endl << endl
648 << fgblue << highint << "Use this model for development purposes ONLY!!!"
649 << normint << reset << endl << endl;
650 } else if (Release == "PRODUCTION" && (debug_lvl & 1)) {
652 << highint << "This aircraft model is a " << fgblue << Release
653 << reset << highint << " release." << endl << endl << reset;
654 } else if (debug_lvl & 1) {
656 << highint << "This aircraft model is an " << fgred << Release
657 << reset << highint << " release!!!" << endl << endl << reset
658 << "This aircraft model may not even properly load, and probably"
659 << " will not fly as expected." << endl << endl
660 << fgred << highint << "Use this model for development purposes ONLY!!!"
661 << normint << reset << endl << endl;
667 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
669 bool FGFDMExec::ReadSlave(Element* el)
671 // Add a new slaveData object to the slave FDM list
672 // Populate that slaveData element with a new FDMExec object
673 // Set the IsSlave flag for that FDMExec object
674 // Get the aircraft name
675 // set debug level to print out no additional data for slave objects
676 // Load the model given the aircraft name
677 // reset debug level to prior setting
679 int saved_debug_lvl = debug_lvl;
682 SlaveFDMList.push_back(new slaveData);
683 SlaveFDMList.back()->exec = new FGFDMExec();
684 SlaveFDMList.back()->exec->SetSlave(true);
686 string AircraftName = AC_cfg->GetValue("file");
688 debug_lvl = 0; // turn off debug output for slave vehicle
690 SlaveFDMList.back()->exec->SetAircraftPath( AircraftPath );
691 SlaveFDMList.back()->exec->SetEnginePath( EnginePath );
692 SlaveFDMList.back()->exec->LoadModel(AircraftName);
693 debug_lvl = saved_debug_lvl; // turn debug output back on for master vehicle
695 AC_cfg->GetNextConfigLine();
696 while ((token = AC_cfg->GetValue()) != string("/SLAVE")) {
698 if (token == "xloc") { *AC_cfg >> SlaveFDMList.back()->x; }
699 else if (token == "yloc") { *AC_cfg >> SlaveFDMList.back()->y; }
700 else if (token == "zloc") { *AC_cfg >> SlaveFDMList.back()->z; }
701 else if (token == "pitch") { *AC_cfg >> SlaveFDMList.back()->pitch;}
702 else if (token == "yaw") { *AC_cfg >> SlaveFDMList.back()->yaw; }
703 else if (token == "roll") { *AC_cfg >> SlaveFDMList.back()->roll; }
704 else cerr << "Unknown identifier: " << token << " in slave vehicle definition" << endl;
708 cout << " X = " << SlaveFDMList.back()->x << endl;
709 cout << " Y = " << SlaveFDMList.back()->y << endl;
710 cout << " Z = " << SlaveFDMList.back()->z << endl;
711 cout << " Pitch = " << SlaveFDMList.back()->pitch << endl;
712 cout << " Yaw = " << SlaveFDMList.back()->yaw << endl;
713 cout << " Roll = " << SlaveFDMList.back()->roll << endl;
719 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
721 FGPropertyManager* FGFDMExec::GetPropertyManager(void)
726 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
728 FGTrim* FGFDMExec::GetTrim(void)
731 Trim = new FGTrim(this,tNone);
735 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
737 void FGFDMExec::DisableOutput(void)
739 for (unsigned i=0; i<Outputs.size(); i++) {
740 Outputs[i]->Disable();
744 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
746 void FGFDMExec::EnableOutput(void)
748 for (unsigned i=0; i<Outputs.size(); i++) {
749 Outputs[i]->Enable();
753 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
755 bool FGFDMExec::SetOutputDirectives(string fname)
757 bool result=true; // for now always return true
759 if (Outputs.size() == 0) {
760 FGOutput* Output = new FGOutput(this);
763 Output->SetDirectivesFile(fname);
765 Outputs.push_back(Output);
766 } else { // Outputs > 1
767 cerr << "First output file being overridden" << endl;
768 Outputs[0]->SetDirectivesFile(fname);
773 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
775 void FGFDMExec::DoTrim(int mode)
779 if (Constructing) return;
781 if (mode < 0 || mode > JSBSim::tNone) {
782 cerr << endl << "Illegal trimming mode!" << endl << endl;
785 saved_time = State->Getsim_time();
786 FGTrim trim(this, (JSBSim::TrimMode)mode);
787 if ( !trim.DoTrim() ) cerr << endl << "Trim Failed" << endl << endl;
789 State->Setsim_time(saved_time);
792 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
794 void FGFDMExec::UseAtmosphereMSIS(void)
796 FGAtmosphere *oldAtmosphere = Atmosphere;
797 Atmosphere = new MSIS(this);
798 if (!Atmosphere->InitModel()) {
799 cerr << fgred << "MSIS Atmosphere model init failed" << fgdef << endl;
802 delete oldAtmosphere;
805 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
807 void FGFDMExec::UseAtmosphereMars(void)
810 FGAtmosphere *oldAtmosphere = Atmosphere;
811 Atmosphere = new FGMars(this);
812 if (!Atmosphere->InitModel()) {
813 cerr << fgred << "Mars Atmosphere model init failed" << fgdef << endl;
816 delete oldAtmosphere;
820 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
821 // The bitmasked value choices are as follows:
822 // unset: In this case (the default) JSBSim would only print
823 // out the normally expected messages, essentially echoing
824 // the config files as they are read. If the environment
825 // variable is not set, debug_lvl is set to 1 internally
826 // 0: This requests JSBSim not to output any messages
828 // 1: This value explicity requests the normal JSBSim
830 // 2: This value asks for a message to be printed out when
831 // a class is instantiated
832 // 4: When this value is set, a message is displayed when a
833 // FGModel object executes its Run() method
834 // 8: When this value is set, various runtime state variables
835 // are printed out periodically
836 // 16: When set various parameters are sanity checked and
837 // a message is printed out when they go out of bounds
839 void FGFDMExec::Debug(int from)
841 if (debug_lvl <= 0) return;
843 if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output
844 if (from == 0) { // Constructor
845 cout << "\n\n " << highint << underon << "JSBSim Flight Dynamics Model v"
846 << JSBSim_version << underoff << normint << endl;
847 cout << halfint << " [JSBSim-ML v" << needed_cfg_version << "]\n\n";
848 cout << normint << "JSBSim startup beginning ...\n\n";
849 } else if (from == 3) {
850 cout << "\n\nJSBSim startup complete\n\n";
853 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
854 if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
855 if (from == 1) cout << "Destroyed: FGFDMExec" << endl;
857 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
859 cout << "================== Frame: " << Frame << " Time: "
860 << State->Getsim_time() << " dt: " << State->Getdt() << endl;
863 if (debug_lvl & 8 ) { // Runtime state variables
865 if (debug_lvl & 16) { // Sanity checking
867 if (debug_lvl & 64) {
868 if (from == 0) { // Constructor
869 cout << IdSrc << endl;
870 cout << IdHdr << endl;