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