]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/JSBSim.cpp
Latest round of JSBSim updates.
[flightgear.git] / src / FDM / JSBSim / JSBSim.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       JSBSim.cpp
4  Author:       Jon S. Berndt
5  Date started: 08/17/99
6  Purpose:      Standalone version of JSBSim.
7  Called by:    The USER.
8
9  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
10
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
14  version.
15
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
19  details.
20
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.
24
25  Further information about the GNU General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30
31 This class Handles calling JSBSim standalone. It is set up for compilation under
32 Borland C+Builder or other compiler.
33
34 HISTORY
35 --------------------------------------------------------------------------------
36 08/17/99   JSB   Created
37
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 INCLUDES
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41
42 #include "FGFDMExec.h"
43 #include "FGRotation.h"
44 #include "FGAtmosphere.h"
45 #include "FGState.h"
46 #include "FGFCS.h"
47 #include "FGAircraft.h"
48 #include "FGTranslation.h"
49 #include "FGPosition.h"
50 #include "FGAuxiliary.h"
51 #include "FGOutput.h"
52 #include "FGConfigFile.h"
53
54 #ifdef FGFS
55 #include <simgear/compiler.h>
56 #include STL_IOSTREAM
57 #  ifdef FG_HAVE_STD_INCLUDES
58 #    include <ctime>
59 #  else
60 #    include <time.h>
61 #  endif
62 #else
63 #include <iostream>
64 #include <ctime>
65 #endif
66
67 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 DEFINITIONS
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70
71 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 GLOBAL DATA
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
74
75 static const char *IdSrc = "$Id$";
76
77 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
80
81 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 DOCUMENTATION
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
84
85 /** Standalone JSBSim main program
86     This is the wrapper program used to instantiate the JSBSim system and control
87     it. Use this program to build a version of JSBSim that can be run from the
88     command line. To get any use out of this, you will have to create a script
89     to run a test case and specify what kind of output you would like.
90     @author Jon S. Berndt
91     @version $Id$
92     @see -
93 */
94
95 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 IMPLEMENTATION
97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
98
99 int main(int argc, char** argv)
100 {
101   FGFDMExec* FDMExec;
102   float cmd = 0.0;
103   bool result = false;
104   bool scripted = false;
105
106   if (argc == 2) {
107     FGConfigFile testFile(argv[1]);
108
109     if (!testFile.IsOpen()) {
110       cout << "Script file not opened" << endl;
111       exit(-1); 
112     }
113
114     testFile.GetNextConfigLine();
115     if (testFile.GetValue("runscript").length() <= 0) {
116       cout << "File: " << argv[1] << " is not a script file" << endl;
117       exit(-1); 
118     }
119     scripted = true;
120   } else if (argc != 3) {
121     cout << endl
122          << "  You must enter the name of a registered aircraft and reset point:"
123          << endl << endl << "  FDM <aircraft name> <reset file>" << endl;
124     cout << endl << "  Alternatively, you may specify only the name of a script file:"
125          << endl << endl << "  FDM <script file>" << endl << endl;
126     exit(0);
127   }
128
129   FDMExec = new FGFDMExec();
130
131   if (scripted) {
132     result = FDMExec->LoadScript(argv[1]);
133     if (!result) {
134       cerr << "Script file " << argv[1] << " was not successfully loaded" << endl;
135       exit(-1);
136     }
137   } else {
138     result = FDMExec->LoadModel("aircraft", "engine", string(argv[1]));
139     if (!result) {
140         cerr << "Aircraft file " << argv[1] << " was not found" << endl;
141             exit(-1);
142     }
143     if ( ! FDMExec->GetState()->Reset("aircraft", string(argv[1]), string(argv[2])))
144                    FDMExec->GetState()->Initialize(2000,0,0,0,0,0,0.5,0.5,40000);
145   }
146
147   while (FDMExec->Run()) {}
148
149   delete FDMExec;
150
151   return 0;
152 }