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
22 ----------------------------------------------------------------------
24 AUTHOR(S): Robert Deters <rdeters@uiuc.edu>
25 Michael Selig <m-selig@uiuc.edu>
27 ----------------------------------------------------------------------
31 ----------------------------------------------------------------------
35 ----------------------------------------------------------------------
39 ----------------------------------------------------------------------
41 CALLED BY: uiuc_menu()
43 ----------------------------------------------------------------------
45 CALLS TO: check_float() if needed
51 ----------------------------------------------------------------------
53 COPYRIGHT: (C) 2003 by Michael Selig
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.
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.
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.
69 **********************************************************************/
71 #include <simgear/compiler.h>
73 #if defined( __MWERKS__ )
74 // -dw- optimizer chokes (big-time) trying to optimize humongous
75 // loop/switch statements
76 #pragma optimization_level 0
83 #include "uiuc_menu_CD.h"
93 void parse_CD( 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,
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];
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());
115 static bool CXfabetaf_first = true;
116 static bool CXfadef_first = true;
117 static bool CXfaqf_first = true;
119 switch(CD_map[linetoken2])
123 if (check_float(linetoken3))
124 token3 >> token_value;
126 uiuc_warnings_errors(1, *command_line);
130 aeroDragParts -> storeCommands (*command_line);
135 if (check_float(linetoken3))
136 token3 >> token_value;
138 uiuc_warnings_errors(1, *command_line);
142 aeroDragParts -> storeCommands (*command_line);
148 if (check_float(linetoken3))
149 token3 >> token_value;
151 uiuc_warnings_errors(1, *command_line);
157 if (check_float(linetoken3))
158 token3 >> token_value;
160 uiuc_warnings_errors(1, *command_line);
164 aeroDragParts -> storeCommands (*command_line);
169 if (check_float(linetoken3))
170 token3 >> token_value;
172 uiuc_warnings_errors(1, *command_line);
174 CD_adot = token_value;
175 CD_adot_clean = CD_adot;
176 aeroDragParts -> storeCommands (*command_line);
181 if (check_float(linetoken3))
182 token3 >> token_value;
184 uiuc_warnings_errors(1, *command_line);
188 aeroDragParts -> storeCommands (*command_line);
193 if (check_float(linetoken3))
194 token3 >> token_value;
196 uiuc_warnings_errors(1, *command_line);
199 aeroDragParts -> storeCommands (*command_line);
204 if (check_float(linetoken3))
205 token3 >> token_value;
207 uiuc_warnings_errors(1, *command_line);
211 aeroDragParts -> storeCommands (*command_line);
216 if (check_float(linetoken3))
217 token3 >> token_value;
219 uiuc_warnings_errors(1, *command_line);
222 aeroDragParts -> storeCommands (*command_line);
227 if (check_float(linetoken3))
228 token3 >> token_value;
230 uiuc_warnings_errors(1, *command_line);
233 aeroDragParts -> storeCommands (*command_line);
238 if (check_float(linetoken3))
239 token3 >> token_value;
241 uiuc_warnings_errors(1, *command_line);
243 CD_beta = token_value;
244 aeroDragParts -> storeCommands (*command_line);
249 if (check_float(linetoken3))
250 token3 >> token_value;
252 uiuc_warnings_errors(1, *command_line);
255 aeroDragParts -> storeCommands (*command_line);
260 if (check_float(linetoken3))
261 token3 >> token_value;
263 uiuc_warnings_errors(1, *command_line);
266 aeroDragParts -> storeCommands (*command_line);
271 if (check_float(linetoken3))
272 token3 >> token_value;
274 uiuc_warnings_errors(1, *command_line);
277 aeroDragParts -> storeCommands (*command_line);
282 CDfa = aircraft_directory + linetoken3;
283 token4 >> token_value_convert1;
284 token5 >> token_value_convert2;
285 convert_y = uiuc_convert(token_value_convert1);
286 convert_x = uiuc_convert(token_value_convert2);
287 /* call 1D File Reader with file name (CDfa) and conversion
288 factors; function returns array of alphas (aArray) and
289 corresponding CD values (CDArray) and max number of
290 terms in arrays (nAlpha) */
291 uiuc_1DdataFileReader(CDfa,
295 aeroDragParts -> storeCommands (*command_line);
300 CDfCL = aircraft_directory + linetoken3;
301 token4 >> token_value_convert1;
302 token5 >> token_value_convert2;
303 convert_y = uiuc_convert(token_value_convert1);
304 convert_x = uiuc_convert(token_value_convert2);
305 /* call 1D File Reader with file name (CDfCL) and conversion
306 factors; function returns array of CLs (CLArray) and
307 corresponding CD values (CDArray) and max number of
308 terms in arrays (nCL) */
309 uiuc_1DdataFileReader(CDfCL,
313 aeroDragParts -> storeCommands (*command_line);
318 CDfade = aircraft_directory + linetoken3;
319 token4 >> token_value_convert1;
320 token5 >> token_value_convert2;
321 token6 >> token_value_convert3;
322 convert_z = uiuc_convert(token_value_convert1);
323 convert_x = uiuc_convert(token_value_convert2);
324 convert_y = uiuc_convert(token_value_convert3);
325 /* call 2D File Reader with file name (CDfade) and
326 conversion factors; function returns array of
327 elevator deflections (deArray) and corresponding
328 alpha (aArray) and delta CD (CDArray) values and
329 max number of terms in alpha arrays (nAlphaArray)
330 and deflection array (nde) */
331 uiuc_2DdataFileReader(CDfade,
337 aeroDragParts -> storeCommands (*command_line);
342 CDfdf = aircraft_directory + linetoken3;
343 token4 >> token_value_convert1;
344 token5 >> token_value_convert2;
345 convert_y = uiuc_convert(token_value_convert1);
346 convert_x = uiuc_convert(token_value_convert2);
347 /* call 1D File Reader with file name (CDfdf) and conversion
348 factors; function returns array of dfs (dfArray) and
349 corresponding CD values (CDArray) and max number of
350 terms in arrays (ndf) */
351 uiuc_1DdataFileReader(CDfdf,
355 aeroDragParts -> storeCommands (*command_line);
360 CDfadf = aircraft_directory + linetoken3;
361 token4 >> token_value_convert1;
362 token5 >> token_value_convert2;
363 token6 >> token_value_convert3;
364 convert_z = uiuc_convert(token_value_convert1);
365 convert_x = uiuc_convert(token_value_convert2);
366 convert_y = uiuc_convert(token_value_convert3);
367 /* call 2D File Reader with file name (CDfadf) and
368 conversion factors; function returns array of
369 flap deflections (dfArray) and corresponding
370 alpha (aArray) and delta CD (CDArray) values and
371 max number of terms in alpha arrays (nAlphaArray)
372 and deflection array (ndf) */
373 uiuc_2DdataFileReader(CDfadf,
379 aeroDragParts -> storeCommands (*command_line);
384 if (check_float(linetoken3))
385 token3 >> token_value;
387 uiuc_warnings_errors(1, *command_line);
391 aeroDragParts -> storeCommands (*command_line);
396 if (check_float(linetoken3))
397 token3 >> token_value;
399 uiuc_warnings_errors(1, *command_line);
403 aeroDragParts -> storeCommands (*command_line);
408 if (check_float(linetoken3))
409 token3 >> token_value;
411 uiuc_warnings_errors(1, *command_line);
415 aeroDragParts -> storeCommands (*command_line);
420 if (check_float(linetoken3))
421 token3 >> token_value;
423 uiuc_warnings_errors(1, *command_line);
427 aeroDragParts -> storeCommands (*command_line);
432 if (check_float(linetoken3))
433 token3 >> token_value;
435 uiuc_warnings_errors(1, *command_line);
439 aeroDragParts -> storeCommands (*command_line);
444 if (check_float(linetoken3))
445 token3 >> token_value;
447 uiuc_warnings_errors(1, *command_line);
449 CX_adot = token_value;
450 CX_adot_clean = CX_adot;
451 aeroDragParts -> storeCommands (*command_line);
456 if (check_float(linetoken3))
457 token3 >> token_value;
459 uiuc_warnings_errors(1, *command_line);
463 aeroDragParts -> storeCommands (*command_line);
468 if (check_float(linetoken3))
469 token3 >> token_value;
471 uiuc_warnings_errors(1, *command_line);
475 aeroDragParts -> storeCommands (*command_line);
480 if (check_float(linetoken3))
481 token3 >> token_value;
483 uiuc_warnings_errors(1, *command_line);
487 aeroDragParts -> storeCommands (*command_line);
492 if (check_float(linetoken3))
493 token3 >> token_value;
495 uiuc_warnings_errors(1, *command_line);
499 aeroDragParts -> storeCommands (*command_line);
504 if (check_float(linetoken3))
505 token3 >> token_value;
507 uiuc_warnings_errors(1, *command_line);
509 CX_adf = token_value;
510 CX_adf_clean = CX_adf;
511 aeroDragParts -> storeCommands (*command_line);
516 int CXfabetaf_index, i;
517 string CXfabetaf_file;
519 CXfabetaf_file = aircraft_directory + linetoken3;
520 token4 >> CXfabetaf_index;
521 if (CXfabetaf_index < 1 || CXfabetaf_index >= 30)
522 uiuc_warnings_errors(1, *command_line);
523 if (CXfabetaf_index > CXfabetaf_nf)
524 CXfabetaf_nf = CXfabetaf_index;
525 token5 >> flap_value;
526 token6 >> token_value_convert1;
527 token7 >> token_value_convert2;
528 token8 >> token_value_convert3;
529 token9 >> token_value_convert4;
530 token10 >> CXfabetaf_nice;
531 convert_z = uiuc_convert(token_value_convert1);
532 convert_x = uiuc_convert(token_value_convert2);
533 convert_y = uiuc_convert(token_value_convert3);
534 convert_f = uiuc_convert(token_value_convert4);
535 CXfabetaf_fArray[CXfabetaf_index] = flap_value * convert_f;
536 /* call 2D File Reader with file name (CXfabetaf_file) and
537 conversion factors; function returns array of
538 elevator deflections (deArray) and corresponding
539 alpha (aArray) and delta CZ (CZArray) values and
540 max number of terms in alpha arrays (nAlphaArray)
541 and delfection array (nde) */
542 uiuc_2DdataFileReader(CXfabetaf_file,
548 d_2_to_3(datafile_xArray, CXfabetaf_aArray, CXfabetaf_index);
549 d_1_to_2(datafile_yArray, CXfabetaf_betaArray, CXfabetaf_index);
550 d_2_to_3(datafile_zArray, CXfabetaf_CXArray, CXfabetaf_index);
551 i_1_to_2(datafile_nxArray, CXfabetaf_nAlphaArray, CXfabetaf_index);
552 CXfabetaf_nbeta[CXfabetaf_index] = datafile_ny;
553 if (CXfabetaf_first==true)
555 if (CXfabetaf_nice == 1)
557 CXfabetaf_na_nice = datafile_nxArray[1];
558 CXfabetaf_nb_nice = datafile_ny;
559 d_1_to_1(datafile_yArray, CXfabetaf_bArray_nice);
560 for (i=1; i<=CXfabetaf_na_nice; i++)
561 CXfabetaf_aArray_nice[i] = datafile_xArray[1][i];
563 aeroDragParts -> storeCommands (*command_line);
564 CXfabetaf_first=false;
570 int CXfadef_index, i;
573 CXfadef_file = aircraft_directory + linetoken3;
574 token4 >> CXfadef_index;
575 if (CXfadef_index < 0 || CXfadef_index >= 30)
576 uiuc_warnings_errors(1, *command_line);
577 if (CXfadef_index > CXfadef_nf)
578 CXfadef_nf = CXfadef_index;
579 token5 >> flap_value;
580 token6 >> token_value_convert1;
581 token7 >> token_value_convert2;
582 token8 >> token_value_convert3;
583 token9 >> token_value_convert4;
584 token10 >> CXfadef_nice;
585 convert_z = uiuc_convert(token_value_convert1);
586 convert_x = uiuc_convert(token_value_convert2);
587 convert_y = uiuc_convert(token_value_convert3);
588 convert_f = uiuc_convert(token_value_convert4);
589 CXfadef_fArray[CXfadef_index] = flap_value * convert_f;
590 /* call 2D File Reader with file name (CXfadef_file) and
591 conversion factors; function returns array of
592 elevator deflections (deArray) and corresponding
593 alpha (aArray) and delta CZ (CZArray) values and
594 max number of terms in alpha arrays (nAlphaArray)
595 and delfection array (nde) */
596 uiuc_2DdataFileReader(CXfadef_file,
602 d_2_to_3(datafile_xArray, CXfadef_aArray, CXfadef_index);
603 d_1_to_2(datafile_yArray, CXfadef_deArray, CXfadef_index);
604 d_2_to_3(datafile_zArray, CXfadef_CXArray, CXfadef_index);
605 i_1_to_2(datafile_nxArray, CXfadef_nAlphaArray, CXfadef_index);
606 CXfadef_nde[CXfadef_index] = datafile_ny;
607 if (CXfadef_first==true)
609 if (CXfadef_nice == 1)
611 CXfadef_na_nice = datafile_nxArray[1];
612 CXfadef_nde_nice = datafile_ny;
613 d_1_to_1(datafile_yArray, CXfadef_deArray_nice);
614 for (i=1; i<=CXfadef_na_nice; i++)
615 CXfadef_aArray_nice[i] = datafile_xArray[1][i];
617 aeroDragParts -> storeCommands (*command_line);
627 CXfaqf_file = aircraft_directory + linetoken3;
628 token4 >> CXfaqf_index;
629 if (CXfaqf_index < 0 || CXfaqf_index >= 30)
630 uiuc_warnings_errors(1, *command_line);
631 if (CXfaqf_index > CXfaqf_nf)
632 CXfaqf_nf = CXfaqf_index;
633 token5 >> flap_value;
634 token6 >> token_value_convert1;
635 token7 >> token_value_convert2;
636 token8 >> token_value_convert3;
637 token9 >> token_value_convert4;
638 token10 >> CXfaqf_nice;
639 convert_z = uiuc_convert(token_value_convert1);
640 convert_x = uiuc_convert(token_value_convert2);
641 convert_y = uiuc_convert(token_value_convert3);
642 convert_f = uiuc_convert(token_value_convert4);
643 CXfaqf_fArray[CXfaqf_index] = flap_value * convert_f;
644 /* call 2D File Reader with file name (CXfaqf_file) and
645 conversion factors; function returns array of
646 elevator deflections (deArray) and corresponding
647 alpha (aArray) and delta CZ (CZArray) values and
648 max number of terms in alpha arrays (nAlphaArray)
649 and delfection array (nde) */
650 uiuc_2DdataFileReader(CXfaqf_file,
656 d_2_to_3(datafile_xArray, CXfaqf_aArray, CXfaqf_index);
657 d_1_to_2(datafile_yArray, CXfaqf_qArray, CXfaqf_index);
658 d_2_to_3(datafile_zArray, CXfaqf_CXArray, CXfaqf_index);
659 i_1_to_2(datafile_nxArray, CXfaqf_nAlphaArray, CXfaqf_index);
660 CXfaqf_nq[CXfaqf_index] = datafile_ny;
661 if (CXfaqf_first==true)
663 if (CXfaqf_nice == 1)
665 CXfaqf_na_nice = datafile_nxArray[1];
666 CXfaqf_nq_nice = datafile_ny;
667 d_1_to_1(datafile_yArray, CXfaqf_qArray_nice);
668 for (i=1; i<=CXfaqf_na_nice; i++)
669 CXfaqf_aArray_nice[i] = datafile_xArray[1][i];
671 aeroDragParts -> storeCommands (*command_line);
678 if (ignore_unknown_keywords) {
681 // print error message
682 uiuc_warnings_errors(2, *command_line);