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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
70 USA or view http://www.gnu.org/copyleft/gpl.html.
72 **********************************************************************/
74 #include <simgear/compiler.h>
76 #if defined( __MWERKS__ )
77 // -dw- optimizer chokes (big-time) trying to optimize humongous
78 // loop/switch statements
79 #pragma optimization_level 0
86 #include "uiuc_menu_CD.h"
96 void parse_CD( 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 ) {
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];
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());
118 static bool CXfabetaf_first = true;
119 static bool CXfadef_first = true;
120 static bool CXfaqf_first = true;
122 switch(CD_map[linetoken2])
126 if (check_float(linetoken3))
127 token3 >> token_value;
129 uiuc_warnings_errors(1, *command_line);
133 aeroDragParts -> storeCommands (*command_line);
138 if (check_float(linetoken3))
139 token3 >> token_value;
141 uiuc_warnings_errors(1, *command_line);
145 aeroDragParts -> storeCommands (*command_line);
151 if (check_float(linetoken3))
152 token3 >> token_value;
154 uiuc_warnings_errors(1, *command_line);
160 if (check_float(linetoken3))
161 token3 >> token_value;
163 uiuc_warnings_errors(1, *command_line);
167 aeroDragParts -> storeCommands (*command_line);
172 if (check_float(linetoken3))
173 token3 >> token_value;
175 uiuc_warnings_errors(1, *command_line);
177 CD_adot = token_value;
178 CD_adot_clean = CD_adot;
179 aeroDragParts -> storeCommands (*command_line);
184 if (check_float(linetoken3))
185 token3 >> token_value;
187 uiuc_warnings_errors(1, *command_line);
191 aeroDragParts -> storeCommands (*command_line);
196 if (check_float(linetoken3))
197 token3 >> token_value;
199 uiuc_warnings_errors(1, *command_line);
202 aeroDragParts -> storeCommands (*command_line);
207 if (check_float(linetoken3))
208 token3 >> token_value;
210 uiuc_warnings_errors(1, *command_line);
214 aeroDragParts -> storeCommands (*command_line);
219 if (check_float(linetoken3))
220 token3 >> token_value;
222 uiuc_warnings_errors(1, *command_line);
225 aeroDragParts -> storeCommands (*command_line);
230 if (check_float(linetoken3))
231 token3 >> token_value;
233 uiuc_warnings_errors(1, *command_line);
236 aeroDragParts -> storeCommands (*command_line);
241 if (check_float(linetoken3))
242 token3 >> token_value;
244 uiuc_warnings_errors(1, *command_line);
246 CD_beta = token_value;
247 aeroDragParts -> storeCommands (*command_line);
252 if (check_float(linetoken3))
253 token3 >> token_value;
255 uiuc_warnings_errors(1, *command_line);
258 aeroDragParts -> storeCommands (*command_line);
263 if (check_float(linetoken3))
264 token3 >> token_value;
266 uiuc_warnings_errors(1, *command_line);
269 aeroDragParts -> storeCommands (*command_line);
274 if (check_float(linetoken3))
275 token3 >> token_value;
277 uiuc_warnings_errors(1, *command_line);
280 aeroDragParts -> storeCommands (*command_line);
285 CDfa = aircraft_directory + linetoken3;
286 token4 >> token_value_convert1;
287 token5 >> token_value_convert2;
288 convert_y = uiuc_convert(token_value_convert1);
289 convert_x = uiuc_convert(token_value_convert2);
290 /* call 1D File Reader with file name (CDfa) and conversion
291 factors; function returns array of alphas (aArray) and
292 corresponding CD values (CDArray) and max number of
293 terms in arrays (nAlpha) */
294 uiuc_1DdataFileReader(CDfa,
298 aeroDragParts -> storeCommands (*command_line);
303 CDfCL = 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 (CDfCL) and conversion
309 factors; function returns array of CLs (CLArray) and
310 corresponding CD values (CDArray) and max number of
311 terms in arrays (nCL) */
312 uiuc_1DdataFileReader(CDfCL,
316 aeroDragParts -> storeCommands (*command_line);
321 CDfade = 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 (CDfade) and
329 conversion factors; function returns array of
330 elevator deflections (deArray) and corresponding
331 alpha (aArray) and delta CD (CDArray) values and
332 max number of terms in alpha arrays (nAlphaArray)
333 and deflection array (nde) */
334 uiuc_2DdataFileReader(CDfade,
340 aeroDragParts -> storeCommands (*command_line);
345 CDfdf = aircraft_directory + linetoken3;
346 token4 >> token_value_convert1;
347 token5 >> token_value_convert2;
348 convert_y = uiuc_convert(token_value_convert1);
349 convert_x = uiuc_convert(token_value_convert2);
350 /* call 1D File Reader with file name (CDfdf) and conversion
351 factors; function returns array of dfs (dfArray) and
352 corresponding CD values (CDArray) and max number of
353 terms in arrays (ndf) */
354 uiuc_1DdataFileReader(CDfdf,
358 aeroDragParts -> storeCommands (*command_line);
363 CDfadf = aircraft_directory + linetoken3;
364 token4 >> token_value_convert1;
365 token5 >> token_value_convert2;
366 token6 >> token_value_convert3;
367 convert_z = uiuc_convert(token_value_convert1);
368 convert_x = uiuc_convert(token_value_convert2);
369 convert_y = uiuc_convert(token_value_convert3);
370 /* call 2D File Reader with file name (CDfadf) and
371 conversion factors; function returns array of
372 flap deflections (dfArray) and corresponding
373 alpha (aArray) and delta CD (CDArray) values and
374 max number of terms in alpha arrays (nAlphaArray)
375 and deflection array (ndf) */
376 uiuc_2DdataFileReader(CDfadf,
382 aeroDragParts -> storeCommands (*command_line);
387 if (check_float(linetoken3))
388 token3 >> token_value;
390 uiuc_warnings_errors(1, *command_line);
394 aeroDragParts -> storeCommands (*command_line);
399 if (check_float(linetoken3))
400 token3 >> token_value;
402 uiuc_warnings_errors(1, *command_line);
406 aeroDragParts -> storeCommands (*command_line);
411 if (check_float(linetoken3))
412 token3 >> token_value;
414 uiuc_warnings_errors(1, *command_line);
418 aeroDragParts -> storeCommands (*command_line);
423 if (check_float(linetoken3))
424 token3 >> token_value;
426 uiuc_warnings_errors(1, *command_line);
430 aeroDragParts -> storeCommands (*command_line);
435 if (check_float(linetoken3))
436 token3 >> token_value;
438 uiuc_warnings_errors(1, *command_line);
442 aeroDragParts -> storeCommands (*command_line);
447 if (check_float(linetoken3))
448 token3 >> token_value;
450 uiuc_warnings_errors(1, *command_line);
452 CX_adot = token_value;
453 CX_adot_clean = CX_adot;
454 aeroDragParts -> storeCommands (*command_line);
459 if (check_float(linetoken3))
460 token3 >> token_value;
462 uiuc_warnings_errors(1, *command_line);
466 aeroDragParts -> storeCommands (*command_line);
471 if (check_float(linetoken3))
472 token3 >> token_value;
474 uiuc_warnings_errors(1, *command_line);
478 aeroDragParts -> storeCommands (*command_line);
483 if (check_float(linetoken3))
484 token3 >> token_value;
486 uiuc_warnings_errors(1, *command_line);
490 aeroDragParts -> storeCommands (*command_line);
495 if (check_float(linetoken3))
496 token3 >> token_value;
498 uiuc_warnings_errors(1, *command_line);
502 aeroDragParts -> storeCommands (*command_line);
507 if (check_float(linetoken3))
508 token3 >> token_value;
510 uiuc_warnings_errors(1, *command_line);
512 CX_adf = token_value;
513 CX_adf_clean = CX_adf;
514 aeroDragParts -> storeCommands (*command_line);
519 int CXfabetaf_index, i;
520 string CXfabetaf_file;
522 CXfabetaf_file = aircraft_directory + linetoken3;
523 token4 >> CXfabetaf_index;
524 if (CXfabetaf_index < 1 || CXfabetaf_index >= 30)
525 uiuc_warnings_errors(1, *command_line);
526 if (CXfabetaf_index > CXfabetaf_nf)
527 CXfabetaf_nf = CXfabetaf_index;
528 token5 >> flap_value;
529 token6 >> token_value_convert1;
530 token7 >> token_value_convert2;
531 token8 >> token_value_convert3;
532 token9 >> token_value_convert4;
533 token10 >> CXfabetaf_nice;
534 convert_z = uiuc_convert(token_value_convert1);
535 convert_x = uiuc_convert(token_value_convert2);
536 convert_y = uiuc_convert(token_value_convert3);
537 convert_f = uiuc_convert(token_value_convert4);
538 CXfabetaf_fArray[CXfabetaf_index] = flap_value * convert_f;
539 /* call 2D File Reader with file name (CXfabetaf_file) and
540 conversion factors; function returns array of
541 elevator deflections (deArray) and corresponding
542 alpha (aArray) and delta CZ (CZArray) values and
543 max number of terms in alpha arrays (nAlphaArray)
544 and delfection array (nde) */
545 uiuc_2DdataFileReader(CXfabetaf_file,
551 d_2_to_3(datafile_xArray, CXfabetaf_aArray, CXfabetaf_index);
552 d_1_to_2(datafile_yArray, CXfabetaf_betaArray, CXfabetaf_index);
553 d_2_to_3(datafile_zArray, CXfabetaf_CXArray, CXfabetaf_index);
554 i_1_to_2(datafile_nxArray, CXfabetaf_nAlphaArray, CXfabetaf_index);
555 CXfabetaf_nbeta[CXfabetaf_index] = datafile_ny;
556 if (CXfabetaf_first==true)
558 if (CXfabetaf_nice == 1)
560 CXfabetaf_na_nice = datafile_nxArray[1];
561 CXfabetaf_nb_nice = datafile_ny;
562 d_1_to_1(datafile_yArray, CXfabetaf_bArray_nice);
563 for (i=1; i<=CXfabetaf_na_nice; i++)
564 CXfabetaf_aArray_nice[i] = datafile_xArray[1][i];
566 aeroDragParts -> storeCommands (*command_line);
567 CXfabetaf_first=false;
573 int CXfadef_index, i;
576 CXfadef_file = aircraft_directory + linetoken3;
577 token4 >> CXfadef_index;
578 if (CXfadef_index < 0 || CXfadef_index >= 30)
579 uiuc_warnings_errors(1, *command_line);
580 if (CXfadef_index > CXfadef_nf)
581 CXfadef_nf = CXfadef_index;
582 token5 >> flap_value;
583 token6 >> token_value_convert1;
584 token7 >> token_value_convert2;
585 token8 >> token_value_convert3;
586 token9 >> token_value_convert4;
587 token10 >> CXfadef_nice;
588 convert_z = uiuc_convert(token_value_convert1);
589 convert_x = uiuc_convert(token_value_convert2);
590 convert_y = uiuc_convert(token_value_convert3);
591 convert_f = uiuc_convert(token_value_convert4);
592 CXfadef_fArray[CXfadef_index] = flap_value * convert_f;
593 /* call 2D File Reader with file name (CXfadef_file) and
594 conversion factors; function returns array of
595 elevator deflections (deArray) and corresponding
596 alpha (aArray) and delta CZ (CZArray) values and
597 max number of terms in alpha arrays (nAlphaArray)
598 and delfection array (nde) */
599 uiuc_2DdataFileReader(CXfadef_file,
605 d_2_to_3(datafile_xArray, CXfadef_aArray, CXfadef_index);
606 d_1_to_2(datafile_yArray, CXfadef_deArray, CXfadef_index);
607 d_2_to_3(datafile_zArray, CXfadef_CXArray, CXfadef_index);
608 i_1_to_2(datafile_nxArray, CXfadef_nAlphaArray, CXfadef_index);
609 CXfadef_nde[CXfadef_index] = datafile_ny;
610 if (CXfadef_first==true)
612 if (CXfadef_nice == 1)
614 CXfadef_na_nice = datafile_nxArray[1];
615 CXfadef_nde_nice = datafile_ny;
616 d_1_to_1(datafile_yArray, CXfadef_deArray_nice);
617 for (i=1; i<=CXfadef_na_nice; i++)
618 CXfadef_aArray_nice[i] = datafile_xArray[1][i];
620 aeroDragParts -> storeCommands (*command_line);
630 CXfaqf_file = aircraft_directory + linetoken3;
631 token4 >> CXfaqf_index;
632 if (CXfaqf_index < 0 || CXfaqf_index >= 30)
633 uiuc_warnings_errors(1, *command_line);
634 if (CXfaqf_index > CXfaqf_nf)
635 CXfaqf_nf = CXfaqf_index;
636 token5 >> flap_value;
637 token6 >> token_value_convert1;
638 token7 >> token_value_convert2;
639 token8 >> token_value_convert3;
640 token9 >> token_value_convert4;
641 token10 >> CXfaqf_nice;
642 convert_z = uiuc_convert(token_value_convert1);
643 convert_x = uiuc_convert(token_value_convert2);
644 convert_y = uiuc_convert(token_value_convert3);
645 convert_f = uiuc_convert(token_value_convert4);
646 CXfaqf_fArray[CXfaqf_index] = flap_value * convert_f;
647 /* call 2D File Reader with file name (CXfaqf_file) and
648 conversion factors; function returns array of
649 elevator deflections (deArray) and corresponding
650 alpha (aArray) and delta CZ (CZArray) values and
651 max number of terms in alpha arrays (nAlphaArray)
652 and delfection array (nde) */
653 uiuc_2DdataFileReader(CXfaqf_file,
659 d_2_to_3(datafile_xArray, CXfaqf_aArray, CXfaqf_index);
660 d_1_to_2(datafile_yArray, CXfaqf_qArray, CXfaqf_index);
661 d_2_to_3(datafile_zArray, CXfaqf_CXArray, CXfaqf_index);
662 i_1_to_2(datafile_nxArray, CXfaqf_nAlphaArray, CXfaqf_index);
663 CXfaqf_nq[CXfaqf_index] = datafile_ny;
664 if (CXfaqf_first==true)
666 if (CXfaqf_nice == 1)
668 CXfaqf_na_nice = datafile_nxArray[1];
669 CXfaqf_nq_nice = datafile_ny;
670 d_1_to_1(datafile_yArray, CXfaqf_qArray_nice);
671 for (i=1; i<=CXfaqf_na_nice; i++)
672 CXfaqf_aArray_nice[i] = datafile_xArray[1][i];
674 aeroDragParts -> storeCommands (*command_line);
681 if (ignore_unknown_keywords) {
684 // print error message
685 uiuc_warnings_errors(2, *command_line);