]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_menu_engine.cpp
Port over remaining Point3D usage to the more type and unit safe SG* classes.
[flightgear.git] / src / FDM / UIUCModel / uiuc_menu_engine.cpp
1 /**********************************************************************
2                                                                        
3  FILENAME:     uiuc_menu_engine.cpp
4
5 ----------------------------------------------------------------------
6
7  DESCRIPTION:  reads input data for specified aircraft and creates 
8                approporiate data storage space
9
10 ----------------------------------------------------------------------
11
12  STATUS:       alpha version
13
14 ----------------------------------------------------------------------
15
16  REFERENCES:   based on "menu reader" format of Michael Selig
17
18 ----------------------------------------------------------------------
19
20  HISTORY:      04/04/2003   initial release
21                06/30/2003   (RD) replaced istrstream with istringstream
22                             to get rid of the annoying warning about
23                             using the strstream header
24
25 ----------------------------------------------------------------------
26
27  AUTHOR(S):    Robert Deters      <rdeters@uiuc.edu>
28                Michael Selig      <m-selig@uiuc.edu>
29
30 ----------------------------------------------------------------------
31
32  VARIABLES:
33
34 ----------------------------------------------------------------------
35
36  INPUTS:       n/a
37
38 ----------------------------------------------------------------------
39
40  OUTPUTS:      n/a
41
42 ----------------------------------------------------------------------
43
44  CALLED BY:    uiuc_menu()
45
46 ----------------------------------------------------------------------
47
48  CALLS TO:     check_float() if needed
49                d_2_to_3() if needed
50                d_1_to_2() if needed
51                i_1_to_2() if needed
52                d_1_to_1() if needed
53
54  ----------------------------------------------------------------------
55
56  COPYRIGHT:    (C) 2003 by Michael Selig
57
58  This program is free software; you can redistribute it and/or
59  modify it under the terms of the GNU General Public License
60  as published by the Free Software Foundation.
61
62  This program is distributed in the hope that it will be useful,
63  but WITHOUT ANY WARRANTY; without even the implied warranty of
64  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
65  GNU General Public License for more details.
66
67  You should have received a copy of the GNU General Public License
68  along with this program; if not, write to the Free Software
69  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
70
71 **********************************************************************/
72
73 #include <simgear/compiler.h>
74
75
76 #include <cstdlib>
77 #include <string>
78 #include <iostream>
79
80 #include "uiuc_menu_engine.h"
81
82 using std::cerr;
83 using std::cout;
84 using std::endl;
85
86 #ifndef _MSC_VER
87 using std::exit;
88 #endif
89
90 void parse_engine( const string& linetoken2, const string& linetoken3,
91                    const string& linetoken4, const string& linetoken5, 
92                    const string& linetoken6, const string& linetoken7, 
93                    const string& linetoken8, const string& linetoken9,
94                    const string& linetoken10,const string& aircraft_directory,
95                    LIST command_line ) {
96     double token_value;
97     int token_value_convert1, token_value_convert2;
98     istringstream token3(linetoken3.c_str());
99     istringstream token4(linetoken4.c_str());
100     istringstream token5(linetoken5.c_str());
101     istringstream token6(linetoken6.c_str());
102     istringstream token7(linetoken7.c_str());
103     istringstream token8(linetoken8.c_str());
104     istringstream token9(linetoken9.c_str());
105     istringstream token10(linetoken10.c_str());
106
107     switch(engine_map[linetoken2])
108       {
109       case simpleSingle_flag:
110         {
111           if (check_float(linetoken3))
112             token3 >> token_value;
113           else
114             uiuc_warnings_errors(1, *command_line);
115           
116           simpleSingleMaxThrust = token_value; 
117           engineParts -> storeCommands (*command_line);
118           break;
119         }
120       case simpleSingleModel_flag:
121         {
122           simpleSingleModel = true;
123           /* input the thrust at zero speed */
124           if (check_float(linetoken3))
125             token3 >> token_value;
126           else
127             uiuc_warnings_errors(1, *command_line);
128           t_v0 = token_value; 
129           /* input slope of thrust at speed for which thrust is zero */
130           if (check_float(linetoken4))
131             token4 >> token_value;
132           else
133             uiuc_warnings_errors(1, *command_line);
134           dtdv_t0 = token_value; 
135           /* input speed at which thrust is zero */
136           if (check_float(linetoken5))
137             token5 >> token_value;
138           else
139             uiuc_warnings_errors(1, *command_line);
140           v_t0 = token_value; 
141           dtdvvt = -dtdv_t0 * v_t0 / t_v0;
142           engineParts -> storeCommands (*command_line);
143           break;
144         }
145       case c172_flag:
146         {
147           engineParts -> storeCommands (*command_line);
148           break;
149         }
150       case cherokee_flag:
151         {
152           engineParts -> storeCommands (*command_line);
153           break;
154         }
155       case Throttle_pct_input_flag:
156         {
157           Throttle_pct_input = true;
158           Throttle_pct_input_file = aircraft_directory + linetoken3;
159           token4 >> token_value_convert1;
160           token5 >> token_value_convert2;
161           convert_y = uiuc_convert(token_value_convert1);
162           convert_x = uiuc_convert(token_value_convert2);
163           uiuc_1DdataFileReader(Throttle_pct_input_file,
164                                 Throttle_pct_input_timeArray,
165                                 Throttle_pct_input_dTArray,
166                                 Throttle_pct_input_ntime);
167           token6 >> token_value;
168           Throttle_pct_input_startTime = token_value;
169           break;
170         }
171       case gyroForce_Q_body_flag:
172         {
173           /* include gyroscopic forces due to pitch */
174           gyroForce_Q_body = true;
175           break;
176         }
177       case gyroForce_R_body_flag:
178         {
179           /* include gyroscopic forces due to yaw */
180           gyroForce_R_body = true;
181           break;
182         }
183
184       case slipstream_effects_flag:
185         {
186         // include slipstream effects
187           b_slipstreamEffects = true;
188           if (!simpleSingleModel)
189             uiuc_warnings_errors(3, *command_line);
190           break;
191         }
192       case propDia_flag:
193         {
194           if (check_float(linetoken3))
195             token3 >> token_value;
196           else
197             uiuc_warnings_errors(1, *command_line);
198           propDia = token_value;
199           break;
200         }
201       case eta_q_Cm_q_flag:
202         {
203         // include slipstream effects due to Cm_q
204           if (check_float(linetoken3))
205             token3 >> token_value;
206           else
207             uiuc_warnings_errors(1, *command_line);
208           eta_q_Cm_q_fac = token_value;
209           if (eta_q_Cm_q_fac == 0.0) {eta_q_Cm_q_fac = 1.0;}
210           break;
211         }
212       case eta_q_Cm_adot_flag:
213         {
214         // include slipstream effects due to Cm_adot
215           if (check_float(linetoken3))
216             token3 >> token_value;
217           else
218             uiuc_warnings_errors(1, *command_line);
219           eta_q_Cm_adot_fac = token_value;
220           if (eta_q_Cm_adot_fac == 0.0) {eta_q_Cm_adot_fac = 1.0;}
221           break;
222         }
223       case eta_q_Cmfade_flag:
224         {
225         // include slipstream effects due to Cmfade
226           if (check_float(linetoken3))
227             token3 >> token_value;
228           else
229             uiuc_warnings_errors(1, *command_line);
230           eta_q_Cmfade_fac = token_value;
231           if (eta_q_Cmfade_fac == 0.0) {eta_q_Cmfade_fac = 1.0;}
232           break;
233         }
234       case eta_q_Cm_de_flag:
235         {
236         // include slipstream effects due to Cmfade
237           if (check_float(linetoken3))
238             token3 >> token_value;
239           else
240             uiuc_warnings_errors(1, *command_line);
241           eta_q_Cm_de_fac = token_value;
242           if (eta_q_Cm_de_fac == 0.0) {eta_q_Cm_de_fac = 1.0;}
243           break;
244         }
245       case eta_q_Cl_beta_flag:
246         {
247         // include slipstream effects due to Cl_beta
248           if (check_float(linetoken3))
249             token3 >> token_value;
250           else
251             uiuc_warnings_errors(1, *command_line);
252           eta_q_Cl_beta_fac = token_value;
253           if (eta_q_Cl_beta_fac == 0.0) {eta_q_Cl_beta_fac = 1.0;}
254           break;
255         }
256       case eta_q_Cl_p_flag:
257         {
258         // include slipstream effects due to Cl_p
259           if (check_float(linetoken3))
260             token3 >> token_value;
261           else
262             uiuc_warnings_errors(1, *command_line);
263           eta_q_Cl_p_fac = token_value;
264           if (eta_q_Cl_p_fac == 0.0) {eta_q_Cl_p_fac = 1.0;}
265           break;
266         }
267       case eta_q_Cl_r_flag:
268         {
269         // include slipstream effects due to Cl_r
270           if (check_float(linetoken3))
271             token3 >> token_value;
272           else
273             uiuc_warnings_errors(1, *command_line);
274           eta_q_Cl_r_fac = token_value;
275           if (eta_q_Cl_r_fac == 0.0) {eta_q_Cl_r_fac = 1.0;}
276           break;
277         }
278       case eta_q_Cl_dr_flag:
279         {
280         // include slipstream effects due to Cl_dr
281           if (check_float(linetoken3))
282             token3 >> token_value;
283           else
284             uiuc_warnings_errors(1, *command_line);
285           eta_q_Cl_dr_fac = token_value;
286           if (eta_q_Cl_dr_fac == 0.0) {eta_q_Cl_dr_fac = 1.0;}
287           break;
288         }
289       case eta_q_CY_beta_flag:
290         {
291         // include slipstream effects due to CY_beta
292           if (check_float(linetoken3))
293             token3 >> token_value;
294           else
295             uiuc_warnings_errors(1, *command_line);
296           eta_q_CY_beta_fac = token_value;
297           if (eta_q_CY_beta_fac == 0.0) {eta_q_CY_beta_fac = 1.0;}
298           break;
299         }
300       case eta_q_CY_p_flag:
301         {
302         // include slipstream effects due to CY_p
303           if (check_float(linetoken3))
304             token3 >> token_value;
305           else
306             uiuc_warnings_errors(1, *command_line);
307           eta_q_CY_p_fac = token_value;
308           if (eta_q_CY_p_fac == 0.0) {eta_q_CY_p_fac = 1.0;}
309           break;
310         }
311       case eta_q_CY_r_flag:
312         {
313         // include slipstream effects due to CY_r
314           if (check_float(linetoken3))
315             token3 >> token_value;
316           else
317             uiuc_warnings_errors(1, *command_line);
318           eta_q_CY_r_fac = token_value;
319           if (eta_q_CY_r_fac == 0.0) {eta_q_CY_r_fac = 1.0;}
320           break;
321         }
322       case eta_q_CY_dr_flag:
323         {
324         // include slipstream effects due to CY_dr
325           if (check_float(linetoken3))
326             token3 >> token_value;
327           else
328             uiuc_warnings_errors(1, *command_line);
329           eta_q_CY_dr_fac = token_value;
330           if (eta_q_CY_dr_fac == 0.0) {eta_q_CY_dr_fac = 1.0;}
331           break;
332         }
333       case eta_q_Cn_beta_flag:
334         {
335         // include slipstream effects due to Cn_beta
336           if (check_float(linetoken3))
337             token3 >> token_value;
338           else
339             uiuc_warnings_errors(1, *command_line);
340           eta_q_Cn_beta_fac = token_value;
341           if (eta_q_Cn_beta_fac == 0.0) {eta_q_Cn_beta_fac = 1.0;}
342           break;
343         }
344       case eta_q_Cn_p_flag:
345         {
346         // include slipstream effects due to Cn_p
347           if (check_float(linetoken3))
348             token3 >> token_value;
349           else
350             uiuc_warnings_errors(1, *command_line);
351           eta_q_Cn_p_fac = token_value;
352           if (eta_q_Cn_p_fac == 0.0) {eta_q_Cn_p_fac = 1.0;}
353           break;
354         }
355       case eta_q_Cn_r_flag:
356         {
357         // include slipstream effects due to Cn_r
358           if (check_float(linetoken3))
359             token3 >> token_value;
360           else
361             uiuc_warnings_errors(1, *command_line);
362           eta_q_Cn_r_fac = token_value;
363           if (eta_q_Cn_r_fac == 0.0) {eta_q_Cn_r_fac = 1.0;}
364           break;
365         }
366       case eta_q_Cn_dr_flag:
367         {
368         // include slipstream effects due to Cn_dr
369           if (check_float(linetoken3))
370             token3 >> token_value;
371           else
372             uiuc_warnings_errors(1, *command_line);
373           eta_q_Cn_dr_fac = token_value;
374           if (eta_q_Cn_dr_fac == 0.0) {eta_q_Cn_dr_fac = 1.0;}
375           break;
376         }
377
378       case omega_flag:
379         {
380           if (check_float(linetoken3))
381             token3 >> token_value;
382           else
383             uiuc_warnings_errors(1, *command_line);
384           minOmega = token_value; 
385           if (check_float(linetoken4))
386             token4 >> token_value;
387           else
388             uiuc_warnings_errors(1, *command_line);
389           maxOmega = token_value; 
390           break;
391         }
392       case omegaRPM_flag:
393         {
394           if (check_float(linetoken3))
395             token3 >> token_value;
396           else
397             uiuc_warnings_errors(1, *command_line);
398           minOmegaRPM = token_value; 
399           minOmega    = minOmegaRPM * 2.0 * LS_PI / 60;
400           if (check_float(linetoken4))
401             token4 >> token_value;
402           else
403             uiuc_warnings_errors(1, *command_line);
404           maxOmegaRPM = token_value; 
405           maxOmega    = maxOmegaRPM * 2.0 * LS_PI / 60;
406           break;
407         }
408       case polarInertia_flag:
409         {
410           if (check_float(linetoken3))
411             token3 >> token_value;
412           else
413             uiuc_warnings_errors(1, *command_line);
414           polarInertia = token_value; 
415           break;
416         }
417       case forcemom_flag:
418         {
419           engineParts -> storeCommands (*command_line);
420           break;
421         }
422       case Xp_input_flag:
423         {
424           Xp_input = true;
425           Xp_input_file = aircraft_directory + linetoken3;
426           token4 >> token_value_convert1;
427           token5 >> token_value_convert2;
428           convert_y = uiuc_convert(token_value_convert1);
429           convert_x = uiuc_convert(token_value_convert2);
430           uiuc_1DdataFileReader(Xp_input_file,
431                                 Xp_input_timeArray,
432                                 Xp_input_XpArray,
433                                 Xp_input_ntime);
434           token6 >> token_value;
435           Xp_input_startTime = token_value;
436           break;
437         }
438       case Zp_input_flag:
439         {
440           Zp_input = true;
441           Zp_input_file = aircraft_directory + linetoken3;
442           token4 >> token_value_convert1;
443           token5 >> token_value_convert2;
444           convert_y = uiuc_convert(token_value_convert1);
445           convert_x = uiuc_convert(token_value_convert2);
446           uiuc_1DdataFileReader(Zp_input_file,
447                                 Zp_input_timeArray,
448                                 Zp_input_ZpArray,
449                                 Zp_input_ntime);
450           token6 >> token_value;
451           Zp_input_startTime = token_value;
452           break;
453         }
454       case Mp_input_flag:
455         {
456           Mp_input = true;
457           Mp_input_file = aircraft_directory + linetoken3;
458           token4 >> token_value_convert1;
459           token5 >> token_value_convert2;
460           convert_y = uiuc_convert(token_value_convert1);
461           convert_x = uiuc_convert(token_value_convert2);
462           uiuc_1DdataFileReader(Mp_input_file,
463                                 Mp_input_timeArray,
464                                 Mp_input_MpArray,
465                                 Mp_input_ntime);
466           token6 >> token_value;
467           Mp_input_startTime = token_value;
468           break;
469         }
470       default:
471         {
472           if (ignore_unknown_keywords) {
473             // do nothing
474           } else {
475             // print error message
476             uiuc_warnings_errors(2, *command_line);
477           }
478           break;
479         }
480       };
481 }