1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 Purpose: Standalone version of JSBSim.
9 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
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 General Public License for more
21 You should have received a copy of the GNU 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.
25 Further information about the GNU General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
31 This class Handles calling JSBSim standalone. It is set up for compilation under
32 Borland C+Builder or other compiler.
35 --------------------------------------------------------------------------------
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 #include "FGFDMExec.h"
43 #include "FGRotation.h"
44 #include "FGAtmosphere.h"
47 #include "FGAircraft.h"
48 #include "FGTranslation.h"
49 #include "FGPosition.h"
50 #include "FGAuxiliary.h"
52 #include "FGConfigFile.h"
54 #include "FGJSBBase.h"
57 #include <simgear/compiler.h>
60 # if defined(sgi) && !defined(__GNUC__)
61 # include <iostream.h>
67 #if __BCPLUSPLUS__ == 0x540
70 //---------------------------------------------------------------------------
72 USEUNIT("FGUtility.cpp");
73 USEUNIT("FGAircraft.cpp");
74 USEUNIT("FGAtmosphere.cpp");
75 USEUNIT("FGAuxiliary.cpp");
76 USEUNIT("FGCoefficient.cpp");
77 USEUNIT("FGColumnVector3.cpp");
78 USEUNIT("FGColumnVector4.cpp");
79 USEUNIT("FGConfigFile.cpp");
80 USEUNIT("FGEngine.cpp");
81 USEUNIT("FGFactorGroup.cpp");
83 USEUNIT("FGFDMExec.cpp");
84 USEUNIT("FGfdmSocket.cpp");
85 USEUNIT("FGForce.cpp");
86 USEUNIT("FGGroundReactions.cpp");
87 USEUNIT("FGInertial.cpp");
88 USEUNIT("FGInitialCondition.cpp");
89 USEUNIT("FGJSBBase.cpp");
90 USEUNIT("FGLGear.cpp");
91 USEUNIT("FGMassBalance.cpp");
92 USEUNIT("FGMatrix33.cpp");
93 USEUNIT("FGModel.cpp");
94 USEUNIT("FGNozzle.cpp");
95 USEUNIT("FGOutput.cpp");
96 USEUNIT("FGPiston.cpp");
97 USEUNIT("FGPosition.cpp");
98 USEUNIT("FGPropeller.cpp");
99 USEUNIT("FGPropulsion.cpp");
100 USEUNIT("FGRocket.cpp");
101 USEUNIT("FGRotation.cpp");
102 USEUNIT("FGRotor.cpp");
103 USEUNIT("FGScript.cpp");
104 USEUNIT("FGState.cpp");
105 USEUNIT("FGTable.cpp");
106 USEUNIT("FGTank.cpp");
107 USEUNIT("FGThruster.cpp");
108 USEUNIT("FGTranslation.cpp");
109 USEUNIT("FGTrim.cpp");
110 USEUNIT("FGTrimAxis.cpp");
111 USEUNIT("FGTurboJet.cpp");
112 USEUNIT("FGTurboProp.cpp");
113 USEUNIT("FGTurboShaft.cpp");
114 USEUNIT("FGAerodynamics.cpp");
115 USEUNIT("filtersjb\FGSwitch.cpp");
116 USEUNIT("filtersjb\FGFCSComponent.cpp");
117 USEUNIT("filtersjb\FGFilter.cpp");
118 USEUNIT("filtersjb\FGGain.cpp");
119 USEUNIT("filtersjb\FGGradient.cpp");
120 USEUNIT("filtersjb\FGKinemat.cpp");
121 USEUNIT("filtersjb\FGSummer.cpp");
122 USEUNIT("filtersjb\FGDeadBand.cpp");
123 //---------------------------------------------------------------------------
127 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
131 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
135 static const char *IdSrc = "$Id$";
140 string LogOutputName;
141 string LogDirectiveName;
144 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
148 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
152 void options(int, char**);
154 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
158 /** Standalone JSBSim main program
159 This is the wrapper program used to instantiate the JSBSim system and control
160 it. Use this program to build a version of JSBSim that can be run from the
161 command line. To get any use out of this, you will have to create a script
162 to run a test case and specify what kind of output you would like.
163 @author Jon S. Berndt
168 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
172 int main(int argc, char* argv[])
178 LogDirectiveName = "";
180 bool Scripted = false;
185 FDMExec = new FGFDMExec();
187 if (!ScriptName.empty()) { // SCRIPTED CASE
189 Script = new FGScript(FDMExec);
190 result = Script->LoadScript(ScriptName);
193 cerr << "Script file " << ScriptName << " was not successfully loaded" << endl;
199 } else if (!AircraftName.empty() || !ResetName.empty()) { // form jsbsim <acname> <resetfile>
201 if ( ! FDMExec->LoadModel("aircraft", "engine", AircraftName)) {
202 cerr << " JSBSim could not be started" << endl << endl;
206 FGInitialCondition IC(FDMExec);
207 if ( ! IC.Load("aircraft",AircraftName,ResetName)) {
208 cerr << "Initialization unsuccessful" << endl;
212 cout << " No Aircraft, Script, or Reset information given" << endl << endl;
217 // RUN loop. MESSAGES are read inside the Run() loop and output as necessary.
220 FGJSBBase::Message* msg;
221 result = FDMExec->Run();
223 while (FDMExec->ReadMessage()) {
224 msg = FDMExec->ProcessMessage();
226 case FGJSBBase::Message::eText:
227 cout << msg->messageId << ": " << msg->text << endl;
229 case FGJSBBase::Message::eBool:
230 cout << msg->messageId << ": " << msg->text << " " << msg->bVal << endl;
232 case FGJSBBase::Message::eInteger:
233 cout << msg->messageId << ": " << msg->text << " " << msg->iVal << endl;
235 case FGJSBBase::Message::eDouble:
236 cout << msg->messageId << ": " << msg->text << " " << msg->dVal << endl;
239 cerr << "Unrecognized message type." << endl;
245 if (!Script->RunScript()) break;
248 result = FDMExec->Run();
256 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
258 void options(int count, char **arg)
263 cout << endl << " JSBSim version " << FDMExec->GetVersion() << endl << endl;
264 cout << " Usage: jsbsim <options>" << endl << endl;
265 cout << " options:" << endl;
266 cout << " --help returns this message" << endl;
267 cout << " --version returns the version number" << endl;
268 cout << " --outputlogfile=<filename> sets the name of the data output file" << endl;
269 cout << " --logdirectivefile=<filename> specifies the name of the data logging directives file" << endl;
270 cout << " --aircraft=<filename> specifies the name of the aircraft to be modeled" << endl;
271 cout << " --script=<filename> specifies a script to run" << endl;
272 cout << " --initfile=<filename> specifies an initilization file" << endl << endl;
273 cout << " NOTE: There can be no spaces around the = sign when" << endl;
274 cout << " an option is followed by a filename" << endl << endl;
277 for (i=1; i<count; i++) {
278 string argument = string(arg[i]);
280 if (argument.find("--help") != string::npos) {
281 cout << endl << " JSBSim version " << FDMExec->GetVersion() << endl << endl;
282 cout << " Usage: jsbsim <options>" << endl << endl;
283 cout << " options:" << endl;
284 cout << " --help returns this message" << endl;
285 cout << " --version returns the version number" << endl;
286 cout << " --outputlogfile=<filename> sets the name of the data output file" << endl;
287 cout << " --logdirectivefile=<filename> specifies the name of the data logging directives file" << endl;
288 cout << " --aircraft=<filename> specifies the name of the aircraft to be modeled" << endl;
289 cout << " --script=<filename> specifies a script to run" << endl;
290 cout << " --initfile=<filename> specifies an initilization file" << endl << endl;
291 cout << " NOTE: There can be no spaces around the = sign when" << endl;
292 cout << " an option is followed by a filename" << endl << endl;
294 } else if (argument.find("--version") != string::npos) {
295 cout << endl << " JSBSim Version: " << FDMExec->GetVersion() << endl << endl;
297 } else if (argument.find("--outputlogfile") != string::npos) {
298 n = argument.find("=")+1;
300 LogOutputName = argument.substr(argument.find("=")+1);
302 LogOutputName = "JSBout.csv";
303 cerr << " Output log file name not valid or not understood. Using JSBout.csv as default";
305 } else if (argument.find("--logdirectivefile") != string::npos) {
306 n = argument.find("=")+1;
308 LogDirectiveName = argument.substr(argument.find("=")+1);
310 cerr << " Log directives file not valid or not understood." << endl << endl;
313 } else if (argument.find("--aircraft") != string::npos) {
314 n = argument.find("=")+1;
316 AircraftName = argument.substr(argument.find("=")+1);
318 cerr << " Aircraft name not valid or not understood." << endl << endl;
321 } else if (argument.find("--script") != string::npos) {
322 n = argument.find("=")+1;
324 ScriptName = argument.substr(argument.find("=")+1);
326 cerr << " Script name not valid or not understood." << endl << endl;
329 } else if (argument.find("--initfile") != string::npos) {
330 n = argument.find("=")+1;
332 ResetName = argument.substr(argument.find("=")+1);
334 cerr << " Reset name not valid or not understood." << endl << endl;
338 cerr << endl << " Parameter: " << argument << " not understood" << endl;