Based on the original Rocket Workbench on SourceForge in CVS at: https://sourceforge.net/projects/rocketworkbench
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
3.2 KiB

  1. /* motor.l - Simulation of rocket flight */
  2. /* Copyright (C) 2000 */
  3. /* Antoine Lefebvre <antoine.lefebvre@polymtl.ca> */
  4. /* This program is free software; you can redistribute it and/or modify*/
  5. /* it under the terms of the GNU General Public License as published by*/
  6. /* the Free Software Foundation; either version 2 of the License, or */
  7. /* (at your option) any later version. */
  8. /* This program is distributed in the hope that it will be useful, */
  9. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  10. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  11. /* GNU General Public License for more details. */
  12. /* You should have received a copy of the GNU General Public License */
  13. /* along with this program; if not, write to the Free Software */
  14. /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. %{
  16. #define YY_DECL int motorscan(char *name, double *diameter, double *length, double *masse_totale, double *masse_poudre, double **thrust, int *ndata)
  17. double P[2][200];
  18. char bidon[32];
  19. int foo;
  20. int count;
  21. int i;
  22. int j;
  23. int tmp1, tmp2, tmp3;
  24. double dtmp1, dtmp2;
  25. %}
  26. %x body
  27. %%
  28. <*>#+.*\n ; /* elimination of the character #, \t, \n, space, ; */
  29. ^[ ]+ ;
  30. <*>^\t+ ;
  31. <*>\n ;
  32. <INITIAL>";"+.*\n ;
  33. 01.*[ ].* {
  34. sscanf(yytext, "%s%s%s", bidon, bidon, name);
  35. /*printf("%s\n", name);*/
  36. count = 0;
  37. }
  38. 07.*[ ].* {
  39. sscanf(yytext, "%s%s%lf", bidon, bidon, &dtmp1);
  40. diameter[0] = dtmp1*2.54/100;
  41. /*printf("%f\n", diameter[0]);*/
  42. }
  43. 08.*[ ].*[ ].* {
  44. sscanf(yytext, "%s%s%s%lf", bidon, bidon, bidon, &dtmp1);
  45. length[0] = dtmp1*2.54/100;
  46. /*printf("%f\n", length[0]);*/
  47. }
  48. 11.*[ ].*[ ].*[ ].* {
  49. sscanf(yytext, "%s%s%s%s%lf", bidon, bidon, bidon, bidon, &dtmp1);
  50. masse_poudre[0] = dtmp1/1000;
  51. /*printf("%f\n", masse_poudre[0]);*/
  52. }
  53. 12.*[ ].*[ ].*[ ].* {
  54. sscanf(yytext, "%s%s%s%s%lf", bidon, bidon, bidon, bidon, &dtmp1);
  55. masse_totale[0] = dtmp1/1000;
  56. /*printf("%f\n", masse_totale[0]);*/
  57. }
  58. 20.*[ ].*[ ].*[ ].* {
  59. sscanf(yytext, "%s%s%s%lf%lf", bidon, bidon, bidon, &P[0][count], &P[1][count]);
  60. count++;
  61. }
  62. 64.* {
  63. // allocate the memory
  64. thrust[0] = new double[count];
  65. thrust[1] = new double[count];
  66. ndata[0] = count;
  67. for (j = 0; j < count; j++)
  68. {
  69. thrust[0][j] = P[0][j];
  70. thrust[1][j] = P[1][j] * 4.448221615; //1lb X 9.80665 X 0.45359237 kg/lb
  71. }
  72. }
  73. [0-9]{2}.*[ ].* { /*garbage all other data*/
  74. }
  75. [A-Z0-9]+[ ]*[0-9]+[ ]*[0-9]+[ ]*[0-9]+[ ]*[0-9]+"."[0-9]+[ ]*[0-9]+"."[0-9]+[ ]*[A-Z0-9]+[ ]* {
  76. sscanf(yytext, "%s%d%d%d%lf%lf%s", name, &tmp1, &tmp2, &foo, masse_poudre, masse_totale, bidon);
  77. diameter[0] = (double)tmp1/1000;
  78. length[0] = (double)tmp2/1000;
  79. count = 0;
  80. BEGIN(body);
  81. }
  82. <body>[0-9]+"."[0-9]+[ ]*[0-9]+"."[0-9]+[ ]* {
  83. sscanf(yytext, "%lf%lf", &P[0][count], &P[1][count]);
  84. count++;
  85. }
  86. <body>";"+.*\n {
  87. thrust[0] = new double[count];
  88. thrust[1] = new double[count];
  89. ndata[0] = count;
  90. for (i = 0; i < 2; i++)
  91. for (j = 0; j < count; j++)
  92. thrust[i][j] = P[i][j];
  93. BEGIN(INITIAL);
  94. }
  95. %%
  96. int yywrap()
  97. {
  98. return 1;
  99. }