comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 658:75dc320f4681

BUGFIX Gas volumes when many tanks and stops.
author JeanDo <jd.gascuel@free.fr>
date Fri, 02 Nov 2012 00:57:09 +0100
parents 06ffc99a405f
children 6e456a6398e0
comparison
equal deleted inserted replaced
657:8dd730d3a5d7 658:75dc320f4681
2395 2395
2396 depth = char_I_bottom_depth; 2396 depth = char_I_bottom_depth;
2397 2397
2398 for(i=0; i<NUM_STOPS; ++i) 2398 for(i=0; i<NUM_STOPS; ++i)
2399 { 2399 {
2400 overlay unsigned char j; 2400 overlay unsigned char newDepth, time;
2401 overlay unsigned char newDepth, newStop, newGas, time;
2402 2401
2403 // Manage stops in reverse order (CF#54) 2402 // Manage stops in reverse order (CF#54)
2404 if( deepest_first ) 2403 if( deepest_first )
2405 { 2404 {
2406 time = char_O_deco_time[i]; 2405 time = char_O_deco_time[i];
2407 if( time == 0 ) break; // End of table: done. 2406 if( time == 0 ) break; // End of table: done.
2408 2407
2409 newStop = newDepth = char_O_deco_depth[i] & 0x7F; 2408 newDepth = char_O_deco_depth[i] & 0x7F;
2410 } 2409 }
2411 else 2410 else
2412 { 2411 {
2413 time = char_O_deco_time[31-i]; 2412 time = char_O_deco_time[31-i];
2414 if( time == 0 ) continue; // not yet: still searh table. 2413 if( time == 0 ) continue; // not yet: still search table.
2415 2414
2416 newStop = newDepth = char_O_deco_depth[31-i] & 0x7F; 2415 newDepth = char_O_deco_depth[31-i] & 0x7F;
2417 } 2416 }
2418 2417
2419 // Gas switch depth ? 2418 //---- Gas switch during this step -----------------------------------
2420 newGas = gas; 2419 {
2421 for(j=0; j<NUM_GAS; ++j) 2420 overlay unsigned char newGas = 0;
2422 { 2421 overlay unsigned char newStop = 0; // NO CHANGE yet
2423 if( j == newGas ) continue; 2422 overlay unsigned char j;
2424 if( char_I_deco_gas_change[j] == 0 ) continue; 2423
2425 if( newStop <= char_I_deco_gas_change[j] ) 2424 for(j=0; j<NUM_GAS; ++j)
2426 if( gas == newGas || (char_I_deco_gas_change[newGas] > char_I_deco_gas_change[j]) ) 2425 {
2426 // Skip gas without changing depth:
2427 if( ! char_I_deco_gas_change[j] )
2428 continue;
2429 // Select gas changed between [newDepth .. depth]
2430 if( newDepth <= char_I_deco_gas_change[j]
2431 && char_I_deco_gas_change[j] <= depth )
2427 { 2432 {
2428 newGas = j; 2433 // Keep the DEEPEST gas in that range:
2429 newStop = char_I_deco_gas_change[j]; 2434 // Note: that = means changing gas at BEGINNING of this stop.
2435 if( char_I_deco_gas_change[j] >= newStop )
2436 {
2437 newGas = j;
2438 newStop = char_I_deco_gas_change[j];
2439 }
2430 } 2440 }
2431 } 2441 }
2432 2442
2433 // usage BEFORE gas switch (if any), at 10m/min : 2443 if( newStop ) // Did we find something ?
2434 if( deco_usage > 0.0 && depth > newStop ) 2444 {
2435 // Plus usage during ascent to the next stop, at 10m/min. 2445 // usage BEFORE gas switch (if any), at 10m/min :
2436 volumes[gas] += ((depth+newStop)*0.05 + 1.0) // average depth --> bar. 2446 if( deco_usage > 0.0 && depth > newStop )
2437 * (depth-newStop)*0.1 // metre --> min 2447 // Plus usage during ascent to the next stop, at 10m/min.
2438 * deco_usage; 2448 volumes[gas] += ((depth+newStop)*0.05 + 1.0) // average depth --> bar.
2439 2449 * (depth-newStop)*0.1 // metre --> min
2440 // Do gas switch: 2450 * deco_usage;
2441 gas = newGas; 2451
2442 depth = newStop; 2452 // Do gas switch:
2453 gas = newGas;
2454 depth = newStop;
2455 }
2456 }
2443 2457
2444 // usage AFTER gas switch (if any), at 10m/min : 2458 // usage AFTER gas switch (if any), at 10m/min :
2445 if( depth > newDepth ) 2459 if( depth > newDepth )
2446 volumes[gas] += ((depth+newDepth)*0.05 + 1.0) // average depth --> bar. 2460 volumes[gas] += ((depth+newDepth)*0.05 + 1.0) // average depth --> bar.
2447 * (depth-newDepth)*0.1 // metre --> min 2461 * (depth-newDepth)*0.1 // metre --> min