comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 233:2cbaa01dac26

Hunting for NoFly (bug BB13)... not found yet... + In DEBUG compile, keep simulated dives in logbook, desat and nofly time, etc.
author JeanDo
date Tue, 15 Mar 2011 19:16:34 +0100
parents 24cd6e256d61
children bb8940caebe1
comparison
equal deleted inserted replaced
232:59c479181724 233:2cbaa01dac26
96 96
97 #include "p2_definitions.h" 97 #include "p2_definitions.h"
98 #include "shared_definitions.h" 98 #include "shared_definitions.h"
99 99
100 // Water vapour partial pressure in the lumb. 100 // Water vapour partial pressure in the lumb.
101 static const float ppWVapour = 0.0627; 101 #define ppWVapour 0.0627
102 102
103 // ************************* 103 // *************************
104 // ** P R O T O T Y P E S ** 104 // ** P R O T O T Y P E S **
105 // ************************* 105 // *************************
106 106
1780 ////////////////////////////////////////////////////////////////////////////// 1780 //////////////////////////////////////////////////////////////////////////////
1781 // deco_calc_desaturation_time 1781 // deco_calc_desaturation_time
1782 // 1782 //
1783 // FIXED N2_ratio 1783 // FIXED N2_ratio
1784 // unchanged in v.101 1784 // unchanged in v.101
1785 // Inputs: int_I_pres_surface, ppWVapour, char_I_desaturation_multiplier
1786 // Outputs: int_O_desaturation_time, char_O_tissue_saturation[0..31]
1785 // 1787 //
1786 void deco_calc_desaturation_time(void) 1788 void deco_calc_desaturation_time(void)
1787 { 1789 {
1788 overlay unsigned short desat_time; // For a particular compartiment, in min. 1790 overlay unsigned short desat_time; // For a particular compartiment, in min.
1789 overlay float temp1; 1791 overlay float temp1;
1790 overlay float temp2; 1792 overlay float temp2;
1791 overlay float temp3; 1793 overlay float temp3;
1792 overlay float temp4; 1794 overlay float temp4;
1793 RESET_C_STACK 1795 RESET_C_STACK
1794 1796
1797 assert( 800 < int_I_pres_surface && int_I_pres_surface < 1100 );
1798 assert( 0 < char_I_desaturation_multiplier && char_I_desaturation_multiplier <= 100 );
1799
1795 N2_ratio = 0.7902; // FIXED sum as stated in b"uhlmann 1800 N2_ratio = 0.7902; // FIXED sum as stated in b"uhlmann
1796 pres_surface = (float)int_I_pres_surface / 1000.0; 1801 pres_surface = int_I_pres_surface * 0.001;
1797 ppO2 = N2_ratio * (pres_surface - ppWVapour); 1802 ppO2 = N2_ratio * (pres_surface - ppWVapour);
1798 int_O_desaturation_time = 0; 1803 int_O_desaturation_time = 0;
1799 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) 1804 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142)
1800 1805
1801 for (ci=0;ci<16;ci++) 1806 for (ci=0;ci<16;ci++)
1802 { 1807 {
1803 overlay float var_N2_halftime = buhlmann_ht[ci]; 1808 overlay float var_N2_halftime = buhlmann_ht[ci];
1804 overlay float var_He_halftime = (buhlmann_ht+16)[ci]; 1809 overlay float var_He_halftime = (buhlmann_ht+16)[ci];
1805 1810
1811 temp1 = 1.05 * ppO2; 1816 temp1 = 1.05 * ppO2;
1812 temp1 = temp1 - pres_tissue[ci]; 1817 temp1 = temp1 - pres_tissue[ci];
1813 temp2 = ppO2 - pres_tissue[ci]; 1818 temp2 = ppO2 - pres_tissue[ci];
1814 if (temp2 >= 0.0) 1819 if (temp2 >= 0.0)
1815 { 1820 {
1816 temp1 = 0; 1821 temp1 = 0.0;
1817 temp2 = 0; 1822 temp2 = 0.0;
1818 } 1823 }
1819 else 1824 else
1820 temp1 = temp1 / temp2; 1825 temp1 = temp1 / temp2;
1821 if (temp1 > 0.0) 1826 if (temp1 > 0.0)
1822 { 1827 {
1826 // minus because log is negative 1831 // minus because log is negative
1827 temp2 = var_N2_halftime * temp1 / float_desaturation_multiplier; // time necessary (in minutes ) for complete desaturation (see comment about 10 percent) , new in v.101: float_desaturation_multiplier 1832 temp2 = var_N2_halftime * temp1 / float_desaturation_multiplier; // time necessary (in minutes ) for complete desaturation (see comment about 10 percent) , new in v.101: float_desaturation_multiplier
1828 } 1833 }
1829 else 1834 else
1830 { 1835 {
1831 temp1 = 0; 1836 temp1 = 0.0;
1832 temp2 = 0; 1837 temp2 = 0.0;
1833 } 1838 }
1834 1839
1835 // He 1840 // He
1836 temp3 = 0.1 - (pres_tissue+16)[ci]; 1841 temp3 = 0.1 - (pres_tissue+16)[ci];
1837 if (temp3 >= 0.0) 1842 if (temp3 >= 0.0)
1838 { 1843 {
1839 temp3 = 0; 1844 temp3 = 0.0;
1840 temp4 = 0; 1845 temp4 = 0.0;
1841 } 1846 }
1842 else 1847 else
1843 temp3 = -1.0 * temp3 / (pres_tissue+16)[ci]; 1848 temp3 = -1.0 * temp3 / (pres_tissue+16)[ci];
1844 if (temp3 > 0.0) 1849 if (temp3 > 0.0)
1845 { 1850 {
1849 // minus because log is negative 1854 // minus because log is negative
1850 temp4 = var_He_halftime * temp3 / float_desaturation_multiplier; // time necessary (in minutes ) for "complete" desaturation, new in v.101 float_desaturation_multiplier 1855 temp4 = var_He_halftime * temp3 / float_desaturation_multiplier; // time necessary (in minutes ) for "complete" desaturation, new in v.101 float_desaturation_multiplier
1851 } 1856 }
1852 else 1857 else
1853 { 1858 {
1854 temp3 = 0; 1859 temp3 = 0.0;
1855 temp4 = 0; 1860 temp4 = 0.0;
1856 } 1861 }
1857 1862
1858 // saturation_time (for flight) 1863 // saturation_time (for flight)
1859 if (temp4 > temp2) 1864 if (temp4 > temp2)
1860 desat_time = (unsigned short)temp4; 1865 desat_time = (unsigned short)temp4;
1869 if (temp2 < 0.0) 1874 if (temp2 < 0.0)
1870 temp2 = 0.0; 1875 temp2 = 0.0;
1871 if (temp2 > 255.0) 1876 if (temp2 > 255.0)
1872 temp2 = 255.0; 1877 temp2 = 255.0;
1873 char_O_tissue_saturation[ci] = (char)temp2; 1878 char_O_tissue_saturation[ci] = (char)temp2;
1879
1874 // He saturation in multiples of halftime for display purposes 1880 // He saturation in multiples of halftime for display purposes
1875 temp4 = temp3 * 20.0; // 0 = 1/8, 120 = 0, 249 = 8 1881 temp4 = temp3 * 20.0; // 0 = 1/8, 120 = 0, 249 = 8
1876 temp4 = temp4 + 80.0; // set center 1882 temp4 = temp4 + 80.0; // set center
1877 if (temp4 < 0.0) 1883 if (temp4 < 0.0)
1878 temp4 = 0.0; 1884 temp4 = 0.0;
1896 flag_in_divemode = 0; 1902 flag_in_divemode = 0;
1897 set_dbg_end_of_dive(); 1903 set_dbg_end_of_dive();
1898 } 1904 }
1899 1905
1900 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann 1906 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann
1901 pres_respiration = int_I_pres_respiration * 0.001; // assembler code uses different digit system 1907 pres_respiration = int_I_pres_respiration * 0.001; // assembler code uses different digit system
1902 pres_surface = int_I_pres_surface * 0.001; // the b"uhlmann formula using pres_surface does not use the N2_ratio 1908 pres_surface = int_I_pres_surface * 0.001; // the b"uhlmann formula using pres_surface does not use the N2_ratio
1903 ppO2 = N2_ratio * (pres_respiration - ppWVapour); // ppWVapour is the extra pressure in the body 1909 ppO2 = N2_ratio * (pres_respiration - ppWVapour); // ppWVapour is the extra pressure in the body
1904 ppHe = 0.0; 1910 ppHe = 0.0;
1905 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) 1911 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142)
1906 float_saturation_multiplier = char_I_saturation_multiplier * 0.01; 1912 float_saturation_multiplier = char_I_saturation_multiplier * 0.01;
1907 1913
1908 calc_tissue(1); // update the pressure in the 32 tissues in accordance with the new ambient pressure 1914 calc_tissue(1); // update the pressure in the 32 tissues in accordance with the new ambient pressure