1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
4 Author: Jon S. Berndt
\r
5 Date started: 08/17/99
\r
6 Purpose: Standalone version of JSBSim.
\r
9 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
\r
11 This program is free software; you can redistribute it and/or modify it under
\r
12 the terms of the GNU General Public License as published by the Free Software
\r
13 Foundation; either version 2 of the License, or (at your option) any later
\r
16 This program is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
21 You should have received a copy of the GNU General Public License along with
\r
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
\r
23 Place - Suite 330, Boston, MA 02111-1307, USA.
\r
25 Further information about the GNU General Public License can also be found on
\r
26 the world wide web at http://www.gnu.org.
\r
28 FUNCTIONAL DESCRIPTION
\r
29 --------------------------------------------------------------------------------
\r
31 This class Handles calling JSBSim standalone. It is set up for compilation under
\r
32 Borland C+Builder or other compiler.
\r
35 --------------------------------------------------------------------------------
\r
36 08/17/99 JSB Created
\r
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
42 #include "FGFDMExec.h"
\r
43 #include "FGRotation.h"
\r
44 #include "FGAtmosphere.h"
\r
45 #include "FGState.h"
\r
47 #include "FGAircraft.h"
\r
48 #include "FGTranslation.h"
\r
49 #include "FGPosition.h"
\r
50 #include "FGAuxiliary.h"
\r
51 #include "FGOutput.h"
\r
52 #include "FGConfigFile.h"
\r
55 #include <simgear/compiler.h>
\r
56 #include STL_IOSTREAM
\r
57 # ifdef SG_HAVE_STD_INCLUDES
\r
63 # if defined(sgi) && !defined(__GNUC__)
\r
64 # include <iostream.h>
\r
67 # include <iostream>
\r
72 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
76 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
80 static const char *IdSrc = "$Id$";
\r
82 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
83 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
\r
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
86 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
90 /** Standalone JSBSim main program
\r
91 This is the wrapper program used to instantiate the JSBSim system and control
\r
92 it. Use this program to build a version of JSBSim that can be run from the
\r
93 command line. To get any use out of this, you will have to create a script
\r
94 to run a test case and specify what kind of output you would like.
\r
95 @author Jon S. Berndt
\r
100 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
104 int main(int argc, char** argv)
\r
106 FGFDMExec* FDMExec;
\r
108 bool result = false;
\r
109 bool scripted = false;
\r
112 FGConfigFile testFile(argv[1]);
\r
114 if (!testFile.IsOpen()) {
\r
115 cout << "Script file not opened" << endl;
\r
119 testFile.GetNextConfigLine();
\r
120 if (testFile.GetValue("runscript").length() <= 0) {
\r
121 cout << "File: " << argv[1] << " is not a script file" << endl;
\r
125 } else if (argc != 3) {
\r
127 << " You must enter the name of a registered aircraft and reset point:"
\r
128 << endl << endl << " FDM <aircraft name> <reset file>" << endl;
\r
129 cout << endl << " Alternatively, you may specify only the name of a script file:"
\r
130 << endl << endl << " FDM <script file>" << endl << endl;
\r
134 FDMExec = new FGFDMExec();
\r
136 if (scripted) { // form jsbsim <scriptfile>
\r
137 result = FDMExec->LoadScript(argv[1]);
\r
139 cerr << "Script file " << argv[1] << " was not successfully loaded" << endl;
\r
142 } else { // form jsbsim <acname> <resetfile>
\r
143 if ( ! FDMExec->LoadModel("aircraft", "engine", string(argv[1]))) {
\r
144 cerr << " JSBSim could not be started" << endl << endl;
\r
148 FGInitialCondition IC(FDMExec);
\r
149 if ( ! IC.Load("aircraft",string(argv[1]),string(argv[2]))) {
\r
150 cerr << "Initialization unsuccessful" << endl;
\r
155 FGJSBBase::Message* msg;
\r
156 while (FDMExec->Run()) {
\r
157 while (FDMExec->ReadMessage()) {
\r
158 msg = FDMExec->ProcessMessage();
\r
159 switch (msg->type) {
\r
160 case FGJSBBase::Message::eText:
\r
161 cout << msg->messageId << ": " << msg->text << endl;
\r
163 case FGJSBBase::Message::eBool:
\r
164 cout << msg->messageId << ": " << msg->text << " " << msg->bVal << endl;
\r
166 case FGJSBBase::Message::eInteger:
\r
167 cout << msg->messageId << ": " << msg->text << " " << msg->iVal << endl;
\r
169 case FGJSBBase::Message::eDouble:
\r
170 cout << msg->messageId << ": " << msg->text << " " << msg->dVal << endl;
\r
173 cerr << "Unrecognized message type." << endl;
\r