Branch data Line data Source code
1 : : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 : :
3 : : Module: FGJSBBase.cpp
4 : : Author: Jon S. Berndt
5 : : Date started: 07/01/01
6 : : Purpose: Encapsulates the JSBBase object
7 : :
8 : : ------------- Copyright (C) 2001 Jon S. Berndt (jon@jsbsim.org) -------------
9 : :
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
13 : : version.
14 : :
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
18 : : details.
19 : :
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.
23 : :
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.
26 : :
27 : : FUNCTIONAL DESCRIPTION
28 : : --------------------------------------------------------------------------------
29 : :
30 : : HISTORY
31 : : --------------------------------------------------------------------------------
32 : : 07/01/01 JSB Created
33 : :
34 : : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 : : INCLUDES
36 : : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37 : :
38 : : #define BASE
39 : :
40 : : #include "FGJSBBase.h"
41 : : #include <iostream>
42 : : #include <sstream>
43 : : #include <cstdlib>
44 : :
45 : : namespace JSBSim {
46 : :
47 : : static const char *IdSrc = "$Id: FGJSBBase.cpp,v 1.29 2010/03/18 13:19:21 jberndt Exp $";
48 : : static const char *IdHdr = ID_JSBBASE;
49 : :
50 : : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 : : CLASS IMPLEMENTATION
52 : : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53 : :
54 : : #ifndef _MSC_VER
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' };
66 : : #else
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' };
78 : : #endif
79 : :
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 : 2 : 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.0;
93 : : const double FGJSBBase::SHRatio = 1.40;
94 : :
95 : : // Note that definition of lbtoslug by the inverse of slugtolb and not
96 : : // to a different constant you can also get from some tables will make
97 : : // lbtoslug*slugtolb == 1 up to the magnitude of roundoff. So converting from
98 : : // slug to lb and back will yield to the original value you started with up
99 : : // to the magnitude of roundoff.
100 : : // Taken from units gnu commandline tool
101 : : const double FGJSBBase::slugtolb = 32.174049;
102 : : const double FGJSBBase::lbtoslug = 1.0/slugtolb;
103 : : const double FGJSBBase::kgtolb = 2.20462;
104 : : const double FGJSBBase::kgtoslug = 0.06852168;
105 : :
106 : 4 : const string FGJSBBase::needed_cfg_version = "2.0";
107 : 4 : const string FGJSBBase::JSBSim_version = "1.0 "__DATE__" "__TIME__;
108 : :
109 : 2 : std::queue <FGJSBBase::Message> FGJSBBase::Messages;
110 [ + + ][ + - ]: 4 : FGJSBBase::Message FGJSBBase::localMsg;
111 : : unsigned int FGJSBBase::messageId = 0;
112 : :
113 : : short FGJSBBase::debug_lvl = 1;
114 : :
115 : : using std::cerr;
116 : : using std::cout;
117 : : using std::endl;
118 : :
119 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 : :
121 : 0 : void FGJSBBase::PutMessage(const Message& msg)
122 : : {
123 : 0 : Messages.push(msg);
124 : 0 : }
125 : :
126 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127 : :
128 : 0 : void FGJSBBase::PutMessage(const string& text)
129 : : {
130 : 0 : Message msg;
131 : : msg.text = text;
132 : 0 : msg.messageId = messageId++;
133 : : msg.subsystem = "FDM";
134 : 0 : msg.type = Message::eText;
135 : 0 : Messages.push(msg);
136 : 0 : }
137 : :
138 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 : :
140 : 0 : void FGJSBBase::PutMessage(const string& text, bool bVal)
141 : : {
142 : 0 : Message msg;
143 : : msg.text = text;
144 : 0 : msg.messageId = messageId++;
145 : : msg.subsystem = "FDM";
146 : 0 : msg.type = Message::eBool;
147 : 0 : msg.bVal = bVal;
148 : 0 : Messages.push(msg);
149 : 0 : }
150 : :
151 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152 : :
153 : 0 : void FGJSBBase::PutMessage(const string& text, int iVal)
154 : : {
155 : 0 : Message msg;
156 : : msg.text = text;
157 : 0 : msg.messageId = messageId++;
158 : : msg.subsystem = "FDM";
159 : 0 : msg.type = Message::eInteger;
160 : 0 : msg.bVal = (iVal != 0);
161 : 0 : Messages.push(msg);
162 : 0 : }
163 : :
164 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165 : :
166 : 0 : void FGJSBBase::PutMessage(const string& text, double dVal)
167 : : {
168 : 0 : Message msg;
169 : : msg.text = text;
170 : 0 : msg.messageId = messageId++;
171 : : msg.subsystem = "FDM";
172 : 0 : msg.type = Message::eDouble;
173 : 0 : msg.bVal = (dVal != 0.0);
174 : 0 : Messages.push(msg);
175 : 0 : }
176 : :
177 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178 : :
179 : 0 : int FGJSBBase::SomeMessages(void)
180 : : {
181 : 0 : return !Messages.empty();
182 : : }
183 : :
184 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 : :
186 : 54003 : void FGJSBBase::ProcessMessage(void)
187 : : {
188 [ - + ]: 54003 : if (Messages.empty()) return;
189 : 0 : localMsg = Messages.front();
190 : :
191 [ # # ]: 54003 : while (Messages.size() > 0) {
192 [ # # # # : 0 : switch (localMsg.type) {
# ]
193 : : case JSBSim::FGJSBBase::Message::eText:
194 : 0 : cout << localMsg.messageId << ": " << localMsg.text << endl;
195 : : break;
196 : : case JSBSim::FGJSBBase::Message::eBool:
197 : 0 : cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.bVal << endl;
198 : : break;
199 : : case JSBSim::FGJSBBase::Message::eInteger:
200 : 0 : cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.iVal << endl;
201 : : break;
202 : : case JSBSim::FGJSBBase::Message::eDouble:
203 : 0 : cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.dVal << endl;
204 : : break;
205 : : default:
206 : 0 : cerr << "Unrecognized message type." << endl;
207 : : break;
208 : : }
209 : 0 : Messages.pop();
210 [ # # ]: 0 : if (Messages.size() > 0) localMsg = Messages.front();
211 : 0 : else break;
212 : : }
213 : :
214 : : }
215 : :
216 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 : :
218 : 0 : FGJSBBase::Message* FGJSBBase::ProcessNextMessage(void)
219 : : {
220 [ # # ]: 0 : if (Messages.empty()) return NULL;
221 : 0 : localMsg = Messages.front();
222 : :
223 : 0 : Messages.pop();
224 : 0 : return &localMsg;
225 : : }
226 : :
227 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228 : :
229 : 0 : void FGJSBBase::disableHighLighting(void) {
230 : 0 : highint[0]='\0';
231 : 0 : halfint[0]='\0';
232 : 0 : normint[0]='\0';
233 : 0 : reset[0]='\0';
234 : 0 : underon[0]='\0';
235 : 0 : underoff[0]='\0';
236 : 0 : fgblue[0]='\0';
237 : 0 : fgcyan[0]='\0';
238 : 0 : fgred[0]='\0';
239 : 0 : fggreen[0]='\0';
240 : 0 : fgdef[0]='\0';
241 : 0 : }
242 : :
243 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244 : :
245 : 391 : string FGJSBBase::CreateIndexedPropertyName(const string& Property, int index)
246 : : {
247 : 391 : std::ostringstream buf;
248 : 391 : buf << Property << '[' << index << ']';
249 : 391 : return buf.str();
250 : : }
251 : :
252 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253 : :
254 : 0 : double FGJSBBase::GaussianRandomNumber(void)
255 : : {
256 : : static double V1, V2, S;
257 : : static int phase = 0;
258 : : double X;
259 : :
260 [ # # ]: 0 : if (phase == 0) {
261 : 0 : V1 = V2 = S = X = 0.0;
262 : :
263 [ # # ][ # # ]: 0 : do {
264 : 0 : double U1 = (double)rand() / RAND_MAX;
265 : 0 : double U2 = (double)rand() / RAND_MAX;
266 : :
267 : 0 : V1 = 2 * U1 - 1;
268 : 0 : V2 = 2 * U2 - 1;
269 : 0 : S = V1 * V1 + V2 * V2;
270 : : } while(S >= 1 || S == 0);
271 : :
272 : 0 : X = V1 * sqrt(-2 * log(S) / S);
273 : : } else
274 : 0 : X = V2 * sqrt(-2 * log(S) / S);
275 : :
276 : 0 : phase = 1 - phase;
277 : :
278 : 0 : return X;
279 : : }
280 : :
281 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
282 : :
283 [ + + ][ + - ]: 12 : } // namespace JSBSim
284 : :
|