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