MCPcopy Create free account
hub / github.com/FlightGear/flightgear / LoadScript

Method LoadScript

src/FDM/JSBSim/input_output/FGScript.cpp:91–364  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90
91bool FGScript::LoadScript(const SGPath& script, double default_dT,
92 const SGPath& initfile)
93{
94 SGPath initialize;
95 string aircraft="", prop_name="";
96 string notifyPropertyName="";
97 Element *element=0, *run_element=0, *event_element=0;
98 Element *set_element=0;
99 Element *notify_element = 0L, *notify_property_element = 0L;
100 double dt = 0.0, value = 0.0;
101 FGCondition *newCondition;
102
103 FGXMLFileRead XMLFileRead;
104 Element* document = XMLFileRead.LoadXMLDocument(script);
105
106 if (!document) {
107 cerr << "File: " << script << " could not be loaded." << endl;
108 return false;
109 }
110
111 if (document->GetName() != string("runscript")) {
112 cerr << "File: " << script << " is not a script file" << endl;
113 return false;
114 }
115
116 ScriptName = document->GetAttributeValue("name");
117
118 // First, find "run" element and set delta T
119
120 run_element = document->FindElement("run");
121
122 if (!run_element) {
123 cerr << "No \"run\" element found in script." << endl;
124 return false;
125 }
126
127 // Set sim timing
128
129 if (run_element->HasAttribute("start"))
130 StartTime = run_element->GetAttributeValueAsNumber("start");
131 else
132 StartTime = 0.0;
133 FDMExec->Setsim_time(StartTime);
134 if (run_element->HasAttribute("end")) {
135 EndTime = run_element->GetAttributeValueAsNumber("end");
136 } else {
137 cerr << "An end time (duration) for the script must be specified in the script <run> element." << endl;
138 return false;
139 }
140
141 if (default_dT == 0.0)
142 dt = run_element->GetAttributeValueAsNumber("dt");
143 else {
144 dt = default_dT;
145 cout << endl << "Overriding simulation step size from the command line. New step size is: "
146 << default_dT << " seconds (" << 1/default_dT << " Hz)" << endl << endl;
147 }
148

Callers

nothing calls this directly

Calls 15

DebugClass · 0.85
LoadXMLDocumentMethod · 0.80
GetAttributeValueMethod · 0.80
FindElementMethod · 0.80
HasAttributeMethod · 0.80
Setsim_timeMethod · 0.80
SetdtMethod · 0.80
GetDeltaTMethod · 0.80
LoadModelMethod · 0.80
GetICMethod · 0.80
GetInputMethod · 0.80

Tested by

no test coverage detected