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"
55 #include <simgear/compiler.h>
57 # ifdef SG_HAVE_STD_INCLUDES
63 # if defined(sgi) && !defined(__GNUC__)
64 # include <iostream.h>
72 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
76 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
80 static const char *IdSrc = "$Id$";
82 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
86 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
90 /** Standalone JSBSim main program
91 This is the wrapper program used to instantiate the JSBSim system and control
92 it. Use this program to build a version of JSBSim that can be run from the
93 command line. To get any use out of this, you will have to create a script
94 to run a test case and specify what kind of output you would like.
100 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
104 int main(int argc, char** argv)
109 bool scripted = false;
112 FGConfigFile testFile(argv[1]);
114 if (!testFile.IsOpen()) {
115 cout << "Script file not opened" << endl;
119 testFile.GetNextConfigLine();
120 if (testFile.GetValue("runscript").length() <= 0) {
121 cout << "File: " << argv[1] << " is not a script file" << endl;
125 } else if (argc != 3) {
127 << " You must enter the name of a registered aircraft and reset point:"
128 << endl << endl << " FDM <aircraft name> <reset file>" << endl;
129 cout << endl << " Alternatively, you may specify only the name of a script file:"
130 << endl << endl << " FDM <script file>" << endl << endl;
134 FDMExec = new FGFDMExec();
136 if (scripted) { // form jsbsim <scriptfile>
137 result = FDMExec->LoadScript(argv[1]);
139 cerr << "Script file " << argv[1] << " was not successfully loaded" << endl;
142 } else { // form jsbsim <acname> <resetfile>
143 if ( ! FDMExec->LoadModel("aircraft", "engine", string(argv[1]))) {
144 cerr << "JSBSim could not be started" << endl;
148 FGInitialCondition IC(FDMExec);
149 if ( ! IC.Load("aircraft",string(argv[1]),string(argv[2]))) {
150 cerr << "Initialization unsuccessful" << endl;
155 struct FGJSBBase::Message* msg;
156 while (FDMExec->Run()) {
157 while (FDMExec->ReadMessage()) {
158 msg = FDMExec->ProcessMessage();
160 case FGJSBBase::Message::eText:
161 cout << msg->messageId << ": " << msg->text << endl;
163 case FGJSBBase::Message::eBool:
164 cout << msg->messageId << ": " << msg->text << " " << msg->bVal << endl;
166 case FGJSBBase::Message::eInteger:
167 cout << msg->messageId << ": " << msg->text << " " << msg->iVal << endl;
169 case FGJSBBase::Message::eDouble:
170 cout << msg->messageId << ": " << msg->text << " " << msg->dVal << endl;
173 cerr << "Unrecognized message type." << endl;