]> git.mxchange.org Git - flightgear.git/blob - JSBsim/FGOutput.cpp
New changes to address various feedback from initial release.
[flightgear.git] / JSBsim / 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 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 General Public License for more
19  details.
20
21  You should have received a copy of the GNU 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 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. Some machines may not support the ncurses console output. Borland is one
32 of those environments which does not, so the ncurses stuff is commented out.
33
34 HISTORY
35 --------------------------------------------------------------------------------
36 12/02/98   JSB   Created
37
38 ********************************************************************************
39 INCLUDES
40 *******************************************************************************/
41
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <iostream.h>
45 #ifdef HAVE_CURSES
46   #include <ncurses.h>
47 #endif
48
49 #include "FGOutput.h"
50 #include "FGState.h"
51 #include "FGFDMExec.h"
52 #include "FGAtmosphere.h"
53 #include "FGFCS.h"
54 #include "FGAircraft.h"
55 #include "FGTranslation.h"
56 #include "FGRotation.h"
57 #include "FGPosition.h"
58 #include "FGAuxiliary.h"
59
60 /*******************************************************************************
61 ************************************ CODE **************************************
62 *******************************************************************************/
63
64 FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
65 {
66   strcpy(Name, "FGOutput");
67   FirstPass = true;
68 #ifdef HAVE_CURSES
69   initscr();
70   cbreak();
71   noecho();
72 #endif
73 }
74
75
76 FGOutput::~FGOutput(void)
77 {
78 }
79
80
81 bool FGOutput::Run(void)
82 {
83   if (!FGModel::Run()) {
84     DelimitedOutput();
85 //    ConsoleOutput();
86   } else {
87   }
88   return false;
89 }
90
91
92 void FGOutput::ConsoleOutput(void)
93 {
94 #ifdef HAVE_CURSES
95   char buffer[20];
96
97   clear();
98   move(1,1);  insstr("Quaternions");
99   move(2,5);  insstr("Q0");
100   move(2,16); insstr("Q1");
101   move(2,27); insstr("Q2");
102   move(2,38); insstr("Q3");
103
104   move(3,1);  sprintf(buffer,"%4.4f",Rotation->GetQ0()); insstr(buffer);
105   move(3,12); sprintf(buffer,"%4.4f",Rotation->GetQ1()); insstr(buffer);
106   move(3,23); sprintf(buffer,"%4.4f",Rotation->GetQ2()); insstr(buffer);
107   move(3,34); sprintf(buffer,"%4.4f",Rotation->GetQ3()); insstr(buffer);
108
109   move(0,0); insstr("Time: ");
110   move(0,6); insstr(gcvt(State->Getsim_time(),6,buffer));
111
112   move(2,46); insstr("Phi");
113   move(2,55); insstr("Tht");
114   move(2,64); insstr("Psi");
115
116   move(3,45); sprintf(buffer,"%3.3f",Rotation->Getphi()); insstr(buffer);
117   move(3,54); sprintf(buffer,"%3.3f",Rotation->Gettht()); insstr(buffer);
118   move(3,63); sprintf(buffer,"%3.3f",Rotation->Getpsi()); insstr(buffer);
119
120   move(5,47); insstr("U");
121   move(5,56); insstr("V");
122   move(5,65); insstr("W");
123
124   move(6,45); sprintf(buffer,"%5.2f",Translation->GetU()); insstr(buffer);
125   move(6,54); sprintf(buffer,"%5.2f",Translation->GetV()); insstr(buffer);
126   move(6,63); sprintf(buffer,"%5.2f",Translation->GetW()); insstr(buffer);
127
128   move(8,47); insstr("Fx");
129   move(8,56); insstr("Fy");
130   move(8,65); insstr("Fz");
131
132   move(9,45); sprintf(buffer,"%5.2f",Aircraft->GetFx()); insstr(buffer);
133   move(9,54); sprintf(buffer,"%5.2f",Aircraft->GetFy()); insstr(buffer);
134   move(9,63); sprintf(buffer,"%5.2f",Aircraft->GetFz()); insstr(buffer);
135
136   move(11,47); insstr("Fn");
137   move(11,56); insstr("Fe");
138   move(11,65); insstr("Fd");
139
140   move(12,45); sprintf(buffer,"%5.2f",Position->GetFn()); insstr(buffer);
141   move(12,54); sprintf(buffer,"%5.2f",Position->GetFe()); insstr(buffer);
142   move(12,63); sprintf(buffer,"%5.2f",Position->GetFd()); insstr(buffer);
143
144   move(14,47); insstr("Latitude");
145   move(14,57); insstr("Longitude");
146   move(14,67); insstr("Altitude");
147
148   move(15,47); sprintf(buffer,"%5.2f",State->Getlatitude()); insstr(buffer);
149   move(15,57); sprintf(buffer,"%5.2f",State->Getlongitude()); insstr(buffer);
150   move(15,67); sprintf(buffer,"%5.2f",State->Geth()); insstr(buffer);
151
152   refresh();
153
154   move(LINES-1,1);
155   refresh();
156 #endif
157 }
158
159
160 void FGOutput::DelimitedOutput(void)
161 {
162   if (FirstPass) {
163     cout << "Time,";
164     cout << "Altitude,";
165     cout << "Phi,";
166     cout << "Tht,";
167     cout << "Psi,";
168     cout << "Rho,";
169     cout << "Vtotal,";
170     cout << "U,";
171     cout << "V,";
172     cout << "W,";
173     cout << "Vn,";
174     cout << "Ve,";
175     cout << "Vd,";
176     cout << "Udot,";
177     cout << "Vdot,";
178     cout << "Wdot,";
179     cout << "Fx,";
180     cout << "Fy,";
181     cout << "Fz,";
182     cout << "Latitude,";
183     cout << "Longitude,";
184     cout << "QBar,";
185     cout << "Alpha";
186     cout << endl;
187     FirstPass = false;
188   } else {
189     cout << State->Getsim_time() << ",";
190     cout << State->Geth() << ",";
191     cout << Rotation->Getphi() << ",";
192     cout << Rotation->Gettht() << ",";
193     cout << Rotation->Getpsi() << ",";
194     cout << Atmosphere->Getrho() << ",";
195     cout << State->GetVt() << ",";
196     cout << Translation->GetU() << ",";
197     cout << Translation->GetV() << ",";
198     cout << Translation->GetW() << ",";
199     cout << Position->GetVn() << ",";
200     cout << Position->GetVe() << ",";
201     cout << Position->GetVd() << ",";
202     cout << Translation->GetUdot() << ",";
203     cout << Translation->GetVdot() << ",";
204     cout << Translation->GetWdot() << ",";
205     cout << Aircraft->GetFx() << ",";
206     cout << Aircraft->GetFy() << ",";
207     cout << Aircraft->GetFz() << ",";
208     cout << State->Getlatitude() << ",";
209     cout << State->Getlongitude() << ",";
210     cout << State->Getqbar() << ",";
211     cout << Translation->Getalpha() << "";
212     cout << endl;
213   }
214 }