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