1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 Purpose: Schedules and runs the model routines.
8 ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.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"
75 static const char *IdSrc = "$Id$";
76 static const char *IdHdr = ID_FDMEXEC;
78 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
82 unsigned int FGFDMExec::FDMctr = 0;
83 FGPropertyManager* FGFDMExec::master=0;
85 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
89 void checkTied ( FGPropertyManager *node )
91 int N = node->nChildren();
94 for (int i=0; i<N; i++) {
95 if (node->getChild(i)->nChildren() ) {
96 checkTied( (FGPropertyManager*)node->getChild(i) );
97 } else if ( node->getChild(i)->isTied() ) {
98 name = ((FGPropertyManager*)node->getChild(i))->GetFullyQualifiedName();
104 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 FGFDMExec::FGFDMExec(FGPropertyManager* root) : Root(root)
122 ExternalReactions = 0;
137 IdFDM = FDMctr; // The main (parent) JSBSim instance is always the "zeroth"
138 FDMctr++; // instance. "child" instances are loaded last.
141 char* num = getenv("JSBSIM_DEBUG");
142 if (num) debug_lvl = atoi(num); // set debug level
143 } catch (...) { // if error set to 1
149 master = new FGPropertyManager;
153 instance = Root->GetNode("/fdm/jsbsim",IdFDM,true);
155 // this is to catch errors in binding member functions to the property tree.
158 } catch ( string msg ) {
159 cout << "Caught error: " << msg << endl;
167 typedef int (FGFDMExec::*iPMF)(void) const;
168 // instance->Tie("simulation/do_trim_analysis", this, (iPMF)0, &FGFDMExec::DoTrimAnalysis);
169 instance->Tie("simulation/do_simple_trim", this, (iPMF)0, &FGFDMExec::DoTrim);
170 instance->Tie("simulation/reset", this, (iPMF)0, &FGFDMExec::ResetToInitialConditions);
171 instance->Tie("simulation/terminate", (int *)&Terminate);
172 Constructing = false;
175 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 FGFDMExec::~FGFDMExec()
180 checkTied( instance );
182 if (Root == 0) delete master;
183 } catch ( string msg ) {
184 cout << "Caught error: " << msg << endl;
187 for (unsigned int i=1; i<ChildFDMList.size(); i++) delete ChildFDMList[i]->exec;
188 ChildFDMList.clear();
190 PropertyCatalog.clear();
197 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199 bool FGFDMExec::Allocate(void)
203 Atmosphere = new FGAtmosphere(this);
204 FCS = new FGFCS(this);
205 Propulsion = new FGPropulsion(this);
206 MassBalance = new FGMassBalance(this);
207 Aerodynamics = new FGAerodynamics (this);
208 Inertial = new FGInertial(this);
210 GroundCallback = new FGGroundCallback(Inertial->GetRefRadius());
212 GroundReactions = new FGGroundReactions(this);
213 ExternalReactions = new FGExternalReactions(this);
214 BuoyantForces = new FGBuoyantForces(this);
215 Aircraft = new FGAircraft(this);
216 Propagate = new FGPropagate(this);
217 Auxiliary = new FGAuxiliary(this);
218 Input = new FGInput(this);
220 State = new FGState(this); // This must be done here, as the FGState
221 // class needs valid pointers to the above
224 // Initialize models so they can communicate with each other
226 Atmosphere->InitModel();
228 Propulsion->InitModel();
229 MassBalance->InitModel();
230 Aerodynamics->InitModel();
231 Inertial->InitModel();
232 GroundReactions->InitModel();
233 ExternalReactions->InitModel();
234 BuoyantForces->InitModel();
235 Aircraft->InitModel();
236 Propagate->InitModel();
237 Auxiliary->InitModel();
240 IC = new FGInitialCondition(this);
242 // Schedule a model. The second arg (the integer) is the pass number. For
243 // instance, the atmosphere model could get executed every fifth pass it is called
244 // by the executive. IC and Trim objects are NOT scheduled.
247 Schedule(Atmosphere, 1);
249 Schedule(Propulsion, 1);
250 Schedule(MassBalance, 1);
251 Schedule(Aerodynamics, 1);
252 Schedule(Inertial, 1);
253 Schedule(GroundReactions, 1);
254 Schedule(ExternalReactions, 1);
255 Schedule(BuoyantForces, 1);
256 Schedule(Aircraft, 1);
257 Schedule(Propagate, 1);
258 Schedule(Auxiliary, 1);
265 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
267 bool FGFDMExec::DeAllocate(void)
276 delete GroundReactions;
277 delete ExternalReactions;
278 delete BuoyantForces;
285 for (unsigned i=0; i<Outputs.size(); i++) delete Outputs[i];
291 delete GroundCallback;
305 ExternalReactions = 0;
316 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
318 int FGFDMExec::Schedule(FGModel* model, int rate)
320 FGModel* model_iterator;
322 model_iterator = FirstModel;
324 if (model_iterator == 0L) { // this is the first model
327 FirstModel->NextModel = 0L;
328 FirstModel->SetRate(rate);
330 } else { // subsequent model
332 while (model_iterator->NextModel != 0L) {
333 model_iterator = model_iterator->NextModel;
335 model_iterator->NextModel = model;
336 model_iterator->NextModel->SetRate(rate);
343 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345 bool FGFDMExec::Run(void)
348 FGModel* model_iterator;
350 model_iterator = FirstModel;
351 if (model_iterator == 0L) return false;
355 for (unsigned int i=1; i<ChildFDMList.size(); i++) {
356 ChildFDMList[i]->AssignState(Propagate); // Transfer state to the child FDM
357 ChildFDMList[i]->Run();
360 // returns true if success
362 if (Script != 0 && !State->IntegrationSuspended()) success = Script->RunScript();
364 while (model_iterator != 0L) {
365 model_iterator->Run();
366 model_iterator = model_iterator->NextModel;
370 if (!Holding()) State->IncrTime();
371 if (Terminate) success = false;
376 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
377 // This call will cause the sim time to reset to 0.0
379 bool FGFDMExec::RunIC(void)
381 State->SuspendIntegration();
382 State->Initialize(IC);
384 State->ResumeIntegration();
389 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
391 // A private, internal function call for Tie-ing to a property, so it needs an
394 void FGFDMExec::ResetToInitialConditions(int mode)
397 for (unsigned int i=0; i<Outputs.size(); i++) {
398 Outputs[i]->SetStartNewFile(true);
402 ResetToInitialConditions();
405 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
407 void FGFDMExec::ResetToInitialConditions(void)
409 FGModel* model_iterator;
411 model_iterator = FirstModel;
412 if (model_iterator == 0L || Constructing) return;
414 while (model_iterator != 0L) {
415 model_iterator->InitModel();
416 model_iterator = model_iterator->NextModel;
420 if (Script) Script->ResetEvents();
423 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
425 void FGFDMExec::SetGroundCallback(FGGroundCallback* p)
427 delete GroundCallback;
431 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
433 double FGFDMExec::GetSimTime(void)
435 return (State->Getsim_time());
438 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
440 double FGFDMExec::GetDeltaT(void)
442 return (State->Getdt());
445 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
447 vector <string> FGFDMExec::EnumerateFDMs(void)
449 vector <string> FDMList;
451 FDMList.push_back(Aircraft->GetAircraftName());
453 for (unsigned int i=1; i<ChildFDMList.size(); i++) {
454 FDMList.push_back(ChildFDMList[i]->exec->GetAircraft()->GetAircraftName());
460 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
462 bool FGFDMExec::LoadScript(string script)
466 Script = new FGScript(this);
467 result = Script->LoadScript(script);
472 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
474 bool FGFDMExec::LoadModel(string AircraftPath, string EnginePath, string SystemsPath,
475 string model, bool addModelToPath)
477 FGFDMExec::AircraftPath = AircraftPath;
478 FGFDMExec::EnginePath = EnginePath;
479 FGFDMExec::SystemsPath = SystemsPath;
481 return LoadModel(model, addModelToPath);
484 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
486 bool FGFDMExec::LoadModel(string model, bool addModelToPath)
489 string aircraftCfgFileName;
490 string separator = "/";
491 Element* element = 0L;
492 bool result = false; // initialize result to false, indicating input file not yet read
494 modelName = model; // Set the class modelName attribute
496 if( AircraftPath.empty() || EnginePath.empty() || SystemsPath.empty()) {
497 cerr << "Error: attempted to load aircraft with undefined ";
498 cerr << "aircraft, engine, and system paths" << endl;
502 FullAircraftPath = AircraftPath;
503 if (addModelToPath) FullAircraftPath += separator + model;
504 aircraftCfgFileName = FullAircraftPath + separator + model + ".xml";
511 int saved_debug_lvl = debug_lvl;
513 document = LoadXMLDocument(aircraftCfgFileName); // "document" is a class member
515 if (IsChild) debug_lvl = 0;
517 ReadPrologue(document);
519 if (IsChild) debug_lvl = saved_debug_lvl;
521 // Process the fileheader element in the aircraft config file. This element is OPTIONAL.
522 element = document->FindElement("fileheader");
524 result = ReadFileHeader(element);
526 cerr << endl << "Aircraft fileheader element has problems in file " << aircraftCfgFileName << endl;
531 if (IsChild) debug_lvl = 0;
533 // Process the metrics element. This element is REQUIRED.
534 element = document->FindElement("metrics");
536 result = Aircraft->Load(element);
538 cerr << endl << "Aircraft metrics element has problems in file " << aircraftCfgFileName << endl;
542 cerr << endl << "No metrics element was found in the aircraft config file." << endl;
546 // Process the mass_balance element. This element is REQUIRED.
547 element = document->FindElement("mass_balance");
549 result = MassBalance->Load(element);
551 cerr << endl << "Aircraft mass_balance element has problems in file " << aircraftCfgFileName << endl;
555 cerr << endl << "No mass_balance element was found in the aircraft config file." << endl;
559 // Process the ground_reactions element. This element is REQUIRED.
560 element = document->FindElement("ground_reactions");
562 result = GroundReactions->Load(element);
564 cerr << endl << "Aircraft ground_reactions element has problems in file " << aircraftCfgFileName << endl;
568 cerr << endl << "No ground_reactions element was found in the aircraft config file." << endl;
572 // Process the external_reactions element. This element is OPTIONAL.
573 element = document->FindElement("external_reactions");
575 result = ExternalReactions->Load(element);
577 cerr << endl << "Aircraft external_reactions element has problems in file " << aircraftCfgFileName << endl;
582 // Process the buoyant_forces element. This element is OPTIONAL.
583 element = document->FindElement("buoyant_forces");
585 result = BuoyantForces->Load(element);
587 cerr << endl << "Aircraft buoyant_forces element has problems in file " << aircraftCfgFileName << endl;
592 // Process the propulsion element. This element is OPTIONAL.
593 element = document->FindElement("propulsion");
595 result = Propulsion->Load(element);
597 cerr << endl << "Aircraft propulsion element has problems in file " << aircraftCfgFileName << endl;
602 // Process the system element[s]. This element is OPTIONAL, and there may be more than one.
603 element = document->FindElement("system");
605 result = FCS->Load(element, FGFCS::stSystem);
607 cerr << endl << "Aircraft system element has problems in file " << aircraftCfgFileName << endl;
610 element = document->FindNextElement("system");
613 // Process the autopilot element. This element is OPTIONAL.
614 element = document->FindElement("autopilot");
616 result = FCS->Load(element, FGFCS::stAutoPilot);
618 cerr << endl << "Aircraft autopilot element has problems in file " << aircraftCfgFileName << endl;
623 // Process the flight_control element. This element is OPTIONAL.
624 element = document->FindElement("flight_control");
626 result = FCS->Load(element, FGFCS::stFCS);
628 cerr << endl << "Aircraft flight_control element has problems in file " << aircraftCfgFileName << endl;
633 // Process the aerodynamics element. This element is OPTIONAL, but almost always expected.
634 element = document->FindElement("aerodynamics");
636 result = Aerodynamics->Load(element);
638 cerr << endl << "Aircraft aerodynamics element has problems in file " << aircraftCfgFileName << endl;
642 cerr << endl << "No expected aerodynamics element was found in the aircraft config file." << endl;
645 // Process the input element. This element is OPTIONAL.
646 element = document->FindElement("input");
648 result = Input->Load(element);
650 cerr << endl << "Aircraft input element has problems in file " << aircraftCfgFileName << endl;
655 // Process the output element[s]. This element is OPTIONAL, and there may be more than one.
657 typedef int (FGOutput::*iOPMF)(void) const;
658 element = document->FindElement("output");
660 if (debug_lvl > 0) cout << endl << " Output data set: " << idx << " ";
661 FGOutput* Output = new FGOutput(this);
664 result = Output->Load(element);
666 cerr << endl << "Aircraft output element has problems in file " << aircraftCfgFileName << endl;
669 Outputs.push_back(Output);
670 string outputProp = CreateIndexedPropertyName("simulation/output",idx);
671 instance->Tie(outputProp+"/log_rate_hz", Output, (iOPMF)0, &FGOutput::SetRate);
674 element = document->FindNextElement("output");
677 // Lastly, process the child element. This element is OPTIONAL - and NOT YET SUPPORTED.
678 element = document->FindElement("child");
680 result = ReadChild(element);
682 cerr << endl << "Aircraft child element has problems in file " << aircraftCfgFileName << endl;
690 cout << endl << fgblue << highint
691 << "End of vehicle configuration loading." << endl
692 << "-------------------------------------------------------------------------------"
696 if (IsChild) debug_lvl = saved_debug_lvl;
700 << " JSBSim failed to open the configuration file: " << aircraftCfgFileName
704 struct PropertyCatalogStructure masterPCS;
705 masterPCS.base_string = "";
706 masterPCS.node = (FGPropertyManager*)Root;
708 BuildPropertyCatalog(&masterPCS);
713 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
715 void FGFDMExec::BuildPropertyCatalog(struct PropertyCatalogStructure* pcs)
717 struct PropertyCatalogStructure* pcsNew = new struct PropertyCatalogStructure;
720 for (int i=0; i<pcs->node->nChildren(); i++) {
721 pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getName();
722 node_idx = pcs->node->getChild(i)->getIndex();
724 pcsNew->base_string = CreateIndexedPropertyName(pcsNew->base_string, node_idx);
726 if (pcs->node->getChild(i)->nChildren() == 0) {
727 if (pcsNew->base_string.substr(0,11) == string("/fdm/jsbsim")) {
728 pcsNew->base_string = pcsNew->base_string.erase(0,12);
730 PropertyCatalog.push_back(pcsNew->base_string);
732 pcsNew->node = (FGPropertyManager*)pcs->node->getChild(i);
733 BuildPropertyCatalog(pcsNew);
739 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
741 string FGFDMExec::QueryPropertyCatalog(string in)
744 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
745 if (PropertyCatalog[i].find(in) != string::npos) results += PropertyCatalog[i] + "\n";
747 if (results.empty()) return "No matches found\n";
751 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
753 void FGFDMExec::PrintPropertyCatalog(void)
756 cout << " " << fgblue << highint << underon << "Property Catalog for "
757 << modelName << reset << endl << endl;
758 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
759 cout << " " << PropertyCatalog[i] << endl;
763 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
765 bool FGFDMExec::ReadFileHeader(Element* el)
767 bool result = true; // true for success
769 if (debug_lvl == 0) return result;
772 cout << endl <<highint << fgblue << "Reading child model: " << IdFDM << reset << endl << endl;
775 if (el->FindElement("description"))
776 cout << " Description: " << el->FindElement("description")->GetDataLine() << endl;
777 if (el->FindElement("author"))
778 cout << " Model Author: " << el->FindElement("author")->GetDataLine() << endl;
779 if (el->FindElement("filecreationdate"))
780 cout << " Creation Date: " << el->FindElement("filecreationdate")->GetDataLine() << endl;
781 if (el->FindElement("version"))
782 cout << " Version: " << el->FindElement("version")->GetDataLine() << endl;
787 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
789 bool FGFDMExec::ReadPrologue(Element* el) // el for ReadPrologue is the document element
791 bool result = true; // true for success
793 if (!el) return false;
795 string AircraftName = el->GetAttributeValue("name");
796 Aircraft->SetAircraftName(AircraftName);
798 if (debug_lvl & 1) cout << underon << "Reading Aircraft Configuration File"
799 << underoff << ": " << highint << AircraftName << normint << endl;
801 CFGVersion = el->GetAttributeValue("version");
802 Release = el->GetAttributeValue("release");
805 cout << " Version: " << highint << CFGVersion
807 if (CFGVersion != needed_cfg_version) {
808 cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
809 " RESULTS WILL BE UNPREDICTABLE !!" << endl;
810 cerr << "Current version needed is: " << needed_cfg_version << endl;
811 cerr << " You have version: " << CFGVersion << endl << fgdef << endl;
815 if (Release == "ALPHA" && (debug_lvl & 1)) {
817 << highint << "This aircraft model is an " << fgred << Release
818 << reset << highint << " release!!!" << endl << endl << reset
819 << "This aircraft model may not even properly load, and probably"
820 << " will not fly as expected." << endl << endl
821 << fgred << highint << "Use this model for development purposes ONLY!!!"
822 << normint << reset << endl << endl;
823 } else if (Release == "BETA" && (debug_lvl & 1)) {
825 << highint << "This aircraft model is a " << fgred << Release
826 << reset << highint << " release!!!" << endl << endl << reset
827 << "This aircraft model probably will not fly as expected." << endl << endl
828 << fgblue << highint << "Use this model for development purposes ONLY!!!"
829 << normint << reset << endl << endl;
830 } else if (Release == "PRODUCTION" && (debug_lvl & 1)) {
832 << highint << "This aircraft model is a " << fgblue << Release
833 << reset << highint << " release." << endl << endl << reset;
834 } else if (debug_lvl & 1) {
836 << highint << "This aircraft model is an " << fgred << Release
837 << reset << highint << " release!!!" << endl << endl << reset
838 << "This aircraft model may not even properly load, and probably"
839 << " will not fly as expected." << endl << endl
840 << fgred << highint << "Use this model for development purposes ONLY!!!"
841 << normint << reset << endl << endl;
847 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
849 bool FGFDMExec::ReadChild(Element* el)
851 // Add a new childData object to the child FDM list
852 // Populate that childData element with a new FDMExec object
853 // Set the IsChild flag for that FDMExec object
854 // Get the aircraft name
855 // set debug level to print out no additional data for child objects
856 // Load the model given the aircraft name
857 // reset debug level to prior setting
861 struct childData* child = new childData;
863 child->exec = new FGFDMExec();
864 child->exec->SetChild(true);
866 string childAircraft = el->GetAttributeValue("name");
867 string sMated = el->GetAttributeValue("mated");
868 if (sMated == "false") child->mated = false; // child objects are mated by default.
869 string sInternal = el->GetAttributeValue("internal");
870 if (sInternal == "true") child->internal = true; // child objects are external by default.
872 child->exec->SetAircraftPath( AircraftPath );
873 child->exec->SetEnginePath( EnginePath );
874 child->exec->SetSystemsPath( SystemsPath );
875 child->exec->LoadModel(childAircraft);
877 Element* location = el->FindElement("location");
879 child->Loc = location->FindElementTripletConvertTo("IN");
881 cerr << endl << highint << fgred << " No location was found for this child object!" << reset << endl;
885 Element* orientation = el->FindElement("orient");
887 child->Orient = orientation->FindElementTripletConvertTo("RAD");
888 } else if (debug_lvl > 0) {
889 cerr << endl << highint << " No orientation was found for this child object! Assuming 0,0,0." << reset << endl;
892 ChildFDMList.push_back(child);
897 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
899 FGPropertyManager* FGFDMExec::GetPropertyManager(void)
904 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
906 FGTrim* FGFDMExec::GetTrim(void)
909 Trim = new FGTrim(this,tNone);
913 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
915 void FGFDMExec::DisableOutput(void)
917 for (unsigned i=0; i<Outputs.size(); i++) {
918 Outputs[i]->Disable();
922 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
924 void FGFDMExec::EnableOutput(void)
926 for (unsigned i=0; i<Outputs.size(); i++) {
927 Outputs[i]->Enable();
931 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
933 bool FGFDMExec::SetOutputDirectives(string fname)
937 FGOutput* Output = new FGOutput(this);
938 Output->SetDirectivesFile(fname);
941 result = Output->Load(0);
942 Outputs.push_back(Output);
944 typedef int (FGOutput::*iOPMF)(void) const;
945 string outputProp = CreateIndexedPropertyName("simulation/output",Outputs.size()-1);
946 instance->Tie(outputProp+"/log_rate_hz", Output, (iOPMF)0, &FGOutput::SetRate);
951 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
953 void FGFDMExec::DoTrim(int mode)
957 if (Constructing) return;
959 if (mode < 0 || mode > JSBSim::tNone) {
960 cerr << endl << "Illegal trimming mode!" << endl << endl;
963 saved_time = State->Getsim_time();
964 FGTrim trim(this, (JSBSim::TrimMode)mode);
965 if ( !trim.DoTrim() ) cerr << endl << "Trim Failed" << endl << endl;
967 State->Setsim_time(saved_time);
970 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
972 void FGFDMExec::DoTrimAnalysis(int mode)
975 if (Constructing) return;
977 if (mode < 0 || mode > JSBSim::taNone) {
978 cerr << endl << "Illegal trimming mode!" << endl << endl;
981 saved_time = State->Getsim_time();
983 FGTrimAnalysis trimAnalysis(this, (JSBSim::TrimAnalysisMode)mode);
985 if ( !trimAnalysis.Load(IC->GetInitFile(), false) ) {
986 cerr << "A problem occurred with trim configuration file " << trimAnalysis.Load(IC->GetInitFile()) << endl;
990 bool result = trimAnalysis.DoTrim();
992 if ( !result ) cerr << endl << "Trim Failed" << endl << endl;
994 trimAnalysis.Report();
995 State->Setsim_time(saved_time);
998 cout << "\nOutput: " << GetOutputFileName() << endl;
1002 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1004 void FGFDMExec::UseAtmosphereMSIS(void)
1006 FGAtmosphere *oldAtmosphere = Atmosphere;
1007 Atmosphere = new MSIS(this);
1008 if (!Atmosphere->InitModel()) {
1009 cerr << fgred << "MSIS Atmosphere model init failed" << fgdef << endl;
1012 delete oldAtmosphere;
1015 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1017 void FGFDMExec::UseAtmosphereMars(void)
1020 FGAtmosphere *oldAtmosphere = Atmosphere;
1021 Atmosphere = new FGMars(this);
1022 if (!Atmosphere->InitModel()) {
1023 cerr << fgred << "Mars Atmosphere model init failed" << fgdef << endl;
1026 delete oldAtmosphere;
1030 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1031 // The bitmasked value choices are as follows:
1032 // unset: In this case (the default) JSBSim would only print
1033 // out the normally expected messages, essentially echoing
1034 // the config files as they are read. If the environment
1035 // variable is not set, debug_lvl is set to 1 internally
1036 // 0: This requests JSBSim not to output any messages
1038 // 1: This value explicity requests the normal JSBSim
1040 // 2: This value asks for a message to be printed out when
1041 // a class is instantiated
1042 // 4: When this value is set, a message is displayed when a
1043 // FGModel object executes its Run() method
1044 // 8: When this value is set, various runtime state variables
1045 // are printed out periodically
1046 // 16: When set various parameters are sanity checked and
1047 // a message is printed out when they go out of bounds
1049 void FGFDMExec::Debug(int from)
1051 if (debug_lvl <= 0) return;
1053 if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output
1054 if (from == 0) { // Constructor
1055 cout << "\n\n " << highint << underon << "JSBSim Flight Dynamics Model v"
1056 << JSBSim_version << underoff << normint << endl;
1057 cout << halfint << " [JSBSim-ML v" << needed_cfg_version << "]\n\n";
1058 cout << normint << "JSBSim startup beginning ...\n\n";
1059 } else if (from == 3) {
1060 cout << "\n\nJSBSim startup complete\n\n";
1063 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
1064 if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
1065 if (from == 1) cout << "Destroyed: FGFDMExec" << endl;
1067 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
1069 cout << "================== Frame: " << Frame << " Time: "
1070 << State->Getsim_time() << " dt: " << State->Getdt() << endl;
1073 if (debug_lvl & 8 ) { // Runtime state variables
1075 if (debug_lvl & 16) { // Sanity checking
1077 if (debug_lvl & 64) {
1078 if (from == 0) { // Constructor
1079 cout << IdSrc << endl;
1080 cout << IdHdr << endl;