]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGOutput.cpp
Revert most iostream-related changes to JSBSim
[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 (jsb@hal-pc.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
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include "FGOutput.h"
42 #include "FGState.h"
43 #include "FGFDMExec.h"
44 #include "FGAtmosphere.h"
45 #include "FGFCS.h"
46 #include "FGAerodynamics.h"
47 #include "FGGroundReactions.h"
48 #include "FGAircraft.h"
49 #include "FGMassBalance.h"
50 #include "FGPropagate.h"
51 #include "FGAuxiliary.h"
52 #include "FGInertial.h"
53
54 #include <fstream>
55 #include <iomanip>
56
57 namespace JSBSim {
58
59 static const char *IdSrc = "$Id$";
60 static const char *IdHdr = ID_OUTPUT;
61
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 CLASS IMPLEMENTATION
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65
66 FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
67 {
68   Name = "FGOutput";
69   sFirstPass = dFirstPass = true;
70   socket = 0;
71   Type = otNone;
72   SubSystems = 0;
73   enabled = true;
74   delimeter = ", ";
75   Filename = "";
76   DirectivesFile = "";
77
78   Debug(0);
79 }
80
81 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82
83 FGOutput::~FGOutput()
84 {
85   delete socket;
86   OutputProperties.clear();
87   Debug(1);
88 }
89
90 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91
92 bool FGOutput::Run(void)
93 {
94   if (FGModel::Run()) return true;
95
96   if (enabled && !State->IntegrationSuspended()&& !FDMExec->Holding()) {
97     if (Type == otSocket) {
98       SocketOutput();
99     } else if (Type == otCSV || Type == otTab) {
100       DelimitedOutput(Filename);
101     } else if (Type == otTerminal) {
102       // Not done yet
103     } else if (Type == otNone) {
104       // Do nothing
105     } else {
106       // Not a valid type of output
107     }
108   }
109   return false;
110 }
111
112 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113
114 void FGOutput::SetType(string type)
115 {
116   if (type == "CSV") {
117     Type = otCSV;
118     delimeter = ", ";
119   } else if (type == "TABULAR") {
120     Type = otTab;
121     delimeter = "\t";
122   } else if (type == "SOCKET") {
123     Type = otSocket;
124   } else if (type == "TERMINAL") {
125     Type = otTerminal;
126   } else if (type != string("NONE")) {
127     Type = otUnknown;
128     cerr << "Unknown type of output specified in config file" << endl;
129   }
130 }
131
132 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133
134 void FGOutput::DelimitedOutput(string fname)
135 {
136   streambuf* buffer;
137   string scratch = "";
138
139   if (fname == "COUT" || fname == "cout") {
140     buffer = cout.rdbuf();
141   } else {
142     datafile.open(fname.c_str());
143     buffer = datafile.rdbuf();
144   }
145
146   ostream outstream(buffer);
147
148   outstream.precision(10);
149
150   if (dFirstPass) {
151     outstream << "Time";
152     if (SubSystems & ssSimulation) {
153       // Nothing here, yet
154     }
155     if (SubSystems & ssAerosurfaces) {
156       outstream << delimeter;
157       outstream << "Aileron Command (norm)" + delimeter;
158       outstream << "Elevator Command (norm)" + delimeter;
159       outstream << "Rudder Command (norm)" + delimeter;
160       outstream << "Flap Command (norm)" + delimeter;
161       outstream << "Left Aileron Position (deg)" + delimeter;
162       outstream << "Right Aileron Position (deg)" + delimeter;
163       outstream << "Elevator Position (deg)" + delimeter;
164       outstream << "Rudder Position (deg)" + delimeter;
165       outstream << "Flap Position (deg)";
166     }
167     if (SubSystems & ssRates) {
168       outstream << delimeter;
169       outstream << "P (deg/s)" + delimeter + "Q (deg/s)" + delimeter + "R (deg/s)" + delimeter;
170       outstream << "P dot (deg/s^2)" + delimeter + "Q dot (deg/s^2)" + delimeter + "R dot (deg/s^2)";
171     }
172     if (SubSystems & ssVelocities) {
173       outstream << delimeter;
174       outstream << "q bar (psf)" + delimeter;
175       outstream << "V_{Total} (ft/s)" + delimeter;
176       outstream << "UBody" + delimeter + "VBody" + delimeter + "WBody" + delimeter;
177       outstream << "Aero V_{X Body} (ft/s)" + delimeter + "Aero V_{Y Body} (ft/s)" + delimeter + "Aero V_{Z Body} (ft/s)" + delimeter;
178       outstream << "V_{North} (ft/s)" + delimeter + "V_{East} (ft/s)" + delimeter + "V_{Down} (ft/s)";
179     }
180     if (SubSystems & ssForces) {
181       outstream << delimeter;
182       outstream << "F_{Drag} (lbs)" + delimeter + "F_{Side} (lbs)" + delimeter + "F_{Lift} (lbs)" + delimeter;
183       outstream << "L/D" + delimeter;
184       outstream << "F_X (lbs)" + delimeter + "F_Y (lbs)" + delimeter + "F_Z (lbs)";
185     }
186     if (SubSystems & ssMoments) {
187       outstream << delimeter;
188       outstream << "L (ft-lbs)" + delimeter + "M (ft-lbs)" + delimeter + "N (ft-lbs)";
189     }
190     if (SubSystems & ssAtmosphere) {
191       outstream << delimeter;
192       outstream << "Rho (slugs/ft^3)" + delimeter;
193       outstream << "P_{SL} (psf)" + delimeter;
194       outstream << "P_{Ambient} (psf)" + delimeter;
195       outstream << "Wind V_{North} (ft/s)" + delimeter + "Wind V_{East} (ft/s)" + delimeter + "Wind V_{Down} (ft/s)";
196     }
197     if (SubSystems & ssMassProps) {
198       outstream << delimeter;
199       outstream << "I_xx" + delimeter;
200       outstream << "I_xy" + delimeter;
201       outstream << "I_xz" + delimeter;
202       outstream << "I_yx" + delimeter;
203       outstream << "I_yy" + delimeter;
204       outstream << "I_yz" + delimeter;
205       outstream << "I_zx" + delimeter;
206       outstream << "I_zy" + delimeter;
207       outstream << "I_zz" + delimeter;
208       outstream << "Mass" + delimeter;
209       outstream << "X_cg" + delimeter + "Y_cg" + delimeter + "Z_cg";
210     }
211     if (SubSystems & ssPropagate) {
212       outstream << delimeter;
213       outstream << "Altitude (ft)" + delimeter;
214       outstream << "Phi (deg)" + delimeter + "Theta (deg)" + delimeter + "Psi (deg)" + delimeter;
215       outstream << "Alpha (deg)" + delimeter;
216       outstream << "Beta (deg)" + delimeter;
217       outstream << "Latitude (deg)" + delimeter;
218       outstream << "Longitude (deg)" + delimeter;
219       outstream << "Distance AGL (ft)" + delimeter;
220       outstream << "Runway Radius (ft)";
221     }
222     if (SubSystems & ssCoefficients) {
223       scratch = Aerodynamics->GetCoefficientStrings(delimeter);
224       if (scratch.length() != 0) outstream << delimeter << scratch;
225     }
226     if (SubSystems & ssFCS) {
227       scratch = FCS->GetComponentStrings(delimeter);
228       if (scratch.length() != 0) outstream << delimeter << scratch;
229     }
230     if (SubSystems & ssGroundReactions) {
231       outstream << delimeter;
232       outstream << GroundReactions->GetGroundReactionStrings(delimeter);
233     }
234     if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
235       outstream << delimeter;
236       outstream << Propulsion->GetPropulsionStrings(delimeter);
237     }
238     if (OutputProperties.size() > 0) {
239       for (unsigned int i=0;i<OutputProperties.size();i++) {
240         outstream << delimeter << OutputProperties[i]->GetPrintableName();
241       }
242     }
243
244     outstream << endl;
245     dFirstPass = false;
246   }
247
248   outstream << State->Getsim_time();
249   if (SubSystems & ssSimulation) {
250   }
251   if (SubSystems & ssAerosurfaces) {
252     outstream << delimeter;
253     outstream << FCS->GetDaCmd() << delimeter;
254     outstream << FCS->GetDeCmd() << delimeter;
255     outstream << FCS->GetDrCmd() << delimeter;
256     outstream << FCS->GetDfCmd() << delimeter;
257     outstream << FCS->GetDaLPos(ofDeg) << delimeter;
258     outstream << FCS->GetDaRPos(ofDeg) << delimeter;
259     outstream << FCS->GetDePos(ofDeg) << delimeter;
260     outstream << FCS->GetDrPos(ofDeg) << delimeter;
261     outstream << FCS->GetDfPos(ofDeg);
262   }
263   if (SubSystems & ssRates) {
264     outstream << delimeter;
265     outstream << (radtodeg*Propagate->GetPQR()).Dump(delimeter) << delimeter;
266     outstream << (radtodeg*Propagate->GetPQRdot()).Dump(delimeter);
267   }
268   if (SubSystems & ssVelocities) {
269     outstream << delimeter;
270     outstream << Auxiliary->Getqbar() << delimeter;
271     outstream << setprecision(12) << Auxiliary->GetVt() << delimeter;
272     outstream << setprecision(12) << Propagate->GetUVW().Dump(delimeter) << delimeter;
273     outstream << Auxiliary->GetAeroUVW().Dump(delimeter) << delimeter;
274     outstream << Propagate->GetVel().Dump(delimeter);
275   }
276   if (SubSystems & ssForces) {
277     outstream << delimeter;
278     outstream << Aerodynamics->GetvFs() << delimeter;
279     outstream << Aerodynamics->GetLoD() << delimeter;
280     outstream << Aircraft->GetForces().Dump(delimeter);
281   }
282   if (SubSystems & ssMoments) {
283     outstream << delimeter;
284     outstream << Aircraft->GetMoments().Dump(delimeter);
285   }
286   if (SubSystems & ssAtmosphere) {
287     outstream << delimeter;
288     outstream << Atmosphere->GetDensity() << delimeter;
289     outstream << Atmosphere->GetPressureSL() << delimeter;
290     outstream << Atmosphere->GetPressure() << delimeter;
291     outstream << Atmosphere->GetWindNED().Dump(delimeter);
292   }
293   if (SubSystems & ssMassProps) {
294     outstream << delimeter;
295     outstream << MassBalance->GetJ() << delimeter;
296     outstream << MassBalance->GetMass() << delimeter;
297     outstream << MassBalance->GetXYZcg();
298   }
299   if (SubSystems & ssPropagate) {
300     outstream << delimeter;
301     outstream << Propagate->Geth() << delimeter;
302     outstream << (radtodeg*Propagate->GetEuler()).Dump(delimeter) << delimeter;
303     outstream << Auxiliary->Getalpha(inDegrees) << delimeter;
304     outstream << Auxiliary->Getbeta(inDegrees) << delimeter;
305     outstream << Propagate->GetLocation().GetLatitudeDeg() << delimeter;
306     outstream << Propagate->GetLocation().GetLongitudeDeg() << delimeter;
307     outstream << Propagate->GetDistanceAGL() << delimeter;
308     outstream << Propagate->GetRunwayRadius();
309   }
310   if (SubSystems & ssCoefficients) {
311     scratch = Aerodynamics->GetCoefficientValues(delimeter);
312     if (scratch.length() != 0) outstream << delimeter << scratch;
313   }
314   if (SubSystems & ssFCS) {
315     scratch = FCS->GetComponentValues(delimeter);
316     if (scratch.length() != 0) outstream << delimeter << scratch;
317   }
318   if (SubSystems & ssGroundReactions) {
319     outstream << delimeter;
320     outstream << GroundReactions->GetGroundReactionValues(delimeter);
321   }
322   if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
323     outstream << delimeter;
324     outstream << Propulsion->GetPropulsionValues(delimeter);
325   }
326
327   for (unsigned int i=0;i<OutputProperties.size();i++) {
328     outstream << delimeter << OutputProperties[i]->getDoubleValue();
329   }
330
331   outstream << endl;
332   outstream.flush();
333 }
334
335 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
336
337 void FGOutput::SocketOutput(void)
338 {
339   string asciiData, scratch;
340
341   if (socket == NULL) return;
342   if (!socket->GetConnectStatus()) return;
343
344   socket->Clear();
345   if (sFirstPass) {
346     socket->Clear("<LABELS>");
347     socket->Append("Time");
348
349     if (SubSystems & ssAerosurfaces) {
350       socket->Append("Aileron Command");
351       socket->Append("Elevator Command");
352       socket->Append("Rudder Command");
353       socket->Append("Flap Command");
354       socket->Append("Left Aileron Position");
355       socket->Append("Right Aileron Position");
356       socket->Append("Elevator Position");
357       socket->Append("Rudder Position");
358       socket->Append("Flap Position");
359     }
360
361     if (SubSystems & ssRates) {
362       socket->Append("P");
363       socket->Append("Q");
364       socket->Append("R");
365       socket->Append("PDot");
366       socket->Append("QDot");
367       socket->Append("RDot");
368     }
369
370     if (SubSystems & ssVelocities) {
371       socket->Append("QBar");
372       socket->Append("Vtotal");
373       socket->Append("UBody");
374       socket->Append("VBody");
375       socket->Append("WBody");
376       socket->Append("UAero");
377       socket->Append("VAero");
378       socket->Append("WAero");
379       socket->Append("Vn");
380       socket->Append("Ve");
381       socket->Append("Vd");
382     }
383     if (SubSystems & ssForces) {
384       socket->Append("F_Drag");
385       socket->Append("F_Side");
386       socket->Append("F_Lift");
387       socket->Append("LoD");
388       socket->Append("Fx");
389       socket->Append("Fy");
390       socket->Append("Fz");
391     }
392     if (SubSystems & ssMoments) {
393       socket->Append("L");
394       socket->Append("M");
395       socket->Append("N");
396     }
397     if (SubSystems & ssAtmosphere) {
398       socket->Append("Rho");
399       socket->Append("SL pressure");
400       socket->Append("Ambient pressure");
401       socket->Append("NWind");
402       socket->Append("EWind");
403       socket->Append("DWind");
404     }
405     if (SubSystems & ssMassProps) {
406       socket->Append("Ixx");
407       socket->Append("Ixy");
408       socket->Append("Ixz");
409       socket->Append("Iyx");
410       socket->Append("Iyy");
411       socket->Append("Iyz");
412       socket->Append("Izx");
413       socket->Append("Izy");
414       socket->Append("Izz");
415       socket->Append("Mass");
416       socket->Append("Xcg");
417       socket->Append("Ycg");
418       socket->Append("Zcg");
419     }
420     if (SubSystems & ssPropagate) {
421         socket->Append("Altitude");
422         socket->Append("Phi (deg)");
423         socket->Append("Tht (deg)");
424         socket->Append("Psi (deg)");
425         socket->Append("Alpha (deg)");
426         socket->Append("Beta (deg)");
427         socket->Append("Latitude (deg)");
428         socket->Append("Longitude (deg)");
429     }
430     if (SubSystems & ssCoefficients) {
431       scratch = Aerodynamics->GetCoefficientStrings(",");
432       if (scratch.length() != 0) socket->Append(scratch);
433     }
434     if (SubSystems & ssFCS) {
435       scratch = FCS->GetComponentStrings(",");
436       if (scratch.length() != 0) socket->Append(scratch);
437     }
438     if (SubSystems & ssGroundReactions) {
439       socket->Append(GroundReactions->GetGroundReactionStrings(","));
440     }
441     if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
442       socket->Append(Propulsion->GetPropulsionStrings(","));
443     }
444     if (OutputProperties.size() > 0) {
445       for (unsigned int i=0;i<OutputProperties.size();i++) {
446         socket->Append(OutputProperties[i]->GetPrintableName());
447       }
448     }
449
450     sFirstPass = false;
451     socket->Send();
452   }
453
454   socket->Clear();
455   socket->Append(State->Getsim_time());
456
457   if (SubSystems & ssAerosurfaces) {
458     socket->Append(FCS->GetDaCmd());
459     socket->Append(FCS->GetDeCmd());
460     socket->Append(FCS->GetDrCmd());
461     socket->Append(FCS->GetDfCmd());
462     socket->Append(FCS->GetDaLPos());
463     socket->Append(FCS->GetDaRPos());
464     socket->Append(FCS->GetDePos());
465     socket->Append(FCS->GetDrPos());
466     socket->Append(FCS->GetDfPos());
467   }
468   if (SubSystems & ssRates) {
469     socket->Append(radtodeg*Propagate->GetPQR(eP));
470     socket->Append(radtodeg*Propagate->GetPQR(eQ));
471     socket->Append(radtodeg*Propagate->GetPQR(eR));
472     socket->Append(radtodeg*Propagate->GetPQRdot(eP));
473     socket->Append(radtodeg*Propagate->GetPQRdot(eQ));
474     socket->Append(radtodeg*Propagate->GetPQRdot(eR));
475   }
476   if (SubSystems & ssVelocities) {
477     socket->Append(Auxiliary->Getqbar());
478     socket->Append(Auxiliary->GetVt());
479     socket->Append(Propagate->GetUVW(eU));
480     socket->Append(Propagate->GetUVW(eV));
481     socket->Append(Propagate->GetUVW(eW));
482     socket->Append(Auxiliary->GetAeroUVW(eU));
483     socket->Append(Auxiliary->GetAeroUVW(eV));
484     socket->Append(Auxiliary->GetAeroUVW(eW));
485     socket->Append(Propagate->GetVel(eNorth));
486     socket->Append(Propagate->GetVel(eEast));
487     socket->Append(Propagate->GetVel(eDown));
488   }
489   if (SubSystems & ssForces) {
490     socket->Append(Aerodynamics->GetvFs()(eDrag));
491     socket->Append(Aerodynamics->GetvFs()(eSide));
492     socket->Append(Aerodynamics->GetvFs()(eLift));
493     socket->Append(Aerodynamics->GetLoD());
494     socket->Append(Aircraft->GetForces(eX));
495     socket->Append(Aircraft->GetForces(eY));
496     socket->Append(Aircraft->GetForces(eZ));
497   }
498   if (SubSystems & ssMoments) {
499     socket->Append(Aircraft->GetMoments(eL));
500     socket->Append(Aircraft->GetMoments(eM));
501     socket->Append(Aircraft->GetMoments(eN));
502   }
503   if (SubSystems & ssAtmosphere) {
504     socket->Append(Atmosphere->GetDensity());
505     socket->Append(Atmosphere->GetPressureSL());
506     socket->Append(Atmosphere->GetPressure());
507     socket->Append(Atmosphere->GetWindNED().Dump(","));
508   }
509   if (SubSystems & ssMassProps) {
510     socket->Append(MassBalance->GetJ()(1,1));
511     socket->Append(MassBalance->GetJ()(1,2));
512     socket->Append(MassBalance->GetJ()(1,3));
513     socket->Append(MassBalance->GetJ()(2,1));
514     socket->Append(MassBalance->GetJ()(2,2));
515     socket->Append(MassBalance->GetJ()(2,3));
516     socket->Append(MassBalance->GetJ()(3,1));
517     socket->Append(MassBalance->GetJ()(3,2));
518     socket->Append(MassBalance->GetJ()(3,3));
519     socket->Append(MassBalance->GetMass());
520     socket->Append(MassBalance->GetXYZcg()(eX));
521     socket->Append(MassBalance->GetXYZcg()(eY));
522     socket->Append(MassBalance->GetXYZcg()(eZ));
523   }
524   if (SubSystems & ssPropagate) {
525     socket->Append(Propagate->Geth());
526     socket->Append(radtodeg*Propagate->GetEuler(ePhi));
527     socket->Append(radtodeg*Propagate->GetEuler(eTht));
528     socket->Append(radtodeg*Propagate->GetEuler(ePsi));
529     socket->Append(Auxiliary->Getalpha(inDegrees));
530     socket->Append(Auxiliary->Getbeta(inDegrees));
531     socket->Append(Propagate->GetLocation().GetLatitudeDeg());
532     socket->Append(Propagate->GetLocation().GetLongitudeDeg());
533   }
534   if (SubSystems & ssCoefficients) {
535     scratch = Aerodynamics->GetCoefficientValues(",");
536     if (scratch.length() != 0) socket->Append(scratch);
537   }
538   if (SubSystems & ssFCS) {
539     scratch = FCS->GetComponentValues(",");
540     if (scratch.length() != 0) socket->Append(scratch);
541   }
542   if (SubSystems & ssGroundReactions) {
543     socket->Append(GroundReactions->GetGroundReactionValues(","));
544   }
545   if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
546     socket->Append(Propulsion->GetPropulsionValues(","));
547   }
548
549   for (unsigned int i=0;i<OutputProperties.size();i++) {
550     socket->Append(OutputProperties[i]->getDoubleValue());
551   }
552
553   socket->Send();
554 }
555
556 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
557
558 void FGOutput::SocketStatusOutput(string out_str)
559 {
560   string asciiData;
561
562   if (socket == NULL) return;
563
564   socket->Clear();
565   asciiData = string("<STATUS>") + out_str;
566   socket->Append(asciiData.c_str());
567   socket->Send();
568 }
569
570 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
571
572 bool FGOutput::Load(Element* element)
573 {
574   string type="", parameter="";
575   string name="", fname="";
576   int OutRate = 0;
577   string property;
578   unsigned int port;
579   Element *property_element;
580
581   string separator = "/";
582 # ifdef macintosh
583   separator = ";";
584 # endif
585
586   if (!DirectivesFile.empty()) { // A directives filename from the command line overrides
587     fname = DirectivesFile;      // one found in the config file.
588   } else {
589     fname = element->GetAttributeValue("file");
590   }
591
592   if (!fname.empty()) {
593     int len = fname.size();
594     if (fname.find(".xml") != string::npos) {
595       output_file_name = fname; // Use supplied name if last four letters are ".xml"
596     } else {
597       output_file_name = FDMExec->GetFullAircraftPath() + separator + fname + ".xml";
598     }
599     document = LoadXMLDocument(output_file_name);
600   } else {
601     document = element;
602   }
603
604   name = document->GetAttributeValue("name");
605   type = document->GetAttributeValue("type");
606   SetType(type);
607   if (!document->GetAttributeValue("port").empty() && type == string("SOCKET")) {
608     port = atoi(document->GetAttributeValue("port").c_str());
609     socket = new FGfdmSocket(name, port);
610   } else {
611     Filename = name;
612   }
613   if (!document->GetAttributeValue("rate").empty()) {
614     OutRate = (int)document->GetAttributeValueAsNumber("rate");
615   } else {
616     OutRate = 1;
617   }
618
619   if (document->FindElementValue("simulation") == string("ON"))
620     SubSystems += ssSimulation;
621   if (document->FindElementValue("aerosurfaces") == string("ON"))
622     SubSystems += ssAerosurfaces;
623   if (document->FindElementValue("rates") == string("ON"))
624     SubSystems += ssRates;
625   if (document->FindElementValue("velocities") == string("ON"))
626     SubSystems += ssVelocities;
627   if (document->FindElementValue("forces") == string("ON"))
628     SubSystems += ssForces;
629   if (document->FindElementValue("moments") == string("ON"))
630     SubSystems += ssMoments;
631   if (document->FindElementValue("atmosphere") == string("ON"))
632     SubSystems += ssAtmosphere;
633   if (document->FindElementValue("massprops") == string("ON"))
634     SubSystems += ssMassProps;
635   if (document->FindElementValue("position") == string("ON"))
636     SubSystems += ssPropagate;
637   if (document->FindElementValue("coefficients") == string("ON"))
638     SubSystems += ssCoefficients;
639   if (document->FindElementValue("ground_reactions") == string("ON"))
640     SubSystems += ssGroundReactions;
641   if (document->FindElementValue("fcs") == string("ON"))
642     SubSystems += ssFCS;
643   if (document->FindElementValue("propulsion") == string("ON"))
644     SubSystems += ssPropulsion;
645   property_element = document->FindElement("property");
646   while (property_element) {
647     string property = property_element->GetDataLine();
648     OutputProperties.push_back(PropertyManager->GetNode(property));
649     property_element = document->FindNextElement("property");
650   }
651
652   OutRate = OutRate>1000?1000:(OutRate<0?0:OutRate);
653   rate = (int)(0.5 + 1.0/(State->Getdt()*OutRate));
654
655   Debug(2);
656
657   return true;
658 }
659
660 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
661 //    The bitmasked value choices are as follows:
662 //    unset: In this case (the default) JSBSim would only print
663 //       out the normally expected messages, essentially echoing
664 //       the config files as they are read. If the environment
665 //       variable is not set, debug_lvl is set to 1 internally
666 //    0: This requests JSBSim not to output any messages
667 //       whatsoever.
668 //    1: This value explicity requests the normal JSBSim
669 //       startup messages
670 //    2: This value asks for a message to be printed out when
671 //       a class is instantiated
672 //    4: When this value is set, a message is displayed when a
673 //       FGModel object executes its Run() method
674 //    8: When this value is set, various runtime state variables
675 //       are printed out periodically
676 //    16: When set various parameters are sanity checked and
677 //       a message is printed out when they go out of bounds
678
679 void FGOutput::Debug(int from)
680 {
681   string scratch="";
682
683   if (debug_lvl <= 0) return;
684
685   if (debug_lvl & 1) { // Standard console startup message output
686     if (from == 0) { // Constructor
687
688     }
689     if (from == 2) {
690       if (output_file_name.empty())
691         cout << "  " << "Output parameters read inline" << endl;
692       else
693         cout << "    Output parameters read from file: " << output_file_name << endl;
694
695       if (Filename == "cout" || Filename == "COUT") {
696         scratch = "    Log output goes to screen console";
697       } else if (!Filename.empty()) {
698         scratch = "    Log output goes to file: " + Filename;
699       }
700       switch (Type) {
701       case otCSV:
702         cout << scratch << " in CSV format output at rate " << 1/(State->Getdt()*rate) << " Hz" << endl;
703         break;
704       case otNone:
705         cout << "  No log output" << endl;
706         break;
707       }
708
709       if (SubSystems & ssSimulation)      cout << "    Simulation parameters logged" << endl;
710       if (SubSystems & ssAerosurfaces)    cout << "    Aerosurface parameters logged" << endl;
711       if (SubSystems & ssRates)           cout << "    Rate parameters logged" << endl;
712       if (SubSystems & ssVelocities)      cout << "    Velocity parameters logged" << endl;
713       if (SubSystems & ssForces)          cout << "    Force parameters logged" << endl;
714       if (SubSystems & ssMoments)         cout << "    Moments parameters logged" << endl;
715       if (SubSystems & ssAtmosphere)      cout << "    Atmosphere parameters logged" << endl;
716       if (SubSystems & ssMassProps)       cout << "    Mass parameters logged" << endl;
717       if (SubSystems & ssCoefficients)    cout << "    Coefficient parameters logged" << endl;
718       if (SubSystems & ssPropagate)       cout << "    Propagate parameters logged" << endl;
719       if (SubSystems & ssGroundReactions) cout << "    Ground parameters logged" << endl;
720       if (SubSystems & ssFCS)             cout << "    FCS parameters logged" << endl;
721       if (SubSystems & ssPropulsion)      cout << "    Propulsion parameters logged" << endl;
722       if (OutputProperties.size() > 0)    cout << "    Properties logged:" << endl;
723       for (unsigned int i=0;i<OutputProperties.size();i++) {
724         cout << "      - " << OutputProperties[i]->GetName() << endl;
725       }
726     }
727   }
728   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
729     if (from == 0) cout << "Instantiated: FGOutput" << endl;
730     if (from == 1) cout << "Destroyed:    FGOutput" << endl;
731   }
732   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
733   }
734   if (debug_lvl & 8 ) { // Runtime state variables
735   }
736   if (debug_lvl & 16) { // Sanity checking
737   }
738   if (debug_lvl & 64) {
739     if (from == 0) { // Constructor
740       cout << IdSrc << endl;
741       cout << IdHdr << endl;
742     }
743   }
744 }
745 }