]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGOutput.cpp
Better fix for a compilation problem with MSVC 2012
[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.67 2012/04/27 12:14: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 FGGroundReactions* GroundReactions = FDMExec->GetGroundReactions();
259   const FGExternalReactions* ExternalReactions = FDMExec->GetExternalReactions();
260   const FGBuoyantForces* BuoyantForces = FDMExec->GetBuoyantForces();
261
262   streambuf* buffer;
263   string scratch = "";
264
265   if (fname == "COUT" || fname == "cout") {
266     buffer = cout.rdbuf();
267   } else {
268     if (!datafile.is_open()) datafile.open(fname.c_str());
269     buffer = datafile.rdbuf();
270   }
271
272   ostream outstream(buffer);
273
274   outstream.precision(10);
275
276   if (dFirstPass) {
277     outstream << "Time";
278     if (SubSystems & ssSimulation) {
279       // Nothing here, yet
280     }
281     if (SubSystems & ssAerosurfaces) {
282       outstream << delimeter;
283       outstream << "Aileron Command (norm)" + delimeter;
284       outstream << "Elevator Command (norm)" + delimeter;
285       outstream << "Rudder Command (norm)" + delimeter;
286       outstream << "Flap Command (norm)" + delimeter;
287       outstream << "Left Aileron Position (deg)" + delimeter;
288       outstream << "Right Aileron Position (deg)" + delimeter;
289       outstream << "Elevator Position (deg)" + delimeter;
290       outstream << "Rudder Position (deg)" + delimeter;
291       outstream << "Flap Position (deg)";
292     }
293     if (SubSystems & ssRates) {
294       outstream << delimeter;
295       outstream << "P (deg/s)" + delimeter + "Q (deg/s)" + delimeter + "R (deg/s)" + delimeter;
296       outstream << "P dot (deg/s^2)" + delimeter + "Q dot (deg/s^2)" + delimeter + "R dot (deg/s^2)" + delimeter;
297       outstream << "P_{inertial} (deg/s)" + delimeter + "Q_{inertial} (deg/s)" + delimeter + "R_{inertial} (deg/s)";
298     }
299     if (SubSystems & ssVelocities) {
300       outstream << delimeter;
301       outstream << "q bar (psf)" + delimeter;
302       outstream << "Reynolds Number" + delimeter;
303       outstream << "V_{Total} (ft/s)" + delimeter;
304       outstream << "V_{Inertial} (ft/s)" + delimeter;
305       outstream << "UBody" + delimeter + "VBody" + delimeter + "WBody" + delimeter;
306       outstream << "Aero V_{X Body} (ft/s)" + delimeter + "Aero V_{Y Body} (ft/s)" + delimeter + "Aero V_{Z Body} (ft/s)" + delimeter;
307       outstream << "V_{X_{inertial}} (ft/s)" + delimeter + "V_{Y_{inertial}} (ft/s)" + delimeter + "V_{Z_{inertial}} (ft/s)" + delimeter;
308       outstream << "V_{X_{ecef}} (ft/s)" + delimeter + "V_{Y_{ecef}} (ft/s)" + delimeter + "V_{Z_{ecef}} (ft/s)" + delimeter;
309       outstream << "V_{North} (ft/s)" + delimeter + "V_{East} (ft/s)" + delimeter + "V_{Down} (ft/s)";
310     }
311     if (SubSystems & ssForces) {
312       outstream << delimeter;
313       outstream << "F_{Drag} (lbs)" + delimeter + "F_{Side} (lbs)" + delimeter + "F_{Lift} (lbs)" + delimeter;
314       outstream << "L/D" + delimeter;
315       outstream << "F_{Aero x} (lbs)" + delimeter + "F_{Aero y} (lbs)" + delimeter + "F_{Aero z} (lbs)" + delimeter;
316       outstream << "F_{Prop x} (lbs)" + delimeter + "F_{Prop y} (lbs)" + delimeter + "F_{Prop z} (lbs)" + delimeter;
317       outstream << "F_{Gear x} (lbs)" + delimeter + "F_{Gear y} (lbs)" + delimeter + "F_{Gear z} (lbs)" + delimeter;
318       outstream << "F_{Ext x} (lbs)" + delimeter + "F_{Ext y} (lbs)" + delimeter + "F_{Ext z} (lbs)" + delimeter;
319       outstream << "F_{Buoyant x} (lbs)" + delimeter + "F_{Buoyant y} (lbs)" + delimeter + "F_{Buoyant z} (lbs)" + delimeter;
320       outstream << "F_{Total x} (lbs)" + delimeter + "F_{Total y} (lbs)" + delimeter + "F_{Total z} (lbs)";
321     }
322     if (SubSystems & ssMoments) {
323       outstream << delimeter;
324       outstream << "L_{Aero} (ft-lbs)" + delimeter + "M_{Aero} (ft-lbs)" + delimeter + "N_{Aero} (ft-lbs)" + delimeter;
325       outstream << "L_{Prop} (ft-lbs)" + delimeter + "M_{Prop} (ft-lbs)" + delimeter + "N_{Prop} (ft-lbs)" + delimeter;
326       outstream << "L_{Gear} (ft-lbs)" + delimeter + "M_{Gear} (ft-lbs)" + delimeter + "N_{Gear} (ft-lbs)" + delimeter;
327       outstream << "L_{ext} (ft-lbs)" + delimeter + "M_{ext} (ft-lbs)" + delimeter + "N_{ext} (ft-lbs)" + delimeter;
328       outstream << "L_{Buoyant} (ft-lbs)" + delimeter + "M_{Buoyant} (ft-lbs)" + delimeter + "N_{Buoyant} (ft-lbs)" + delimeter;
329       outstream << "L_{Total} (ft-lbs)" + delimeter + "M_{Total} (ft-lbs)" + delimeter + "N_{Total} (ft-lbs)";
330     }
331     if (SubSystems & ssAtmosphere) {
332       outstream << delimeter;
333       outstream << "Rho (slugs/ft^3)" + delimeter;
334       outstream << "Absolute Viscosity" + delimeter;
335       outstream << "Kinematic Viscosity" + delimeter;
336       outstream << "Temperature (R)" + delimeter;
337       outstream << "P_{SL} (psf)" + delimeter;
338       outstream << "P_{Ambient} (psf)" + delimeter;
339       outstream << "Turbulence Magnitude (ft/sec)" + delimeter;
340       outstream << "Turbulence X Direction (rad)" + delimeter + "Turbulence Y Direction (rad)" + delimeter + "Turbulence Z Direction (rad)" + delimeter;
341       outstream << "Wind V_{North} (ft/s)" + delimeter + "Wind V_{East} (ft/s)" + delimeter + "Wind V_{Down} (ft/s)";
342     }
343     if (SubSystems & ssMassProps) {
344       outstream << delimeter;
345       outstream << "I_{xx}" + delimeter;
346       outstream << "I_{xy}" + delimeter;
347       outstream << "I_{xz}" + delimeter;
348       outstream << "I_{yx}" + delimeter;
349       outstream << "I_{yy}" + delimeter;
350       outstream << "I_{yz}" + delimeter;
351       outstream << "I_{zx}" + delimeter;
352       outstream << "I_{zy}" + delimeter;
353       outstream << "I_{zz}" + delimeter;
354       outstream << "Mass" + delimeter;
355       outstream << "X_{cg}" + delimeter + "Y_{cg}" + delimeter + "Z_{cg}";
356     }
357     if (SubSystems & ssPropagate) {
358       outstream << delimeter;
359       outstream << "Altitude ASL (ft)" + delimeter;
360       outstream << "Altitude AGL (ft)" + delimeter;
361       outstream << "Phi (deg)" + delimeter + "Theta (deg)" + delimeter + "Psi (deg)" + delimeter;
362       outstream << "Alpha (deg)" + delimeter;
363       outstream << "Beta (deg)" + delimeter;
364       outstream << "Latitude (deg)" + delimeter;
365       outstream << "Longitude (deg)" + delimeter;
366       outstream << "X_{ECI} (ft)" + delimeter + "Y_{ECI} (ft)" + delimeter + "Z_{ECI} (ft)" + delimeter;
367       outstream << "X_{ECEF} (ft)" + delimeter + "Y_{ECEF} (ft)" + delimeter + "Z_{ECEF} (ft)" + delimeter;
368       outstream << "Earth Position Angle (deg)" + delimeter;
369       outstream << "Distance AGL (ft)" + delimeter;
370       outstream << "Terrain Elevation (ft)";
371     }
372     if (SubSystems & ssAeroFunctions) {
373       scratch = Aerodynamics->GetAeroFunctionStrings(delimeter);
374       if (scratch.length() != 0) outstream << delimeter << scratch;
375     }
376     if (SubSystems & ssFCS) {
377       scratch = FCS->GetComponentStrings(delimeter);
378       if (scratch.length() != 0) outstream << delimeter << scratch;
379     }
380     if (SubSystems & ssGroundReactions) {
381       outstream << delimeter;
382       outstream << GroundReactions->GetGroundReactionStrings(delimeter);
383     }
384     if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
385       outstream << delimeter;
386       outstream << Propulsion->GetPropulsionStrings(delimeter);
387     }
388     if (OutputProperties.size() > 0) {
389       for (unsigned int i=0;i<OutputProperties.size();i++) {
390         outstream << delimeter << OutputProperties[i]->GetPrintableName();
391       }
392     }
393
394     outstream << endl;
395     dFirstPass = false;
396   }
397
398   outstream << FDMExec->GetSimTime();
399   if (SubSystems & ssSimulation) {
400   }
401   if (SubSystems & ssAerosurfaces) {
402     outstream << delimeter;
403     outstream << FCS->GetDaCmd() << delimeter;
404     outstream << FCS->GetDeCmd() << delimeter;
405     outstream << FCS->GetDrCmd() << delimeter;
406     outstream << FCS->GetDfCmd() << delimeter;
407     outstream << FCS->GetDaLPos(ofDeg) << delimeter;
408     outstream << FCS->GetDaRPos(ofDeg) << delimeter;
409     outstream << FCS->GetDePos(ofDeg) << delimeter;
410     outstream << FCS->GetDrPos(ofDeg) << delimeter;
411     outstream << FCS->GetDfPos(ofDeg);
412   }
413   if (SubSystems & ssRates) {
414     outstream << delimeter;
415     outstream << (radtodeg*Propagate->GetPQR()).Dump(delimeter) << delimeter;
416     outstream << (radtodeg*Accelerations->GetPQRdot()).Dump(delimeter) << delimeter;
417     outstream << (radtodeg*Propagate->GetPQRi()).Dump(delimeter);
418   }
419   if (SubSystems & ssVelocities) {
420     outstream << delimeter;
421     outstream << Auxiliary->Getqbar() << delimeter;
422     outstream << Auxiliary->GetReynoldsNumber() << delimeter;
423     outstream << setprecision(12) << Auxiliary->GetVt() << delimeter;
424     outstream << Propagate->GetInertialVelocityMagnitude() << delimeter;
425     outstream << setprecision(12) << Propagate->GetUVW().Dump(delimeter) << delimeter;
426     outstream << Auxiliary->GetAeroUVW().Dump(delimeter) << delimeter;
427     outstream << Propagate->GetInertialVelocity().Dump(delimeter) << delimeter;
428     outstream << Propagate->GetECEFVelocity().Dump(delimeter) << delimeter;
429     outstream << Propagate->GetVel().Dump(delimeter);
430     outstream.precision(10);
431   }
432   if (SubSystems & ssForces) {
433     outstream << delimeter;
434     outstream << Aerodynamics->GetvFw().Dump(delimeter) << delimeter;
435     outstream << Aerodynamics->GetLoD() << delimeter;
436     outstream << Aerodynamics->GetForces().Dump(delimeter) << delimeter;
437     outstream << Propulsion->GetForces().Dump(delimeter) << delimeter;
438     outstream << GroundReactions->GetForces().Dump(delimeter) << delimeter;
439     outstream << ExternalReactions->GetForces().Dump(delimeter) << delimeter;
440     outstream << BuoyantForces->GetForces().Dump(delimeter) << delimeter;
441     outstream << Aircraft->GetForces().Dump(delimeter);
442   }
443   if (SubSystems & ssMoments) {
444     outstream << delimeter;
445     outstream << Aerodynamics->GetMoments().Dump(delimeter) << delimeter;
446     outstream << Propulsion->GetMoments().Dump(delimeter) << delimeter;
447     outstream << GroundReactions->GetMoments().Dump(delimeter) << delimeter;
448     outstream << ExternalReactions->GetMoments().Dump(delimeter) << delimeter;
449     outstream << BuoyantForces->GetMoments().Dump(delimeter) << delimeter;
450     outstream << Aircraft->GetMoments().Dump(delimeter);
451   }
452   if (SubSystems & ssAtmosphere) {
453     outstream << delimeter;
454     outstream << Atmosphere->GetDensity() << delimeter;
455     outstream << Atmosphere->GetAbsoluteViscosity() << delimeter;
456     outstream << Atmosphere->GetKinematicViscosity() << delimeter;
457     outstream << Atmosphere->GetTemperature() << delimeter;
458     outstream << Atmosphere->GetPressureSL() << delimeter;
459     outstream << Atmosphere->GetPressure() << delimeter;
460     outstream << Winds->GetTurbMagnitude() << delimeter;
461     outstream << Winds->GetTurbDirection().Dump(delimeter) << delimeter;
462     outstream << Winds->GetTotalWindNED().Dump(delimeter);
463   }
464   if (SubSystems & ssMassProps) {
465     outstream << delimeter;
466     outstream << MassBalance->GetJ().Dump(delimeter) << delimeter;
467     outstream << MassBalance->GetMass() << delimeter;
468     outstream << MassBalance->GetXYZcg().Dump(delimeter);
469   }
470   if (SubSystems & ssPropagate) {
471     outstream.precision(14);
472     outstream << delimeter;
473     outstream << Propagate->GetAltitudeASL() << delimeter;
474     outstream << Propagate->GetDistanceAGL() << delimeter;
475     outstream << (radtodeg*Propagate->GetEuler()).Dump(delimeter) << delimeter;
476     outstream << Auxiliary->Getalpha(inDegrees) << delimeter;
477     outstream << Auxiliary->Getbeta(inDegrees) << delimeter;
478     outstream << Propagate->GetLocation().GetLatitudeDeg() << delimeter;
479     outstream << Propagate->GetLocation().GetLongitudeDeg() << delimeter;
480     outstream.precision(18);
481     outstream << ((FGColumnVector3)Propagate->GetInertialPosition()).Dump(delimeter) << delimeter;
482     outstream << ((FGColumnVector3)Propagate->GetLocation()).Dump(delimeter) << delimeter;
483     outstream.precision(14);
484     outstream << Propagate->GetEarthPositionAngleDeg() << delimeter;
485     outstream << Propagate->GetDistanceAGL() << delimeter;
486     outstream << Propagate->GetTerrainElevation();
487     outstream.precision(10);
488   }
489   if (SubSystems & ssAeroFunctions) {
490     scratch = Aerodynamics->GetAeroFunctionValues(delimeter);
491     if (scratch.length() != 0) outstream << delimeter << scratch;
492   }
493   if (SubSystems & ssFCS) {
494     scratch = FCS->GetComponentValues(delimeter);
495     if (scratch.length() != 0) outstream << delimeter << scratch;
496   }
497   if (SubSystems & ssGroundReactions) {
498     outstream << delimeter;
499     outstream << GroundReactions->GetGroundReactionValues(delimeter);
500   }
501   if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
502     outstream << delimeter;
503     outstream << Propulsion->GetPropulsionValues(delimeter);
504   }
505
506   outstream.precision(18);
507   for (unsigned int i=0;i<OutputProperties.size();i++) {
508     outstream << delimeter << OutputProperties[i]->getDoubleValue();
509   }
510   outstream.precision(10);
511
512   outstream << endl;
513   outstream.flush();
514 }
515
516 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
517
518 void FGOutput::SocketDataFill(FGNetFDM* net)
519 {
520   const FGAuxiliary* Auxiliary = FDMExec->GetAuxiliary();
521   const FGPropulsion* Propulsion = FDMExec->GetPropulsion();
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 FGAccelerations* Accelerations = FDMExec->GetAccelerations();
739   const FGFCS* FCS = FDMExec->GetFCS();
740   const FGAtmosphere* Atmosphere = FDMExec->GetAtmosphere();
741   const FGWinds* Winds = FDMExec->GetWinds();
742   const FGAircraft* Aircraft = FDMExec->GetAircraft();
743   const FGGroundReactions* GroundReactions = FDMExec->GetGroundReactions();
744
745   string asciiData, scratch;
746
747   if (socket == NULL) return;
748   if (!socket->GetConnectStatus()) return;
749
750   socket->Clear();
751   if (sFirstPass) {
752     socket->Clear("<LABELS>");
753     socket->Append("Time");
754
755     if (SubSystems & ssAerosurfaces) {
756       socket->Append("Aileron Command");
757       socket->Append("Elevator Command");
758       socket->Append("Rudder Command");
759       socket->Append("Flap Command");
760       socket->Append("Left Aileron Position");
761       socket->Append("Right Aileron Position");
762       socket->Append("Elevator Position");
763       socket->Append("Rudder Position");
764       socket->Append("Flap Position");
765     }
766
767     if (SubSystems & ssRates) {
768       socket->Append("P");
769       socket->Append("Q");
770       socket->Append("R");
771       socket->Append("PDot");
772       socket->Append("QDot");
773       socket->Append("RDot");
774     }
775
776     if (SubSystems & ssVelocities) {
777       socket->Append("QBar");
778       socket->Append("Vtotal");
779       socket->Append("UBody");
780       socket->Append("VBody");
781       socket->Append("WBody");
782       socket->Append("UAero");
783       socket->Append("VAero");
784       socket->Append("WAero");
785       socket->Append("Vn");
786       socket->Append("Ve");
787       socket->Append("Vd");
788     }
789     if (SubSystems & ssForces) {
790       socket->Append("F_Drag");
791       socket->Append("F_Side");
792       socket->Append("F_Lift");
793       socket->Append("LoD");
794       socket->Append("Fx");
795       socket->Append("Fy");
796       socket->Append("Fz");
797     }
798     if (SubSystems & ssMoments) {
799       socket->Append("L");
800       socket->Append("M");
801       socket->Append("N");
802     }
803     if (SubSystems & ssAtmosphere) {
804       socket->Append("Rho");
805       socket->Append("SL pressure");
806       socket->Append("Ambient pressure");
807       socket->Append("Turbulence Magnitude");
808       socket->Append("Turbulence Direction X");
809       socket->Append("Turbulence Direction Y");
810       socket->Append("Turbulence Direction Z");
811       socket->Append("NWind");
812       socket->Append("EWind");
813       socket->Append("DWind");
814     }
815     if (SubSystems & ssMassProps) {
816       socket->Append("Ixx");
817       socket->Append("Ixy");
818       socket->Append("Ixz");
819       socket->Append("Iyx");
820       socket->Append("Iyy");
821       socket->Append("Iyz");
822       socket->Append("Izx");
823       socket->Append("Izy");
824       socket->Append("Izz");
825       socket->Append("Mass");
826       socket->Append("Xcg");
827       socket->Append("Ycg");
828       socket->Append("Zcg");
829     }
830     if (SubSystems & ssPropagate) {
831         socket->Append("Altitude");
832         socket->Append("Phi (deg)");
833         socket->Append("Tht (deg)");
834         socket->Append("Psi (deg)");
835         socket->Append("Alpha (deg)");
836         socket->Append("Beta (deg)");
837         socket->Append("Latitude (deg)");
838         socket->Append("Longitude (deg)");
839     }
840     if (SubSystems & ssAeroFunctions) {
841       scratch = Aerodynamics->GetAeroFunctionStrings(",");
842       if (scratch.length() != 0) socket->Append(scratch);
843     }
844     if (SubSystems & ssFCS) {
845       scratch = FCS->GetComponentStrings(",");
846       if (scratch.length() != 0) socket->Append(scratch);
847     }
848     if (SubSystems & ssGroundReactions) {
849       socket->Append(GroundReactions->GetGroundReactionStrings(","));
850     }
851     if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
852       socket->Append(Propulsion->GetPropulsionStrings(","));
853     }
854     if (OutputProperties.size() > 0) {
855       for (unsigned int i=0;i<OutputProperties.size();i++) {
856         socket->Append(OutputProperties[i]->GetPrintableName());
857       }
858     }
859
860     sFirstPass = false;
861     socket->Send();
862   }
863
864   socket->Clear();
865   socket->Append(FDMExec->GetSimTime());
866
867   if (SubSystems & ssAerosurfaces) {
868     socket->Append(FCS->GetDaCmd());
869     socket->Append(FCS->GetDeCmd());
870     socket->Append(FCS->GetDrCmd());
871     socket->Append(FCS->GetDfCmd());
872     socket->Append(FCS->GetDaLPos());
873     socket->Append(FCS->GetDaRPos());
874     socket->Append(FCS->GetDePos());
875     socket->Append(FCS->GetDrPos());
876     socket->Append(FCS->GetDfPos());
877   }
878   if (SubSystems & ssRates) {
879     socket->Append(radtodeg*Propagate->GetPQR(eP));
880     socket->Append(radtodeg*Propagate->GetPQR(eQ));
881     socket->Append(radtodeg*Propagate->GetPQR(eR));
882     socket->Append(radtodeg*Accelerations->GetPQRdot(eP));
883     socket->Append(radtodeg*Accelerations->GetPQRdot(eQ));
884     socket->Append(radtodeg*Accelerations->GetPQRdot(eR));
885   }
886   if (SubSystems & ssVelocities) {
887     socket->Append(Auxiliary->Getqbar());
888     socket->Append(Auxiliary->GetVt());
889     socket->Append(Propagate->GetUVW(eU));
890     socket->Append(Propagate->GetUVW(eV));
891     socket->Append(Propagate->GetUVW(eW));
892     socket->Append(Auxiliary->GetAeroUVW(eU));
893     socket->Append(Auxiliary->GetAeroUVW(eV));
894     socket->Append(Auxiliary->GetAeroUVW(eW));
895     socket->Append(Propagate->GetVel(eNorth));
896     socket->Append(Propagate->GetVel(eEast));
897     socket->Append(Propagate->GetVel(eDown));
898   }
899   if (SubSystems & ssForces) {
900     socket->Append(Aerodynamics->GetvFw()(eDrag));
901     socket->Append(Aerodynamics->GetvFw()(eSide));
902     socket->Append(Aerodynamics->GetvFw()(eLift));
903     socket->Append(Aerodynamics->GetLoD());
904     socket->Append(Aircraft->GetForces(eX));
905     socket->Append(Aircraft->GetForces(eY));
906     socket->Append(Aircraft->GetForces(eZ));
907   }
908   if (SubSystems & ssMoments) {
909     socket->Append(Aircraft->GetMoments(eL));
910     socket->Append(Aircraft->GetMoments(eM));
911     socket->Append(Aircraft->GetMoments(eN));
912   }
913   if (SubSystems & ssAtmosphere) {
914     socket->Append(Atmosphere->GetDensity());
915     socket->Append(Atmosphere->GetPressureSL());
916     socket->Append(Atmosphere->GetPressure());
917     socket->Append(Winds->GetTurbMagnitude());
918     socket->Append(Winds->GetTurbDirection().Dump(","));
919     socket->Append(Winds->GetTotalWindNED().Dump(","));
920   }
921   if (SubSystems & ssMassProps) {
922     socket->Append(MassBalance->GetJ()(1,1));
923     socket->Append(MassBalance->GetJ()(1,2));
924     socket->Append(MassBalance->GetJ()(1,3));
925     socket->Append(MassBalance->GetJ()(2,1));
926     socket->Append(MassBalance->GetJ()(2,2));
927     socket->Append(MassBalance->GetJ()(2,3));
928     socket->Append(MassBalance->GetJ()(3,1));
929     socket->Append(MassBalance->GetJ()(3,2));
930     socket->Append(MassBalance->GetJ()(3,3));
931     socket->Append(MassBalance->GetMass());
932     socket->Append(MassBalance->GetXYZcg()(eX));
933     socket->Append(MassBalance->GetXYZcg()(eY));
934     socket->Append(MassBalance->GetXYZcg()(eZ));
935   }
936   if (SubSystems & ssPropagate) {
937     socket->Append(Propagate->GetAltitudeASL());
938     socket->Append(radtodeg*Propagate->GetEuler(ePhi));
939     socket->Append(radtodeg*Propagate->GetEuler(eTht));
940     socket->Append(radtodeg*Propagate->GetEuler(ePsi));
941     socket->Append(Auxiliary->Getalpha(inDegrees));
942     socket->Append(Auxiliary->Getbeta(inDegrees));
943     socket->Append(Propagate->GetLocation().GetLatitudeDeg());
944     socket->Append(Propagate->GetLocation().GetLongitudeDeg());
945   }
946   if (SubSystems & ssAeroFunctions) {
947     scratch = Aerodynamics->GetAeroFunctionValues(",");
948     if (scratch.length() != 0) socket->Append(scratch);
949   }
950   if (SubSystems & ssFCS) {
951     scratch = FCS->GetComponentValues(",");
952     if (scratch.length() != 0) socket->Append(scratch);
953   }
954   if (SubSystems & ssGroundReactions) {
955     socket->Append(GroundReactions->GetGroundReactionValues(","));
956   }
957   if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
958     socket->Append(Propulsion->GetPropulsionValues(","));
959   }
960
961   for (unsigned int i=0;i<OutputProperties.size();i++) {
962     socket->Append(OutputProperties[i]->getDoubleValue());
963   }
964
965   socket->Send();
966 }
967
968 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
969
970 void FGOutput::SocketStatusOutput(const string& out_str)
971 {
972   string asciiData;
973
974   if (socket == NULL) return;
975
976   socket->Clear();
977   asciiData = string("<STATUS>") + out_str;
978   socket->Append(asciiData.c_str());
979   socket->Send();
980 }
981
982 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
983
984 bool FGOutput::Load(int subSystems, std::string protocol, std::string  type, std::string port, std::string name, double outRate, std::vector<FGPropertyManager *> & outputProperties)
985 {
986   SetType(type);
987   SetRate(outRate);
988   SubSystems = subSystems;
989   OutputProperties = outputProperties;
990
991   if (((Type == otCSV) || (Type == otTab)) && (name != "cout") && (name !="COUT"))
992     name = FDMExec->GetRootDir() + name;
993
994   if (!port.empty() && (Type == otSocket || Type == otFlightGear)) {
995     SetProtocol(protocol);
996     socket = new FGfdmSocket(name, atoi(port.c_str()), Protocol);
997   } else {
998     BaseFilename = Filename = name;
999   }
1000
1001   Debug(2);
1002   return true;
1003 }
1004
1005 bool FGOutput::Load(Element* element)
1006 {
1007   int subSystems = 0;
1008   Element *property_element;
1009   std::vector<FGPropertyManager *> outputProperties;
1010
1011   if (!DirectivesFile.empty()) { // A directives filename from the command line overrides
1012     output_file_name = DirectivesFile;      // one found in the config file.
1013     document = LoadXMLDocument(output_file_name);
1014   } else if (!element->GetAttributeValue("file").empty()) {
1015     output_file_name = FDMExec->GetRootDir() + element->GetAttributeValue("file");
1016     document = LoadXMLDocument(output_file_name);
1017   } else {
1018     document = element;
1019   }
1020
1021   if (!document) return false;
1022
1023   string type = document->GetAttributeValue("type");
1024   string name = document->GetAttributeValue("name");
1025   string port = document->GetAttributeValue("port");
1026   string protocol = document->GetAttributeValue("protocol");
1027   if (!document->GetAttributeValue("rate").empty()) {
1028     rate = document->GetAttributeValueAsNumber("rate");
1029   } else {
1030     rate = 1;
1031   }
1032
1033   if (document->FindElementValue("simulation") == string("ON"))
1034     subSystems += ssSimulation;
1035   if (document->FindElementValue("aerosurfaces") == string("ON"))
1036     subSystems += ssAerosurfaces;
1037   if (document->FindElementValue("rates") == string("ON"))
1038     subSystems += ssRates;
1039   if (document->FindElementValue("velocities") == string("ON"))
1040     subSystems += ssVelocities;
1041   if (document->FindElementValue("forces") == string("ON"))
1042     subSystems += ssForces;
1043   if (document->FindElementValue("moments") == string("ON"))
1044     subSystems += ssMoments;
1045   if (document->FindElementValue("atmosphere") == string("ON"))
1046     subSystems += ssAtmosphere;
1047   if (document->FindElementValue("massprops") == string("ON"))
1048     subSystems += ssMassProps;
1049   if (document->FindElementValue("position") == string("ON"))
1050     subSystems += ssPropagate;
1051   if (document->FindElementValue("coefficients") == string("ON") || document->FindElementValue("aerodynamics") == string("ON"))
1052     subSystems += ssAeroFunctions;
1053   if (document->FindElementValue("ground_reactions") == string("ON"))
1054     subSystems += ssGroundReactions;
1055   if (document->FindElementValue("fcs") == string("ON"))
1056     subSystems += ssFCS;
1057   if (document->FindElementValue("propulsion") == string("ON"))
1058     subSystems += ssPropulsion;
1059   property_element = document->FindElement("property");
1060   while (property_element) {
1061     string property_str = property_element->GetDataLine();
1062     FGPropertyManager* node = PropertyManager->GetNode(property_str);
1063     if (!node) {
1064       cerr << fgred << highint << endl << "  No property by the name "
1065            << property_str << " has been defined. This property will " << endl
1066            << "  not be logged. You should check your configuration file."
1067            << reset << endl;
1068     } else {
1069       outputProperties.push_back(node);
1070     }
1071     property_element = document->FindNextElement("property");
1072   }
1073
1074   return Load(subSystems, protocol, type, port, name, rate, outputProperties);
1075 }
1076
1077
1078
1079 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1080
1081 void FGOutput::SetRate(double rtHz)
1082 {
1083   rtHz = rtHz>1000?1000:(rtHz<0?0:rtHz);
1084   if (rtHz > 0) {
1085     rate = (int)(0.5 + 1.0/(FDMExec->GetDeltaT()*rtHz));
1086     Enable();
1087   } else {
1088     rate = 1;
1089     Disable();
1090   }
1091 }
1092
1093 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1094 //    The bitmasked value choices are as follows:
1095 //    unset: In this case (the default) JSBSim would only print
1096 //       out the normally expected messages, essentially echoing
1097 //       the config files as they are read. If the environment
1098 //       variable is not set, debug_lvl is set to 1 internally
1099 //    0: This requests JSBSim not to output any messages
1100 //       whatsoever.
1101 //    1: This value explicity requests the normal JSBSim
1102 //       startup messages
1103 //    2: This value asks for a message to be printed out when
1104 //       a class is instantiated
1105 //    4: When this value is set, a message is displayed when a
1106 //       FGModel object executes its Run() method
1107 //    8: When this value is set, various runtime state variables
1108 //       are printed out periodically
1109 //    16: When set various parameters are sanity checked and
1110 //       a message is printed out when they go out of bounds
1111
1112 void FGOutput::Debug(int from)
1113 {
1114   string scratch="";
1115
1116   if (debug_lvl <= 0) return;
1117
1118   if (debug_lvl & 1) { // Standard console startup message output
1119     if (from == 0) { // Constructor
1120
1121     }
1122     if (from == 2) {
1123       if (output_file_name.empty())
1124         cout << "  " << "Output parameters read inline" << endl;
1125       else
1126         cout << "    Output parameters read from file: " << output_file_name << endl;
1127
1128       if (Filename == "cout" || Filename == "COUT") {
1129         scratch = "    Log output goes to screen console";
1130       } else if (!Filename.empty()) {
1131         scratch = "    Log output goes to file: " + Filename;
1132       }
1133       switch (Type) {
1134       case otCSV:
1135         cout << scratch << " in CSV format output at rate " << 1/(FDMExec->GetDeltaT()*rate) << " Hz" << endl;
1136         break;
1137       case otNone:
1138       default:
1139         cout << "  No log output" << endl;
1140         break;
1141       }
1142
1143       if (SubSystems & ssSimulation)      cout << "    Simulation parameters logged" << endl;
1144       if (SubSystems & ssAerosurfaces)    cout << "    Aerosurface parameters logged" << endl;
1145       if (SubSystems & ssRates)           cout << "    Rate parameters logged" << endl;
1146       if (SubSystems & ssVelocities)      cout << "    Velocity parameters logged" << endl;
1147       if (SubSystems & ssForces)          cout << "    Force parameters logged" << endl;
1148       if (SubSystems & ssMoments)         cout << "    Moments parameters logged" << endl;
1149       if (SubSystems & ssAtmosphere)      cout << "    Atmosphere parameters logged" << endl;
1150       if (SubSystems & ssMassProps)       cout << "    Mass parameters logged" << endl;
1151       if (SubSystems & ssAeroFunctions)    cout << "    Coefficient parameters logged" << endl;
1152       if (SubSystems & ssPropagate)       cout << "    Propagate parameters logged" << endl;
1153       if (SubSystems & ssGroundReactions) cout << "    Ground parameters logged" << endl;
1154       if (SubSystems & ssFCS)             cout << "    FCS parameters logged" << endl;
1155       if (SubSystems & ssPropulsion)      cout << "    Propulsion parameters logged" << endl;
1156       if (OutputProperties.size() > 0)    cout << "    Properties logged:" << endl;
1157       for (unsigned int i=0;i<OutputProperties.size();i++) {
1158         cout << "      - " << OutputProperties[i]->GetName() << endl;
1159       }
1160     }
1161   }
1162   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
1163     if (from == 0) cout << "Instantiated: FGOutput" << endl;
1164     if (from == 1) cout << "Destroyed:    FGOutput" << endl;
1165   }
1166   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
1167   }
1168   if (debug_lvl & 8 ) { // Runtime state variables
1169   }
1170   if (debug_lvl & 16) { // Sanity checking
1171   }
1172   if (debug_lvl & 64) {
1173     if (from == 0) { // Constructor
1174       cout << IdSrc << endl;
1175       cout << IdHdr << endl;
1176     }
1177   }
1178 }
1179 }