]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_menu_Cm.cpp
Fix many clang errors in UIUC code
[flightgear.git] / src / FDM / UIUCModel / uiuc_menu_Cm.cpp
1 /**********************************************************************
2                                                                        
3  FILENAME:     uiuc_menu_Cm.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_Cm.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_Cm( 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 Cmfabetaf_first = true;
113     static bool Cmfadef_first = true;
114     static bool Cmfaqf_first = true;
115
116     switch(Cm_map[linetoken2])
117       {
118       case Cmo_flag:
119         {
120           if (check_float(linetoken3))
121             token3 >> token_value;
122           else
123             uiuc_warnings_errors(1, *command_line);
124           
125           Cmo = token_value;
126           Cmo_clean = Cmo;
127           aeroPitchParts -> storeCommands (*command_line);
128           break;
129         }
130       case Cm_a_flag:
131         {
132           if (check_float(linetoken3))
133             token3 >> token_value;
134           else
135             uiuc_warnings_errors(1, *command_line);
136           
137           Cm_a = token_value;
138           Cm_a_clean = Cm_a;
139           aeroPitchParts -> storeCommands (*command_line);
140           break;
141         }
142       case Cm_a2_flag:
143         {
144           if (check_float(linetoken3))
145             token3 >> token_value;
146           else
147             uiuc_warnings_errors(1, *command_line);
148           
149           Cm_a2 = token_value;
150           Cm_a2_clean = Cm_a2;
151           aeroPitchParts -> storeCommands (*command_line);
152           break;
153         }
154       case Cm_adot_flag:
155         {
156           if (check_float(linetoken3))
157             token3 >> token_value;
158           else
159             uiuc_warnings_errors(1, *command_line);
160           
161           Cm_adot = token_value;
162           Cm_adot_clean = Cm_adot;
163           aeroPitchParts -> storeCommands (*command_line);
164           break;
165         }
166       case Cm_q_flag:
167         {
168           if (check_float(linetoken3))
169             token3 >> token_value;
170           else
171             uiuc_warnings_errors(1, *command_line);
172           
173           Cm_q = token_value;
174           Cm_q_clean = Cm_q;
175           aeroPitchParts -> storeCommands (*command_line);
176           break;
177         }
178       case Cm_ih_flag:
179         {
180           if (check_float(linetoken3))
181             token3 >> token_value;
182           else
183             uiuc_warnings_errors(1, *command_line);
184           
185           Cm_ih = token_value;
186           aeroPitchParts -> storeCommands (*command_line);
187           break;
188         }
189       case Cm_de_flag:
190         {
191           if (check_float(linetoken3))
192             token3 >> token_value;
193           else
194             uiuc_warnings_errors(1, *command_line);
195           
196           Cm_de = token_value;
197           Cm_de_clean = Cm_de;
198           aeroPitchParts -> storeCommands (*command_line);
199           break;
200         }
201       case Cm_b2_flag:
202         {
203           if (check_float(linetoken3))
204             token3 >> token_value;
205           else
206             uiuc_warnings_errors(1, *command_line);
207           
208           Cm_b2 = token_value;
209           Cm_b2_clean = Cm_b2;
210           aeroPitchParts -> storeCommands (*command_line);
211           break;
212         }
213       case Cm_r_flag:
214         {
215           if (check_float(linetoken3))
216             token3 >> token_value;
217           else
218             uiuc_warnings_errors(1, *command_line);
219           
220           Cm_r = token_value;
221           Cm_r_clean = Cm_r;
222           aeroPitchParts -> storeCommands (*command_line);
223           break;
224         }
225       case Cm_df_flag:
226         {
227           if (check_float(linetoken3))
228             token3 >> token_value;
229           else
230             uiuc_warnings_errors(1, *command_line);
231           
232           Cm_df = token_value;
233           Cm_df_clean = Cm_df;
234           aeroPitchParts -> storeCommands (*command_line);
235           break;
236         }
237       case Cm_ds_flag:
238         {
239           if (check_float(linetoken3))
240             token3 >> token_value;
241           else
242             uiuc_warnings_errors(1, *command_line);
243           
244           Cm_ds = token_value;
245           aeroPitchParts -> storeCommands (*command_line);
246           break;
247         }
248       case Cm_dg_flag:
249         {
250           if (check_float(linetoken3))
251             token3 >> token_value;
252           else
253             uiuc_warnings_errors(1, *command_line);
254           
255           Cm_dg = token_value;
256           aeroPitchParts -> storeCommands (*command_line);
257           break;
258         }
259       case Cmfa_flag:
260         {
261           Cmfa = aircraft_directory + linetoken3;
262           token4 >> token_value_convert1;
263           token5 >> token_value_convert2;
264           convert_y = uiuc_convert(token_value_convert1);
265           convert_x = uiuc_convert(token_value_convert2);
266           /* call 1D File Reader with file name (Cmfa) and conversion 
267              factors; function returns array of alphas (aArray) and 
268              corresponding Cm values (CmArray) and max number of 
269              terms in arrays (nAlpha) */
270           uiuc_1DdataFileReader(Cmfa,
271                                 Cmfa_aArray,
272                                 Cmfa_CmArray,
273                                 Cmfa_nAlpha);
274           aeroPitchParts -> storeCommands (*command_line);
275           break;
276         }
277       case Cmfade_flag:
278         {
279           Cmfade = aircraft_directory + linetoken3;
280           token4 >> token_value_convert1;
281           token5 >> token_value_convert2;
282           token6 >> token_value_convert3;
283           convert_z = uiuc_convert(token_value_convert1);
284           convert_x = uiuc_convert(token_value_convert2);
285           convert_y = uiuc_convert(token_value_convert3);
286           /* call 2D File Reader with file name (Cmfade) and 
287              conversion factors; function returns array of 
288              elevator deflections (deArray) and corresponding 
289              alpha (aArray) and delta Cm (CmArray) values and 
290              max number of terms in alpha arrays (nAlphaArray) 
291              and deflection array (nde) */
292           uiuc_2DdataFileReader(Cmfade,
293                                 Cmfade_aArray,
294                                 Cmfade_deArray,
295                                 Cmfade_CmArray,
296                                 Cmfade_nAlphaArray,
297                                 Cmfade_nde);
298           aeroPitchParts -> storeCommands (*command_line);
299           break;
300         }
301       case Cmfdf_flag:
302         {
303           Cmfdf = aircraft_directory + linetoken3;
304           token4 >> token_value_convert1;
305           token5 >> token_value_convert2;
306           convert_y = uiuc_convert(token_value_convert1);
307           convert_x = uiuc_convert(token_value_convert2);
308           /* call 1D File Reader with file name (Cmfdf) and conversion 
309              factors; function returns array of dfs (dfArray) and 
310              corresponding Cm values (CmArray) and max number of 
311              terms in arrays (ndf) */
312           uiuc_1DdataFileReader(Cmfdf,
313                                 Cmfdf_dfArray,
314                                 Cmfdf_CmArray,
315                                 Cmfdf_ndf);
316           aeroPitchParts -> storeCommands (*command_line);
317           break;
318         }
319       case Cmfadf_flag:
320         {
321           Cmfadf = aircraft_directory + linetoken3;
322           token4 >> token_value_convert1;
323           token5 >> token_value_convert2;
324           token6 >> token_value_convert3;
325           convert_z = uiuc_convert(token_value_convert1);
326           convert_x = uiuc_convert(token_value_convert2);
327           convert_y = uiuc_convert(token_value_convert3);
328           /* call 2D File Reader with file name (Cmfadf) and 
329              conversion factors; function returns array of 
330              flap deflections (dfArray) and corresponding 
331              alpha (aArray) and delta Cm (CmArray) values and 
332              max number of terms in alpha arrays (nAlphaArray) 
333              and deflection array (ndf) */
334           uiuc_2DdataFileReader(Cmfadf,
335                                 Cmfadf_aArray,
336                                 Cmfadf_dfArray,
337                                 Cmfadf_CmArray,
338                                 Cmfadf_nAlphaArray,
339                                 Cmfadf_ndf);
340           aeroPitchParts -> storeCommands (*command_line);
341           break;
342         }
343       case Cmfabetaf_flag:
344         {
345           int Cmfabetaf_index, i;
346           string Cmfabetaf_file;
347           double flap_value;
348           Cmfabetaf_file = aircraft_directory + linetoken3;
349           token4 >> Cmfabetaf_index;
350           if (Cmfabetaf_index < 0 || Cmfabetaf_index >= 30)
351             uiuc_warnings_errors(1, *command_line);
352           if (Cmfabetaf_index > Cmfabetaf_nf)
353             Cmfabetaf_nf = Cmfabetaf_index;
354           token5 >> flap_value;
355           token6 >> token_value_convert1;
356           token7 >> token_value_convert2;
357           token8 >> token_value_convert3;
358           token9 >> token_value_convert4;
359           token10 >> Cmfabetaf_nice;
360           convert_z = uiuc_convert(token_value_convert1);
361           convert_x = uiuc_convert(token_value_convert2);
362           convert_y = uiuc_convert(token_value_convert3);
363           convert_f = uiuc_convert(token_value_convert4);
364           Cmfabetaf_fArray[Cmfabetaf_index] = flap_value * convert_f;
365           /* call 2D File Reader with file name (Cmfabetaf_file) and 
366              conversion factors; function returns array of 
367              elevator deflections (deArray) and corresponding 
368              alpha (aArray) and delta CZ (CZArray) values and 
369              max number of terms in alpha arrays (nAlphaArray) 
370              and delfection array (nde) */
371           uiuc_2DdataFileReader(Cmfabetaf_file,
372                                 datafile_xArray,
373                                 datafile_yArray,
374                                 datafile_zArray,
375                                 datafile_nxArray,
376                                 datafile_ny);
377           d_2_to_3(datafile_xArray, Cmfabetaf_aArray, Cmfabetaf_index);
378           d_1_to_2(datafile_yArray, Cmfabetaf_betaArray, Cmfabetaf_index);
379           d_2_to_3(datafile_zArray, Cmfabetaf_CmArray, Cmfabetaf_index);
380           i_1_to_2(datafile_nxArray, Cmfabetaf_nAlphaArray, Cmfabetaf_index);
381           Cmfabetaf_nbeta[Cmfabetaf_index] = datafile_ny;
382           if (Cmfabetaf_first==true)
383             {
384               if (Cmfabetaf_nice == 1)
385                 {
386                   Cmfabetaf_na_nice = datafile_nxArray[1];
387                   Cmfabetaf_nb_nice = datafile_ny;
388                   d_1_to_1(datafile_yArray, Cmfabetaf_bArray_nice);
389                   for (i=1; i<=Cmfabetaf_na_nice; i++)
390                     Cmfabetaf_aArray_nice[i] = datafile_xArray[1][i];
391                 }
392               aeroPitchParts -> storeCommands (*command_line);
393               Cmfabetaf_first=false;
394             }
395           break;
396         }
397       case Cmfadef_flag:
398         {
399           int Cmfadef_index, i;
400           string Cmfadef_file;
401           double flap_value;
402           Cmfadef_file = aircraft_directory + linetoken3;
403           token4 >> Cmfadef_index;
404           if (Cmfadef_index < 0 || Cmfadef_index >= 30)
405             uiuc_warnings_errors(1, *command_line);
406           if (Cmfadef_index > Cmfadef_nf)
407             Cmfadef_nf = Cmfadef_index;
408           token5 >> flap_value;
409           token6 >> token_value_convert1;
410           token7 >> token_value_convert2;
411           token8 >> token_value_convert3;
412           token9 >> token_value_convert4;
413           token10 >> Cmfadef_nice;
414           convert_z = uiuc_convert(token_value_convert1);
415           convert_x = uiuc_convert(token_value_convert2);
416           convert_y = uiuc_convert(token_value_convert3);
417           convert_f = uiuc_convert(token_value_convert4);
418           Cmfadef_fArray[Cmfadef_index] = flap_value * convert_f;
419           /* call 2D File Reader with file name (Cmfadef_file) and 
420              conversion factors; function returns array of 
421              elevator deflections (deArray) and corresponding 
422              alpha (aArray) and delta CZ (CZArray) values and 
423              max number of terms in alpha arrays (nAlphaArray) 
424              and delfection array (nde) */
425           uiuc_2DdataFileReader(Cmfadef_file,
426                                 datafile_xArray,
427                                 datafile_yArray,
428                                 datafile_zArray,
429                                 datafile_nxArray,
430                                 datafile_ny);
431           d_2_to_3(datafile_xArray, Cmfadef_aArray, Cmfadef_index);
432           d_1_to_2(datafile_yArray, Cmfadef_deArray, Cmfadef_index);
433           d_2_to_3(datafile_zArray, Cmfadef_CmArray, Cmfadef_index);
434           i_1_to_2(datafile_nxArray, Cmfadef_nAlphaArray, Cmfadef_index);
435           Cmfadef_nde[Cmfadef_index] = datafile_ny;
436           if (Cmfadef_first==true)
437             {
438               if (Cmfadef_nice == 1)
439                 {
440                   Cmfadef_na_nice = datafile_nxArray[1];
441                   Cmfadef_nde_nice = datafile_ny;
442                   d_1_to_1(datafile_yArray, Cmfadef_deArray_nice);
443                   for (i=1; i<=Cmfadef_na_nice; i++)
444                     Cmfadef_aArray_nice[i] = datafile_xArray[1][i];
445                 }
446               aeroPitchParts -> storeCommands (*command_line);
447               Cmfadef_first=false;
448             }
449           break;
450         }
451       case Cmfaqf_flag:
452         {
453           int Cmfaqf_index, i;
454           string Cmfaqf_file;
455           double flap_value;
456           Cmfaqf_file = aircraft_directory + linetoken3;
457           token4 >> Cmfaqf_index;
458           if (Cmfaqf_index < 0 || Cmfaqf_index >= 30)
459             uiuc_warnings_errors(1, *command_line);
460           if (Cmfaqf_index > Cmfaqf_nf)
461             Cmfaqf_nf = Cmfaqf_index;
462           token5 >> flap_value;
463           token6 >> token_value_convert1;
464           token7 >> token_value_convert2;
465           token8 >> token_value_convert3;
466           token9 >> token_value_convert4;
467           token10 >> Cmfaqf_nice;
468           convert_z = uiuc_convert(token_value_convert1);
469           convert_x = uiuc_convert(token_value_convert2);
470           convert_y = uiuc_convert(token_value_convert3);
471           convert_f = uiuc_convert(token_value_convert4);
472           Cmfaqf_fArray[Cmfaqf_index] = flap_value * convert_f;
473           /* call 2D File Reader with file name (Cmfaqf_file) and 
474              conversion factors; function returns array of 
475              elevator deflections (deArray) and corresponding 
476              alpha (aArray) and delta CZ (CZArray) values and 
477              max number of terms in alpha arrays (nAlphaArray) 
478              and delfection array (nde) */
479           uiuc_2DdataFileReader(Cmfaqf_file,
480                                 datafile_xArray,
481                                 datafile_yArray,
482                                 datafile_zArray,
483                                 datafile_nxArray,
484                                 datafile_ny);
485           d_2_to_3(datafile_xArray, Cmfaqf_aArray, Cmfaqf_index);
486           d_1_to_2(datafile_yArray, Cmfaqf_qArray, Cmfaqf_index);
487           d_2_to_3(datafile_zArray, Cmfaqf_CmArray, Cmfaqf_index);
488           i_1_to_2(datafile_nxArray, Cmfaqf_nAlphaArray, Cmfaqf_index);
489           Cmfaqf_nq[Cmfaqf_index] = datafile_ny;
490           if (Cmfaqf_first==true)
491             {
492               if (Cmfaqf_nice == 1)
493                 {
494                   Cmfaqf_na_nice = datafile_nxArray[1];
495                   Cmfaqf_nq_nice = datafile_ny;
496                   d_1_to_1(datafile_yArray, Cmfaqf_qArray_nice);
497                   for (i=1; i<=Cmfaqf_na_nice; i++)
498                     Cmfaqf_aArray_nice[i] = datafile_xArray[1][i];
499                 }
500               aeroPitchParts -> storeCommands (*command_line);
501               Cmfaqf_first=false;
502             }
503           break;
504         }
505       default:
506         {
507           if (ignore_unknown_keywords) {
508             // do nothing
509           } else {
510             // print error message
511             uiuc_warnings_errors(2, *command_line);
512           }
513           break;
514         }
515       };
516 }