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>
80 #include "uiuc_menu_Cm.h"
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,
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];
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());
112 static bool Cmfabetaf_first = true;
113 static bool Cmfadef_first = true;
114 static bool Cmfaqf_first = true;
116 switch(Cm_map[linetoken2])
120 if (check_float(linetoken3))
121 token3 >> token_value;
123 uiuc_warnings_errors(1, *command_line);
127 aeroPitchParts -> storeCommands (*command_line);
132 if (check_float(linetoken3))
133 token3 >> token_value;
135 uiuc_warnings_errors(1, *command_line);
139 aeroPitchParts -> storeCommands (*command_line);
144 if (check_float(linetoken3))
145 token3 >> token_value;
147 uiuc_warnings_errors(1, *command_line);
151 aeroPitchParts -> storeCommands (*command_line);
156 if (check_float(linetoken3))
157 token3 >> token_value;
159 uiuc_warnings_errors(1, *command_line);
161 Cm_adot = token_value;
162 Cm_adot_clean = Cm_adot;
163 aeroPitchParts -> storeCommands (*command_line);
168 if (check_float(linetoken3))
169 token3 >> token_value;
171 uiuc_warnings_errors(1, *command_line);
175 aeroPitchParts -> storeCommands (*command_line);
180 if (check_float(linetoken3))
181 token3 >> token_value;
183 uiuc_warnings_errors(1, *command_line);
186 aeroPitchParts -> storeCommands (*command_line);
191 if (check_float(linetoken3))
192 token3 >> token_value;
194 uiuc_warnings_errors(1, *command_line);
198 aeroPitchParts -> storeCommands (*command_line);
203 if (check_float(linetoken3))
204 token3 >> token_value;
206 uiuc_warnings_errors(1, *command_line);
210 aeroPitchParts -> storeCommands (*command_line);
215 if (check_float(linetoken3))
216 token3 >> token_value;
218 uiuc_warnings_errors(1, *command_line);
222 aeroPitchParts -> storeCommands (*command_line);
227 if (check_float(linetoken3))
228 token3 >> token_value;
230 uiuc_warnings_errors(1, *command_line);
234 aeroPitchParts -> storeCommands (*command_line);
239 if (check_float(linetoken3))
240 token3 >> token_value;
242 uiuc_warnings_errors(1, *command_line);
245 aeroPitchParts -> storeCommands (*command_line);
250 if (check_float(linetoken3))
251 token3 >> token_value;
253 uiuc_warnings_errors(1, *command_line);
256 aeroPitchParts -> storeCommands (*command_line);
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,
274 aeroPitchParts -> storeCommands (*command_line);
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,
298 aeroPitchParts -> storeCommands (*command_line);
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,
316 aeroPitchParts -> storeCommands (*command_line);
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,
340 aeroPitchParts -> storeCommands (*command_line);
345 int Cmfabetaf_index, i;
346 string Cmfabetaf_file;
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,
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)
384 if (Cmfabetaf_nice == 1)
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];
392 aeroPitchParts -> storeCommands (*command_line);
393 Cmfabetaf_first=false;
399 int Cmfadef_index, i;
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,
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)
438 if (Cmfadef_nice == 1)
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];
446 aeroPitchParts -> storeCommands (*command_line);
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,
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)
492 if (Cmfaqf_nice == 1)
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];
500 aeroPitchParts -> storeCommands (*command_line);
507 if (ignore_unknown_keywords) {
510 // print error message
511 uiuc_warnings_errors(2, *command_line);