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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44 #include "FGFDMExec.h"
46 #include <models/FGAtmosphere.h>
47 #include <models/atmosphere/FGMSIS.h>
48 #include <models/atmosphere/FGMars.h>
49 #include <models/FGFCS.h>
50 #include <models/FGPropulsion.h>
51 #include <models/FGMassBalance.h>
52 #include <models/FGGroundReactions.h>
53 #include <models/FGExternalReactions.h>
54 #include <models/FGBuoyantForces.h>
55 #include <models/FGAerodynamics.h>
56 #include <models/FGInertial.h>
57 #include <models/FGAircraft.h>
58 #include <models/FGPropagate.h>
59 #include <models/FGAuxiliary.h>
60 #include <models/FGInput.h>
61 #include <models/FGOutput.h>
62 #include <initialization/FGInitialCondition.h>
63 //#include <initialization/FGTrimAnalysis.h> // Remove until later
64 #include <input_output/FGPropertyManager.h>
65 #include <input_output/FGScript.h>
72 static const char *IdSrc = "$Id$";
73 static const char *IdHdr = ID_FDMEXEC;
75 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
79 unsigned int FGFDMExec::FDMctr = 0;
80 FGPropertyManager* FGFDMExec::master=0;
82 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
86 void checkTied ( FGPropertyManager *node )
88 int N = node->nChildren();
91 for (int i=0; i<N; i++) {
92 if (node->getChild(i)->nChildren() ) {
93 // cout << "Untieing " << node->getChild(i)->getName() << " property branch." << endl;
94 checkTied( (FGPropertyManager*)node->getChild(i) );
95 } else if ( node->getChild(i)->isTied() ) {
96 name = ((FGPropertyManager*)node->getChild(i))->GetFullyQualifiedName();
102 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 FGFDMExec::FGFDMExec(FGPropertyManager* root) : Root(root)
120 ExternalReactions = 0;
135 // Multiple FDM's are stopped for now. We need to ensure that
136 // the "user" instance always gets the zeroeth instance number,
137 // because there may be instruments or scripts tied to properties
138 // in the jsbsim[0] node.
139 // ToDo: it could be that when JSBSim is reset and a new FDM is wanted, that
140 // process might try setting FDMctr = 0. Then the line below would not need
141 // to be commented out.
146 char* num = getenv("JSBSIM_DEBUG");
147 if (num) debug_lvl = atoi(num); // set debug level
148 } catch (...) { // if error set to 1
154 master = new FGPropertyManager;
158 instance = Root->GetNode("/fdm/jsbsim",IdFDM,true);
160 // this is to catch errors in binding member functions to the property tree.
163 } catch ( string msg ) {
164 cout << "Caught error: " << msg << endl;
172 typedef int (FGFDMExec::*iPMF)(void) const;
173 // instance->Tie("simulation/do_trim_analysis", this, (iPMF)0, &FGFDMExec::DoTrimAnalysis);
174 instance->Tie("simulation/do_simple_trim", this, (iPMF)0, &FGFDMExec::DoTrim);
175 instance->Tie("simulation/terminate", (int *)&Terminate);
176 Constructing = false;
179 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 FGFDMExec::~FGFDMExec()
184 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);
212 GroundCallback = new FGGroundCallback(Inertial->GetRefRadius());
214 GroundReactions = new FGGroundReactions(this);
215 ExternalReactions = new FGExternalReactions(this);
216 BuoyantForces = new FGBuoyantForces(this);
217 Aircraft = new FGAircraft(this);
218 Propagate = new FGPropagate(this);
219 Auxiliary = new FGAuxiliary(this);
220 Input = new FGInput(this);
222 State = new FGState(this); // This must be done here, as the FGState
223 // class needs valid pointers to the above
226 // Initialize models so they can communicate with each other
228 Atmosphere->InitModel();
230 Propulsion->InitModel();
231 MassBalance->InitModel();
232 Aerodynamics->InitModel();
233 Inertial->InitModel();
234 GroundReactions->InitModel();
235 ExternalReactions->InitModel();
236 BuoyantForces->InitModel();
237 Aircraft->InitModel();
238 Propagate->InitModel();
239 Auxiliary->InitModel();
242 IC = new FGInitialCondition(this);
244 // Schedule a model. The second arg (the integer) is the pass number. For
245 // instance, the atmosphere model could get executed every fifth pass it is called
246 // by the executive. IC and Trim objects are NOT scheduled.
249 Schedule(Atmosphere, 1);
251 Schedule(Propulsion, 1);
252 Schedule(MassBalance, 1);
253 Schedule(Aerodynamics, 1);
254 Schedule(Inertial, 1);
255 Schedule(GroundReactions, 1);
256 Schedule(ExternalReactions, 1);
257 Schedule(BuoyantForces, 1);
258 Schedule(Aircraft, 1);
259 Schedule(Propagate, 1);
260 Schedule(Auxiliary, 1);
267 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269 bool FGFDMExec::DeAllocate(void)
278 delete GroundReactions;
279 delete ExternalReactions;
280 delete BuoyantForces;
287 for (unsigned i=0; i<Outputs.size(); i++) delete Outputs[i];
293 delete GroundCallback;
307 ExternalReactions = 0;
318 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
320 int FGFDMExec::Schedule(FGModel* model, int rate)
322 FGModel* model_iterator;
324 model_iterator = FirstModel;
326 if (model_iterator == 0L) { // this is the first model
329 FirstModel->NextModel = 0L;
330 FirstModel->SetRate(rate);
332 } else { // subsequent model
334 while (model_iterator->NextModel != 0L) {
335 model_iterator = model_iterator->NextModel;
337 model_iterator->NextModel = model;
338 model_iterator->NextModel->SetRate(rate);
345 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
347 bool FGFDMExec::Run(void)
350 FGModel* model_iterator;
352 model_iterator = FirstModel;
353 if (model_iterator == 0L) return false;
357 for (unsigned int i=1; i<SlaveFDMList.size(); i++) {
358 // SlaveFDMList[i]->exec->State->Initialize(); // Transfer state to the slave FDM
359 // SlaveFDMList[i]->exec->Run();
362 // returns true if success
364 if (Script != 0 && !State->IntegrationSuspended()) success = Script->RunScript();
366 while (model_iterator != 0L) {
367 model_iterator->Run();
368 model_iterator = model_iterator->NextModel;
372 if (!Holding()) State->IncrTime();
373 if (Terminate) success = false;
378 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
379 // This call will cause the sim time to reset to 0.0
381 bool FGFDMExec::RunIC(void)
383 State->SuspendIntegration();
384 State->Initialize(IC);
386 State->ResumeIntegration();
391 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
393 void FGFDMExec::ResetToInitialConditions(void)
395 FGModel* model_iterator;
397 model_iterator = FirstModel;
398 if (model_iterator == 0L) return;
400 while (model_iterator != 0L) {
401 model_iterator->InitModel();
402 model_iterator = model_iterator->NextModel;
406 if (Script) Script->ResetEvents();
409 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411 void FGFDMExec::SetGroundCallback(FGGroundCallback* p)
413 delete GroundCallback;
417 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
419 double FGFDMExec::GetSimTime(void)
421 return (State->Getsim_time());
424 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
426 double FGFDMExec::GetDeltaT(void)
428 return (State->Getdt());
431 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
433 vector <string> FGFDMExec::EnumerateFDMs(void)
435 vector <string> FDMList;
437 FDMList.push_back(Aircraft->GetAircraftName());
439 for (unsigned int i=1; i<SlaveFDMList.size(); i++) {
440 FDMList.push_back(SlaveFDMList[i]->exec->GetAircraft()->GetAircraftName());
446 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
448 bool FGFDMExec::LoadScript(string script)
452 Script = new FGScript(this);
453 result = Script->LoadScript(script);
458 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
460 bool FGFDMExec::LoadModel(string AircraftPath, string EnginePath, string SystemsPath,
461 string model, bool addModelToPath)
463 FGFDMExec::AircraftPath = AircraftPath;
464 FGFDMExec::EnginePath = EnginePath;
465 FGFDMExec::SystemsPath = SystemsPath;
467 return LoadModel(model, addModelToPath);
470 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
472 bool FGFDMExec::LoadModel(string model, bool addModelToPath)
475 string aircraftCfgFileName;
476 string separator = "/";
477 Element* element = 0L;
478 bool result = false; // initialize result to false, indicating input file not yet read
480 modelName = model; // Set the class modelName attribute
482 if( AircraftPath.empty() || EnginePath.empty() || SystemsPath.empty()) {
483 cerr << "Error: attempted to load aircraft with undefined ";
484 cerr << "aircraft, engine, and system paths" << endl;
488 FullAircraftPath = AircraftPath;
489 if (addModelToPath) FullAircraftPath += separator + model;
490 aircraftCfgFileName = FullAircraftPath + separator + model + ".xml";
497 document = LoadXMLDocument(aircraftCfgFileName); // "document" is a class member
499 ReadPrologue(document);
500 element = document->GetElement();
503 while (element && result) {
504 string element_name = element->GetName();
505 if (element_name == "fileheader" ) result = ReadFileHeader(element);
506 else if (element_name == "slave") result = ReadSlave(element);
507 else if (element_name == "metrics") result = Aircraft->Load(element);
508 else if (element_name == "mass_balance") result = MassBalance->Load(element);
509 else if (element_name == "ground_reactions") result = GroundReactions->Load(element);
510 else if (element_name == "external_reactions") result = ExternalReactions->Load(element);
511 else if (element_name == "buoyant_forces") result = BuoyantForces->Load(element);
512 else if (element_name == "propulsion") result = Propulsion->Load(element);
513 else if (element_name == "system") result = FCS->Load(element,
515 else if (element_name == "autopilot") result = FCS->Load(element,
517 else if (element_name == "flight_control") result = FCS->Load(element,
519 else if (element_name == "aerodynamics") result = Aerodynamics->Load(element);
520 else if (element_name == "input") result = Input->Load(element);
521 else if (element_name == "output") {
522 FGOutput* Output = new FGOutput(this);
525 result = Output->Load(element);
526 Outputs.push_back(Output);
529 cerr << "Found unexpected subsystem: " << element_name << ", exiting." << endl;
533 element = document->GetNextElement();
537 << " JSBSim failed to load aircraft model."
547 << " JSBSim failed to load properly."
552 struct PropertyCatalogStructure masterPCS;
553 masterPCS.base_string = "";
554 masterPCS.node = (FGPropertyManager*)Root;
556 BuildPropertyCatalog(&masterPCS);
561 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
563 void FGFDMExec::BuildPropertyCatalog(struct PropertyCatalogStructure* pcs)
565 struct PropertyCatalogStructure* pcsNew = new struct PropertyCatalogStructure;
569 for (unsigned int i=0; i<pcs->node->nChildren(); i++) {
570 pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getName();
571 node_idx = pcs->node->getChild(i)->getIndex();
572 sprintf(int_buf, "[%d]", node_idx);
573 if (node_idx != 0) pcsNew->base_string += string(int_buf);
574 if (pcs->node->getChild(i)->nChildren() == 0) {
575 if (pcsNew->base_string.substr(0,11) == string("/fdm/jsbsim")) {
576 pcsNew->base_string = pcsNew->base_string.erase(0,12);
578 PropertyCatalog.push_back(pcsNew->base_string);
580 pcsNew->node = (FGPropertyManager*)pcs->node->getChild(i);
581 BuildPropertyCatalog(pcsNew);
587 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
589 string FGFDMExec::QueryPropertyCatalog(string in)
592 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
593 if (PropertyCatalog[i].find(in) != string::npos) results += PropertyCatalog[i] + "\n";
595 if (results.empty()) return "No matches found\n";
599 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
601 void FGFDMExec::PrintPropertyCatalog(void)
604 cout << " " << fgblue << highint << underon << "Property Catalog for "
605 << modelName << reset << endl << endl;
606 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
607 cout << " " << PropertyCatalog[i] << endl;
611 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
613 bool FGFDMExec::ReadFileHeader(Element* el)
615 bool result = true; // true for success
617 if (debug_lvl & ~1) return result;
619 if (el->FindElement("author"))
620 cout << " Model Author: " << el->FindElement("author")->GetDataLine() << endl;
621 if (el->FindElement("filecreationdate"))
622 cout << " Creation Date: " << el->FindElement("filecreationdate")->GetDataLine() << endl;
623 if (el->FindElement("version"))
624 cout << " Version: " << el->FindElement("version")->GetDataLine() << endl;
625 if (el->FindElement("description"))
626 cout << " Description: " << el->FindElement("description")->GetDataLine() << endl;
631 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
633 bool FGFDMExec::ReadPrologue(Element* el) // el for ReadPrologue is the document element
635 bool result = true; // true for success
637 if (!el) return false;
639 string AircraftName = el->GetAttributeValue("name");
640 Aircraft->SetAircraftName(AircraftName);
642 if (debug_lvl & 1) cout << underon << "Reading Aircraft Configuration File"
643 << underoff << ": " << highint << AircraftName << normint << endl;
645 CFGVersion = el->GetAttributeValue("version");
646 Release = el->GetAttributeValue("release");
649 cout << " Version: " << highint << CFGVersion
651 if (CFGVersion != needed_cfg_version) {
652 cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
653 " RESULTS WILL BE UNPREDICTABLE !!" << endl;
654 cerr << "Current version needed is: " << needed_cfg_version << endl;
655 cerr << " You have version: " << CFGVersion << endl << fgdef << endl;
659 if (Release == "ALPHA" && (debug_lvl & 1)) {
661 << highint << "This aircraft model is an " << fgred << Release
662 << reset << highint << " release!!!" << endl << endl << reset
663 << "This aircraft model may not even properly load, and probably"
664 << " will not fly as expected." << endl << endl
665 << fgred << highint << "Use this model for development purposes ONLY!!!"
666 << normint << reset << endl << endl;
667 } else if (Release == "BETA" && (debug_lvl & 1)) {
669 << highint << "This aircraft model is a " << fgred << Release
670 << reset << highint << " release!!!" << endl << endl << reset
671 << "This aircraft model probably will not fly as expected." << endl << endl
672 << fgblue << highint << "Use this model for development purposes ONLY!!!"
673 << normint << reset << endl << endl;
674 } else if (Release == "PRODUCTION" && (debug_lvl & 1)) {
676 << highint << "This aircraft model is a " << fgblue << Release
677 << reset << highint << " release." << endl << endl << reset;
678 } else if (debug_lvl & 1) {
680 << highint << "This aircraft model is an " << fgred << Release
681 << reset << highint << " release!!!" << endl << endl << reset
682 << "This aircraft model may not even properly load, and probably"
683 << " will not fly as expected." << endl << endl
684 << fgred << highint << "Use this model for development purposes ONLY!!!"
685 << normint << reset << endl << endl;
691 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
693 bool FGFDMExec::ReadSlave(Element* el)
695 // Add a new slaveData object to the slave FDM list
696 // Populate that slaveData element with a new FDMExec object
697 // Set the IsSlave flag for that FDMExec object
698 // Get the aircraft name
699 // set debug level to print out no additional data for slave objects
700 // Load the model given the aircraft name
701 // reset debug level to prior setting
703 int saved_debug_lvl = debug_lvl;
706 SlaveFDMList.push_back(new slaveData);
707 SlaveFDMList.back()->exec = new FGFDMExec();
708 SlaveFDMList.back()->exec->SetSlave(true);
710 string AircraftName = AC_cfg->GetValue("file");
712 debug_lvl = 0; // turn off debug output for slave vehicle
714 SlaveFDMList.back()->exec->SetAircraftPath( AircraftPath );
715 SlaveFDMList.back()->exec->SetEnginePath( EnginePath );
716 SlaveFDMList.back()->exec->SetSystemsPath( SystemsPath );
717 SlaveFDMList.back()->exec->LoadModel(AircraftName);
718 debug_lvl = saved_debug_lvl; // turn debug output back on for master vehicle
720 AC_cfg->GetNextConfigLine();
721 while ((token = AC_cfg->GetValue()) != string("/SLAVE")) {
723 if (token == "xloc") { *AC_cfg >> SlaveFDMList.back()->x; }
724 else if (token == "yloc") { *AC_cfg >> SlaveFDMList.back()->y; }
725 else if (token == "zloc") { *AC_cfg >> SlaveFDMList.back()->z; }
726 else if (token == "pitch") { *AC_cfg >> SlaveFDMList.back()->pitch;}
727 else if (token == "yaw") { *AC_cfg >> SlaveFDMList.back()->yaw; }
728 else if (token == "roll") { *AC_cfg >> SlaveFDMList.back()->roll; }
729 else cerr << "Unknown identifier: " << token << " in slave vehicle definition" << endl;
733 cout << " X = " << SlaveFDMList.back()->x << endl;
734 cout << " Y = " << SlaveFDMList.back()->y << endl;
735 cout << " Z = " << SlaveFDMList.back()->z << endl;
736 cout << " Pitch = " << SlaveFDMList.back()->pitch << endl;
737 cout << " Yaw = " << SlaveFDMList.back()->yaw << endl;
738 cout << " Roll = " << SlaveFDMList.back()->roll << endl;
744 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
746 FGPropertyManager* FGFDMExec::GetPropertyManager(void)
751 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
753 FGTrim* FGFDMExec::GetTrim(void)
756 Trim = new FGTrim(this,tNone);
760 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
762 void FGFDMExec::DisableOutput(void)
764 for (unsigned i=0; i<Outputs.size(); i++) {
765 Outputs[i]->Disable();
769 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
771 void FGFDMExec::EnableOutput(void)
773 for (unsigned i=0; i<Outputs.size(); i++) {
774 Outputs[i]->Enable();
778 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
780 bool FGFDMExec::SetOutputDirectives(string fname)
784 FGOutput* Output = new FGOutput(this);
785 Output->SetDirectivesFile(fname);
788 result = Output->Load(0);
789 Outputs.push_back(Output);
794 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
796 void FGFDMExec::DoTrim(int mode)
800 if (Constructing) return;
802 if (mode < 0 || mode > JSBSim::tNone) {
803 cerr << endl << "Illegal trimming mode!" << endl << endl;
806 saved_time = State->Getsim_time();
807 FGTrim trim(this, (JSBSim::TrimMode)mode);
808 if ( !trim.DoTrim() ) cerr << endl << "Trim Failed" << endl << endl;
810 State->Setsim_time(saved_time);
813 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
815 void FGFDMExec::DoTrimAnalysis(int mode)
818 if (Constructing) return;
820 if (mode < 0 || mode > JSBSim::taNone) {
821 cerr << endl << "Illegal trimming mode!" << endl << endl;
824 saved_time = State->Getsim_time();
826 FGTrimAnalysis trimAnalysis(this, (JSBSim::TrimAnalysisMode)mode);
828 if ( !trimAnalysis.Load(IC->GetInitFile(), false) ) {
829 cerr << "A problem occurred with trim configuration file " << trimAnalysis.Load(IC->GetInitFile()) << endl;
833 bool result = trimAnalysis.DoTrim();
835 if ( !result ) cerr << endl << "Trim Failed" << endl << endl;
837 trimAnalysis.Report();
838 State->Setsim_time(saved_time);
841 cout << "\nOutput: " << GetOutputFileName() << endl;
845 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
847 void FGFDMExec::UseAtmosphereMSIS(void)
849 FGAtmosphere *oldAtmosphere = Atmosphere;
850 Atmosphere = new MSIS(this);
851 if (!Atmosphere->InitModel()) {
852 cerr << fgred << "MSIS Atmosphere model init failed" << fgdef << endl;
855 delete oldAtmosphere;
858 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
860 void FGFDMExec::UseAtmosphereMars(void)
863 FGAtmosphere *oldAtmosphere = Atmosphere;
864 Atmosphere = new FGMars(this);
865 if (!Atmosphere->InitModel()) {
866 cerr << fgred << "Mars Atmosphere model init failed" << fgdef << endl;
869 delete oldAtmosphere;
873 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
874 // The bitmasked value choices are as follows:
875 // unset: In this case (the default) JSBSim would only print
876 // out the normally expected messages, essentially echoing
877 // the config files as they are read. If the environment
878 // variable is not set, debug_lvl is set to 1 internally
879 // 0: This requests JSBSim not to output any messages
881 // 1: This value explicity requests the normal JSBSim
883 // 2: This value asks for a message to be printed out when
884 // a class is instantiated
885 // 4: When this value is set, a message is displayed when a
886 // FGModel object executes its Run() method
887 // 8: When this value is set, various runtime state variables
888 // are printed out periodically
889 // 16: When set various parameters are sanity checked and
890 // a message is printed out when they go out of bounds
892 void FGFDMExec::Debug(int from)
894 if (debug_lvl <= 0) return;
896 if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output
897 if (from == 0) { // Constructor
898 cout << "\n\n " << highint << underon << "JSBSim Flight Dynamics Model v"
899 << JSBSim_version << underoff << normint << endl;
900 cout << halfint << " [JSBSim-ML v" << needed_cfg_version << "]\n\n";
901 cout << normint << "JSBSim startup beginning ...\n\n";
902 } else if (from == 3) {
903 cout << "\n\nJSBSim startup complete\n\n";
906 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
907 if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
908 if (from == 1) cout << "Destroyed: FGFDMExec" << endl;
910 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
912 cout << "================== Frame: " << Frame << " Time: "
913 << State->Getsim_time() << " dt: " << State->Getdt() << endl;
916 if (debug_lvl & 8 ) { // Runtime state variables
918 if (debug_lvl & 16) { // Sanity checking
920 if (debug_lvl & 64) {
921 if (from == 0) { // Constructor
922 cout << IdSrc << endl;
923 cout << IdHdr << endl;