1 /**********************************************************************
3 FILENAME: uiuc_menu_CD.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_CD.h"
95 void parse_CD( 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 CXfabetaf_first = true;
118 static bool CXfadef_first = true;
119 static bool CXfaqf_first = true;
121 switch(CD_map[linetoken2])
125 if (check_float(linetoken3))
126 token3 >> token_value;
128 uiuc_warnings_errors(1, *command_line);
132 aeroDragParts -> storeCommands (*command_line);
137 if (check_float(linetoken3))
138 token3 >> token_value;
140 uiuc_warnings_errors(1, *command_line);
144 aeroDragParts -> storeCommands (*command_line);
150 if (check_float(linetoken3))
151 token3 >> token_value;
153 uiuc_warnings_errors(1, *command_line);
159 if (check_float(linetoken3))
160 token3 >> token_value;
162 uiuc_warnings_errors(1, *command_line);
166 aeroDragParts -> storeCommands (*command_line);
171 if (check_float(linetoken3))
172 token3 >> token_value;
174 uiuc_warnings_errors(1, *command_line);
176 CD_adot = token_value;
177 CD_adot_clean = CD_adot;
178 aeroDragParts -> storeCommands (*command_line);
183 if (check_float(linetoken3))
184 token3 >> token_value;
186 uiuc_warnings_errors(1, *command_line);
190 aeroDragParts -> storeCommands (*command_line);
195 if (check_float(linetoken3))
196 token3 >> token_value;
198 uiuc_warnings_errors(1, *command_line);
201 aeroDragParts -> storeCommands (*command_line);
206 if (check_float(linetoken3))
207 token3 >> token_value;
209 uiuc_warnings_errors(1, *command_line);
213 aeroDragParts -> storeCommands (*command_line);
218 if (check_float(linetoken3))
219 token3 >> token_value;
221 uiuc_warnings_errors(1, *command_line);
224 aeroDragParts -> storeCommands (*command_line);
229 if (check_float(linetoken3))
230 token3 >> token_value;
232 uiuc_warnings_errors(1, *command_line);
235 aeroDragParts -> storeCommands (*command_line);
240 if (check_float(linetoken3))
241 token3 >> token_value;
243 uiuc_warnings_errors(1, *command_line);
245 CD_beta = token_value;
246 aeroDragParts -> storeCommands (*command_line);
251 if (check_float(linetoken3))
252 token3 >> token_value;
254 uiuc_warnings_errors(1, *command_line);
257 aeroDragParts -> storeCommands (*command_line);
262 if (check_float(linetoken3))
263 token3 >> token_value;
265 uiuc_warnings_errors(1, *command_line);
268 aeroDragParts -> storeCommands (*command_line);
273 if (check_float(linetoken3))
274 token3 >> token_value;
276 uiuc_warnings_errors(1, *command_line);
279 aeroDragParts -> storeCommands (*command_line);
284 CDfa = aircraft_directory + linetoken3;
285 token4 >> token_value_convert1;
286 token5 >> token_value_convert2;
287 convert_y = uiuc_convert(token_value_convert1);
288 convert_x = uiuc_convert(token_value_convert2);
289 /* call 1D File Reader with file name (CDfa) and conversion
290 factors; function returns array of alphas (aArray) and
291 corresponding CD values (CDArray) and max number of
292 terms in arrays (nAlpha) */
293 uiuc_1DdataFileReader(CDfa,
297 aeroDragParts -> storeCommands (*command_line);
302 CDfCL = aircraft_directory + linetoken3;
303 token4 >> token_value_convert1;
304 token5 >> token_value_convert2;
305 convert_y = uiuc_convert(token_value_convert1);
306 convert_x = uiuc_convert(token_value_convert2);
307 /* call 1D File Reader with file name (CDfCL) and conversion
308 factors; function returns array of CLs (CLArray) and
309 corresponding CD values (CDArray) and max number of
310 terms in arrays (nCL) */
311 uiuc_1DdataFileReader(CDfCL,
315 aeroDragParts -> storeCommands (*command_line);
320 CDfade = aircraft_directory + linetoken3;
321 token4 >> token_value_convert1;
322 token5 >> token_value_convert2;
323 token6 >> token_value_convert3;
324 convert_z = uiuc_convert(token_value_convert1);
325 convert_x = uiuc_convert(token_value_convert2);
326 convert_y = uiuc_convert(token_value_convert3);
327 /* call 2D File Reader with file name (CDfade) and
328 conversion factors; function returns array of
329 elevator deflections (deArray) and corresponding
330 alpha (aArray) and delta CD (CDArray) values and
331 max number of terms in alpha arrays (nAlphaArray)
332 and deflection array (nde) */
333 uiuc_2DdataFileReader(CDfade,
339 aeroDragParts -> storeCommands (*command_line);
344 CDfdf = aircraft_directory + linetoken3;
345 token4 >> token_value_convert1;
346 token5 >> token_value_convert2;
347 convert_y = uiuc_convert(token_value_convert1);
348 convert_x = uiuc_convert(token_value_convert2);
349 /* call 1D File Reader with file name (CDfdf) and conversion
350 factors; function returns array of dfs (dfArray) and
351 corresponding CD values (CDArray) and max number of
352 terms in arrays (ndf) */
353 uiuc_1DdataFileReader(CDfdf,
357 aeroDragParts -> storeCommands (*command_line);
362 CDfadf = aircraft_directory + linetoken3;
363 token4 >> token_value_convert1;
364 token5 >> token_value_convert2;
365 token6 >> token_value_convert3;
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 /* call 2D File Reader with file name (CDfadf) and
370 conversion factors; function returns array of
371 flap deflections (dfArray) and corresponding
372 alpha (aArray) and delta CD (CDArray) values and
373 max number of terms in alpha arrays (nAlphaArray)
374 and deflection array (ndf) */
375 uiuc_2DdataFileReader(CDfadf,
381 aeroDragParts -> storeCommands (*command_line);
386 if (check_float(linetoken3))
387 token3 >> token_value;
389 uiuc_warnings_errors(1, *command_line);
393 aeroDragParts -> storeCommands (*command_line);
398 if (check_float(linetoken3))
399 token3 >> token_value;
401 uiuc_warnings_errors(1, *command_line);
405 aeroDragParts -> storeCommands (*command_line);
410 if (check_float(linetoken3))
411 token3 >> token_value;
413 uiuc_warnings_errors(1, *command_line);
417 aeroDragParts -> storeCommands (*command_line);
422 if (check_float(linetoken3))
423 token3 >> token_value;
425 uiuc_warnings_errors(1, *command_line);
429 aeroDragParts -> storeCommands (*command_line);
434 if (check_float(linetoken3))
435 token3 >> token_value;
437 uiuc_warnings_errors(1, *command_line);
441 aeroDragParts -> storeCommands (*command_line);
446 if (check_float(linetoken3))
447 token3 >> token_value;
449 uiuc_warnings_errors(1, *command_line);
451 CX_adot = token_value;
452 CX_adot_clean = CX_adot;
453 aeroDragParts -> storeCommands (*command_line);
458 if (check_float(linetoken3))
459 token3 >> token_value;
461 uiuc_warnings_errors(1, *command_line);
465 aeroDragParts -> storeCommands (*command_line);
470 if (check_float(linetoken3))
471 token3 >> token_value;
473 uiuc_warnings_errors(1, *command_line);
477 aeroDragParts -> storeCommands (*command_line);
482 if (check_float(linetoken3))
483 token3 >> token_value;
485 uiuc_warnings_errors(1, *command_line);
489 aeroDragParts -> storeCommands (*command_line);
494 if (check_float(linetoken3))
495 token3 >> token_value;
497 uiuc_warnings_errors(1, *command_line);
501 aeroDragParts -> storeCommands (*command_line);
506 if (check_float(linetoken3))
507 token3 >> token_value;
509 uiuc_warnings_errors(1, *command_line);
511 CX_adf = token_value;
512 CX_adf_clean = CX_adf;
513 aeroDragParts -> storeCommands (*command_line);
518 int CXfabetaf_index, i;
519 string CXfabetaf_file;
521 CXfabetaf_file = aircraft_directory + linetoken3;
522 token4 >> CXfabetaf_index;
523 if (CXfabetaf_index < 1 || CXfabetaf_index >= 30)
524 uiuc_warnings_errors(1, *command_line);
525 if (CXfabetaf_index > CXfabetaf_nf)
526 CXfabetaf_nf = CXfabetaf_index;
527 token5 >> flap_value;
528 token6 >> token_value_convert1;
529 token7 >> token_value_convert2;
530 token8 >> token_value_convert3;
531 token9 >> token_value_convert4;
532 token10 >> CXfabetaf_nice;
533 convert_z = uiuc_convert(token_value_convert1);
534 convert_x = uiuc_convert(token_value_convert2);
535 convert_y = uiuc_convert(token_value_convert3);
536 convert_f = uiuc_convert(token_value_convert4);
537 CXfabetaf_fArray[CXfabetaf_index] = flap_value * convert_f;
538 /* call 2D File Reader with file name (CXfabetaf_file) and
539 conversion factors; function returns array of
540 elevator deflections (deArray) and corresponding
541 alpha (aArray) and delta CZ (CZArray) values and
542 max number of terms in alpha arrays (nAlphaArray)
543 and delfection array (nde) */
544 uiuc_2DdataFileReader(CXfabetaf_file,
550 d_2_to_3(datafile_xArray, CXfabetaf_aArray, CXfabetaf_index);
551 d_1_to_2(datafile_yArray, CXfabetaf_betaArray, CXfabetaf_index);
552 d_2_to_3(datafile_zArray, CXfabetaf_CXArray, CXfabetaf_index);
553 i_1_to_2(datafile_nxArray, CXfabetaf_nAlphaArray, CXfabetaf_index);
554 CXfabetaf_nbeta[CXfabetaf_index] = datafile_ny;
555 if (CXfabetaf_first==true)
557 if (CXfabetaf_nice == 1)
559 CXfabetaf_na_nice = datafile_nxArray[1];
560 CXfabetaf_nb_nice = datafile_ny;
561 d_1_to_1(datafile_yArray, CXfabetaf_bArray_nice);
562 for (i=1; i<=CXfabetaf_na_nice; i++)
563 CXfabetaf_aArray_nice[i] = datafile_xArray[1][i];
565 aeroDragParts -> storeCommands (*command_line);
566 CXfabetaf_first=false;
572 int CXfadef_index, i;
575 CXfadef_file = aircraft_directory + linetoken3;
576 token4 >> CXfadef_index;
577 if (CXfadef_index < 0 || CXfadef_index >= 30)
578 uiuc_warnings_errors(1, *command_line);
579 if (CXfadef_index > CXfadef_nf)
580 CXfadef_nf = CXfadef_index;
581 token5 >> flap_value;
582 token6 >> token_value_convert1;
583 token7 >> token_value_convert2;
584 token8 >> token_value_convert3;
585 token9 >> token_value_convert4;
586 token10 >> CXfadef_nice;
587 convert_z = uiuc_convert(token_value_convert1);
588 convert_x = uiuc_convert(token_value_convert2);
589 convert_y = uiuc_convert(token_value_convert3);
590 convert_f = uiuc_convert(token_value_convert4);
591 CXfadef_fArray[CXfadef_index] = flap_value * convert_f;
592 /* call 2D File Reader with file name (CXfadef_file) and
593 conversion factors; function returns array of
594 elevator deflections (deArray) and corresponding
595 alpha (aArray) and delta CZ (CZArray) values and
596 max number of terms in alpha arrays (nAlphaArray)
597 and delfection array (nde) */
598 uiuc_2DdataFileReader(CXfadef_file,
604 d_2_to_3(datafile_xArray, CXfadef_aArray, CXfadef_index);
605 d_1_to_2(datafile_yArray, CXfadef_deArray, CXfadef_index);
606 d_2_to_3(datafile_zArray, CXfadef_CXArray, CXfadef_index);
607 i_1_to_2(datafile_nxArray, CXfadef_nAlphaArray, CXfadef_index);
608 CXfadef_nde[CXfadef_index] = datafile_ny;
609 if (CXfadef_first==true)
611 if (CXfadef_nice == 1)
613 CXfadef_na_nice = datafile_nxArray[1];
614 CXfadef_nde_nice = datafile_ny;
615 d_1_to_1(datafile_yArray, CXfadef_deArray_nice);
616 for (i=1; i<=CXfadef_na_nice; i++)
617 CXfadef_aArray_nice[i] = datafile_xArray[1][i];
619 aeroDragParts -> storeCommands (*command_line);
629 CXfaqf_file = aircraft_directory + linetoken3;
630 token4 >> CXfaqf_index;
631 if (CXfaqf_index < 0 || CXfaqf_index >= 30)
632 uiuc_warnings_errors(1, *command_line);
633 if (CXfaqf_index > CXfaqf_nf)
634 CXfaqf_nf = CXfaqf_index;
635 token5 >> flap_value;
636 token6 >> token_value_convert1;
637 token7 >> token_value_convert2;
638 token8 >> token_value_convert3;
639 token9 >> token_value_convert4;
640 token10 >> CXfaqf_nice;
641 convert_z = uiuc_convert(token_value_convert1);
642 convert_x = uiuc_convert(token_value_convert2);
643 convert_y = uiuc_convert(token_value_convert3);
644 convert_f = uiuc_convert(token_value_convert4);
645 CXfaqf_fArray[CXfaqf_index] = flap_value * convert_f;
646 /* call 2D File Reader with file name (CXfaqf_file) and
647 conversion factors; function returns array of
648 elevator deflections (deArray) and corresponding
649 alpha (aArray) and delta CZ (CZArray) values and
650 max number of terms in alpha arrays (nAlphaArray)
651 and delfection array (nde) */
652 uiuc_2DdataFileReader(CXfaqf_file,
658 d_2_to_3(datafile_xArray, CXfaqf_aArray, CXfaqf_index);
659 d_1_to_2(datafile_yArray, CXfaqf_qArray, CXfaqf_index);
660 d_2_to_3(datafile_zArray, CXfaqf_CXArray, CXfaqf_index);
661 i_1_to_2(datafile_nxArray, CXfaqf_nAlphaArray, CXfaqf_index);
662 CXfaqf_nq[CXfaqf_index] = datafile_ny;
663 if (CXfaqf_first==true)
665 if (CXfaqf_nice == 1)
667 CXfaqf_na_nice = datafile_nxArray[1];
668 CXfaqf_nq_nice = datafile_ny;
669 d_1_to_1(datafile_yArray, CXfaqf_qArray_nice);
670 for (i=1; i<=CXfaqf_na_nice; i++)
671 CXfaqf_aArray_nice[i] = datafile_xArray[1][i];
673 aeroDragParts -> storeCommands (*command_line);
680 if (ignore_unknown_keywords) {
683 // print error message
684 uiuc_warnings_errors(2, *command_line);