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