]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/models/FGOutput.cpp
Removed useless divisions - As a side effect, it removes the risk of divisions by...
[flightgear.git] / src / FDM / JSBSim / models / FGOutput.cpp
index c074d98138b7cc138353bad2a6e2b8233beaa238..3131cd6c0d7506bd0d2a9288becb32d8b9a3ce8f 100644 (file)
@@ -74,7 +74,7 @@ using namespace std;
 
 namespace JSBSim {
 
-static const char *IdSrc = "$Id: FGOutput.cpp,v 1.49 2010/10/15 11:30:29 jberndt Exp $";
+static const char *IdSrc = "$Id: FGOutput.cpp,v 1.55 2011/05/20 03:18:36 jberndt Exp $";
 static const char *IdHdr = ID_OUTPUT;
 
 // (stolen from FGFS native_fdm.cxx)
@@ -157,8 +157,6 @@ FGOutput::~FGOutput()
 
 bool FGOutput::InitModel(void)
 {
-  if (!FGModel::InitModel()) return false;
-
   if (Filename.size() > 0 && StartNewFile) {
     ostringstream buf;
     string::size_type dot = BaseFilename.find_last_of('.');
@@ -178,25 +176,13 @@ bool FGOutput::InitModel(void)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-bool FGOutput::Run(void)
+bool FGOutput::Run(bool Holding)
 {
-  if (FGModel::Run()) return true;
+  if (FGModel::Run(Holding)) return true;
 
-  if (enabled && !FDMExec->IntegrationSuspended()&& !FDMExec->Holding()) {
+  if (enabled && !FDMExec->IntegrationSuspended() && !Holding) {
     RunPreFunctions();
-    if (Type == otSocket) {
-      SocketOutput();
-    } else if (Type == otFlightGear) {
-      FlightGearSocketOutput();
-    } else if (Type == otCSV || Type == otTab) {
-      DelimitedOutput(Filename);
-    } else if (Type == otTerminal) {
-      // Not done yet
-    } else if (Type == otNone) {
-      // Do nothing
-    } else {
-      // Not a valid type of output
-    }
+    Print();
     RunPostFunctions();
   }
   return false;
@@ -204,6 +190,25 @@ bool FGOutput::Run(void)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
+void FGOutput::Print(void)
+{
+  if (Type == otSocket) {
+    SocketOutput();
+  } else if (Type == otFlightGear) {
+    FlightGearSocketOutput();
+  } else if (Type == otCSV || Type == otTab) {
+    DelimitedOutput(Filename);
+  } else if (Type == otTerminal) {
+    // Not done yet
+  } else if (Type == otNone) {
+    // Do nothing
+  } else {
+    // Not a valid type of output
+  }
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
 void FGOutput::SetType(const string& type)
 {
   if (type == "CSV") {
@@ -237,6 +242,19 @@ void FGOutput::SetProtocol(const string& protocol)
 
 void FGOutput::DelimitedOutput(const string& fname)
 {
+  const FGAerodynamics* Aerodynamics = FDMExec->GetAerodynamics();
+  const FGAuxiliary* Auxiliary = FDMExec->GetAuxiliary();
+  const FGAircraft* Aircraft = FDMExec->GetAircraft();
+  const FGAtmosphere* Atmosphere = FDMExec->GetAtmosphere();
+  const FGPropulsion* Propulsion = FDMExec->GetPropulsion();
+  const FGMassBalance* MassBalance = FDMExec->GetMassBalance();
+  const FGPropagate* Propagate = FDMExec->GetPropagate();
+  const FGFCS* FCS = FDMExec->GetFCS();
+  const FGInertial* Inertial = FDMExec->GetInertial();
+  const FGGroundReactions* GroundReactions = FDMExec->GetGroundReactions();
+  const FGExternalReactions* ExternalReactions = FDMExec->GetExternalReactions();
+  const FGBuoyantForces* BuoyantForces = FDMExec->GetBuoyantForces();
+
   streambuf* buffer;
   string scratch = "";
 
@@ -283,6 +301,7 @@ void FGOutput::DelimitedOutput(const string& fname)
       outstream << "UBody" + delimeter + "VBody" + delimeter + "WBody" + delimeter;
       outstream << "Aero V_{X Body} (ft/s)" + delimeter + "Aero V_{Y Body} (ft/s)" + delimeter + "Aero V_{Z Body} (ft/s)" + delimeter;
       outstream << "V_{X_{inertial}} (ft/s)" + delimeter + "V_{Y_{inertial}} (ft/s)" + delimeter + "V_{Z_{inertial}} (ft/s)" + delimeter;
+      outstream << "V_{X_{ecef}} (ft/s)" + delimeter + "V_{Y_{ecef}} (ft/s)" + delimeter + "V_{Z_{ecef}} (ft/s)" + delimeter;
       outstream << "V_{North} (ft/s)" + delimeter + "V_{East} (ft/s)" + delimeter + "V_{Down} (ft/s)";
     }
     if (SubSystems & ssForces) {
@@ -346,8 +365,8 @@ void FGOutput::DelimitedOutput(const string& fname)
       outstream << "Distance AGL (ft)" + delimeter;
       outstream << "Terrain Elevation (ft)";
     }
-    if (SubSystems & ssCoefficients) {
-      scratch = Aerodynamics->GetCoefficientStrings(delimeter);
+    if (SubSystems & ssAeroFunctions) {
+      scratch = Aerodynamics->GetAeroFunctionStrings(delimeter);
       if (scratch.length() != 0) outstream << delimeter << scratch;
     }
     if (SubSystems & ssFCS) {
@@ -402,6 +421,7 @@ void FGOutput::DelimitedOutput(const string& fname)
     outstream << setprecision(12) << Propagate->GetUVW().Dump(delimeter) << delimeter;
     outstream << Auxiliary->GetAeroUVW().Dump(delimeter) << delimeter;
     outstream << Propagate->GetInertialVelocity().Dump(delimeter) << delimeter;
+    outstream << Propagate->GetECEFVelocity().Dump(delimeter) << delimeter;
     outstream << Propagate->GetVel().Dump(delimeter);
     outstream.precision(10);
   }
@@ -462,8 +482,8 @@ void FGOutput::DelimitedOutput(const string& fname)
     outstream << Propagate->GetTerrainElevation();
     outstream.precision(10);
   }
-  if (SubSystems & ssCoefficients) {
-    scratch = Aerodynamics->GetCoefficientValues(delimeter);
+  if (SubSystems & ssAeroFunctions) {
+    scratch = Aerodynamics->GetAeroFunctionValues(delimeter);
     if (scratch.length() != 0) outstream << delimeter << scratch;
   }
   if (SubSystems & ssFCS) {
@@ -493,6 +513,13 @@ void FGOutput::DelimitedOutput(const string& fname)
 
 void FGOutput::SocketDataFill(FGNetFDM* net)
 {
+  const FGAerodynamics* Aerodynamics = FDMExec->GetAerodynamics();
+  const FGAuxiliary* Auxiliary = FDMExec->GetAuxiliary();
+  const FGPropulsion* Propulsion = FDMExec->GetPropulsion();
+  const FGMassBalance* MassBalance = FDMExec->GetMassBalance();
+  const FGPropagate* Propagate = FDMExec->GetPropagate();
+  const FGFCS* FCS = FDMExec->GetFCS();
+  const FGGroundReactions* GroundReactions = FDMExec->GetGroundReactions();
     unsigned int i;
 
     // Version
@@ -701,6 +728,16 @@ void FGOutput::FlightGearSocketOutput(void)
 
 void FGOutput::SocketOutput(void)
 {
+  const FGAerodynamics* Aerodynamics = FDMExec->GetAerodynamics();
+  const FGAuxiliary* Auxiliary = FDMExec->GetAuxiliary();
+  const FGPropulsion* Propulsion = FDMExec->GetPropulsion();
+  const FGMassBalance* MassBalance = FDMExec->GetMassBalance();
+  const FGPropagate* Propagate = FDMExec->GetPropagate();
+  const FGFCS* FCS = FDMExec->GetFCS();
+  const FGAtmosphere* Atmosphere = FDMExec->GetAtmosphere();
+  const FGAircraft* Aircraft = FDMExec->GetAircraft();
+  const FGGroundReactions* GroundReactions = FDMExec->GetGroundReactions();
+
   string asciiData, scratch;
 
   if (socket == NULL) return;
@@ -796,8 +833,8 @@ void FGOutput::SocketOutput(void)
         socket->Append("Latitude (deg)");
         socket->Append("Longitude (deg)");
     }
-    if (SubSystems & ssCoefficients) {
-      scratch = Aerodynamics->GetCoefficientStrings(",");
+    if (SubSystems & ssAeroFunctions) {
+      scratch = Aerodynamics->GetAeroFunctionStrings(",");
       if (scratch.length() != 0) socket->Append(scratch);
     }
     if (SubSystems & ssFCS) {
@@ -902,8 +939,8 @@ void FGOutput::SocketOutput(void)
     socket->Append(Propagate->GetLocation().GetLatitudeDeg());
     socket->Append(Propagate->GetLocation().GetLongitudeDeg());
   }
-  if (SubSystems & ssCoefficients) {
-    scratch = Aerodynamics->GetCoefficientValues(",");
+  if (SubSystems & ssAeroFunctions) {
+    scratch = Aerodynamics->GetAeroFunctionValues(",");
     if (scratch.length() != 0) socket->Append(scratch);
   }
   if (SubSystems & ssFCS) {
@@ -944,7 +981,7 @@ bool FGOutput::Load(Element* element)
 {
   string parameter="";
   string name="";
-  int OutRate = 0;
+  double OutRate = 0.0;
   unsigned int port;
   Element *property_element;
 
@@ -973,7 +1010,7 @@ bool FGOutput::Load(Element* element)
     BaseFilename = Filename = name;
   }
   if (!document->GetAttributeValue("rate").empty()) {
-    OutRate = (int)document->GetAttributeValueAsNumber("rate");
+    OutRate = document->GetAttributeValueAsNumber("rate");
   } else {
     OutRate = 1;
   }
@@ -997,7 +1034,7 @@ bool FGOutput::Load(Element* element)
   if (document->FindElementValue("position") == string("ON"))
     SubSystems += ssPropagate;
   if (document->FindElementValue("coefficients") == string("ON"))
-    SubSystems += ssCoefficients;
+    SubSystems += ssAeroFunctions;
   if (document->FindElementValue("ground_reactions") == string("ON"))
     SubSystems += ssGroundReactions;
   if (document->FindElementValue("fcs") == string("ON"))
@@ -1028,7 +1065,7 @@ bool FGOutput::Load(Element* element)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-void FGOutput::SetRate(int rtHz)
+void FGOutput::SetRate(double rtHz)
 {
   rtHz = rtHz>1000?1000:(rtHz<0?0:rtHz);
   if (rtHz > 0) {
@@ -1098,7 +1135,7 @@ void FGOutput::Debug(int from)
       if (SubSystems & ssMoments)         cout << "    Moments parameters logged" << endl;
       if (SubSystems & ssAtmosphere)      cout << "    Atmosphere parameters logged" << endl;
       if (SubSystems & ssMassProps)       cout << "    Mass parameters logged" << endl;
-      if (SubSystems & ssCoefficients)    cout << "    Coefficient parameters logged" << endl;
+      if (SubSystems & ssAeroFunctions)    cout << "    Coefficient parameters logged" << endl;
       if (SubSystems & ssPropagate)       cout << "    Propagate parameters logged" << endl;
       if (SubSystems & ssGroundReactions) cout << "    Ground parameters logged" << endl;
       if (SubSystems & ssFCS)             cout << "    FCS parameters logged" << endl;