diff src/p2_deco.c @ 115:72259a79eac2

FIX: Gas volume computation when using several travel mix.
author heinrichsweikamp
date Mon, 23 Jun 2014 17:55:27 +0200
parents 109df032cc54
children d076e9c02438
line wrap: on
line diff
--- a/src/p2_deco.c	Mon Jun 23 17:44:18 2014 +0200
+++ b/src/p2_deco.c	Mon Jun 23 17:55:27 2014 +0200
@@ -85,6 +85,8 @@
 // 2013/03/05: [jDG] Should vault low_depth too.
 // 2013/03/05: [jDG] Wrobell remark: ascent_to_first_stop works better with finer steps (2sec).
 // 2013/05/08: [jDG] A. Salm remark: NOAA tables for CNS are in ATA, not bar.
+// 2013/12/21: [jDG] Fix CNS calculation in decoplan w/o marked gas switch
+// 2014/06/16: [jDG] Fix Helium diluant. Fix volumes with many travel mix.
 //
 // TODO:
 //
@@ -2158,6 +2160,7 @@
     overlay float bottom_usage, deco_usage;
     overlay unsigned char i, deepest_first;
     overlay unsigned char gas, depth;
+    overlay unsigned char lastGasStop = 255;
     RESET_C_STACK
 
     //---- initialize with bottom consumption --------------------------------
@@ -2167,7 +2170,7 @@
     assert(1 <= char_I_first_gas && char_I_first_gas <= NUM_GAS);
     gas = char_I_first_gas - 1;
 
-    bottom_usage = (float) char_I_bottom_usage;
+    bottom_usage = 20;      // In liter/minutes.
     if( char_I_const_ppO2 == 0 && bottom_usage > 0.0 )
         volumes[gas]
             = (char_I_bottom_depth*0.1 + 1.0)           // Use Psurface = 1.0 bar.
@@ -2175,7 +2178,8 @@
             * bottom_usage;                             // In liter/minutes.
 
     //---- Ascent usage ------------------------------------------------------
-    deco_usage    = (float) char_I_deco_usage; // In liter/minutes.
+    deepest_first = 0;
+    deco_usage    = 20;     // In liter/minutes.
 
     depth = char_I_bottom_depth;
 
@@ -2199,7 +2203,8 @@
             newDepth = char_O_deco_depth[31-i];
         }
 
-        //---- Gas switch during this step -----------------------------------
+        //---- Gas switch during or before this stop --------------------------
+        for(;;)
         {
             overlay unsigned char newGas = 0;
             overlay unsigned char newStop = 0;  // NO CHANGE yet
@@ -2210,12 +2215,13 @@
                 // Skip gas without changing depth:
                 if( ! char_I_deco_gas_change[j] )
                     continue;
-                // Select gas changed between [newDepth .. depth]
+                // 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] <= depth )
+                 && char_I_deco_gas_change[j] < lastGasStop )
                 {
                     // Keep the DEEPEST gas in that range:
-                    // Note: that = means changing gas at BEGINNING of this stop.
                     if( char_I_deco_gas_change[j] >= newStop )
                     {
                         newGas  = j;
@@ -2224,28 +2230,32 @@
                 }
             }
 
-            if( newStop ) // Did we find something ?
-            {
-                // 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;
+             // Did we find something ?
+            if( !newStop )
+                break;
 
-                // Do gas switch:
-                gas = newGas;
+            //---- 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 :
+        //---- 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 stop:
         depth = newDepth;
 
         // Usage at stop: