X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FJSBSim%2FFGJSBBase.cpp;h=d34075e702c45573969548abeda6680f4ad51e5a;hb=ec454158fee605314172422bf0934263b5e1fe42;hp=259220dbb343b1016c06b187be7d6646ef3bb53a;hpb=3cda82e0a9b3ff5eb6d21408328c5f864be31e0d;p=flightgear.git diff --git a/src/FDM/JSBSim/FGJSBBase.cpp b/src/FDM/JSBSim/FGJSBBase.cpp index 259220dbb..d34075e70 100644 --- a/src/FDM/JSBSim/FGJSBBase.cpp +++ b/src/FDM/JSBSim/FGJSBBase.cpp @@ -5,7 +5,7 @@ Date started: 07/01/01 Purpose: Encapsulates the JSBBase object - ------------- Copyright (C) 2001 Jon S. Berndt (jsb@hal-pc.org) ------------- + ------------- Copyright (C) 2001 Jon S. Berndt (jon@jsbsim.org) ------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software @@ -35,11 +35,16 @@ HISTORY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ +#define BASE + #include "FGJSBBase.h" +#include +#include +#include namespace JSBSim { -static const char *IdSrc = "$Id$"; +static const char *IdSrc = "$Id: FGJSBBase.cpp,v 1.30 2011/06/13 11:47:04 jberndt Exp $"; static const char *IdHdr = ID_JSBBASE; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -72,8 +77,8 @@ CLASS IMPLEMENTATION char FGJSBBase::fgdef[6] = {'\0' }; #endif -const double FGJSBBase::radtodeg = 57.29578; -const double FGJSBBase::degtorad = 1.745329E-2; +const double FGJSBBase::radtodeg = 57.295779513082320876798154814105; +const double FGJSBBase::degtorad = 0.017453292519943295769236907684886; const double FGJSBBase::hptoftlbssec = 550.0; const double FGJSBBase::psftoinhg = 0.014138; const double FGJSBBase::psftopa = 47.88; @@ -81,7 +86,12 @@ const double FGJSBBase::fpstokts = 0.592484; const double FGJSBBase::ktstofps = 1.68781; const double FGJSBBase::inchtoft = 0.08333333; const double FGJSBBase::in3tom3 = 1.638706E-5; -double FGJSBBase::Reng = 1716.0; +const double FGJSBBase::m3toft3 = 1.0/(fttom*fttom*fttom); +const double FGJSBBase::inhgtopa = 3386.38; +const double FGJSBBase::fttom = 0.3048; +double FGJSBBase::Reng = 1716.56; // Gas constant for Air (ft-lb/slug-R) +double FGJSBBase::Rstar = 1545.348; // Universal gas constant +double FGJSBBase::Mair = 28.9645; // const double FGJSBBase::SHRatio = 1.40; // Note that definition of lbtoslug by the inverse of slugtolb and not @@ -92,9 +102,11 @@ const double FGJSBBase::SHRatio = 1.40; // Taken from units gnu commandline tool const double FGJSBBase::slugtolb = 32.174049; const double FGJSBBase::lbtoslug = 1.0/slugtolb; +const double FGJSBBase::kgtolb = 2.20462; +const double FGJSBBase::kgtoslug = 0.06852168; const string FGJSBBase::needed_cfg_version = "2.0"; -const string FGJSBBase::JSBSim_version = "Pre-1.0 "__DATE__" "__TIME__; +const string FGJSBBase::JSBSim_version = "1.0 "__DATE__" "__TIME__; std::queue FGJSBBase::Messages; FGJSBBase::Message FGJSBBase::localMsg; @@ -102,6 +114,10 @@ unsigned int FGJSBBase::messageId = 0; short FGJSBBase::debug_lvl = 1; +using std::cerr; +using std::cout; +using std::endl; + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void FGJSBBase::PutMessage(const Message& msg) @@ -169,10 +185,43 @@ int FGJSBBase::SomeMessages(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -FGJSBBase::Message* FGJSBBase::ProcessMessage(void) +void FGJSBBase::ProcessMessage(void) +{ + if (Messages.empty()) return; + localMsg = Messages.front(); + + while (Messages.size() > 0) { + switch (localMsg.type) { + case JSBSim::FGJSBBase::Message::eText: + cout << localMsg.messageId << ": " << localMsg.text << endl; + break; + case JSBSim::FGJSBBase::Message::eBool: + cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.bVal << endl; + break; + case JSBSim::FGJSBBase::Message::eInteger: + cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.iVal << endl; + break; + case JSBSim::FGJSBBase::Message::eDouble: + cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.dVal << endl; + break; + default: + cerr << "Unrecognized message type." << endl; + break; + } + Messages.pop(); + if (Messages.size() > 0) localMsg = Messages.front(); + else break; + } + +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +FGJSBBase::Message* FGJSBBase::ProcessNextMessage(void) { if (Messages.empty()) return NULL; localMsg = Messages.front(); + Messages.pop(); return &localMsg; } @@ -195,5 +244,43 @@ void FGJSBBase::disableHighLighting(void) { //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +string FGJSBBase::CreateIndexedPropertyName(const string& Property, int index) +{ + std::ostringstream buf; + buf << Property << '[' << index << ']'; + return buf.str(); +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +double FGJSBBase::GaussianRandomNumber(void) +{ + static double V1, V2, S; + static int phase = 0; + double X; + + if (phase == 0) { + V1 = V2 = S = X = 0.0; + + do { + double U1 = (double)rand() / RAND_MAX; + double U2 = (double)rand() / RAND_MAX; + + V1 = 2 * U1 - 1; + V2 = 2 * U2 - 1; + S = V1 * V1 + V2 * V2; + } while(S >= 1 || S == 0); + + X = V1 * sqrt(-2 * log(S) / S); + } else + X = V2 * sqrt(-2 * log(S) / S); + + phase = 1 - phase; + + return X; +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + } // namespace JSBSim