]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_menu_CD.cpp
Make yasim accept the launchbar and hook properties. They are not tied to anything...
[flightgear.git] / src / FDM / UIUCModel / uiuc_menu_CD.cpp
1 /**********************************************************************
2                                                                        
3  FILENAME:     uiuc_menu_CD.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_CD.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_CD( 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, token_value_convert3;
104     int token_value_convert4;
105     double datafile_xArray[100][100], datafile_yArray[100];
106     double datafile_zArray[100][100];
107     double convert_f;
108     int datafile_nxArray[100], datafile_ny;
109     istringstream token3(linetoken3.c_str());
110     istringstream token4(linetoken4.c_str());
111     istringstream token5(linetoken5.c_str());
112     istringstream token6(linetoken6.c_str());
113     istringstream token7(linetoken7.c_str());
114     istringstream token8(linetoken8.c_str());
115     istringstream token9(linetoken9.c_str());
116     istringstream token10(linetoken10.c_str());
117
118     static bool CXfabetaf_first = true;
119     static bool CXfadef_first = true;
120     static bool CXfaqf_first = true;
121
122     switch(CD_map[linetoken2])
123       {
124       case CDo_flag:
125         {
126           if (check_float(linetoken3))
127             token3 >> token_value;
128           else
129             uiuc_warnings_errors(1, *command_line);
130           
131           CDo = token_value;
132           CDo_clean = CDo;
133           aeroDragParts -> storeCommands (*command_line);
134           break;
135         }
136       case CDK_flag:
137         {
138           if (check_float(linetoken3))
139             token3 >> token_value;
140           else
141             uiuc_warnings_errors(1, *command_line);
142           
143           CDK = token_value;
144           CDK_clean = CDK;
145           aeroDragParts -> storeCommands (*command_line);
146           break;
147         }
148       case CLK_flag:
149         {
150           b_CLK = true;
151           if (check_float(linetoken3))
152             token3 >> token_value;
153           else
154             uiuc_warnings_errors(1, *command_line);
155           CLK = token_value;
156           break;
157         }
158       case CD_a_flag:
159         {
160           if (check_float(linetoken3))
161             token3 >> token_value;
162           else
163             uiuc_warnings_errors(1, *command_line);
164           
165           CD_a = token_value;
166           CD_a_clean = CD_a;
167           aeroDragParts -> storeCommands (*command_line);
168           break;
169         }
170       case CD_adot_flag:
171         {
172           if (check_float(linetoken3))
173             token3 >> token_value;
174           else
175             uiuc_warnings_errors(1, *command_line);
176           
177           CD_adot = token_value;
178           CD_adot_clean = CD_adot;
179           aeroDragParts -> storeCommands (*command_line);
180           break;
181         }
182       case CD_q_flag:
183         {
184           if (check_float(linetoken3))
185             token3 >> token_value;
186           else
187             uiuc_warnings_errors(1, *command_line);
188           
189           CD_q = token_value;
190           CD_q_clean = CD_q;
191           aeroDragParts -> storeCommands (*command_line);
192           break;
193         }
194       case CD_ih_flag:
195         {
196           if (check_float(linetoken3))
197             token3 >> token_value;
198           else
199             uiuc_warnings_errors(1, *command_line);
200           
201           CD_ih = token_value;
202           aeroDragParts -> storeCommands (*command_line);
203           break;
204         }
205       case CD_de_flag:
206         {
207           if (check_float(linetoken3))
208             token3 >> token_value;
209           else
210             uiuc_warnings_errors(1, *command_line);
211           
212           CD_de = token_value;
213           CD_de_clean = CD_de;
214           aeroDragParts -> storeCommands (*command_line);
215           break;
216         }
217       case CD_dr_flag:
218         {
219           if (check_float(linetoken3))
220             token3 >> token_value;
221           else
222             uiuc_warnings_errors(1, *command_line);
223           
224           CD_dr = token_value;
225           aeroDragParts -> storeCommands (*command_line);
226           break;
227         }
228       case CD_da_flag:
229         {
230           if (check_float(linetoken3))
231             token3 >> token_value;
232           else
233             uiuc_warnings_errors(1, *command_line);
234           
235           CD_da = token_value;
236           aeroDragParts -> storeCommands (*command_line);
237           break;
238         }
239       case CD_beta_flag:
240         {
241           if (check_float(linetoken3))
242             token3 >> token_value;
243           else
244             uiuc_warnings_errors(1, *command_line);
245           
246           CD_beta = token_value;
247           aeroDragParts -> storeCommands (*command_line);
248           break;
249         }
250       case CD_df_flag:
251         {
252           if (check_float(linetoken3))
253             token3 >> token_value;
254           else
255             uiuc_warnings_errors(1, *command_line);
256           
257           CD_df = token_value;
258           aeroDragParts -> storeCommands (*command_line);
259           break;
260         }
261       case CD_ds_flag:
262         {
263           if (check_float(linetoken3))
264             token3 >> token_value;
265           else
266             uiuc_warnings_errors(1, *command_line);
267           
268           CD_ds = token_value;
269           aeroDragParts -> storeCommands (*command_line);
270           break;
271         }
272       case CD_dg_flag:
273         {
274           if (check_float(linetoken3))
275             token3 >> token_value;
276           else
277             uiuc_warnings_errors(1, *command_line);
278           
279           CD_dg = token_value;
280           aeroDragParts -> storeCommands (*command_line);
281           break;
282         }
283       case CDfa_flag:
284         {
285           CDfa = aircraft_directory + linetoken3;
286           token4 >> token_value_convert1;
287           token5 >> token_value_convert2;
288           convert_y = uiuc_convert(token_value_convert1);
289           convert_x = uiuc_convert(token_value_convert2);
290           /* call 1D File Reader with file name (CDfa) and conversion 
291              factors; function returns array of alphas (aArray) and 
292              corresponding CD values (CDArray) and max number of 
293              terms in arrays (nAlpha) */
294           uiuc_1DdataFileReader(CDfa,
295                                 CDfa_aArray,
296                                 CDfa_CDArray,
297                                 CDfa_nAlpha);
298           aeroDragParts -> storeCommands (*command_line);
299           break;
300         }
301       case CDfCL_flag:
302         {
303           CDfCL = aircraft_directory + linetoken3;
304           token4 >> token_value_convert1;
305           token5 >> token_value_convert2;
306           convert_y = uiuc_convert(token_value_convert1);
307           convert_x = uiuc_convert(token_value_convert2);
308           /* call 1D File Reader with file name (CDfCL) and conversion 
309              factors; function returns array of CLs (CLArray) and 
310              corresponding CD values (CDArray) and max number of 
311              terms in arrays (nCL) */
312           uiuc_1DdataFileReader(CDfCL,
313                                 CDfCL_CLArray,
314                                 CDfCL_CDArray,
315                                 CDfCL_nCL);
316           aeroDragParts -> storeCommands (*command_line);
317           break;
318         }
319       case CDfade_flag:
320         {
321           CDfade = aircraft_directory + linetoken3;
322           token4 >> token_value_convert1;
323           token5 >> token_value_convert2;
324           token6 >> token_value_convert3;
325           convert_z = uiuc_convert(token_value_convert1);
326           convert_x = uiuc_convert(token_value_convert2);
327           convert_y = uiuc_convert(token_value_convert3);
328           /* call 2D File Reader with file name (CDfade) and 
329              conversion factors; function returns array of 
330              elevator deflections (deArray) and corresponding 
331              alpha (aArray) and delta CD (CDArray) values and 
332              max number of terms in alpha arrays (nAlphaArray) 
333              and deflection array (nde) */
334           uiuc_2DdataFileReader(CDfade,
335                                 CDfade_aArray,
336                                 CDfade_deArray,
337                                 CDfade_CDArray,
338                                 CDfade_nAlphaArray,
339                                 CDfade_nde);
340           aeroDragParts -> storeCommands (*command_line);
341           break;
342         }
343       case CDfdf_flag:
344         {
345           CDfdf = aircraft_directory + linetoken3;
346           token4 >> token_value_convert1;
347           token5 >> token_value_convert2;
348           convert_y = uiuc_convert(token_value_convert1);
349           convert_x = uiuc_convert(token_value_convert2);
350           /* call 1D File Reader with file name (CDfdf) and conversion 
351              factors; function returns array of dfs (dfArray) and 
352              corresponding CD values (CDArray) and max number of 
353              terms in arrays (ndf) */
354           uiuc_1DdataFileReader(CDfdf,
355                                 CDfdf_dfArray,
356                                 CDfdf_CDArray,
357                                 CDfdf_ndf);
358           aeroDragParts -> storeCommands (*command_line);
359           break;
360         }
361       case CDfadf_flag:
362         {
363           CDfadf = aircraft_directory + linetoken3;
364           token4 >> token_value_convert1;
365           token5 >> token_value_convert2;
366           token6 >> token_value_convert3;
367           convert_z = uiuc_convert(token_value_convert1);
368           convert_x = uiuc_convert(token_value_convert2);
369           convert_y = uiuc_convert(token_value_convert3);
370           /* call 2D File Reader with file name (CDfadf) and 
371              conversion factors; function returns array of 
372              flap deflections (dfArray) and corresponding 
373              alpha (aArray) and delta CD (CDArray) values and 
374              max number of terms in alpha arrays (nAlphaArray) 
375              and deflection array (ndf) */
376           uiuc_2DdataFileReader(CDfadf,
377                                 CDfadf_aArray,
378                                 CDfadf_dfArray,
379                                 CDfadf_CDArray,
380                                 CDfadf_nAlphaArray,
381                                 CDfadf_ndf);
382           aeroDragParts -> storeCommands (*command_line);
383           break;
384         }
385       case CXo_flag:
386         {
387           if (check_float(linetoken3))
388             token3 >> token_value;
389           else
390             uiuc_warnings_errors(1, *command_line);
391           
392           CXo = token_value;
393           CXo_clean = CXo;
394           aeroDragParts -> storeCommands (*command_line);
395           break;
396         }
397       case CXK_flag:
398         {
399           if (check_float(linetoken3))
400             token3 >> token_value;
401           else
402             uiuc_warnings_errors(1, *command_line);
403           
404           CXK = token_value;
405           CXK_clean = CXK;
406           aeroDragParts -> storeCommands (*command_line);
407           break;
408         }
409       case CX_a_flag:
410         {
411           if (check_float(linetoken3))
412             token3 >> token_value;
413           else
414             uiuc_warnings_errors(1, *command_line);
415           
416           CX_a = token_value;
417           CX_a_clean = CX_a;
418           aeroDragParts -> storeCommands (*command_line);
419           break;
420         }
421       case CX_a2_flag:
422         {
423           if (check_float(linetoken3))
424             token3 >> token_value;
425           else
426             uiuc_warnings_errors(1, *command_line);
427           
428           CX_a2 = token_value;
429           CX_a2_clean = CX_a2;
430           aeroDragParts -> storeCommands (*command_line);
431           break;
432         }
433       case CX_a3_flag:
434         {
435           if (check_float(linetoken3))
436             token3 >> token_value;
437           else
438             uiuc_warnings_errors(1, *command_line);
439           
440           CX_a3 = token_value;
441           CX_a3_clean = CX_a3;
442           aeroDragParts -> storeCommands (*command_line);
443           break;
444         }
445       case CX_adot_flag:
446         {
447           if (check_float(linetoken3))
448             token3 >> token_value;
449           else
450             uiuc_warnings_errors(1, *command_line);
451           
452           CX_adot = token_value;
453           CX_adot_clean = CX_adot;
454           aeroDragParts -> storeCommands (*command_line);
455           break;
456         }
457       case CX_q_flag:
458         {
459           if (check_float(linetoken3))
460             token3 >> token_value;
461           else
462             uiuc_warnings_errors(1, *command_line);
463           
464           CX_q = token_value;
465           CX_q_clean = CX_q;
466           aeroDragParts -> storeCommands (*command_line);
467           break;
468         }
469       case CX_de_flag:
470         {
471           if (check_float(linetoken3))
472             token3 >> token_value;
473           else
474             uiuc_warnings_errors(1, *command_line);
475           
476           CX_de = token_value;
477           CX_de_clean = CX_de;
478           aeroDragParts -> storeCommands (*command_line);
479           break;
480         }
481       case CX_dr_flag:
482         {
483           if (check_float(linetoken3))
484             token3 >> token_value;
485           else
486             uiuc_warnings_errors(1, *command_line);
487           
488           CX_dr = token_value;
489           CX_dr_clean = CX_dr;
490           aeroDragParts -> storeCommands (*command_line);
491           break;
492         }
493       case CX_df_flag:
494         {
495           if (check_float(linetoken3))
496             token3 >> token_value;
497           else
498             uiuc_warnings_errors(1, *command_line);
499           
500           CX_df = token_value;
501           CX_df_clean = CX_df;
502           aeroDragParts -> storeCommands (*command_line);
503           break;
504         }
505       case CX_adf_flag:
506         {
507           if (check_float(linetoken3))
508             token3 >> token_value;
509           else
510             uiuc_warnings_errors(1, *command_line);
511           
512           CX_adf = token_value;
513           CX_adf_clean = CX_adf;
514           aeroDragParts -> storeCommands (*command_line);
515           break;
516         }
517       case CXfabetaf_flag:
518         {
519           int CXfabetaf_index, i;
520           string CXfabetaf_file;
521           double flap_value;
522           CXfabetaf_file = aircraft_directory + linetoken3;
523           token4 >> CXfabetaf_index;
524           if (CXfabetaf_index < 1 || CXfabetaf_index >= 30)
525             uiuc_warnings_errors(1, *command_line);
526           if (CXfabetaf_index > CXfabetaf_nf)
527             CXfabetaf_nf = CXfabetaf_index;
528           token5 >> flap_value;
529           token6 >> token_value_convert1;
530           token7 >> token_value_convert2;
531           token8 >> token_value_convert3;
532           token9 >> token_value_convert4;
533           token10 >> CXfabetaf_nice;
534           convert_z = uiuc_convert(token_value_convert1);
535           convert_x = uiuc_convert(token_value_convert2);
536           convert_y = uiuc_convert(token_value_convert3);
537           convert_f = uiuc_convert(token_value_convert4);
538           CXfabetaf_fArray[CXfabetaf_index] = flap_value * convert_f;
539           /* call 2D File Reader with file name (CXfabetaf_file) and 
540              conversion factors; function returns array of 
541              elevator deflections (deArray) and corresponding 
542              alpha (aArray) and delta CZ (CZArray) values and 
543              max number of terms in alpha arrays (nAlphaArray) 
544              and delfection array (nde) */
545           uiuc_2DdataFileReader(CXfabetaf_file,
546                                 datafile_xArray,
547                                 datafile_yArray,
548                                 datafile_zArray,
549                                 datafile_nxArray,
550                                 datafile_ny);
551           d_2_to_3(datafile_xArray, CXfabetaf_aArray, CXfabetaf_index);
552           d_1_to_2(datafile_yArray, CXfabetaf_betaArray, CXfabetaf_index);
553           d_2_to_3(datafile_zArray, CXfabetaf_CXArray, CXfabetaf_index);
554           i_1_to_2(datafile_nxArray, CXfabetaf_nAlphaArray, CXfabetaf_index);
555           CXfabetaf_nbeta[CXfabetaf_index] = datafile_ny;
556           if (CXfabetaf_first==true)
557             {
558               if (CXfabetaf_nice == 1)
559                 {
560                   CXfabetaf_na_nice = datafile_nxArray[1];
561                   CXfabetaf_nb_nice = datafile_ny;
562                   d_1_to_1(datafile_yArray, CXfabetaf_bArray_nice);
563                   for (i=1; i<=CXfabetaf_na_nice; i++)
564                     CXfabetaf_aArray_nice[i] = datafile_xArray[1][i];
565                 }
566               aeroDragParts -> storeCommands (*command_line);
567               CXfabetaf_first=false;
568             }
569           break;
570         }
571       case CXfadef_flag:
572         {
573           int CXfadef_index, i;
574           string CXfadef_file;
575           double flap_value;
576           CXfadef_file = aircraft_directory + linetoken3;
577           token4 >> CXfadef_index;
578           if (CXfadef_index < 0 || CXfadef_index >= 30)
579             uiuc_warnings_errors(1, *command_line);
580           if (CXfadef_index > CXfadef_nf)
581             CXfadef_nf = CXfadef_index;
582           token5 >> flap_value;
583           token6 >> token_value_convert1;
584           token7 >> token_value_convert2;
585           token8 >> token_value_convert3;
586           token9 >> token_value_convert4;
587           token10 >> CXfadef_nice;
588           convert_z = uiuc_convert(token_value_convert1);
589           convert_x = uiuc_convert(token_value_convert2);
590           convert_y = uiuc_convert(token_value_convert3);
591           convert_f = uiuc_convert(token_value_convert4);
592           CXfadef_fArray[CXfadef_index] = flap_value * convert_f;
593           /* call 2D File Reader with file name (CXfadef_file) and 
594              conversion factors; function returns array of 
595              elevator deflections (deArray) and corresponding 
596              alpha (aArray) and delta CZ (CZArray) values and 
597              max number of terms in alpha arrays (nAlphaArray) 
598              and delfection array (nde) */
599           uiuc_2DdataFileReader(CXfadef_file,
600                                 datafile_xArray,
601                                 datafile_yArray,
602                                 datafile_zArray,
603                                 datafile_nxArray,
604                                 datafile_ny);
605           d_2_to_3(datafile_xArray, CXfadef_aArray, CXfadef_index);
606           d_1_to_2(datafile_yArray, CXfadef_deArray, CXfadef_index);
607           d_2_to_3(datafile_zArray, CXfadef_CXArray, CXfadef_index);
608           i_1_to_2(datafile_nxArray, CXfadef_nAlphaArray, CXfadef_index);
609           CXfadef_nde[CXfadef_index] = datafile_ny;
610           if (CXfadef_first==true)
611             {
612               if (CXfadef_nice == 1)
613                 {
614                   CXfadef_na_nice = datafile_nxArray[1];
615                   CXfadef_nde_nice = datafile_ny;
616                   d_1_to_1(datafile_yArray, CXfadef_deArray_nice);
617                   for (i=1; i<=CXfadef_na_nice; i++)
618                     CXfadef_aArray_nice[i] = datafile_xArray[1][i];
619                 }
620               aeroDragParts -> storeCommands (*command_line);
621               CXfadef_first=false;
622             }
623           break;
624         }
625       case CXfaqf_flag:
626         {
627           int CXfaqf_index, i;
628           string CXfaqf_file;
629           double flap_value;
630           CXfaqf_file = aircraft_directory + linetoken3;
631           token4 >> CXfaqf_index;
632           if (CXfaqf_index < 0 || CXfaqf_index >= 30)
633             uiuc_warnings_errors(1, *command_line);
634           if (CXfaqf_index > CXfaqf_nf)
635             CXfaqf_nf = CXfaqf_index;
636           token5 >> flap_value;
637           token6 >> token_value_convert1;
638           token7 >> token_value_convert2;
639           token8 >> token_value_convert3;
640           token9 >> token_value_convert4;
641           token10 >> CXfaqf_nice;
642           convert_z = uiuc_convert(token_value_convert1);
643           convert_x = uiuc_convert(token_value_convert2);
644           convert_y = uiuc_convert(token_value_convert3);
645           convert_f = uiuc_convert(token_value_convert4);
646           CXfaqf_fArray[CXfaqf_index] = flap_value * convert_f;
647           /* call 2D File Reader with file name (CXfaqf_file) and 
648              conversion factors; function returns array of 
649              elevator deflections (deArray) and corresponding 
650              alpha (aArray) and delta CZ (CZArray) values and 
651              max number of terms in alpha arrays (nAlphaArray) 
652              and delfection array (nde) */
653           uiuc_2DdataFileReader(CXfaqf_file,
654                                 datafile_xArray,
655                                 datafile_yArray,
656                                 datafile_zArray,
657                                 datafile_nxArray,
658                                 datafile_ny);
659           d_2_to_3(datafile_xArray, CXfaqf_aArray, CXfaqf_index);
660           d_1_to_2(datafile_yArray, CXfaqf_qArray, CXfaqf_index);
661           d_2_to_3(datafile_zArray, CXfaqf_CXArray, CXfaqf_index);
662           i_1_to_2(datafile_nxArray, CXfaqf_nAlphaArray, CXfaqf_index);
663           CXfaqf_nq[CXfaqf_index] = datafile_ny;
664           if (CXfaqf_first==true)
665             {
666               if (CXfaqf_nice == 1)
667                 {
668                   CXfaqf_na_nice = datafile_nxArray[1];
669                   CXfaqf_nq_nice = datafile_ny;
670                   d_1_to_1(datafile_yArray, CXfaqf_qArray_nice);
671                   for (i=1; i<=CXfaqf_na_nice; i++)
672                     CXfaqf_aArray_nice[i] = datafile_xArray[1][i];
673                 }
674               aeroDragParts -> storeCommands (*command_line);
675               CXfaqf_first=false;
676             }
677           break;
678         }
679       default:
680         {
681           if (ignore_unknown_keywords) {
682             // do nothing
683           } else {
684             // print error message
685             uiuc_warnings_errors(2, *command_line);
686           }
687           break;
688         }
689       };
690 }