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