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