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
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_Cm.h"
93 void parse_Cm( 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 Cmfabetaf_first = true;
116 static bool Cmfadef_first = true;
117 static bool Cmfaqf_first = true;
119 switch(Cm_map[linetoken2])
123 if (check_float(linetoken3))
124 token3 >> token_value;
126 uiuc_warnings_errors(1, *command_line);
130 aeroPitchParts -> storeCommands (*command_line);
135 if (check_float(linetoken3))
136 token3 >> token_value;
138 uiuc_warnings_errors(1, *command_line);
142 aeroPitchParts -> storeCommands (*command_line);
147 if (check_float(linetoken3))
148 token3 >> token_value;
150 uiuc_warnings_errors(1, *command_line);
154 aeroPitchParts -> storeCommands (*command_line);
159 if (check_float(linetoken3))
160 token3 >> token_value;
162 uiuc_warnings_errors(1, *command_line);
164 Cm_adot = token_value;
165 Cm_adot_clean = Cm_adot;
166 aeroPitchParts -> storeCommands (*command_line);
171 if (check_float(linetoken3))
172 token3 >> token_value;
174 uiuc_warnings_errors(1, *command_line);
178 aeroPitchParts -> storeCommands (*command_line);
183 if (check_float(linetoken3))
184 token3 >> token_value;
186 uiuc_warnings_errors(1, *command_line);
189 aeroPitchParts -> storeCommands (*command_line);
194 if (check_float(linetoken3))
195 token3 >> token_value;
197 uiuc_warnings_errors(1, *command_line);
201 aeroPitchParts -> storeCommands (*command_line);
206 if (check_float(linetoken3))
207 token3 >> token_value;
209 uiuc_warnings_errors(1, *command_line);
213 aeroPitchParts -> storeCommands (*command_line);
218 if (check_float(linetoken3))
219 token3 >> token_value;
221 uiuc_warnings_errors(1, *command_line);
225 aeroPitchParts -> storeCommands (*command_line);
230 if (check_float(linetoken3))
231 token3 >> token_value;
233 uiuc_warnings_errors(1, *command_line);
237 aeroPitchParts -> storeCommands (*command_line);
242 if (check_float(linetoken3))
243 token3 >> token_value;
245 uiuc_warnings_errors(1, *command_line);
248 aeroPitchParts -> storeCommands (*command_line);
253 if (check_float(linetoken3))
254 token3 >> token_value;
256 uiuc_warnings_errors(1, *command_line);
259 aeroPitchParts -> storeCommands (*command_line);
264 Cmfa = aircraft_directory + linetoken3;
265 token4 >> token_value_convert1;
266 token5 >> token_value_convert2;
267 convert_y = uiuc_convert(token_value_convert1);
268 convert_x = uiuc_convert(token_value_convert2);
269 /* call 1D File Reader with file name (Cmfa) and conversion
270 factors; function returns array of alphas (aArray) and
271 corresponding Cm values (CmArray) and max number of
272 terms in arrays (nAlpha) */
273 uiuc_1DdataFileReader(Cmfa,
277 aeroPitchParts -> storeCommands (*command_line);
282 Cmfade = aircraft_directory + linetoken3;
283 token4 >> token_value_convert1;
284 token5 >> token_value_convert2;
285 token6 >> token_value_convert3;
286 convert_z = uiuc_convert(token_value_convert1);
287 convert_x = uiuc_convert(token_value_convert2);
288 convert_y = uiuc_convert(token_value_convert3);
289 /* call 2D File Reader with file name (Cmfade) and
290 conversion factors; function returns array of
291 elevator deflections (deArray) and corresponding
292 alpha (aArray) and delta Cm (CmArray) values and
293 max number of terms in alpha arrays (nAlphaArray)
294 and deflection array (nde) */
295 uiuc_2DdataFileReader(Cmfade,
301 aeroPitchParts -> storeCommands (*command_line);
306 Cmfdf = aircraft_directory + linetoken3;
307 token4 >> token_value_convert1;
308 token5 >> token_value_convert2;
309 convert_y = uiuc_convert(token_value_convert1);
310 convert_x = uiuc_convert(token_value_convert2);
311 /* call 1D File Reader with file name (Cmfdf) and conversion
312 factors; function returns array of dfs (dfArray) and
313 corresponding Cm values (CmArray) and max number of
314 terms in arrays (ndf) */
315 uiuc_1DdataFileReader(Cmfdf,
319 aeroPitchParts -> storeCommands (*command_line);
324 Cmfadf = aircraft_directory + linetoken3;
325 token4 >> token_value_convert1;
326 token5 >> token_value_convert2;
327 token6 >> token_value_convert3;
328 convert_z = uiuc_convert(token_value_convert1);
329 convert_x = uiuc_convert(token_value_convert2);
330 convert_y = uiuc_convert(token_value_convert3);
331 /* call 2D File Reader with file name (Cmfadf) and
332 conversion factors; function returns array of
333 flap deflections (dfArray) and corresponding
334 alpha (aArray) and delta Cm (CmArray) values and
335 max number of terms in alpha arrays (nAlphaArray)
336 and deflection array (ndf) */
337 uiuc_2DdataFileReader(Cmfadf,
343 aeroPitchParts -> storeCommands (*command_line);
348 int Cmfabetaf_index, i;
349 string Cmfabetaf_file;
351 Cmfabetaf_file = aircraft_directory + linetoken3;
352 token4 >> Cmfabetaf_index;
353 if (Cmfabetaf_index < 0 || Cmfabetaf_index >= 30)
354 uiuc_warnings_errors(1, *command_line);
355 if (Cmfabetaf_index > Cmfabetaf_nf)
356 Cmfabetaf_nf = Cmfabetaf_index;
357 token5 >> flap_value;
358 token6 >> token_value_convert1;
359 token7 >> token_value_convert2;
360 token8 >> token_value_convert3;
361 token9 >> token_value_convert4;
362 token10 >> Cmfabetaf_nice;
363 convert_z = uiuc_convert(token_value_convert1);
364 convert_x = uiuc_convert(token_value_convert2);
365 convert_y = uiuc_convert(token_value_convert3);
366 convert_f = uiuc_convert(token_value_convert4);
367 Cmfabetaf_fArray[Cmfabetaf_index] = flap_value * convert_f;
368 /* call 2D File Reader with file name (Cmfabetaf_file) and
369 conversion factors; function returns array of
370 elevator deflections (deArray) and corresponding
371 alpha (aArray) and delta CZ (CZArray) values and
372 max number of terms in alpha arrays (nAlphaArray)
373 and delfection array (nde) */
374 uiuc_2DdataFileReader(Cmfabetaf_file,
380 d_2_to_3(datafile_xArray, Cmfabetaf_aArray, Cmfabetaf_index);
381 d_1_to_2(datafile_yArray, Cmfabetaf_betaArray, Cmfabetaf_index);
382 d_2_to_3(datafile_zArray, Cmfabetaf_CmArray, Cmfabetaf_index);
383 i_1_to_2(datafile_nxArray, Cmfabetaf_nAlphaArray, Cmfabetaf_index);
384 Cmfabetaf_nbeta[Cmfabetaf_index] = datafile_ny;
385 if (Cmfabetaf_first==true)
387 if (Cmfabetaf_nice == 1)
389 Cmfabetaf_na_nice = datafile_nxArray[1];
390 Cmfabetaf_nb_nice = datafile_ny;
391 d_1_to_1(datafile_yArray, Cmfabetaf_bArray_nice);
392 for (i=1; i<=Cmfabetaf_na_nice; i++)
393 Cmfabetaf_aArray_nice[i] = datafile_xArray[1][i];
395 aeroPitchParts -> storeCommands (*command_line);
396 Cmfabetaf_first=false;
402 int Cmfadef_index, i;
405 Cmfadef_file = aircraft_directory + linetoken3;
406 token4 >> Cmfadef_index;
407 if (Cmfadef_index < 0 || Cmfadef_index >= 30)
408 uiuc_warnings_errors(1, *command_line);
409 if (Cmfadef_index > Cmfadef_nf)
410 Cmfadef_nf = Cmfadef_index;
411 token5 >> flap_value;
412 token6 >> token_value_convert1;
413 token7 >> token_value_convert2;
414 token8 >> token_value_convert3;
415 token9 >> token_value_convert4;
416 token10 >> Cmfadef_nice;
417 convert_z = uiuc_convert(token_value_convert1);
418 convert_x = uiuc_convert(token_value_convert2);
419 convert_y = uiuc_convert(token_value_convert3);
420 convert_f = uiuc_convert(token_value_convert4);
421 Cmfadef_fArray[Cmfadef_index] = flap_value * convert_f;
422 /* call 2D File Reader with file name (Cmfadef_file) and
423 conversion factors; function returns array of
424 elevator deflections (deArray) and corresponding
425 alpha (aArray) and delta CZ (CZArray) values and
426 max number of terms in alpha arrays (nAlphaArray)
427 and delfection array (nde) */
428 uiuc_2DdataFileReader(Cmfadef_file,
434 d_2_to_3(datafile_xArray, Cmfadef_aArray, Cmfadef_index);
435 d_1_to_2(datafile_yArray, Cmfadef_deArray, Cmfadef_index);
436 d_2_to_3(datafile_zArray, Cmfadef_CmArray, Cmfadef_index);
437 i_1_to_2(datafile_nxArray, Cmfadef_nAlphaArray, Cmfadef_index);
438 Cmfadef_nde[Cmfadef_index] = datafile_ny;
439 if (Cmfadef_first==true)
441 if (Cmfadef_nice == 1)
443 Cmfadef_na_nice = datafile_nxArray[1];
444 Cmfadef_nde_nice = datafile_ny;
445 d_1_to_1(datafile_yArray, Cmfadef_deArray_nice);
446 for (i=1; i<=Cmfadef_na_nice; i++)
447 Cmfadef_aArray_nice[i] = datafile_xArray[1][i];
449 aeroPitchParts -> storeCommands (*command_line);
459 Cmfaqf_file = aircraft_directory + linetoken3;
460 token4 >> Cmfaqf_index;
461 if (Cmfaqf_index < 0 || Cmfaqf_index >= 30)
462 uiuc_warnings_errors(1, *command_line);
463 if (Cmfaqf_index > Cmfaqf_nf)
464 Cmfaqf_nf = Cmfaqf_index;
465 token5 >> flap_value;
466 token6 >> token_value_convert1;
467 token7 >> token_value_convert2;
468 token8 >> token_value_convert3;
469 token9 >> token_value_convert4;
470 token10 >> Cmfaqf_nice;
471 convert_z = uiuc_convert(token_value_convert1);
472 convert_x = uiuc_convert(token_value_convert2);
473 convert_y = uiuc_convert(token_value_convert3);
474 convert_f = uiuc_convert(token_value_convert4);
475 Cmfaqf_fArray[Cmfaqf_index] = flap_value * convert_f;
476 /* call 2D File Reader with file name (Cmfaqf_file) and
477 conversion factors; function returns array of
478 elevator deflections (deArray) and corresponding
479 alpha (aArray) and delta CZ (CZArray) values and
480 max number of terms in alpha arrays (nAlphaArray)
481 and delfection array (nde) */
482 uiuc_2DdataFileReader(Cmfaqf_file,
488 d_2_to_3(datafile_xArray, Cmfaqf_aArray, Cmfaqf_index);
489 d_1_to_2(datafile_yArray, Cmfaqf_qArray, Cmfaqf_index);
490 d_2_to_3(datafile_zArray, Cmfaqf_CmArray, Cmfaqf_index);
491 i_1_to_2(datafile_nxArray, Cmfaqf_nAlphaArray, Cmfaqf_index);
492 Cmfaqf_nq[Cmfaqf_index] = datafile_ny;
493 if (Cmfaqf_first==true)
495 if (Cmfaqf_nice == 1)
497 Cmfaqf_na_nice = datafile_nxArray[1];
498 Cmfaqf_nq_nice = datafile_ny;
499 d_1_to_1(datafile_yArray, Cmfaqf_qArray_nice);
500 for (i=1; i<=Cmfaqf_na_nice; i++)
501 Cmfaqf_aArray_nice[i] = datafile_xArray[1][i];
503 aeroPitchParts -> storeCommands (*command_line);
510 if (ignore_unknown_keywords) {
513 // print error message
514 uiuc_warnings_errors(2, *command_line);