1 /**********************************************************************
3 FILENAME: uiuc_menu_Cm.cpp
5 ----------------------------------------------------------------------
7 DESCRIPTION: reads input data for specified aircraft and creates
8 approporiate data storage space
10 ----------------------------------------------------------------------
14 ----------------------------------------------------------------------
16 REFERENCES: based on "menu reader" format of Michael Selig
18 ----------------------------------------------------------------------
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
25 ----------------------------------------------------------------------
27 AUTHOR(S): Robert Deters <rdeters@uiuc.edu>
28 Michael Selig <m-selig@uiuc.edu>
30 ----------------------------------------------------------------------
34 ----------------------------------------------------------------------
38 ----------------------------------------------------------------------
42 ----------------------------------------------------------------------
44 CALLED BY: uiuc_menu()
46 ----------------------------------------------------------------------
48 CALLS TO: check_float() if needed
54 ----------------------------------------------------------------------
56 COPYRIGHT: (C) 2003 by Michael Selig
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.
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.
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.
71 **********************************************************************/
73 #include <simgear/compiler.h>
75 #if defined( __MWERKS__ )
76 // -dw- optimizer chokes (big-time) trying to optimize humongous
77 // loop/switch statements
78 #pragma optimization_level 0
85 #include "uiuc_menu_Cm.h"
95 void parse_Cm( 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 ) {
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];
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());
117 static bool Cmfabetaf_first = true;
118 static bool Cmfadef_first = true;
119 static bool Cmfaqf_first = true;
121 switch(Cm_map[linetoken2])
125 if (check_float(linetoken3))
126 token3 >> token_value;
128 uiuc_warnings_errors(1, *command_line);
132 aeroPitchParts -> storeCommands (*command_line);
137 if (check_float(linetoken3))
138 token3 >> token_value;
140 uiuc_warnings_errors(1, *command_line);
144 aeroPitchParts -> storeCommands (*command_line);
149 if (check_float(linetoken3))
150 token3 >> token_value;
152 uiuc_warnings_errors(1, *command_line);
156 aeroPitchParts -> storeCommands (*command_line);
161 if (check_float(linetoken3))
162 token3 >> token_value;
164 uiuc_warnings_errors(1, *command_line);
166 Cm_adot = token_value;
167 Cm_adot_clean = Cm_adot;
168 aeroPitchParts -> storeCommands (*command_line);
173 if (check_float(linetoken3))
174 token3 >> token_value;
176 uiuc_warnings_errors(1, *command_line);
180 aeroPitchParts -> storeCommands (*command_line);
185 if (check_float(linetoken3))
186 token3 >> token_value;
188 uiuc_warnings_errors(1, *command_line);
191 aeroPitchParts -> storeCommands (*command_line);
196 if (check_float(linetoken3))
197 token3 >> token_value;
199 uiuc_warnings_errors(1, *command_line);
203 aeroPitchParts -> storeCommands (*command_line);
208 if (check_float(linetoken3))
209 token3 >> token_value;
211 uiuc_warnings_errors(1, *command_line);
215 aeroPitchParts -> storeCommands (*command_line);
220 if (check_float(linetoken3))
221 token3 >> token_value;
223 uiuc_warnings_errors(1, *command_line);
227 aeroPitchParts -> storeCommands (*command_line);
232 if (check_float(linetoken3))
233 token3 >> token_value;
235 uiuc_warnings_errors(1, *command_line);
239 aeroPitchParts -> storeCommands (*command_line);
244 if (check_float(linetoken3))
245 token3 >> token_value;
247 uiuc_warnings_errors(1, *command_line);
250 aeroPitchParts -> storeCommands (*command_line);
255 if (check_float(linetoken3))
256 token3 >> token_value;
258 uiuc_warnings_errors(1, *command_line);
261 aeroPitchParts -> storeCommands (*command_line);
266 Cmfa = 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 (Cmfa) and conversion
272 factors; function returns array of alphas (aArray) and
273 corresponding Cm values (CmArray) and max number of
274 terms in arrays (nAlpha) */
275 uiuc_1DdataFileReader(Cmfa,
279 aeroPitchParts -> storeCommands (*command_line);
284 Cmfade = aircraft_directory + linetoken3;
285 token4 >> token_value_convert1;
286 token5 >> token_value_convert2;
287 token6 >> token_value_convert3;
288 convert_z = uiuc_convert(token_value_convert1);
289 convert_x = uiuc_convert(token_value_convert2);
290 convert_y = uiuc_convert(token_value_convert3);
291 /* call 2D File Reader with file name (Cmfade) and
292 conversion factors; function returns array of
293 elevator deflections (deArray) and corresponding
294 alpha (aArray) and delta Cm (CmArray) values and
295 max number of terms in alpha arrays (nAlphaArray)
296 and deflection array (nde) */
297 uiuc_2DdataFileReader(Cmfade,
303 aeroPitchParts -> storeCommands (*command_line);
308 Cmfdf = aircraft_directory + linetoken3;
309 token4 >> token_value_convert1;
310 token5 >> token_value_convert2;
311 convert_y = uiuc_convert(token_value_convert1);
312 convert_x = uiuc_convert(token_value_convert2);
313 /* call 1D File Reader with file name (Cmfdf) and conversion
314 factors; function returns array of dfs (dfArray) and
315 corresponding Cm values (CmArray) and max number of
316 terms in arrays (ndf) */
317 uiuc_1DdataFileReader(Cmfdf,
321 aeroPitchParts -> storeCommands (*command_line);
326 Cmfadf = aircraft_directory + linetoken3;
327 token4 >> token_value_convert1;
328 token5 >> token_value_convert2;
329 token6 >> token_value_convert3;
330 convert_z = uiuc_convert(token_value_convert1);
331 convert_x = uiuc_convert(token_value_convert2);
332 convert_y = uiuc_convert(token_value_convert3);
333 /* call 2D File Reader with file name (Cmfadf) and
334 conversion factors; function returns array of
335 flap deflections (dfArray) and corresponding
336 alpha (aArray) and delta Cm (CmArray) values and
337 max number of terms in alpha arrays (nAlphaArray)
338 and deflection array (ndf) */
339 uiuc_2DdataFileReader(Cmfadf,
345 aeroPitchParts -> storeCommands (*command_line);
350 int Cmfabetaf_index, i;
351 string Cmfabetaf_file;
353 Cmfabetaf_file = aircraft_directory + linetoken3;
354 token4 >> Cmfabetaf_index;
355 if (Cmfabetaf_index < 0 || Cmfabetaf_index >= 30)
356 uiuc_warnings_errors(1, *command_line);
357 if (Cmfabetaf_index > Cmfabetaf_nf)
358 Cmfabetaf_nf = Cmfabetaf_index;
359 token5 >> flap_value;
360 token6 >> token_value_convert1;
361 token7 >> token_value_convert2;
362 token8 >> token_value_convert3;
363 token9 >> token_value_convert4;
364 token10 >> Cmfabetaf_nice;
365 convert_z = uiuc_convert(token_value_convert1);
366 convert_x = uiuc_convert(token_value_convert2);
367 convert_y = uiuc_convert(token_value_convert3);
368 convert_f = uiuc_convert(token_value_convert4);
369 Cmfabetaf_fArray[Cmfabetaf_index] = flap_value * convert_f;
370 /* call 2D File Reader with file name (Cmfabetaf_file) and
371 conversion factors; function returns array of
372 elevator deflections (deArray) and corresponding
373 alpha (aArray) and delta CZ (CZArray) values and
374 max number of terms in alpha arrays (nAlphaArray)
375 and delfection array (nde) */
376 uiuc_2DdataFileReader(Cmfabetaf_file,
382 d_2_to_3(datafile_xArray, Cmfabetaf_aArray, Cmfabetaf_index);
383 d_1_to_2(datafile_yArray, Cmfabetaf_betaArray, Cmfabetaf_index);
384 d_2_to_3(datafile_zArray, Cmfabetaf_CmArray, Cmfabetaf_index);
385 i_1_to_2(datafile_nxArray, Cmfabetaf_nAlphaArray, Cmfabetaf_index);
386 Cmfabetaf_nbeta[Cmfabetaf_index] = datafile_ny;
387 if (Cmfabetaf_first==true)
389 if (Cmfabetaf_nice == 1)
391 Cmfabetaf_na_nice = datafile_nxArray[1];
392 Cmfabetaf_nb_nice = datafile_ny;
393 d_1_to_1(datafile_yArray, Cmfabetaf_bArray_nice);
394 for (i=1; i<=Cmfabetaf_na_nice; i++)
395 Cmfabetaf_aArray_nice[i] = datafile_xArray[1][i];
397 aeroPitchParts -> storeCommands (*command_line);
398 Cmfabetaf_first=false;
404 int Cmfadef_index, i;
407 Cmfadef_file = aircraft_directory + linetoken3;
408 token4 >> Cmfadef_index;
409 if (Cmfadef_index < 0 || Cmfadef_index >= 30)
410 uiuc_warnings_errors(1, *command_line);
411 if (Cmfadef_index > Cmfadef_nf)
412 Cmfadef_nf = Cmfadef_index;
413 token5 >> flap_value;
414 token6 >> token_value_convert1;
415 token7 >> token_value_convert2;
416 token8 >> token_value_convert3;
417 token9 >> token_value_convert4;
418 token10 >> Cmfadef_nice;
419 convert_z = uiuc_convert(token_value_convert1);
420 convert_x = uiuc_convert(token_value_convert2);
421 convert_y = uiuc_convert(token_value_convert3);
422 convert_f = uiuc_convert(token_value_convert4);
423 Cmfadef_fArray[Cmfadef_index] = flap_value * convert_f;
424 /* call 2D File Reader with file name (Cmfadef_file) and
425 conversion factors; function returns array of
426 elevator deflections (deArray) and corresponding
427 alpha (aArray) and delta CZ (CZArray) values and
428 max number of terms in alpha arrays (nAlphaArray)
429 and delfection array (nde) */
430 uiuc_2DdataFileReader(Cmfadef_file,
436 d_2_to_3(datafile_xArray, Cmfadef_aArray, Cmfadef_index);
437 d_1_to_2(datafile_yArray, Cmfadef_deArray, Cmfadef_index);
438 d_2_to_3(datafile_zArray, Cmfadef_CmArray, Cmfadef_index);
439 i_1_to_2(datafile_nxArray, Cmfadef_nAlphaArray, Cmfadef_index);
440 Cmfadef_nde[Cmfadef_index] = datafile_ny;
441 if (Cmfadef_first==true)
443 if (Cmfadef_nice == 1)
445 Cmfadef_na_nice = datafile_nxArray[1];
446 Cmfadef_nde_nice = datafile_ny;
447 d_1_to_1(datafile_yArray, Cmfadef_deArray_nice);
448 for (i=1; i<=Cmfadef_na_nice; i++)
449 Cmfadef_aArray_nice[i] = datafile_xArray[1][i];
451 aeroPitchParts -> storeCommands (*command_line);
461 Cmfaqf_file = aircraft_directory + linetoken3;
462 token4 >> Cmfaqf_index;
463 if (Cmfaqf_index < 0 || Cmfaqf_index >= 30)
464 uiuc_warnings_errors(1, *command_line);
465 if (Cmfaqf_index > Cmfaqf_nf)
466 Cmfaqf_nf = Cmfaqf_index;
467 token5 >> flap_value;
468 token6 >> token_value_convert1;
469 token7 >> token_value_convert2;
470 token8 >> token_value_convert3;
471 token9 >> token_value_convert4;
472 token10 >> Cmfaqf_nice;
473 convert_z = uiuc_convert(token_value_convert1);
474 convert_x = uiuc_convert(token_value_convert2);
475 convert_y = uiuc_convert(token_value_convert3);
476 convert_f = uiuc_convert(token_value_convert4);
477 Cmfaqf_fArray[Cmfaqf_index] = flap_value * convert_f;
478 /* call 2D File Reader with file name (Cmfaqf_file) and
479 conversion factors; function returns array of
480 elevator deflections (deArray) and corresponding
481 alpha (aArray) and delta CZ (CZArray) values and
482 max number of terms in alpha arrays (nAlphaArray)
483 and delfection array (nde) */
484 uiuc_2DdataFileReader(Cmfaqf_file,
490 d_2_to_3(datafile_xArray, Cmfaqf_aArray, Cmfaqf_index);
491 d_1_to_2(datafile_yArray, Cmfaqf_qArray, Cmfaqf_index);
492 d_2_to_3(datafile_zArray, Cmfaqf_CmArray, Cmfaqf_index);
493 i_1_to_2(datafile_nxArray, Cmfaqf_nAlphaArray, Cmfaqf_index);
494 Cmfaqf_nq[Cmfaqf_index] = datafile_ny;
495 if (Cmfaqf_first==true)
497 if (Cmfaqf_nice == 1)
499 Cmfaqf_na_nice = datafile_nxArray[1];
500 Cmfaqf_nq_nice = datafile_ny;
501 d_1_to_1(datafile_yArray, Cmfaqf_qArray_nice);
502 for (i=1; i<=Cmfaqf_na_nice; i++)
503 Cmfaqf_aArray_nice[i] = datafile_xArray[1][i];
505 aeroPitchParts -> storeCommands (*command_line);
512 if (ignore_unknown_keywords) {
515 // print error message
516 uiuc_warnings_errors(2, *command_line);