# HG changeset patch
# User JeanDo
# Date 1335304033 -7200
# Node ID fff1d38625f00dcc027db3f25d0a5c9b3e7136d4
# Parent  fbd5e2b75a63b2b9991628e417f3f8ff02760e1e
BUGFIX: GasVolumes should check for a gas switch before the first stop.

diff -r fbd5e2b75a63 -r fff1d38625f0 code_part1/OSTC_code_c_part2/p2_deco.c
--- a/code_part1/OSTC_code_c_part2/p2_deco.c	Tue Apr 24 08:39:43 2012 +0200
+++ b/code_part1/OSTC_code_c_part2/p2_deco.c	Tue Apr 24 23:47:13 2012 +0200
@@ -2345,11 +2345,23 @@
             = (char_I_bottom_depth*0.1 + 1.0)           // Use Psurface = 1.0 bar.
             * char_I_bottom_time                        // in minutes.
             * bottom_usage;                             // In liter/minutes.
-    else
-        volumes[gas] = 65535.0;
+
+    //---- Starts by a gas switch ? ------------------------------------------
+    // If there is no special gas-switch stops inserted, then
+    // we should pay attention to the gas when starting to ascent, before
+    // the first stop...
+    if( read_custom_function(55) == 0 )
+    {
+        overlay unsigned char j;
+        for(j=0; j<NUM_GAS; ++j)
+        {
+            if( char_O_first_deco_depth < char_I_deco_gas_change[j] )
+                if( !char_I_deco_gas_change[gas] || (char_I_deco_gas_change[gas] > char_I_deco_gas_change[j]) )
+                    gas = j;
+        }
+    }
 
     //---- Ascent usage ------------------------------------------------------
-
     deepest_first = read_custom_function(54) == 0;
     deco_usage    = (float) read_custom_function(57); // In liter/minutes.
 
@@ -2363,8 +2375,6 @@
             += (char_I_bottom_depth*0.1 + 1.0)          // Depth -> bar
              * (char_I_bottom_depth - char_O_first_deco_depth) * 0.1  // ascent time (min)
              * deco_usage;                              // Consumption ( xxx / min @ 1 bar)
-    else
-        volumes[gas] = 65535.0;
 
     for(i=0; i<NUM_STOPS; ++i)
     {