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