1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 Purpose: Encapsulates the JSBBase object
8 ------------- Copyright (C) 2001 Jon S. Berndt (jon@jsbsim.org) -------------
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU Lesser General Public License as published by the Free Software
12 Foundation; either version 2 of the License, or (at your option) any later
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
20 You should have received a copy of the GNU Lesser General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22 Place - Suite 330, Boston, MA 02111-1307, USA.
24 Further information about the GNU Lesser General Public License can also be found on
25 the world wide web at http://www.gnu.org.
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
31 --------------------------------------------------------------------------------
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 #include "FGJSBBase.h"
47 static const char *IdSrc = "$Id: FGJSBBase.cpp,v 1.30 2011/06/13 11:47:04 jberndt Exp $";
48 static const char *IdHdr = ID_JSBBASE;
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55 char FGJSBBase::highint[5] = {27, '[', '1', 'm', '\0' };
56 char FGJSBBase::halfint[5] = {27, '[', '2', 'm', '\0' };
57 char FGJSBBase::normint[6] = {27, '[', '2', '2', 'm', '\0' };
58 char FGJSBBase::reset[5] = {27, '[', '0', 'm', '\0' };
59 char FGJSBBase::underon[5] = {27, '[', '4', 'm', '\0' };
60 char FGJSBBase::underoff[6] = {27, '[', '2', '4', 'm', '\0' };
61 char FGJSBBase::fgblue[6] = {27, '[', '3', '4', 'm', '\0' };
62 char FGJSBBase::fgcyan[6] = {27, '[', '3', '6', 'm', '\0' };
63 char FGJSBBase::fgred[6] = {27, '[', '3', '1', 'm', '\0' };
64 char FGJSBBase::fggreen[6] = {27, '[', '3', '2', 'm', '\0' };
65 char FGJSBBase::fgdef[6] = {27, '[', '3', '9', 'm', '\0' };
67 char FGJSBBase::highint[5] = {'\0' };
68 char FGJSBBase::halfint[5] = {'\0' };
69 char FGJSBBase::normint[6] = {'\0' };
70 char FGJSBBase::reset[5] = {'\0' };
71 char FGJSBBase::underon[5] = {'\0' };
72 char FGJSBBase::underoff[6] = {'\0' };
73 char FGJSBBase::fgblue[6] = {'\0' };
74 char FGJSBBase::fgcyan[6] = {'\0' };
75 char FGJSBBase::fgred[6] = {'\0' };
76 char FGJSBBase::fggreen[6] = {'\0' };
77 char FGJSBBase::fgdef[6] = {'\0' };
80 const double FGJSBBase::radtodeg = 57.295779513082320876798154814105;
81 const double FGJSBBase::degtorad = 0.017453292519943295769236907684886;
82 const double FGJSBBase::hptoftlbssec = 550.0;
83 const double FGJSBBase::psftoinhg = 0.014138;
84 const double FGJSBBase::psftopa = 47.88;
85 const double FGJSBBase::fpstokts = 0.592484;
86 const double FGJSBBase::ktstofps = 1.68781;
87 const double FGJSBBase::inchtoft = 0.08333333;
88 const double FGJSBBase::in3tom3 = 1.638706E-5;
89 const double FGJSBBase::m3toft3 = 1.0/(fttom*fttom*fttom);
90 const double FGJSBBase::inhgtopa = 3386.38;
91 const double FGJSBBase::fttom = 0.3048;
92 double FGJSBBase::Reng = 1716.56; // Gas constant for Air (ft-lb/slug-R)
93 double FGJSBBase::Rstar = 1545.348; // Universal gas constant
94 double FGJSBBase::Mair = 28.9645; //
95 const double FGJSBBase::SHRatio = 1.40;
97 // Note that definition of lbtoslug by the inverse of slugtolb and not
98 // to a different constant you can also get from some tables will make
99 // lbtoslug*slugtolb == 1 up to the magnitude of roundoff. So converting from
100 // slug to lb and back will yield to the original value you started with up
101 // to the magnitude of roundoff.
102 // Taken from units gnu commandline tool
103 const double FGJSBBase::slugtolb = 32.174049;
104 const double FGJSBBase::lbtoslug = 1.0/slugtolb;
105 const double FGJSBBase::kgtolb = 2.20462;
106 const double FGJSBBase::kgtoslug = 0.06852168;
108 const string FGJSBBase::needed_cfg_version = "2.0";
109 const string FGJSBBase::JSBSim_version = "1.0 "__DATE__" "__TIME__;
111 std::queue <FGJSBBase::Message> FGJSBBase::Messages;
112 FGJSBBase::Message FGJSBBase::localMsg;
113 unsigned int FGJSBBase::messageId = 0;
115 short FGJSBBase::debug_lvl = 1;
121 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 void FGJSBBase::PutMessage(const Message& msg)
128 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 void FGJSBBase::PutMessage(const string& text)
134 msg.messageId = messageId++;
135 msg.subsystem = "FDM";
136 msg.type = Message::eText;
140 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 void FGJSBBase::PutMessage(const string& text, bool bVal)
146 msg.messageId = messageId++;
147 msg.subsystem = "FDM";
148 msg.type = Message::eBool;
153 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 void FGJSBBase::PutMessage(const string& text, int iVal)
159 msg.messageId = messageId++;
160 msg.subsystem = "FDM";
161 msg.type = Message::eInteger;
162 msg.bVal = (iVal != 0);
166 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168 void FGJSBBase::PutMessage(const string& text, double dVal)
172 msg.messageId = messageId++;
173 msg.subsystem = "FDM";
174 msg.type = Message::eDouble;
175 msg.bVal = (dVal != 0.0);
179 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 int FGJSBBase::SomeMessages(void)
183 return !Messages.empty();
186 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188 void FGJSBBase::ProcessMessage(void)
190 if (Messages.empty()) return;
191 localMsg = Messages.front();
193 while (Messages.size() > 0) {
194 switch (localMsg.type) {
195 case JSBSim::FGJSBBase::Message::eText:
196 cout << localMsg.messageId << ": " << localMsg.text << endl;
198 case JSBSim::FGJSBBase::Message::eBool:
199 cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.bVal << endl;
201 case JSBSim::FGJSBBase::Message::eInteger:
202 cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.iVal << endl;
204 case JSBSim::FGJSBBase::Message::eDouble:
205 cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.dVal << endl;
208 cerr << "Unrecognized message type." << endl;
212 if (Messages.size() > 0) localMsg = Messages.front();
218 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220 FGJSBBase::Message* FGJSBBase::ProcessNextMessage(void)
222 if (Messages.empty()) return NULL;
223 localMsg = Messages.front();
229 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231 void FGJSBBase::disableHighLighting(void) {
245 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247 string FGJSBBase::CreateIndexedPropertyName(const string& Property, int index)
249 std::ostringstream buf;
250 buf << Property << '[' << index << ']';
254 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
256 double FGJSBBase::GaussianRandomNumber(void)
258 static double V1, V2, S;
259 static int phase = 0;
263 V1 = V2 = S = X = 0.0;
266 double U1 = (double)rand() / RAND_MAX;
267 double U2 = (double)rand() / RAND_MAX;
271 S = V1 * V1 + V2 * V2;
272 } while(S >= 1 || S == 0);
274 X = V1 * sqrt(-2 * log(S) / S);
276 X = V2 * sqrt(-2 * log(S) / S);
283 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285 } // namespace JSBSim