comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 310:b20fc8c4ac92

Fix EAD/END display (not mm, m with a trailling space)
author JeanDo
date Sun, 01 May 2011 19:55:47 +0200
parents 5bc3467fc421
children b7e4e74c0e17
comparison
equal deleted inserted replaced
309:2f21f7a77608 310:b20fc8c4ac92
102 #include "p2_definitions.h" 102 #include "p2_definitions.h"
103 #define TEST_MAIN 103 #define TEST_MAIN
104 #include "shared_definitions.h" 104 #include "shared_definitions.h"
105 105
106 // Water vapour partial pressure in the lumb. 106 // Water vapour partial pressure in the lumb.
107 #define ppWVapour 0.0627 107 #define ppWater 0.0627
108 108
109 // ************************* 109 // *************************
110 // ** P R O T O T Y P E S ** 110 // ** P R O T O T Y P E S **
111 // ************************* 111 // *************************
112 112
1119 ////////////////////////////////////////////////////////////////////////////// 1119 //////////////////////////////////////////////////////////////////////////////
1120 // 1120 //
1121 // Input: calc_N2_ratio, calc_He_ratio : simulated gas mix. 1121 // Input: calc_N2_ratio, calc_He_ratio : simulated gas mix.
1122 // temp_deco : simulated respiration pressure + security offset (deco_distance) 1122 // temp_deco : simulated respiration pressure + security offset (deco_distance)
1123 // float_deco_distance : security factor. 1123 // float_deco_distance : security factor.
1124 // Water-vapor pressure inside lumbs (ppWVapour). 1124 // Water-vapor pressure inside limbs (ppWater).
1125 // 1125 //
1126 // Output: ppN2, ppHe. 1126 // Output: ppN2, ppHe.
1127 // 1127 //
1128 static void sim_alveolar_presures(void) 1128 static void sim_alveolar_presures(void)
1129 { 1129 {
1138 //---- CCR mode : deco gas switch ? -------------------------------------- 1138 //---- CCR mode : deco gas switch ? --------------------------------------
1139 if( char_I_const_ppO2 != 0 ) 1139 if( char_I_const_ppO2 != 0 )
1140 { 1140 {
1141 // In CCR mode, use calc_XX_ratio instead of XX_ratio. 1141 // In CCR mode, use calc_XX_ratio instead of XX_ratio.
1142 // Note: PPO2 and ratios are known outside the lumbs, so there is no 1142 // Note: PPO2 and ratios are known outside the lumbs, so there is no
1143 // ppWVapour in the equations below: 1143 // ppWater in the equations below:
1144 if( temp_deco > deco_ppO2_change ) 1144 if( temp_deco > deco_ppO2_change )
1145 deco_diluent -= const_ppO2; 1145 deco_diluent -= const_ppO2;
1146 else 1146 else
1147 deco_diluent -= deco_ppO2; 1147 deco_diluent -= deco_ppO2;
1148 deco_diluent /= calc_N2_ratio + calc_He_ratio; 1148 deco_diluent /= calc_N2_ratio + calc_He_ratio;
1149 1149
1150 if (deco_diluent > temp_deco) 1150 if (deco_diluent > temp_deco)
1151 deco_diluent = temp_deco; 1151 deco_diluent = temp_deco;
1152 } 1152 }
1153 1153
1154 if( deco_diluent > ppWVapour ) 1154 if( deco_diluent > ppWater )
1155 { 1155 {
1156 ppN2 = calc_N2_ratio * (deco_diluent - ppWVapour); 1156 ppN2 = calc_N2_ratio * (deco_diluent - ppWater);
1157 ppHe = calc_He_ratio * (deco_diluent - ppWVapour); 1157 ppHe = calc_He_ratio * (deco_diluent - ppWater);
1158 } 1158 }
1159 else 1159 else
1160 { 1160 {
1161 ppN2 = 0.0; 1161 ppN2 = 0.0;
1162 ppHe = 0.0; 1162 ppHe = 0.0;
1187 pres_respiration = int_I_pres_respiration * 0.001; 1187 pres_respiration = int_I_pres_respiration * 0.001;
1188 1188
1189 for(ci=0; ci<16; ci++) 1189 for(ci=0; ci<16; ci++)
1190 { 1190 {
1191 // cycle through the 16 Bühlmann tissues 1191 // cycle through the 16 Bühlmann tissues
1192 overlay float p = N2_ratio * (pres_respiration - ppWVapour); 1192 overlay float p = N2_ratio * (pres_respiration - ppWater);
1193 pres_tissue[ci] = p; 1193 pres_tissue[ci] = p;
1194 1194
1195 // cycle through the 16 Bühlmann tissues for Helium 1195 // cycle through the 16 Bühlmann tissues for Helium
1196 (pres_tissue+16)[ci] = 0.0; 1196 (pres_tissue+16)[ci] = 0.0;
1197 } // for 0 to 16 1197 } // for 0 to 16
1396 1396
1397 char_O_diluent = (char)(pres_diluent/pres_respiration*100.0 + 0.5); 1397 char_O_diluent = (char)(pres_diluent/pres_respiration*100.0 + 0.5);
1398 char_O_diluent_ppO2 = (char)(pres_diluent * (1.0 - N2_ratio - He_ratio) * 100.0 + 0.5); 1398 char_O_diluent_ppO2 = (char)(pres_diluent * (1.0 - N2_ratio - He_ratio) * 100.0 + 0.5);
1399 } 1399 }
1400 1400
1401 if( pres_diluent > ppWVapour ) // new in v.101 1401 if( pres_diluent > ppWater ) // new in v.101
1402 { 1402 {
1403 overlay float EAD, END; 1403 overlay float EAD, END;
1404 1404
1405 ppN2 = N2_ratio * (pres_diluent - ppWVapour); // changed in v.101 1405 ppN2 = N2_ratio * (pres_diluent - ppWater); // changed in v.101
1406 ppHe = He_ratio * (pres_diluent - ppWVapour); // changed in v.101 1406 ppHe = He_ratio * (pres_diluent - ppWater); // changed in v.101
1407 1407
1408 // EAD : Equivalent Air Dive. Equivalent depth for the same N2 level 1408 // EAD : Equivalent Air Dive. Equivalent depth for the same N2 level
1409 // with plain air. 1409 // with plain air.
1410 // ppN2 = 79% * (P_EAD - ppWVapour) 1410 // ppN2 = 79% * (P_EAD - ppWater)
1411 // EAD = (P_EAD - Psurface) * 10 1411 // EAD = (P_EAD - Psurface) * 10
1412 // ie: EAD = (ppN2 / 0.7902 + ppWVapour -Psurface) * 10 1412 // ie: EAD = (ppN2 / 0.7902 + ppWater -Psurface) * 10
1413 EAD = (ppN2 / 0.7902 + ppWVapour - pres_surface) * 9.985; 1413 EAD = (ppN2 / 0.7902 + ppWater - pres_surface) * 9.985;
1414 if( EAD < 0.0 || EAD > 245.5 ) EAD = 0.0; 1414 if( EAD < 0.0 || EAD > 245.5 ) EAD = 0.0;
1415 char_O_EAD = (char)(EAD + 0.5); 1415 char_O_EAD = (char)(EAD + 0.5);
1416 1416
1417 // END : Equivalent Narcotic Dive. 1417 // END : Equivalent Narcotic Dive.
1418 // Here we count O2 as narcotic too. Hence everything but helium (has a narcosis factor of 1418 // Here we count O2 as narcotic too. Hence everything but helium (has a narcosis factor of
1419 // 0.23 btw). Hence the formula becomes: 1419 // 0.23 btw). Hence the formula becomes:
1420 // END * BarPerMeter * (1.0 - 0.0) - ppWVapour + Psurface == Pambient - ppHe - ppWVapour 1420 // END * BarPerMeter * (1.0 - 0.0) - ppWater + Psurface == Pambient - ppHe - ppWater
1421 // ie: END = (Pambient - ppHe - Psurface) * 9.985 1421 // ie: END = (Pambient - ppHe - Psurface) * 9.985
1422 // 1422 //
1423 // Source cited: 1423 // Source cited:
1424 // The Physiology and Medicine of Diving by Peter Bennett and David Elliott, 1424 // The Physiology and Medicine of Diving by Peter Bennett and David Elliott,
1425 // 4th edition, 1993, W.B.Saunders Company Ltd, London. 1425 // 4th edition, 1993, W.B.Saunders Company Ltd, London.
1973 ////////////////////////////////////////////////////////////////////////////// 1973 //////////////////////////////////////////////////////////////////////////////
1974 // deco_calc_desaturation_time 1974 // deco_calc_desaturation_time
1975 // 1975 //
1976 // FIXED N2_ratio 1976 // FIXED N2_ratio
1977 // unchanged in v.101 1977 // unchanged in v.101
1978 // Inputs: int_I_pres_surface, ppWVapour, char_I_desaturation_multiplier 1978 // Inputs: int_I_pres_surface, ppWater, char_I_desaturation_multiplier
1979 // Outputs: int_O_desaturation_time, char_O_tissue_saturation[0..31] 1979 // Outputs: int_O_desaturation_time, char_O_tissue_saturation[0..31]
1980 // 1980 //
1981 void deco_calc_desaturation_time(void) 1981 void deco_calc_desaturation_time(void)
1982 { 1982 {
1983 RESET_C_STACK 1983 RESET_C_STACK
1996 _endasm 1996 _endasm
1997 #endif 1997 #endif
1998 1998
1999 N2_ratio = 0.7902; // FIXED sum as stated in bühlmann 1999 N2_ratio = 0.7902; // FIXED sum as stated in bühlmann
2000 pres_surface = int_I_pres_surface * 0.001; 2000 pres_surface = int_I_pres_surface * 0.001;
2001 ppN2 = N2_ratio * (pres_surface - ppWVapour); 2001 ppN2 = N2_ratio * (pres_surface - ppWater);
2002 int_O_desaturation_time = 0; 2002 int_O_desaturation_time = 0;
2003 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) 2003 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142)
2004 2004
2005 for (ci=0;ci<16;ci++) 2005 for (ci=0;ci<16;ci++)
2006 { 2006 {
2116 } 2116 }
2117 2117
2118 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann 2118 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann
2119 pres_respiration = int_I_pres_respiration * 0.001; // assembler code uses different digit system 2119 pres_respiration = int_I_pres_respiration * 0.001; // assembler code uses different digit system
2120 pres_surface = int_I_pres_surface * 0.001; // the b"uhlmann formula using pres_surface does not use the N2_ratio 2120 pres_surface = int_I_pres_surface * 0.001; // the b"uhlmann formula using pres_surface does not use the N2_ratio
2121 ppN2 = N2_ratio * (pres_respiration - ppWVapour); // ppWVapour is the extra pressure in the body 2121 ppN2 = N2_ratio * (pres_respiration - ppWater); // ppWater is the extra pressure in the body
2122 ppHe = 0.0; 2122 ppHe = 0.0;
2123 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) 2123 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142)
2124 float_saturation_multiplier = char_I_saturation_multiplier * 0.01; 2124 float_saturation_multiplier = char_I_saturation_multiplier * 0.01;
2125 2125
2126 calc_tissue(1); // update the pressure in the 32 tissues in accordance with the new ambient pressure 2126 calc_tissue(1); // update the pressure in the 32 tissues in accordance with the new ambient pressure