]> git.mxchange.org Git - flightgear.git/blobdiff - LaRCsim/atmos_62.c
Attempting to iron out seg faults and crashes.
[flightgear.git] / LaRCsim / atmos_62.c
index f0ec1ab150345fec22d37ac2427a6624027c37fb..f2863a82a009fddfcdce76f73053b35f7e686528 100644 (file)
@@ -59,6 +59,9 @@
 
 #include "ls_types.h"
 #include "ls_constants.h"
+
+#include "atmos_62.h"
+
 #include <math.h>
 
 #define        alt_0   d_a_table[index  ][0]
@@ -210,8 +213,19 @@ void ls_atmos( SCALAR altitude, SCALAR * sigma, SCALAR * v_sound,
        { 238000.,       1.18020E-07,    9.52550E+02,    2.29613E-16,   -1.45786E-08    },
        { 240000.,       1.08270E-07,    9.47120E+02,    0.00000E+00,    0.00000E+00    }
     };
-    
-    index = altitude / 2000;
+
+    /* for purposes of doing the table lookup, force the incoming
+       altitude to be >= 0 */
+
+    // printf("altitude = %.2f\n", altitude);
+
+    if ( altitude < 0.0 ) {
+       altitude = 0.0;
+    }
+
+    // printf("altitude = %.2f\n", altitude);
+
+    index = (int)( altitude / 2000 );
     if (index > (MAX_ALT_INDEX-2))
     {
      index = MAX_ALT_INDEX-2; /* limit maximum altitude */
@@ -236,6 +250,7 @@ void ls_atmos( SCALAR altitude, SCALAR * sigma, SCALAR * v_sound,
     if (altitude < HLEV)    /* BUG - these curve fits are only good to about 75000 ft */
       {
        t_amb_r = 1. - 6.875e-6*altitude;
+       // printf("index = %d  t_amb_r = %.2f\n", index, t_amb_r);
        p_amb_r = pow( t_amb_r, 5.256 );
       }
     else