changeset 695:5bf4f526f552

... minor cleanups ...
author JeanDo
date Wed, 13 Feb 2013 10:36:28 +0100
parents 59e5998931d3
children 59a9402ba6dd
files code_part1/OSTC_code_c_part2/p2_deco.c
diffstat 1 files changed, 28 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/code_part1/OSTC_code_c_part2/p2_deco.c	Tue Feb 12 14:57:14 2013 +0100
+++ b/code_part1/OSTC_code_c_part2/p2_deco.c	Wed Feb 13 10:36:28 2013 +0100
@@ -165,11 +165,11 @@
 static float			locked_GF_step;             // GF_delta / low_depth
 
 static unsigned char    temp_depth_limit;
-static unsigned char    low_depth;                  // Depth of deepest stop
+float                   low_depth;                  // Depth of deepest stop
 
 // Simulation context: used to predict ascent.
-static unsigned char	sim_lead_tissue_no;         // Leading compatiment number.
-static float			sim_lead_tissue_limit;      // Buhlmann tolerated pressure.
+unsigned char           sim_lead_tissue_no;         // Leading compatiment number.
+float	                sim_lead_tissue_limit;      // Buhlmann tolerated pressure.
 
 // Real context: what we are doing now.
 static float			calc_lead_tissue_limit;     // 
@@ -551,37 +551,37 @@
 
         sim_limit( GF_low );
         p = sim_lead_tissue_limit - pres_surface;
+        p *= BAR_TO_METER;
         if( p <= 0.0f )
             goto no_deco_stop;          // We can surface directly...
 
-        p *= BAR_TO_METER;
+        // Store the deepest point needing a deco stop as the LOW reference for GF.
+        // NOTE: following stops will be validated using this LOW-HIGH gf scale,
+        //       so if we want to keep coherency, we should not validate this stop
+        //       yet, but apply the search to it, as for all the following stops afterward.
+        if( p > low_depth )
+        {
+            low_depth = p;
+            locked_GF_step = GF_delta / low_depth;
+        }
+
         if( p < min_depth )
             goto no_deco_stop;          // First stop is higher than 1' ascent.
 
-        first_stop = 3 * (short)(0.99999 + p*0.333333);
+        // Round to multiple of 3m.
+        first_stop = 3 * (short)(0.9995f + p*0.333333f);
         assert( first_stop < 128 );
 
         // Apply correction for the shallowest stop.
         if( first_stop == 3 )                           // new in v104
             first_stop = char_I_depth_last_deco;        // Use last 3m..6m instead.
 
-        // Store the deepest point needing a deco stop as the LOW reference for GF.
-        // NOTE: following stops will be validated using this LOW-HIGH gf scale,
-        //       so if we want to keep coherency, we should not validate this stop
-        //       yet, but apply the search to it, as for all the following stops afterward.
-        if( first_stop > low_depth )
-        {
-            low_depth = first_stop;
-            locked_GF_step = GF_delta / first_stop;
-        }
-
         // We have a stop candidate.
         // But maybe ascending to the next stop will diminish the constraint,
         // because the GF might decrease more than the preassure gradient...
         while(first_stop > 0)
         {
             overlay unsigned char next_stop;            // Next depth (0..90m)
-            overlay float pres_stop;                    // Next pressure (bar)
 
             // Check max speed, or reaching surface.
             if( first_stop <= min_depth )
@@ -594,31 +594,30 @@
             else
                 next_stop = first_stop - 3;             // Index of next (upper) stop.
             
-            // Just a check we are indeed above LOW ref.
-            assert( next_stop < low_depth );
-
             // Total preassure at the new stop candidate:
-            pres_stop =  next_stop * METER_TO_BAR
-    	              + pres_surface;
+            p = next_stop * METER_TO_BAR
+    	      + pres_surface;
 
-            // Keep GF_low until a first stop depth is found:
-            sim_limit( GF_high - next_stop * locked_GF_step );
+            // Recompute limit for this new stop:
+            if( !low_depth || next_stop > low_depth )
+                sim_limit( GF_low );
+            else
+                sim_limit( GF_high - next_stop * locked_GF_step );
 
-            // Check upper limit (lowest pressure tolerated):
-            if( sim_lead_tissue_limit >= pres_stop )    // check if ascent to next deco stop is ok
-                goto deco_stop_found;
+            // Check upper limit (lowest ambiant pressure tolerated):
+            if( sim_lead_tissue_limit >= p )
+                goto deco_stop_found;       // Ascent to next_stop forbiden.
 
             // Else, validate that stop and loop...
             first_stop = next_stop;
         }
-        assert( first_stop == 0 );
 
 no_deco_stop:
 		temp_depth_limit = min_depth;
         goto done;
 
+deco_stop_found:
         // next stop is the last validated depth found, aka first_stop
-deco_stop_found:
         need_stop = 1;                  // Hit.
         temp_depth_limit = first_stop;  // Stop depth, in meter.
 
@@ -1069,7 +1068,7 @@
         // Values that should be reset just once for the full real dive.
         // This is used to record the lowest stop for the whole dive,
         // Including ACCROSS all simulated ascent.
-        low_depth = 0;
+        low_depth = 0.0;
         locked_GF_step = 0.0;
 
         // Reset gas switch history.
@@ -1682,7 +1681,6 @@
               / (GF_current / var_N2_b + 1.0 - GF_current);
         else
             p = (p - var_N2_a) * var_N2_b;
-        if( p < 0.0 ) p = 0.0;
 
         if( p > sim_lead_tissue_limit )
         {