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>
80 #include "uiuc_menu_CD.h"
90 void parse_CD( 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 CXfabetaf_first = true;
113 static bool CXfadef_first = true;
114 static bool CXfaqf_first = true;
116 switch(CD_map[linetoken2])
120 if (check_float(linetoken3))
121 token3 >> token_value;
123 uiuc_warnings_errors(1, *command_line);
127 aeroDragParts -> storeCommands (*command_line);
132 if (check_float(linetoken3))
133 token3 >> token_value;
135 uiuc_warnings_errors(1, *command_line);
139 aeroDragParts -> storeCommands (*command_line);
145 if (check_float(linetoken3))
146 token3 >> token_value;
148 uiuc_warnings_errors(1, *command_line);
154 if (check_float(linetoken3))
155 token3 >> token_value;
157 uiuc_warnings_errors(1, *command_line);
161 aeroDragParts -> storeCommands (*command_line);
166 if (check_float(linetoken3))
167 token3 >> token_value;
169 uiuc_warnings_errors(1, *command_line);
171 CD_adot = token_value;
172 CD_adot_clean = CD_adot;
173 aeroDragParts -> storeCommands (*command_line);
178 if (check_float(linetoken3))
179 token3 >> token_value;
181 uiuc_warnings_errors(1, *command_line);
185 aeroDragParts -> storeCommands (*command_line);
190 if (check_float(linetoken3))
191 token3 >> token_value;
193 uiuc_warnings_errors(1, *command_line);
196 aeroDragParts -> storeCommands (*command_line);
201 if (check_float(linetoken3))
202 token3 >> token_value;
204 uiuc_warnings_errors(1, *command_line);
208 aeroDragParts -> storeCommands (*command_line);
213 if (check_float(linetoken3))
214 token3 >> token_value;
216 uiuc_warnings_errors(1, *command_line);
219 aeroDragParts -> storeCommands (*command_line);
224 if (check_float(linetoken3))
225 token3 >> token_value;
227 uiuc_warnings_errors(1, *command_line);
230 aeroDragParts -> storeCommands (*command_line);
235 if (check_float(linetoken3))
236 token3 >> token_value;
238 uiuc_warnings_errors(1, *command_line);
240 CD_beta = token_value;
241 aeroDragParts -> storeCommands (*command_line);
246 if (check_float(linetoken3))
247 token3 >> token_value;
249 uiuc_warnings_errors(1, *command_line);
252 aeroDragParts -> storeCommands (*command_line);
257 if (check_float(linetoken3))
258 token3 >> token_value;
260 uiuc_warnings_errors(1, *command_line);
263 aeroDragParts -> storeCommands (*command_line);
268 if (check_float(linetoken3))
269 token3 >> token_value;
271 uiuc_warnings_errors(1, *command_line);
274 aeroDragParts -> storeCommands (*command_line);
279 CDfa = aircraft_directory + linetoken3;
280 token4 >> token_value_convert1;
281 token5 >> token_value_convert2;
282 convert_y = uiuc_convert(token_value_convert1);
283 convert_x = uiuc_convert(token_value_convert2);
284 /* call 1D File Reader with file name (CDfa) and conversion
285 factors; function returns array of alphas (aArray) and
286 corresponding CD values (CDArray) and max number of
287 terms in arrays (nAlpha) */
288 uiuc_1DdataFileReader(CDfa,
292 aeroDragParts -> storeCommands (*command_line);
297 CDfCL = aircraft_directory + linetoken3;
298 token4 >> token_value_convert1;
299 token5 >> token_value_convert2;
300 convert_y = uiuc_convert(token_value_convert1);
301 convert_x = uiuc_convert(token_value_convert2);
302 /* call 1D File Reader with file name (CDfCL) and conversion
303 factors; function returns array of CLs (CLArray) and
304 corresponding CD values (CDArray) and max number of
305 terms in arrays (nCL) */
306 uiuc_1DdataFileReader(CDfCL,
310 aeroDragParts -> storeCommands (*command_line);
315 CDfade = aircraft_directory + linetoken3;
316 token4 >> token_value_convert1;
317 token5 >> token_value_convert2;
318 token6 >> token_value_convert3;
319 convert_z = uiuc_convert(token_value_convert1);
320 convert_x = uiuc_convert(token_value_convert2);
321 convert_y = uiuc_convert(token_value_convert3);
322 /* call 2D File Reader with file name (CDfade) and
323 conversion factors; function returns array of
324 elevator deflections (deArray) and corresponding
325 alpha (aArray) and delta CD (CDArray) values and
326 max number of terms in alpha arrays (nAlphaArray)
327 and deflection array (nde) */
328 uiuc_2DdataFileReader(CDfade,
334 aeroDragParts -> storeCommands (*command_line);
339 CDfdf = aircraft_directory + linetoken3;
340 token4 >> token_value_convert1;
341 token5 >> token_value_convert2;
342 convert_y = uiuc_convert(token_value_convert1);
343 convert_x = uiuc_convert(token_value_convert2);
344 /* call 1D File Reader with file name (CDfdf) and conversion
345 factors; function returns array of dfs (dfArray) and
346 corresponding CD values (CDArray) and max number of
347 terms in arrays (ndf) */
348 uiuc_1DdataFileReader(CDfdf,
352 aeroDragParts -> storeCommands (*command_line);
357 CDfadf = aircraft_directory + linetoken3;
358 token4 >> token_value_convert1;
359 token5 >> token_value_convert2;
360 token6 >> token_value_convert3;
361 convert_z = uiuc_convert(token_value_convert1);
362 convert_x = uiuc_convert(token_value_convert2);
363 convert_y = uiuc_convert(token_value_convert3);
364 /* call 2D File Reader with file name (CDfadf) and
365 conversion factors; function returns array of
366 flap deflections (dfArray) and corresponding
367 alpha (aArray) and delta CD (CDArray) values and
368 max number of terms in alpha arrays (nAlphaArray)
369 and deflection array (ndf) */
370 uiuc_2DdataFileReader(CDfadf,
376 aeroDragParts -> storeCommands (*command_line);
381 if (check_float(linetoken3))
382 token3 >> token_value;
384 uiuc_warnings_errors(1, *command_line);
388 aeroDragParts -> storeCommands (*command_line);
393 if (check_float(linetoken3))
394 token3 >> token_value;
396 uiuc_warnings_errors(1, *command_line);
400 aeroDragParts -> storeCommands (*command_line);
405 if (check_float(linetoken3))
406 token3 >> token_value;
408 uiuc_warnings_errors(1, *command_line);
412 aeroDragParts -> storeCommands (*command_line);
417 if (check_float(linetoken3))
418 token3 >> token_value;
420 uiuc_warnings_errors(1, *command_line);
424 aeroDragParts -> storeCommands (*command_line);
429 if (check_float(linetoken3))
430 token3 >> token_value;
432 uiuc_warnings_errors(1, *command_line);
436 aeroDragParts -> storeCommands (*command_line);
441 if (check_float(linetoken3))
442 token3 >> token_value;
444 uiuc_warnings_errors(1, *command_line);
446 CX_adot = token_value;
447 CX_adot_clean = CX_adot;
448 aeroDragParts -> storeCommands (*command_line);
453 if (check_float(linetoken3))
454 token3 >> token_value;
456 uiuc_warnings_errors(1, *command_line);
460 aeroDragParts -> storeCommands (*command_line);
465 if (check_float(linetoken3))
466 token3 >> token_value;
468 uiuc_warnings_errors(1, *command_line);
472 aeroDragParts -> storeCommands (*command_line);
477 if (check_float(linetoken3))
478 token3 >> token_value;
480 uiuc_warnings_errors(1, *command_line);
484 aeroDragParts -> storeCommands (*command_line);
489 if (check_float(linetoken3))
490 token3 >> token_value;
492 uiuc_warnings_errors(1, *command_line);
496 aeroDragParts -> storeCommands (*command_line);
501 if (check_float(linetoken3))
502 token3 >> token_value;
504 uiuc_warnings_errors(1, *command_line);
506 CX_adf = token_value;
507 CX_adf_clean = CX_adf;
508 aeroDragParts -> storeCommands (*command_line);
513 int CXfabetaf_index, i;
514 string CXfabetaf_file;
516 CXfabetaf_file = aircraft_directory + linetoken3;
517 token4 >> CXfabetaf_index;
518 if (CXfabetaf_index < 1 || CXfabetaf_index >= 30)
519 uiuc_warnings_errors(1, *command_line);
520 if (CXfabetaf_index > CXfabetaf_nf)
521 CXfabetaf_nf = CXfabetaf_index;
522 token5 >> flap_value;
523 token6 >> token_value_convert1;
524 token7 >> token_value_convert2;
525 token8 >> token_value_convert3;
526 token9 >> token_value_convert4;
527 token10 >> CXfabetaf_nice;
528 convert_z = uiuc_convert(token_value_convert1);
529 convert_x = uiuc_convert(token_value_convert2);
530 convert_y = uiuc_convert(token_value_convert3);
531 convert_f = uiuc_convert(token_value_convert4);
532 CXfabetaf_fArray[CXfabetaf_index] = flap_value * convert_f;
533 /* call 2D File Reader with file name (CXfabetaf_file) and
534 conversion factors; function returns array of
535 elevator deflections (deArray) and corresponding
536 alpha (aArray) and delta CZ (CZArray) values and
537 max number of terms in alpha arrays (nAlphaArray)
538 and delfection array (nde) */
539 uiuc_2DdataFileReader(CXfabetaf_file,
545 d_2_to_3(datafile_xArray, CXfabetaf_aArray, CXfabetaf_index);
546 d_1_to_2(datafile_yArray, CXfabetaf_betaArray, CXfabetaf_index);
547 d_2_to_3(datafile_zArray, CXfabetaf_CXArray, CXfabetaf_index);
548 i_1_to_2(datafile_nxArray, CXfabetaf_nAlphaArray, CXfabetaf_index);
549 CXfabetaf_nbeta[CXfabetaf_index] = datafile_ny;
550 if (CXfabetaf_first==true)
552 if (CXfabetaf_nice == 1)
554 CXfabetaf_na_nice = datafile_nxArray[1];
555 CXfabetaf_nb_nice = datafile_ny;
556 d_1_to_1(datafile_yArray, CXfabetaf_bArray_nice);
557 for (i=1; i<=CXfabetaf_na_nice; i++)
558 CXfabetaf_aArray_nice[i] = datafile_xArray[1][i];
560 aeroDragParts -> storeCommands (*command_line);
561 CXfabetaf_first=false;
567 int CXfadef_index, i;
570 CXfadef_file = aircraft_directory + linetoken3;
571 token4 >> CXfadef_index;
572 if (CXfadef_index < 0 || CXfadef_index >= 30)
573 uiuc_warnings_errors(1, *command_line);
574 if (CXfadef_index > CXfadef_nf)
575 CXfadef_nf = CXfadef_index;
576 token5 >> flap_value;
577 token6 >> token_value_convert1;
578 token7 >> token_value_convert2;
579 token8 >> token_value_convert3;
580 token9 >> token_value_convert4;
581 token10 >> CXfadef_nice;
582 convert_z = uiuc_convert(token_value_convert1);
583 convert_x = uiuc_convert(token_value_convert2);
584 convert_y = uiuc_convert(token_value_convert3);
585 convert_f = uiuc_convert(token_value_convert4);
586 CXfadef_fArray[CXfadef_index] = flap_value * convert_f;
587 /* call 2D File Reader with file name (CXfadef_file) and
588 conversion factors; function returns array of
589 elevator deflections (deArray) and corresponding
590 alpha (aArray) and delta CZ (CZArray) values and
591 max number of terms in alpha arrays (nAlphaArray)
592 and delfection array (nde) */
593 uiuc_2DdataFileReader(CXfadef_file,
599 d_2_to_3(datafile_xArray, CXfadef_aArray, CXfadef_index);
600 d_1_to_2(datafile_yArray, CXfadef_deArray, CXfadef_index);
601 d_2_to_3(datafile_zArray, CXfadef_CXArray, CXfadef_index);
602 i_1_to_2(datafile_nxArray, CXfadef_nAlphaArray, CXfadef_index);
603 CXfadef_nde[CXfadef_index] = datafile_ny;
604 if (CXfadef_first==true)
606 if (CXfadef_nice == 1)
608 CXfadef_na_nice = datafile_nxArray[1];
609 CXfadef_nde_nice = datafile_ny;
610 d_1_to_1(datafile_yArray, CXfadef_deArray_nice);
611 for (i=1; i<=CXfadef_na_nice; i++)
612 CXfadef_aArray_nice[i] = datafile_xArray[1][i];
614 aeroDragParts -> storeCommands (*command_line);
624 CXfaqf_file = aircraft_directory + linetoken3;
625 token4 >> CXfaqf_index;
626 if (CXfaqf_index < 0 || CXfaqf_index >= 30)
627 uiuc_warnings_errors(1, *command_line);
628 if (CXfaqf_index > CXfaqf_nf)
629 CXfaqf_nf = CXfaqf_index;
630 token5 >> flap_value;
631 token6 >> token_value_convert1;
632 token7 >> token_value_convert2;
633 token8 >> token_value_convert3;
634 token9 >> token_value_convert4;
635 token10 >> CXfaqf_nice;
636 convert_z = uiuc_convert(token_value_convert1);
637 convert_x = uiuc_convert(token_value_convert2);
638 convert_y = uiuc_convert(token_value_convert3);
639 convert_f = uiuc_convert(token_value_convert4);
640 CXfaqf_fArray[CXfaqf_index] = flap_value * convert_f;
641 /* call 2D File Reader with file name (CXfaqf_file) and
642 conversion factors; function returns array of
643 elevator deflections (deArray) and corresponding
644 alpha (aArray) and delta CZ (CZArray) values and
645 max number of terms in alpha arrays (nAlphaArray)
646 and delfection array (nde) */
647 uiuc_2DdataFileReader(CXfaqf_file,
653 d_2_to_3(datafile_xArray, CXfaqf_aArray, CXfaqf_index);
654 d_1_to_2(datafile_yArray, CXfaqf_qArray, CXfaqf_index);
655 d_2_to_3(datafile_zArray, CXfaqf_CXArray, CXfaqf_index);
656 i_1_to_2(datafile_nxArray, CXfaqf_nAlphaArray, CXfaqf_index);
657 CXfaqf_nq[CXfaqf_index] = datafile_ny;
658 if (CXfaqf_first==true)
660 if (CXfaqf_nice == 1)
662 CXfaqf_na_nice = datafile_nxArray[1];
663 CXfaqf_nq_nice = datafile_ny;
664 d_1_to_1(datafile_yArray, CXfaqf_qArray_nice);
665 for (i=1; i<=CXfaqf_na_nice; i++)
666 CXfaqf_aArray_nice[i] = datafile_xArray[1][i];
668 aeroDragParts -> storeCommands (*command_line);
675 if (ignore_unknown_keywords) {
678 // print error message
679 uiuc_warnings_errors(2, *command_line);