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