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