changeset 784:46ef1e1388f1

Merge
author heinrichsweikamp
date Mon, 23 Jun 2014 17:29:59 +0200
parents e57e8045527d (diff) 9635f6276c3e (current diff)
children b0c96aaa86e4
files
diffstat 1 files changed, 27 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/code_part1/OSTC_code_c_part2/p2_deco.c	Mon Jun 02 12:55:38 2014 +0200
+++ b/code_part1/OSTC_code_c_part2/p2_deco.c	Mon Jun 23 17:29:59 2014 +0200
@@ -90,6 +90,7 @@
 // 2013/05/08: [jDG] A. Salm remark: NOAA tables for CNS are in ATA, not bar.
 // 2013/10/22: [mH]  Remove CF55 stuff
 // 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:
 //  + Allow to abort MD2 calculation (have to restart next time).
@@ -922,7 +923,7 @@
     }
 
     assert( 0.0 <= calc_N2_ratio && calc_N2_ratio <= 0.95 );
-    assert( 0.0 <= calc_He_ratio && calc_He_ratio <= 0.95 );
+    assert( 0.0 <= calc_He_ratio && calc_He_ratio <= 1.00 );
     assert( (calc_N2_ratio + calc_He_ratio) <= 1.00 );
 }
 
@@ -1164,7 +1165,7 @@
 {
     assert( 0.00 <= N2_ratio && N2_ratio <= 1.00 );
     assert( 0.00 <= He_ratio && He_ratio <= 1.00 );
-    assert( (N2_ratio + He_ratio) <= 0.95 );
+    assert( (N2_ratio + He_ratio) <= 1.00 );
     assert( 0.800 < pres_respiration && pres_respiration < 14.0 );
 
     pres_diluent = pres_respiration;
@@ -2355,6 +2356,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 --------------------------------
@@ -2397,7 +2399,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
@@ -2408,12 +2411,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;
@@ -2422,28 +2426,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: