comparison src/p2_deco.c @ 325:d82516b8298e new_screen_layout

Merged default into new_screen_layout
author Janos Kovacs <kovjanos@gmail.com>
date Sat, 13 Jun 2015 22:54:37 +0200
parents 0e9dcdcf03c1
children 7812ec7ef694
comparison
equal deleted inserted replaced
321:8b70dd8d9904 325:d82516b8298e
85 // 2013/03/05: [jDG] Should vault low_depth too. 85 // 2013/03/05: [jDG] Should vault low_depth too.
86 // 2013/03/05: [jDG] Wrobell remark: ascent_to_first_stop works better with finer steps (2sec). 86 // 2013/03/05: [jDG] Wrobell remark: ascent_to_first_stop works better with finer steps (2sec).
87 // 2013/05/08: [jDG] A. Salm remark: NOAA tables for CNS are in ATA, not bar. 87 // 2013/05/08: [jDG] A. Salm remark: NOAA tables for CNS are in ATA, not bar.
88 // 2013/12/21: [jDG] Fix CNS calculation in decoplan w/o marked gas switch 88 // 2013/12/21: [jDG] Fix CNS calculation in decoplan w/o marked gas switch
89 // 2014/06/16: [jDG] Fix Helium diluant. Fix volumes with many travel mix. 89 // 2014/06/16: [jDG] Fix Helium diluant. Fix volumes with many travel mix.
90 // 2014/06/29: [mH] Compute int_O_ceiling 90 // 2014/06/29: [mH] Compute int_O_ceiling
91 // 2015/06/12: [jDG] Fix NDL prediction while desaturating with the Buhlmann model.
91 // 92 //
92 // TODO: 93 // TODO:
93 // 94 //
94 // Literature: 95 // Literature:
95 // Buhlmann, Albert: Tauchmedizin; 4. Auflage [2002]; 96 // Buhlmann, Albert: Tauchmedizin; 4. Auflage [2002];
188 #ifndef UNIX 189 #ifndef UNIX
189 # pragma udata bank6=0x600 190 # pragma udata bank6=0x600
190 #endif 191 #endif
191 192
192 static unsigned char ci; 193 static unsigned char ci;
193 static float pres_respiration; 194 static float pres_respiration;
194 static float pres_surface; 195 static float pres_surface;
195 static float temp_deco; 196 static float temp_deco;
196 static float ppN2; 197 static float ppN2;
197 static float ppHe; 198 static float ppHe;
198 static float temp_tissue; 199 static float temp_tissue;
199 static float N2_ratio; // Breathed gas nitrogen ratio. 200 static float N2_ratio; // Breathed gas nitrogen ratio.
200 static float He_ratio; // Breathed gas helium ratio. 201 static float He_ratio; // Breathed gas helium ratio.
201 static float var_N2_a; // Buhlmann a, for current N2 tissue. 202 static float var_N2_a; // Buhlmann a, for current N2 tissue.
202 static float var_N2_b; // Buhlmann b, for current N2 tissue. 203 static float var_N2_b; // Buhlmann b, for current N2 tissue.
203 static float var_He_a; // Buhlmann a, for current He tissue. 204 static float var_He_a; // Buhlmann a, for current He tissue.
204 static float var_He_b; // Buhlmann b, for current He tissue. 205 static float var_He_b; // Buhlmann b, for current He tissue.
205 static float var_N2_e; // Exposition, for current N2 tissue. 206 static float var_N2_e; // Exposition, for current N2 tissue.
206 static float var_He_e; // Exposition, for current He tissue. 207 static float var_He_e; // Exposition, for current He tissue.
207 static float var_N2_ht; // Half-time for current N2 tissue. 208 static float var_N2_ht; // Half-time for current N2 tissue.
208 static float var_He_ht; // Half-time for current N2 tissue. 209 static float var_He_ht; // Half-time for current N2 tissue.
209 210
210 static float pres_diluent; // new in v.101 211 static float pres_diluent; // new in v.101
211 static float const_ppO2; // new in v.101 212 static float const_ppO2; // new in v.101
212 213
213 static unsigned char sim_gas_last_depth; // Depth of last used gas, to detected a gas switch. 214 static unsigned char sim_gas_last_depth; // Depth of last used gas, to detected a gas switch.
214 static unsigned char sim_gas_last_used; // Number of last used gas, to detected a gas switch. 215 static unsigned char sim_gas_last_used; // Number of last used gas, to detected a gas switch.
215 static unsigned short sim_dive_mins; // Simulated dive time. 216 static unsigned short sim_dive_mins; // Simulated dive time.
216 static float calc_N2_ratio; // Simulated (switched) nitrogen ratio. 217 static float calc_N2_ratio; // Simulated (switched) nitrogen ratio.
217 static float calc_He_ratio; // Simulated (switched) helium ratio. 218 static float calc_He_ratio; // Simulated (switched) helium ratio.
218 static float CNS_fraction; // new in v.101 219 static float CNS_fraction; // new in v.101
219 static float float_saturation_multiplier; // new in v.101 220 static float float_saturation_multiplier; // new in v.101
220 static float float_desaturation_multiplier; // new in v.101 221 static float float_desaturation_multiplier; // new in v.101
221 static float float_deco_distance; // new in v.101 222 static float float_deco_distance; // new in v.101
222 223
223 static unsigned char deco_gas_change[NUM_GAS]; // new in v.109 224 static unsigned char deco_gas_change[NUM_GAS]; // new in v.109
224 static unsigned char internal_deco_gas [NUM_STOPS]; 225 static unsigned char internal_deco_gas [NUM_STOPS];
225 226
226 //---- Bank 7 parameters ----------------------------------------------------- 227 //---- Bank 7 parameters -----------------------------------------------------
727 // 728 //
728 // Output: sim_gas_last_depth = 0..5, temp_depth_limit. 729 // Output: sim_gas_last_depth = 0..5, temp_depth_limit.
729 // 730 //
730 static void gas_switch_find_current(void) 731 static void gas_switch_find_current(void)
731 { 732 {
732 assert( 0 < char_I_current_gas && char_I_current_gas <= (NUM_GAS+1) ); 733 assert( 0 < char_I_current_gas && char_I_current_gas <= (2*NUM_GAS) );
733 734
734 if( char_I_current_gas <= NUM_GAS ) // Gas1..Gas5 735 if( char_I_current_gas <= NUM_GAS ) // Gas1..Gas5
735 { 736 {
736 sim_gas_last_used = char_I_current_gas; 737 sim_gas_last_used = char_I_current_gas;
737 738
1414 overlay float dTHe = (ppHe - tHe) * var_He_e; 1415 overlay float dTHe = (ppHe - tHe) * var_He_e;
1415 1416
1416 //---- Apply security margin when using the non-GF model 1417 //---- Apply security margin when using the non-GF model
1417 if( char_I_deco_model == 0 ) 1418 if( char_I_deco_model == 0 )
1418 { 1419 {
1419 dTN2 *= float_saturation_multiplier; 1420 // NDL can be computed while ascending... SO we have
1420 dTHe *= float_saturation_multiplier; 1421 // to check wether we are saturating or desaturating.
1422 if( dTN2 > 0.0 ) dTN2 *= float_saturation_multiplier;
1423 else dTN2 *= float_desaturation_multiplier;
1424
1425 if( dTHe > 0.0 ) dTHe *= float_saturation_multiplier;
1426 else dTHe *= float_saturation_multiplier;
1421 } 1427 }
1422 else // Or GF-based model 1428 else // Or GF-based model
1423 M0 = GF_high * (M0 - pres_surface) + pres_surface; 1429 M0 = GF_high * (M0 - pres_surface) + pres_surface;
1424 1430
1425 //---- Simulate off-gasing while going to surface 1431 //---- Simulate off-gasing while going to surface
1893 for(t=0; t<char_I_dive_interval; ++t) 1899 for(t=0; t<char_I_dive_interval; ++t)
1894 { 1900 {
1895 calc_tissue(2); // period = 10min. 1901 calc_tissue(2); // period = 10min.
1896 CNS_fraction = 0.92587471 * CNS_fraction; // Half-time = 90min: (1/2)^(1/9) 1902 CNS_fraction = 0.92587471 * CNS_fraction; // Half-time = 90min: (1/2)^(1/9)
1897 } 1903 }
1898 assert( 0.0 <= CNS_fraction && CNS_fraction <= 2.56 ); 1904 assert( 0.0 <= CNS_fraction && CNS_fraction <= 9.99 ); // 999 %
1899 int_O_CNS_fraction = (unsigned int)(CNS_fraction * 100.0 + 0.5); 1905 int_O_CNS_fraction = (unsigned short)(CNS_fraction * 100.0 + 0.5);
1900 1906
1901 //---- Restore model ----------------------------------------------------- 1907 //---- Restore model -----------------------------------------------------
1902 char_I_deco_model = backup_model; 1908 char_I_deco_model = backup_model;
1903 } 1909 }
1904 1910
1926 void deco_calc_CNS_fraction(void) 1932 void deco_calc_CNS_fraction(void)
1927 { 1933 {
1928 overlay float time_factor = 1.0f; 1934 overlay float time_factor = 1.0f;
1929 RESET_C_STACK 1935 RESET_C_STACK
1930 1936
1931 assert( 0.0 <= CNS_fraction && CNS_fraction <= 2.56 ); 1937 assert( 0.0 <= CNS_fraction && CNS_fraction <= 9.99 );
1932 assert( char_I_actual_ppO2 > 15 ); 1938 assert( char_I_actual_ppO2 > 15 );
1933 1939
1934 if( char_I_step_is_1min == 1 ) 1940 if( char_I_step_is_1min == 1 )
1935 time_factor = 30.0f; 1941 time_factor = 30.0f;
1936 else if( char_I_step_is_1min == 2 ) 1942 else if( char_I_step_is_1min == 2 )
1955 CNS_fraction += time_factor/( -88.84 * char_I_actual_ppO2 + 17100.0); 1961 CNS_fraction += time_factor/( -88.84 * char_I_actual_ppO2 + 17100.0);
1956 else if (char_I_actual_ppO2 < 167) 1962 else if (char_I_actual_ppO2 < 167)
1957 CNS_fraction += time_factor/(-222.11 * char_I_actual_ppO2 + 37350.0); 1963 CNS_fraction += time_factor/(-222.11 * char_I_actual_ppO2 + 37350.0);
1958 //------------------------------------------------------------------------ 1964 //------------------------------------------------------------------------
1959 // Arieli et all.(2002): Modeling pulmonary and CNS O2 toxicity: 1965 // Arieli et all.(2002): Modeling pulmonary and CNS O2 toxicity:
1960 // J Appl Physiol 92: 248–256, 2002, doi:10.1152/japplphysiol.00434.2001 1966 // J Appl Physiol 92: 248--256, 2002, doi:10.1152/japplphysiol.00434.2001
1961 // Formula (A1) based on value for 1.55 and c=20 1967 // Formula (A1) based on value for 1.55 and c=20
1962 // example calculation: Sqrt((1.7/1.55)^20)*0.000404 1968 // example calculation: Sqrt((1.7/1.55)^20)*0.000404
1963 else if (char_I_actual_ppO2 < 172) 1969 else if (char_I_actual_ppO2 < 172)
1964 CNS_fraction += time_factor*0.00102; 1970 CNS_fraction += time_factor*0.00102;
1965 else if (char_I_actual_ppO2 < 177) 1971 else if (char_I_actual_ppO2 < 177)
1977 else if (char_I_actual_ppO2 < 233) 1983 else if (char_I_actual_ppO2 < 233)
1978 CNS_fraction += time_factor*0.0209; 1984 CNS_fraction += time_factor*0.0209;
1979 else 1985 else
1980 CNS_fraction += time_factor*0.0482; // value for 2.5 1986 CNS_fraction += time_factor*0.0482; // value for 2.5
1981 1987
1982 if( CNS_fraction > 9.99) 1988 if( CNS_fraction > 9.99) // Limit display to 999%
1983 CNS_fraction = 9.99; 1989 CNS_fraction = 9.99;
1984 if( CNS_fraction < 0.0 ) 1990 if( CNS_fraction < 0.0 )
1985 CNS_fraction = 0.0; 1991 CNS_fraction = 0.0;
1986 1992
1987 int_O_CNS_fraction = (unsigned int)(100.0 * CNS_fraction + 0.5); 1993 int_O_CNS_fraction = (unsigned short)(100.0 * CNS_fraction + 0.5);
1988 } 1994 }
1989 1995
1990 ////////////////////////////////////////////////////////////////////////////// 1996 //////////////////////////////////////////////////////////////////////////////
1991 // deco_calc_CNS_planning 1997 // deco_calc_CNS_planning
1992 // 1998 //
2110 // Uses and Updates: CNS_fraction 2116 // Uses and Updates: CNS_fraction
2111 // 2117 //
2112 void deco_calc_CNS_decrease_15min(void) 2118 void deco_calc_CNS_decrease_15min(void)
2113 { 2119 {
2114 RESET_C_STACK 2120 RESET_C_STACK
2115 assert( 0.0 <= CNS_fraction && CNS_fraction <= 2.56 ); 2121 assert( 0.0 <= CNS_fraction && CNS_fraction <= 9.99 );
2116 2122
2117 CNS_fraction = 0.890899 * CNS_fraction; 2123 CNS_fraction = 0.890899 * CNS_fraction;
2118 int_O_CNS_fraction = (unsigned int)(CNS_fraction * 100.0 + 0.5); 2124 int_O_CNS_fraction = (unsigned short)(CNS_fraction * 100.0 + 0.5);
2119 } 2125 }
2120 2126
2121 ////////////////////////////////////////////////////////////////////////////// 2127 //////////////////////////////////////////////////////////////////////////////
2122 // deco_calc_percentage 2128 // deco_calc_percentage
2123 // 2129 //
2257 pres_tissue_He[x] = pres_tissue_He_vault[x]; 2263 pres_tissue_He[x] = pres_tissue_He_vault[x];
2258 } 2264 }
2259 2265
2260 // Restore both CNS variable, too. 2266 // Restore both CNS variable, too.
2261 CNS_fraction = cns_vault; 2267 CNS_fraction = cns_vault;
2262 int_O_CNS_fraction = (unsigned int)(CNS_fraction * 100.0 + 0.5); 2268 int_O_CNS_fraction = (unsigned short)(CNS_fraction * 100.0 + 0.5);
2263 2269
2264 // GF history too: 2270 // GF history too:
2265 low_depth = low_depth_vault; 2271 low_depth = low_depth_vault;
2266 locked_GF_step = GF_delta / low_depth; 2272 locked_GF_step = GF_delta / low_depth;
2267 } 2273 }