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