comparison src/p2_deco.c @ 348:fca4f9de5f4a

[FIX] GasVolume: missing gas changes w/o stops.
author jDG
date Wed, 15 Jul 2015 17:57:37 +0200
parents 7812ec7ef694
children de8c45fb2ab9
comparison
equal deleted inserted replaced
347:7e5772df60cd 348:fca4f9de5f4a
2167 { 2167 {
2168 overlay float volumes[NUM_GAS]; 2168 overlay float volumes[NUM_GAS];
2169 overlay float bottom_usage, deco_usage; 2169 overlay float bottom_usage, deco_usage;
2170 overlay unsigned char i; 2170 overlay unsigned char i;
2171 overlay unsigned char gas, depth; 2171 overlay unsigned char gas, depth;
2172 overlay unsigned char lastGasStop;
2172 RESET_C_STACK 2173 RESET_C_STACK
2173 2174
2174 //---- initialize -------------------------------------------------------- 2175 //---- initialize --------------------------------------------------------
2175 for(i=0; i<NUM_GAS; ++i) // Nothing yet... 2176 for(i=0; i<NUM_GAS; ++i) // Nothing yet...
2176 volumes[i] = 0.0; 2177 volumes[i] = 0.0;
2191 = (char_I_bottom_depth*0.1 + 1.0) // Use Psurface = 1.0 bar. 2192 = (char_I_bottom_depth*0.1 + 1.0) // Use Psurface = 1.0 bar.
2192 * char_I_bottom_time // in minutes. 2193 * char_I_bottom_time // in minutes.
2193 * bottom_usage; // In liter/minutes. 2194 * bottom_usage; // In liter/minutes.
2194 2195
2195 //---- Ascent usage ------------------------------------------------------ 2196 //---- Ascent usage ------------------------------------------------------
2196 depth = char_I_bottom_depth; 2197 depth = lastGasStop = char_I_bottom_depth;
2197 2198
2198 for(i=0; i<NUM_STOPS; ++i) 2199 for(i=0; i<NUM_STOPS; ++i)
2199 { 2200 {
2200 overlay unsigned char newDepth, time, newGas; 2201 overlay unsigned char newDepth, time;
2201 2202
2202 time = char_O_deco_time[i]; 2203 time = char_O_deco_time [i];
2203 if( time == 0 ) break; // End of stops. 2204 if( time == 0 ) break; // End of table: done.
2204 2205
2205 newDepth = char_O_deco_depth[i]; 2206 newDepth = char_O_deco_depth[i];
2206 newGas = char_O_deco_gas [i]-1;
2207
2208 assert(0 < newDepth && newDepth <= depth); 2207 assert(0 < newDepth && newDepth <= depth);
2209 assert(0 <= newGas && newGas < NUM_GAS); 2208
2210 2209 //---- Any gas switch before this stop -------------------------------
2211 //---- usage BEFORE gas switch (if any), at 10m/min: 2210 for(;;)
2212 volumes[gas] += ((depth+newDepth)*0.05 + 1.0) // average depth --> bar. 2211 {
2213 * (depth-newDepth)*0.1 // metre --> min 2212 overlay unsigned char newGas = 0;
2214 * deco_usage; 2213 overlay unsigned char newStop = 0; // NO CHANGE yet
2215 2214 overlay unsigned char j;
2216 //---- Do gas switch, at new depth: 2215
2217 gas = newGas; 2216 for(j=0; j<NUM_GAS; ++j)
2217 {
2218 // Skip gas without changing depth:
2219 if( ! char_I_deco_gas_change[j] )
2220 continue;
2221 // Select gas changed between [newDepth .. lastGasStop[
2222 // Note that <= means changing gas at BEGINNING of this stop.
2223 // Note that < means we cant use the same gas twice
2224 if( newDepth <= char_I_deco_gas_change[j]
2225 && char_I_deco_gas_change[j] < lastGasStop )
2226 {
2227 // Keep the DEEPEST gas in that range:
2228 if( char_I_deco_gas_change[j] >= newStop )
2229 {
2230 newGas = j;
2231 newStop = char_I_deco_gas_change[j];
2232 }
2233 }
2234 }
2235
2236 // Did we find something ?
2237 if( !newStop )
2238 break;
2239
2240 //---- usage BEFORE gas switch (if any), at 10m/min :
2241 if( depth > newStop )
2242 // Plus usage during ascent to the next stop, at 10m/min.
2243 volumes[gas] += ((depth+newStop)*0.05 + 1.0) // average depth --> bar.
2244 * (depth-newStop)*0.1 // metre --> min
2245 * deco_usage;
2246
2247 //---- Do gas switch:
2248 gas = newGas;
2249
2250 lastGasStop = newStop; // Mark last used gas
2251 if( newStop < depth ) // ascent to gas switch,
2252 depth = newStop;
2253 }
2254
2255 // Are we back to gas from the deco list (just in case):
2256 assert(gas == char_O_deco_gas[i]-1);
2257
2258 //---- usage AFTER gas switch (if any), at 10m/min :
2259 if( depth > newDepth )
2260 volumes[gas] += ((depth+newDepth)*0.05 + 1.0) // average depth --> bar.
2261 * (depth-newDepth)*0.1 // metre --> min
2262 * deco_usage;
2263
2264 //---- Do stop:
2218 depth = newDepth; 2265 depth = newDepth;
2219 2266
2220 //---- Usage at stop: 2267 //---- Usage at stop:
2221 volumes[gas] += (depth*0.1 + 1.0) // depth --> bar. 2268 volumes[gas] += (depth*0.1 + 1.0) // depth --> bar.
2222 * time // in minutes. 2269 * time // in minutes.