| 1 | /********************************************************************** |
| 2 | |
| 3 | FILENAME: uiuc_menu.cpp |
| 4 | |
| 5 | ---------------------------------------------------------------------- |
| 6 | |
| 7 | DESCRIPTION: reads input file for specified aircraft and creates |
| 8 | approporiate data storage space |
| 9 | |
| 10 | ---------------------------------------------------------------------- |
| 11 | |
| 12 | STATUS: alpha version |
| 13 | |
| 14 | ---------------------------------------------------------------------- |
| 15 | |
| 16 | REFERENCES: based on "menu reader" format of Michael Selig |
| 17 | |
| 18 | ---------------------------------------------------------------------- |
| 19 | |
| 20 | HISTORY: 01/29/2000 initial release |
| 21 | 02/18/2000 (JS) added 1D data file capability for |
| 22 | CL(a) and CD(a) -- calls |
| 23 | uiuc_1DdataFileReader |
| 24 | 02/22/2000 (JS) added ice map functions |
| 25 | 02/29/2000 (JS) added 2D data file capability for |
| 26 | CL(a,de), CD(a,de), Cm(a,de), CY(a,da), |
| 27 | CY(beta,dr), Cl(a,da), Cl(beta,dr), |
| 28 | Cn(a,da), Cn(beta,dr) -- calls |
| 29 | uiuc_2DdataFileReader |
| 30 | 02/02/2000 (JS) added record options for 1D and |
| 31 | 2D interpolated variables |
| 32 | 03/28/2000 (JS) streamlined conversion factors for |
| 33 | file readers -- since they are global |
| 34 | variables, it is not necessary to put |
| 35 | them in the function calls |
| 36 | 03/29/2000 (JS) added Cmfa and Weight flags; |
| 37 | added misc map; added Dx_cg (etc) to init |
| 38 | map |
| 39 | 04/01/2000 (JS) added throttle, longitudinal, lateral, |
| 40 | and rudder inputs to record map |
| 41 | 04/05/2000 (JS) added Altitude to init and record |
| 42 | maps; added zero_Long_trim to |
| 43 | controlSurface map |
| 44 | 03/09/2001 (DPM) added support for gear. |
| 45 | 06/18/2001 (RD) Added Alpha, Beta, U_body, |
| 46 | V_body, and W_body to init map. Added |
| 47 | aileron_input, rudder_input, pilot_elev_no, |
| 48 | pilot_ail_no, and pilot_rud_no to |
| 49 | controlSurface map. Added Throttle_pct_input |
| 50 | to engine map. Added CZfa to CL map. |
| 51 | 07/05/2001 (RD) Changed pilot_elev_no = true to pilot_ |
| 52 | elev_no_check=false. This is to allow pilot |
| 53 | to fly aircraft after input files have been |
| 54 | used. |
| 55 | 08/27/2001 (RD) Added xxx_init_true and xxx_init for |
| 56 | P_body, Q_body, R_body, Phi, Theta, Psi, |
| 57 | U_body, V_body, and W_body to help in |
| 58 | starting the A/C at an initial condition. |
| 59 | 10/25/2001 (RD) Added new variables needed for the non- |
| 60 | linear Twin Otter model at zero flaps |
| 61 | (Cxfxxf0) |
| 62 | 11/12/2001 (RD) Added new variables needed for the non- |
| 63 | linear Twin Otter model with flaps |
| 64 | (Cxfxxf). Removed zero flap variables. |
| 65 | Added minmaxfind() which is needed for non- |
| 66 | linear variables |
| 67 | 01/11/2002 (AP) Added keywords for bootTime |
| 68 | 02/13/2002 (RD) Added variables so linear aero model |
| 69 | values can be recorded |
| 70 | 02/18/2002 (RD) Added variables necessary to use the |
| 71 | uiuc_3Dinterp_quick() function. Takes |
| 72 | advantage of data in a "nice" form (data |
| 73 | that are in a rectangular matrix). |
| 74 | 03/13/2002 (RD) Added aircraft_directory so full path |
| 75 | is no longer needed in the aircraft.dat file |
| 76 | 04/02/2002 (RD) Removed minmaxfind() since it was no |
| 77 | longer needed. Added d_2_to_3(), |
| 78 | d_1_to_2(), and i_1_to_2() so uiuc_menu() |
| 79 | will compile with certain compilers. |
| 80 | 08/29/2002 (RD) Separated each primary keyword into its |
| 81 | own function to speed up compile time |
| 82 | 08/29/2002 (RD w/ help from CO) Made changes to shorten |
| 83 | compile time. [] RD to add more comments here. |
| 84 | 08/29/2003 (MSS) Adding new keywords for new engine model |
| 85 | and slipstream effects on tail. |
| 86 | 03/02/2003 (RD) Changed Cxfxxf areas so that there is a |
| 87 | conversion factor for flap angle |
| 88 | 03/03/2003 (RD) Added flap_cmd_record |
| 89 | 03/16/2003 (RD) Added trigger record flags |
| 90 | 04/02/2003 (RD) Tokens are now equal to 0 when no value |
| 91 | is given in the input file |
| 92 | 04/04/2003 (RD) To speed up compile time on this file, |
| 93 | each first level token now goes to its |
| 94 | own file uiuc_menu_*.cpp |
| 95 | |
| 96 | ---------------------------------------------------------------------- |
| 97 | |
| 98 | AUTHOR(S): Bipin Sehgal <[email protected]> |
| 99 | Jeff Scott http://www.jeffscott.net/ |
| 100 | Robert Deters <[email protected]> |
| 101 | Michael Selig <[email protected]> |
| 102 | David Megginson <[email protected]> |
| 103 | Ann Peedikayil <[email protected]> |
| 104 | ---------------------------------------------------------------------- |
| 105 | |
| 106 | VARIABLES: |
| 107 | |
| 108 | ---------------------------------------------------------------------- |
| 109 | |
| 110 | INPUTS: n/a |
| 111 | |
| 112 | ---------------------------------------------------------------------- |
| 113 | |
| 114 | OUTPUTS: n/a |
| 115 | |
| 116 | ---------------------------------------------------------------------- |
| 117 | |
| 118 | CALLED BY: uiuc_wrapper.cpp |
| 119 | |
| 120 | ---------------------------------------------------------------------- |
| 121 | |
| 122 | CALLS TO: aircraft.dat |
| 123 | tabulated data files (if needed) |
| 124 | uiuc_menu_init() |
| 125 | uiuc_menu_geometry() |
| 126 | uiuc_menu_mass() |
| 127 | uiuc_menu_controlSurface() |
| 128 | uiuc_menu_CD() |
| 129 | uiuc_menu_CL() |
| 130 | uiuc_menu_Cm() |
| 131 | uiuc_menu_CY() |
| 132 | uiuc_menu_Cl() |
| 133 | uiuc_menu_Cn() |
| 134 | uiuc_menu_ice() |
| 135 | uiuc_menu_engine() |
| 136 | uiuc_menu_fog() |
| 137 | uiuc_menu_gear() |
| 138 | uiuc_menu_record() |
| 139 | uiuc_menu_misc() |
| 140 | |
| 141 | ---------------------------------------------------------------------- |
| 142 | |
| 143 | COPYRIGHT: (C) 2000 by Michael Selig |
| 144 | |
| 145 | This program is free software; you can redistribute it and/or |
| 146 | modify it under the terms of the GNU General Public License |
| 147 | as published by the Free Software Foundation. |
| 148 | |
| 149 | This program is distributed in the hope that it will be useful, |
| 150 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 151 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 152 | GNU General Public License for more details. |
| 153 | |
| 154 | You should have received a copy of the GNU General Public License |
| 155 | along with this program; if not, write to the Free Software |
| 156 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 157 | |
| 158 | **********************************************************************/ |
| 159 | |
| 160 | #include <simgear/compiler.h> |
| 161 | |
| 162 | |
| 163 | #include <cstdlib> |
| 164 | #include <string> |
| 165 | #include <iostream> |
| 166 | |
| 167 | #include "uiuc_menu.h" |
| 168 | |
| 169 | using std::string; |
| 170 | using std::istringstream; |
| 171 | using std::cerr; |
| 172 | using std::cout; |
| 173 | using std::endl; |
| 174 | |
| 175 | #ifndef _MSC_VER |
| 176 | using std::exit; |
| 177 | #endif |
| 178 | |
| 179 | void uiuc_menu( string aircraft_name ) |
| 180 | { |
| 181 | string aircraft_directory; |
| 182 | stack command_list; |
| 183 | |
| 184 | string linetoken1; |
| 185 | string linetoken2; |
| 186 | string linetoken3; |
| 187 | string linetoken4; |
| 188 | string linetoken5; |
| 189 | string linetoken6; |
| 190 | string linetoken7; |
| 191 | string linetoken8; |
| 192 | string linetoken9; |
| 193 | string linetoken10; |
| 194 | |
| 195 | /* the following default setting should eventually be moved to a default or uiuc_init routine */ |
| 196 | |
| 197 | recordRate = 1; /* record every time step, default */ |
| 198 | recordStartTime = 0; /* record from beginning of simulation */ |
| 199 | |
| 200 | /* set speed at which dynamic pressure terms will be accounted for, |
| 201 | since if velocity is too small, coefficients will go to infinity */ |
| 202 | dyn_on_speed = 33; /* 20 kts (33 ft/sec), default */ |
| 203 | dyn_on_speed_zero = 0.5 * dyn_on_speed; /* only used if use_dyn_on_speed_curve1 is used */ |
| 204 | bootindex = 0; // the index for the bootTime |
| 205 | |
| 206 | /* Read the file and get the list of commands */ |
| 207 | airplane = new ParseFile(aircraft_name); /* struct that includes all lines of the input file */ |
| 208 | command_list = airplane -> getCommands(); |
| 209 | /* structs to include all parts included in the input file for specific keyword groups */ |
| 210 | initParts = new ParseFile(); |
| 211 | geometryParts = new ParseFile(); |
| 212 | massParts = new ParseFile(); |
| 213 | engineParts = new ParseFile(); |
| 214 | aeroDragParts = new ParseFile(); |
| 215 | aeroLiftParts = new ParseFile(); |
| 216 | aeroPitchParts = new ParseFile(); |
| 217 | aeroSideforceParts = new ParseFile(); |
| 218 | aeroRollParts = new ParseFile(); |
| 219 | aeroYawParts = new ParseFile(); |
| 220 | gearParts = new ParseFile(); |
| 221 | recordParts = new ParseFile(); |
| 222 | |
| 223 | if (command_list.begin() == command_list.end()) |
| 224 | { |
| 225 | cerr << "UIUC ERROR: File " << aircraft_name <<" does not exist" << endl; |
| 226 | exit(-1); |
| 227 | } |
| 228 | |
| 229 | //construct aircraft-directory |
| 230 | aircraft_directory = aircraft_name; |
| 231 | int index_aircraft_dat = aircraft_directory.find("aircraft.dat"); |
| 232 | aircraft_directory.erase(index_aircraft_dat,12); |
| 233 | |
| 234 | for (LIST command_line = command_list.begin(); command_line!=command_list.end(); ++command_line) |
| 235 | { |
| 236 | cout << *command_line << endl; |
| 237 | |
| 238 | linetoken1 = airplane -> getToken (*command_line, 1); |
| 239 | linetoken2 = airplane -> getToken (*command_line, 2); |
| 240 | if (linetoken2=="") |
| 241 | linetoken2="0"; |
| 242 | linetoken3 = airplane -> getToken (*command_line, 3); |
| 243 | if (linetoken3=="") |
| 244 | linetoken3="0"; |
| 245 | linetoken4 = airplane -> getToken (*command_line, 4); |
| 246 | if (linetoken4=="") |
| 247 | linetoken4="0"; |
| 248 | linetoken5 = airplane -> getToken (*command_line, 5); |
| 249 | if (linetoken5=="") |
| 250 | linetoken5="0"; |
| 251 | linetoken6 = airplane -> getToken (*command_line, 6); |
| 252 | if (linetoken6=="") |
| 253 | linetoken6="0"; |
| 254 | linetoken7 = airplane -> getToken (*command_line, 7); |
| 255 | if (linetoken7=="") |
| 256 | linetoken7="0"; |
| 257 | linetoken8 = airplane -> getToken (*command_line, 8); |
| 258 | if (linetoken8=="") |
| 259 | linetoken8="0"; |
| 260 | linetoken9 = airplane -> getToken (*command_line, 9); |
| 261 | if (linetoken9=="") |
| 262 | linetoken9="0"; |
| 263 | linetoken10 = airplane -> getToken (*command_line, 10); |
| 264 | if (linetoken10=="") |
| 265 | linetoken10="0"; |
| 266 | |
| 267 | //cout << linetoken1 << endl; |
| 268 | //cout << linetoken2 << endl; |
| 269 | //cout << linetoken3 << endl; |
| 270 | //cout << linetoken4 << endl; |
| 271 | //cout << linetoken5 << endl; |
| 272 | //cout << linetoken6 << endl; |
| 273 | //cout << linetoken7 << endl; |
| 274 | //cout << linetoken8 << endl; |
| 275 | //cout << linetoken9 << endl; |
| 276 | //cout << linetoken10 << endl; |
| 277 | |
| 278 | //istrstream token3(linetoken3.c_str()); |
| 279 | //istrstream token4(linetoken4.c_str()); |
| 280 | //istrstream token5(linetoken5.c_str()); |
| 281 | //istrstream token6(linetoken6.c_str()); |
| 282 | //istrstream token7(linetoken7.c_str()); |
| 283 | //istrstream token8(linetoken8.c_str()); |
| 284 | //istrstream token9(linetoken9.c_str()); |
| 285 | //istrstream token10(linetoken10.c_str()); |
| 286 | |
| 287 | switch (Keyword_map[linetoken1]) |
| 288 | { |
| 289 | case init_flag: |
| 290 | { |
| 291 | parse_init( linetoken2, linetoken3, linetoken4, |
| 292 | linetoken5, linetoken6, linetoken7, |
| 293 | linetoken8, linetoken9, linetoken10, |
| 294 | aircraft_directory, command_line ); |
| 295 | break; |
| 296 | } // end init map |
| 297 | |
| 298 | |
| 299 | case geometry_flag: |
| 300 | { |
| 301 | parse_geometry( linetoken2, linetoken3, linetoken4, |
| 302 | linetoken5, linetoken6, linetoken7, |
| 303 | linetoken8, linetoken9, linetoken10, |
| 304 | aircraft_directory, command_line ); |
| 305 | break; |
| 306 | } // end geometry map |
| 307 | |
| 308 | |
| 309 | case controlSurface_flag: |
| 310 | { |
| 311 | parse_controlSurface( linetoken2, linetoken3, linetoken4, |
| 312 | linetoken5, linetoken6, linetoken7, |
| 313 | linetoken8, linetoken9, linetoken10, |
| 314 | aircraft_directory, command_line ); |
| 315 | break; |
| 316 | } // end controlSurface map |
| 317 | |
| 318 | |
| 319 | case mass_flag: |
| 320 | { |
| 321 | parse_mass( linetoken2, linetoken3, linetoken4, |
| 322 | linetoken5, linetoken6, linetoken7, |
| 323 | linetoken8, linetoken9, linetoken10, |
| 324 | aircraft_directory, command_line ); |
| 325 | break; |
| 326 | } // end mass map |
| 327 | |
| 328 | |
| 329 | case engine_flag: |
| 330 | { |
| 331 | parse_engine( linetoken2, linetoken3, linetoken4, |
| 332 | linetoken5, linetoken6, linetoken7, |
| 333 | linetoken8, linetoken9, linetoken10, |
| 334 | aircraft_directory, command_line ); |
| 335 | break; |
| 336 | } // end engine map |
| 337 | |
| 338 | |
| 339 | case CD_flag: |
| 340 | { |
| 341 | parse_CD( linetoken2, linetoken3, linetoken4, |
| 342 | linetoken5, linetoken6, linetoken7, |
| 343 | linetoken8, linetoken9, linetoken10, |
| 344 | aircraft_directory, command_line ); |
| 345 | break; |
| 346 | } // end CD map |
| 347 | |
| 348 | |
| 349 | case CL_flag: |
| 350 | { |
| 351 | parse_CL( linetoken2, linetoken3, linetoken4, |
| 352 | linetoken5, linetoken6, linetoken7, |
| 353 | linetoken8, linetoken9, linetoken10, |
| 354 | aircraft_directory, command_line ); |
| 355 | break; |
| 356 | } // end CL map |
| 357 | |
| 358 | |
| 359 | case Cm_flag: |
| 360 | { |
| 361 | parse_Cm( linetoken2, linetoken3, linetoken4, |
| 362 | linetoken5, linetoken6, linetoken7, |
| 363 | linetoken8, linetoken9, linetoken10, |
| 364 | aircraft_directory, command_line ); |
| 365 | break; |
| 366 | } // end Cm map |
| 367 | |
| 368 | |
| 369 | case CY_flag: |
| 370 | { |
| 371 | parse_CY( linetoken2, linetoken3, linetoken4, |
| 372 | linetoken5, linetoken6, linetoken7, |
| 373 | linetoken8, linetoken9, linetoken10, |
| 374 | aircraft_directory, command_line ); |
| 375 | break; |
| 376 | } // end CY map |
| 377 | |
| 378 | |
| 379 | case Cl_flag: |
| 380 | { |
| 381 | parse_Cl( linetoken2, linetoken3, linetoken4, |
| 382 | linetoken5, linetoken6, linetoken7, |
| 383 | linetoken8, linetoken9, linetoken10, |
| 384 | aircraft_directory, command_line ); |
| 385 | break; |
| 386 | } // end Cl map |
| 387 | |
| 388 | |
| 389 | case Cn_flag: |
| 390 | { |
| 391 | parse_Cn( linetoken2, linetoken3, linetoken4, |
| 392 | linetoken5, linetoken6, linetoken7, |
| 393 | linetoken8, linetoken9, linetoken10, |
| 394 | aircraft_directory, command_line ); |
| 395 | break; |
| 396 | } // end Cn map |
| 397 | |
| 398 | |
| 399 | case gear_flag: |
| 400 | { |
| 401 | parse_gear( linetoken2, linetoken3, linetoken4, |
| 402 | linetoken5, linetoken6, linetoken7, |
| 403 | linetoken8, linetoken9, linetoken10, |
| 404 | aircraft_directory, command_line ); |
| 405 | break; |
| 406 | } // end gear map |
| 407 | |
| 408 | |
| 409 | case ice_flag: |
| 410 | { |
| 411 | parse_ice( linetoken2, linetoken3, linetoken4, |
| 412 | linetoken5, linetoken6, linetoken7, |
| 413 | linetoken8, linetoken9, linetoken10, |
| 414 | aircraft_directory, command_line ); |
| 415 | break; |
| 416 | } // end ice map |
| 417 | |
| 418 | |
| 419 | case fog_flag: |
| 420 | { |
| 421 | parse_fog( linetoken2, linetoken3, linetoken4, |
| 422 | linetoken5, linetoken6, linetoken7, |
| 423 | linetoken8, linetoken9, linetoken10, |
| 424 | aircraft_directory, command_line ); |
| 425 | break; |
| 426 | } // end fog map |
| 427 | |
| 428 | |
| 429 | case record_flag: |
| 430 | { |
| 431 | static int fout_flag=0; |
| 432 | if (fout_flag==0) |
| 433 | { |
| 434 | fout_flag=-1; |
| 435 | fout.open("uiuc_record.dat"); |
| 436 | } |
| 437 | parse_record( linetoken2, linetoken3, linetoken4, |
| 438 | linetoken5, linetoken6, linetoken7, |
| 439 | linetoken8, linetoken9, linetoken10, |
| 440 | aircraft_directory, command_line ); |
| 441 | break; |
| 442 | } // end record map |
| 443 | |
| 444 | |
| 445 | case misc_flag: |
| 446 | { |
| 447 | parse_misc( linetoken2, linetoken3, linetoken4, |
| 448 | linetoken5, linetoken6, linetoken7, |
| 449 | linetoken8, linetoken9, linetoken10, |
| 450 | aircraft_directory, command_line ); |
| 451 | break; |
| 452 | } // end misc map |
| 453 | |
| 454 | |
| 455 | default: |
| 456 | { |
| 457 | if (linetoken1=="*") |
| 458 | return; |
| 459 | if (ignore_unknown_keywords) { |
| 460 | // do nothing |
| 461 | } else { |
| 462 | // print error message |
| 463 | uiuc_warnings_errors(2, *command_line); |
| 464 | } |
| 465 | break; |
| 466 | } |
| 467 | }; |
| 468 | } // end keyword map |
| 469 | |
| 470 | delete airplane; |
| 471 | } |
| 472 | |
| 473 | // end menu.cpp |