JSBSim Flight Dynamics Model 1.2.2 (22 Mar 2025)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGOutputTextFile.cpp
1/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 Module: FGOutputTextFile.cpp
4 Author: Bertrand Coconnier
5 Date started: 09/17/11
6 Purpose: Manage output of sim parameters to a text file
7 Called by: FGOutput
8
9 ------------- Copyright (C) 2011 Bertrand Coconnier -------------
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
13 Software Foundation; either version 2 of the License, or (at your option) any
14 later 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
22 with this program; if not, write to the Free Software Foundation, Inc., 59
23 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25 Further information about the GNU Lesser General Public License can also be
26 found on the world wide web at http://www.gnu.org.
27
28FUNCTIONAL DESCRIPTION
29--------------------------------------------------------------------------------
30This is the place where you create output routines to dump data for perusal
31later.
32
33HISTORY
34--------------------------------------------------------------------------------
3509/17/11 BC Created
36
37%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38INCLUDES
39%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41#include <iomanip>
42
43#include "FGOutputTextFile.h"
44#include "models/FGAerodynamics.h"
45#include "models/FGAccelerations.h"
46#include "models/FGAtmosphere.h"
47#include "models/FGAuxiliary.h"
48#include "models/FGPropulsion.h"
49#include "models/FGMassBalance.h"
50#include "models/FGExternalReactions.h"
51#include "models/FGBuoyantForces.h"
52#include "models/FGFCS.h"
53#include "models/atmosphere/FGWinds.h"
54#include "input_output/FGXMLElement.h"
55#include "input_output/string_utilities.h"
56
57using namespace std;
58
59namespace JSBSim {
60
61/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62CLASS IMPLEMENTATION
63%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64
66{
67 if(!FGOutputFile::Load(el))
68 return false;
69
70 string type = el->GetAttributeValue("type");
71 string delim;
72 if (type == "TABULAR") {
73 delim = "\t";
74 } else {
75 delim = ",";
76 }
77
78 SetDelimiter(delim);
79
80 return true;
81}
82
83//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84
86{
87 datafile.clear();
88 datafile.open(Filename);
89 if (!datafile) {
90 cerr << endl << fgred << highint << "ERROR: unable to open the file "
91 << reset << Filename.c_str() << endl
92 << fgred << highint << " => Output to this file is disabled."
93 << reset << endl << endl;
94 Disable();
95 return false;
96 }
97
98 string scratch = "";
99 streambuf* buffer = datafile.rdbuf();
100 ostream outstream(buffer);
101
102 outstream.precision(10);
103
104 outstream << "Time";
105 if (SubSystems & ssSimulation) {
106 // Nothing here, yet
107 }
108 if (SubSystems & ssAerosurfaces) {
109 outstream << delimeter;
110 outstream << "Aileron Command (norm)" + delimeter;
111 outstream << "Elevator Command (norm)" + delimeter;
112 outstream << "Rudder Command (norm)" + delimeter;
113 outstream << "Flap Command (norm)" + delimeter;
114 outstream << "Left Aileron Position (deg)" + delimeter;
115 outstream << "Right Aileron Position (deg)" + delimeter;
116 outstream << "Elevator Position (deg)" + delimeter;
117 outstream << "Rudder Position (deg)" + delimeter;
118 outstream << "Flap Position (deg)";
119 }
120 if (SubSystems & ssRates) {
121 outstream << delimeter;
122 outstream << "P (deg/s)" + delimeter + "Q (deg/s)" + delimeter + "R (deg/s)" + delimeter;
123 outstream << "P dot (deg/s^2)" + delimeter + "Q dot (deg/s^2)" + delimeter + "R dot (deg/s^2)" + delimeter;
124 outstream << "P_{inertial} (deg/s)" + delimeter + "Q_{inertial} (deg/s)" + delimeter + "R_{inertial} (deg/s)";
125 }
126 if (SubSystems & ssVelocities) {
127 outstream << delimeter;
128 outstream << "q bar (psf)" + delimeter;
129 outstream << "Reynolds Number" + delimeter;
130 outstream << "V_{Total} (ft/s)" + delimeter;
131 outstream << "V_{Inertial} (ft/s)" + delimeter;
132 outstream << "UBody" + delimeter + "VBody" + delimeter + "WBody" + delimeter;
133 outstream << "UdotBody" + delimeter + "VdotBody" + delimeter + "WdotBody" + delimeter;
134 outstream << "UdotBody_i" + delimeter + "VdotBody_i" + delimeter + "WdotBody_i" + delimeter;
135 outstream << "BodyAccel_X" + delimeter + "BodyAccel_Y" + delimeter + "BodyAccel_Z" + delimeter;
136 outstream << "Aero V_{X Body} (ft/s)" + delimeter + "Aero V_{Y Body} (ft/s)" + delimeter + "Aero V_{Z Body} (ft/s)" + delimeter;
137 outstream << "V_{X_{inertial}} (ft/s)" + delimeter + "V_{Y_{inertial}} (ft/s)" + delimeter + "V_{Z_{inertial}} (ft/s)" + delimeter;
138 outstream << "V_{X_{ecef}} (ft/s)" + delimeter + "V_{Y_{ecef}} (ft/s)" + delimeter + "V_{Z_{ecef}} (ft/s)" + delimeter;
139 outstream << "V_{North} (ft/s)" + delimeter + "V_{East} (ft/s)" + delimeter + "V_{Down} (ft/s)";
140 }
141 if (SubSystems & ssForces) {
142 outstream << delimeter;
143 outstream << "F_{Drag} (lbs)" + delimeter + "F_{Side} (lbs)" + delimeter + "F_{Lift} (lbs)" + delimeter;
144 outstream << "L/D" + delimeter;
145 outstream << "F_{Aero x} (lbs)" + delimeter + "F_{Aero y} (lbs)" + delimeter + "F_{Aero z} (lbs)" + delimeter;
146 outstream << "F_{Prop x} (lbs)" + delimeter + "F_{Prop y} (lbs)" + delimeter + "F_{Prop z} (lbs)" + delimeter;
147 outstream << "F_{Gear x} (lbs)" + delimeter + "F_{Gear y} (lbs)" + delimeter + "F_{Gear z} (lbs)" + delimeter;
148 outstream << "F_{Ext x} (lbs)" + delimeter + "F_{Ext y} (lbs)" + delimeter + "F_{Ext z} (lbs)" + delimeter;
149 outstream << "F_{Buoyant x} (lbs)" + delimeter + "F_{Buoyant y} (lbs)" + delimeter + "F_{Buoyant z} (lbs)" + delimeter;
150 outstream << "F_{Weight x} (lbs)" + delimeter + "F_{Weight y} (lbs)" + delimeter + "F_{Weight z} (lbs)" + delimeter;
151 outstream << "F_{Total x} (lbs)" + delimeter + "F_{Total y} (lbs)" + delimeter + "F_{Total z} (lbs)";
152 }
153 if (SubSystems & ssMoments) {
154 outstream << delimeter;
155 outstream << "L_{Aero} (ft-lbs)" + delimeter + "M_{Aero} (ft-lbs)" + delimeter + "N_{Aero} (ft-lbs)" + delimeter;
156 outstream << "L_{Aero MRC} (ft-lbs)" + delimeter + "M_{Aero MRC} (ft-lbs)" + delimeter + "N_{Aero MRC} (ft-lbs)" + delimeter;
157 outstream << "L_{Prop} (ft-lbs)" + delimeter + "M_{Prop} (ft-lbs)" + delimeter + "N_{Prop} (ft-lbs)" + delimeter;
158 outstream << "L_{Gear} (ft-lbs)" + delimeter + "M_{Gear} (ft-lbs)" + delimeter + "N_{Gear} (ft-lbs)" + delimeter;
159 outstream << "L_{ext} (ft-lbs)" + delimeter + "M_{ext} (ft-lbs)" + delimeter + "N_{ext} (ft-lbs)" + delimeter;
160 outstream << "L_{Buoyant} (ft-lbs)" + delimeter + "M_{Buoyant} (ft-lbs)" + delimeter + "N_{Buoyant} (ft-lbs)" + delimeter;
161 outstream << "L_{Total} (ft-lbs)" + delimeter + "M_{Total} (ft-lbs)" + delimeter + "N_{Total} (ft-lbs)";
162 }
163 if (SubSystems & ssAtmosphere) {
164 outstream << delimeter;
165 outstream << "Rho (slugs/ft^3)" + delimeter;
166 outstream << "Absolute Viscosity" + delimeter;
167 outstream << "Kinematic Viscosity" + delimeter;
168 outstream << "Temperature (R)" + delimeter;
169 outstream << "P_{SL} (psf)" + delimeter;
170 outstream << "P_{Ambient} (psf)" + delimeter;
171 outstream << "Turbulence Magnitude (ft/sec)" + delimeter;
172 outstream << "Turbulence X Direction (deg)" + delimeter;
173 outstream << "Wind V_{North} (ft/s)" + delimeter + "Wind V_{East} (ft/s)" + delimeter + "Wind V_{Down} (ft/s)" + delimeter;
174 outstream << "Roll Turbulence (deg/sec)" + delimeter + "Pitch Turbulence (deg/sec)" + delimeter + "Yaw Turbulence (deg/sec)";
175 }
176 if (SubSystems & ssMassProps) {
177 outstream << delimeter;
178 outstream << "I_{xx}" + delimeter;
179 outstream << "I_{xy}" + delimeter;
180 outstream << "I_{xz}" + delimeter;
181 outstream << "I_{yx}" + delimeter;
182 outstream << "I_{yy}" + delimeter;
183 outstream << "I_{yz}" + delimeter;
184 outstream << "I_{zx}" + delimeter;
185 outstream << "I_{zy}" + delimeter;
186 outstream << "I_{zz}" + delimeter;
187 outstream << "Mass" + delimeter;
188 outstream << "Weight" + delimeter;
189 outstream << "X_{cg}" + delimeter + "Y_{cg}" + delimeter + "Z_{cg}";
190 }
191 if (SubSystems & ssPropagate) {
192 outstream << delimeter;
193 outstream << "Altitude ASL (ft)" + delimeter;
194 outstream << "Altitude AGL (ft)" + delimeter;
195 outstream << "Phi (deg)" + delimeter + "Theta (deg)" + delimeter + "Psi (deg)" + delimeter;
196 outstream << "Q(1)_{LOCAL}" + delimeter + "Q(2)_{LOCAL}" + delimeter + "Q(3)_{LOCAL}" + delimeter + "Q(4)_{LOCAL}" + delimeter;
197 outstream << "Q(1)_{ECEF}" + delimeter + "Q(2)_{ECEF}" + delimeter + "Q(3)_{ECEF}" + delimeter + "Q(4)_{ECEF}" + delimeter;
198 outstream << "Q(1)_{ECI}" + delimeter + "Q(2)_{ECI}" + delimeter + "Q(3)_{ECI}" + delimeter + "Q(4)_{ECI}" + delimeter;
199 outstream << "Alpha (deg)" + delimeter;
200 outstream << "Beta (deg)" + delimeter;
201 outstream << "Latitude (deg)" + delimeter;
202 outstream << "Latitude Geodetic (deg)" + delimeter;
203 outstream << "Longitude (deg)" + delimeter;
204 outstream << "X_{ECI} (ft)" + delimeter + "Y_{ECI} (ft)" + delimeter + "Z_{ECI} (ft)" + delimeter;
205 outstream << "X_{ECEF} (ft)" + delimeter + "Y_{ECEF} (ft)" + delimeter + "Z_{ECEF} (ft)" + delimeter;
206 outstream << "Earth Position Angle (deg)" + delimeter;
207 outstream << "Distance AGL (ft)" + delimeter;
208 outstream << "Terrain Elevation (ft)";
209 }
210 if (SubSystems & ssAeroFunctions) {
211 scratch = Aerodynamics->GetAeroFunctionStrings(delimeter);
212 if (scratch.length() != 0) outstream << delimeter << scratch;
213 }
214 if (SubSystems & ssFCS) {
215 scratch = FCS->GetComponentStrings(delimeter);
216 if (scratch.length() != 0) outstream << delimeter << scratch;
217 }
218 if (SubSystems & ssGroundReactions) {
219 outstream << delimeter;
220 outstream << GroundReactions->GetGroundReactionStrings(delimeter);
221 }
222 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
223 outstream << delimeter;
224 outstream << Propulsion->GetPropulsionStrings(delimeter);
225 }
226
227 for (unsigned int i=0;i<OutputParameters.size();++i) {
228 if (!OutputCaptions[i].empty())
229 outstream << delimeter << OutputCaptions[i];
230 else
231 outstream << delimeter << OutputParameters[i]->GetFullyQualifiedName();
232 }
233
234 if (!PreFunctions.empty()) {
235 for (unsigned int i=0;i<PreFunctions.size();i++) {
236 outstream << delimeter << PreFunctions[i]->GetName();
237 }
238 }
239
240 outstream << endl;
241 outstream.flush();
242
243 return true;
244}
245
246//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247
249{
250 streambuf* buffer;
251 string scratch = Filename.utf8Str();
252
253 if (to_upper(scratch) == "COUT") {
254 buffer = cout.rdbuf();
255 } else {
256 buffer = datafile.rdbuf();
257 }
258
259 ostream outstream(buffer);
260
261 outstream.precision(10);
262
263 outstream << FDMExec->GetSimTime();
264 if (SubSystems & ssSimulation) {
265 }
266 if (SubSystems & ssAerosurfaces) {
267 outstream << delimeter;
268 outstream << FCS->GetDaCmd() << delimeter;
269 outstream << FCS->GetDeCmd() << delimeter;
270 outstream << FCS->GetDrCmd() << delimeter;
271 outstream << FCS->GetDfCmd() << delimeter;
272 outstream << FCS->GetDaLPos(ofDeg) << delimeter;
273 outstream << FCS->GetDaRPos(ofDeg) << delimeter;
274 outstream << FCS->GetDePos(ofDeg) << delimeter;
275 outstream << FCS->GetDrPos(ofDeg) << delimeter;
276 outstream << FCS->GetDfPos(ofDeg);
277 }
278 if (SubSystems & ssRates) {
279 outstream << delimeter;
280 outstream << (radtodeg*Propagate->GetPQR()).Dump(delimeter) << delimeter;
281 outstream << (radtodeg*Accelerations->GetPQRdot()).Dump(delimeter) << delimeter;
282 outstream << (radtodeg*Propagate->GetPQRi()).Dump(delimeter);
283 }
284 if (SubSystems & ssVelocities) {
285 outstream << delimeter;
286 outstream << Auxiliary->Getqbar() << delimeter;
287 outstream << Auxiliary->GetReynoldsNumber() << delimeter;
288 outstream << setprecision(12) << Auxiliary->GetVt() << delimeter;
289 outstream << Propagate->GetInertialVelocityMagnitude() << delimeter;
290 outstream << setprecision(12) << Propagate->GetUVW().Dump(delimeter) << delimeter;
291 outstream << setprecision(12) << Accelerations->GetUVWdot().Dump(delimeter) << delimeter;
292 outstream << setprecision(12) << Accelerations->GetUVWidot().Dump(delimeter) << delimeter;
293 outstream << setprecision(12) << Accelerations->GetBodyAccel().Dump(delimeter) << delimeter;
294 outstream << Auxiliary->GetAeroUVW().Dump(delimeter) << delimeter;
295 outstream << Propagate->GetInertialVelocity().Dump(delimeter) << delimeter;
296 outstream << Propagate->GetECEFVelocity().Dump(delimeter) << delimeter;
297 outstream << Propagate->GetVel().Dump(delimeter);
298 outstream.precision(10);
299 }
300 if (SubSystems & ssForces) {
301 outstream << delimeter;
302 outstream << Aerodynamics->GetvFw().Dump(delimeter) << delimeter;
303 outstream << Aerodynamics->GetLoD() << delimeter;
304 outstream << Aerodynamics->GetForces().Dump(delimeter) << delimeter;
305 outstream << Propulsion->GetForces().Dump(delimeter) << delimeter;
306 outstream << Accelerations->GetGroundForces().Dump(delimeter) << delimeter;
307 outstream << ExternalReactions->GetForces().Dump(delimeter) << delimeter;
308 outstream << BuoyantForces->GetForces().Dump(delimeter) << delimeter;
309 outstream << Accelerations->GetWeight().Dump(delimeter) << delimeter;
310 outstream << Accelerations->GetForces().Dump(delimeter);
311 }
312 if (SubSystems & ssMoments) {
313 outstream << delimeter;
314 outstream << Aerodynamics->GetMoments().Dump(delimeter) << delimeter;
315 outstream << Aerodynamics->GetMomentsMRC().Dump(delimeter) << delimeter;
316 outstream << Propulsion->GetMoments().Dump(delimeter) << delimeter;
317 outstream << Accelerations->GetGroundMoments().Dump(delimeter) << delimeter;
318 outstream << ExternalReactions->GetMoments().Dump(delimeter) << delimeter;
319 outstream << BuoyantForces->GetMoments().Dump(delimeter) << delimeter;
320 outstream << Accelerations->GetMoments().Dump(delimeter);
321 }
322 if (SubSystems & ssAtmosphere) {
323 const auto Atmosphere = FDMExec->GetAtmosphere();
324 outstream << delimeter;
325 outstream << Atmosphere->GetDensity() << delimeter;
326 outstream << Atmosphere->GetAbsoluteViscosity() << delimeter;
327 outstream << Atmosphere->GetKinematicViscosity() << delimeter;
328 outstream << Atmosphere->GetTemperature() << delimeter;
329 outstream << Atmosphere->GetPressureSL() << delimeter;
330 outstream << Atmosphere->GetPressure() << delimeter;
331 outstream << Winds->GetTurbMagnitude() << delimeter;
332 outstream << Winds->GetTurbDirection() << delimeter;
333 outstream << Winds->GetTotalWindNED().Dump(delimeter) << delimeter;
334 outstream << (Winds->GetTurbPQR()*radtodeg).Dump(delimeter);
335 }
336 if (SubSystems & ssMassProps) {
337 outstream << delimeter;
338 outstream << MassBalance->GetJ().Dump(delimeter) << delimeter;
339 outstream << MassBalance->GetMass() << delimeter;
340 outstream << MassBalance->GetWeight() << delimeter;
341 outstream << MassBalance->GetXYZcg().Dump(delimeter);
342 }
343 if (SubSystems & ssPropagate) {
344 outstream.precision(14);
345 outstream << delimeter;
346 outstream << Propagate->GetAltitudeASL() << delimeter;
347 outstream << Propagate->GetDistanceAGL() << delimeter;
348 outstream << (radtodeg*Propagate->GetEuler()).Dump(delimeter) << delimeter;
349 outstream << Propagate->GetQuaternion().Dump(delimeter) << delimeter;
350 FGQuaternion Qec = Propagate->GetQuaternionECEF();
351 outstream << Qec.Dump(delimeter) << delimeter;
352 outstream << Propagate->GetQuaternionECI().Dump(delimeter) << delimeter;
353 outstream << Auxiliary->Getalpha(inDegrees) << delimeter;
354 outstream << Auxiliary->Getbeta(inDegrees) << delimeter;
355 outstream << Propagate->GetLatitudeDeg() << delimeter;
356 outstream << Propagate->GetGeodLatitudeDeg() << delimeter;
357 outstream << Propagate->GetLongitudeDeg() << delimeter;
358 outstream.precision(18);
359 outstream << ((FGColumnVector3)Propagate->GetInertialPosition()).Dump(delimeter) << delimeter;
360 outstream << ((FGColumnVector3)Propagate->GetLocation()).Dump(delimeter) << delimeter;
361 outstream.precision(14);
362 outstream << Propagate->GetEarthPositionAngleDeg() << delimeter;
363 outstream << Propagate->GetDistanceAGL() << delimeter;
364 outstream << Propagate->GetTerrainElevation();
365 outstream.precision(10);
366 }
367 if (SubSystems & ssAeroFunctions) {
368 scratch = Aerodynamics->GetAeroFunctionValues(delimeter);
369 if (scratch.length() != 0) outstream << delimeter << scratch;
370 }
371 if (SubSystems & ssFCS) {
372 scratch = FCS->GetComponentValues(delimeter);
373 if (scratch.length() != 0) outstream << delimeter << scratch;
374 }
375 if (SubSystems & ssGroundReactions) {
376 outstream << delimeter;
377 outstream << GroundReactions->GetGroundReactionValues(delimeter);
378 }
379 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
380 outstream << delimeter;
381 outstream << Propulsion->GetPropulsionValues(delimeter);
382 }
383
384 outstream.precision(18);
385 for (unsigned int i=0;i<OutputParameters.size();++i) {
386 outstream << delimeter << OutputParameters[i]->GetValue();
387 }
388 for (unsigned int i=0;i<PreFunctions.size();i++) {
389 outstream << delimeter << PreFunctions[i]->getDoubleValue();
390 }
391 outstream.precision(10);
392
393 outstream << endl;
394 outstream.flush();
395}
396}
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
This class implements a 3 element column vector.
double GetSimTime(void) const
Returns the cumulative simulation time in seconds.
Definition FGFDMExec.h:549
static char fgred[6]
red text
Definition FGJSBBase.h:166
static char reset[5]
resets text properties
Definition FGJSBBase.h:156
static char highint[5]
highlights text
Definition FGJSBBase.h:150
bool Load(Element *el) override
Init the output directives from an XML file.
bool OpenFile(void) override
Opens the file.
bool Load(Element *el) override
Init the output directives from an XML file.
void Print(void) override
Generates the output to the text file.
void SetDelimiter(const std::string &delim)
Set the delimiter.
void Disable(void)
Disables the output generation.
@ ssPropulsion
Subsystem: Propulsion (= 4096)
@ ssForces
Subsystem: Forces (= 16)
@ ssAtmosphere
Subsystem: Atmosphere (= 64)
@ ssPropagate
Subsystem: Propagate (= 512)
@ ssGroundReactions
Subsystem: Ground Reactions (= 1024)
@ ssFCS
Subsystem: FCS (= 2048)
@ ssMoments
Subsystem: Moments (= 32)
@ ssRates
Subsystem: Body rates (= 4)
@ ssVelocities
Subsystem: Velocities (= 8)
@ ssAerosurfaces
Subsystem: Aerosurfaces (= 2)
@ ssMassProps
Subsystem: Mass Properties (= 128)
@ ssSimulation
Subsystem: Simulation (= 1)
@ ssAeroFunctions
Subsystem: Coefficients (= 256)
Models the Quaternion representation of rotations.