40 #include "FGJSBBase.h"
41 #include "models/FGAtmosphere.h"
52 char FGJSBBase::highint[5] = {27,
'[',
'1',
'm',
'\0' };
53 char FGJSBBase::halfint[5] = {27,
'[',
'2',
'm',
'\0' };
54 char FGJSBBase::normint[6] = {27,
'[',
'2',
'2',
'm',
'\0' };
55 char FGJSBBase::reset[5] = {27,
'[',
'0',
'm',
'\0' };
56 char FGJSBBase::underon[5] = {27,
'[',
'4',
'm',
'\0' };
57 char FGJSBBase::underoff[6] = {27,
'[',
'2',
'4',
'm',
'\0' };
58 char FGJSBBase::fgblue[6] = {27,
'[',
'3',
'4',
'm',
'\0' };
59 char FGJSBBase::fgcyan[6] = {27,
'[',
'3',
'6',
'm',
'\0' };
60 char FGJSBBase::fgred[6] = {27,
'[',
'3',
'1',
'm',
'\0' };
61 char FGJSBBase::fggreen[6] = {27,
'[',
'3',
'2',
'm',
'\0' };
62 char FGJSBBase::fgdef[6] = {27,
'[',
'3',
'9',
'm',
'\0' };
64 char FGJSBBase::highint[5] = {
'\0' };
65 char FGJSBBase::halfint[5] = {
'\0' };
66 char FGJSBBase::normint[6] = {
'\0' };
67 char FGJSBBase::reset[5] = {
'\0' };
68 char FGJSBBase::underon[5] = {
'\0' };
69 char FGJSBBase::underoff[6] = {
'\0' };
70 char FGJSBBase::fgblue[6] = {
'\0' };
71 char FGJSBBase::fgcyan[6] = {
'\0' };
72 char FGJSBBase::fgred[6] = {
'\0' };
73 char FGJSBBase::fggreen[6] = {
'\0' };
74 char FGJSBBase::fgdef[6] = {
'\0' };
77 const string FGJSBBase::needed_cfg_version =
"2.0";
78 const string FGJSBBase::JSBSim_version = JSBSIM_VERSION
" " __DATE__
" " __TIME__ ;
80 queue <FGJSBBase::Message> FGJSBBase::Messages;
81 FGJSBBase::Message FGJSBBase::localMsg;
82 unsigned int FGJSBBase::messageId = 0;
84 int FGJSBBase::gaussian_random_number_phase = 0;
86 short FGJSBBase::debug_lvl = 1;
90 void FGJSBBase::PutMessage(
const Message& msg)
97 void FGJSBBase::PutMessage(
const string& text)
101 msg.messageId = messageId++;
102 msg.subsystem =
"FDM";
103 msg.type = Message::eText;
109 void FGJSBBase::PutMessage(
const string& text,
bool bVal)
113 msg.messageId = messageId++;
114 msg.subsystem =
"FDM";
115 msg.type = Message::eBool;
122 void FGJSBBase::PutMessage(
const string& text,
int iVal)
126 msg.messageId = messageId++;
127 msg.subsystem =
"FDM";
128 msg.type = Message::eInteger;
135 void FGJSBBase::PutMessage(
const string& text,
double dVal)
139 msg.messageId = messageId++;
140 msg.subsystem =
"FDM";
141 msg.type = Message::eDouble;
148 void FGJSBBase::ProcessMessage(
void)
150 if (Messages.empty())
return;
151 localMsg = Messages.front();
153 while (SomeMessages()) {
154 switch (localMsg.type) {
155 case JSBSim::FGJSBBase::Message::eText:
156 cout << localMsg.messageId <<
": " << localMsg.text << endl;
158 case JSBSim::FGJSBBase::Message::eBool:
159 cout << localMsg.messageId <<
": " << localMsg.text <<
" " << localMsg.bVal << endl;
161 case JSBSim::FGJSBBase::Message::eInteger:
162 cout << localMsg.messageId <<
": " << localMsg.text <<
" " << localMsg.iVal << endl;
164 case JSBSim::FGJSBBase::Message::eDouble:
165 cout << localMsg.messageId <<
": " << localMsg.text <<
" " << localMsg.dVal << endl;
168 cerr <<
"Unrecognized message type." << endl;
172 if (SomeMessages()) localMsg = Messages.front();
182 if (Messages.empty())
return NULL;
183 localMsg = Messages.front();
191 void FGJSBBase::disableHighLighting(
void)
208 string FGJSBBase::CreateIndexedPropertyName(
const string& Property,
int index)
211 buf << Property <<
'[' << index <<
']';
217 double FGJSBBase::GaussianRandomNumber(
void)
219 static double V1, V2, S;
222 if (gaussian_random_number_phase == 0) {
223 V1 = V2 = S = X = 0.0;
226 double U1 = (double)rand() / RAND_MAX;
227 double U2 = (double)rand() / RAND_MAX;
231 S = V1 * V1 + V2 * V2;
232 }
while(S >= 1 || S == 0);
234 X = V1 * sqrt(-2 * log(S) / S);
236 X = V2 * sqrt(-2 * log(S) / S);
238 gaussian_random_number_phase = 1 - gaussian_random_number_phase;
245 double FGJSBBase::PitotTotalPressure(
double mach,
double p)
247 if (mach < 0)
return p;
249 return p*pow((1 + 0.2*mach*mach),3.5);
266 return p*166.92158009316827*pow(mach,7.0)/pow(7*mach*mach-1,2.5);
275 double FGJSBBase::MachFromImpactPressure(
double qc,
double p)
277 double A = qc / p + 1;
278 double M = sqrt(5.0*(pow(A, 1. / 3.5) - 1));
281 for (
unsigned int i = 0; i<10; i++)
282 M = 0.8812848543473311*sqrt(A*pow(1 - 1.0 / (7.0*M*M), 2.5));
289 double FGJSBBase::VcalibratedFromMach(
double mach,
double p)
291 double asl = FGAtmosphere::StdDaySLsoundspeed;
292 double psl = FGAtmosphere::StdDaySLpressure;
293 double qc = PitotTotalPressure(mach, p) - p;
295 return asl * MachFromImpactPressure(qc, psl);
300 double FGJSBBase::MachFromVcalibrated(
double vcas,
double p)
302 double asl = FGAtmosphere::StdDaySLsoundspeed;
303 double psl = FGAtmosphere::StdDaySLpressure;
304 double qc = PitotTotalPressure(vcas / asl, psl) - psl;
306 return MachFromImpactPressure(qc, p);