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