comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 200:0a3ca358c684

BUGFIX clear decotable at begin of simulator mode. + minor P2_deco cleanups and comments.
author JeanDo
date Mon, 14 Feb 2011 23:15:40 +0100
parents f15e804ff67f
children e5c484d59a91
comparison
equal deleted inserted replaced
199:f5e9db793dd3 200:0a3ca358c684
73 // 73 //
74 // TODO: 74 // TODO:
75 // + Allow to abort MD2 calculation (have to restart next time). 75 // + Allow to abort MD2 calculation (have to restart next time).
76 // 76 //
77 // Literature: 77 // Literature:
78 // B"uhlmann, Albert: Tauchmedizin; 4. Auflage; 78 // Bühlmann, Albert: Tauchmedizin; 4. Auflage [2002];
79 // Schr"oder, Kai & Reith, Steffen; 2000; S"attigungsvorg"ange beim Tauchen, das Modell ZH-L16, Funktionsweise von Tauchcomputern; http://www.achim-und-kai.de/kai/tausim/saett_faq 79 // Schr"oder, Kai & Reith, Steffen; 2000; S"attigungsvorg"ange beim Tauchen, das Modell ZH-L16, Funktionsweise von Tauchcomputern; http://www.achim-und-kai.de/kai/tausim/saett_faq
80 // Morrison, Stuart; 2000; DIY DECOMPRESSION; http://www.lizardland.co.uk/DIYDeco.html 80 // Morrison, Stuart; 2000; DIY DECOMPRESSION; http://www.lizardland.co.uk/DIYDeco.html
81 // Balthasar, Steffen; Dekompressionstheorie I: Neo Haldane Modelle; http://www.txfreak.de/dekompressionstheorie_1.pdf 81 // Balthasar, Steffen; Dekompressionstheorie I: Neo Haldane Modelle; http://www.txfreak.de/dekompressionstheorie_1.pdf
82 // Baker, Erik C.; Clearing Up The Confusion About "Deep Stops" 82 // Baker, Erik C.; Clearing Up The Confusion About "Deep Stops"
83 // Baker, Erik C.; Understanding M-values; http://www.txfreak.de/understanding_m-values.pdf 83 // Baker, Erik C.; Understanding M-values; http://www.txfreak.de/understanding_m-values.pdf
94 // *********************************************** 94 // ***********************************************
95 95
96 #include "p2_definitions.h" 96 #include "p2_definitions.h"
97 #include "shared_definitions.h" 97 #include "shared_definitions.h"
98 98
99 // Water vapour partial pressure in the lumb.
100 static const float ppWVapour = 0.0627;
101
99 // ************************* 102 // *************************
100 // ** P R O T O T Y P E S ** 103 // ** P R O T O T Y P E S **
101 // ************************* 104 // *************************
102 105
103 static void calc_hauptroutine(void); 106 static void calc_hauptroutine(void);
104 static void calc_nullzeit(void); 107 static void calc_nullzeit(void);
105 108
106 static void calc_tissue(PARAMETER unsigned char period); 109 static void calc_tissue(PARAMETER unsigned char period);
107 static void calc_limit(PARAMETER float GF_current); 110 static void calc_limit(PARAMETER float GF_current);
108 111
109 static void calc_wo_deco_step_2s(void);
110 static void clear_tissue(void); 112 static void clear_tissue(void);
111 static void calc_ascenttime(void); 113 static void calc_ascenttime(void);
112 static void update_startvalues(void); 114 static void update_startvalues(void);
113 static void clear_deco_table(void); 115 static void clear_deco_table(void);
114 static void update_deco_table(void); 116 static void update_deco_table(void);
125 static void calc_hauptroutine_calc_deco(void); 127 static void calc_hauptroutine_calc_deco(void);
126 static void sim_ascent_to_first_stop(void); 128 static void sim_ascent_to_first_stop(void);
127 129
128 static void calc_nextdecodepth(void); 130 static void calc_nextdecodepth(void);
129 131
130 //---- Bank 3 parameters ----------------------------------------------------- 132 //---- Bank 4 parameters -----------------------------------------------------
131 #pragma udata bank4=0x400 133 #pragma udata bank4=0x400
132 134
133 static unsigned char low_depth; 135 static unsigned char low_depth;
134 static float temp_limit; 136 static float temp_limit;
135 static float GF_low; 137 static float GF_low;
157 #pragma udata bank5=0x500 159 #pragma udata bank5=0x500
158 160
159 static unsigned char ci; 161 static unsigned char ci;
160 static float pres_respiration; 162 static float pres_respiration;
161 static float pres_surface; 163 static float pres_surface;
162 static float temp1;
163 static float temp_deco; 164 static float temp_deco;
164 static float temp_atem; 165 static float ppO2;
165 static float temp2_atem; 166 static float ppHe;
166 static float temp_tissue; 167 static float temp_tissue;
167 static float N2_ratio; 168 static float N2_ratio; // Breathed gas nitrogen ratio.
168 static float He_ratio; 169 static float He_ratio; // Breathed gas helium ratio.
169 static float var_N2_a; 170 static float var_N2_a; // Bühlmann a, for current N2 tissue.
170 static float var_N2_b; 171 static float var_N2_b; // Bühlmann b, for current N2 tissue.
171 static float var_He_a; 172 static float var_He_a; // Bühlmann a, for current He tissue.
172 static float var_He_b; 173 static float var_He_b; // Bühlmann b, for current He tissue.
173 static float var_N2_e; 174 static float var_N2_e; // Exposition, for current N2 tissue.
174 static float var_He_e; 175 static float var_He_e; // Exposition, for current He tissue.
175 static float var_N2_halftime;
176 static float var_He_halftime;
177 176
178 static float pres_diluent; // new in v.101 177 static float pres_diluent; // new in v.101
179 static float deco_diluent; // new in v.101 178 static float deco_diluent; // new in v.101
180 static float const_ppO2; // new in v.101 179 static float const_ppO2; // new in v.101
181 static float deco_ppO2_change; // new in v.101 180 static float deco_ppO2_change; // new in v.101
182 static float deco_ppO2; // new in v.101 181 static float deco_ppO2; // new in v.101
183 182
184 static unsigned char sim_gas_last_used; // Last used gas, to detected a gas switch. 183 static unsigned char sim_gas_last_used; // Last used gas, to detected a gas switch.
185 static unsigned char sim_gas_delay; // Delay added for gas switch (count down) [min]. 184 static unsigned char sim_gas_delay; // Delay added for gas switch (count down) [min].
186 static float calc_N2_ratio; // new in v.101 185 static float calc_N2_ratio; // Simulated (switched) nitrogen ratio.
187 static float calc_He_ratio; // new in v.101 186 static float calc_He_ratio; // Simulated (switched) helium ratio.
188 static float CNS_fraction; // new in v.101 187 static float CNS_fraction; // new in v.101
189 static float float_saturation_multiplier; // new in v.101 188 static float float_saturation_multiplier; // new in v.101
190 static float float_desaturation_multiplier; // new in v.101 189 static float float_desaturation_multiplier; // new in v.101
191 static float float_deco_distance; // new in v.101 190 static float float_deco_distance; // new in v.101
192 static char flag_in_divemode; // new in v.108 191 static char flag_in_divemode; // new in v.108
193 192
194 static float deco_gas_change1; // new in v.101 193 static float deco_gas_change1; // new in v.101
195 static float deco_gas_change2; // new in v.109 194 static float deco_gas_change2; // new in v.109
405 // DBG - multi main during dive 404 // DBG - multi main during dive
406 // 405 //
407 static void check_dbg(PARAMETER char is_post_check) 406 static void check_dbg(PARAMETER char is_post_check)
408 { 407 {
409 overlay unsigned int temp_DBS = 0; 408 overlay unsigned int temp_DBS = 0;
410 overlay char i; // Local loop index. 409 overlay unsigned char i; // Local loop index.
411 410
412 if( (DBG_N2_ratio != N2_ratio) || (DBG_He_ratio != He_ratio) ) 411 if( (DBG_N2_ratio != N2_ratio) || (DBG_He_ratio != He_ratio) )
413 temp_DBS |= DBG_c_gas; 412 temp_DBS |= DBG_c_gas;
414 if(DBG_const_ppO2 != const_ppO2) 413 if(DBG_const_ppO2 != const_ppO2)
415 temp_DBS |= DBG_c_ppO2; 414 temp_DBS |= DBG_c_ppO2;
840 calc_hauptroutine(); 839 calc_hauptroutine();
841 int_O_desaturation_time = 65535; 840 int_O_desaturation_time = 65535;
842 } 841 }
843 842
844 ////////////////////////////////////////////////////////////////////////////// 843 //////////////////////////////////////////////////////////////////////////////
845
846 void deco_calc_without_deco(void)
847 {
848 RESET_C_STACK
849 calc_wo_deco_step_2s();
850 deco_calc_desaturation_time();
851 }
852
853 //////////////////////////////////////////////////////////////////////////////
854 // Reset decompression model: 844 // Reset decompression model:
855 // + Set all tissues to equilibrium with Air at ambient pressure. 845 // + Set all tissues to equilibrium with Air at ambient pressure.
856 // + Reset last stop to 0m 846 // + Reset last stop to 0m
857 // + Reset all model output. 847 // + Reset all model output.
858 void deco_clear_tissue(void) 848 void deco_clear_tissue(void)
865 855
866 void deco_calc_wo_deco_step_1_min(void) 856 void deco_calc_wo_deco_step_1_min(void)
867 { 857 {
868 RESET_C_STACK 858 RESET_C_STACK
869 calc_wo_deco_step_1_min(); 859 calc_wo_deco_step_1_min();
870 char_O_deco_status = 3; // surface new in v.102 overwrites value of calc_wo_deco_step_1_min
871 deco_calc_desaturation_time(); 860 deco_calc_desaturation_time();
872 } 861 }
873 862
874 ////////////////////////////////////////////////////////////////////////////// 863 //////////////////////////////////////////////////////////////////////////////
875 864
900 pres_respiration = (float)int_I_pres_respiration / 1000.0; 889 pres_respiration = (float)int_I_pres_respiration / 1000.0;
901 890
902 for(ci=0; ci<16; ci++) 891 for(ci=0; ci<16; ci++)
903 { 892 {
904 // cycle through the 16 Bühlmann tissues 893 // cycle through the 16 Bühlmann tissues
905 overlay float p = N2_ratio * (pres_respiration - 0.0627); 894 overlay float p = N2_ratio * (pres_respiration - ppWVapour);
906 pres_tissue[ci] = p; 895 pres_tissue[ci] = p;
907 896
908 read_buhlmann_coefficients(-1); 897 read_buhlmann_coefficients(-1);
909 898
910 p = (p - var_N2_a) * var_N2_b ; 899 p = (p - var_N2_a) * var_N2_b ;
921 char_O_nullzeit = 0; 910 char_O_nullzeit = 0;
922 int_O_ascenttime = 0; 911 int_O_ascenttime = 0;
923 char_O_gradient_factor = 0; 912 char_O_gradient_factor = 0;
924 char_O_relative_gradient_GF = 0; 913 char_O_relative_gradient_GF = 0;
925 char_I_depth_last_deco = 0; // for compatibility with v.101pre_no_last_deco 914 char_I_depth_last_deco = 0; // for compatibility with v.101pre_no_last_deco
926 }
927
928 //////////////////////////////////////////////////////////////////////////////
929 // calc_wo_deco_step_2s
930 //
931 // optimized in v.101 (float_..saturation_multiplier)
932 //
933 // Note: fixed N2_ratio for standard air.
934
935 static void calc_wo_deco_step_2s(void)
936 {
937 N2_ratio = 0.7902; // Sum as stated in b"uhlmann
938 pres_respiration = (float)int_I_pres_respiration / 1000.0; // assembler code uses different digit system
939 pres_surface = (float)int_I_pres_surface / 1000.0; // the b"uhlmann formula using pres_surface does apply to the pressure without any inert ratio
940 temp_atem = N2_ratio * (pres_respiration - 0.0627); // 0.0627 is the extra pressure in the body
941 temp2_atem = 0.0;
942 float_desaturation_multiplier = char_I_desaturation_multiplier * 0.01;
943 float_saturation_multiplier = char_I_saturation_multiplier * 0.01;
944
945 calc_tissue(0); // update the pressure in the 32 tissues in accordance with the new ambient pressure for 2 seconds.
946
947 clear_deco_table();
948 char_O_deco_status = 0;
949 char_O_nullzeit = 0;
950 int_O_ascenttime = 0;
951 calc_gradient_factor();
952 } 915 }
953 916
954 ////////////////////////////////////////////////////////////////////////////// 917 //////////////////////////////////////////////////////////////////////////////
955 // calc_hauptroutine 918 // calc_hauptroutine
956 // 919 //
991 switch( char_O_deco_status ) 954 switch( char_O_deco_status )
992 { 955 {
993 case 3: //---- At surface: start a new dive ------------------------------ 956 case 3: //---- At surface: start a new dive ------------------------------
994 clear_deco_table(); 957 clear_deco_table();
995 copy_deco_table(); 958 copy_deco_table();
996 update_startvalues(); 959 low_depth = 0; // Reset GF history.
997 low_depth = 0; 960 int_O_ascenttime = 0; // Reset DTR.
998 char_O_deco_status = 0; // Calc bottom-time/nullzeit next iteration. 961 char_O_nullzeit = 0; // Reset bottom time.
962 char_O_deco_status = 0; // Calc bottom-time/nullzeit next iteration.
999 backup_low_depth = 255; // backup is empty... 963 backup_low_depth = 255; // backup is empty...
1000 break; 964 break;
1001 965
1002 case 0: //---- bottom time ----------------------------------------------- 966 case 0: //---- bottom time -----------------------------------------------
1003 update_startvalues();
1004 calc_nullzeit(); 967 calc_nullzeit();
1005 check_ndl(); 968 check_ndl();
1006 char_O_deco_status = 2; // calc ascent next time. 969 char_O_deco_status = 2; // calc ascent next time.
1007 break; 970 break;
1008 971
1057 // _____________ G A S _ C H A N G E S ________________ 1020 // _____________ G A S _ C H A N G E S ________________
1058 // ____________________________________________________ 1021 // ____________________________________________________
1059 1022
1060 int_temp = (int_I_pres_respiration - int_I_pres_surface) + MBAR_REACH_GASCHANGE_AUTO_CHANGE_OFF; 1023 int_temp = (int_I_pres_respiration - int_I_pres_surface) + MBAR_REACH_GASCHANGE_AUTO_CHANGE_OFF;
1061 1024
1062 deco_gas_change1 = 0; 1025 deco_gas_change1 = 0.0;
1063 deco_gas_change2 = 0; 1026 deco_gas_change2 = 0.0;
1064 deco_gas_change3 = 0; 1027 deco_gas_change3 = 0.0;
1065 deco_gas_change4 = 0; 1028 deco_gas_change4 = 0.0;
1066 deco_gas_change5 = 0; 1029 deco_gas_change5 = 0.0;
1067 1030
1068 if(char_I_deco_gas_change1) 1031 if(char_I_deco_gas_change1)
1069 { 1032 {
1070 overlay int int_temp2 = ((int)char_I_deco_gas_change1) * 100; 1033 overlay int int_temp2 = ((int)char_I_deco_gas_change1) * 100;
1071 if(int_temp > int_temp2) 1034 if(int_temp > int_temp2)
1138 { 1101 {
1139 pres_diluent = ((pres_respiration - const_ppO2)/(N2_ratio + He_ratio)); // new in v.101 1102 pres_diluent = ((pres_respiration - const_ppO2)/(N2_ratio + He_ratio)); // new in v.101
1140 if (pres_diluent > pres_respiration) // new in v.101 1103 if (pres_diluent > pres_respiration) // new in v.101
1141 pres_diluent = pres_respiration; // new in v.101 1104 pres_diluent = pres_respiration; // new in v.101
1142 } 1105 }
1143 if (pres_diluent > 0.0627) // new in v.101 1106 if (pres_diluent > ppWVapour) // new in v.101
1144 { 1107 {
1145 temp_atem = N2_ratio * (pres_diluent - 0.0627); // changed in v.101 1108 ppO2 = N2_ratio * (pres_diluent - ppWVapour); // changed in v.101
1146 temp2_atem = He_ratio * (pres_diluent - 0.0627); // changed in v.101 1109 ppHe = He_ratio * (pres_diluent - ppWVapour); // changed in v.101
1147 char_O_diluent = (char)(pres_diluent/pres_respiration*100.0); 1110 char_O_diluent = (char)(pres_diluent/pres_respiration*100.0);
1148 } 1111 }
1149 else // new in v.101 1112 else // new in v.101
1150 { 1113 {
1151 temp_atem = 0.0; // new in v.101 1114 ppO2 = 0.0; // new in v.101
1152 temp2_atem = 0.0; // new in v.101 1115 ppHe = 0.0; // new in v.101
1153 char_O_diluent = 0; 1116 char_O_diluent = 0;
1154 } 1117 }
1155 1118
1156 if(!char_I_step_is_1min) 1119 if(!char_I_step_is_1min)
1157 calc_tissue(0); 1120 calc_tissue(0);
1247 } 1210 }
1248 } 1211 }
1249 1212
1250 if (deco_diluent > temp_deco) 1213 if (deco_diluent > temp_deco)
1251 deco_diluent = temp_deco; 1214 deco_diluent = temp_deco;
1252 if (deco_diluent > 0.0627) 1215 if (deco_diluent > ppWVapour)
1253 { 1216 {
1254 temp_atem = calc_N2_ratio * (deco_diluent - 0.0627); 1217 ppO2 = calc_N2_ratio * (deco_diluent - ppWVapour);
1255 temp2_atem = calc_He_ratio * (deco_diluent - 0.0627); 1218 ppHe = calc_He_ratio * (deco_diluent - ppWVapour);
1256 } 1219 }
1257 else 1220 else
1258 { 1221 {
1259 temp_atem = 0.0; 1222 ppO2 = 0.0;
1260 temp2_atem = 0.0; 1223 ppHe = 0.0;
1261 } 1224 }
1262 assert( 0.0 <= temp_atem && temp_atem < 14.0 ); 1225 assert( 0.0 <= ppO2 && ppO2 < 14.0 );
1263 assert( 0.0 <= temp2_atem && temp2_atem < 14.0 ); 1226 assert( 0.0 <= ppHe && ppHe < 14.0 );
1264 } 1227 }
1265 1228
1266 ////////////////////////////////////////////////////////////////////////////// 1229 //////////////////////////////////////////////////////////////////////////////
1267 // Compute stops. 1230 // Compute stops.
1268 // 1231 //
1278 // Do not ascent while doing a gas switch. 1241 // Do not ascent while doing a gas switch.
1279 if( sim_gas_delay == 0 ) 1242 if( sim_gas_delay == 0 )
1280 calc_nextdecodepth(); 1243 calc_nextdecodepth();
1281 1244
1282 //---- Finish computations once surface is reached ------------------- 1245 //---- Finish computations once surface is reached -------------------
1283 if( temp_depth_limit <= 0 ) 1246 if( temp_depth_limit == 0 )
1284 { 1247 {
1285 copy_deco_table(); 1248 copy_deco_table();
1286 calc_ascenttime(); 1249 calc_ascenttime();
1287 char_O_deco_status = 0; // calc nullzeit next time. 1250 char_O_deco_status = 0; // calc nullzeit next time.
1288 return; 1251 return;
1314 void sim_ascent_to_first_stop(void) 1277 void sim_ascent_to_first_stop(void)
1315 { 1278 {
1316 update_startvalues(); 1279 update_startvalues();
1317 clear_deco_table(); 1280 clear_deco_table();
1318 1281
1319 temp_deco = pres_respiration; 1282 temp_deco = pres_respiration; // Starts from current real depth.
1320 1283
1321 // Loop until first top or surface is reached. 1284 // Loop until first top or surface is reached.
1322 for(;;) 1285 for(;;)
1323 { 1286 {
1324 // Do not ascent while doing a gas switch. 1287 // Do not ascent while doing a gas switch.
1367 for (ci=0;ci<16;ci++) 1330 for (ci=0;ci<16;ci++)
1368 { 1331 {
1369 read_buhlmann_coefficients(period); // 2 sec or 1 min period. 1332 read_buhlmann_coefficients(period); // 2 sec or 1 min period.
1370 1333
1371 // N2 1334 // N2
1372 temp_tissue = (temp_atem - pres_tissue[ci]) * var_N2_e; 1335 temp_tissue = (ppO2 - pres_tissue[ci]) * var_N2_e;
1373 temp_tissue_safety(); 1336 temp_tissue_safety();
1374 pres_tissue[ci] += temp_tissue; 1337 pres_tissue[ci] += temp_tissue;
1375 1338
1376 // He 1339 // He
1377 temp_tissue = (temp2_atem - (pres_tissue+16)[ci]) * var_He_e; 1340 temp_tissue = (ppHe - (pres_tissue+16)[ci]) * var_He_e;
1378 temp_tissue_safety(); 1341 temp_tissue_safety();
1379 (pres_tissue+16)[ci] += temp_tissue; 1342 (pres_tissue+16)[ci] += temp_tissue;
1380 } 1343 }
1381 } 1344 }
1382 1345
1434 // unchanged in v.101 1397 // unchanged in v.101
1435 // 1398 //
1436 static void calc_nullzeit(void) 1399 static void calc_nullzeit(void)
1437 { 1400 {
1438 overlay int loop; 1401 overlay int loop;
1402 update_startvalues();
1439 1403
1440 char_O_nullzeit = 0; 1404 char_O_nullzeit = 0;
1441 for(loop = 1; loop <= 17; loop++) 1405 for(loop = 1; loop <= 17; loop++)
1442 { 1406 {
1443 backup_sim_pres_tissue(); 1407 backup_sim_pres_tissue();
1545 for(ci=0; ci<16; ci++) 1509 for(ci=0; ci<16; ci++)
1546 { 1510 {
1547 read_buhlmann_coefficients(period); // 1 or 10 minute(s) interval 1511 read_buhlmann_coefficients(period); // 1 or 10 minute(s) interval
1548 1512
1549 // N2 1513 // N2
1550 temp_tissue = (temp_atem - sim_pres_tissue[ci]) * var_N2_e; 1514 temp_tissue = (ppO2 - sim_pres_tissue[ci]) * var_N2_e;
1551 temp_tissue_safety(); 1515 temp_tissue_safety();
1552 sim_pres_tissue[ci] += temp_tissue; 1516 sim_pres_tissue[ci] += temp_tissue;
1553 1517
1554 // He 1518 // He
1555 temp_tissue = (temp2_atem - (sim_pres_tissue+16)[ci]) * var_He_e; 1519 temp_tissue = (ppHe - (sim_pres_tissue+16)[ci]) * var_He_e;
1556 temp_tissue_safety(); 1520 temp_tissue_safety();
1557 (sim_pres_tissue+16)[ci] += temp_tissue; 1521 (sim_pres_tissue+16)[ci] += temp_tissue;
1558 } 1522 }
1559 } 1523 }
1560 1524
1634 // internal_deco_time [] : time (in minutes) of each stops. 1598 // internal_deco_time [] : time (in minutes) of each stops.
1635 // 1599 //
1636 static void update_deco_table() 1600 static void update_deco_table()
1637 { 1601 {
1638 overlay unsigned char x; 1602 overlay unsigned char x;
1603 assert( temp_depth_limit < 128 ); // Can't be negativ (overflown).
1639 1604
1640 for(x=0; x<32; ++x) 1605 for(x=0; x<32; ++x)
1641 { 1606 {
1642 if( internal_deco_depth[x] == temp_depth_limit) 1607 if( internal_deco_depth[x] == temp_depth_limit )
1643 { 1608 {
1644 // Do not overflow (max 255') 1609 // Do not overflow (max 255')
1645 if( internal_deco_time[x] < 255 ) 1610 if( internal_deco_time[x] < 255 )
1646 { 1611 {
1647 internal_deco_time[x]++; 1612 internal_deco_time[x]++;
1728 // unchanged in v.101 1693 // unchanged in v.101
1729 // 1694 //
1730 void deco_calc_desaturation_time(void) 1695 void deco_calc_desaturation_time(void)
1731 { 1696 {
1732 overlay unsigned int desat_time; // For a particular compartiment, in min. 1697 overlay unsigned int desat_time; // For a particular compartiment, in min.
1698 overlay float temp1;
1733 overlay float temp2; 1699 overlay float temp2;
1734 overlay float temp3; 1700 overlay float temp3;
1735 overlay float temp4; 1701 overlay float temp4;
1736 RESET_C_STACK 1702 RESET_C_STACK
1737 1703
1738 N2_ratio = 0.7902; // FIXED sum as stated in b"uhlmann 1704 N2_ratio = 0.7902; // FIXED sum as stated in b"uhlmann
1739 pres_surface = (float)int_I_pres_surface / 1000.0; 1705 pres_surface = (float)int_I_pres_surface / 1000.0;
1740 temp_atem = N2_ratio * (pres_surface - 0.0627); 1706 ppO2 = N2_ratio * (pres_surface - ppWVapour);
1741 int_O_desaturation_time = 0; 1707 int_O_desaturation_time = 0;
1742 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) 1708 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142)
1743 1709
1744 for (ci=0;ci<16;ci++) 1710 for (ci=0;ci<16;ci++)
1745 { 1711 {
1746 var_N2_halftime = buhlmann_ht[ci]; 1712 overlay float var_N2_halftime = buhlmann_ht[ci];
1747 var_He_halftime = (buhlmann_ht+16)[ci]; 1713 overlay float var_He_halftime = (buhlmann_ht+16)[ci];
1748 1714
1749 // saturation_time (for flight) and N2_saturation in multiples of halftime 1715 // saturation_time (for flight) and N2_saturation in multiples of halftime
1750 // version v.100: 1.1 = 10 percent distance to totally clean (totally clean is not possible, would take infinite time ) 1716 // version v.100: 1.1 = 10 percent distance to totally clean (totally clean is not possible, would take infinite time )
1751 // new in version v.101: 1.07 = 7 percent distance to totally clean (totally clean is not possible, would take infinite time ) 1717 // new in version v.101: 1.07 = 7 percent distance to totally clean (totally clean is not possible, would take infinite time )
1752 // changes in v.101: 1.05 = 5 percent dist to totally clean is new desaturation point for display and noFly calculations 1718 // changes in v.101: 1.05 = 5 percent dist to totally clean is new desaturation point for display and noFly calculations
1753 // N2 1719 // N2
1754 temp1 = 1.05 * temp_atem; 1720 temp1 = 1.05 * ppO2;
1755 temp1 = temp1 - pres_tissue[ci]; 1721 temp1 = temp1 - pres_tissue[ci];
1756 temp2 = temp_atem - pres_tissue[ci]; 1722 temp2 = ppO2 - pres_tissue[ci];
1757 if (temp2 >= 0.0) 1723 if (temp2 >= 0.0)
1758 { 1724 {
1759 temp1 = 0; 1725 temp1 = 0;
1760 temp2 = 0; 1726 temp2 = 0;
1761 } 1727 }
1841 } 1807 }
1842 1808
1843 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann 1809 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann
1844 pres_respiration = (float)int_I_pres_respiration / 1000.0; // assembler code uses different digit system 1810 pres_respiration = (float)int_I_pres_respiration / 1000.0; // assembler code uses different digit system
1845 pres_surface = (float)int_I_pres_surface / 1000.0; // the b"uhlmann formula using pres_surface does not use the N2_ratio 1811 pres_surface = (float)int_I_pres_surface / 1000.0; // the b"uhlmann formula using pres_surface does not use the N2_ratio
1846 temp_atem = N2_ratio * (pres_respiration - 0.0627); // 0.0627 is the extra pressure in the body 1812 ppO2 = N2_ratio * (pres_respiration - ppWVapour); // ppWVapour is the extra pressure in the body
1847 temp2_atem = 0.0; 1813 ppHe = 0.0;
1848 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) 1814 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142)
1849 float_saturation_multiplier = char_I_saturation_multiplier * 0.01; 1815 float_saturation_multiplier = char_I_saturation_multiplier * 0.01;
1850 1816
1851 calc_tissue(1); // update the pressure in the 32 tissues in accordance with the new ambient pressure 1817 calc_tissue(1); // update the pressure in the 32 tissues in accordance with the new ambient pressure
1852 1818
1853 clear_deco_table(); 1819 clear_deco_table();
1854 char_O_deco_status = 0; 1820 char_O_deco_status = 3; // surface new in v.102 : stays in surface state.
1855 char_O_nullzeit = 0; 1821 char_O_nullzeit = 0;
1856 int_O_ascenttime = 0; 1822 int_O_ascenttime = 0;
1857 calc_gradient_factor(); 1823 calc_gradient_factor();
1858 } 1824 }
1859 1825
2027 // deco_calc_CNS_decrease_15min 1993 // deco_calc_CNS_decrease_15min
2028 // 1994 //
2029 // new in v.101 1995 // new in v.101
2030 // 1996 //
2031 // calculates the half time of 90 minutes in 6 steps of 15 min 1997 // calculates the half time of 90 minutes in 6 steps of 15 min
1998 // (Used in sleepmode, for low battery mode).
2032 // 1999 //
2033 // Output: char_O_CNS_fraction 2000 // Output: char_O_CNS_fraction
2034 // Uses and Updates: CNS_fraction 2001 // Uses and Updates: CNS_fraction
2035 // 2002 //
2036 void deco_calc_CNS_decrease_15min(void) 2003 void deco_calc_CNS_decrease_15min(void)
2045 // 2012 //
2046 // new in v.101 2013 // new in v.101
2047 // 2014 //
2048 // calculates int_I_temp * char_I_temp / 100 2015 // calculates int_I_temp * char_I_temp / 100
2049 // output is int_I_temp 2016 // output is int_I_temp
2017 //
2018 // Used to compute NoFly remaining time.
2050 2019
2051 void deco_calc_percentage(void) 2020 void deco_calc_percentage(void)
2052 { 2021 {
2053 RESET_C_STACK 2022 RESET_C_STACK
2054 int_I_temp = (int)(int_I_temp * (char_I_temp / 100.0)); 2023 int_I_temp = (int)(int_I_temp * (char_I_temp / 100.0));