From d19ef5cd9931d532eb1b8e2de3f7be0f6f22f8ae Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 20 Nov 2001 22:34:24 +0000 Subject: [PATCH] Synced with latest JSBSim cvs. --- src/FDM/JSBSim.cxx | 22 + src/FDM/JSBSim/FGAerodynamics.cpp | 16 +- src/FDM/JSBSim/FGAerodynamics.h | 12 +- src/FDM/JSBSim/FGAircraft.cpp | 128 ++--- src/FDM/JSBSim/FGAircraft.h | 63 +-- src/FDM/JSBSim/FGAtmosphere.cpp | 6 +- src/FDM/JSBSim/FGAtmosphere.h | 36 +- src/FDM/JSBSim/FGAuxiliary.cpp | 12 +- src/FDM/JSBSim/FGAuxiliary.h | 28 +- src/FDM/JSBSim/FGCoefficient.cpp | 16 +- src/FDM/JSBSim/FGCoefficient.h | 14 +- src/FDM/JSBSim/FGColumnVector3.cpp | 4 +- src/FDM/JSBSim/FGColumnVector3.h | 6 +- src/FDM/JSBSim/FGColumnVector4.cpp | 4 +- src/FDM/JSBSim/FGColumnVector4.h | 6 +- src/FDM/JSBSim/FGConfigFile.cpp | 625 +++++++++++----------- src/FDM/JSBSim/FGConfigFile.h | 6 +- src/FDM/JSBSim/FGEngine.cpp | 9 +- src/FDM/JSBSim/FGEngine.h | 64 +-- src/FDM/JSBSim/FGFCS.cpp | 50 +- src/FDM/JSBSim/FGFCS.h | 94 ++-- src/FDM/JSBSim/FGFDMExec.cpp | 20 +- src/FDM/JSBSim/FGFDMExec.h | 18 +- src/FDM/JSBSim/FGFactorGroup.cpp | 6 +- src/FDM/JSBSim/FGFactorGroup.h | 8 +- src/FDM/JSBSim/FGForce.cpp | 6 +- src/FDM/JSBSim/FGForce.h | 18 +- src/FDM/JSBSim/FGGroundReactions.cpp | 6 +- src/FDM/JSBSim/FGInertial.cpp | 2 +- src/FDM/JSBSim/FGInertial.h | 2 +- src/FDM/JSBSim/FGInitialCondition.cpp | 125 +++-- src/FDM/JSBSim/FGInitialCondition.h | 206 +++---- src/FDM/JSBSim/FGJSBBase.h | 15 +- src/FDM/JSBSim/FGLGear.cpp | 30 +- src/FDM/JSBSim/FGLGear.h | 37 +- src/FDM/JSBSim/FGMassBalance.h | 54 +- src/FDM/JSBSim/FGMatrix33.cpp | 4 +- src/FDM/JSBSim/FGMatrix33.h | 2 +- src/FDM/JSBSim/FGNozzle.cpp | 10 +- src/FDM/JSBSim/FGNozzle.h | 16 +- src/FDM/JSBSim/FGOutput.cpp | 138 +++-- src/FDM/JSBSim/FGOutput.h | 18 + src/FDM/JSBSim/FGPiston.cpp | 78 +-- src/FDM/JSBSim/FGPiston.h | 66 +-- src/FDM/JSBSim/FGPosition.cpp | 2 +- src/FDM/JSBSim/FGPosition.h | 8 +- src/FDM/JSBSim/FGPropeller.cpp | 22 +- src/FDM/JSBSim/FGPropeller.h | 34 +- src/FDM/JSBSim/FGPropulsion.cpp | 42 +- src/FDM/JSBSim/FGPropulsion.h | 18 +- src/FDM/JSBSim/FGRocket.cpp | 8 +- src/FDM/JSBSim/FGRocket.h | 16 +- src/FDM/JSBSim/FGRotation.cpp | 4 +- src/FDM/JSBSim/FGRotation.h | 36 +- src/FDM/JSBSim/FGRotor.cpp | 2 +- src/FDM/JSBSim/FGRotor.h | 2 +- src/FDM/JSBSim/FGState.cpp | 65 +-- src/FDM/JSBSim/FGState.h | 60 +-- src/FDM/JSBSim/FGTable.cpp | 20 +- src/FDM/JSBSim/FGTable.h | 14 +- src/FDM/JSBSim/FGTank.cpp | 6 +- src/FDM/JSBSim/FGTank.h | 22 +- src/FDM/JSBSim/FGThruster.h | 16 +- src/FDM/JSBSim/FGTranslation.cpp | 6 +- src/FDM/JSBSim/FGTranslation.h | 44 +- src/FDM/JSBSim/FGTrim.cpp | 36 +- src/FDM/JSBSim/FGTrim.h | 14 +- src/FDM/JSBSim/FGTrimAxis.cpp | 44 +- src/FDM/JSBSim/FGTrimAxis.h | 44 +- src/FDM/JSBSim/FGTurboJet.cpp | 2 +- src/FDM/JSBSim/FGTurboJet.h | 2 +- src/FDM/JSBSim/FGTurboProp.cpp | 2 +- src/FDM/JSBSim/FGTurboProp.h | 2 +- src/FDM/JSBSim/FGTurboShaft.cpp | 2 +- src/FDM/JSBSim/FGTurboShaft.h | 2 +- src/FDM/JSBSim/FGfdmSocket.cpp | 2 +- src/FDM/JSBSim/FGfdmSocket.h | 2 +- src/FDM/JSBSim/JSBSim.cpp | 22 +- src/FDM/JSBSim/filtersjb/FGFCSComponent.h | 6 +- src/FDM/JSBSim/filtersjb/FGFilter.cpp | 2 +- src/FDM/JSBSim/filtersjb/FGFilter.h | 32 +- src/FDM/JSBSim/filtersjb/FGFlaps.cpp | 8 +- src/FDM/JSBSim/filtersjb/FGFlaps.h | 10 +- src/FDM/JSBSim/filtersjb/FGGain.cpp | 4 +- src/FDM/JSBSim/filtersjb/FGGain.h | 4 +- src/FDM/JSBSim/filtersjb/FGSummer.h | 2 +- 86 files changed, 1436 insertions(+), 1361 deletions(-) diff --git a/src/FDM/JSBSim.cxx b/src/FDM/JSBSim.cxx index 42bc2c553..ee28d6a63 100644 --- a/src/FDM/JSBSim.cxx +++ b/src/FDM/JSBSim.cxx @@ -259,6 +259,28 @@ bool FGJSBsim::update( int multiloop ) { fdmex->Run(); } + struct FGJSBBase::Message* msg; + while (fdmex->ReadMessage()) { + msg = fdmex->ProcessMessage(); + switch (msg->type) { + case FGJSBBase::Message::eText: + cout << msg->messageId << ": " << msg->text << endl; + break; + case FGJSBBase::Message::eBool: + cout << msg->messageId << ": " << msg->text << " " << msg->bVal << endl; + break; + case FGJSBBase::Message::eInteger: + cout << msg->messageId << ": " << msg->text << " " << msg->iVal << endl; + break; + case FGJSBBase::Message::eDouble: + cout << msg->messageId << ": " << msg->text << " " << msg->dVal << endl; + break; + default: + cerr << "Unrecognized message type." << endl; + break; + } + } + for( i=0; iGetEngine(i); diff --git a/src/FDM/JSBSim/FGAerodynamics.cpp b/src/FDM/JSBSim/FGAerodynamics.cpp index ed8ac0b7c..8c20cc60f 100644 --- a/src/FDM/JSBSim/FGAerodynamics.cpp +++ b/src/FDM/JSBSim/FGAerodynamics.cpp @@ -88,14 +88,10 @@ FGAerodynamics::~FGAerodynamics() bool FGAerodynamics::Run(void) { - float alpha, beta; unsigned int axis_ctr,ctr; if (!FGModel::Run()) { - alpha = Translation->Getalpha(); - beta = Translation->Getbeta(); - vLastFs = vFs; vFs.InitMatrix(); @@ -105,7 +101,7 @@ bool FGAerodynamics::Run(void) } } - vForces = State->GetTs2b(alpha, beta)*vFs; + vForces = State->GetTs2b()*vFs; vDXYZcg(eX) = -(Aircraft->GetXYZrp(eX) - MassBalance->GetXYZcg(eX))*inchtoft; @@ -135,12 +131,12 @@ bool FGAerodynamics::Load(FGConfigFile* AC_cfg) AC_cfg->GetNextConfigLine(); - while ((token = AC_cfg->GetValue()) != "/AERODYNAMICS") { + while ((token = AC_cfg->GetValue()) != string("/AERODYNAMICS")) { if (token == "AXIS") { CoeffArray ca; axis = AC_cfg->GetValue("NAME"); AC_cfg->GetNextConfigLine(); - while ((token = AC_cfg->GetValue()) != "/AXIS") { + while ((token = AC_cfg->GetValue()) != string("/AXIS")) { if( token == "COEFFICIENT" ) { ca.push_back( new FGCoefficient(FDMExec) ); ca.back()->Load(AC_cfg); @@ -202,7 +198,7 @@ string FGAerodynamics::GetCoefficientValues(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -float FGAerodynamics::GetNlf(void) +double FGAerodynamics::GetNlf(void) { if (fabs(Position->GetGamma()) < 1.57) { return (vFs(eZ)/(MassBalance->GetWeight()*cos(Position->GetGamma()))); @@ -213,9 +209,9 @@ float FGAerodynamics::GetNlf(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -float FGAerodynamics::GetLoD(void) +double FGAerodynamics::GetLoD(void) { - float LoD; + double LoD; if (vFs(1) != 0.00) return vFs(3)/vFs(1); else return 0.00; diff --git a/src/FDM/JSBSim/FGAerodynamics.h b/src/FDM/JSBSim/FGAerodynamics.h index fc87b529d..ffacb3148 100644 --- a/src/FDM/JSBSim/FGAerodynamics.h +++ b/src/FDM/JSBSim/FGAerodynamics.h @@ -112,18 +112,18 @@ public: /** Gets the total aerodynamic force vector. @return a force vector reference. */ FGColumnVector3& GetForces(void) {return vForces;} - inline float GetForces(int n) {return vForces(n);} + inline double GetForces(int n) {return vForces(n);} /** Gets the total aerodynamic moment vector. @return a moment vector reference. */ FGColumnVector3& GetMoments(void) {return vMoments;} - inline float GetMoments(int n) {return vMoments(n);} + inline double GetMoments(int n) {return vMoments(n);} inline FGColumnVector3& GetvLastFs(void) { return vLastFs; } - inline float GetvLastFs(int axis) { return vLastFs(axis); } + inline double GetvLastFs(int axis) { return vLastFs(axis); } inline FGColumnVector3& GetvFs(void) { return vFs; } - inline float GetvFs(int axis) { return vFs(axis); } - float GetLoD(void); + inline double GetvFs(int axis) { return vFs(axis); } + double GetLoD(void); /** Gets the strings for the current set of coefficients. @return a string containing the descriptive names for all coefficients */ @@ -135,7 +135,7 @@ public: string GetCoefficientValues(void); /// Gets the Normal Load Factor - float GetNlf(void); + double GetNlf(void); private: typedef map AxisIndex; diff --git a/src/FDM/JSBSim/FGAircraft.cpp b/src/FDM/JSBSim/FGAircraft.cpp index 44dd4e75e..f57e6b33a 100644 --- a/src/FDM/JSBSim/FGAircraft.cpp +++ b/src/FDM/JSBSim/FGAircraft.cpp @@ -134,8 +134,8 @@ bool FGAircraft::Load(FGConfigFile* AC_cfg) ReadPrologue(AC_cfg); - while ((AC_cfg->GetNextConfigLine() != "EOF") && - (token = AC_cfg->GetValue()) != "/FDM_CONFIG") { + while ((AC_cfg->GetNextConfigLine() != string("EOF")) && + (token = AC_cfg->GetValue()) != string("/FDM_CONFIG")) { if (token == "METRICS") { if (debug_lvl > 0) cout << fgcyan << "\n Reading Metrics" << fgdef << endl; ReadMetrics(AC_cfg); @@ -196,16 +196,40 @@ bool FGAircraft::Run(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +void FGAircraft::ReadPrologue(FGConfigFile* AC_cfg) +{ + string token = AC_cfg->GetValue(); + string scratch; + AircraftName = AC_cfg->GetValue("NAME"); + if (debug_lvl > 0) cout << underon << "Reading Aircraft Configuration File" + << underoff << ": " << highint << AircraftName << normint << endl; + scratch = AC_cfg->GetValue("VERSION").c_str(); + + CFGVersion = AC_cfg->GetValue("VERSION"); + + if (debug_lvl > 0) + cout << " Version: " << highint << CFGVersion + << normint << endl; + if (CFGVersion != needed_cfg_version) { + cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT." + " RESULTS WILL BE UNPREDICTABLE !!" << endl; + cerr << "Current version needed is: " << needed_cfg_version << endl; + cerr << " You have version: " << CFGVersion << endl << fgdef << endl; + } +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + void FGAircraft::ReadMetrics(FGConfigFile* AC_cfg) { string token = ""; string parameter; - float EW, bixx, biyy, bizz, bixz, biyz; + double EW, bixx, biyy, bizz, bixz, biyz; FGColumnVector3 vbaseXYZcg(3); AC_cfg->GetNextConfigLine(); - while ((token = AC_cfg->GetValue()) != "/METRICS") { + while ((token = AC_cfg->GetValue()) != string("/METRICS")) { *AC_cfg >> parameter; if (parameter == "AC_WINGAREA") { *AC_cfg >> WingArea; @@ -325,100 +349,8 @@ void FGAircraft::ReadUndercarriage(FGConfigFile* AC_cfg) void FGAircraft::ReadOutput(FGConfigFile* AC_cfg) { - string token, parameter; - int OutRate = 0; - int subsystems = 0; - - token = AC_cfg->GetValue("NAME"); - Output->SetFilename(token); - token = AC_cfg->GetValue("TYPE"); - Output->SetType(token); - AC_cfg->GetNextConfigLine(); - - while ((token = AC_cfg->GetValue()) != "/OUTPUT") { - *AC_cfg >> parameter; - if (parameter == "RATE_IN_HZ") *AC_cfg >> OutRate; - if (parameter == "SIMULATION") { - *AC_cfg >> parameter; - if (parameter == "ON") subsystems += ssSimulation; - } - if (parameter == "AEROSURFACES") { - *AC_cfg >> parameter; - if (parameter == "ON") subsystems += ssAerosurfaces; - } - if (parameter == "RATES") { - *AC_cfg >> parameter; - if (parameter == "ON") subsystems += ssRates; - } - if (parameter == "VELOCITIES") { - *AC_cfg >> parameter; - if (parameter == "ON") subsystems += ssVelocities; - } - if (parameter == "FORCES") { - *AC_cfg >> parameter; - if (parameter == "ON") subsystems += ssForces; - } - if (parameter == "MOMENTS") { - *AC_cfg >> parameter; - if (parameter == "ON") subsystems += ssMoments; - } - if (parameter == "ATMOSPHERE") { - *AC_cfg >> parameter; - if (parameter == "ON") subsystems += ssAtmosphere; - } - if (parameter == "MASSPROPS") { - *AC_cfg >> parameter; - if (parameter == "ON") subsystems += ssMassProps; - } - if (parameter == "POSITION") { - *AC_cfg >> parameter; - if (parameter == "ON") subsystems += ssPosition; - } - if (parameter == "COEFFICIENTS") { - *AC_cfg >> parameter; - if (parameter == "ON") subsystems += ssCoefficients; - } - if (parameter == "GROUND_REACTIONS") { - *AC_cfg >> parameter; - if (parameter == "ON") subsystems += ssGroundReactions; - } - if (parameter == "FCS") { - *AC_cfg >> parameter; - if (parameter == "ON") subsystems += ssFCS; - } - if (parameter == "PROPULSION") { - *AC_cfg >> parameter; - if (parameter == "ON") subsystems += ssPropulsion; - } - } - - Output->SetSubsystems(subsystems); - - OutRate = OutRate>120?120:(OutRate<0?0:OutRate); - Output->SetRate( (int)(0.5 + 1.0/(State->Getdt()*OutRate)) ); -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -void FGAircraft::ReadPrologue(FGConfigFile* AC_cfg) -{ - string token = AC_cfg->GetValue(); - string scratch; - AircraftName = AC_cfg->GetValue("NAME"); - if (debug_lvl > 0) cout << underon << "Reading Aircraft Configuration File" - << underoff << ": " << highint << AircraftName << normint << endl; - scratch = AC_cfg->GetValue("VERSION").c_str(); - - CFGVersion = AC_cfg->GetValue("VERSION"); - - if (debug_lvl > 0) - cout << " Version: " << highint << CFGVersion - << normint << endl; - if (CFGVersion != needed_cfg_version) { - cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT." - " RESULTS WILL BE UNPREDICTABLE !!" << endl; - cerr << "Current version needed is: " << needed_cfg_version << endl; - cerr << " You have version: " << CFGVersion << endl << fgdef << endl; + if (!Output->Load(AC_cfg)) { + cerr << "Output not successfully loaded" << endl; } } diff --git a/src/FDM/JSBSim/FGAircraft.h b/src/FDM/JSBSim/FGAircraft.h index 710401f36..2fee85267 100644 --- a/src/FDM/JSBSim/FGAircraft.h +++ b/src/FDM/JSBSim/FGAircraft.h @@ -172,53 +172,36 @@ public: inline string GetAircraftName(void) { return AircraftName; } /// Gets the wing area - inline float GetWingArea(void) { return WingArea; } + inline double GetWingArea(void) { return WingArea; } /// Gets the wing span - inline float GetWingSpan(void) { return WingSpan; } + inline double GetWingSpan(void) { return WingSpan; } /// Gets the average wing chord - inline float Getcbar(void) { return cbar; } - inline float GetWingIncidence(void) { return WingIncidence; } - inline float GetHTailArea(void) { return HTailArea; } - inline float GetHTailArm(void) { return HTailArm; } - inline float GetVTailArea(void) { return VTailArea; } - inline float GetVTailArm(void) { return VTailArm; } - inline float Getlbarh(void) { return lbarh; } // HTailArm / cbar - inline float Getlbarv(void) { return lbarv; } // VTailArm / cbar - inline float Getvbarh(void) { return vbarh; } // H. Tail Volume - inline float Getvbarv(void) { return vbarv; } // V. Tail Volume + inline double Getcbar(void) { return cbar; } + inline double GetWingIncidence(void) { return WingIncidence; } + inline double GetHTailArea(void) { return HTailArea; } + inline double GetHTailArm(void) { return HTailArm; } + inline double GetVTailArea(void) { return VTailArea; } + inline double GetVTailArm(void) { return VTailArm; } + inline double Getlbarh(void) { return lbarh; } // HTailArm / cbar + inline double Getlbarv(void) { return lbarv; } // VTailArm / cbar + inline double Getvbarh(void) { return vbarh; } // H. Tail Volume + inline double Getvbarv(void) { return vbarv; } // V. Tail Volume inline FGColumnVector3& GetMoments(void) { return vMoments; } inline FGColumnVector3& GetForces(void) { return vForces; } inline FGColumnVector3& GetBodyAccel(void) { return vBodyAccel; } inline FGColumnVector3& GetNcg (void) { return vNcg; } inline FGColumnVector3& GetXYZrp(void) { return vXYZrp; } inline FGColumnVector3& GetXYZep(void) { return vXYZep; } - inline float GetXYZrp(int idx) { return vXYZrp(idx); } - inline float GetXYZep(int idx) { return vXYZep(idx); } - inline float GetAlphaCLMax(void) { return alphaclmax; } - inline float GetAlphaCLMin(void) { return alphaclmin; } + inline double GetXYZrp(int idx) { return vXYZrp(idx); } + inline double GetXYZep(int idx) { return vXYZep(idx); } + inline double GetAlphaCLMax(void) { return alphaclmax; } + inline double GetAlphaCLMin(void) { return alphaclmin; } - inline void SetAlphaCLMax(float tt) { alphaclmax=tt; } - inline void SetAlphaCLMin(float tt) { alphaclmin=tt; } + inline void SetAlphaCLMax(double tt) { alphaclmax=tt; } + inline void SetAlphaCLMin(double tt) { alphaclmin=tt; } inline bool GetStallWarn(void) { return impending_stall; } - /// Subsystem types for specifying which will be output in the FDM data logging - enum SubSystems { - /** Subsystem: Simulation (= 1) */ ssSimulation = 1, - /** Subsystem: Aerosurfaces (= 2) */ ssAerosurfaces = 2, - /** Subsystem: Body rates (= 4) */ ssRates = 4, - /** Subsystem: Velocities (= 8) */ ssVelocities = 8, - /** Subsystem: Forces (= 16) */ ssForces = 16, - /** Subsystem: Moments (= 32) */ ssMoments = 32, - /** Subsystem: Atmosphere (= 64) */ ssAtmosphere = 64, - /** Subsystem: Mass Properties (= 128) */ ssMassProps = 128, - /** Subsystem: Coefficients (= 256) */ ssCoefficients = 256, - /** Subsystem: Position (= 512) */ ssPosition = 512, - /** Subsystem: Ground Reactions (= 1024) */ ssGroundReactions = 1024, - /** Subsystem: FCS (= 2048) */ ssFCS = 2048, - /** Subsystem: Propulsion (= 4096) */ ssPropulsion = 4096 - } subsystems; - private: FGColumnVector3 vMoments; FGColumnVector3 vForces; @@ -229,11 +212,11 @@ private: FGColumnVector3 vBodyAccel; FGColumnVector3 vNcg; - float WingArea, WingSpan, cbar, WingIncidence; - float HTailArea, VTailArea, HTailArm, VTailArm; - float lbarh,lbarv,vbarh,vbarv; - float alphaclmax,alphaclmin; - float impending_stall; + double WingArea, WingSpan, cbar, WingIncidence; + double HTailArea, VTailArea, HTailArm, VTailArm; + double lbarh,lbarv,vbarh,vbarv; + double alphaclmax,alphaclmin; + double impending_stall; string CFGVersion; string AircraftName; diff --git a/src/FDM/JSBSim/FGAtmosphere.cpp b/src/FDM/JSBSim/FGAtmosphere.cpp index 1ce5138f7..407d5dfd4 100644 --- a/src/FDM/JSBSim/FGAtmosphere.cpp +++ b/src/FDM/JSBSim/FGAtmosphere.cpp @@ -135,19 +135,19 @@ bool FGAtmosphere::Run(void) soundspeed = sqrt(SHRatio*Reng*temperature); State->Seta(soundspeed); - } else { // skip Run() execution this time } + return false; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGAtmosphere::Calculate(float altitude) +void FGAtmosphere::Calculate(double altitude) { //see reference [1] - float slope,reftemp,refpress; + double slope,reftemp,refpress; int i=0; bool lookup = false; // cout << "Atmosphere: h=" << altitude << " rho= " << density << endl; i=lastIndex; diff --git a/src/FDM/JSBSim/FGAtmosphere.h b/src/FDM/JSBSim/FGAtmosphere.h index 431af4d45..fe0fe322b 100644 --- a/src/FDM/JSBSim/FGAtmosphere.h +++ b/src/FDM/JSBSim/FGAtmosphere.h @@ -91,32 +91,32 @@ public: bool InitModel(void); /// Returns the temperature in degrees Rankine. - inline float GetTemperature(void) {return temperature;} + inline double GetTemperature(void) {return temperature;} /** Returns the density in slugs/ft^3. This function may only be used if Run() is called first. */ - inline float GetDensity(void) {return density;} + inline double GetDensity(void) {return density;} /// Returns the pressure in psf. - inline float GetPressure(void) {return pressure;} + inline double GetPressure(void) {return pressure;} /// Returns the speed of sound in ft/sec. - inline float GetSoundSpeed(void) {return soundspeed;} + inline double GetSoundSpeed(void) {return soundspeed;} /// Returns the sea level temperature in degrees Rankine. - inline float GetTemperatureSL(void) { return SLtemperature; } + inline double GetTemperatureSL(void) { return SLtemperature; } /// Returns the sea level density in slugs/ft^3 - inline float GetDensitySL(void) { return SLdensity; } + inline double GetDensitySL(void) { return SLdensity; } /// Returns the sea level pressure in psf. - inline float GetPressureSL(void) { return SLpressure; } + inline double GetPressureSL(void) { return SLpressure; } /// Returns the sea level speed of sound in ft/sec. - inline float GetSoundSpeedSL(void) { return SLsoundspeed; } + inline double GetSoundSpeedSL(void) { return SLsoundspeed; } /// Returns the ratio of at-altitude temperature over the sea level value. - inline float GetTemperatureRatio(void) { return temperature*rSLtemperature; } + inline double GetTemperatureRatio(void) { return temperature*rSLtemperature; } /// Returns the ratio of at-altitude density over the sea level value. - inline float GetDensityRatio(void) { return density*rSLdensity; } + inline double GetDensityRatio(void) { return density*rSLdensity; } /// Returns the ratio of at-altitude pressure over the sea level value. - inline float GetPressureRatio(void) { return pressure*rSLpressure; } + inline double GetPressureRatio(void) { return pressure*rSLpressure; } /// Returns the ratio of at-altitude sound speed over the sea level value. - inline float GetSoundSpeedRatio(void) { return soundspeed*rSLsoundspeed; } + inline double GetSoundSpeedRatio(void) { return soundspeed*rSLsoundspeed; } /// Tells the simulator to use an externally calculated atmosphere model. inline void UseExternal(void) { useExternal=true; } @@ -126,21 +126,21 @@ public: bool External(void) { return useExternal; } /// Provides the external atmosphere model with an interface to set the temperature. - inline void SetExTemperature(float t) { exTemperature=t; } + inline void SetExTemperature(double t) { exTemperature=t; } /// Provides the external atmosphere model with an interface to set the density. - inline void SetExDensity(float d) { exDensity=d; } + inline void SetExDensity(double d) { exDensity=d; } /// Provides the external atmosphere model with an interface to set the pressure. - inline void SetExPressure(float p) { exPressure=p; } + inline void SetExPressure(double p) { exPressure=p; } /// Sets the wind components in NED frame. - inline void SetWindNED(float wN, float wE, float wD) { vWindNED(1)=wN; vWindNED(2)=wE; vWindNED(3)=wD;} + inline void SetWindNED(double wN, double wE, double wD) { vWindNED(1)=wN; vWindNED(2)=wE; vWindNED(3)=wD;} /// Retrieves the wind components in NED frame. inline FGColumnVector3& GetWindNED(void) { return vWindNED; } /** Retrieves the wind direction. The direction is defined as north=0 and increases counterclockwise. The wind heading is returned in radians.*/ - inline float GetWindPsi(void) { return psiw; } + inline double GetWindPsi(void) { return psiw; } private: double rho; @@ -157,7 +157,7 @@ private: FGColumnVector3 vWindNED; double psiw; - void Calculate(float altitude); + void Calculate(double altitude); void Debug(void); }; diff --git a/src/FDM/JSBSim/FGAuxiliary.cpp b/src/FDM/JSBSim/FGAuxiliary.cpp index 6c2ee284b..46f157545 100644 --- a/src/FDM/JSBSim/FGAuxiliary.cpp +++ b/src/FDM/JSBSim/FGAuxiliary.cpp @@ -86,7 +86,7 @@ FGAuxiliary::~FGAuxiliary() bool FGAuxiliary::Run() { - float A,B,D; + double A,B,D; if (!FGModel::Run()) { GetState(); @@ -164,9 +164,9 @@ bool FGAuxiliary::Run() //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -float FGAuxiliary::GetHeadWind(void) +double FGAuxiliary::GetHeadWind(void) { - float psiw,vw,psi; + double psiw,vw,psi; psiw = Atmosphere->GetWindPsi(); psi = Rotation->Getpsi(); @@ -177,9 +177,9 @@ float FGAuxiliary::GetHeadWind(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -float FGAuxiliary::GetCrossWind(void) +double FGAuxiliary::GetCrossWind(void) { - float psiw,vw,psi; + double psiw,vw,psi; psiw = Atmosphere->GetWindPsi(); psi = Rotation->Getpsi(); @@ -197,7 +197,7 @@ FGColumnVector3 FGAuxiliary::GetNpilot(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -float FGAuxiliary::GetNpilot(int idx) +double FGAuxiliary::GetNpilot(int idx) { return (vPilotAccel/Inertial->gravity())(idx); } diff --git a/src/FDM/JSBSim/FGAuxiliary.h b/src/FDM/JSBSim/FGAuxiliary.h index 23ef0d7f7..a29ae2303 100644 --- a/src/FDM/JSBSim/FGAuxiliary.h +++ b/src/FDM/JSBSim/FGAuxiliary.h @@ -85,26 +85,26 @@ public: bool Run(void); // Use FGInitialCondition to set these speeds - inline float GetVcalibratedFPS(void) { return vcas; } - inline float GetVcalibratedKTS(void) { return vcas*fpstokts; } - inline float GetVequivalentFPS(void) { return veas; } - inline float GetVequivalentKTS(void) { return veas*fpstokts; } + inline double GetVcalibratedFPS(void) { return vcas; } + inline double GetVcalibratedKTS(void) { return vcas*fpstokts; } + inline double GetVequivalentFPS(void) { return veas; } + inline double GetVequivalentKTS(void) { return veas*fpstokts; } inline FGColumnVector3& GetPilotAccel(void) { return vPilotAccel; } - inline float GetPilotAccel(int idx) { return vPilotAccel(idx); } + inline double GetPilotAccel(int idx) { return vPilotAccel(idx); } FGColumnVector3 GetNpilot(void); - float GetNpilot(int idx); + double GetNpilot(int idx); - inline float GetEarthPositionAngle(void) { return earthPosAngle; } + inline double GetEarthPositionAngle(void) { return earthPosAngle; } - float GetHeadWind(void); - float GetCrossWind(void); + double GetHeadWind(void); + double GetCrossWind(void); private: - float vcas; - float veas; - float mach; - float qbar,rhosl,rho,p,psl,pt; + double vcas; + double veas; + double mach; + double qbar,rhosl,rho,p,psl,pt; // Don't add a getter for pt! // pt above is freestream total pressure for subsonic only @@ -116,7 +116,7 @@ private: FGColumnVector3 vPilotAccel; FGColumnVector3 vToEyePt; - float earthPosAngle; + double earthPosAngle; void GetState(void); void Debug(void); diff --git a/src/FDM/JSBSim/FGCoefficient.cpp b/src/FDM/JSBSim/FGCoefficient.cpp index 142c90e70..927084f82 100644 --- a/src/FDM/JSBSim/FGCoefficient.cpp +++ b/src/FDM/JSBSim/FGCoefficient.cpp @@ -140,7 +140,7 @@ bool FGCoefficient::Load(FGConfigFile *AC_cfg) { n = multparms.find("|"); start = 0; - if(multparms != "FG_NONE") { + if (multparms != string("FG_NONE")) { while (n < end && n >= 0) { n -= start; mult = multparms.substr(start,n); @@ -179,9 +179,9 @@ bool FGCoefficient::Load(FGConfigFile *AC_cfg) { //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -float FGCoefficient::Value(float rVal, float cVal) +double FGCoefficient::Value(double rVal, double cVal) { - float Value; + double Value; unsigned int midx; SD = Value = Table->GetValue(rVal, cVal); @@ -194,9 +194,9 @@ float FGCoefficient::Value(float rVal, float cVal) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -float FGCoefficient::Value(float Val) +double FGCoefficient::Value(double Val) { - float Value; + double Value; SD = Value = Table->GetValue(Val); @@ -208,9 +208,9 @@ float FGCoefficient::Value(float Val) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -float FGCoefficient::Value(void) +double FGCoefficient::Value(void) { - float Value; + double Value; SD = Value = StaticValue; @@ -222,7 +222,7 @@ float FGCoefficient::Value(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -float FGCoefficient::TotalValue() +double FGCoefficient::TotalValue() { switch(type) { diff --git a/src/FDM/JSBSim/FGCoefficient.h b/src/FDM/JSBSim/FGCoefficient.h index b35282b79..fb574aa71 100644 --- a/src/FDM/JSBSim/FGCoefficient.h +++ b/src/FDM/JSBSim/FGCoefficient.h @@ -104,9 +104,9 @@ public: virtual bool Load(FGConfigFile* AC_cfg); typedef vector MultVec; - virtual float TotalValue(void); + virtual double TotalValue(void); virtual inline string Getname(void) {return name;} - virtual inline float GetSD(void) { return SD;} + virtual inline double GetSD(void) { return SD;} inline MultVec Getmultipliers(void) {return multipliers;} void DumpSD(void); @@ -126,15 +126,15 @@ private: string description; string name; string method; - float Value(float, float); - float Value(float); - float Value(void); - float StaticValue; + double Value(double, double); + double Value(double); + double Value(void); + double StaticValue; eParam LookupR, LookupC; MultVec multipliers; int rows, columns; Type type; - float SD; // Actual stability derivative (or other coefficient) value + double SD; // Actual stability derivative (or other coefficient) value FGTable *Table; FGFDMExec* FDMExec; diff --git a/src/FDM/JSBSim/FGColumnVector3.cpp b/src/FDM/JSBSim/FGColumnVector3.cpp index 4f4f54d31..070ea5e71 100644 --- a/src/FDM/JSBSim/FGColumnVector3.cpp +++ b/src/FDM/JSBSim/FGColumnVector3.cpp @@ -218,7 +218,7 @@ FGColumnVector3 operator*(const double scalar, const FGColumnVector3& C) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -float FGColumnVector3::Magnitude(void) +double FGColumnVector3::Magnitude(void) { double num; @@ -307,7 +307,7 @@ ostream& operator<<(ostream& os, const FGColumnVector3& col) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -FGColumnVector3& FGColumnVector3::operator<<(const float ff) +FGColumnVector3& FGColumnVector3::operator<<(const double ff) { data[rowCtr] = ff; if (++rowCtr > 3 ) diff --git a/src/FDM/JSBSim/FGColumnVector3.h b/src/FDM/JSBSim/FGColumnVector3.h index 613dde3c5..6c61b3ec6 100644 --- a/src/FDM/JSBSim/FGColumnVector3.h +++ b/src/FDM/JSBSim/FGColumnVector3.h @@ -95,12 +95,12 @@ public: void operator*=(const double scalar); void operator/=(const double scalar); - FGColumnVector3& operator<<(const float ff); + FGColumnVector3& operator<<(const double ff); inline void InitMatrix(void) { data[1]=0; data[2]=0; data[3]=0; } - inline void InitMatrix(float ff) { data[1]=ff; data[2]=ff; data[3]=ff; } + inline void InitMatrix(double ff) { data[1]=ff; data[2]=ff; data[3]=ff; } - float Magnitude(void); + double Magnitude(void); FGColumnVector3 Normalize(void); friend FGColumnVector3 operator*(const double scalar, const FGColumnVector3& A); diff --git a/src/FDM/JSBSim/FGColumnVector4.cpp b/src/FDM/JSBSim/FGColumnVector4.cpp index 24883abde..1a1b6f26c 100644 --- a/src/FDM/JSBSim/FGColumnVector4.cpp +++ b/src/FDM/JSBSim/FGColumnVector4.cpp @@ -204,7 +204,7 @@ FGColumnVector4 operator*(const double scalar, const FGColumnVector4& C) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -float FGColumnVector4::Magnitude(void) +double FGColumnVector4::Magnitude(void) { double num; @@ -299,7 +299,7 @@ ostream& operator<<(ostream& os, FGColumnVector4& col) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -FGColumnVector4& FGColumnVector4::operator<<(const float ff) +FGColumnVector4& FGColumnVector4::operator<<(const double ff) { data[rowCtr] = ff; if (++rowCtr > 4 ) diff --git a/src/FDM/JSBSim/FGColumnVector4.h b/src/FDM/JSBSim/FGColumnVector4.h index 5275f0509..1a47539d1 100644 --- a/src/FDM/JSBSim/FGColumnVector4.h +++ b/src/FDM/JSBSim/FGColumnVector4.h @@ -95,12 +95,12 @@ public: inline double operator()(int m) const { return data[m]; } inline double& operator()(int m) { return data[m]; } - FGColumnVector4& operator<<(const float ff); + FGColumnVector4& operator<<(const double ff); inline void InitMatrix(void) { data[1]=0; data[2]=0; data[3]=0; } - inline void InitMatrix(float ff) { data[1]=ff; data[2]=ff; data[3]=ff; } + inline void InitMatrix(double ff) { data[1]=ff; data[2]=ff; data[3]=ff; } - float Magnitude(void); + double Magnitude(void); FGColumnVector4 Normalize(void); friend FGColumnVector4 operator*(const double scalar, const FGColumnVector4& A); diff --git a/src/FDM/JSBSim/FGConfigFile.cpp b/src/FDM/JSBSim/FGConfigFile.cpp index 42fbe6a32..b9d5066f8 100644 --- a/src/FDM/JSBSim/FGConfigFile.cpp +++ b/src/FDM/JSBSim/FGConfigFile.cpp @@ -1,303 +1,322 @@ -/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - Header: FGConfigFile.h - Author: Jon Berndt - Date started: 03/29/00 - Purpose: Config file read-in class - Called by: FGAircraft - -FUNCTIONAL DESCRIPTION --------------------------------------------------------------------------------- - -HISTORY --------------------------------------------------------------------------------- -03/16/2000 JSB Created - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -INCLUDES -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ - -#include "FGConfigFile.h" -#include -#include - -static const char *IdSrc = "$Id$"; -static const char *IdHdr = ID_CONFIGFILE; - -/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -CLASS IMPLEMENTATION -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ - -FGConfigFile::FGConfigFile(string cfgFileName) -{ -#if defined ( sgi ) && !defined( __GNUC__ ) - cfgfile.open(cfgFileName.c_str(), ios::in ); -#else - cfgfile.open(cfgFileName.c_str(), ios::in | ios::binary ); -#endif - CommentsOn = false; - CurrentIndex = 0; - Opened = true; -#if defined ( sgi ) && !defined( __GNUC__ ) - if (!cfgfile.fail() && !cfgfile.eof()) GetNextConfigLine(); -#else - if (cfgfile.is_open()) GetNextConfigLine(); -#endif - else Opened = false; - - if (debug_lvl & 2) cout << "Instantiated: FGConfigFile" << endl; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -FGConfigFile::~FGConfigFile() -{ - cfgfile.close(); - if (debug_lvl & 2) cout << "Destroyed: FGConfigFile" << endl; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -string FGConfigFile::GetNextConfigLine(void) -{ - int deblank; - - do { - CurrentLine = GetLine(); - if (CurrentLine.find("") != CurrentLine.npos) { - CommentsOn = false; - - if (CurrentLine.find("-->") != CurrentLine.npos) - CurrentLine.erase(CurrentLine.find("-->"),4); - - while((deblank = CurrentLine.find(" ")) != CurrentLine.npos) CurrentLine.erase(deblank,1); - if (CurrentLine.size() <= 2) CurrentLine = ""; - - CommentString += CurrentLine; - GetNextConfigLine(); - } - - if (CommentsOn) CommentString += CurrentLine + "\r\n"; - - } while (CommentsOn); - - if (CurrentLine.length() == 0) GetNextConfigLine(); - CurrentIndex = 0; - return CurrentLine; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -string FGConfigFile::GetCommentString(void) -{ - return CommentString; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -string FGConfigFile::GetValue(string val) -{ - unsigned int pos, p1, p2, ptest; - - if (val == "") { // this call is to return the tag value - pos = CurrentLine.find("<"); - if (pos != CurrentLine.npos) { // beginning brace found "<" - p1 = CurrentLine.find_first_not_of(" ",pos+1); - if (p1 != CurrentLine.npos) { // found first character of tag - p2 = CurrentLine.find_first_of(" >",p1+1); - if (p2 == CurrentLine.npos) p2 = p1+1; - return CurrentLine.substr(p1,p2-p1); - } - } else { // beginning brace "<" not found; this is a regular data line - pos = CurrentLine.find_first_not_of(" "); - if (pos != CurrentLine.npos) { // first character in line found - p2 = CurrentLine.find_first_of(" ",pos+1); - if (p2 != CurrentLine.npos) { - return CurrentLine.substr(pos,p2-pos); - } else { - return CurrentLine.substr(pos,CurrentLine.length()-pos); - } - } - } - } else { // return a value for a specific tag - pos = CurrentLine.find(val); - if (pos != CurrentLine.npos) { - pos = CurrentLine.find("=",pos); - if (pos != CurrentLine.npos) { - ptest = CurrentLine.find_first_not_of(" ",pos+1); - if (ptest != CurrentLine.npos) { - p1 = ptest + 1; - if (CurrentLine[ptest] == '"') { // quoted - p2 = CurrentLine.find_first_of("\"",p1); - } else { // not quoted - p2 = CurrentLine.find_first_of(" ",p1); - } - if (p2 != CurrentLine.npos) { - return CurrentLine.substr(p1,p2-p1); - } - } - } else { // "=" not found - pos = CurrentLine.find(val); - pos = CurrentLine.find_first_of(" ",pos+1); - ptest = CurrentLine.find_first_not_of(" ",pos+1); - if (ptest != CurrentLine.npos) { - if (CurrentLine[ptest] == '"') { // quoted - p1 = ptest + 1; - p2 = CurrentLine.find_first_of("\"",p1); - } else { // not quoted - p1 = ptest; - p2 = CurrentLine.find_first_of(" ",p1); - } - if (p2 != CurrentLine.npos) { - return CurrentLine.substr(p1,p2-p1); - } else { - p2 = CurrentLine.length(); - return CurrentLine.substr(p1,p2-p1); - } - } - } - } - } - - return string(""); -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -string FGConfigFile::GetValue(void) -{ - return GetValue(""); -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -string FGConfigFile::GetLine(void) -{ - string scratch = ""; - int test; - - while ((test = cfgfile.get()) != EOF) { - if (test >= 0x20) { - scratch += (char)test; - } else { - if ((test = cfgfile.get()) != EOF) { -#if defined ( sgi ) && !defined( __GNUC__ ) - if (test >= 0x20) cfgfile.putback(test); -#else - if (test >= 0x20) cfgfile.unget(); -#endif - break; - } - } - } - if (cfgfile.eof()) return string("EOF"); - return scratch; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -FGConfigFile& FGConfigFile::operator>>(double& val) -{ - unsigned int pos, end; - - pos = CurrentLine.find_first_not_of(", ",CurrentIndex); - if (pos == CurrentLine.npos) pos = CurrentLine.length(); - end = CurrentLine.find_first_of(", ",pos+1); - if (end == CurrentLine.npos) end = CurrentLine.length(); - string str = CurrentLine.substr(pos, end - pos); - val = strtod(str.c_str(),NULL); - CurrentIndex = end+1; - if (CurrentIndex >= CurrentLine.length()) GetNextConfigLine(); - return *this; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -FGConfigFile& FGConfigFile::operator>>(float& val) -{ - unsigned int pos, end; - - pos = CurrentLine.find_first_not_of(", ",CurrentIndex); - if (pos == CurrentLine.npos) pos = CurrentLine.length(); - end = CurrentLine.find_first_of(", ",pos+1); - if (end == CurrentLine.npos) end = CurrentLine.length(); - string str = CurrentLine.substr(pos, end - pos); - val = strtod(str.c_str(),NULL); - CurrentIndex = end+1; - if (CurrentIndex >= CurrentLine.length()) GetNextConfigLine(); - return *this; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -FGConfigFile& FGConfigFile::operator>>(int& val) -{ - unsigned int pos, end; - - pos = CurrentLine.find_first_not_of(", ",CurrentIndex); - if (pos == CurrentLine.npos) pos = CurrentLine.length(); - end = CurrentLine.find_first_of(", ",pos+1); - if (end == CurrentLine.npos) end = CurrentLine.length(); - string str = CurrentLine.substr(pos, end - pos); - val = atoi(str.c_str()); - CurrentIndex = end+1; - if (CurrentIndex >= CurrentLine.length()) GetNextConfigLine(); - return *this; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -FGConfigFile& FGConfigFile::operator>>(eParam& val) -{ - unsigned int pos, end; - - pos = CurrentLine.find_first_not_of(", ",CurrentIndex); - if (pos == CurrentLine.npos) pos = CurrentLine.length(); - end = CurrentLine.find_first_of(", ",pos+1); - if (end == CurrentLine.npos) end = CurrentLine.length(); - string str = CurrentLine.substr(pos, end - pos); - val = (eParam)atoi(str.c_str()); - CurrentIndex = end+1; - if (CurrentIndex >= CurrentLine.length()) GetNextConfigLine(); - return *this; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -FGConfigFile& FGConfigFile::operator>>(string& str) -{ - unsigned int pos, end; - - pos = CurrentLine.find_first_not_of(", ",CurrentIndex); - if (pos == CurrentLine.npos) pos = CurrentLine.length(); - end = CurrentLine.find_first_of(", ",pos+1); - if (end == CurrentLine.npos) end = CurrentLine.length(); - str = CurrentLine.substr(pos, end - pos); - CurrentIndex = end+1; - if (CurrentIndex >= CurrentLine.length()) GetNextConfigLine(); - return *this; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -void FGConfigFile::ResetLineIndexToZero(void) -{ - CurrentIndex = 0; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -void FGConfigFile::Debug(void) -{ - //TODO: Add your source code here -} - +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + Header: FGConfigFile.h + Author: Jon Berndt + Date started: 03/29/00 + Purpose: Config file read-in class + Called by: FGAircraft + +FUNCTIONAL DESCRIPTION +-------------------------------------------------------------------------------- + +HISTORY +-------------------------------------------------------------------------------- +03/16/2000 JSB Created + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +INCLUDES +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + +#include "FGConfigFile.h" +#include +#include + +static const char *IdSrc = "$Id$"; +static const char *IdHdr = ID_CONFIGFILE; + +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +CLASS IMPLEMENTATION +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + +FGConfigFile::FGConfigFile(string cfgFileName) +{ +#if defined ( sgi ) && !defined( __GNUC__ ) + cfgfile.open(cfgFileName.c_str(), ios::in ); +#else + cfgfile.open(cfgFileName.c_str(), ios::in | ios::binary ); +#endif + CommentsOn = false; + CurrentIndex = 0; + Opened = true; +#if defined ( sgi ) && !defined( __GNUC__ ) + if (!cfgfile.fail() && !cfgfile.eof()) GetNextConfigLine(); +#else + if (cfgfile.is_open()) GetNextConfigLine(); +#endif + else Opened = false; + + if (debug_lvl & 2) cout << "Instantiated: FGConfigFile" << endl; +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +FGConfigFile::~FGConfigFile() +{ + cfgfile.close(); + if (debug_lvl & 2) cout << "Destroyed: FGConfigFile" << endl; +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +string FGConfigFile::GetNextConfigLine(void) +{ + int deblank, not_found = string::npos; + int comment_starts_at; + int comment_ends_at; + int comment_length; + int line_length; + bool start_comment, end_comment; + string CommentStringTemp; + + do { + CurrentLine = GetLine(); + line_length = CurrentLine.length(); + comment_starts_at = CurrentLine.find(""); + + if (comment_ends_at >= 0) end_comment = true; + else end_comment = false; + + if (!start_comment && !end_comment) { // command comment + if (CommentsOn) CommentStringTemp = CurrentLine; + CommentString += CommentStringTemp + "\r\n"; + } else if (start_comment && comment_ends_at > comment_starts_at) { // + CommentsOn = false; + comment_length = comment_ends_at + 2 - comment_starts_at + 1; + LineComment = CurrentLine.substr(comment_starts_at+4, comment_length-4-3); + CurrentLine.erase(comment_starts_at, comment_length); + } else if ( start_comment && !end_comment) { // + CommentsOn = false; + comment_length = comment_ends_at + 2 + 1; + CommentStringTemp = CurrentLine.substr(0, comment_length-4); + CommentString += CommentStringTemp + "\r\n"; + CurrentLine.erase(0, comment_length); + } else if (start_comment && comment_ends_at < comment_starts_at) { // --> command