comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 251:f0cba9cff25c

Still hunting for bb13...
author JeanDo
date Tue, 29 Mar 2011 23:47:34 +0200
parents ce869aad7440
children 8b252ff2eded
comparison
equal deleted inserted replaced
250:4ef3bcbc7091 251:f0cba9cff25c
1471 // 1471 //
1472 // optimized in v.101 1472 // optimized in v.101
1473 // 1473 //
1474 static void calc_tissue(PARAMETER unsigned char period) 1474 static void calc_tissue(PARAMETER unsigned char period)
1475 { 1475 {
1476 assert( 0.00 <= ppN2 && ppN2 < 6.40 ); // 80% N2 at 70m 1476 assert( 0.00 <= ppN2 && ppN2 < 11.2 ); // 80% N2 at 130m
1477 assert( 0.00 <= ppHe && ppHe < 18.9 ); // 90% He at 200m 1477 assert( 0.00 <= ppHe && ppHe < 12.6 ); // 90% He at 130m
1478 1478
1479 for (ci=0;ci<16;ci++) 1479 for (ci=0;ci<16;ci++)
1480 { 1480 {
1481 read_buhlmann_coefficients(period); // 2 sec or 1 min period. 1481 read_buhlmann_coefficients(period); // 2 sec or 1 min period.
1482 1482
1653 // Function very simular to calc_tissue, but: 1653 // Function very simular to calc_tissue, but:
1654 // + Use a 1min or 10min period. 1654 // + Use a 1min or 10min period.
1655 // + Do it on sim_pres_tissue, instead of pres_tissue. 1655 // + Do it on sim_pres_tissue, instead of pres_tissue.
1656 static void sim_tissue(PARAMETER unsigned char period) 1656 static void sim_tissue(PARAMETER unsigned char period)
1657 { 1657 {
1658 assert( 0.00 <= ppN2 && ppN2 < 6.40 ); // 80% N2 at 70m 1658 assert( 0.00 <= ppN2 && ppN2 < 11.2 ); // 80% N2 at 130m
1659 assert( 0.00 <= ppHe && ppHe < 18.9 ); // 90% He at 200m 1659 assert( 0.00 <= ppHe && ppHe < 12.6 ); // 90% He at 130m
1660 1660
1661 for(ci=0; ci<16; ci++) 1661 for(ci=0; ci<16; ci++)
1662 { 1662 {
1663 read_buhlmann_coefficients(period); // 1 or 10 minute(s) interval 1663 read_buhlmann_coefficients(period); // 1 or 10 minute(s) interval
1664 1664
1855 // Inputs: int_I_pres_surface, ppWVapour, char_I_desaturation_multiplier 1855 // Inputs: int_I_pres_surface, ppWVapour, char_I_desaturation_multiplier
1856 // Outputs: int_O_desaturation_time, char_O_tissue_saturation[0..31] 1856 // Outputs: int_O_desaturation_time, char_O_tissue_saturation[0..31]
1857 // 1857 //
1858 void deco_calc_desaturation_time(void) 1858 void deco_calc_desaturation_time(void)
1859 { 1859 {
1860 overlay unsigned short desat_time; // For a particular compartiment, in min.
1861 overlay float temp1;
1862 overlay float temp2;
1863 overlay float temp3;
1864 overlay float temp4;
1865 RESET_C_STACK 1860 RESET_C_STACK
1866 1861
1867 assert( 800 < int_I_pres_surface && int_I_pres_surface < 1100 ); 1862 assert( 800 < int_I_pres_surface && int_I_pres_surface < 1100 );
1868 assert( 0 < char_I_desaturation_multiplier && char_I_desaturation_multiplier <= 100 ); 1863 assert( 0 < char_I_desaturation_multiplier && char_I_desaturation_multiplier <= 100 );
1869 1864
1873 int_O_desaturation_time = 0; 1868 int_O_desaturation_time = 0;
1874 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) 1869 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142)
1875 1870
1876 for (ci=0;ci<16;ci++) 1871 for (ci=0;ci<16;ci++)
1877 { 1872 {
1873 overlay unsigned short desat_time; // For a particular compartiment, in min.
1874 overlay float temp1;
1875 overlay float temp2;
1876 overlay float temp3;
1877 overlay float temp4;
1878
1878 overlay float var_N2_halftime = buhlmann_ht[ci]; 1879 overlay float var_N2_halftime = buhlmann_ht[ci];
1879 overlay float var_He_halftime = (buhlmann_ht+16)[ci]; 1880 overlay float var_He_halftime = (buhlmann_ht+16)[ci];
1880 1881
1881 // saturation_time (for flight) and N2_saturation in multiples of halftime 1882 // saturation_time (for flight) and N2_saturation in multiples of halftime
1882 // version v.100: 1.1 = 10 percent distance to totally clean (totally clean is not possible, would take infinite time ) 1883 // version v.100: 1.1 = 10 percent distance to totally clean (totally clean is not possible, would take infinite time )
1891 temp1 = 0.0; 1892 temp1 = 0.0;
1892 temp2 = 0.0; 1893 temp2 = 0.0;
1893 } 1894 }
1894 else 1895 else
1895 temp1 = temp1 / temp2; 1896 temp1 = temp1 / temp2;
1896 if (temp1 > 0.0) 1897 if( 0.0 < temp1 && temp1 < 1.0 )
1897 { 1898 {
1898 temp1 = log(1.0 - temp1); 1899 temp1 = log(1.0 - temp1);
1899 temp1 = temp1 / -0.6931; // temp1 is the multiples of half times necessary. 1900 temp1 = temp1 / -0.6931; // temp1 is the multiples of half times necessary.
1900 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested. 1901 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested.
1901 // minus because log is negative 1902 // minus because log is negative
1914 temp3 = 0.0; 1915 temp3 = 0.0;
1915 temp4 = 0.0; 1916 temp4 = 0.0;
1916 } 1917 }
1917 else 1918 else
1918 temp3 = -1.0 * temp3 / (pres_tissue+16)[ci]; 1919 temp3 = -1.0 * temp3 / (pres_tissue+16)[ci];
1919 if (temp3 > 0.0) 1920 if( 0.0 < temp3 && temp3 < 1.0 )
1920 { 1921 {
1921 temp3 = log(1.0 - temp3); 1922 temp3 = log(1.0 - temp3);
1922 temp3 = temp3 / -0.6931; // temp1 is the multiples of half times necessary. 1923 temp3 = temp3 / -0.6931; // temp1 is the multiples of half times necessary.
1923 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested. 1924 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested.
1924 // minus because log is negative 1925 // minus because log is negative
1933 // saturation_time (for flight) 1934 // saturation_time (for flight)
1934 if (temp4 > temp2) 1935 if (temp4 > temp2)
1935 desat_time = (unsigned short)temp4; 1936 desat_time = (unsigned short)temp4;
1936 else 1937 else
1937 desat_time = (unsigned short)temp2; 1938 desat_time = (unsigned short)temp2;
1938 if(desat_time > int_O_desaturation_time) 1939
1939 int_O_desaturation_time = desat_time; 1940 if(desat_time > int_O_desaturation_time)
1941 int_O_desaturation_time = desat_time;
1940 1942
1941 // N2 saturation in multiples of halftime for display purposes 1943 // N2 saturation in multiples of halftime for display purposes
1942 temp2 = temp1 * 20.0; // 0 = 1/8, 120 = 0, 249 = 8 1944 temp2 = temp1 * 20.0; // 0 = 1/8, 120 = 0, 249 = 8
1943 temp2 = temp2 + 80.0; // set center 1945 temp2 = temp2 + 80.0; // set center
1944 if (temp2 < 0.0) 1946 if (temp2 < 0.0)
1965 // optimized in v.101 (...saturation_multiplier) 1967 // optimized in v.101 (...saturation_multiplier)
1966 // desaturation slowed down to 70,42% 1968 // desaturation slowed down to 70,42%
1967 // 1969 //
1968 static void calc_wo_deco_step_1_min(void) 1970 static void calc_wo_deco_step_1_min(void)
1969 { 1971 {
1972 assert( 800 < int_I_pres_surface && int_I_pres_surface < 1100 );
1973 assert( 800 < int_I_pres_respiration && int_I_pres_respiration < 1100 );
1974 assert( 100 <= char_I_saturation_multiplier && char_I_saturation_multiplier < 200 );
1975 assert( 0 < char_I_desaturation_multiplier && char_I_desaturation_multiplier <= 100 );
1976
1970 if(flag_in_divemode) 1977 if(flag_in_divemode)
1971 { 1978 {
1972 flag_in_divemode = 0; 1979 flag_in_divemode = 0;
1973 set_dbg_end_of_dive(); 1980 set_dbg_end_of_dive();
1974 } 1981 }