]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_menu_CL.cpp
Provide a better(?) solution to the windows GDI problem
[flightgear.git] / src / FDM / UIUCModel / uiuc_menu_CL.cpp
1 /**********************************************************************
2                                                                        
3  FILENAME:     uiuc_menu_CL.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_CL.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_CL( 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 CZfabetaf_first = true;
116     static bool CZfadef_first = true;
117     static bool CZfaqf_first = true;
118
119     switch(CL_map[linetoken2])
120       {
121       case CLo_flag:
122         {
123           if (check_float(linetoken3))
124             token3 >> token_value;
125           else
126             uiuc_warnings_errors(1, *command_line);
127           
128           CLo = token_value;
129           CLo_clean = CLo;
130           aeroLiftParts -> storeCommands (*command_line);
131           break;
132         }
133       case CL_a_flag:
134         {
135           if (check_float(linetoken3))
136             token3 >> token_value;
137           else
138             uiuc_warnings_errors(1, *command_line);
139           
140           CL_a = token_value;
141           CL_a_clean = CL_a;
142           aeroLiftParts -> storeCommands (*command_line);
143           break;
144         }
145       case CL_adot_flag:
146         {
147           if (check_float(linetoken3))
148             token3 >> token_value;
149           else
150             uiuc_warnings_errors(1, *command_line);
151           
152           CL_adot = token_value;
153           CL_adot_clean = CL_adot;
154           aeroLiftParts -> storeCommands (*command_line);
155           break;
156         }
157       case CL_q_flag:
158         {
159           if (check_float(linetoken3))
160             token3 >> token_value;
161           else
162             uiuc_warnings_errors(1, *command_line);
163           
164           CL_q = token_value;
165           CL_q_clean = CL_q;
166           aeroLiftParts -> storeCommands (*command_line);
167           break;
168         }
169       case CL_ih_flag:
170         {
171           if (check_float(linetoken3))
172             token3 >> token_value;
173           else
174             uiuc_warnings_errors(1, *command_line);
175           
176           CL_ih = token_value;
177           aeroLiftParts -> storeCommands (*command_line);
178           break;
179         }
180       case CL_de_flag:
181         {
182           if (check_float(linetoken3))
183             token3 >> token_value;
184           else
185             uiuc_warnings_errors(1, *command_line);
186           
187           CL_de = token_value;
188           CL_de_clean = CL_de;
189           aeroLiftParts -> storeCommands (*command_line);
190           break;
191         }
192       case CL_df_flag:
193         {
194           if (check_float(linetoken3))
195             token3 >> token_value;
196           else
197             uiuc_warnings_errors(1, *command_line);
198           
199           CL_df = token_value;
200           aeroLiftParts -> storeCommands (*command_line);
201           break;
202         }
203       case CL_ds_flag:
204         {
205           if (check_float(linetoken3))
206             token3 >> token_value;
207           else
208             uiuc_warnings_errors(1, *command_line);
209           
210           CL_ds = token_value;
211           aeroLiftParts -> storeCommands (*command_line);
212           break;
213         }
214       case CL_dg_flag:
215         {
216           if (check_float(linetoken3))
217             token3 >> token_value;
218           else
219             uiuc_warnings_errors(1, *command_line);
220           
221           CL_dg = token_value;
222           aeroLiftParts -> storeCommands (*command_line);
223           break;
224         }
225       case CLfa_flag:
226         {
227           CLfa = aircraft_directory + linetoken3;
228           token4 >> token_value_convert1;
229           token5 >> token_value_convert2;
230           convert_y = uiuc_convert(token_value_convert1);
231           convert_x = uiuc_convert(token_value_convert2);
232           /* call 1D File Reader with file name (CLfa) and conversion 
233              factors; function returns array of alphas (aArray) and 
234              corresponding CL values (CLArray) and max number of 
235              terms in arrays (nAlpha) */
236           uiuc_1DdataFileReader(CLfa,
237                                 CLfa_aArray,
238                                 CLfa_CLArray,
239                                 CLfa_nAlpha);
240           aeroLiftParts -> storeCommands (*command_line);
241           break;
242         }
243       case CLfade_flag:
244         {
245           CLfade = aircraft_directory + linetoken3;
246           token4 >> token_value_convert1;
247           token5 >> token_value_convert2;
248           token6 >> token_value_convert3;
249           convert_z = uiuc_convert(token_value_convert1);
250           convert_x = uiuc_convert(token_value_convert2);
251           convert_y = uiuc_convert(token_value_convert3);
252           /* call 2D File Reader with file name (CLfade) and 
253              conversion factors; function returns array of 
254              elevator deflections (deArray) and corresponding 
255              alpha (aArray) and delta CL (CLArray) values and 
256              max number of terms in alpha arrays (nAlphaArray) 
257              and deflection array (nde) */
258           uiuc_2DdataFileReader(CLfade,
259                                 CLfade_aArray,
260                                 CLfade_deArray,
261                                 CLfade_CLArray,
262                                 CLfade_nAlphaArray,
263                                 CLfade_nde);
264           aeroLiftParts -> storeCommands (*command_line);
265           break;
266         }
267       case CLfdf_flag:
268         {
269           CLfdf = aircraft_directory + linetoken3;
270           token4 >> token_value_convert1;
271           token5 >> token_value_convert2;
272           convert_y = uiuc_convert(token_value_convert1);
273           convert_x = uiuc_convert(token_value_convert2);
274           /* call 1D File Reader with file name (CLfdf) and conversion 
275              factors; function returns array of dfs (dfArray) and 
276              corresponding CL values (CLArray) and max number of 
277              terms in arrays (ndf) */
278           uiuc_1DdataFileReader(CLfdf,
279                                 CLfdf_dfArray,
280                                 CLfdf_CLArray,
281                                 CLfdf_ndf);
282           aeroLiftParts -> storeCommands (*command_line);
283           
284           // additional variables to streamline flap routine in aerodeflections
285           ndf = CLfdf_ndf;
286           int temp_counter = 1;
287           while (temp_counter <= ndf)
288             {
289               dfArray[temp_counter] = CLfdf_dfArray[temp_counter];
290               TimeArray[temp_counter] = dfTimefdf_TimeArray[temp_counter];
291               temp_counter++;
292             }
293           break;
294         }
295       case CLfadf_flag:
296         {
297           CLfadf = aircraft_directory + linetoken3;
298           token4 >> token_value_convert1;
299           token5 >> token_value_convert2;
300           token6 >> token_value_convert3;
301           convert_z = uiuc_convert(token_value_convert1);
302           convert_x = uiuc_convert(token_value_convert2);
303           convert_y = uiuc_convert(token_value_convert3);
304           /* call 2D File Reader with file name (CLfadf) and 
305              conversion factors; function returns array of 
306              flap deflections (dfArray) and corresponding 
307              alpha (aArray) and delta CL (CLArray) values and 
308              max number of terms in alpha arrays (nAlphaArray) 
309              and deflection array (ndf) */
310           uiuc_2DdataFileReader(CLfadf,
311                                 CLfadf_aArray,
312                                 CLfadf_dfArray,
313                                 CLfadf_CLArray,
314                                 CLfadf_nAlphaArray,
315                                 CLfadf_ndf);
316           aeroLiftParts -> storeCommands (*command_line);
317           break;
318         }
319       case CZo_flag:
320         {
321           if (check_float(linetoken3))
322             token3 >> token_value;
323           else
324             uiuc_warnings_errors(1, *command_line);
325           
326           CZo = token_value;
327           CZo_clean = CZo;
328           aeroLiftParts -> storeCommands (*command_line);
329           break;
330         }
331       case CZ_a_flag:
332         {
333           if (check_float(linetoken3))
334             token3 >> token_value;
335           else
336             uiuc_warnings_errors(1, *command_line);
337           
338           CZ_a = token_value;
339           CZ_a_clean = CZ_a;
340           aeroLiftParts -> storeCommands (*command_line);
341           break;
342         }
343       case CZ_a2_flag:
344         {
345           if (check_float(linetoken3))
346             token3 >> token_value;
347           else
348             uiuc_warnings_errors(1, *command_line);
349           
350           CZ_a2 = token_value;
351           CZ_a2_clean = CZ_a2;
352           aeroLiftParts -> storeCommands (*command_line);
353           break;
354         }
355       case CZ_a3_flag:
356         {
357           if (check_float(linetoken3))
358             token3 >> token_value;
359           else
360             uiuc_warnings_errors(1, *command_line);
361           
362           CZ_a3 = token_value;
363           CZ_a3_clean = CZ_a3;
364           aeroLiftParts -> storeCommands (*command_line);
365           break;
366         }
367       case CZ_adot_flag:
368         {
369           if (check_float(linetoken3))
370             token3 >> token_value;
371           else
372             uiuc_warnings_errors(1, *command_line);
373           
374           CZ_adot = token_value;
375           CZ_adot_clean = CZ_adot;
376           aeroLiftParts -> storeCommands (*command_line);
377           break;
378         }
379       case CZ_q_flag:
380         {
381           if (check_float(linetoken3))
382             token3 >> token_value;
383           else
384             uiuc_warnings_errors(1, *command_line);
385           
386           CZ_q = token_value;
387           CZ_q_clean = CZ_q;
388           aeroLiftParts -> storeCommands (*command_line);
389           break;
390         }
391       case CZ_de_flag:
392         {
393           if (check_float(linetoken3))
394             token3 >> token_value;
395           else
396             uiuc_warnings_errors(1, *command_line);
397           
398           CZ_de = token_value;
399           CZ_de_clean = CZ_de;
400           aeroLiftParts -> storeCommands (*command_line);
401           break;
402         }
403       case CZ_deb2_flag:
404         {
405           if (check_float(linetoken3))
406             token3 >> token_value;
407           else
408             uiuc_warnings_errors(1, *command_line);
409           
410           CZ_deb2 = token_value;
411           CZ_deb2_clean = CZ_deb2;
412           aeroLiftParts -> storeCommands (*command_line);
413           break;
414         }
415       case CZ_df_flag:
416         {
417           if (check_float(linetoken3))
418             token3 >> token_value;
419           else
420             uiuc_warnings_errors(1, *command_line);
421           
422           CZ_df = token_value;
423           CZ_df_clean = CZ_df;
424           aeroLiftParts -> storeCommands (*command_line);
425           break;
426         }
427       case CZ_adf_flag:
428         {
429           if (check_float(linetoken3))
430             token3 >> token_value;
431           else
432             uiuc_warnings_errors(1, *command_line);
433           
434           CZ_adf = token_value;
435           CZ_adf_clean = CZ_adf;
436           aeroLiftParts -> storeCommands (*command_line);
437           break;
438         }
439       case CZfa_flag:
440         {
441           CZfa = aircraft_directory + linetoken3;
442           token4 >> token_value_convert1;
443           token5 >> token_value_convert2;
444           convert_y = uiuc_convert(token_value_convert1);
445           convert_x = uiuc_convert(token_value_convert2);
446           /* call 1D File Reader with file name (CZfa) and conversion 
447              factors; function returns array of alphas (aArray) and 
448              corresponding CZ values (CZArray) and max number of 
449              terms in arrays (nAlpha) */
450           uiuc_1DdataFileReader(CZfa,
451                                 CZfa_aArray,
452                                 CZfa_CZArray,
453                                 CZfa_nAlpha);
454           aeroLiftParts -> storeCommands (*command_line);
455           break;
456         }
457       case CZfabetaf_flag:
458         {
459           int CZfabetaf_index, i;
460           string CZfabetaf_file;
461           double flap_value;
462           CZfabetaf_file = aircraft_directory + linetoken3;
463           token4 >> CZfabetaf_index;
464           if (CZfabetaf_index < 0 || CZfabetaf_index >= 30)
465             uiuc_warnings_errors(1, *command_line);
466           if (CZfabetaf_index > CZfabetaf_nf)
467             CZfabetaf_nf = CZfabetaf_index;
468           token5 >> flap_value;
469           token6 >> token_value_convert1;
470           token7 >> token_value_convert2;
471           token8 >> token_value_convert3;
472           token9 >> token_value_convert4;
473           token10 >> CZfabetaf_nice;
474           convert_z = uiuc_convert(token_value_convert1);
475           convert_x = uiuc_convert(token_value_convert2);
476           convert_y = uiuc_convert(token_value_convert3);
477           convert_f = uiuc_convert(token_value_convert4);
478           CZfabetaf_fArray[CZfabetaf_index] = flap_value * convert_f;
479           /* call 2D File Reader with file name (CZfabetaf_file) and 
480              conversion factors; function returns array of 
481              beta (betaArray) and corresponding 
482              alpha (aArray) and CZ (CZArray) values and 
483              max number of terms in alpha arrays (nAlphaArray) 
484              and beta array (nbeta) */
485           uiuc_2DdataFileReader(CZfabetaf_file,
486                                 datafile_xArray,
487                                 datafile_yArray,
488                                 datafile_zArray,
489                                 datafile_nxArray,
490                                 datafile_ny);
491           d_2_to_3(datafile_xArray, CZfabetaf_aArray, CZfabetaf_index);
492           d_1_to_2(datafile_yArray, CZfabetaf_betaArray, CZfabetaf_index);
493           d_2_to_3(datafile_zArray, CZfabetaf_CZArray, CZfabetaf_index);
494           i_1_to_2(datafile_nxArray, CZfabetaf_nAlphaArray, CZfabetaf_index);
495           CZfabetaf_nbeta[CZfabetaf_index] = datafile_ny;
496           if (CZfabetaf_first==true)
497             {
498               if (CZfabetaf_nice == 1)
499                 {
500                   CZfabetaf_na_nice = datafile_nxArray[1];
501                   CZfabetaf_nb_nice = datafile_ny;
502                   d_1_to_1(datafile_yArray, CZfabetaf_bArray_nice);
503                   for (i=1; i<=CZfabetaf_na_nice; i++)
504                     CZfabetaf_aArray_nice[i] = datafile_xArray[1][i];
505                 }
506               aeroLiftParts -> storeCommands (*command_line);
507               CZfabetaf_first=false;
508             }
509           break;
510         }
511       case CZfadef_flag:
512         {
513           int CZfadef_index, i;
514           string CZfadef_file;
515           double flap_value;
516           CZfadef_file = aircraft_directory + linetoken3;
517           token4 >> CZfadef_index;
518           if (CZfadef_index < 0 || CZfadef_index >= 30)
519             uiuc_warnings_errors(1, *command_line);
520           if (CZfadef_index > CZfadef_nf)
521             CZfadef_nf = CZfadef_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 >> CZfadef_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           CZfadef_fArray[CZfadef_index] = flap_value * convert_f;
533           /* call 2D File Reader with file name (CZfadef_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(CZfadef_file,
540                                 datafile_xArray,
541                                 datafile_yArray,
542                                 datafile_zArray,
543                                 datafile_nxArray,
544                                 datafile_ny);
545           d_2_to_3(datafile_xArray, CZfadef_aArray, CZfadef_index);
546           d_1_to_2(datafile_yArray, CZfadef_deArray, CZfadef_index);
547           d_2_to_3(datafile_zArray, CZfadef_CZArray, CZfadef_index);
548           i_1_to_2(datafile_nxArray, CZfadef_nAlphaArray, CZfadef_index);
549           CZfadef_nde[CZfadef_index] = datafile_ny;
550           if (CZfadef_first==true)
551             {
552               if (CZfadef_nice == 1)
553                 {
554                   CZfadef_na_nice = datafile_nxArray[1];
555                   CZfadef_nde_nice = datafile_ny;
556                   d_1_to_1(datafile_yArray, CZfadef_deArray_nice);
557                   for (i=1; i<=CZfadef_na_nice; i++)
558                     CZfadef_aArray_nice[i] = datafile_xArray[1][i];
559                 }
560               aeroLiftParts -> storeCommands (*command_line);
561               CZfadef_first=false;
562             }
563           break;
564         }
565       case CZfaqf_flag:
566         {
567           int CZfaqf_index, i;
568           string CZfaqf_file;
569           double flap_value;
570           CZfaqf_file = aircraft_directory + linetoken3;
571           token4 >> CZfaqf_index;
572           if (CZfaqf_index < 0 || CZfaqf_index >= 30)
573             uiuc_warnings_errors(1, *command_line);
574           if (CZfaqf_index > CZfaqf_nf)
575             CZfaqf_nf = CZfaqf_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 >> CZfaqf_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           CZfaqf_fArray[CZfaqf_index] = flap_value * convert_f;
587           /* call 2D File Reader with file name (CZfaqf_file) and 
588              conversion factors; function returns array of 
589              pitch rate (qArray) and corresponding 
590              alpha (aArray) and delta CZ (CZArray) values and 
591              max number of terms in alpha arrays (nAlphaArray) 
592              and pitch rate array (nq) */
593           uiuc_2DdataFileReader(CZfaqf_file,
594                                 datafile_xArray,
595                                 datafile_yArray,
596                                 datafile_zArray,
597                                 datafile_nxArray,
598                                 datafile_ny);
599           d_2_to_3(datafile_xArray, CZfaqf_aArray, CZfaqf_index);
600           d_1_to_2(datafile_yArray, CZfaqf_qArray, CZfaqf_index);
601           d_2_to_3(datafile_zArray, CZfaqf_CZArray, CZfaqf_index);
602           i_1_to_2(datafile_nxArray, CZfaqf_nAlphaArray, CZfaqf_index);
603           CZfaqf_nq[CZfaqf_index] = datafile_ny;
604           if (CZfaqf_first==true)
605             {
606               if (CZfaqf_nice == 1)
607                 {
608                   CZfaqf_na_nice = datafile_nxArray[1];
609                   CZfaqf_nq_nice = datafile_ny;
610                   d_1_to_1(datafile_yArray, CZfaqf_qArray_nice);
611                   for (i=1; i<=CZfaqf_na_nice; i++)
612                     CZfaqf_aArray_nice[i] = datafile_xArray[1][i];
613                 }
614               aeroLiftParts -> storeCommands (*command_line);
615               CZfaqf_first=false;
616             }
617           break;
618         }
619       default:
620         {
621           if (ignore_unknown_keywords) {
622             // do nothing
623           } else {
624             // print error message
625             uiuc_warnings_errors(2, *command_line);
626           }
627           break;
628         }
629       };
630 }