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