diff src/p2_deco.c @ 288:08986d479b94

FIX gas_volume shall read gas switches from char_O_deco_gas
author jdg@air
date Fri, 29 May 2015 02:40:43 +0200
parents f342853afcd9
children 30edd177016a
line wrap: on
line diff
--- a/src/p2_deco.c	Fri May 29 02:24:03 2015 +0200
+++ b/src/p2_deco.c	Fri May 29 02:40:43 2015 +0200
@@ -2165,7 +2165,6 @@
     overlay float bottom_usage, deco_usage;
     overlay unsigned char i;
     overlay unsigned char gas, depth;
-    overlay unsigned char lastGasStop = 255;
     RESET_C_STACK
 
     //---- initialize with bottom consumption --------------------------------
@@ -2189,65 +2188,24 @@
 
     for(i=0; i<NUM_STOPS; ++i)
     {
-        overlay unsigned char newDepth, time;
+        overlay unsigned char newDepth, time, newGas;
 
         time = char_O_deco_time[i];
-        if( time == 0 ) continue;       // not yet: still search table.
-        newDepth = char_O_deco_depth[i];
+        if( time == 0 ) break;       // End of stops.
 
-        //---- Gas switch during or before this stop --------------------------
-        for(;;)
-        {
-            overlay unsigned char newGas = 0;
-            overlay unsigned char newStop = 0;  // NO CHANGE yet
-            overlay unsigned char j;
+        newDepth = char_O_deco_depth[i];
+        newGas   = char_O_deco_gas  [i]-1;
+
+        assert(0 < newDepth && newDepth <= depth);
+        assert(0 <= newGas && newGas < NUM_GAS);
 
-            for(j=0; j<NUM_GAS; ++j)
-            {
-                // Skip gas without changing depth:
-                if( ! char_I_deco_gas_change[j] )
-                    continue;
-                // Select gas changed between [newDepth .. lastGasStop[
-                // Note that <= means changing gas at BEGINNING of this stop.
-                // Note that < means we cant use the same gas twice
-                if( newDepth <= char_I_deco_gas_change[j]
-                 && char_I_deco_gas_change[j] < lastGasStop )
-                {
-                    // Keep the DEEPEST gas in that range:
-                    if( char_I_deco_gas_change[j] >= newStop )
-                    {
-                        newGas  = j;
-                        newStop = char_I_deco_gas_change[j];
-                    }
-                }
-            }
+        //---- usage BEFORE gas switch (if any), at 10m/min ------------------
+        volumes[gas] += ((depth+newDepth)*0.05 + 1.0)    // average depth --> bar.
+                      * (depth-newDepth)*0.1             // metre --> min
+                      * deco_usage;
 
-             // Did we find something ?
-            if( !newStop )
-                break;
-
-            //---- usage BEFORE gas switch (if any), at 10m/min :
-            if( deco_usage > 0.0 && depth > newStop )
-                // Plus usage during ascent to the next stop, at 10m/min.
-                volumes[gas] += ((depth+newStop)*0.05 + 1.0)    // average depth --> bar.
-                              * (depth-newStop)*0.1             // metre --> min
-                              * deco_usage;
-
-            //---- Do gas switch:
-            gas = newGas;
-
-            lastGasStop = newStop;          // Mark last used gas
-            if( newStop < depth )           // ascent to gas switch,
-                depth = newStop;
-        }
-
-        //---- usage AFTER gas switch (if any), at 10m/min :
-        if( depth > newDepth )
-            volumes[gas] += ((depth+newDepth)*0.05 + 1.0)    // average depth --> bar.
-                          * (depth-newDepth)*0.1             // metre --> min
-                          * deco_usage;
-
-        //---- Do stop:
+        //---- Do gas switch, at new depth
+        gas   = newGas;
         depth = newDepth;
 
         // Usage at stop: