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