]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_menu_controlSurface.cpp
Make sure sign is preserved for turbulence direction.
[flightgear.git] / src / FDM / UIUCModel / uiuc_menu_controlSurface.cpp
1 /**********************************************************************
2                                                                        
3  FILENAME:     uiuc_menu_controlSurface.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_controlSurface.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_controlSurface( 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, 
98                            const string& aircraft_directory, 
99                            LIST command_line ) {
100     double token_value;
101     int token_value_convert1, token_value_convert2;
102     istrstream token3(linetoken3.c_str());
103     istrstream token4(linetoken4.c_str());
104     istrstream token5(linetoken5.c_str());
105     istrstream token6(linetoken6.c_str());
106     istrstream token7(linetoken7.c_str());
107     istrstream token8(linetoken8.c_str());
108     istrstream token9(linetoken9.c_str());
109     istrstream token10(linetoken10.c_str());
110
111     switch(controlSurface_map[linetoken2])
112       {
113       case de_flag:
114         {
115           if (check_float(linetoken3))
116             token3 >> token_value;
117           else
118             uiuc_warnings_errors(1, *command_line);
119           
120           demax = token_value;
121           
122           if (check_float(linetoken4))
123             token4 >> token_value;
124           else
125             uiuc_warnings_errors(1, *command_line);
126           
127           demin = token_value;
128           break;
129         }
130       case da_flag:
131         {
132           if (check_float(linetoken3))
133             token3 >> token_value;
134           else
135             uiuc_warnings_errors(1, *command_line);
136           
137           damax = token_value;
138           
139           if (check_float(linetoken4))
140             token4 >> token_value;
141           else
142             uiuc_warnings_errors(1, *command_line);
143           
144           damin = token_value;
145           break;
146         }
147       case dr_flag:
148         {
149           if (check_float(linetoken3))
150             token3 >> token_value;
151           else
152             uiuc_warnings_errors(1, *command_line);
153           
154           drmax = token_value;
155           
156           if (check_float(linetoken4))
157             token4 >> token_value;
158           else
159             uiuc_warnings_errors(1, *command_line);
160           
161           drmin = token_value;
162           break;
163         }
164       case set_Long_trim_flag:
165         {
166           if (check_float(linetoken3))
167             token3 >> token_value;
168           else
169             uiuc_warnings_errors(1, *command_line);
170           
171           set_Long_trim = true;
172           elevator_tab = token_value;
173           break;
174         }
175       case set_Long_trim_deg_flag:
176         {
177           if (check_float(linetoken3))
178             token3 >> token_value;
179           else
180             uiuc_warnings_errors(1, *command_line);
181           
182           set_Long_trim = true;
183           elevator_tab = token_value * DEG_TO_RAD;
184           break;
185         }
186       case zero_Long_trim_flag:
187         {
188           zero_Long_trim = true;
189           break;
190         }
191       case elevator_step_flag:
192         {
193           // set step input flag
194           elevator_step = true;
195           
196           // read in step angle in degrees and convert
197           if (check_float(linetoken3))
198             token3 >> token_value;
199           else
200             uiuc_warnings_errors(1, *command_line);
201           
202           elevator_step_angle = token_value * DEG_TO_RAD;
203           
204           // read in step start time
205           if (check_float(linetoken4))
206             token4 >> token_value;
207           else
208             uiuc_warnings_errors(1, *command_line);
209           
210           elevator_step_startTime = token_value;
211           break;
212         }
213       case elevator_singlet_flag:
214         {
215           // set singlet input flag
216           elevator_singlet = true;
217           
218           // read in singlet angle in degrees and convert
219           if (check_float(linetoken3))
220             token3 >> token_value;
221           else
222             uiuc_warnings_errors(1, *command_line);
223           
224           elevator_singlet_angle = token_value * DEG_TO_RAD;
225           
226           // read in singlet start time
227           if (check_float(linetoken4))
228             token4 >> token_value;
229           else
230             uiuc_warnings_errors(1, *command_line);
231           
232           elevator_singlet_startTime = token_value;
233           
234           // read in singlet duration
235           if (check_float(linetoken5))
236             token5 >> token_value;
237           else
238             uiuc_warnings_errors(1, *command_line);
239           
240           elevator_singlet_duration = token_value;
241           break;
242         }
243       case elevator_doublet_flag:
244         {
245           // set doublet input flag
246           elevator_doublet = true;
247           
248           // read in doublet angle in degrees and convert
249           if (check_float(linetoken3))
250             token3 >> token_value;
251           else
252             uiuc_warnings_errors(1, *command_line);
253           
254           elevator_doublet_angle = token_value * DEG_TO_RAD;
255           
256           // read in doublet start time
257           if (check_float(linetoken4))
258             token4 >> token_value;
259           else
260             uiuc_warnings_errors(1, *command_line);
261           
262           elevator_doublet_startTime = token_value;
263           
264           // read in doublet duration
265           if (check_float(linetoken5))
266             token5 >> token_value;
267           else
268             uiuc_warnings_errors(1, *command_line);
269           
270           elevator_doublet_duration = token_value;
271           break;
272         }
273       case elevator_input_flag:
274         {
275           elevator_input = true;
276           elevator_input_file = aircraft_directory + linetoken3;
277           token4 >> token_value_convert1;
278           token5 >> token_value_convert2;
279           convert_y = uiuc_convert(token_value_convert1);
280           convert_x = uiuc_convert(token_value_convert2);
281           uiuc_1DdataFileReader(elevator_input_file,
282                                 elevator_input_timeArray,
283                                 elevator_input_deArray,
284                                 elevator_input_ntime);
285           token6 >> token_value;
286           elevator_input_startTime = token_value;
287           break;
288         }
289       case aileron_input_flag:
290         {
291           aileron_input = true;
292           aileron_input_file = aircraft_directory + linetoken3;
293           token4 >> token_value_convert1;
294           token5 >> token_value_convert2;
295           convert_y = uiuc_convert(token_value_convert1);
296           convert_x = uiuc_convert(token_value_convert2);
297           uiuc_1DdataFileReader(aileron_input_file,
298                                 aileron_input_timeArray,
299                                 aileron_input_daArray,
300                                 aileron_input_ntime);
301           token6 >> token_value;
302           aileron_input_startTime = token_value;
303           break;
304         }
305       case rudder_input_flag:
306         {
307           rudder_input = true;
308           rudder_input_file = aircraft_directory + linetoken3;
309           token4 >> token_value_convert1;
310           token5 >> token_value_convert2;
311           convert_y = uiuc_convert(token_value_convert1);
312           convert_x = uiuc_convert(token_value_convert2);
313           uiuc_1DdataFileReader(rudder_input_file,
314                                 rudder_input_timeArray,
315                                 rudder_input_drArray,
316                                 rudder_input_ntime);
317           token6 >> token_value;
318           rudder_input_startTime = token_value;
319           break;
320         }
321       case flap_pos_input_flag:
322         {
323           flap_pos_input = true;
324           flap_pos_input_file = aircraft_directory + linetoken3;
325           token4 >> token_value_convert1;
326           token5 >> token_value_convert2;
327           convert_y = uiuc_convert(token_value_convert1);
328           convert_x = uiuc_convert(token_value_convert2);
329           uiuc_1DdataFileReader(flap_pos_input_file,
330                                 flap_pos_input_timeArray,
331                                 flap_pos_input_dfArray,
332                                 flap_pos_input_ntime);
333           token6 >> token_value;
334           flap_pos_input_startTime = token_value;
335           break;
336         }
337       case pilot_elev_no_flag:
338         {
339           pilot_elev_no_check = true;
340           break;
341         }
342       case pilot_ail_no_flag:
343         {
344           pilot_ail_no_check = true;
345           break;
346         }
347       case pilot_rud_no_flag:
348         {
349           pilot_rud_no_check = true;
350           break;
351         }
352       case flap_max_flag:
353         {
354           if (check_float(linetoken3))
355             token3 >> token_value;
356           else
357             uiuc_warnings_errors(1, *command_line);
358           
359           use_flaps = true;
360           flap_max = token_value;
361           break;
362         }
363       case flap_rate_flag:
364         {
365           if (check_float(linetoken3))
366             token3 >> token_value;
367           else
368             uiuc_warnings_errors(1, *command_line);
369           
370           use_flaps = true;
371           flap_rate = token_value;
372           break;
373         }
374       case spoiler_max_flag:
375         {
376           if (check_float(linetoken3))
377             token3 >> token_value;
378           else
379             uiuc_warnings_errors(1, *command_line);
380           
381           use_spoilers = true;
382           spoiler_max = token_value;
383           break;
384         }
385       case spoiler_rate_flag:
386         {
387           if (check_float(linetoken3))
388             token3 >> token_value;
389           else
390             uiuc_warnings_errors(1, *command_line);
391           
392           use_spoilers = true;
393           spoiler_rate = token_value;
394           break;
395         }
396       case aileron_sas_KP_flag:
397         {
398           if (check_float(linetoken3))
399             token3 >> token_value;
400           else
401             uiuc_warnings_errors(1, *command_line);
402
403           aileron_sas_KP = token_value;
404           break;
405         }
406       case aileron_sas_max_flag:
407         {
408           if (check_float(linetoken3))
409             token3 >> token_value;
410           else
411             uiuc_warnings_errors(1, *command_line);
412           aileron_sas_max = token_value;
413           use_aileron_sas_max = true;
414           break;
415         }
416       case aileron_stick_gain_flag:
417         {
418           if (check_float(linetoken3))
419             token3 >> token_value;
420           else
421             uiuc_warnings_errors(1, *command_line);
422           aileron_stick_gain = token_value;
423           use_aileron_stick_gain = true;
424           break;
425         }
426       case elevator_sas_KQ_flag:
427         {
428           if (check_float(linetoken3))
429             token3 >> token_value;
430           else
431             uiuc_warnings_errors(1, *command_line);
432           elevator_sas_KQ = token_value;
433           break;
434         }
435       case elevator_sas_max_flag:
436         {
437           if (check_float(linetoken3))
438             token3 >> token_value;
439           else
440             uiuc_warnings_errors(1, *command_line);
441           elevator_sas_max = token_value;
442           use_elevator_sas_max = true;
443           break;
444         }
445       case elevator_sas_min_flag:
446         {
447           if (check_float(linetoken3))
448             token3 >> token_value;
449           else
450             uiuc_warnings_errors(1, *command_line);
451           elevator_sas_min = token_value;
452           use_elevator_sas_min = true;
453           break;
454         }
455       case elevator_stick_gain_flag:
456         {
457           if (check_float(linetoken3))
458             token3 >> token_value;
459           else
460             uiuc_warnings_errors(1, *command_line);
461           elevator_stick_gain = token_value;
462           use_elevator_stick_gain = true;
463           break;
464         }
465       case rudder_sas_KR_flag:
466         {
467           if (check_float(linetoken3))
468             token3 >> token_value;
469           else
470             uiuc_warnings_errors(1, *command_line);
471           rudder_sas_KR = token_value;
472           break;
473         }
474       case rudder_sas_max_flag:
475         {
476           if (check_float(linetoken3))
477             token3 >> token_value;
478           else
479             uiuc_warnings_errors(1, *command_line);
480           rudder_sas_max = token_value;
481           use_rudder_sas_max = true;
482           break;
483         }
484       case rudder_stick_gain_flag:
485         {
486           if (check_float(linetoken3))
487             token3 >> token_value;
488           else
489             uiuc_warnings_errors(1, *command_line);
490           rudder_stick_gain = token_value;
491           use_rudder_stick_gain = true;
492           break;
493         }
494       case use_aileron_sas_type1_flag:
495         {
496           use_aileron_sas_type1 = true;
497           break;
498         }
499       case use_elevator_sas_type1_flag:
500         {
501           use_elevator_sas_type1 = true;
502           break;
503         }
504       case use_rudder_sas_type1_flag:
505         {
506           use_rudder_sas_type1 = true;
507           break;
508         }
509       default:
510         {
511           if (ignore_unknown_keywords) {
512             // do nothing
513           } else {
514             // print error message
515             uiuc_warnings_errors(2, *command_line);
516           }
517           break;
518         }
519       };
520 }