]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGOutput.cpp
Andreas Gaeb: fix #222 (JSBSIm reset problems)
[flightgear.git] / src / FDM / JSBSim / models / FGOutput.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGOutput.cpp
4  Author:       Jon Berndt
5  Date started: 12/02/98
6  Purpose:      Manage output of sim parameters to file or stdout
7  Called by:    FGSimExec
8
9  ------------- Copyright (C) 1999  Jon S. Berndt (jon@jsbsim.org) -------------
10
11  This program is free software; you can redistribute it and/or modify it under
12  the terms of the GNU Lesser General Public License as published by the Free Software
13  Foundation; either version 2 of the License, or (at your option) any later
14  version.
15
16  This program is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
19  details.
20
21  You should have received a copy of the GNU Lesser General Public License along with
22  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23  Place - Suite 330, Boston, MA  02111-1307, USA.
24
25  Further information about the GNU Lesser General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This is the place where you create output routines to dump data for perusal
31 later.
32
33 HISTORY
34 --------------------------------------------------------------------------------
35 12/02/98   JSB   Created
36 11/09/07   HDW   Added FlightGear Socket Interface
37
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 INCLUDES
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41
42 #include "FGOutput.h"
43 #include "FGFDMExec.h"
44 #include "FGAtmosphere.h"
45 #include "FGFCS.h"
46 #include "FGAerodynamics.h"
47 #include "FGGroundReactions.h"
48 #include "FGExternalReactions.h"
49 #include "FGBuoyantForces.h"
50 #include "FGAircraft.h"
51 #include "FGMassBalance.h"
52 #include "FGPropagate.h"
53 #include "FGAuxiliary.h"
54 #include "FGInertial.h"
55 #include "FGPropulsion.h"
56 #include "models/propulsion/FGEngine.h"
57 #include "models/propulsion/FGTank.h"
58 #include "models/propulsion/FGPiston.h"
59 #include <sstream>
60 #include <iomanip>
61 #include <cstring>
62 #include <cstdlib>
63
64 #if defined(WIN32) && !defined(__CYGWIN__)
65 #  include <windows.h>
66 #else
67 #  include <netinet/in.h>       // htonl() ntohl()
68 #endif
69
70 static const int endianTest = 1;
71 #define isLittleEndian (*((char *) &endianTest ) != 0)
72
73 using namespace std;
74
75 namespace JSBSim {
76
77 static const char *IdSrc = "$Id: FGOutput.cpp,v 1.50 2010/11/18 12:38:06 jberndt Exp $";
78 static const char *IdHdr = ID_OUTPUT;
79
80 // (stolen from FGFS native_fdm.cxx)
81 // The function htond is defined this way due to the way some
82 // processors and OSes treat floating point values.  Some will raise
83 // an exception whenever a "bad" floating point value is loaded into a
84 // floating point register.  Solaris is notorious for this, but then
85 // so is LynxOS on the PowerPC.  By translating the data in place,
86 // there is no need to load a FP register with the "corruped" floating
87 // point value.  By doing the BIG_ENDIAN test, I can optimize the
88 // routine for big-endian processors so it can be as efficient as
89 // possible
90 static void htond (double &x)
91 {
92     if ( isLittleEndian ) {
93         int    *Double_Overlay;
94         int     Holding_Buffer;
95
96         Double_Overlay = (int *) &x;
97         Holding_Buffer = Double_Overlay [0];
98
99         Double_Overlay [0] = htonl (Double_Overlay [1]);
100         Double_Overlay [1] = htonl (Holding_Buffer);
101     } else {
102         return;
103     }
104 }
105
106 // Float version
107 static void htonf (float &x)
108 {
109     if ( isLittleEndian ) {
110         int    *Float_Overlay;
111         int     Holding_Buffer;
112
113         Float_Overlay = (int *) &x;
114         Holding_Buffer = Float_Overlay [0];
115
116         Float_Overlay [0] = htonl (Holding_Buffer);
117     } else {
118         return;
119     }
120 }
121
122
123 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 CLASS IMPLEMENTATION
125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
126
127 FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
128 {
129   Name = "FGOutput";
130   sFirstPass = dFirstPass = true;
131   socket = 0;
132   runID_postfix = 0;
133   Type = otNone;
134   SubSystems = 0;
135   enabled = true;
136   StartNewFile = false;
137   delimeter = ", ";
138   BaseFilename = Filename = "";
139   DirectivesFile = "";
140   output_file_name = "";
141
142   memset(&fgSockBuf, 0x00, sizeof(fgSockBuf));
143
144   Debug(0);
145 }
146
147 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148
149 FGOutput::~FGOutput()
150 {
151   delete socket;
152   OutputProperties.clear();
153   Debug(1);
154 }
155
156 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157
158 bool FGOutput::InitModel(void)
159 {
160   if (!FGModel::InitModel()) return false;
161
162   if (Filename.size() > 0 && StartNewFile) {
163     ostringstream buf;
164     string::size_type dot = BaseFilename.find_last_of('.');
165     if (dot != string::npos) {
166       buf << BaseFilename.substr(0, dot) << '_' << runID_postfix++ << BaseFilename.substr(dot);
167     } else {
168       buf << BaseFilename << '_' << runID_postfix++;
169     }
170     Filename = buf.str();
171     datafile.close();
172     StartNewFile = false;
173     dFirstPass = true;
174   }
175
176   return true;
177 }
178
179 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180
181 bool FGOutput::Run(void)
182 {
183   if (FGModel::Run()) return true;
184
185   if (enabled && !FDMExec->IntegrationSuspended()&& !FDMExec->Holding()) {
186     RunPreFunctions();
187     if (Type == otSocket) {
188       SocketOutput();
189     } else if (Type == otFlightGear) {
190       FlightGearSocketOutput();
191     } else if (Type == otCSV || Type == otTab) {
192       DelimitedOutput(Filename);
193     } else if (Type == otTerminal) {
194       // Not done yet
195     } else if (Type == otNone) {
196       // Do nothing
197     } else {
198       // Not a valid type of output
199     }
200     RunPostFunctions();
201   }
202   return false;
203 }
204
205 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206
207 void FGOutput::SetType(const string& type)
208 {
209   if (type == "CSV") {
210     Type = otCSV;
211     delimeter = ", ";
212   } else if (type == "TABULAR") {
213     Type = otTab;
214     delimeter = "\t";
215   } else if (type == "SOCKET") {
216     Type = otSocket;
217   } else if (type == "FLIGHTGEAR") {
218     Type = otFlightGear;
219   } else if (type == "TERMINAL") {
220     Type = otTerminal;
221   } else if (type != string("NONE")) {
222     Type = otUnknown;
223     cerr << "Unknown type of output specified in config file" << endl;
224   }
225 }
226
227 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228
229 void FGOutput::SetProtocol(const string& protocol)
230 {
231   if (protocol == "UDP") Protocol = FGfdmSocket::ptUDP;
232   else if (protocol == "TCP") Protocol = FGfdmSocket::ptTCP;
233   else Protocol = FGfdmSocket::ptTCP; // Default to TCP
234 }
235
236 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237
238 void FGOutput::DelimitedOutput(const string& fname)
239 {
240   const FGAerodynamics* Aerodynamics = FDMExec->GetAerodynamics();
241   const FGAuxiliary* Auxiliary = FDMExec->GetAuxiliary();
242   const FGAircraft* Aircraft = FDMExec->GetAircraft();
243   const FGAtmosphere* Atmosphere = FDMExec->GetAtmosphere();
244   const FGPropulsion* Propulsion = FDMExec->GetPropulsion();
245   const FGMassBalance* MassBalance = FDMExec->GetMassBalance();
246   const FGPropagate* Propagate = FDMExec->GetPropagate();
247   const FGFCS* FCS = FDMExec->GetFCS();
248   const FGInertial* Inertial = FDMExec->GetInertial();
249   const FGGroundReactions* GroundReactions = FDMExec->GetGroundReactions();
250   const FGExternalReactions* ExternalReactions = FDMExec->GetExternalReactions();
251   const FGBuoyantForces* BuoyantForces = FDMExec->GetBuoyantForces();
252
253   streambuf* buffer;
254   string scratch = "";
255
256   if (fname == "COUT" || fname == "cout") {
257     buffer = cout.rdbuf();
258   } else {
259     if (!datafile.is_open()) datafile.open(fname.c_str());
260     buffer = datafile.rdbuf();
261   }
262
263   ostream outstream(buffer);
264
265   outstream.precision(10);
266
267   if (dFirstPass) {
268     outstream << "Time";
269     if (SubSystems & ssSimulation) {
270       // Nothing here, yet
271     }
272     if (SubSystems & ssAerosurfaces) {
273       outstream << delimeter;
274       outstream << "Aileron Command (norm)" + delimeter;
275       outstream << "Elevator Command (norm)" + delimeter;
276       outstream << "Rudder Command (norm)" + delimeter;
277       outstream << "Flap Command (norm)" + delimeter;
278       outstream << "Left Aileron Position (deg)" + delimeter;
279       outstream << "Right Aileron Position (deg)" + delimeter;
280       outstream << "Elevator Position (deg)" + delimeter;
281       outstream << "Rudder Position (deg)" + delimeter;
282       outstream << "Flap Position (deg)";
283     }
284     if (SubSystems & ssRates) {
285       outstream << delimeter;
286       outstream << "P (deg/s)" + delimeter + "Q (deg/s)" + delimeter + "R (deg/s)" + delimeter;
287       outstream << "P dot (deg/s^2)" + delimeter + "Q dot (deg/s^2)" + delimeter + "R dot (deg/s^2)" + delimeter;
288       outstream << "P_{inertial} (deg/s)" + delimeter + "Q_{inertial} (deg/s)" + delimeter + "R_{inertial} (deg/s)";
289     }
290     if (SubSystems & ssVelocities) {
291       outstream << delimeter;
292       outstream << "q bar (psf)" + delimeter;
293       outstream << "Reynolds Number" + delimeter;
294       outstream << "V_{Total} (ft/s)" + delimeter;
295       outstream << "V_{Inertial} (ft/s)" + delimeter;
296       outstream << "UBody" + delimeter + "VBody" + delimeter + "WBody" + delimeter;
297       outstream << "Aero V_{X Body} (ft/s)" + delimeter + "Aero V_{Y Body} (ft/s)" + delimeter + "Aero V_{Z Body} (ft/s)" + delimeter;
298       outstream << "V_{X_{inertial}} (ft/s)" + delimeter + "V_{Y_{inertial}} (ft/s)" + delimeter + "V_{Z_{inertial}} (ft/s)" + delimeter;
299       outstream << "V_{North} (ft/s)" + delimeter + "V_{East} (ft/s)" + delimeter + "V_{Down} (ft/s)";
300     }
301     if (SubSystems & ssForces) {
302       outstream << delimeter;
303       outstream << "F_{Drag} (lbs)" + delimeter + "F_{Side} (lbs)" + delimeter + "F_{Lift} (lbs)" + delimeter;
304       outstream << "L/D" + delimeter;
305       outstream << "F_{Aero x} (lbs)" + delimeter + "F_{Aero y} (lbs)" + delimeter + "F_{Aero z} (lbs)" + delimeter;
306       outstream << "F_{Prop x} (lbs)" + delimeter + "F_{Prop y} (lbs)" + delimeter + "F_{Prop z} (lbs)" + delimeter;
307       outstream << "F_{Gear x} (lbs)" + delimeter + "F_{Gear y} (lbs)" + delimeter + "F_{Gear z} (lbs)" + delimeter;
308       outstream << "F_{Ext x} (lbs)" + delimeter + "F_{Ext y} (lbs)" + delimeter + "F_{Ext z} (lbs)" + delimeter;
309       outstream << "F_{Buoyant x} (lbs)" + delimeter + "F_{Buoyant y} (lbs)" + delimeter + "F_{Buoyant z} (lbs)" + delimeter;
310       outstream << "F_{Total x} (lbs)" + delimeter + "F_{Total y} (lbs)" + delimeter + "F_{Total z} (lbs)";
311     }
312     if (SubSystems & ssMoments) {
313       outstream << delimeter;
314       outstream << "L_{Aero} (ft-lbs)" + delimeter + "M_{Aero} ( ft-lbs)" + delimeter + "N_{Aero} (ft-lbs)" + delimeter;
315       outstream << "L_{Prop} (ft-lbs)" + delimeter + "M_{Prop} (ft-lbs)" + delimeter + "N_{Prop} (ft-lbs)" + delimeter;
316       outstream << "L_{Gear} (ft-lbs)" + delimeter + "M_{Gear} (ft-lbs)" + delimeter + "N_{Gear} (ft-lbs)" + delimeter;
317       outstream << "L_{ext} (ft-lbs)" + delimeter + "M_{ext} (ft-lbs)" + delimeter + "N_{ext} (ft-lbs)" + delimeter;
318       outstream << "L_{Buoyant} (ft-lbs)" + delimeter + "M_{Buoyant} (ft-lbs)" + delimeter + "N_{Buoyant} (ft-lbs)" + delimeter;
319       outstream << "L_{Total} (ft-lbs)" + delimeter + "M_{Total} (ft-lbs)" + delimeter + "N_{Total} (ft-lbs)";
320     }
321     if (SubSystems & ssAtmosphere) {
322       outstream << delimeter;
323       outstream << "Rho (slugs/ft^3)" + delimeter;
324       outstream << "Absolute Viscosity" + delimeter;
325       outstream << "Kinematic Viscosity" + delimeter;
326       outstream << "Temperature (R)" + delimeter;
327       outstream << "P_{SL} (psf)" + delimeter;
328       outstream << "P_{Ambient} (psf)" + delimeter;
329       outstream << "Turbulence Magnitude (ft/sec)" + delimeter;
330       outstream << "Turbulence X Direction (rad)" + delimeter + "Turbulence Y Direction (rad)" + delimeter + "Turbulence Z Direction (rad)" + delimeter;
331       outstream << "Wind V_{North} (ft/s)" + delimeter + "Wind V_{East} (ft/s)" + delimeter + "Wind V_{Down} (ft/s)";
332     }
333     if (SubSystems & ssMassProps) {
334       outstream << delimeter;
335       outstream << "I_{xx}" + delimeter;
336       outstream << "I_{xy}" + delimeter;
337       outstream << "I_{xz}" + delimeter;
338       outstream << "I_{yx}" + delimeter;
339       outstream << "I_{yy}" + delimeter;
340       outstream << "I_{yz}" + delimeter;
341       outstream << "I_{zx}" + delimeter;
342       outstream << "I_{zy}" + delimeter;
343       outstream << "I_{zz}" + delimeter;
344       outstream << "Mass" + delimeter;
345       outstream << "X_{cg}" + delimeter + "Y_{cg}" + delimeter + "Z_{cg}";
346     }
347     if (SubSystems & ssPropagate) {
348       outstream << delimeter;
349       outstream << "Altitude ASL (ft)" + delimeter;
350       outstream << "Altitude AGL (ft)" + delimeter;
351       outstream << "Phi (deg)" + delimeter + "Theta (deg)" + delimeter + "Psi (deg)" + delimeter;
352       outstream << "Alpha (deg)" + delimeter;
353       outstream << "Beta (deg)" + delimeter;
354       outstream << "Latitude (deg)" + delimeter;
355       outstream << "Longitude (deg)" + delimeter;
356       outstream << "X_{ECI} (ft)" + delimeter + "Y_{ECI} (ft)" + delimeter + "Z_{ECI} (ft)" + delimeter;
357       outstream << "X_{ECEF} (ft)" + delimeter + "Y_{ECEF} (ft)" + delimeter + "Z_{ECEF} (ft)" + delimeter;
358       outstream << "Earth Position Angle (deg)" + delimeter;
359       outstream << "Distance AGL (ft)" + delimeter;
360       outstream << "Terrain Elevation (ft)";
361     }
362     if (SubSystems & ssCoefficients) {
363       scratch = Aerodynamics->GetCoefficientStrings(delimeter);
364       if (scratch.length() != 0) outstream << delimeter << scratch;
365     }
366     if (SubSystems & ssFCS) {
367       scratch = FCS->GetComponentStrings(delimeter);
368       if (scratch.length() != 0) outstream << delimeter << scratch;
369     }
370     if (SubSystems & ssGroundReactions) {
371       outstream << delimeter;
372       outstream << GroundReactions->GetGroundReactionStrings(delimeter);
373     }
374     if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
375       outstream << delimeter;
376       outstream << Propulsion->GetPropulsionStrings(delimeter);
377     }
378     if (OutputProperties.size() > 0) {
379       for (unsigned int i=0;i<OutputProperties.size();i++) {
380         outstream << delimeter << OutputProperties[i]->GetPrintableName();
381       }
382     }
383
384     outstream << endl;
385     dFirstPass = false;
386   }
387
388   outstream << FDMExec->GetSimTime();
389   if (SubSystems & ssSimulation) {
390   }
391   if (SubSystems & ssAerosurfaces) {
392     outstream << delimeter;
393     outstream << FCS->GetDaCmd() << delimeter;
394     outstream << FCS->GetDeCmd() << delimeter;
395     outstream << FCS->GetDrCmd() << delimeter;
396     outstream << FCS->GetDfCmd() << delimeter;
397     outstream << FCS->GetDaLPos(ofDeg) << delimeter;
398     outstream << FCS->GetDaRPos(ofDeg) << delimeter;
399     outstream << FCS->GetDePos(ofDeg) << delimeter;
400     outstream << FCS->GetDrPos(ofDeg) << delimeter;
401     outstream << FCS->GetDfPos(ofDeg);
402   }
403   if (SubSystems & ssRates) {
404     outstream << delimeter;
405     outstream << (radtodeg*Propagate->GetPQR()).Dump(delimeter) << delimeter;
406     outstream << (radtodeg*Propagate->GetPQRdot()).Dump(delimeter) << delimeter;
407     outstream << (radtodeg*Propagate->GetPQRi()).Dump(delimeter);
408   }
409   if (SubSystems & ssVelocities) {
410     outstream << delimeter;
411     outstream << Auxiliary->Getqbar() << delimeter;
412     outstream << Auxiliary->GetReynoldsNumber() << delimeter;
413     outstream << setprecision(12) << Auxiliary->GetVt() << delimeter;
414     outstream << Propagate->GetInertialVelocityMagnitude() << delimeter;
415     outstream << setprecision(12) << Propagate->GetUVW().Dump(delimeter) << delimeter;
416     outstream << Auxiliary->GetAeroUVW().Dump(delimeter) << delimeter;
417     outstream << Propagate->GetInertialVelocity().Dump(delimeter) << delimeter;
418     outstream << Propagate->GetVel().Dump(delimeter);
419     outstream.precision(10);
420   }
421   if (SubSystems & ssForces) {
422     outstream << delimeter;
423     outstream << Aerodynamics->GetvFw().Dump(delimeter) << delimeter;
424     outstream << Aerodynamics->GetLoD() << delimeter;
425     outstream << Aerodynamics->GetForces().Dump(delimeter) << delimeter;
426     outstream << Propulsion->GetForces().Dump(delimeter) << delimeter;
427     outstream << GroundReactions->GetForces().Dump(delimeter) << delimeter;
428     outstream << ExternalReactions->GetForces().Dump(delimeter) << delimeter;
429     outstream << BuoyantForces->GetForces().Dump(delimeter) << delimeter;
430     outstream << Aircraft->GetForces().Dump(delimeter);
431   }
432   if (SubSystems & ssMoments) {
433     outstream << delimeter;
434     outstream << Aerodynamics->GetMoments().Dump(delimeter) << delimeter;
435     outstream << Propulsion->GetMoments().Dump(delimeter) << delimeter;
436     outstream << GroundReactions->GetMoments().Dump(delimeter) << delimeter;
437     outstream << ExternalReactions->GetMoments().Dump(delimeter) << delimeter;
438     outstream << BuoyantForces->GetMoments().Dump(delimeter) << delimeter;
439     outstream << Aircraft->GetMoments().Dump(delimeter);
440   }
441   if (SubSystems & ssAtmosphere) {
442     outstream << delimeter;
443     outstream << Atmosphere->GetDensity() << delimeter;
444     outstream << Atmosphere->GetAbsoluteViscosity() << delimeter;
445     outstream << Atmosphere->GetKinematicViscosity() << delimeter;
446     outstream << Atmosphere->GetTemperature() << delimeter;
447     outstream << Atmosphere->GetPressureSL() << delimeter;
448     outstream << Atmosphere->GetPressure() << delimeter;
449     outstream << Atmosphere->GetTurbMagnitude() << delimeter;
450     outstream << Atmosphere->GetTurbDirection().Dump(delimeter) << delimeter;
451     outstream << Atmosphere->GetTotalWindNED().Dump(delimeter);
452   }
453   if (SubSystems & ssMassProps) {
454     outstream << delimeter;
455     outstream << MassBalance->GetJ().Dump(delimeter) << delimeter;
456     outstream << MassBalance->GetMass() << delimeter;
457     outstream << MassBalance->GetXYZcg().Dump(delimeter);
458   }
459   if (SubSystems & ssPropagate) {
460     outstream.precision(14);
461     outstream << delimeter;
462     outstream << Propagate->GetAltitudeASL() << delimeter;
463     outstream << Propagate->GetDistanceAGL() << delimeter;
464     outstream << (radtodeg*Propagate->GetEuler()).Dump(delimeter) << delimeter;
465     outstream << Auxiliary->Getalpha(inDegrees) << delimeter;
466     outstream << Auxiliary->Getbeta(inDegrees) << delimeter;
467     outstream << Propagate->GetLocation().GetLatitudeDeg() << delimeter;
468     outstream << Propagate->GetLocation().GetLongitudeDeg() << delimeter;
469     outstream.precision(18);
470     outstream << ((FGColumnVector3)Propagate->GetInertialPosition()).Dump(delimeter) << delimeter;
471     outstream << ((FGColumnVector3)Propagate->GetLocation()).Dump(delimeter) << delimeter;
472     outstream.precision(14);
473     outstream << Inertial->GetEarthPositionAngleDeg() << delimeter;
474     outstream << Propagate->GetDistanceAGL() << delimeter;
475     outstream << Propagate->GetTerrainElevation();
476     outstream.precision(10);
477   }
478   if (SubSystems & ssCoefficients) {
479     scratch = Aerodynamics->GetCoefficientValues(delimeter);
480     if (scratch.length() != 0) outstream << delimeter << scratch;
481   }
482   if (SubSystems & ssFCS) {
483     scratch = FCS->GetComponentValues(delimeter);
484     if (scratch.length() != 0) outstream << delimeter << scratch;
485   }
486   if (SubSystems & ssGroundReactions) {
487     outstream << delimeter;
488     outstream << GroundReactions->GetGroundReactionValues(delimeter);
489   }
490   if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
491     outstream << delimeter;
492     outstream << Propulsion->GetPropulsionValues(delimeter);
493   }
494
495   outstream.precision(18);
496   for (unsigned int i=0;i<OutputProperties.size();i++) {
497     outstream << delimeter << OutputProperties[i]->getDoubleValue();
498   }
499   outstream.precision(10);
500
501   outstream << endl;
502   outstream.flush();
503 }
504
505 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
506
507 void FGOutput::SocketDataFill(FGNetFDM* net)
508 {
509   const FGAerodynamics* Aerodynamics = FDMExec->GetAerodynamics();
510   const FGAuxiliary* Auxiliary = FDMExec->GetAuxiliary();
511   const FGPropulsion* Propulsion = FDMExec->GetPropulsion();
512   const FGMassBalance* MassBalance = FDMExec->GetMassBalance();
513   const FGPropagate* Propagate = FDMExec->GetPropagate();
514   const FGFCS* FCS = FDMExec->GetFCS();
515   const FGGroundReactions* GroundReactions = FDMExec->GetGroundReactions();
516     unsigned int i;
517
518     // Version
519     net->version = FG_NET_FDM_VERSION;
520
521     // Positions
522     net->longitude = Propagate->GetLocation().GetLongitude(); // geodetic (radians)
523     net->latitude  = Propagate->GetLocation().GetLatitude(); // geodetic (radians)
524     net->altitude  = Propagate->GetAltitudeASL()*0.3048; // altitude, above sea level (meters)
525     net->agl       = (float)(Propagate->GetDistanceAGL()*0.3048); // altitude, above ground level (meters)
526
527     net->phi       = (float)(Propagate->GetEuler(ePhi)); // roll (radians)
528     net->theta     = (float)(Propagate->GetEuler(eTht)); // pitch (radians)
529     net->psi       = (float)(Propagate->GetEuler(ePsi)); // yaw or true heading (radians)
530
531     net->alpha     = (float)(Auxiliary->Getalpha()); // angle of attack (radians)
532     net->beta      = (float)(Auxiliary->Getbeta()); // side slip angle (radians)
533
534     // Velocities
535     net->phidot     = (float)(Auxiliary->GetEulerRates(ePhi)); // roll rate (radians/sec)
536     net->thetadot   = (float)(Auxiliary->GetEulerRates(eTht)); // pitch rate (radians/sec)
537     net->psidot     = (float)(Auxiliary->GetEulerRates(ePsi)); // yaw rate (radians/sec)
538     net->vcas       = (float)(Auxiliary->GetVcalibratedFPS()); // VCAS, ft/sec
539     net->climb_rate = (float)(Propagate->Gethdot());           // altitude rate, ft/sec
540     net->v_north    = (float)(Propagate->GetVel(eNorth));      // north vel in NED frame, fps
541     net->v_east     = (float)(Propagate->GetVel(eEast));       // east vel in NED frame, fps
542     net->v_down     = (float)(Propagate->GetVel(eDown));       // down vel in NED frame, fps
543 //---ADD METHOD TO CALCULATE THESE TERMS---
544     net->v_wind_body_north = (float)(Propagate->GetVel(eNorth)); // north vel in NED relative to airmass, fps
545     net->v_wind_body_east = (float)(Propagate->GetVel(eEast)); // east vel in NED relative to airmass, fps
546     net->v_wind_body_down = (float)(Propagate->GetVel(eDown)); // down vel in NED relative to airmass, fps
547
548     // Accelerations
549     net->A_X_pilot   = (float)(Auxiliary->GetPilotAccel(1));    // X body accel, ft/s/s
550     net->A_Y_pilot   = (float)(Auxiliary->GetPilotAccel(2));    // Y body accel, ft/s/s
551     net->A_Z_pilot   = (float)(Auxiliary->GetPilotAccel(3));    // Z body accel, ft/s/s
552
553     // Stall
554     net->stall_warning = 0.0;  // 0.0 - 1.0 indicating the amount of stall
555     net->slip_deg    = (float)(Auxiliary->Getbeta(inDegrees));  // slip ball deflection, deg
556
557     // Engine status
558     net->num_engines = Propulsion->GetNumEngines(); // Number of valid engines
559
560     for (i=0; i<net->num_engines; i++) {
561        if (Propulsion->GetEngine(i)->GetRunning())
562           net->eng_state[i] = 2;       // Engine state running
563        else if (Propulsion->GetEngine(i)->GetCranking())
564           net->eng_state[i] = 1;       // Engine state cranking
565        else
566           net->eng_state[i] = 0;       // Engine state off
567
568        switch (Propulsion->GetEngine(i)->GetType()) {
569        case (FGEngine::etRocket):
570        break;
571        case (FGEngine::etPiston):
572           net->rpm[i]       = (float)(((FGPiston *)Propulsion->GetEngine(i))->getRPM());
573           net->fuel_flow[i] = (float)(((FGPiston *)Propulsion->GetEngine(i))->getFuelFlow_gph());
574           net->fuel_px[i]   = 0; // Fuel pressure, psi  (N/A in current model)
575           net->egt[i]       = (float)(((FGPiston *)Propulsion->GetEngine(i))->GetEGT());
576           net->cht[i]       = (float)(((FGPiston *)Propulsion->GetEngine(i))->getCylinderHeadTemp_degF());
577           net->mp_osi[i]    = (float)(((FGPiston *)Propulsion->GetEngine(i))->getManifoldPressure_inHg());
578           net->oil_temp[i]  = (float)(((FGPiston *)Propulsion->GetEngine(i))->getOilTemp_degF());
579           net->oil_px[i]    = (float)(((FGPiston *)Propulsion->GetEngine(i))->getOilPressure_psi());
580           net->tit[i]       = 0; // Turbine Inlet Temperature  (N/A for piston)
581        break;
582        case (FGEngine::etTurbine):
583        break;
584        case (FGEngine::etTurboprop):
585        break;
586        case (FGEngine::etElectric):
587        break;
588        case (FGEngine::etUnknown):
589        break;
590        }
591     }
592
593     // Consumables
594     net->num_tanks = Propulsion->GetNumTanks();   // Max number of fuel tanks
595
596     for (i=0; i<net->num_tanks; i++) {
597        net->fuel_quantity[i] = (float)(((FGTank *)Propulsion->GetTank(i))->GetContents());
598     }
599
600     // Gear status
601     net->num_wheels  = GroundReactions->GetNumGearUnits();
602
603     for (i=0; i<net->num_wheels; i++) {
604        net->wow[i]              = GroundReactions->GetGearUnit(i)->GetWOW();
605        if (GroundReactions->GetGearUnit(i)->GetGearUnitDown())
606           net->gear_pos[i]      = 1;  //gear down, using FCS convention
607        else
608           net->gear_pos[i]      = 0;  //gear up, using FCS convention
609        net->gear_steer[i]       = (float)(GroundReactions->GetGearUnit(i)->GetSteerNorm());
610        net->gear_compression[i] = (float)(GroundReactions->GetGearUnit(i)->GetCompLen());
611     }
612
613     // Environment
614     net->cur_time    = (long int)1234567890;    // Friday, Feb 13, 2009, 23:31:30 UTC (not processed by FGFS anyway)
615     net->warp        = 0;                       // offset in seconds to unix time
616     net->visibility  = 25000.0;                 // visibility in meters (for env. effects)
617
618     // Control surface positions (normalized values)
619     net->elevator          = (float)(FCS->GetDePos(ofNorm));    // Norm Elevator Pos, --
620     net->elevator_trim_tab = (float)(FCS->GetPitchTrimCmd());   // Norm Elev Trim Tab Pos, --
621     net->left_flap         = (float)(FCS->GetDfPos(ofNorm));    // Norm Flap Pos, --
622     net->right_flap        = (float)(FCS->GetDfPos(ofNorm));    // Norm Flap Pos, --
623     net->left_aileron      = (float)(FCS->GetDaLPos(ofNorm));   // Norm L Aileron Pos, --
624     net->right_aileron     = (float)(FCS->GetDaRPos(ofNorm));   // Norm R Aileron Pos, --
625     net->rudder            = (float)(FCS->GetDrPos(ofNorm));    // Norm Rudder Pos, --
626     net->nose_wheel        = (float)(FCS->GetDrPos(ofNorm));    // *** FIX ***  Using Rudder Pos for NWS, --
627     net->speedbrake        = (float)(FCS->GetDsbPos(ofNorm));   // Norm Speedbrake Pos, --
628     net->spoilers          = (float)(FCS->GetDspPos(ofNorm));   // Norm Spoiler Pos, --
629
630     // Convert the net buffer to network format
631     if ( isLittleEndian ) {
632         net->version = htonl(net->version);
633
634         htond(net->longitude);
635         htond(net->latitude);
636         htond(net->altitude);
637         htonf(net->agl);
638         htonf(net->phi);
639         htonf(net->theta);
640         htonf(net->psi);
641         htonf(net->alpha);
642         htonf(net->beta);
643
644         htonf(net->phidot);
645         htonf(net->thetadot);
646         htonf(net->psidot);
647         htonf(net->vcas);
648         htonf(net->climb_rate);
649         htonf(net->v_north);
650         htonf(net->v_east);
651         htonf(net->v_down);
652         htonf(net->v_wind_body_north);
653         htonf(net->v_wind_body_east);
654         htonf(net->v_wind_body_down);
655
656         htonf(net->A_X_pilot);
657         htonf(net->A_Y_pilot);
658         htonf(net->A_Z_pilot);
659
660         htonf(net->stall_warning);
661         htonf(net->slip_deg);
662
663         for (i=0; i<net->num_engines; ++i ) {
664             net->eng_state[i] = htonl(net->eng_state[i]);
665             htonf(net->rpm[i]);
666             htonf(net->fuel_flow[i]);
667             htonf(net->fuel_px[i]);
668             htonf(net->egt[i]);
669             htonf(net->cht[i]);
670             htonf(net->mp_osi[i]);
671             htonf(net->tit[i]);
672             htonf(net->oil_temp[i]);
673             htonf(net->oil_px[i]);
674         }
675         net->num_engines = htonl(net->num_engines);
676
677         for (i=0; i<net->num_tanks; ++i ) {
678             htonf(net->fuel_quantity[i]);
679         }
680         net->num_tanks = htonl(net->num_tanks);
681
682         for (i=0; i<net->num_wheels; ++i ) {
683             net->wow[i] = htonl(net->wow[i]);
684             htonf(net->gear_pos[i]);
685             htonf(net->gear_steer[i]);
686             htonf(net->gear_compression[i]);
687         }
688         net->num_wheels = htonl(net->num_wheels);
689
690         net->cur_time = htonl( net->cur_time );
691         net->warp = htonl( net->warp );
692         htonf(net->visibility);
693
694         htonf(net->elevator);
695         htonf(net->elevator_trim_tab);
696         htonf(net->left_flap);
697         htonf(net->right_flap);
698         htonf(net->left_aileron);
699         htonf(net->right_aileron);
700         htonf(net->rudder);
701         htonf(net->nose_wheel);
702         htonf(net->speedbrake);
703         htonf(net->spoilers);
704     }
705 }
706
707 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
708
709 void FGOutput::FlightGearSocketOutput(void)
710 {
711   int length = sizeof(fgSockBuf);
712
713   if (socket == NULL) return;
714   if (!socket->GetConnectStatus()) return;
715
716   SocketDataFill(&fgSockBuf);
717   socket->Send((char *)&fgSockBuf, length);
718 }
719
720 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
721
722 void FGOutput::SocketOutput(void)
723 {
724   const FGAerodynamics* Aerodynamics = FDMExec->GetAerodynamics();
725   const FGAuxiliary* Auxiliary = FDMExec->GetAuxiliary();
726   const FGPropulsion* Propulsion = FDMExec->GetPropulsion();
727   const FGMassBalance* MassBalance = FDMExec->GetMassBalance();
728   const FGPropagate* Propagate = FDMExec->GetPropagate();
729   const FGFCS* FCS = FDMExec->GetFCS();
730   const FGAtmosphere* Atmosphere = FDMExec->GetAtmosphere();
731   const FGAircraft* Aircraft = FDMExec->GetAircraft();
732   const FGGroundReactions* GroundReactions = FDMExec->GetGroundReactions();
733
734   string asciiData, scratch;
735
736   if (socket == NULL) return;
737   if (!socket->GetConnectStatus()) return;
738
739   socket->Clear();
740   if (sFirstPass) {
741     socket->Clear("<LABELS>");
742     socket->Append("Time");
743
744     if (SubSystems & ssAerosurfaces) {
745       socket->Append("Aileron Command");
746       socket->Append("Elevator Command");
747       socket->Append("Rudder Command");
748       socket->Append("Flap Command");
749       socket->Append("Left Aileron Position");
750       socket->Append("Right Aileron Position");
751       socket->Append("Elevator Position");
752       socket->Append("Rudder Position");
753       socket->Append("Flap Position");
754     }
755
756     if (SubSystems & ssRates) {
757       socket->Append("P");
758       socket->Append("Q");
759       socket->Append("R");
760       socket->Append("PDot");
761       socket->Append("QDot");
762       socket->Append("RDot");
763     }
764
765     if (SubSystems & ssVelocities) {
766       socket->Append("QBar");
767       socket->Append("Vtotal");
768       socket->Append("UBody");
769       socket->Append("VBody");
770       socket->Append("WBody");
771       socket->Append("UAero");
772       socket->Append("VAero");
773       socket->Append("WAero");
774       socket->Append("Vn");
775       socket->Append("Ve");
776       socket->Append("Vd");
777     }
778     if (SubSystems & ssForces) {
779       socket->Append("F_Drag");
780       socket->Append("F_Side");
781       socket->Append("F_Lift");
782       socket->Append("LoD");
783       socket->Append("Fx");
784       socket->Append("Fy");
785       socket->Append("Fz");
786     }
787     if (SubSystems & ssMoments) {
788       socket->Append("L");
789       socket->Append("M");
790       socket->Append("N");
791     }
792     if (SubSystems & ssAtmosphere) {
793       socket->Append("Rho");
794       socket->Append("SL pressure");
795       socket->Append("Ambient pressure");
796       socket->Append("Turbulence Magnitude");
797       socket->Append("Turbulence Direction X");
798       socket->Append("Turbulence Direction Y");
799       socket->Append("Turbulence Direction Z");
800       socket->Append("NWind");
801       socket->Append("EWind");
802       socket->Append("DWind");
803     }
804     if (SubSystems & ssMassProps) {
805       socket->Append("Ixx");
806       socket->Append("Ixy");
807       socket->Append("Ixz");
808       socket->Append("Iyx");
809       socket->Append("Iyy");
810       socket->Append("Iyz");
811       socket->Append("Izx");
812       socket->Append("Izy");
813       socket->Append("Izz");
814       socket->Append("Mass");
815       socket->Append("Xcg");
816       socket->Append("Ycg");
817       socket->Append("Zcg");
818     }
819     if (SubSystems & ssPropagate) {
820         socket->Append("Altitude");
821         socket->Append("Phi (deg)");
822         socket->Append("Tht (deg)");
823         socket->Append("Psi (deg)");
824         socket->Append("Alpha (deg)");
825         socket->Append("Beta (deg)");
826         socket->Append("Latitude (deg)");
827         socket->Append("Longitude (deg)");
828     }
829     if (SubSystems & ssCoefficients) {
830       scratch = Aerodynamics->GetCoefficientStrings(",");
831       if (scratch.length() != 0) socket->Append(scratch);
832     }
833     if (SubSystems & ssFCS) {
834       scratch = FCS->GetComponentStrings(",");
835       if (scratch.length() != 0) socket->Append(scratch);
836     }
837     if (SubSystems & ssGroundReactions) {
838       socket->Append(GroundReactions->GetGroundReactionStrings(","));
839     }
840     if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
841       socket->Append(Propulsion->GetPropulsionStrings(","));
842     }
843     if (OutputProperties.size() > 0) {
844       for (unsigned int i=0;i<OutputProperties.size();i++) {
845         socket->Append(OutputProperties[i]->GetPrintableName());
846       }
847     }
848
849     sFirstPass = false;
850     socket->Send();
851   }
852
853   socket->Clear();
854   socket->Append(FDMExec->GetSimTime());
855
856   if (SubSystems & ssAerosurfaces) {
857     socket->Append(FCS->GetDaCmd());
858     socket->Append(FCS->GetDeCmd());
859     socket->Append(FCS->GetDrCmd());
860     socket->Append(FCS->GetDfCmd());
861     socket->Append(FCS->GetDaLPos());
862     socket->Append(FCS->GetDaRPos());
863     socket->Append(FCS->GetDePos());
864     socket->Append(FCS->GetDrPos());
865     socket->Append(FCS->GetDfPos());
866   }
867   if (SubSystems & ssRates) {
868     socket->Append(radtodeg*Propagate->GetPQR(eP));
869     socket->Append(radtodeg*Propagate->GetPQR(eQ));
870     socket->Append(radtodeg*Propagate->GetPQR(eR));
871     socket->Append(radtodeg*Propagate->GetPQRdot(eP));
872     socket->Append(radtodeg*Propagate->GetPQRdot(eQ));
873     socket->Append(radtodeg*Propagate->GetPQRdot(eR));
874   }
875   if (SubSystems & ssVelocities) {
876     socket->Append(Auxiliary->Getqbar());
877     socket->Append(Auxiliary->GetVt());
878     socket->Append(Propagate->GetUVW(eU));
879     socket->Append(Propagate->GetUVW(eV));
880     socket->Append(Propagate->GetUVW(eW));
881     socket->Append(Auxiliary->GetAeroUVW(eU));
882     socket->Append(Auxiliary->GetAeroUVW(eV));
883     socket->Append(Auxiliary->GetAeroUVW(eW));
884     socket->Append(Propagate->GetVel(eNorth));
885     socket->Append(Propagate->GetVel(eEast));
886     socket->Append(Propagate->GetVel(eDown));
887   }
888   if (SubSystems & ssForces) {
889     socket->Append(Aerodynamics->GetvFw()(eDrag));
890     socket->Append(Aerodynamics->GetvFw()(eSide));
891     socket->Append(Aerodynamics->GetvFw()(eLift));
892     socket->Append(Aerodynamics->GetLoD());
893     socket->Append(Aircraft->GetForces(eX));
894     socket->Append(Aircraft->GetForces(eY));
895     socket->Append(Aircraft->GetForces(eZ));
896   }
897   if (SubSystems & ssMoments) {
898     socket->Append(Aircraft->GetMoments(eL));
899     socket->Append(Aircraft->GetMoments(eM));
900     socket->Append(Aircraft->GetMoments(eN));
901   }
902   if (SubSystems & ssAtmosphere) {
903     socket->Append(Atmosphere->GetDensity());
904     socket->Append(Atmosphere->GetPressureSL());
905     socket->Append(Atmosphere->GetPressure());
906     socket->Append(Atmosphere->GetTurbMagnitude());
907     socket->Append(Atmosphere->GetTurbDirection().Dump(","));
908     socket->Append(Atmosphere->GetTotalWindNED().Dump(","));
909   }
910   if (SubSystems & ssMassProps) {
911     socket->Append(MassBalance->GetJ()(1,1));
912     socket->Append(MassBalance->GetJ()(1,2));
913     socket->Append(MassBalance->GetJ()(1,3));
914     socket->Append(MassBalance->GetJ()(2,1));
915     socket->Append(MassBalance->GetJ()(2,2));
916     socket->Append(MassBalance->GetJ()(2,3));
917     socket->Append(MassBalance->GetJ()(3,1));
918     socket->Append(MassBalance->GetJ()(3,2));
919     socket->Append(MassBalance->GetJ()(3,3));
920     socket->Append(MassBalance->GetMass());
921     socket->Append(MassBalance->GetXYZcg()(eX));
922     socket->Append(MassBalance->GetXYZcg()(eY));
923     socket->Append(MassBalance->GetXYZcg()(eZ));
924   }
925   if (SubSystems & ssPropagate) {
926     socket->Append(Propagate->GetAltitudeASL());
927     socket->Append(radtodeg*Propagate->GetEuler(ePhi));
928     socket->Append(radtodeg*Propagate->GetEuler(eTht));
929     socket->Append(radtodeg*Propagate->GetEuler(ePsi));
930     socket->Append(Auxiliary->Getalpha(inDegrees));
931     socket->Append(Auxiliary->Getbeta(inDegrees));
932     socket->Append(Propagate->GetLocation().GetLatitudeDeg());
933     socket->Append(Propagate->GetLocation().GetLongitudeDeg());
934   }
935   if (SubSystems & ssCoefficients) {
936     scratch = Aerodynamics->GetCoefficientValues(",");
937     if (scratch.length() != 0) socket->Append(scratch);
938   }
939   if (SubSystems & ssFCS) {
940     scratch = FCS->GetComponentValues(",");
941     if (scratch.length() != 0) socket->Append(scratch);
942   }
943   if (SubSystems & ssGroundReactions) {
944     socket->Append(GroundReactions->GetGroundReactionValues(","));
945   }
946   if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
947     socket->Append(Propulsion->GetPropulsionValues(","));
948   }
949
950   for (unsigned int i=0;i<OutputProperties.size();i++) {
951     socket->Append(OutputProperties[i]->getDoubleValue());
952   }
953
954   socket->Send();
955 }
956
957 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
958
959 void FGOutput::SocketStatusOutput(const string& out_str)
960 {
961   string asciiData;
962
963   if (socket == NULL) return;
964
965   socket->Clear();
966   asciiData = string("<STATUS>") + out_str;
967   socket->Append(asciiData.c_str());
968   socket->Send();
969 }
970
971 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
972
973 bool FGOutput::Load(Element* element)
974 {
975   string parameter="";
976   string name="";
977   int OutRate = 0;
978   unsigned int port;
979   Element *property_element;
980
981   string separator = "/";
982
983   if (!DirectivesFile.empty()) { // A directives filename from the command line overrides
984     output_file_name = DirectivesFile;      // one found in the config file.
985     document = LoadXMLDocument(output_file_name);
986   } else if (!element->GetAttributeValue("file").empty()) {
987     output_file_name = FDMExec->GetRootDir() + element->GetAttributeValue("file");
988     document = LoadXMLDocument(output_file_name);
989   } else {
990     document = element;
991   }
992
993   if (!document) return false;
994
995   name = FDMExec->GetRootDir() + document->GetAttributeValue("name");
996   SetType(document->GetAttributeValue("type"));
997   Port = document->GetAttributeValue("port");
998   if (!Port.empty() && (Type == otSocket || Type == otFlightGear)) {
999     port = atoi(Port.c_str());
1000     SetProtocol(document->GetAttributeValue("protocol"));
1001     socket = new FGfdmSocket(name, port, Protocol);
1002   } else {
1003     BaseFilename = Filename = name;
1004   }
1005   if (!document->GetAttributeValue("rate").empty()) {
1006     OutRate = (int)document->GetAttributeValueAsNumber("rate");
1007   } else {
1008     OutRate = 1;
1009   }
1010
1011   if (document->FindElementValue("simulation") == string("ON"))
1012     SubSystems += ssSimulation;
1013   if (document->FindElementValue("aerosurfaces") == string("ON"))
1014     SubSystems += ssAerosurfaces;
1015   if (document->FindElementValue("rates") == string("ON"))
1016     SubSystems += ssRates;
1017   if (document->FindElementValue("velocities") == string("ON"))
1018     SubSystems += ssVelocities;
1019   if (document->FindElementValue("forces") == string("ON"))
1020     SubSystems += ssForces;
1021   if (document->FindElementValue("moments") == string("ON"))
1022     SubSystems += ssMoments;
1023   if (document->FindElementValue("atmosphere") == string("ON"))
1024     SubSystems += ssAtmosphere;
1025   if (document->FindElementValue("massprops") == string("ON"))
1026     SubSystems += ssMassProps;
1027   if (document->FindElementValue("position") == string("ON"))
1028     SubSystems += ssPropagate;
1029   if (document->FindElementValue("coefficients") == string("ON"))
1030     SubSystems += ssCoefficients;
1031   if (document->FindElementValue("ground_reactions") == string("ON"))
1032     SubSystems += ssGroundReactions;
1033   if (document->FindElementValue("fcs") == string("ON"))
1034     SubSystems += ssFCS;
1035   if (document->FindElementValue("propulsion") == string("ON"))
1036     SubSystems += ssPropulsion;
1037   property_element = document->FindElement("property");
1038   while (property_element) {
1039     string property_str = property_element->GetDataLine();
1040     FGPropertyManager* node = PropertyManager->GetNode(property_str);
1041     if (!node) {
1042       cerr << fgred << highint << endl << "  No property by the name "
1043            << property_str << " has been defined. This property will " << endl
1044            << "  not be logged. You should check your configuration file."
1045            << reset << endl;
1046     } else {
1047       OutputProperties.push_back(node);
1048     }
1049     property_element = document->FindNextElement("property");
1050   }
1051
1052   SetRate(OutRate);
1053
1054   Debug(2);
1055
1056   return true;
1057 }
1058
1059 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1060
1061 void FGOutput::SetRate(int rtHz)
1062 {
1063   rtHz = rtHz>1000?1000:(rtHz<0?0:rtHz);
1064   if (rtHz > 0) {
1065     rate = (int)(0.5 + 1.0/(FDMExec->GetDeltaT()*rtHz));
1066     Enable();
1067   } else {
1068     rate = 1;
1069     Disable();
1070   }
1071 }
1072
1073 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1074 //    The bitmasked value choices are as follows:
1075 //    unset: In this case (the default) JSBSim would only print
1076 //       out the normally expected messages, essentially echoing
1077 //       the config files as they are read. If the environment
1078 //       variable is not set, debug_lvl is set to 1 internally
1079 //    0: This requests JSBSim not to output any messages
1080 //       whatsoever.
1081 //    1: This value explicity requests the normal JSBSim
1082 //       startup messages
1083 //    2: This value asks for a message to be printed out when
1084 //       a class is instantiated
1085 //    4: When this value is set, a message is displayed when a
1086 //       FGModel object executes its Run() method
1087 //    8: When this value is set, various runtime state variables
1088 //       are printed out periodically
1089 //    16: When set various parameters are sanity checked and
1090 //       a message is printed out when they go out of bounds
1091
1092 void FGOutput::Debug(int from)
1093 {
1094   string scratch="";
1095
1096   if (debug_lvl <= 0) return;
1097
1098   if (debug_lvl & 1) { // Standard console startup message output
1099     if (from == 0) { // Constructor
1100
1101     }
1102     if (from == 2) {
1103       if (output_file_name.empty())
1104         cout << "  " << "Output parameters read inline" << endl;
1105       else
1106         cout << "    Output parameters read from file: " << output_file_name << endl;
1107
1108       if (Filename == "cout" || Filename == "COUT") {
1109         scratch = "    Log output goes to screen console";
1110       } else if (!Filename.empty()) {
1111         scratch = "    Log output goes to file: " + Filename;
1112       }
1113       switch (Type) {
1114       case otCSV:
1115         cout << scratch << " in CSV format output at rate " << 1/(FDMExec->GetDeltaT()*rate) << " Hz" << endl;
1116         break;
1117       case otNone:
1118       default:
1119         cout << "  No log output" << endl;
1120         break;
1121       }
1122
1123       if (SubSystems & ssSimulation)      cout << "    Simulation parameters logged" << endl;
1124       if (SubSystems & ssAerosurfaces)    cout << "    Aerosurface parameters logged" << endl;
1125       if (SubSystems & ssRates)           cout << "    Rate parameters logged" << endl;
1126       if (SubSystems & ssVelocities)      cout << "    Velocity parameters logged" << endl;
1127       if (SubSystems & ssForces)          cout << "    Force parameters logged" << endl;
1128       if (SubSystems & ssMoments)         cout << "    Moments parameters logged" << endl;
1129       if (SubSystems & ssAtmosphere)      cout << "    Atmosphere parameters logged" << endl;
1130       if (SubSystems & ssMassProps)       cout << "    Mass parameters logged" << endl;
1131       if (SubSystems & ssCoefficients)    cout << "    Coefficient parameters logged" << endl;
1132       if (SubSystems & ssPropagate)       cout << "    Propagate parameters logged" << endl;
1133       if (SubSystems & ssGroundReactions) cout << "    Ground parameters logged" << endl;
1134       if (SubSystems & ssFCS)             cout << "    FCS parameters logged" << endl;
1135       if (SubSystems & ssPropulsion)      cout << "    Propulsion parameters logged" << endl;
1136       if (OutputProperties.size() > 0)    cout << "    Properties logged:" << endl;
1137       for (unsigned int i=0;i<OutputProperties.size();i++) {
1138         cout << "      - " << OutputProperties[i]->GetName() << endl;
1139       }
1140     }
1141   }
1142   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
1143     if (from == 0) cout << "Instantiated: FGOutput" << endl;
1144     if (from == 1) cout << "Destroyed:    FGOutput" << endl;
1145   }
1146   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
1147   }
1148   if (debug_lvl & 8 ) { // Runtime state variables
1149   }
1150   if (debug_lvl & 16) { // Sanity checking
1151   }
1152   if (debug_lvl & 64) {
1153     if (from == 0) { // Constructor
1154       cout << IdSrc << endl;
1155       cout << IdHdr << endl;
1156     }
1157   }
1158 }
1159 }