1 /**********************************************************************
2 
3  FILENAME:     uiuc_menu_init.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                08/20/2003   (RD) removed old_flap_routine
25 
26 ----------------------------------------------------------------------
27 
28  AUTHOR(S):    Robert Deters      <rdeters@uiuc.edu>
29                Michael Selig      <m-selig@uiuc.edu>
30 
31 ----------------------------------------------------------------------
32 
33  VARIABLES:
34 
35 ----------------------------------------------------------------------
36 
37  INPUTS:       n/a
38 
39 ----------------------------------------------------------------------
40 
41  OUTPUTS:      n/a
42 
43 ----------------------------------------------------------------------
44 
45  CALLED BY:    uiuc_menu()
46 
47 ----------------------------------------------------------------------
48 
49  CALLS TO:     check_float() if needed
50                d_2_to_3() if needed
51                d_1_to_2() if needed
52                i_1_to_2() if needed
53                d_1_to_1() if needed
54 
55  ----------------------------------------------------------------------
56 
57  COPYRIGHT:    (C) 2003 by Michael Selig
58 
59  This program is free software; you can redistribute it and/or
60  modify it under the terms of the GNU General Public License
61  as published by the Free Software Foundation.
62 
63  This program is distributed in the hope that it will be useful,
64  but WITHOUT ANY WARRANTY; without even the implied warranty of
65  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
66  GNU General Public License for more details.
67 
68  You should have received a copy of the GNU General Public License
69  along with this program; if not, write to the Free Software
70  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
71 
72 **********************************************************************/
73 
74 #include <simgear/compiler.h>
75 
76 
77 #include <cstdlib>
78 #include <string>
79 #include <iostream>
80 
81 #include "uiuc_menu_init.h"
82 
83 using std::cerr;
84 using std::cout;
85 using std::endl;
86 
87 #ifndef _MSC_VER
88 using std::exit;
89 #endif
90 
parse_init(const string & linetoken2,const string & linetoken3,const string & linetoken4,const string & linetoken5,const string & linetoken6,const string & linetoken7,const string & linetoken8,const string & linetoken9,const string & linetoken10,const string & aircraft_directory,LIST command_line)91 void parse_init( const string& linetoken2, const string& linetoken3,
92                  const string& linetoken4, const string& linetoken5,
93                  const string& linetoken6, const string& linetoken7,
94                  const string& linetoken8, const string& linetoken9,
95                  const string& linetoken10, const string& aircraft_directory,
96                  LIST command_line ) {
97     double token_value;
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     int token_value_recordRate;
107 
108     switch(init_map[linetoken2])
109       {
110       case Dx_pilot_flag:
111         {
112           if (check_float(linetoken3))
113             token3 >> token_value;
114           else
115             uiuc_warnings_errors(1, *command_line);
116 
117           Dx_pilot = token_value;
118           initParts -> storeCommands (*command_line);
119           break;
120         }
121       case Dy_pilot_flag:
122         {
123           if (check_float(linetoken3))
124             token3 >> token_value;
125           else
126             uiuc_warnings_errors(1, *command_line);
127 
128           Dy_pilot = token_value;
129           initParts -> storeCommands (*command_line);
130           break;
131         }
132       case Dz_pilot_flag:
133         {
134           if (check_float(linetoken3))
135             token3 >> token_value;
136           else
137             uiuc_warnings_errors(1, *command_line);
138 
139           Dz_pilot = token_value;
140           initParts -> storeCommands (*command_line);
141           break;
142         }
143       case Dx_cg_flag:
144         {
145           if (check_float(linetoken3))
146             token3 >> token_value;
147           else
148             uiuc_warnings_errors(1, *command_line);
149 
150           Dx_cg = token_value;
151           initParts -> storeCommands (*command_line);
152           break;
153         }
154       case Dy_cg_flag:
155         {
156           if (check_float(linetoken3))
157             token3 >> token_value;
158           else
159             uiuc_warnings_errors(1, *command_line);
160 
161           Dy_cg = token_value;
162           initParts -> storeCommands (*command_line);
163           break;
164         }
165       case Dz_cg_flag:
166         {
167           if (check_float(linetoken3))
168             token3 >> token_value;
169           else
170             uiuc_warnings_errors(1, *command_line);
171 
172           Dz_cg = token_value;
173           initParts -> storeCommands (*command_line);
174           break;
175         }
176       case Altitude_flag:
177         {
178           if (check_float(linetoken3))
179             token3 >> token_value;
180           else
181             uiuc_warnings_errors(1, *command_line);
182 
183           Altitude = token_value;
184           initParts -> storeCommands (*command_line);
185           break;
186         }
187       case V_north_flag:
188         {
189           if (check_float(linetoken3))
190             token3 >> token_value;
191           else
192             uiuc_warnings_errors(1, *command_line);
193 
194           V_north = token_value;
195           initParts -> storeCommands (*command_line);
196           break;
197         }
198       case V_east_flag:
199         {
200           initParts -> storeCommands (*command_line);
201           if (check_float(linetoken3))
202             token3 >> token_value;
203           else
204             uiuc_warnings_errors(1, *command_line);
205 
206           V_east = token_value;
207           break;
208         }
209       case V_down_flag:
210         {
211           if (check_float(linetoken3))
212             token3 >> token_value;
213           else
214             uiuc_warnings_errors(1, *command_line);
215 
216           V_down = token_value;
217           initParts -> storeCommands (*command_line);
218           break;
219         }
220       case P_body_flag:
221         {
222           if (check_float(linetoken3))
223             token3 >> token_value;
224           else
225             uiuc_warnings_errors(1, *command_line);
226 
227           P_body_init_true = true;
228           P_body_init = token_value;
229           initParts -> storeCommands (*command_line);
230           break;
231         }
232       case Q_body_flag:
233         {
234           if (check_float(linetoken3))
235             token3 >> token_value;
236           else
237             uiuc_warnings_errors(1, *command_line);
238 
239           Q_body_init_true = true;
240           Q_body_init = token_value;
241           initParts -> storeCommands (*command_line);
242           break;
243         }
244       case R_body_flag:
245         {
246           if (check_float(linetoken3))
247             token3 >> token_value;
248           else
249             uiuc_warnings_errors(1, *command_line);
250 
251           R_body_init_true = true;
252           R_body_init = token_value;
253           initParts -> storeCommands (*command_line);
254           break;
255         }
256       case Phi_flag:
257         {
258           if (check_float(linetoken3))
259             token3 >> token_value;
260           else
261             uiuc_warnings_errors(1, *command_line);
262 
263           Phi_init_true = true;
264           Phi_init = token_value;
265           initParts -> storeCommands (*command_line);
266           break;
267         }
268       case Theta_flag:
269         {
270           if (check_float(linetoken3))
271             token3 >> token_value;
272           else
273             uiuc_warnings_errors(1, *command_line);
274 
275           Theta_init_true = true;
276           Theta_init = token_value;
277           initParts -> storeCommands (*command_line);
278           break;
279         }
280       case Psi_flag:
281         {
282           if (check_float(linetoken3))
283             token3 >> token_value;
284           else
285             uiuc_warnings_errors(1, *command_line);
286 
287           Psi_init_true = true;
288           Psi_init = token_value;
289           initParts -> storeCommands (*command_line);
290           break;
291         }
292       case Long_trim_flag:
293         {
294           if (check_float(linetoken3))
295             token3 >> token_value;
296           else
297             uiuc_warnings_errors(1, *command_line);
298 
299           Long_trim = token_value;
300           initParts -> storeCommands (*command_line);
301           break;
302         }
303       case recordRate_flag:
304         {
305           //can't use check_float since variable is integer
306           token3 >> token_value_recordRate;
307           recordRate = 120 / token_value_recordRate;
308           break;
309         }
310       case recordStartTime_flag:
311         {
312           if (check_float(linetoken3))
313             token3 >> token_value;
314           else
315             uiuc_warnings_errors(1, *command_line);
316 
317           recordStartTime = token_value;
318           break;
319         }
320       case use_V_rel_wind_2U_flag:
321         {
322           use_V_rel_wind_2U = true;
323           break;
324         }
325       case nondim_rate_V_rel_wind_flag:
326         {
327           nondim_rate_V_rel_wind = true;
328           break;
329         }
330       case use_abs_U_body_2U_flag:
331         {
332           use_abs_U_body_2U = true;
333           break;
334         }
335       case dyn_on_speed_flag:
336         {
337           if (check_float(linetoken3))
338             token3 >> token_value;
339           else
340             uiuc_warnings_errors(1, *command_line);
341 
342           dyn_on_speed = token_value;
343           break;
344         }
345       case dyn_on_speed_zero_flag:
346         {
347           if (check_float(linetoken3))
348             token3 >> token_value;
349           else
350             uiuc_warnings_errors(1, *command_line);
351 
352           dyn_on_speed_zero = token_value;
353           break;
354         }
355       case use_dyn_on_speed_curve1_flag:
356         {
357           use_dyn_on_speed_curve1 = true;
358           break;
359         }
360       case use_Alpha_dot_on_speed_flag:
361         {
362           use_Alpha_dot_on_speed = true;
363           if (check_float(linetoken3))
364             token3 >> token_value;
365           else
366             uiuc_warnings_errors(1, *command_line);
367           Alpha_dot_on_speed = token_value;
368           break;
369         }
370       case use_gamma_horiz_on_speed_flag:
371         {
372           use_gamma_horiz_on_speed = true;
373           if (check_float(linetoken3))
374             token3 >> token_value;
375           else
376             uiuc_warnings_errors(1, *command_line);
377           gamma_horiz_on_speed = token_value;
378           break;
379         }
380       case downwashMode_flag:
381         {
382           b_downwashMode = true;
383           token3 >> downwashMode;
384           if (downwashMode==100)
385             ;
386           // compute downwash using downwashCoef, do nothing here
387           else
388             uiuc_warnings_errors(4, *command_line);
389           break;
390         }
391       case downwashCoef_flag:
392         {
393           if (check_float(linetoken3))
394             token3 >> token_value;
395           else
396             uiuc_warnings_errors(1, *command_line);
397           downwashCoef = token_value;
398           break;
399         }
400       case Alpha_flag:
401         {
402           if (check_float(linetoken3))
403             token3 >> token_value;
404           else
405             uiuc_warnings_errors(1, *command_line);
406 
407           Alpha_init_true = true;
408           Alpha_init = token_value;
409           break;
410         }
411       case Beta_flag:
412         {
413           if (check_float(linetoken3))
414             token3 >> token_value;
415           else
416             uiuc_warnings_errors(1, *command_line);
417 
418           Beta_init_true = true;
419           Beta_init = token_value;
420           break;
421         }
422       case U_body_flag:
423         {
424           if (check_float(linetoken3))
425             token3 >> token_value;
426           else
427             uiuc_warnings_errors(1, *command_line);
428 
429           U_body_init_true = true;
430           U_body_init = token_value;
431           break;
432         }
433       case V_body_flag:
434         {
435           if (check_float(linetoken3))
436             token3 >> token_value;
437           else
438             uiuc_warnings_errors(1, *command_line);
439 
440           V_body_init_true = true;
441           V_body_init = token_value;
442           break;
443         }
444       case W_body_flag:
445         {
446           if (check_float(linetoken3))
447             token3 >> token_value;
448           else
449             uiuc_warnings_errors(1, *command_line);
450 
451           W_body_init_true = true;
452           W_body_init = token_value;
453           break;
454         }
455       case ignore_unknown_keywords_flag:
456         {
457           ignore_unknown_keywords=true;
458           break;
459         }
460       case trim_case_2_flag:
461         {
462           trim_case_2 = true;
463           break;
464         }
465       case use_uiuc_network_flag:
466         {
467           use_uiuc_network = true;
468           server_IP = linetoken3;
469           token4 >> port_num;
470           break;
471         }
472       case icing_demo_flag:
473         {
474           icing_demo = true;
475           break;
476         }
477       case outside_control_flag:
478         {
479           outside_control = true;
480           break;
481         }
482       default:
483         {
484           if (ignore_unknown_keywords){
485             // do nothing
486           } else {
487             // print error message
488             uiuc_warnings_errors(2, *command_line);
489           }
490           break;
491         }
492       };
493 }
494