]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_menu_engine.cpp
Harald JOHNSEN:
[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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
70  USA or view http://www.gnu.org/copyleft/gpl.html.
71
72 **********************************************************************/
73
74 #include <simgear/compiler.h>
75
76 #if defined( __MWERKS__ )
77 // -dw- optimizer chokes (big-time) trying to optimize humongous
78 // loop/switch statements
79 #pragma optimization_level 0
80 #endif
81
82 #include <cstdlib>
83 #include <string>
84 #include STL_IOSTREAM
85
86 #include "uiuc_menu_engine.h"
87
88 SG_USING_STD(cerr);
89 SG_USING_STD(cout);
90 SG_USING_STD(endl);
91
92 #ifndef _MSC_VER
93 SG_USING_STD(exit);
94 #endif
95
96 void parse_engine( const string& linetoken2, const string& linetoken3,
97                    const string& linetoken4, const string& linetoken5, 
98                    const string& linetoken6, const string& linetoken7, 
99                    const string& linetoken8, const string& linetoken9,
100                    const string& linetoken10,const string& aircraft_directory,
101                    LIST command_line ) {
102     double token_value;
103     int token_value_convert1, token_value_convert2;
104     istringstream token3(linetoken3.c_str());
105     istringstream token4(linetoken4.c_str());
106     istringstream token5(linetoken5.c_str());
107     istringstream token6(linetoken6.c_str());
108     istringstream token7(linetoken7.c_str());
109     istringstream token8(linetoken8.c_str());
110     istringstream token9(linetoken9.c_str());
111     istringstream token10(linetoken10.c_str());
112
113     switch(engine_map[linetoken2])
114       {
115       case simpleSingle_flag:
116         {
117           if (check_float(linetoken3))
118             token3 >> token_value;
119           else
120             uiuc_warnings_errors(1, *command_line);
121           
122           simpleSingleMaxThrust = token_value; 
123           engineParts -> storeCommands (*command_line);
124           break;
125         }
126       case simpleSingleModel_flag:
127         {
128           simpleSingleModel = true;
129           /* input the thrust at zero speed */
130           if (check_float(linetoken3))
131             token3 >> token_value;
132           else
133             uiuc_warnings_errors(1, *command_line);
134           t_v0 = token_value; 
135           /* input slope of thrust at speed for which thrust is zero */
136           if (check_float(linetoken4))
137             token4 >> token_value;
138           else
139             uiuc_warnings_errors(1, *command_line);
140           dtdv_t0 = token_value; 
141           /* input speed at which thrust is zero */
142           if (check_float(linetoken5))
143             token5 >> token_value;
144           else
145             uiuc_warnings_errors(1, *command_line);
146           v_t0 = token_value; 
147           dtdvvt = -dtdv_t0 * v_t0 / t_v0;
148           engineParts -> storeCommands (*command_line);
149           break;
150         }
151       case c172_flag:
152         {
153           engineParts -> storeCommands (*command_line);
154           break;
155         }
156       case cherokee_flag:
157         {
158           engineParts -> storeCommands (*command_line);
159           break;
160         }
161       case Throttle_pct_input_flag:
162         {
163           Throttle_pct_input = true;
164           Throttle_pct_input_file = aircraft_directory + linetoken3;
165           token4 >> token_value_convert1;
166           token5 >> token_value_convert2;
167           convert_y = uiuc_convert(token_value_convert1);
168           convert_x = uiuc_convert(token_value_convert2);
169           uiuc_1DdataFileReader(Throttle_pct_input_file,
170                                 Throttle_pct_input_timeArray,
171                                 Throttle_pct_input_dTArray,
172                                 Throttle_pct_input_ntime);
173           token6 >> token_value;
174           Throttle_pct_input_startTime = token_value;
175           break;
176         }
177       case gyroForce_Q_body_flag:
178         {
179           /* include gyroscopic forces due to pitch */
180           gyroForce_Q_body = true;
181           break;
182         }
183       case gyroForce_R_body_flag:
184         {
185           /* include gyroscopic forces due to yaw */
186           gyroForce_R_body = true;
187           break;
188         }
189
190       case slipstream_effects_flag:
191         {
192         // include slipstream effects
193           b_slipstreamEffects = true;
194           if (!simpleSingleModel)
195             uiuc_warnings_errors(3, *command_line);
196           break;
197         }
198       case propDia_flag:
199         {
200           if (check_float(linetoken3))
201             token3 >> token_value;
202           else
203             uiuc_warnings_errors(1, *command_line);
204           propDia = token_value;
205           break;
206         }
207       case eta_q_Cm_q_flag:
208         {
209         // include slipstream effects due to Cm_q
210           if (check_float(linetoken3))
211             token3 >> token_value;
212           else
213             uiuc_warnings_errors(1, *command_line);
214           eta_q_Cm_q_fac = token_value;
215           if (eta_q_Cm_q_fac == 0.0) {eta_q_Cm_q_fac = 1.0;}
216           break;
217         }
218       case eta_q_Cm_adot_flag:
219         {
220         // include slipstream effects due to Cm_adot
221           if (check_float(linetoken3))
222             token3 >> token_value;
223           else
224             uiuc_warnings_errors(1, *command_line);
225           eta_q_Cm_adot_fac = token_value;
226           if (eta_q_Cm_adot_fac == 0.0) {eta_q_Cm_adot_fac = 1.0;}
227           break;
228         }
229       case eta_q_Cmfade_flag:
230         {
231         // include slipstream effects due to Cmfade
232           if (check_float(linetoken3))
233             token3 >> token_value;
234           else
235             uiuc_warnings_errors(1, *command_line);
236           eta_q_Cmfade_fac = token_value;
237           if (eta_q_Cmfade_fac == 0.0) {eta_q_Cmfade_fac = 1.0;}
238           break;
239         }
240       case eta_q_Cm_de_flag:
241         {
242         // include slipstream effects due to Cmfade
243           if (check_float(linetoken3))
244             token3 >> token_value;
245           else
246             uiuc_warnings_errors(1, *command_line);
247           eta_q_Cm_de_fac = token_value;
248           if (eta_q_Cm_de_fac == 0.0) {eta_q_Cm_de_fac = 1.0;}
249           break;
250         }
251       case eta_q_Cl_beta_flag:
252         {
253         // include slipstream effects due to Cl_beta
254           if (check_float(linetoken3))
255             token3 >> token_value;
256           else
257             uiuc_warnings_errors(1, *command_line);
258           eta_q_Cl_beta_fac = token_value;
259           if (eta_q_Cl_beta_fac == 0.0) {eta_q_Cl_beta_fac = 1.0;}
260           break;
261         }
262       case eta_q_Cl_p_flag:
263         {
264         // include slipstream effects due to Cl_p
265           if (check_float(linetoken3))
266             token3 >> token_value;
267           else
268             uiuc_warnings_errors(1, *command_line);
269           eta_q_Cl_p_fac = token_value;
270           if (eta_q_Cl_p_fac == 0.0) {eta_q_Cl_p_fac = 1.0;}
271           break;
272         }
273       case eta_q_Cl_r_flag:
274         {
275         // include slipstream effects due to Cl_r
276           if (check_float(linetoken3))
277             token3 >> token_value;
278           else
279             uiuc_warnings_errors(1, *command_line);
280           eta_q_Cl_r_fac = token_value;
281           if (eta_q_Cl_r_fac == 0.0) {eta_q_Cl_r_fac = 1.0;}
282           break;
283         }
284       case eta_q_Cl_dr_flag:
285         {
286         // include slipstream effects due to Cl_dr
287           if (check_float(linetoken3))
288             token3 >> token_value;
289           else
290             uiuc_warnings_errors(1, *command_line);
291           eta_q_Cl_dr_fac = token_value;
292           if (eta_q_Cl_dr_fac == 0.0) {eta_q_Cl_dr_fac = 1.0;}
293           break;
294         }
295       case eta_q_CY_beta_flag:
296         {
297         // include slipstream effects due to CY_beta
298           if (check_float(linetoken3))
299             token3 >> token_value;
300           else
301             uiuc_warnings_errors(1, *command_line);
302           eta_q_CY_beta_fac = token_value;
303           if (eta_q_CY_beta_fac == 0.0) {eta_q_CY_beta_fac = 1.0;}
304           break;
305         }
306       case eta_q_CY_p_flag:
307         {
308         // include slipstream effects due to CY_p
309           if (check_float(linetoken3))
310             token3 >> token_value;
311           else
312             uiuc_warnings_errors(1, *command_line);
313           eta_q_CY_p_fac = token_value;
314           if (eta_q_CY_p_fac == 0.0) {eta_q_CY_p_fac = 1.0;}
315           break;
316         }
317       case eta_q_CY_r_flag:
318         {
319         // include slipstream effects due to CY_r
320           if (check_float(linetoken3))
321             token3 >> token_value;
322           else
323             uiuc_warnings_errors(1, *command_line);
324           eta_q_CY_r_fac = token_value;
325           if (eta_q_CY_r_fac == 0.0) {eta_q_CY_r_fac = 1.0;}
326           break;
327         }
328       case eta_q_CY_dr_flag:
329         {
330         // include slipstream effects due to CY_dr
331           if (check_float(linetoken3))
332             token3 >> token_value;
333           else
334             uiuc_warnings_errors(1, *command_line);
335           eta_q_CY_dr_fac = token_value;
336           if (eta_q_CY_dr_fac == 0.0) {eta_q_CY_dr_fac = 1.0;}
337           break;
338         }
339       case eta_q_Cn_beta_flag:
340         {
341         // include slipstream effects due to Cn_beta
342           if (check_float(linetoken3))
343             token3 >> token_value;
344           else
345             uiuc_warnings_errors(1, *command_line);
346           eta_q_Cn_beta_fac = token_value;
347           if (eta_q_Cn_beta_fac == 0.0) {eta_q_Cn_beta_fac = 1.0;}
348           break;
349         }
350       case eta_q_Cn_p_flag:
351         {
352         // include slipstream effects due to Cn_p
353           if (check_float(linetoken3))
354             token3 >> token_value;
355           else
356             uiuc_warnings_errors(1, *command_line);
357           eta_q_Cn_p_fac = token_value;
358           if (eta_q_Cn_p_fac == 0.0) {eta_q_Cn_p_fac = 1.0;}
359           break;
360         }
361       case eta_q_Cn_r_flag:
362         {
363         // include slipstream effects due to Cn_r
364           if (check_float(linetoken3))
365             token3 >> token_value;
366           else
367             uiuc_warnings_errors(1, *command_line);
368           eta_q_Cn_r_fac = token_value;
369           if (eta_q_Cn_r_fac == 0.0) {eta_q_Cn_r_fac = 1.0;}
370           break;
371         }
372       case eta_q_Cn_dr_flag:
373         {
374         // include slipstream effects due to Cn_dr
375           if (check_float(linetoken3))
376             token3 >> token_value;
377           else
378             uiuc_warnings_errors(1, *command_line);
379           eta_q_Cn_dr_fac = token_value;
380           if (eta_q_Cn_dr_fac == 0.0) {eta_q_Cn_dr_fac = 1.0;}
381           break;
382         }
383
384       case omega_flag:
385         {
386           if (check_float(linetoken3))
387             token3 >> token_value;
388           else
389             uiuc_warnings_errors(1, *command_line);
390           minOmega = token_value; 
391           if (check_float(linetoken4))
392             token4 >> token_value;
393           else
394             uiuc_warnings_errors(1, *command_line);
395           maxOmega = token_value; 
396           break;
397         }
398       case omegaRPM_flag:
399         {
400           if (check_float(linetoken3))
401             token3 >> token_value;
402           else
403             uiuc_warnings_errors(1, *command_line);
404           minOmegaRPM = token_value; 
405           minOmega    = minOmegaRPM * 2.0 * LS_PI / 60;
406           if (check_float(linetoken4))
407             token4 >> token_value;
408           else
409             uiuc_warnings_errors(1, *command_line);
410           maxOmegaRPM = token_value; 
411           maxOmega    = maxOmegaRPM * 2.0 * LS_PI / 60;
412           break;
413         }
414       case polarInertia_flag:
415         {
416           if (check_float(linetoken3))
417             token3 >> token_value;
418           else
419             uiuc_warnings_errors(1, *command_line);
420           polarInertia = token_value; 
421           break;
422         }
423       case forcemom_flag:
424         {
425           engineParts -> storeCommands (*command_line);
426           break;
427         }
428       case Xp_input_flag:
429         {
430           Xp_input = true;
431           Xp_input_file = aircraft_directory + linetoken3;
432           token4 >> token_value_convert1;
433           token5 >> token_value_convert2;
434           convert_y = uiuc_convert(token_value_convert1);
435           convert_x = uiuc_convert(token_value_convert2);
436           uiuc_1DdataFileReader(Xp_input_file,
437                                 Xp_input_timeArray,
438                                 Xp_input_XpArray,
439                                 Xp_input_ntime);
440           token6 >> token_value;
441           Xp_input_startTime = token_value;
442           break;
443         }
444       case Zp_input_flag:
445         {
446           Zp_input = true;
447           Zp_input_file = aircraft_directory + linetoken3;
448           token4 >> token_value_convert1;
449           token5 >> token_value_convert2;
450           convert_y = uiuc_convert(token_value_convert1);
451           convert_x = uiuc_convert(token_value_convert2);
452           uiuc_1DdataFileReader(Zp_input_file,
453                                 Zp_input_timeArray,
454                                 Zp_input_ZpArray,
455                                 Zp_input_ntime);
456           token6 >> token_value;
457           Zp_input_startTime = token_value;
458           break;
459         }
460       case Mp_input_flag:
461         {
462           Mp_input = true;
463           Mp_input_file = aircraft_directory + linetoken3;
464           token4 >> token_value_convert1;
465           token5 >> token_value_convert2;
466           convert_y = uiuc_convert(token_value_convert1);
467           convert_x = uiuc_convert(token_value_convert2);
468           uiuc_1DdataFileReader(Mp_input_file,
469                                 Mp_input_timeArray,
470                                 Mp_input_MpArray,
471                                 Mp_input_ntime);
472           token6 >> token_value;
473           Mp_input_startTime = token_value;
474           break;
475         }
476       default:
477         {
478           if (ignore_unknown_keywords) {
479             // do nothing
480           } else {
481             // print error message
482             uiuc_warnings_errors(2, *command_line);
483           }
484           break;
485         }
486       };
487 }