Mercurial > public > ostc4
annotate Discovery/Src/vpm.c @ 654:890440ab993a
Introduced new menu tab for addition CCR options:
The Xtra menu tab was only used in dive mode before. The tab is now enabled in surface mode and provide access to scrubber timer functionality. To enables this infrastructure (structure, multilanguage strings etc.) have been added to the sourcecode.
author | Ideenmodellierer |
---|---|
date | Sun, 25 Apr 2021 20:41:19 +0200 |
parents | 305f251cc981 |
children | b7d93ff6b3b2 |
rev | line source |
---|---|
38 | 1 /////////////////////////////////////////////////////////////////////////////// |
2 /// -*- coding: UTF-8 -*- | |
3 /// | |
4 /// \file Discovery/Src/vpm.c | |
5 /// \brief critical_volume comment by hw | |
6 /// \author Heinrichs Weikamp, Erik C. Baker | |
7 /// \date 19-April-2014 | |
8 /// | |
9 /// \details | |
10 /// | |
11 /// $Id$ | |
12 /////////////////////////////////////////////////////////////////////////////// | |
13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh | |
14 /// | |
15 /// This program is free software: you can redistribute it and/or modify | |
16 /// it under the terms of the GNU General Public License as published by | |
17 /// the Free Software Foundation, either version 3 of the License, or | |
18 /// (at your option) any later version. | |
19 /// | |
20 /// This program is distributed in the hope that it will be useful, | |
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 /// GNU General Public License for more details. | |
24 /// | |
25 /// You should have received a copy of the GNU General Public License | |
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
27 ////////////////////////////////////////////////////////////////////////////// | |
28 /// \par Varying Permeability Model (VPM) Decompression Program in c (converted from FORTRAN) | |
29 /// | |
30 /// Author: Erik C. Baker | |
31 /// | |
32 /// "DISTRIBUTE FREELY - CREDIT THE AUTHORS" | |
33 /// | |
34 /// This program extends the 1986 VPM algorithm (Yount & Hoffman) to include | |
35 /// mixed gas, repetitive, and altitude diving. Developments to the algorithm | |
36 /// were made by David E. Yount, Eric B. Maiken, and Erik C. Baker over a | |
37 /// period from 1999 to 2001. This work is dedicated in remembrance of | |
38 /// Professor David E. Yount who passed away on April 27, 2000. | |
39 /// | |
40 /// Notes: | |
41 /// 1. This program uses the sixteen (16) half-time compartments of the | |
42 /// Buhlmann ZH-L16 model. The optional Compartment 1b is used here with | |
43 /// half-times of 1.88 minutes for helium and 5.0 minutes for nitrogen. | |
44 /// | |
45 /// 2. This program uses various DEC, IBM, and Microsoft extensions which | |
46 /// may not be supported by all FORTRAN compilers. Comments are made with | |
47 /// a capital "C" in the first column or an exclamation point "!" placed | |
48 /// in a line after code. An asterisk "*" in column 6 is a continuation | |
49 /// of the previous line. All code, except for line numbers, starts in | |
50 /// column 7. | |
51 /// | |
52 /// 3. Comments and suggestions for improvements are welcome. Please | |
53 /// respond by e-mail to: EBaker@se.aeieng.com | |
54 /// | |
55 /// Acknowledgment: Thanks to Kurt Spaugh for recommendations on how to clean | |
56 /// up the code. | |
57 /// =============================================================================== | |
58 /// Converted to vpmdeco.c using f2c; R.McGinnis (CABER Swe) 5/01 | |
59 /// =============================================================================== | |
60 /// | |
61 /// ************************ Heirichs Weipkamp ************************************** | |
62 /// | |
63 /// The original Yount & Baker code has been adjusted for real life calculation. | |
64 /// | |
65 /// 1) The original main function has been split in several functions | |
66 /// | |
67 /// 2) When the deco zone is reached (while ascending) the gradient factors are kept fix | |
68 /// and critical volume algorithm is switched of. maxfirststopdepth is kept fix | |
69 /// to make shure Boeyls Law algorithm works correctly | |
70 /// | |
71 /// 4) gas_loadings_ascent_descend heeds all gaschanges and CCR support has been added | |
72 /// | |
73 | |
74 #include <stdio.h> | |
75 #include <stdlib.h> | |
76 #include <string.h> | |
77 #include <math.h> | |
78 #include <time.h> | |
79 | |
80 #include "vpm.h" | |
81 #include "decom.h" | |
82 | |
83 #define GAS_N2 0 | |
84 #define GAS_HE 1 | |
85 | |
290 | 86 static const _Bool buehlmannSafety = true; |
38 | 87 /* Common Block Declarations */ |
88 | |
89 extern const float SURFACE_TENSION_GAMMA; //!Adj. Range: 0.015 to 0.065 N/m | |
90 extern const float SKIN_COMPRESSION_GAMMAC; //!Adj. Range: 0.160 to 0.290 N/m | |
91 extern const float UNITS_FACTOR; | |
92 extern const float WATER_VAPOR_PRESSURE; // (Schreiner value) based on respiratory quotien | |
93 extern const float CRIT_VOLUME_PARAMETER_LAMBDA; //!Adj. Range: 6500 to 8300 fsw-min | |
290 | 94 //extern const float GRADIENT_ONSET_OF_IMPERM_ATM; //!Adj. Range: 5.0 to 10.0 atm |
38 | 95 extern const float REGENERATION_TIME_CONSTANT; //!Adj. Range: 10080 to 51840 min |
290 | 96 //extern const float PRESSURE_OTHER_GASES_MMHG; //!Constant value for PO2 up to 2 atm |
38 | 97 extern const float CONSTANT_PRESSURE_OTHER_GASES; // PRESSURE_OTHER_GASES_MMHG / 760. * UNITS_FACTOR; |
98 | |
99 extern const float HELIUM_TIME_CONSTANT[]; | |
100 extern const float NITROGEN_TIME_CONSTANT[]; | |
101 | |
290 | 102 static float minimum_deco_stop_time; |
103 static float run_time, run_time_first_stop; | |
104 static float segment_time; | |
105 static short mix_number; | |
106 static float barometric_pressure; | |
107 static _Bool altitude_dive_algorithm_off; | |
108 static _Bool units_equal_fsw, units_equal_msw; | |
38 | 109 |
110 /* by hw 11.06.2015 to allow */ | |
290 | 111 static float gCNS_VPM; |
38 | 112 |
290 | 113 static float helium_pressure[16], nitrogen_pressure[16]; |
114 static float surface_phase_volume_time[16]; | |
115 static float regenerated_radius_he[16], regenerated_radius_n2[16]; | |
116 static float allowable_gradient_he[16], allowable_gradient_n2[16]; | |
38 | 117 |
118 //_Bool deco_zone_reached; | |
290 | 119 static _Bool critical_volume_algorithm_off; |
120 static float max_first_stop_depth; | |
121 static float max_deco_ceiling_depth; | |
38 | 122 //Boylslaw compensation |
290 | 123 static float deco_gradient_he[16]; |
124 static float deco_gradient_n2[16]; | |
125 static int vpm_calc_what; | |
126 static int count_critical_volume_iteration; | |
127 static short number_of_changes; | |
128 static float depth_change[11]; | |
129 static float step_size_change[11]; | |
130 static float rate_change[11]; | |
131 static short mix_change[11]; | |
38 | 132 |
290 | 133 static const _Bool vpm_b = true; |
38 | 134 |
135 extern const float float_buehlmann_N2_factor_expositon_20_seconds[]; | |
136 extern const float float_buehlmann_He_factor_expositon_20_seconds[]; | |
137 extern const float float_buehlmann_N2_factor_expositon_one_minute[]; | |
138 extern const float float_buehlmann_He_factor_expositon_one_minute[]; | |
139 extern const float float_buehlmann_N2_factor_expositon_five_minutes[]; | |
140 extern const float float_buehlmann_He_factor_expositon_five_minutes[]; | |
141 extern const float float_buehlmann_N2_factor_expositon_one_hour[]; | |
142 extern const float float_buehlmann_He_factor_expositon_one_hour[]; | |
143 | |
290 | 144 static float depth_start_of_deco_calc; |
145 static float depth_start_of_deco_zone; | |
146 static float first_stop_depth; | |
147 static float run_time_start_of_deco_zone; | |
38 | 148 |
290 | 149 static float r_nint(float *x); |
150 static float r_int(float *x); | |
151 static _Bool nullzeit_unter60; | |
152 static int vpm_calc_status; | |
153 static _Bool buehlmann_wait_exceeded = false; | |
38 | 154 |
290 | 155 static SLifeData* pInput = NULL; |
156 static SVpm* pVpm = NULL; | |
157 static SDecoinfo* pDecoInfo = NULL; | |
158 static SDiveSettings* pDiveSettings = NULL; | |
159 | |
160 static float r_nint(float *x) | |
38 | 161 { |
162 return( (*x)>=0 ? | |
163 floorf(*x + 0.5f) : -floorf(0.5f - *x) ); | |
164 } | |
165 | |
290 | 166 static float r_int(float *x) |
38 | 167 { |
168 return( (*x>0) ? floorf(*x) : -floorf(- *x) ); | |
169 } | |
170 | |
171 /** private functions | |
172 */ | |
290 | 173 extern int radius_root_finder (float *a, float *b, float *c,float *low_bound, float *high_bound, float *ending_radius); |
38 | 174 |
290 | 175 static int nuclear_regeneration(float *dive_time);// clock_(); |
176 static int calc_deco_ceiling(float *deco_ceiling_depth,_Bool fallowablw); | |
177 static int critical_volume(float *deco_phase_volume_time); ; | |
178 static int calc_start_of_deco_zone(float *starting_depth, float *rate, float *depth_start_of_deco_zone); | |
179 static int calc_initial_allowable_gradient(void); | |
180 static void decompression_stop(float *deco_stop_depth, float *step_size, _Bool final_deco_calculation); | |
181 static int gas_loadings_ascent_descen(float* helium_pressure, float* nitrogen_pressure, float starting_depth,float ending_depth, float rate,_Bool check_gas_change); | |
182 static int calc_surface_phase_volume_time(void); | |
183 static int calc_max_actual_gradient(float *deco_stop_depth); | |
184 static int projected_ascent(float *starting_depth, float *rate, float *deco_stop_depth, float *step_size); | |
185 static void vpm_calc_deco(void); | |
186 static int vpm_calc_critcal_volume(_Bool begin,_Bool calc_nulltime); | |
187 static int vpm_check_converged(_Bool calc_nulltime); | |
188 static int vpm_calc_final_deco(_Bool begin); | |
189 static void BOYLES_LAW_COMPENSATION (float* First_Stop_Depth,float * Deco_Stop_Depth,float* Step_Size); | |
292 | 190 static int vpm_calc_ndl(void); |
290 | 191 static void vpm_init_1(void); |
192 static void vpm_calc_deco_ceiling(void); | |
38 | 193 |
290 | 194 static void vpm_init_1(void) |
38 | 195 { |
196 units_equal_msw = true; | |
197 units_equal_fsw = false; | |
198 altitude_dive_algorithm_off= true; //!Options: ON or OFF | |
199 minimum_deco_stop_time=1.0; //!Options: float positive number | |
200 critical_volume_algorithm_off= false; //!Options: ON or OFF | |
201 run_time = 0.; | |
202 //barometric_pressure = dive_data.surface * 10; | |
203 | |
204 //mix_number = dive_data.selected_gas + 1; | |
205 | |
206 max_first_stop_depth = 0; | |
207 max_deco_ceiling_depth = 0; | |
208 //deco_zone_reached = false; | |
209 depth_start_of_deco_calc = 0; | |
210 depth_start_of_deco_zone = 0; | |
211 first_stop_depth = 0; | |
212 run_time_start_of_deco_zone = 0; | |
213 | |
214 gCNS_VPM = 0; | |
215 } | |
216 | |
217 float vpm_get_CNS(void) | |
218 { | |
219 return gCNS_VPM; | |
220 } | |
221 | |
222 int vpm_calc(SLifeData* pINPUT, | |
223 SDiveSettings* pSettings, | |
224 SVpm* pVPM, | |
225 SDecoinfo* | |
226 pDECOINFO, | |
227 int calc_what) | |
228 { | |
229 vpm_init_1(); | |
230 //decom_CreateGasChangeList(pSettings, pINPUT); | |
231 vpm_calc_what = calc_what; | |
232 /**clear decoInfo*/ | |
233 pDECOINFO->output_time_to_surface_seconds = 0; | |
234 pDECOINFO->output_ndl_seconds = 0; | |
235 pDECOINFO->output_ceiling_meter = 0; | |
247
3949781096d4
feature: Relative GF to Saturation renames
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
236 pDECOINFO->super_saturation = 0; |
38 | 237 uint8_t tmp_calc_status; |
238 for(int i=0;i<DECOINFO_STRUCT_MAX_STOPS;i++) | |
239 { | |
240 pDECOINFO->output_stop_length_seconds[i] = 0; | |
241 } | |
242 | |
305
305f251cc981
bugfix, consistency: show deco/NDL really after 1 minute divetime
Jan Mulder <jlmulder@xs4all.nl>
parents:
293
diff
changeset
|
243 if(pINPUT->dive_time_seconds_without_surface_time < 60) |
38 | 244 { |
292 | 245 vpm_calc_status = CALC_NDL; |
38 | 246 return vpm_calc_status; |
247 } | |
248 pVpm = pVPM; | |
249 pInput = pINPUT; | |
250 pDecoInfo = pDECOINFO; | |
251 pDiveSettings = pSettings; | |
252 | |
292 | 253 if(vpm_calc_status == CALC_NDL) |
38 | 254 { |
292 | 255 tmp_calc_status = vpm_calc_ndl(); |
38 | 256 } |
257 else | |
258 { | |
259 tmp_calc_status = CALC_BEGIN; | |
260 } | |
261 //Normal Deco calculation | |
292 | 262 if(tmp_calc_status != CALC_NDL) |
38 | 263 { |
264 max_first_stop_depth = pVpm->max_first_stop_depth_save; | |
265 run_time_start_of_deco_zone = pVpm->run_time_start_of_deco_zone_save; | |
266 depth_start_of_deco_zone = pVpm->depth_start_of_deco_zone_save; | |
267 for (int i = 0; i < 16; ++i) { | |
268 helium_pressure[i] = pInput->tissue_helium_bar[i] * 10; | |
269 nitrogen_pressure[i] = pInput->tissue_nitrogen_bar[i] * 10; | |
270 } | |
271 vpm_calc_deco(); | |
272 tmp_calc_status = vpm_calc_critcal_volume(true,false); | |
273 if(vpm_calc_what == DECOSTOPS) | |
274 { | |
275 pVpm->max_first_stop_depth_save = max_first_stop_depth; | |
276 pVpm->run_time_start_of_deco_zone_save = run_time_start_of_deco_zone; | |
277 pVpm->depth_start_of_deco_zone_save = depth_start_of_deco_zone; | |
278 } | |
279 } | |
280 | |
281 //Only Decostops not futute stops | |
282 if(vpm_calc_what == DECOSTOPS) | |
283 vpm_calc_status = tmp_calc_status; | |
284 return vpm_calc_status; | |
285 } | |
286 | |
287 void vpm_saturation_after_ascent(SLifeData* input) | |
288 { | |
289 int i = 0; | |
290 for (i = 0; i < 16; ++i) { | |
291 pInput->tissue_helium_bar[i] = helium_pressure[i] / 10; | |
292 pInput->tissue_nitrogen_bar[i] = nitrogen_pressure[i] / 10; | |
293 } | |
294 pInput->pressure_ambient_bar = pInput->pressure_surface_bar; | |
295 } | |
296 /* =============================================================================== */ | |
297 /* NOTE ABOUT PRESSURE UNITS USED IN CALCULATIONS: */ | |
298 /* It is the convention in decompression calculations to compute all gas */ | |
299 /* loadings, absolute pressures, partial pressures, etc., in the units of */ | |
300 /* depth pressure that you are diving - either feet of seawater (fsw) or */ | |
301 /* meters of seawater (msw). This program follows that convention with the */ | |
302 /* the exception that all VPM calculations are performed in SI units (by */ | |
303 /* necessity). Accordingly, there are several conversions back and forth */ | |
304 /* between the diving pressure units and the SI units. */ | |
305 /* =============================================================================== */ | |
306 /* =============================================================================== */ | |
307 /* FUNCTION SUBPROGRAM FOR GAS LOADING CALCULATIONS - ASCENT AND DESCENT */ | |
308 /* =============================================================================== */ | |
309 | |
310 | |
311 | |
312 /* =============================================================================== */ | |
313 /* SUBROUTINE GAS_LOADINGS_ASCENT_DESCENT */ | |
314 /* Purpose: This subprogram applies the Schreiner equation to update the */ | |
315 /* gas loadings (partial pressures of helium and nitrogen) in the half-time */ | |
316 /* compartments due to a linear ascent or descent segment at a constant rate. */ | |
317 /* =============================================================================== */ | |
318 | |
290 | 319 static int gas_loadings_ascent_descen(float* helium_pressure, |
38 | 320 float* nitrogen_pressure, |
321 float starting_depth, | |
322 float ending_depth, | |
323 float rate,_Bool check_gas_change) | |
324 { | |
325 short i; | |
326 float initial_inspired_n2_pressure, | |
327 initial_inspired_he_pressure, nitrogen_rate, | |
328 last_run_time, | |
329 starting_ambient_pressure, | |
330 ending_ambient_pressure; | |
331 float initial_helium_pressure[16]; | |
332 float initial_nitrogen_pressure[16]; | |
333 float helium_rate; | |
334 float fraction_helium_begin; | |
335 float fraction_helium_end; | |
336 float fraction_nitrogen_begin; | |
337 float fraction_nitrogen_end; | |
338 float ending_depth_tmp = ending_depth; | |
339 float segment_time_tmp = 0; | |
340 /* loop */ | |
341 /* =============================================================================== */ | |
342 /* CALCULATIONS */ | |
343 /* =============================================================================== */ | |
344 segment_time = (ending_depth_tmp - starting_depth) / rate; | |
345 last_run_time = run_time; | |
346 run_time = last_run_time + segment_time; | |
347 do { | |
348 ending_depth_tmp = ending_depth; | |
349 if (starting_depth > ending_depth && check_gas_change && number_of_changes > 1) | |
350 { | |
351 for (i = 1; i < number_of_changes; ++i) | |
352 { | |
353 if (depth_change[i] < starting_depth && depth_change[i] > ending_depth) | |
354 { | |
355 ending_depth_tmp = depth_change[i]; | |
356 break; | |
357 } | |
358 } | |
359 for (i = 1; i < number_of_changes; ++i) | |
360 { | |
361 if (depth_change[i] >= starting_depth) | |
362 { | |
363 mix_number = mix_change[i]; | |
364 } | |
365 } | |
366 } | |
367 segment_time_tmp = (ending_depth_tmp - starting_depth) / rate; | |
368 ending_ambient_pressure = ending_depth_tmp + barometric_pressure; | |
369 starting_ambient_pressure = starting_depth + barometric_pressure; | |
370 decom_get_inert_gases( starting_ambient_pressure / 10, (&pDiveSettings->decogaslist[mix_number]), &fraction_nitrogen_begin, &fraction_helium_begin ); | |
371 decom_get_inert_gases( ending_ambient_pressure / 10, (&pDiveSettings->decogaslist[mix_number]), &fraction_nitrogen_end, &fraction_helium_end ); | |
372 | |
373 initial_inspired_he_pressure = (starting_ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_helium_begin; | |
374 initial_inspired_n2_pressure = (starting_ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_nitrogen_begin; | |
375 //helium_rate = *rate * fraction_helium[mix_number - 1]; | |
376 helium_rate = ((ending_ambient_pressure - WATER_VAPOR_PRESSURE)* fraction_helium_end - initial_inspired_he_pressure)/segment_time_tmp; | |
377 //nitrogen_rate2 = *rate * fraction_nitrogen[mix_number - 1]; | |
378 nitrogen_rate = ((ending_ambient_pressure - WATER_VAPOR_PRESSURE)* fraction_nitrogen_end - initial_inspired_n2_pressure)/segment_time_tmp; | |
379 | |
380 | |
381 decom_oxygen_calculate_cns_stage_SchreinerStyle(segment_time_tmp,&pDiveSettings->decogaslist[mix_number],starting_ambient_pressure/10,ending_ambient_pressure/10,&gCNS_VPM); | |
382 //if(fabs(nitrogen_rate - nitrogen_rate2) > 0.000001) | |
383 //return -2; | |
384 for (i = 1; i <= 16; ++i) | |
385 { | |
386 initial_helium_pressure[i - 1] = helium_pressure[i - 1]; | |
387 initial_nitrogen_pressure[i - 1] = nitrogen_pressure[i - 1]; | |
388 helium_pressure[i - 1] = | |
389 schreiner_equation__2(&initial_inspired_he_pressure, | |
390 &helium_rate, | |
391 &segment_time, | |
392 &HELIUM_TIME_CONSTANT[i - 1], | |
393 &initial_helium_pressure[i - 1]); | |
394 nitrogen_pressure[i - 1] = | |
395 schreiner_equation__2(&initial_inspired_n2_pressure, | |
396 &nitrogen_rate, | |
397 &segment_time, | |
398 &NITROGEN_TIME_CONSTANT[i - 1], | |
399 &initial_nitrogen_pressure[i - 1]); | |
400 | |
401 //nextround??? | |
402 | |
403 } | |
404 starting_depth = ending_depth_tmp; | |
405 } while(ending_depth_tmp > ending_depth); | |
406 | |
407 return 0; | |
408 } /* gas_loadings_ascent_descen */ | |
409 | |
290 | 410 static float last_phase_volume_time[16]; |
411 static float n2_pressure_start_of_deco_zone[16]; | |
412 static float he_pressure_start_of_deco_zone[16]; | |
413 static float phase_volume_time[16]; | |
414 static float n2_pressure_start_of_ascent[16]; | |
415 static float he_pressure_start_of_ascent[16]; | |
416 static float run_time_start_of_deco_calc; | |
417 static float starting_depth; | |
418 static float last_run_time; | |
419 static float deco_phase_volume_time; | |
420 static float run_time_start_of_ascent; | |
421 static float rate; | |
422 static float step_size; | |
423 static _Bool vpm_violates_buehlmann; | |
38 | 424 |
290 | 425 static void vpm_calc_deco(void) |
38 | 426 { |
427 /* System generated locals */ | |
428 | |
429 //float deepest_possible_stop_depth; | |
430 // altitude_of_dive, | |
431 short i; | |
432 int j = 0; | |
433 | |
434 // float rounding_operation; | |
435 | |
436 /* =============================================================================== */ | |
437 /* INPUT PARAMETERS TO BE USED FOR STAGED DECOMPRESSION AND SAVE IN ARRAYS. */ | |
438 /* ASSIGN INITAL PARAMETERS TO BE USED AT START OF ASCENT */ | |
439 /* The user has the ability to change mix, ascent rate, and step size in any */ | |
440 /* combination at any depth during the ascent. */ | |
441 /* =============================================================================== */ | |
442 | |
443 run_time = ((float)pInput->dive_time_seconds )/ 60; | |
444 count_critical_volume_iteration = 0; | |
445 number_of_changes = 1; | |
446 | |
447 barometric_pressure = pInput->pressure_surface_bar * 10; | |
448 depth_change[0] =(pInput->pressure_ambient_bar - pInput->pressure_surface_bar)* 10; | |
449 mix_change[0] = 0; | |
450 rate_change[0 ] = -10;// neu 160215 hw, zuvor: -12; | |
451 step_size_change[0] = 3; | |
452 vpm_violates_buehlmann = false; | |
453 | |
454 for (i = 1; i < BUEHLMANN_STRUCT_MAX_GASES; i++) | |
455 { | |
456 depth_change[i] = 0; | |
457 mix_change[i] = 0; | |
458 } | |
459 j = 0; | |
460 | |
461 for (i = 1; i < BUEHLMANN_STRUCT_MAX_GASES; i++) | |
462 { | |
463 if(pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero >= depth_change[0] + 1) | |
464 continue; | |
465 | |
466 if(pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero <= 0) | |
467 break; | |
468 | |
469 j++; | |
470 number_of_changes ++; | |
471 depth_change[j] = pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero ; | |
472 mix_change[j] = i; | |
473 rate_change[j] = -10;// neu 160215 hw, zuvor: -12; | |
474 step_size_change[j] = 3; | |
475 } | |
476 | |
477 starting_depth = depth_change[0] ; | |
478 mix_number = mix_change[0] ; | |
479 rate = rate_change[0]; | |
480 step_size = step_size_change[0]; | |
481 | |
482 for (i = 0; i < 16; ++i) { | |
483 he_pressure_start_of_ascent[i ] = helium_pressure[i]; | |
484 n2_pressure_start_of_ascent[i] = nitrogen_pressure[i]; | |
485 } | |
486 run_time_start_of_ascent = run_time; | |
487 if(starting_depth <= depth_start_of_deco_zone && vpm_calc_what == DECOSTOPS) | |
488 { | |
489 pVpm->deco_zone_reached = true; | |
490 depth_start_of_deco_calc = starting_depth; | |
491 critical_volume_algorithm_off = true; | |
492 } | |
493 else | |
494 { | |
495 //if(deco_zone_reached) | |
496 //{ | |
497 pVpm->deco_zone_reached = false; | |
498 critical_volume_algorithm_off = false; | |
499 //max_first_stop_depth = 0; | |
500 //max_first_stop_depth_save = 0; | |
501 //} | |
502 /* =============================================================================== */ | |
503 /* BEGIN PROCESS OF ASCENT AND DECOMPRESSION */ | |
504 /* First, calculate the regeneration of critical radii that takes place over */ | |
505 /* the dive time. The regeneration time constant has a time scale of weeks */ | |
506 /* so this will have very little impact on dives of normal length, but will */ | |
507 /* have major impact for saturation dives. */ | |
508 /* =============================================================================== */ | |
509 | |
510 nuclear_regeneration(&run_time); | |
511 | |
512 /* =============================================================================== */ | |
513 /* CALCULATE INITIAL ALLOWABLE GRADIENTS FOR ASCENT */ | |
514 /* This is based on the maximum effective crushing pressure on critical radii */ | |
515 /* in each compartment achieved during the dive profile. */ | |
516 /* =============================================================================== */ | |
517 | |
518 calc_initial_allowable_gradient(); | |
519 | |
520 /* =============================================================================== */ | |
521 /* SAVE VARIABLES AT START OF ASCENT (END OF BOTTOM TIME) SINCE THESE WILL */ | |
522 /* BE USED LATER TO COMPUTE THE FINAL ASCENT PROFILE THAT IS WRITTEN TO THE */ | |
523 /* OUTPUT FILE. */ | |
524 /* The VPM uses an iterative process to compute decompression schedules so */ | |
525 /* there will be more than one pass through the decompression loop. */ | |
526 /* =============================================================================== */ | |
527 | |
528 /* =============================================================================== */ | |
529 /* CALCULATE THE DEPTH WHERE THE DECOMPRESSION ZONE BEGINS FOR THIS PROFILE */ | |
530 /* BASED ON THE INITIAL ASCENT PARAMETERS AND WRITE THE DEEPEST POSSIBLE */ | |
531 /* DECOMPRESSION STOP DEPTH TO THE OUTPUT FILE */ | |
532 /* Knowing where the decompression zone starts is very important. Below */ | |
533 /* that depth there is no possibility for bubble formation because there */ | |
534 /* will be no supersaturation gradients. Deco stops should never start */ | |
535 /* below the deco zone. The deepest possible stop deco stop depth is */ | |
536 /* defined as the next "standard" stop depth above the point where the */ | |
537 /* leading compartment enters the deco zone. Thus, the program will not */ | |
538 /* base this calculation on step sizes larger than 10 fsw or 3 msw. The */ | |
539 /* deepest possible stop depth is not used in the program, per se, rather */ | |
540 /* it is information to tell the diver where to start putting on the brakes */ | |
541 /* during ascent. This should be prominently displayed by any deco program. */ | |
542 /* =============================================================================== */ | |
543 | |
544 calc_start_of_deco_zone(&starting_depth, &rate, &depth_start_of_deco_zone); | |
545 /* =============================================================================== */ | |
546 /* TEMPORARILY ASCEND PROFILE TO THE START OF THE DECOMPRESSION ZONE, SAVE */ | |
547 /* VARIABLES AT THIS POINT, AND INITIALIZE VARIABLES FOR CRITICAL VOLUME LOOP */ | |
548 /* The iterative process of the VPM Critical Volume Algorithm will operate */ | |
549 /* only in the decompression zone since it deals with excess gas volume */ | |
550 /* released as a result of supersaturation gradients (not possible below the */ | |
551 /* decompression zone). */ | |
552 /* =============================================================================== */ | |
553 gas_loadings_ascent_descen(helium_pressure,nitrogen_pressure, starting_depth, depth_start_of_deco_zone, rate, true); | |
554 | |
555 run_time_start_of_deco_zone = run_time; | |
556 depth_start_of_deco_calc = depth_start_of_deco_zone; | |
557 | |
558 for (i = 0; i < 16; ++i) | |
559 { | |
560 pVpm->max_actual_gradient[i] = 0.; | |
561 } | |
562 } | |
563 | |
564 for (i = 0; i < 16; ++i) | |
565 { | |
566 surface_phase_volume_time[i] = 0.; | |
567 last_phase_volume_time[i] = 0.; | |
568 he_pressure_start_of_deco_zone[i] = helium_pressure[i]; | |
569 n2_pressure_start_of_deco_zone[i] = nitrogen_pressure[i]; | |
570 //pVpm->max_actual_gradient[i] = 0.; | |
571 } | |
572 run_time_start_of_deco_calc = run_time; | |
573 } | |
574 /* =============================================================================== */ | |
575 /* START OF CRITICAL VOLUME LOOP */ | |
576 /* This loop operates between Lines 50 and 100. If the Critical Volume */ | |
577 /* Algorithm is toggled "off" in the program settings, there will only be */ | |
578 /* one pass through this loop. Otherwise, there will be two or more passes */ | |
579 /* through this loop until the deco schedule is "converged" - that is when a */ | |
580 /* comparison between the phase volume time of the present iteration and the */ | |
581 /* last iteration is less than or equal to one minute. This implies that */ | |
582 /* the volume of released gas in the most recent iteration differs from the */ | |
583 /* "critical" volume limit by an acceptably small amount. The critical */ | |
584 /* volume limit is set by the Critical Volume Parameter Lambda in the program */ | |
585 /* settings (default setting is 7500 fsw-min with adjustability range from */ | |
586 /* from 6500 to 8300 fsw-min according to Bruce Wienke). */ | |
587 /* =============================================================================== */ | |
588 /* L50: */ | |
589 | |
290 | 590 static float deco_stop_depth; |
591 static int vpm_calc_critcal_volume(_Bool begin, | |
38 | 592 _Bool calc_nulltime) |
593 { /* loop will run continuous there is an exit stateme */ | |
594 | |
595 short i; | |
596 | |
597 float rounding_operation2; | |
598 //float ending_depth; | |
599 float deco_ceiling_depth; | |
600 | |
601 //float deco_time; | |
602 int count = 0; | |
603 _Bool first_stop; | |
604 int dp = 0; | |
605 float tissue_He_saturation[16]; | |
606 float tissue_N2_saturation[16]; | |
607 float vpm_buehlmann_safety_gradient = 1.0f - (((float)pDiveSettings->vpm_conservatism) / 40); | |
608 /* =============================================================================== */ | |
609 /* CALCULATE CURRENT DECO CEILING BASED ON ALLOWABLE SUPERSATURATION */ | |
610 /* GRADIENTS AND SET FIRST DECO STOP. CHECK TO MAKE SURE THAT SELECTED STEP */ | |
611 /* SIZE WILL NOT ROUND UP FIRST STOP TO A DEPTH THAT IS BELOW THE DECO ZONE. */ | |
612 /* =============================================================================== */ | |
613 if(begin) | |
614 { | |
615 if(depth_start_of_deco_calc < max_first_stop_depth ) | |
616 { | |
617 if(vpm_b) | |
618 { | |
619 BOYLES_LAW_COMPENSATION(&max_first_stop_depth, &depth_start_of_deco_calc, &step_size); | |
620 } | |
621 calc_deco_ceiling(&deco_ceiling_depth, false); | |
622 } | |
623 else | |
624 calc_deco_ceiling(&deco_ceiling_depth, true); | |
625 | |
626 | |
627 if (deco_ceiling_depth <= 0.0f) { | |
628 deco_stop_depth = 0.0f; | |
629 } else { | |
630 rounding_operation2 = deco_ceiling_depth / step_size + ( float)0.5f; | |
631 deco_stop_depth = r_nint(&rounding_operation2) * step_size; | |
632 } | |
633 | |
634 // buehlmann safety | |
635 if(buehlmannSafety) | |
636 { | |
637 for (i = 0; i < 16; i++) | |
638 { | |
639 tissue_He_saturation[i] = helium_pressure[i] / 10; | |
640 tissue_N2_saturation[i] = nitrogen_pressure[i] / 10; | |
641 } | |
642 | |
643 if(!decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (deco_stop_depth / 10.0f) + pInput->pressure_surface_bar)) | |
644 { | |
645 | |
646 vpm_violates_buehlmann = true; | |
647 do { | |
648 deco_stop_depth += 3; | |
649 } while (!decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (deco_stop_depth / 10.0f) + pInput->pressure_surface_bar)); | |
650 } | |
651 } | |
652 | |
653 /* =============================================================================== */ | |
654 /* PERFORM A SEPARATE "PROJECTED ASCENT" OUTSIDE OF THE MAIN PROGRAM TO MAKE */ | |
655 /* SURE THAT AN INCREASE IN GAS LOADINGS DURING ASCENT TO THE FIRST STOP WILL */ | |
656 /* NOT CAUSE A VIOLATION OF THE DECO CEILING. IF SO, ADJUST THE FIRST STOP */ | |
657 /* DEEPER BASED ON STEP SIZE UNTIL A SAFE ASCENT CAN BE MADE. */ | |
658 /* Note: this situation is a possibility when ascending from extremely deep */ | |
659 /* dives or due to an unusual gas mix selection. */ | |
660 /* CHECK AGAIN TO MAKE SURE THAT ADJUSTED FIRST STOP WILL NOT BE BELOW THE */ | |
661 /* DECO ZONE. */ | |
662 /* =============================================================================== */ | |
663 if (deco_stop_depth < depth_start_of_deco_calc) | |
664 { | |
665 projected_ascent(&depth_start_of_deco_calc, &rate, &deco_stop_depth, &step_size); | |
666 } | |
667 | |
668 /*if (deco_stop_depth > depth_start_of_deco_zone) { | |
669 printf("\t\n"); | |
670 printf(fmt_905); | |
671 printf(fmt_900); | |
672 printf("\nPROGRAM TERMINATED\n"); | |
673 exit(1); | |
674 }*/ | |
675 | |
676 /* =============================================================================== */ | |
677 /* HANDLE THE SPECIAL CASE WHEN NO DECO STOPS ARE REQUIRED - ASCENT CAN BE */ | |
678 /* MADE DIRECTLY TO THE SURFACE */ | |
679 /* Write ascent data to output file and exit the Critical Volume Loop. */ | |
680 /* =============================================================================== */ | |
681 | |
682 if (deco_stop_depth == 0.0f) | |
683 { | |
684 if(calc_nulltime) | |
685 { | |
686 return CALC_END; | |
687 } | |
688 if(pVpm->deco_zone_reached) | |
689 { | |
690 for(dp = 0;dp < DECOINFO_STRUCT_MAX_STOPS;dp++) | |
691 { | |
692 pDecoInfo->output_stop_length_seconds[dp] = 0; | |
693 } | |
694 pDecoInfo->output_ndl_seconds = 0; | |
695 } | |
696 | |
292 | 697 return CALC_NDL; |
38 | 698 /* exit the critical volume l */ |
699 } | |
700 | |
701 /* =============================================================================== */ | |
702 /* ASSIGN VARIABLES FOR ASCENT FROM START OF DECO ZONE TO FIRST STOP. SAVE */ | |
703 /* FIRST STOP DEPTH FOR LATER USE WHEN COMPUTING THE FINAL ASCENT PROFILE */ | |
704 /* =============================================================================== */ | |
705 deco_stop_depth = fmaxf(deco_stop_depth,(float)pDiveSettings->last_stop_depth_bar * 10); | |
706 starting_depth = depth_start_of_deco_calc; | |
707 first_stop_depth = deco_stop_depth; | |
708 first_stop = true; | |
709 } | |
710 /* =============================================================================== */ | |
711 /* DECO STOP LOOP BLOCK WITHIN CRITICAL VOLUME LOOP */ | |
712 /* This loop computes a decompression schedule to the surface during each */ | |
713 /* iteration of the critical volume loop. No output is written from this */ | |
714 /* loop, rather it computes a schedule from which the in-water portion of the */ | |
715 /* total phase volume time (Deco_Phase_Volume_Time) can be extracted. Also, */ | |
716 /* the gas loadings computed at the end of this loop are used the subroutine */ | |
717 /* which computes the out-of-water portion of the total phase volume time */ | |
718 /* (Surface_Phase_Volume_Time) for that schedule. */ | |
719 | |
720 /* Note that exit is made from the loop after last ascent is made to a deco */ | |
721 /* stop depth that is less than or equal to zero. A final deco stop less */ | |
722 /* than zero can happen when the user makes an odd step size change during */ | |
723 /* ascent - such as specifying a 5 msw step size change at the 3 msw stop! */ | |
724 /* =============================================================================== */ | |
725 | |
726 while(true) /* loop will run continuous there is an break statement */ | |
727 { | |
728 if(starting_depth > deco_stop_depth ) | |
729 gas_loadings_ascent_descen(helium_pressure, nitrogen_pressure, starting_depth, deco_stop_depth, rate,first_stop); | |
730 | |
731 first_stop = false; | |
732 if (deco_stop_depth <= 0.0f) | |
733 { | |
734 break; | |
735 } | |
736 if (number_of_changes > 1) | |
737 { | |
738 int i1 = number_of_changes; | |
739 for (i = 2; i <= i1; ++i) { | |
740 if (depth_change[i - 1] >= deco_stop_depth) | |
741 { | |
742 mix_number = mix_change[i - 1]; | |
743 rate = rate_change[i - 1]; | |
744 step_size = step_size_change[i - 1]; | |
745 } | |
746 } | |
747 } | |
748 if(vpm_b) | |
749 { | |
750 float fist_stop_depth2 = fmaxf(first_stop_depth,max_first_stop_depth); | |
751 BOYLES_LAW_COMPENSATION(&fist_stop_depth2, &deco_stop_depth, &step_size); | |
752 } | |
753 decompression_stop(&deco_stop_depth, &step_size, false); | |
754 starting_depth = deco_stop_depth; | |
755 | |
756 if(deco_stop_depth == (float)pDiveSettings->last_stop_depth_bar * 10) | |
757 deco_stop_depth = 0; | |
758 else | |
759 { | |
760 deco_stop_depth = deco_stop_depth - step_size; | |
761 deco_stop_depth = fmaxf(deco_stop_depth,(float)pDiveSettings->last_stop_depth_bar * 10); | |
762 } | |
763 | |
764 count++; | |
765 //if(count > 14) | |
766 //return CALC_CRITICAL2; | |
767 /* L60: */ | |
768 } | |
769 | |
770 return vpm_check_converged(calc_nulltime); | |
771 } | |
772 /* =============================================================================== */ | |
773 /* COMPUTE TOTAL PHASE VOLUME TIME AND MAKE CRITICAL VOLUME COMPARISON */ | |
774 /* The deco phase volume time is computed from the run time. The surface */ | |
775 /* phase volume time is computed in a subroutine based on the surfacing gas */ | |
776 /* loadings from previous deco loop block. Next the total phase volume time */ | |
777 /* (in-water + surface) for each compartment is compared against the previous */ | |
778 /* total phase volume time. The schedule is converged when the difference is */ | |
779 /* less than or equal to 1 minute in any one of the 16 compartments. */ | |
780 | |
781 /* Note: the "phase volume time" is somewhat of a mathematical concept. */ | |
782 /* It is the time divided out of a total integration of supersaturation */ | |
783 /* gradient x time (in-water and surface). This integration is multiplied */ | |
784 /* by the excess bubble number to represent the amount of free-gas released */ | |
785 /* as a result of allowing a certain number of excess bubbles to form. */ | |
786 /* =============================================================================== */ | |
787 /* end of deco stop loop */ | |
788 | |
290 | 789 static int vpm_check_converged(_Bool calc_nulltime) |
38 | 790 { |
791 | |
792 short i; | |
793 float critical_volume_comparison; | |
794 float r1; | |
795 _Bool schedule_converged = false; | |
796 | |
797 | |
798 deco_phase_volume_time = run_time - run_time_start_of_deco_zone; | |
799 calc_surface_phase_volume_time(); | |
800 | |
801 for (i = 1; i <= 16; ++i) | |
802 { | |
803 phase_volume_time[i - 1] = | |
804 deco_phase_volume_time + surface_phase_volume_time[i - 1]; | |
805 critical_volume_comparison = (r1 = phase_volume_time[i - 1] - last_phase_volume_time[i - 1], fabs(r1)); | |
806 | |
807 if (critical_volume_comparison <= 1.0f) | |
808 { | |
809 schedule_converged = true; | |
810 } | |
811 } | |
812 | |
813 /* =============================================================================== */ | |
814 /* CRITICAL VOLUME DECISION TREE BETWEEN LINES 70 AND 99 */ | |
815 /* There are two options here. If the Critical Volume Agorithm setting is */ | |
816 /* "on" and the schedule is converged, or the Critical Volume Algorithm */ | |
817 /* setting was "off" in the first place, the program will re-assign variables */ | |
818 /* to their values at the start of ascent (end of bottom time) and process */ | |
819 /* a complete decompression schedule once again using all the same ascent */ | |
820 /* parameters and first stop depth. This decompression schedule will match */ | |
821 /* the last iteration of the Critical Volume Loop and the program will write */ | |
822 /* the final deco schedule to the output file. */ | |
823 | |
824 /* Note: if the Critical Volume Agorithm setting was "off", the final deco */ | |
825 /* schedule will be based on "Initial Allowable Supersaturation Gradients." */ | |
826 /* If it was "on", the final schedule will be based on "Adjusted Allowable */ | |
827 /* Supersaturation Gradients" (gradients that are "relaxed" as a result of */ | |
828 /* the Critical Volume Algorithm). */ | |
829 | |
830 /* If the Critical Volume Agorithm setting is "on" and the schedule is not */ | |
831 /* converged, the program will re-assign variables to their values at the */ | |
832 /* start of the deco zone and process another trial decompression schedule. */ | |
833 /* =============================================================================== */ | |
834 /* L70: */ | |
835 //Not more than 4 iteration allowed | |
836 count_critical_volume_iteration++; | |
837 if(count_critical_volume_iteration > 4) | |
838 { | |
839 //return CALC_FINAL_DECO; | |
840 if(calc_nulltime) | |
841 return CALC_FINAL_DECO; | |
842 else | |
843 return vpm_calc_final_deco(true); | |
844 } | |
845 if (schedule_converged || critical_volume_algorithm_off) | |
846 { | |
847 | |
848 //return CALC_FINAL_DECO; | |
849 if(calc_nulltime) | |
850 return CALC_FINAL_DECO; | |
851 else | |
852 return vpm_calc_final_deco(true); | |
853 /* final deco schedule */ | |
854 /* exit critical volume l */ | |
855 | |
856 /* =============================================================================== */ | |
857 /* IF SCHEDULE NOT CONVERGED, COMPUTE RELAXED ALLOWABLE SUPERSATURATION */ | |
858 /* GRADIENTS WITH VPM CRITICAL VOLUME ALGORITHM AND PROCESS ANOTHER */ | |
859 /* ITERATION OF THE CRITICAL VOLUME LOOP */ | |
860 /* =============================================================================== */ | |
861 | |
862 } else { | |
863 critical_volume(&deco_phase_volume_time); | |
864 deco_phase_volume_time = 0.; | |
865 run_time = run_time_start_of_deco_calc; | |
866 starting_depth = depth_start_of_deco_calc; | |
867 mix_number = mix_change[0]; | |
868 rate = rate_change[0]; | |
869 step_size = step_size_change[0]; | |
870 for (i = 1; i <= 16; ++i) | |
871 { | |
872 last_phase_volume_time[i - 1] = phase_volume_time[i - 1]; | |
873 helium_pressure[i - 1] = he_pressure_start_of_deco_zone[i - 1]; | |
874 nitrogen_pressure[i - 1] = n2_pressure_start_of_deco_zone[i - 1]; | |
875 } | |
876 if(calc_nulltime) | |
877 return CALC_CRITICAL; | |
878 else | |
879 return vpm_calc_critcal_volume(true, false); | |
880 } | |
881 /* end of critical volume decision */ | |
882 /* L100: */ | |
883 // }/* end of critical vol loop */ | |
884 } | |
885 | |
290 | 886 static void vpm_calc_deco_ceiling(void) |
38 | 887 { |
888 | |
889 short i; | |
890 // hw 1601209 float r1; | |
891 // hw 1601209 float stop_time; | |
892 // hw 1601209 int count = 0; | |
893 //static int dp_max; | |
894 //static float surfacetime; | |
895 // _Bool first_stop = false; | |
896 float tissue_He_saturation[16]; | |
897 float tissue_N2_saturation[16]; | |
898 float vpm_buehlmann_safety_gradient = 1.0f - (((float)pDiveSettings->vpm_conservatism) / 40); | |
899 //max_first_stop_depth = fmaxf(first_stop_depth,max_first_stop_depth); | |
900 | |
901 /** CALC DECO Ceiling ******************************************************************/ | |
902 /** Not when Future stops */ | |
903 if(vpm_calc_what == DECOSTOPS) | |
904 { | |
905 | |
906 for (i = 1; i <= 16; ++i) | |
907 { | |
908 helium_pressure[i - 1] = he_pressure_start_of_deco_zone[i - 1]; | |
909 nitrogen_pressure[i - 1] = n2_pressure_start_of_deco_zone[i - 1]; | |
910 } | |
911 run_time = run_time_start_of_ascent;// run_time_start_of_ascent; | |
912 starting_depth = depth_change[0]; | |
913 mix_number = mix_change[0]; | |
914 rate = rate_change[0]; | |
915 //gas_loadings_ascent_descen(helium_pressure,nitrogen_pressure, starting_depth, depth_start_of_deco_calc, rate, true); | |
916 | |
917 float deco_ceiling_depth = 0.0f; | |
918 if(depth_start_of_deco_calc > max_deco_ceiling_depth) | |
919 { | |
920 calc_deco_ceiling(&deco_ceiling_depth, true); | |
921 } | |
922 if(buehlmannSafety) | |
923 { | |
924 for (i = 0; i < 16; i++) | |
925 { | |
926 tissue_He_saturation[i] = helium_pressure[i] / 10; | |
927 tissue_N2_saturation[i] = nitrogen_pressure[i] / 10; | |
928 } | |
929 | |
930 if(!decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (deco_ceiling_depth / 10.0f) + pInput->pressure_surface_bar)) | |
931 { | |
932 | |
933 vpm_violates_buehlmann = true; | |
934 do { | |
935 deco_ceiling_depth += 0.1f; | |
936 } while (!decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (deco_ceiling_depth / 10.0f) + pInput->pressure_surface_bar)); | |
937 } | |
938 } | |
939 | |
940 if (deco_ceiling_depth < depth_start_of_deco_calc) | |
941 { | |
942 projected_ascent(&depth_start_of_deco_calc, &rate, &deco_ceiling_depth, &step_size); | |
943 } | |
944 | |
945 max_deco_ceiling_depth = fmaxf(max_deco_ceiling_depth,deco_ceiling_depth); | |
946 | |
947 if(depth_start_of_deco_calc > deco_ceiling_depth) | |
948 { | |
949 gas_loadings_ascent_descen(helium_pressure,nitrogen_pressure, depth_start_of_deco_calc,deco_ceiling_depth, rate, true); | |
950 //surfacetime += segment_time; | |
951 } | |
952 | |
953 if(vpm_b) | |
954 { | |
955 BOYLES_LAW_COMPENSATION(&max_deco_ceiling_depth, &deco_ceiling_depth, &step_size); | |
956 } | |
957 calc_deco_ceiling(&deco_ceiling_depth, false); | |
958 | |
959 // buehlmann safety | |
960 if(vpm_violates_buehlmann) | |
961 { | |
962 for (i = 0; i < 16; i++) | |
963 { | |
964 tissue_He_saturation[i] = helium_pressure[i] / 10; | |
965 tissue_N2_saturation[i] = nitrogen_pressure[i] / 10; | |
966 } | |
967 | |
968 if(!decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (deco_ceiling_depth / 10.0f) + pInput->pressure_surface_bar)) | |
969 { | |
970 | |
971 vpm_violates_buehlmann = true; | |
972 do { | |
973 deco_ceiling_depth += 0.1f; | |
974 } while (!decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (deco_ceiling_depth / 10.0f) + pInput->pressure_surface_bar)); | |
975 } | |
976 } | |
977 // output_ceiling_meter | |
978 if(deco_ceiling_depth > first_stop_depth) | |
979 deco_ceiling_depth = first_stop_depth; | |
980 pDecoInfo->output_ceiling_meter = deco_ceiling_depth ; | |
981 } | |
982 else | |
983 { | |
984 pDecoInfo->output_ceiling_meter = 0; | |
985 } | |
986 | |
987 // fix hw 160627 | |
988 if(pDecoInfo->output_ceiling_meter < 0) | |
989 pDecoInfo->output_ceiling_meter = 0; | |
990 | |
991 /*** End CALC ceiling ***************************************************/ | |
992 } | |
993 | |
994 | |
995 /* =============================================================================== */ | |
996 /* DECO STOP LOOP BLOCK FOR FINAL DECOMPRESSION SCHEDULE */ | |
997 /* =============================================================================== */ | |
998 | |
290 | 999 static int vpm_calc_final_deco(_Bool begin) |
38 | 1000 { |
1001 short i; | |
1002 float r1; | |
1003 float stop_time; | |
1004 int count = 0; | |
1005 static int dp_max; | |
1006 static float surfacetime; | |
1007 _Bool first_stop = false; | |
1008 max_first_stop_depth = fmaxf(first_stop_depth,max_first_stop_depth); | |
1009 if(begin) | |
1010 { | |
1011 gCNS_VPM = 0; | |
1012 dp_max = 0; | |
1013 for (i = 1; i <= 16; ++i) | |
1014 { | |
1015 helium_pressure[i - 1] = | |
1016 he_pressure_start_of_ascent[i - 1]; | |
1017 nitrogen_pressure[i - 1] = | |
1018 n2_pressure_start_of_ascent[i - 1]; | |
1019 } | |
1020 run_time = run_time_start_of_ascent;// run_time_start_of_ascent; | |
1021 starting_depth = depth_change[0]; | |
1022 mix_number = mix_change[0]; | |
1023 rate = rate_change[0]; | |
1024 step_size = step_size_change[0]; | |
1025 deco_stop_depth = first_stop_depth; | |
1026 max_first_stop_depth = fmaxf(first_stop_depth,max_first_stop_depth); | |
1027 last_run_time = 0.; | |
1028 | |
1029 | |
1030 | |
1031 /* =============================================================================== */ | |
1032 /* DECO STOP LOOP BLOCK FOR FINAL DECOMPRESSION SCHEDULE */ | |
1033 /* =============================================================================== */ | |
1034 surfacetime = 0; | |
1035 first_stop = true; | |
1036 } | |
1037 | |
1038 while(true) /* loop will run continuous until there is an break statement */ | |
1039 { | |
1040 if(starting_depth > deco_stop_depth) | |
1041 { | |
1042 gas_loadings_ascent_descen(helium_pressure,nitrogen_pressure, starting_depth,deco_stop_depth, rate, first_stop); | |
1043 surfacetime += segment_time; | |
1044 } | |
1045 | |
1046 /* =============================================================================== */ | |
1047 /* DURING FINAL DECOMPRESSION SCHEDULE PROCESS, COMPUTE MAXIMUM ACTUAL */ | |
1048 /* SUPERSATURATION GRADIENT RESULTING IN EACH COMPARTMENT */ | |
1049 /* If there is a repetitive dive, this will be used later in the VPM */ | |
1050 /* Repetitive Algorithm to adjust the values for critical radii. */ | |
1051 /* =============================================================================== */ | |
1052 if(vpm_calc_what == DECOSTOPS) | |
1053 calc_max_actual_gradient(&deco_stop_depth); | |
1054 | |
1055 if (deco_stop_depth <= 0.0f) { | |
1056 break; | |
1057 } | |
1058 if (number_of_changes > 1) | |
1059 { | |
1060 int i1 = number_of_changes; | |
1061 for (i = 2; i <= i1; ++i) | |
1062 { | |
1063 if (depth_change[i - 1] >= deco_stop_depth) | |
1064 { | |
1065 mix_number = mix_change[i - 1]; | |
1066 rate = rate_change[i - 1]; | |
1067 step_size = step_size_change[i - 1]; | |
1068 } | |
1069 } | |
1070 } | |
1071 | |
1072 if(first_stop) | |
1073 { | |
1074 run_time_first_stop = run_time; | |
1075 first_stop = false; | |
1076 } | |
1077 if(vpm_b) | |
1078 { | |
1079 BOYLES_LAW_COMPENSATION(&max_first_stop_depth, &deco_stop_depth, &step_size); | |
1080 } | |
1081 decompression_stop(&deco_stop_depth, &step_size, true); | |
1082 | |
1083 /* =============================================================================== */ | |
1084 /* This next bit justs rounds up the stop time at the first stop to be in */ | |
1085 /* whole increments of the minimum stop time (to make for a nice deco table). */ | |
1086 /* =============================================================================== */ | |
1087 | |
1088 if (last_run_time == 0.0f) | |
1089 { | |
1090 r1 = segment_time / minimum_deco_stop_time + 0.5f; | |
1091 stop_time = r_int(&r1) * minimum_deco_stop_time; | |
1092 } else { | |
1093 stop_time = run_time - last_run_time; | |
1094 } | |
1095 stop_time = segment_time; | |
1096 surfacetime += stop_time; | |
1097 if((vpm_calc_what == DECOSTOPS) || (vpm_calc_what == BAILOUTSTOPS)) | |
1098 { | |
1099 int dp = 0; | |
1100 if(deco_stop_depth == (float)pDiveSettings->last_stop_depth_bar * 10) | |
1101 { | |
1102 dp = 0; | |
1103 } | |
1104 else | |
1105 { | |
1106 dp = 1 + (int)((deco_stop_depth - (pDiveSettings->input_second_to_last_stop_depth_bar * 10)) / step_size); | |
1107 } | |
1108 dp_max = (int)fmaxf(dp_max,dp); | |
1109 if(dp < DECOINFO_STRUCT_MAX_STOPS) | |
1110 { | |
1111 int stop_time_seconds = fminf((999 * 60), (int)(stop_time *60)); | |
1112 // | |
1113 | |
1114 //if(vpm_calc_what == DECOSTOPS) | |
1115 pDecoInfo->output_stop_length_seconds[dp] = (unsigned short)stop_time_seconds; | |
1116 //else | |
1117 //decostop_bailout[dp] = (unsigned short)stop_time_seconds; | |
1118 } | |
1119 } | |
1120 | |
1121 | |
1122 /* =============================================================================== */ | |
1123 /* DURING FINAL DECOMPRESSION SCHEDULE, IF MINIMUM STOP TIME PARAMETER IS A */ | |
1124 /* WHOLE NUMBER (i.e. 1 minute) THEN WRITE DECO SCHEDULE USING short */ | |
1125 /* NUMBERS (looks nicer). OTHERWISE, USE DECIMAL NUMBERS. */ | |
1126 /* Note: per the request of a noted exploration diver(!), program now allows */ | |
1127 /* a minimum stop time of less than one minute so that total ascent time can */ | |
1128 /* be minimized on very long dives. In fact, with step size set at 1 fsw or */ | |
1129 /* 0.2 msw and minimum stop time set at 0.1 minute (6 seconds), a near */ | |
1130 /* continuous decompression schedule can be computed. */ | |
1131 /* =============================================================================== */ | |
1132 | |
1133 starting_depth = deco_stop_depth; | |
1134 if(deco_stop_depth == (float)pDiveSettings->last_stop_depth_bar * 10) | |
1135 deco_stop_depth = 0; | |
1136 else | |
1137 { | |
1138 deco_stop_depth = deco_stop_depth - step_size; | |
1139 deco_stop_depth = fmaxf(deco_stop_depth,(float)pDiveSettings->last_stop_depth_bar * 10); | |
1140 } | |
1141 | |
1142 last_run_time = run_time; | |
1143 count++; | |
1144 //if(count > 14) | |
1145 //return CALC_FINAL_DECO2; | |
1146 /* L80: */ | |
1147 } /* for final deco sche */ | |
1148 | |
1149 if( (vpm_calc_what == DECOSTOPS) || (vpm_calc_what == BAILOUTSTOPS)) | |
1150 { | |
1151 for(int dp = dp_max +1;dp < DECOINFO_STRUCT_MAX_STOPS;dp++) | |
1152 { | |
1153 //if(vpm_calc_what == DECOSTOPS) | |
1154 pDecoInfo->output_stop_length_seconds[dp] = 0; | |
1155 //else | |
1156 //decostop_bailout[dp] = 0; | |
1157 } | |
1158 } | |
1159 pDecoInfo->output_time_to_surface_seconds = (int)(surfacetime * 60); | |
1160 pDecoInfo->output_ndl_seconds = 0; | |
1161 | |
1162 vpm_calc_deco_ceiling(); | |
1163 /* end of deco stop lo */ | |
1164 return CALC_END; | |
1165 } | |
1166 | |
1167 /* =============================================================================== */ | |
1168 /* SUBROUTINE NUCLEAR_REGENERATION */ | |
1169 /* Purpose: This subprogram calculates the regeneration of VPM critical */ | |
1170 /* radii that takes place over the dive time. The regeneration time constant */ | |
1171 /* has a time scale of weeks so this will have very little impact on dives of */ | |
1172 /* normal length, but will have a major impact for saturation dives. */ | |
1173 /* =============================================================================== */ | |
1174 | |
290 | 1175 static int nuclear_regeneration(float *dive_time) |
38 | 1176 { |
1177 /* Local variables */ | |
1178 float crush_pressure_adjust_ratio_he, | |
1179 ending_radius_n2, | |
1180 ending_radius_he; | |
1181 short i; | |
1182 float crushing_pressure_pascals_n2, | |
1183 crushing_pressure_pascals_he, | |
1184 adj_crush_pressure_n2_pascals, | |
1185 adj_crush_pressure_he_pascals, | |
1186 crush_pressure_adjust_ratio_n2; | |
1187 | |
1188 /* loop */ | |
1189 /* =============================================================================== */ | |
1190 /* CALCULATIONS */ | |
1191 /* First convert the maximum crushing pressure obtained for each compartment */ | |
1192 /* to Pascals. Next, compute the ending radius for helium and nitrogen */ | |
1193 /* critical nuclei in each compartment. */ | |
1194 /* =============================================================================== */ | |
1195 | |
1196 for (i = 1; i <= 16; ++i) | |
1197 { | |
1198 crushing_pressure_pascals_he = | |
1199 pVpm->max_crushing_pressure_he[i - 1] / UNITS_FACTOR * 101325.0f; | |
1200 crushing_pressure_pascals_n2 = | |
1201 pVpm->max_crushing_pressure_n2[i - 1] / UNITS_FACTOR * 101325.0f; | |
1202 ending_radius_he = | |
1203 1.0f / (crushing_pressure_pascals_he / | |
1204 ((SKIN_COMPRESSION_GAMMAC - SURFACE_TENSION_GAMMA) * 2.0f) + | |
1205 1.0f / pVpm->adjusted_critical_radius_he[i - 1]); | |
1206 ending_radius_n2 = | |
1207 1.0f / (crushing_pressure_pascals_n2 / | |
1208 ((SKIN_COMPRESSION_GAMMAC - SURFACE_TENSION_GAMMA) * 2.0f) + | |
1209 1.0f / pVpm->adjusted_critical_radius_n2[i - 1]); | |
1210 | |
1211 /* =============================================================================== */ | |
1212 /* A "regenerated" radius for each nucleus is now calculated based on the */ | |
1213 /* regeneration time constant. This means that after application of */ | |
1214 /* crushing pressure and reduction in radius, a nucleus will slowly grow */ | |
1215 /* back to its original initial radius over a period of time. This */ | |
1216 /* phenomenon is probabilistic in nature and depends on absolute temperature. */ | |
1217 /* It is independent of crushing pressure. */ | |
1218 /* =============================================================================== */ | |
1219 | |
1220 regenerated_radius_he[i - 1] = | |
1221 pVpm->adjusted_critical_radius_he[i - 1] + | |
1222 (ending_radius_he - pVpm->adjusted_critical_radius_he[i - 1]) * | |
1223 expf(-(*dive_time) / REGENERATION_TIME_CONSTANT); | |
1224 regenerated_radius_n2[i - 1] = | |
1225 pVpm->adjusted_critical_radius_n2[i - 1] + | |
1226 (ending_radius_n2 - pVpm->adjusted_critical_radius_n2[i - 1]) * | |
1227 expf(-(*dive_time) / REGENERATION_TIME_CONSTANT); | |
1228 | |
1229 /* =============================================================================== */ | |
1230 /* In order to preserve reference back to the initial critical radii after */ | |
1231 /* regeneration, an "adjusted crushing pressure" for the nuclei in each */ | |
1232 /* compartment must be computed. In other words, this is the value of */ | |
1233 /* crushing pressure that would have reduced the original nucleus to the */ | |
1234 /* to the present radius had regeneration not taken place. The ratio */ | |
1235 /* for adjusting crushing pressure is obtained from algebraic manipulation */ | |
1236 /* of the standard VPM equations. The adjusted crushing pressure, in lieu */ | |
1237 /* of the original crushing pressure, is then applied in the VPM Critical */ | |
1238 /* Volume Algorithm and the VPM Repetitive Algorithm. */ | |
1239 /* =============================================================================== */ | |
1240 | |
1241 crush_pressure_adjust_ratio_he = | |
1242 ending_radius_he * (pVpm->adjusted_critical_radius_he[i - 1] - | |
1243 regenerated_radius_he[i - 1]) / | |
1244 (regenerated_radius_he[i - 1] * | |
1245 (pVpm->adjusted_critical_radius_he[i - 1] - | |
1246 ending_radius_he)); | |
1247 crush_pressure_adjust_ratio_n2 = | |
1248 ending_radius_n2 * (pVpm->adjusted_critical_radius_n2[i - 1] - | |
1249 regenerated_radius_n2[i - 1]) / | |
1250 (regenerated_radius_n2[i - 1] * | |
1251 (pVpm->adjusted_critical_radius_n2[i - 1] - | |
1252 ending_radius_n2)); | |
1253 adj_crush_pressure_he_pascals = | |
1254 crushing_pressure_pascals_he * crush_pressure_adjust_ratio_he; | |
1255 adj_crush_pressure_n2_pascals = | |
1256 crushing_pressure_pascals_n2 * crush_pressure_adjust_ratio_n2; | |
1257 pVpm->adjusted_crushing_pressure_he[i - 1] = | |
1258 adj_crush_pressure_he_pascals / 101325.0f * UNITS_FACTOR; | |
1259 pVpm->adjusted_crushing_pressure_n2[i - 1] = | |
1260 adj_crush_pressure_n2_pascals / 101325.0f * UNITS_FACTOR; | |
1261 } | |
1262 return 0; | |
1263 } /* nuclear_regeneration */ | |
1264 | |
1265 /* =============================================================================== */ | |
1266 /* SUBROUTINE CALC_INITIAL_ALLOWABLE_GRADIENT */ | |
1267 /* Purpose: This subprogram calculates the initial allowable gradients for */ | |
1268 /* helium and nitrogren in each compartment. These are the gradients that */ | |
1269 /* will be used to set the deco ceiling on the first pass through the deco */ | |
1270 /* loop. If the Critical Volume Algorithm is set to "off", then these */ | |
1271 /* gradients will determine the final deco schedule. Otherwise, if the */ | |
1272 /* Critical Volume Algorithm is set to "on", these gradients will be further */ | |
1273 /* "relaxed" by the Critical Volume Algorithm subroutine. The initial */ | |
1274 /* allowable gradients are referred to as "PssMin" in the papers by Yount */ | |
1275 /* and colleauges, i.e., the minimum supersaturation pressure gradients */ | |
1276 /* that will probe bubble formation in the VPM nuclei that started with the */ | |
1277 /* designated minimum initial radius (critical radius). */ | |
1278 | |
1279 /* The initial allowable gradients are computed directly from the */ | |
1280 /* "regenerated" radii after the Nuclear Regeneration subroutine. These */ | |
1281 /* gradients are tracked separately for helium and nitrogen. */ | |
1282 /* =============================================================================== */ | |
1283 | |
290 | 1284 static int calc_initial_allowable_gradient() |
38 | 1285 { |
1286 float initial_allowable_grad_n2_pa, | |
1287 initial_allowable_grad_he_pa; | |
1288 short i; | |
1289 | |
1290 /* loop */ | |
1291 /* =============================================================================== */ | |
1292 /* CALCULATIONS */ | |
1293 /* The initial allowable gradients are computed in Pascals and then converted */ | |
1294 /* to the diving pressure units. Two different sets of arrays are used to */ | |
1295 /* save the calculations - Initial Allowable Gradients and Allowable */ | |
1296 /* Gradients. The Allowable Gradients are assigned the values from Initial */ | |
1297 /* Allowable Gradients however the Allowable Gradients can be changed later */ | |
1298 /* by the Critical Volume subroutine. The values for the Initial Allowable */ | |
1299 /* Gradients are saved in a global array for later use by both the Critical */ | |
1300 /* Volume subroutine and the VPM Repetitive Algorithm subroutine. */ | |
1301 /* =============================================================================== */ | |
1302 | |
1303 for (i = 1; i <= 16; ++i) | |
1304 { | |
1305 initial_allowable_grad_n2_pa = | |
1306 SURFACE_TENSION_GAMMA * 2.0f * | |
1307 (SKIN_COMPRESSION_GAMMAC - SURFACE_TENSION_GAMMA) / | |
1308 (regenerated_radius_n2[i - 1] * SKIN_COMPRESSION_GAMMAC); | |
1309 | |
1310 initial_allowable_grad_he_pa = | |
1311 SURFACE_TENSION_GAMMA * 2.0f * | |
1312 (SKIN_COMPRESSION_GAMMAC - SURFACE_TENSION_GAMMA) / | |
1313 (regenerated_radius_he[i - 1] * SKIN_COMPRESSION_GAMMAC); | |
1314 | |
1315 pVpm->initial_allowable_gradient_n2[i - 1] = | |
1316 initial_allowable_grad_n2_pa / 101325.0f * UNITS_FACTOR; | |
1317 | |
1318 pVpm->initial_allowable_gradient_he[i - 1] = | |
1319 initial_allowable_grad_he_pa / 101325.0f * UNITS_FACTOR; | |
1320 | |
1321 allowable_gradient_he[i - 1] = | |
1322 pVpm->initial_allowable_gradient_he[i - 1]; | |
1323 | |
1324 allowable_gradient_n2[i - 1] = | |
1325 pVpm->initial_allowable_gradient_n2[i - 1]; | |
1326 } | |
1327 return 0; | |
1328 } /* calc_initial_allowable_gradient */ | |
1329 | |
1330 /* =============================================================================== */ | |
1331 /* SUBROUTINE CALC_DECO_CEILING */ | |
1332 /* Purpose: This subprogram calculates the deco ceiling (the safe ascent */ | |
1333 /* depth) in each compartment, based on the allowable gradients, and then */ | |
1334 /* finds the deepest deco ceiling across all compartments. This deepest */ | |
1335 /* value (Deco Ceiling Depth) is then used by the Decompression Stop */ | |
1336 /* subroutine to determine the actual deco schedule. */ | |
1337 /* =============================================================================== */ | |
1338 | |
290 | 1339 static int calc_deco_ceiling(float *deco_ceiling_depth,_Bool fallowable) |
38 | 1340 { |
1341 /* System generated locals */ | |
1342 float r1, r2; | |
1343 /* Local variables */ | |
1344 float weighted_allowable_gradient; | |
1345 short i; | |
1346 float compartment_deco_ceiling[16], | |
1347 gas_loading, | |
1348 tolerated_ambient_pressure; | |
1349 float gradient_he, gradient_n2; | |
1350 | |
1351 if(!vpm_b) | |
1352 fallowable = true; | |
1353 /* loop */ | |
1354 /* =============================================================================== */ | |
1355 /* CALCULATIONS */ | |
1356 /* Since there are two sets of allowable gradients being tracked, one for */ | |
1357 /* helium and one for nitrogen, a "weighted allowable gradient" must be */ | |
1358 /* computed each time based on the proportions of helium and nitrogen in */ | |
1359 /* each compartment. This proportioning follows the methodology of */ | |
1360 /* Buhlmann/Keller. If there is no helium and nitrogen in the compartment, */ | |
1361 /* such as after extended periods of oxygen breathing, then the minimum value */ | |
1362 /* across both gases will be used. It is important to note that if a */ | |
1363 /* compartment is empty of helium and nitrogen, then the weighted allowable */ | |
1364 /* gradient formula cannot be used since it will result in division by zero. */ | |
1365 /* =============================================================================== */ | |
1366 | |
1367 for (i = 1; i <= 16; ++i) | |
1368 { | |
1369 | |
1370 // abfrage raus und pointer stattdessen | |
1371 if(fallowable){ | |
1372 gradient_he = allowable_gradient_he[i-1]; | |
1373 gradient_n2 = allowable_gradient_n2[i-1]; | |
1374 } | |
1375 else{ | |
1376 gradient_he = deco_gradient_he[i-1]; | |
1377 gradient_n2 = deco_gradient_n2[i-1]; | |
1378 } | |
1379 | |
1380 gas_loading = helium_pressure[i - 1] + nitrogen_pressure[i - 1]; | |
1381 | |
1382 if (gas_loading > 0) | |
1383 { | |
1384 weighted_allowable_gradient = | |
1385 (gradient_he * helium_pressure[i - 1] + | |
1386 gradient_n2 * nitrogen_pressure[i - 1]) / | |
1387 (helium_pressure[i - 1] + nitrogen_pressure[i - 1]); | |
1388 | |
1389 tolerated_ambient_pressure = | |
1390 gas_loading + | |
1391 CONSTANT_PRESSURE_OTHER_GASES - | |
1392 weighted_allowable_gradient; | |
1393 } | |
1394 else | |
1395 { | |
1396 /* Computing MIN */ | |
1397 r1 = gradient_he; | |
1398 r2 = gradient_n2; | |
1399 weighted_allowable_gradient = fminf(r1,r2); | |
1400 | |
1401 tolerated_ambient_pressure = | |
1402 CONSTANT_PRESSURE_OTHER_GASES - weighted_allowable_gradient; | |
1403 } | |
1404 | |
1405 /* =============================================================================== */ | |
1406 /* The tolerated ambient pressure cannot be less than zero absolute, i.e., */ | |
1407 /* the vacuum of outer space! */ | |
1408 /* =============================================================================== */ | |
1409 | |
1410 if (tolerated_ambient_pressure < 0) { | |
1411 tolerated_ambient_pressure = 0; | |
1412 } | |
1413 compartment_deco_ceiling[i - 1] = | |
1414 tolerated_ambient_pressure - barometric_pressure; | |
1415 } | |
1416 | |
1417 /* =============================================================================== */ | |
1418 /* The Deco Ceiling Depth is computed in a loop after all of the individual */ | |
1419 /* compartment deco ceilings have been calculated. It is important that the */ | |
1420 /* Deco Ceiling Depth (max deco ceiling across all compartments) only be */ | |
1421 /* extracted from the compartment values and not be compared against some */ | |
1422 /* initialization value. For example, if MAX(Deco_Ceiling_Depth . .) was */ | |
1423 /* compared against zero, this could cause a program lockup because sometimes */ | |
1424 /* the Deco Ceiling Depth needs to be negative (but not less than zero */ | |
1425 /* absolute ambient pressure) in order to decompress to the last stop at zero */ | |
1426 /* depth. */ | |
1427 /* =============================================================================== */ | |
1428 | |
1429 *deco_ceiling_depth = compartment_deco_ceiling[0]; | |
1430 for (i = 2; i <= 16; ++i) | |
1431 { | |
1432 /* Computing MAX */ | |
1433 r1 = *deco_ceiling_depth; | |
1434 r2 = compartment_deco_ceiling[i - 1]; | |
1435 *deco_ceiling_depth = fmaxf(r1,r2); | |
1436 } | |
1437 return 0; | |
1438 } /* calc_deco_ceiling */ | |
1439 | |
1440 | |
1441 | |
1442 /* =============================================================================== */ | |
1443 /* SUBROUTINE CALC_MAX_ACTUAL_GRADIENT */ | |
1444 /* Purpose: This subprogram calculates the actual supersaturation gradient */ | |
1445 /* obtained in each compartment as a result of the ascent profile during */ | |
1446 /* decompression. Similar to the concept with crushing pressure, the */ | |
1447 /* supersaturation gradients are not cumulative over a multi-level, staged */ | |
1448 /* ascent. Rather, it will be the maximum value obtained in any one discrete */ | |
1449 /* step of the overall ascent. Thus, the program must compute and store the */ | |
1450 /* maximum actual gradient for each compartment that was obtained across all */ | |
1451 /* steps of the ascent profile. This subroutine is invoked on the last pass */ | |
1452 /* through the deco stop loop block when the final deco schedule is being */ | |
1453 /* generated. */ | |
1454 /* */ | |
1455 /* The max actual gradients are later used by the VPM Repetitive Algorithm to */ | |
1456 /* determine if adjustments to the critical radii are required. If the max */ | |
1457 /* actual gradient did not exceed the initial alllowable gradient, then no */ | |
1458 /* adjustment will be made. However, if the max actual gradient did exceed */ | |
1459 /* the intitial allowable gradient, such as permitted by the Critical Volume */ | |
1460 /* Algorithm, then the critical radius will be adjusted (made larger) on the */ | |
1461 /* repetitive dive to compensate for the bubbling that was allowed on the */ | |
1462 /* previous dive. The use of the max actual gradients is intended to prevent */ | |
1463 /* the repetitive algorithm from being overly conservative. */ | |
1464 /* =============================================================================== */ | |
1465 | |
290 | 1466 static int calc_max_actual_gradient(float *deco_stop_depth) |
38 | 1467 { |
1468 /* System generated locals */ | |
1469 float r1; | |
1470 | |
1471 /* Local variables */ | |
1472 short i; | |
1473 float compartment_gradient; | |
1474 | |
1475 /* loop */ | |
1476 /* =============================================================================== */ | |
1477 /* CALCULATIONS */ | |
1478 /* Note: negative supersaturation gradients are meaningless for this */ | |
1479 /* application, so the values must be equal to or greater than zero. */ | |
1480 /* =============================================================================== */ | |
1481 | |
1482 for (i = 1; i <= 16; ++i) | |
1483 { | |
1484 compartment_gradient = | |
1485 helium_pressure[i - 1] + | |
1486 nitrogen_pressure[i - 1] + | |
1487 CONSTANT_PRESSURE_OTHER_GASES - | |
1488 (*deco_stop_depth + barometric_pressure); | |
1489 if (compartment_gradient <= 0.0f) { | |
1490 compartment_gradient = 0.0f; | |
1491 } | |
1492 /* Computing MAX */ | |
1493 r1 = pVpm->max_actual_gradient[i - 1]; | |
1494 pVpm->max_actual_gradient[i - 1] = fmaxf(r1, compartment_gradient); | |
1495 } | |
1496 return 0; | |
1497 } /* calc_max_actual_gradient */ | |
1498 | |
1499 /* =============================================================================== */ | |
1500 /* SUBROUTINE CALC_SURFACE_PHASE_VOLUME_TIME */ | |
1501 /* Purpose: This subprogram computes the surface portion of the total phase */ | |
1502 /* volume time. This is the time factored out of the integration of */ | |
1503 /* supersaturation gradient x time over the surface interval. The VPM */ | |
1504 /* considers the gradients that allow bubbles to form or to drive bubble */ | |
1505 /* growth both in the water and on the surface after the dive. */ | |
1506 | |
1507 /* This subroutine is a new development to the VPM algorithm in that it */ | |
1508 /* computes the time course of supersaturation gradients on the surface */ | |
1509 /* when both helium and nitrogen are present. Refer to separate write-up */ | |
1510 /* for a more detailed explanation of this algorithm. */ | |
1511 /* =============================================================================== */ | |
1512 | |
290 | 1513 static int calc_surface_phase_volume_time() |
38 | 1514 { |
1515 /* Local variables */ | |
1516 float decay_time_to_zero_gradient; | |
1517 short i; | |
1518 float integral_gradient_x_time, | |
1519 surface_inspired_n2_pressure; | |
1520 | |
1521 /* loop */ | |
1522 /* =============================================================================== */ | |
1523 /* CALCULATIONS */ | |
1524 /* =============================================================================== */ | |
1525 | |
1526 surface_inspired_n2_pressure = | |
1527 (barometric_pressure - WATER_VAPOR_PRESSURE) * 0.79f; | |
1528 for (i = 1; i <= 16; ++i) | |
1529 { | |
1530 if (nitrogen_pressure[i - 1] > surface_inspired_n2_pressure) | |
1531 { | |
1532 surface_phase_volume_time[i - 1] = | |
1533 (helium_pressure[i - 1] / HELIUM_TIME_CONSTANT[i - 1] + | |
1534 (nitrogen_pressure[i - 1] - surface_inspired_n2_pressure) / | |
1535 NITROGEN_TIME_CONSTANT[i - 1]) / | |
1536 (helium_pressure[i - 1] + nitrogen_pressure[i - 1] - | |
1537 surface_inspired_n2_pressure); | |
1538 } else if (nitrogen_pressure[i - 1] <= surface_inspired_n2_pressure && | |
1539 helium_pressure[i - 1] + nitrogen_pressure[i - 1] >= surface_inspired_n2_pressure) | |
1540 { | |
1541 decay_time_to_zero_gradient = | |
1542 1.0f / (NITROGEN_TIME_CONSTANT[i - 1] - HELIUM_TIME_CONSTANT[i - 1]) * | |
1543 log((surface_inspired_n2_pressure - nitrogen_pressure[i - 1]) / | |
1544 helium_pressure[i - 1]); | |
1545 integral_gradient_x_time = | |
1546 helium_pressure[i - 1] / | |
1547 HELIUM_TIME_CONSTANT[i - 1] * | |
1548 (1.0f - expf(-HELIUM_TIME_CONSTANT[i - 1] * | |
1549 decay_time_to_zero_gradient)) + | |
1550 (nitrogen_pressure[i - 1] - surface_inspired_n2_pressure) / | |
1551 NITROGEN_TIME_CONSTANT[i - 1] * | |
1552 (1.0f - expf(-NITROGEN_TIME_CONSTANT[i - 1] * | |
1553 decay_time_to_zero_gradient)); | |
1554 surface_phase_volume_time[i - 1] = | |
1555 integral_gradient_x_time / | |
1556 (helium_pressure[i - 1] + | |
1557 nitrogen_pressure[i - 1] - | |
1558 surface_inspired_n2_pressure); | |
1559 } else { | |
1560 surface_phase_volume_time[i - 1] = 0.0f; | |
1561 } | |
1562 } | |
1563 return 0; | |
1564 } /* calc_surface_phase_volume_time */ | |
1565 | |
1566 /* =============================================================================== */ | |
1567 /* SUBROUTINE CRITICAL_VOLUME */ | |
1568 /* Purpose: This subprogram applies the VPM Critical Volume Algorithm. This */ | |
1569 /* algorithm will compute "relaxed" gradients for helium and nitrogen based */ | |
1570 /* on the setting of the Critical Volume Parameter Lambda. */ | |
1571 /* =============================================================================== */ | |
1572 | |
290 | 1573 static int critical_volume(float *deco_phase_volume_time) |
38 | 1574 { |
1575 /* System generated locals */ | |
1576 float r1; | |
1577 | |
1578 /* Local variables */ | |
1579 float initial_allowable_grad_n2_pa, | |
1580 initial_allowable_grad_he_pa, | |
1581 parameter_lambda_pascals, b, | |
1582 c; | |
1583 short i; | |
1584 float new_allowable_grad_n2_pascals, | |
1585 phase_volume_time[16], | |
1586 new_allowable_grad_he_pascals, | |
1587 adj_crush_pressure_n2_pascals, | |
1588 adj_crush_pressure_he_pascals; | |
1589 | |
1590 /* loop */ | |
1591 /* =============================================================================== */ | |
1592 /* CALCULATIONS */ | |
1593 /* Note: Since the Critical Volume Parameter Lambda was defined in units of */ | |
1594 /* fsw-min in the original papers by Yount and colleauges, the same */ | |
1595 /* convention is retained here. Although Lambda is adjustable only in units */ | |
1596 /* of fsw-min in the program settings (range from 6500 to 8300 with default */ | |
1597 /* 7500), it will convert to the proper value in Pascals-min in this */ | |
1598 /* subroutine regardless of which diving pressure units are being used in */ | |
1599 /* the main program - feet of seawater (fsw) or meters of seawater (msw). */ | |
1600 /* The allowable gradient is computed using the quadratic formula (refer to */ | |
1601 /* separate write-up posted on the Deco List web site). */ | |
1602 /* =============================================================================== */ | |
1603 | |
1604 /** | |
1605 ****************************************************************************** | |
1606 * @brief critical_volume comment by hw | |
1607 * @version V0.0.1 | |
1608 * @date 19-April-2014 | |
1609 * @retval global: allowable_gradient_he[i], allowable_gradient_n2[i] | |
1610 ****************************************************************************** | |
1611 */ | |
1612 | |
1613 parameter_lambda_pascals = | |
1614 CRIT_VOLUME_PARAMETER_LAMBDA / 33.0f * 101325.0f; | |
1615 for (i = 1; i <= 16; ++i) | |
1616 { | |
1617 phase_volume_time[i - 1] = | |
1618 *deco_phase_volume_time + surface_phase_volume_time[i - 1]; | |
1619 } | |
1620 for (i = 1; i <= 16; ++i) | |
1621 { | |
1622 | |
1623 adj_crush_pressure_he_pascals = | |
1624 pVpm->adjusted_crushing_pressure_he[i - 1] / UNITS_FACTOR * 101325.0f; | |
1625 | |
1626 initial_allowable_grad_he_pa = | |
1627 pVpm->initial_allowable_gradient_he[i - 1] / UNITS_FACTOR * 101325.0f; | |
1628 | |
1629 b = initial_allowable_grad_he_pa + parameter_lambda_pascals * | |
1630 SURFACE_TENSION_GAMMA / ( | |
1631 SKIN_COMPRESSION_GAMMAC * phase_volume_time[i - 1]); | |
1632 | |
1633 c = SURFACE_TENSION_GAMMA * ( | |
1634 SURFACE_TENSION_GAMMA * ( | |
1635 parameter_lambda_pascals * adj_crush_pressure_he_pascals)) / | |
1636 (SKIN_COMPRESSION_GAMMAC * | |
1637 (SKIN_COMPRESSION_GAMMAC * phase_volume_time[i - 1])); | |
1638 /* Computing 2nd power */ | |
1639 | |
1640 r1 = b; | |
1641 | |
1642 new_allowable_grad_he_pascals = | |
1643 (b + sqrtf(r1 * r1 - c * 4.0f)) / 2.0f; | |
1644 | |
1645 /* modify global variable */ | |
1646 allowable_gradient_he[i - 1] = | |
1647 new_allowable_grad_he_pascals / 101325.0f * UNITS_FACTOR; | |
1648 } | |
1649 | |
1650 for (i = 1; i <= 16; ++i) | |
1651 { | |
1652 adj_crush_pressure_n2_pascals = | |
1653 pVpm->adjusted_crushing_pressure_n2[i - 1] / UNITS_FACTOR * 101325.0f; | |
1654 | |
1655 initial_allowable_grad_n2_pa = | |
1656 pVpm->initial_allowable_gradient_n2[i - 1] / UNITS_FACTOR * 101325.0f; | |
1657 | |
1658 b = initial_allowable_grad_n2_pa + parameter_lambda_pascals * | |
1659 SURFACE_TENSION_GAMMA / ( | |
1660 SKIN_COMPRESSION_GAMMAC * phase_volume_time[i - 1]); | |
1661 | |
1662 c = SURFACE_TENSION_GAMMA * | |
1663 (SURFACE_TENSION_GAMMA * | |
1664 (parameter_lambda_pascals * adj_crush_pressure_n2_pascals)) / | |
1665 (SKIN_COMPRESSION_GAMMAC * | |
1666 (SKIN_COMPRESSION_GAMMAC * phase_volume_time[i - 1])); | |
1667 /* Computing 2nd power */ | |
1668 | |
1669 r1 = b; | |
1670 | |
1671 new_allowable_grad_n2_pascals = | |
1672 (b + sqrtf(r1 * r1 - c * 4.0f)) / 2.0f; | |
1673 | |
1674 /* modify global variable */ | |
1675 allowable_gradient_n2[i - 1] = | |
1676 new_allowable_grad_n2_pascals / 101325.0f * UNITS_FACTOR; | |
1677 } | |
1678 return 0; | |
1679 } /* critical_volume */ | |
1680 | |
1681 /* =============================================================================== */ | |
1682 /* SUBROUTINE CALC_START_OF_DECO_ZONE */ | |
1683 /* Purpose: This subroutine uses the Bisection Method to find the depth at */ | |
1684 /* which the leading compartment just enters the decompression zone. */ | |
1685 /* Source: "Numerical Recipes in Fortran 77", Cambridge University Press, */ | |
1686 /* 1992. */ | |
1687 /* =============================================================================== */ | |
1688 | |
290 | 1689 static int calc_start_of_deco_zone(float *starting_depth, |
38 | 1690 float *rate, |
1691 float *depth_start_of_deco_zone) | |
1692 { | |
1693 /* Local variables */ | |
1694 float last_diff_change, | |
1695 initial_helium_pressure, | |
1696 mid_range_nitrogen_pressure; | |
1697 short i, j; | |
1698 float initial_inspired_n2_pressure, | |
1699 cpt_depth_start_of_deco_zone, | |
1700 low_bound, | |
1701 initial_inspired_he_pressure, | |
1702 high_bound_nitrogen_pressure, | |
1703 nitrogen_rate, | |
1704 function_at_mid_range, | |
1705 function_at_low_bound, | |
1706 high_bound, | |
1707 mid_range_helium_pressure, | |
1708 mid_range_time, | |
1709 starting_ambient_pressure, | |
1710 initial_nitrogen_pressure, | |
1711 function_at_high_bound; | |
1712 | |
1713 float time_to_start_of_deco_zone, | |
1714 high_bound_helium_pressure, | |
1715 helium_rate, | |
1716 differential_change; | |
1717 float fraction_helium_begin; | |
1718 float fraction_helium_end; | |
1719 float fraction_nitrogen_begin; | |
1720 float fraction_nitrogen_end; | |
1721 float ending_ambient_pressure; | |
1722 float time_test; | |
1723 | |
1724 | |
1725 /* loop */ | |
1726 /* =============================================================================== */ | |
1727 /* CALCULATIONS */ | |
1728 /* First initialize some variables */ | |
1729 /* =============================================================================== */ | |
1730 | |
1731 *depth_start_of_deco_zone = 0.0f; | |
1732 starting_ambient_pressure = *starting_depth + barometric_pressure; | |
1733 | |
1734 //>>>>>>>>>>>>>>>>>>>> | |
1735 //Test depth to calculate helium_rate and nitrogen_rate | |
1736 ending_ambient_pressure = starting_ambient_pressure/2; | |
1737 | |
1738 time_test = (ending_ambient_pressure - starting_ambient_pressure) / *rate; | |
1739 decom_get_inert_gases(starting_ambient_pressure / 10, (&pDiveSettings->decogaslist[mix_number]), &fraction_nitrogen_begin, &fraction_helium_begin ); | |
1740 decom_get_inert_gases(ending_ambient_pressure / 10, (&pDiveSettings->decogaslist[mix_number]), &fraction_nitrogen_end, &fraction_helium_end ); | |
1741 initial_inspired_he_pressure = (starting_ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_helium_begin; | |
1742 initial_inspired_n2_pressure = (starting_ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_nitrogen_begin; | |
1743 helium_rate = ((ending_ambient_pressure - WATER_VAPOR_PRESSURE)* fraction_helium_end - initial_inspired_he_pressure)/time_test; | |
1744 nitrogen_rate = ((ending_ambient_pressure - WATER_VAPOR_PRESSURE)* fraction_nitrogen_end - initial_inspired_n2_pressure)/time_test; | |
1745 //>>>>>>>>>>>>>>>>>>>>> | |
1746 /*initial_inspired_he_pressure = | |
1747 (starting_ambient_pressure - water_vapor_pressure) * | |
1748 fraction_helium[mix_number - 1]; | |
1749 initial_inspired_n2_pressure = | |
1750 (starting_ambient_pressure - water_vapor_pressure) * | |
1751 fraction_nitrogen[mix_number - 1]; | |
1752 helium_rate = *rate * fraction_helium[mix_number - 1]; | |
1753 nitrogen_rate = *rate * fraction_nitrogen[mix_number - 1];*/ | |
1754 | |
1755 /* =============================================================================== */ | |
1756 /* ESTABLISH THE BOUNDS FOR THE ROOT SEARCH USING THE BISECTION METHOD */ | |
1757 /* AND CHECK TO MAKE SURE THAT THE ROOT WILL BE WITHIN BOUNDS. PROCESS */ | |
1758 /* EACH COMPARTMENT INDIVIDUALLY AND FIND THE MAXIMUM DEPTH ACROSS ALL */ | |
1759 /* COMPARTMENTS (LEADING COMPARTMENT) */ | |
1760 /* In this case, we are solving for time - the time when the gas tension in */ | |
1761 /* the compartment will be equal to ambient pressure. The low bound for time */ | |
1762 /* is set at zero and the high bound is set at the time it would take to */ | |
1763 /* ascend to zero ambient pressure (absolute). Since the ascent rate is */ | |
1764 /* negative, a multiplier of -1.0 is used to make the time positive. The */ | |
1765 /* desired point when gas tension equals ambient pressure is found at a time */ | |
1766 /* somewhere between these endpoints. The algorithm checks to make sure that */ | |
1767 /* the solution lies in between these bounds by first computing the low bound */ | |
1768 /* and high bound function values. */ | |
1769 /* =============================================================================== */ | |
1770 | |
1771 low_bound = 0.; | |
1772 high_bound = starting_ambient_pressure / *rate * -1.0f; | |
1773 for (i = 1; i <= 16; ++i) | |
1774 { | |
1775 initial_helium_pressure = helium_pressure[i - 1]; | |
1776 initial_nitrogen_pressure = nitrogen_pressure[i - 1]; | |
1777 function_at_low_bound = | |
1778 initial_helium_pressure + | |
1779 initial_nitrogen_pressure + | |
1780 CONSTANT_PRESSURE_OTHER_GASES - | |
1781 starting_ambient_pressure; | |
1782 high_bound_helium_pressure = | |
1783 schreiner_equation__2(&initial_inspired_he_pressure, | |
1784 &helium_rate, | |
1785 &high_bound, | |
1786 &HELIUM_TIME_CONSTANT[i - 1], | |
1787 &initial_helium_pressure); | |
1788 high_bound_nitrogen_pressure = | |
1789 schreiner_equation__2(&initial_inspired_n2_pressure, | |
1790 &nitrogen_rate, | |
1791 &high_bound, | |
1792 &NITROGEN_TIME_CONSTANT[i - 1], | |
1793 &initial_nitrogen_pressure); | |
1794 function_at_high_bound = high_bound_helium_pressure + | |
1795 high_bound_nitrogen_pressure + | |
1796 CONSTANT_PRESSURE_OTHER_GASES; | |
1797 if (function_at_high_bound * function_at_low_bound >= 0.0f) | |
1798 { | |
1799 printf("\nERROR! ROOT IS NOT WITHIN BRACKETS"); | |
1800 } | |
1801 | |
1802 /* =============================================================================== */ | |
1803 /* APPLY THE BISECTION METHOD IN SEVERAL ITERATIONS UNTIL A SOLUTION WITH */ | |
1804 /* THE DESIRED ACCURACY IS FOUND */ | |
1805 /* Note: the program allows for up to 100 iterations. Normally an exit will */ | |
1806 /* be made from the loop well before that number. If, for some reason, the */ | |
1807 /* program exceeds 100 iterations, there will be a pause to alert the user. */ | |
1808 /* =============================================================================== */ | |
1809 | |
1810 if (function_at_low_bound < 0.0f) | |
1811 { | |
1812 time_to_start_of_deco_zone = low_bound; | |
1813 differential_change = high_bound - low_bound; | |
1814 } else { | |
1815 time_to_start_of_deco_zone = high_bound; | |
1816 differential_change = low_bound - high_bound; | |
1817 } | |
1818 for (j = 1; j <= 100; ++j) | |
1819 { | |
1820 last_diff_change = differential_change; | |
1821 differential_change = last_diff_change * 0.5f; | |
1822 mid_range_time = | |
1823 time_to_start_of_deco_zone + | |
1824 differential_change; | |
1825 mid_range_helium_pressure = | |
1826 schreiner_equation__2(&initial_inspired_he_pressure, | |
1827 &helium_rate, | |
1828 &mid_range_time, | |
1829 &HELIUM_TIME_CONSTANT[i - 1], | |
1830 &initial_helium_pressure); | |
1831 mid_range_nitrogen_pressure = | |
1832 schreiner_equation__2(&initial_inspired_n2_pressure, | |
1833 &nitrogen_rate, | |
1834 &mid_range_time, | |
1835 &NITROGEN_TIME_CONSTANT[i - 1], | |
1836 &initial_nitrogen_pressure); | |
1837 function_at_mid_range = | |
1838 mid_range_helium_pressure + | |
1839 mid_range_nitrogen_pressure + | |
1840 CONSTANT_PRESSURE_OTHER_GASES - | |
1841 (starting_ambient_pressure + *rate * mid_range_time); | |
1842 if (function_at_mid_range <= 0.0f) { | |
1843 time_to_start_of_deco_zone = mid_range_time; | |
1844 } | |
1845 if( fabs(differential_change) < 0.001f | |
1846 || function_at_mid_range == 0.0f) | |
1847 { | |
1848 goto L170; | |
1849 } | |
1850 /* L150: */ | |
1851 } | |
1852 printf("\nERROR! ROOT SEARCH EXCEEDED MAXIMUM ITERATIONS"); | |
1853 //pause(); | |
1854 | |
1855 /* =============================================================================== */ | |
1856 /* When a solution with the desired accuracy is found, the program jumps out */ | |
1857 /* of the loop to Line 170 and assigns the solution value for the individual */ | |
1858 /* compartment. */ | |
1859 /* =============================================================================== */ | |
1860 | |
1861 L170: | |
1862 cpt_depth_start_of_deco_zone = | |
1863 starting_ambient_pressure + | |
1864 *rate * time_to_start_of_deco_zone - | |
1865 barometric_pressure; | |
1866 | |
1867 /* =============================================================================== */ | |
1868 /* The overall solution will be the compartment with the maximum depth where */ | |
1869 /* gas tension equals ambient pressure (leading compartment). */ | |
1870 /* =============================================================================== */ | |
1871 | |
1872 *depth_start_of_deco_zone = | |
1873 fmaxf(*depth_start_of_deco_zone, cpt_depth_start_of_deco_zone); | |
1874 /* L200: */ | |
1875 } | |
1876 return 0; | |
1877 } /* calc_start_of_deco_zone */ | |
1878 | |
1879 /* =============================================================================== */ | |
1880 /* SUBROUTINE PROJECTED_ASCENT */ | |
1881 /* Purpose: This subprogram performs a simulated ascent outside of the main */ | |
1882 /* program to ensure that a deco ceiling will not be violated due to unusual */ | |
1883 /* gas loading during ascent (on-gassing). If the deco ceiling is violated, */ | |
1884 /* the stop depth will be adjusted deeper by the step size until a safe */ | |
1885 /* ascent can be made. */ | |
1886 /* =============================================================================== */ | |
1887 | |
290 | 1888 static int projected_ascent(float *starting_depth, |
38 | 1889 float *rate, |
1890 float *deco_stop_depth, | |
1891 float *step_size) | |
1892 { | |
1893 /* Local variables */ | |
1894 float weighted_allowable_gradient, | |
1895 ending_ambient_pressure, | |
1896 temp_gas_loading[16]; | |
1897 int i; | |
1898 float allowable_gas_loading[16]; | |
1899 float temp_nitrogen_pressure[16]; | |
1900 float temp_helium_pressure[16]; | |
1901 float run_time_save = 0; | |
1902 | |
1903 /* loop */ | |
1904 /* =============================================================================== */ | |
1905 /* CALCULATIONS */ | |
1906 /* =============================================================================== */ | |
1907 | |
1908 | |
1909 L665: | |
1910 ending_ambient_pressure = *deco_stop_depth + barometric_pressure; | |
1911 for (i = 1; i <= 16; ++i) { | |
1912 temp_helium_pressure[i - 1] = helium_pressure[i - 1]; | |
1913 temp_nitrogen_pressure[i - 1] = nitrogen_pressure[i - 1]; | |
1914 } | |
1915 run_time_save = run_time; | |
1916 gas_loadings_ascent_descen(temp_helium_pressure, temp_nitrogen_pressure, *starting_depth,*deco_stop_depth,*rate,true); | |
1917 run_time = run_time_save; | |
1918 | |
1919 for (i = 1; i <= 16; ++i) | |
1920 { | |
1921 temp_gas_loading[i - 1] = | |
1922 temp_helium_pressure[i - 1] + | |
1923 temp_nitrogen_pressure[i - 1]; | |
1924 if (temp_gas_loading[i - 1] > 0.0f) | |
1925 { | |
1926 weighted_allowable_gradient = | |
1927 (allowable_gradient_he[i - 1] * | |
1928 temp_helium_pressure[i - 1] + | |
1929 allowable_gradient_n2[i - 1] * | |
1930 temp_nitrogen_pressure[i - 1]) / temp_gas_loading[i - 1]; | |
1931 } else { | |
1932 /* Computing MIN */ | |
1933 weighted_allowable_gradient = fminf(allowable_gradient_he[i - 1],allowable_gradient_n2[i - 1]); | |
1934 } | |
1935 allowable_gas_loading[i - 1] = | |
1936 ending_ambient_pressure + | |
1937 weighted_allowable_gradient - | |
1938 CONSTANT_PRESSURE_OTHER_GASES; | |
1939 /* L670: */ | |
1940 } | |
1941 for (i = 1; i <= 16; ++i) { | |
1942 if (temp_gas_loading[i - 1] > allowable_gas_loading[i - 1]) { | |
1943 *deco_stop_depth += *step_size; | |
1944 goto L665; | |
1945 } | |
1946 /* L671: */ | |
1947 } | |
1948 return 0; | |
1949 } /* projected_ascent */ | |
1950 | |
1951 /* =============================================================================== */ | |
1952 /* SUBROUTINE DECOMPRESSION_STOP */ | |
1953 /* Purpose: This subprogram calculates the required time at each */ | |
1954 /* decompression stop. */ | |
1955 /* =============================================================================== */ | |
1956 | |
290 | 1957 static void decompression_stop(float *deco_stop_depth, |
38 | 1958 float *step_size, |
1959 _Bool final_deco_calculation) | |
1960 { | |
1961 /* Local variables */ | |
1962 float inspired_nitrogen_pressure; | |
1963 // short last_segment_number; | |
1964 // float weighted_allowable_gradient; | |
1965 float initial_helium_pressure[16]; | |
1966 /* by hw */ | |
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
1967 float initial_CNS = gCNS_VPM; |
38 | 1968 |
1969 //static float time_counter; | |
1970 short i; | |
1971 float ambient_pressure; | |
1972 float inspired_helium_pressure, | |
1973 next_stop; | |
1974 //last_run_time, | |
1975 //temp_segment_time; | |
1976 | |
1977 float deco_ceiling_depth, | |
1978 initial_nitrogen_pressure[16]; | |
1979 //round_up_operation; | |
1980 float fraction_helium_begin; | |
1981 float fraction_nitrogen_begin; | |
1982 int count = 0; | |
1983 _Bool buehlmann_wait = false; | |
1984 float tissue_He_saturation[16]; | |
1985 float tissue_N2_saturation[16]; | |
1986 float vpm_buehlmann_safety_gradient = 1.0f - (((float)pDiveSettings->vpm_conservatism) / 40); | |
1987 /* loop */ | |
1988 /* =============================================================================== */ | |
1989 /* CALCULATIONS */ | |
1990 /* =============================================================================== */ | |
1991 | |
1992 segment_time = 0; | |
1993 // temp_segment_time = segment_time; | |
1994 ambient_pressure = *deco_stop_depth + barometric_pressure; | |
1995 //ending_ambient_pressure = ambient_pressure; | |
1996 decom_get_inert_gases(ambient_pressure / 10, (&pDiveSettings->decogaslist[mix_number]), &fraction_nitrogen_begin, &fraction_helium_begin ); | |
1997 | |
1998 if(*deco_stop_depth == (float)(pDiveSettings->last_stop_depth_bar * 10)) | |
1999 next_stop = 0; | |
2000 else | |
2001 { | |
2002 next_stop = *deco_stop_depth - *step_size; | |
2003 next_stop = fmaxf(next_stop,(float)pDiveSettings->last_stop_depth_bar * 10); | |
2004 } | |
2005 | |
2006 inspired_helium_pressure = | |
2007 (ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_helium_begin; | |
2008 inspired_nitrogen_pressure = | |
2009 (ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_nitrogen_begin; | |
2010 | |
2011 /* =============================================================================== */ | |
2012 /* Check to make sure that program won't lock up if unable to decompress */ | |
2013 /* to the next stop. If so, write error message and terminate program. */ | |
2014 /* =============================================================================== */ | |
2015 | |
2016 //deco_ceiling_depth = next_stop +1; //deco_ceiling_depth = next_stop + 1; | |
2017 if(!vpm_violates_buehlmann) | |
149 | 2018 { |
38 | 2019 calc_deco_ceiling(&deco_ceiling_depth, false); //weg, weil auf jeden Fall schleife für safety und so konservativer |
149 | 2020 } |
38 | 2021 else |
149 | 2022 { |
38 | 2023 deco_ceiling_depth = next_stop + 1; |
149 | 2024 } |
38 | 2025 if(deco_ceiling_depth > next_stop) |
2026 { | |
2027 while (deco_ceiling_depth > next_stop) | |
2028 { | |
2029 | |
2030 segment_time += 60; | |
2031 if(segment_time >= 999 ) | |
2032 { | |
2033 segment_time = 999 ; | |
2034 run_time += segment_time; | |
2035 return; | |
2036 } | |
2037 //goto L700; | |
2038 initial_CNS = gCNS_VPM; | |
2039 decom_oxygen_calculate_cns_exposure(60*60,&pDiveSettings->decogaslist[mix_number],ambient_pressure/10,&gCNS_VPM); | |
2040 for (i = 0; i < 16; i++) | |
2041 { | |
2042 initial_helium_pressure[i] = helium_pressure[i]; | |
2043 initial_nitrogen_pressure[i] = nitrogen_pressure[i]; | |
2044 helium_pressure[i] += (inspired_helium_pressure - helium_pressure[i]) * float_buehlmann_He_factor_expositon_one_hour[i]; | |
2045 nitrogen_pressure[i] += (inspired_nitrogen_pressure - nitrogen_pressure[i]) * float_buehlmann_N2_factor_expositon_one_hour[i]; | |
2046 } | |
2047 calc_deco_ceiling(&deco_ceiling_depth, false); | |
2048 } | |
2049 if(deco_ceiling_depth < next_stop) | |
2050 { | |
2051 segment_time -= 60; | |
2052 gCNS_VPM = initial_CNS; | |
2053 for (i = 0; i < 16; i++) | |
2054 { | |
2055 helium_pressure[i] = initial_helium_pressure[i]; | |
2056 nitrogen_pressure[i] = initial_nitrogen_pressure[i]; | |
2057 } | |
2058 deco_ceiling_depth = next_stop +1; | |
2059 } | |
2060 count = 0; | |
2061 while (deco_ceiling_depth > next_stop && count < 13) | |
2062 { | |
2063 count++; | |
2064 segment_time += 5; | |
2065 //goto L700; | |
2066 initial_CNS = gCNS_VPM; | |
2067 decom_oxygen_calculate_cns_exposure(60*5,&pDiveSettings->decogaslist[mix_number],ambient_pressure/10,&gCNS_VPM); | |
2068 for (i = 0; i < 16; i++) | |
2069 { | |
2070 initial_helium_pressure[i] = helium_pressure[i]; | |
2071 initial_nitrogen_pressure[i] = nitrogen_pressure[i]; | |
2072 helium_pressure[i] += (inspired_helium_pressure - helium_pressure[i]) * float_buehlmann_He_factor_expositon_five_minutes[i]; | |
2073 nitrogen_pressure[i] += (inspired_nitrogen_pressure - nitrogen_pressure[i]) * float_buehlmann_N2_factor_expositon_five_minutes[i]; | |
2074 } | |
2075 calc_deco_ceiling(&deco_ceiling_depth, false); | |
2076 } | |
2077 if(deco_ceiling_depth < next_stop) | |
2078 { | |
2079 segment_time -= 5; | |
2080 gCNS_VPM = initial_CNS; | |
2081 for (i = 0; i < 16; i++) { | |
2082 helium_pressure[i] = initial_helium_pressure[i]; | |
2083 nitrogen_pressure[i] = initial_nitrogen_pressure[i]; | |
2084 } | |
2085 deco_ceiling_depth = next_stop +1; | |
2086 } | |
2087 buehlmann_wait = false; | |
2088 while (buehlmann_wait || (deco_ceiling_depth > next_stop)) | |
2089 { | |
2090 //time_counter = temp_segment_time; | |
2091 segment_time += 1; | |
2092 | |
2093 if(segment_time >= 999 ) | |
2094 { | |
2095 segment_time = 999 ; | |
2096 run_time += segment_time; | |
2097 return; | |
2098 } | |
2099 //goto L700; | |
2100 initial_CNS = gCNS_VPM; | |
2101 decom_oxygen_calculate_cns_exposure(60*1,&pDiveSettings->decogaslist[mix_number],ambient_pressure/10,&gCNS_VPM); | |
2102 for (i = 0; i < 16; i++) | |
2103 { | |
2104 initial_helium_pressure[i] = helium_pressure[i]; | |
2105 initial_nitrogen_pressure[i] = nitrogen_pressure[i]; | |
2106 helium_pressure[i] += (inspired_helium_pressure - helium_pressure[i]) * float_buehlmann_He_factor_expositon_one_minute[i]; | |
2107 nitrogen_pressure[i] += (inspired_nitrogen_pressure - nitrogen_pressure[i]) * float_buehlmann_N2_factor_expositon_one_minute[i]; | |
2108 } | |
2109 if(!buehlmann_wait) | |
2110 calc_deco_ceiling(&deco_ceiling_depth, false); | |
2111 | |
2112 if(buehlmannSafety && final_deco_calculation && !(deco_ceiling_depth > next_stop)) | |
2113 { | |
2114 for (i = 0; i < 16; i++) | |
2115 { | |
2116 tissue_He_saturation[i] = helium_pressure[i] / 10; | |
2117 tissue_N2_saturation[i] = nitrogen_pressure[i] / 10; | |
2118 } | |
2119 if( (fabsf(nitrogen_pressure[15] - inspired_nitrogen_pressure) < 0.00001f) && (fabsf(helium_pressure[15] - inspired_helium_pressure) < 0.00001f) | |
2120 && (fabsf(nitrogen_pressure[0] - inspired_nitrogen_pressure) < 0.00001f) && (fabsf(helium_pressure[0] - inspired_helium_pressure) < 0.00001f)) | |
2121 { | |
2122 buehlmann_wait_exceeded = true; | |
2123 break; | |
2124 } | |
2125 | |
2126 if(decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (next_stop / 10.0f) + pInput->pressure_surface_bar)) | |
2127 break; | |
2128 | |
2129 buehlmann_wait = true; | |
2130 } | |
2131 } | |
2132 if(buehlmann_wait) | |
149 | 2133 { |
38 | 2134 vpm_violates_buehlmann = true; |
149 | 2135 } |
2136 if(!buehlmann_wait) | |
38 | 2137 { |
2138 if(deco_ceiling_depth < next_stop) | |
2139 { | |
2140 segment_time -= 1; | |
2141 gCNS_VPM = initial_CNS; | |
2142 for (i = 0; i < 16; i++) { | |
2143 helium_pressure[i] = initial_helium_pressure[i]; | |
2144 nitrogen_pressure[i] = initial_nitrogen_pressure[i]; | |
2145 } | |
2146 deco_ceiling_depth = next_stop +1; | |
2147 } | |
2148 while (deco_ceiling_depth > next_stop) | |
2149 { | |
2150 //time_counter = temp_segment_time; | |
2151 segment_time += (float) 1.0f / 3.0f; | |
2152 //goto L700; | |
2153 initial_CNS = gCNS_VPM; | |
2154 decom_oxygen_calculate_cns_exposure(20,&pDiveSettings->decogaslist[mix_number],ambient_pressure/10,&gCNS_VPM); | |
2155 for (i = 0; i < 16; i++) | |
2156 { | |
2157 helium_pressure[i] += (inspired_helium_pressure - helium_pressure[i]) * float_buehlmann_He_factor_expositon_20_seconds[i]; | |
2158 nitrogen_pressure[i] += (inspired_nitrogen_pressure - nitrogen_pressure[i]) * float_buehlmann_N2_factor_expositon_20_seconds[i]; | |
2159 } | |
2160 calc_deco_ceiling(&deco_ceiling_depth, false); | |
2161 } | |
2162 } | |
2163 } | |
2164 | |
2165 /*float pressure_save =dive_data.pressure; | |
2166 dive_data.pressure = ambient_pressure/10; | |
2167 tissues_exposure_stage(st_deco_test,(int)(segment_time * 60), &dive_data, &gaslist); | |
2168 dive_data.pressure = pressure_save;*/ | |
2169 run_time += segment_time; | |
2170 return; | |
2171 } /* decompression_stop */ | |
2172 | |
2173 /* =============================================================================== */ | |
2174 // SUROUTINE BOYLES_LAW_COMPENSATION | |
2175 // Purpose: This subprogram calculates the reduction in allowable gradients | |
2176 // with decreasing ambient pressure during the decompression profile based | |
2177 // on Boyle's Law considerations. | |
2178 //=============================================================================== | |
290 | 2179 static void BOYLES_LAW_COMPENSATION (float* First_Stop_Depth, |
38 | 2180 float* Deco_Stop_Depth, |
2181 float* Step_Size) | |
2182 { | |
2183 short i; | |
2184 | |
2185 float Next_Stop; | |
2186 float Ambient_Pressure_First_Stop, Ambient_Pressure_Next_Stop; | |
2187 float Amb_Press_First_Stop_Pascals, Amb_Press_Next_Stop_Pascals; | |
2188 float A, B, C, Low_Bound, High_Bound, Ending_Radius; | |
2189 float Deco_Gradient_Pascals; | |
2190 float Allow_Grad_First_Stop_He_Pa, Radius_First_Stop_He; | |
2191 float Allow_Grad_First_Stop_N2_Pa, Radius_First_Stop_N2; | |
2192 | |
2193 //=============================================================================== | |
2194 // LO//AL ARRAYS | |
2195 //=============================================================================== | |
2196 // float Radius1_He[16], Radius2_He[16]; | |
2197 // float Radius1_N2[16], Radius2_N2[16]; | |
2198 float root_factor; | |
2199 | |
2200 //=============================================================================== | |
2201 // CALCULATIONS | |
2202 //=============================================================================== | |
2203 Next_Stop = *Deco_Stop_Depth - *Step_Size; | |
2204 | |
2205 Ambient_Pressure_First_Stop = *First_Stop_Depth + | |
2206 barometric_pressure; | |
2207 | |
2208 Ambient_Pressure_Next_Stop = Next_Stop + barometric_pressure; | |
2209 | |
2210 Amb_Press_First_Stop_Pascals = (Ambient_Pressure_First_Stop/UNITS_FACTOR) * 101325.0f; | |
2211 | |
2212 Amb_Press_Next_Stop_Pascals = | |
2213 (Ambient_Pressure_Next_Stop/UNITS_FACTOR) * 101325.0f; | |
2214 root_factor = powf(Amb_Press_First_Stop_Pascals/Amb_Press_Next_Stop_Pascals,1.0f / 3.0f); | |
2215 | |
2216 for( i = 0; i < 16;i++) | |
2217 { | |
2218 Allow_Grad_First_Stop_He_Pa = | |
2219 (allowable_gradient_he[i]/UNITS_FACTOR) * 101325.0f; | |
2220 | |
2221 Radius_First_Stop_He = (2.0f * SURFACE_TENSION_GAMMA) / | |
2222 Allow_Grad_First_Stop_He_Pa; | |
2223 | |
2224 // Radius1_He[i] = Radius_First_Stop_He; | |
2225 A = Amb_Press_Next_Stop_Pascals; | |
2226 B = -2.0f * SURFACE_TENSION_GAMMA; | |
2227 C = (Amb_Press_First_Stop_Pascals + (2.0f * SURFACE_TENSION_GAMMA)/ | |
2228 Radius_First_Stop_He)* Radius_First_Stop_He* | |
2229 (Radius_First_Stop_He*(Radius_First_Stop_He)); | |
2230 Low_Bound = Radius_First_Stop_He; | |
2231 High_Bound = Radius_First_Stop_He * root_factor; | |
2232 //*pow(Amb_Press_First_Stop_Pascals/Amb_Press_Next_Stop_Pascals,1.0/3.0); | |
2233 //*(Amb_Press_First_Stop_Pascals/Amb_Press_Next_Stop_Pascals)**(1.0/3.0); | |
2234 | |
2235 radius_root_finder(&A,&B,&C, &Low_Bound, &High_Bound, | |
2236 &Ending_Radius); | |
2237 | |
2238 // Radius2_He[i] = Ending_Radius; | |
2239 Deco_Gradient_Pascals = (2.0f * SURFACE_TENSION_GAMMA) / | |
2240 Ending_Radius; | |
2241 | |
2242 deco_gradient_he[i] = (Deco_Gradient_Pascals / 101325.0f)* | |
2243 UNITS_FACTOR; | |
2244 | |
2245 } | |
2246 | |
2247 for( i = 0; i < 16;i++) | |
2248 { | |
2249 Allow_Grad_First_Stop_N2_Pa = | |
2250 (allowable_gradient_n2[i]/UNITS_FACTOR) * 101325.0f; | |
2251 | |
2252 Radius_First_Stop_N2 = (2.0f * SURFACE_TENSION_GAMMA) / | |
2253 Allow_Grad_First_Stop_N2_Pa; | |
2254 | |
2255 // Radius1_N2[i] = Radius_First_Stop_N2; | |
2256 A = Amb_Press_Next_Stop_Pascals; | |
2257 B = -2.0f * SURFACE_TENSION_GAMMA; | |
2258 C = (Amb_Press_First_Stop_Pascals + (2.0f * SURFACE_TENSION_GAMMA)/ | |
2259 Radius_First_Stop_N2)* Radius_First_Stop_N2* | |
2260 (Radius_First_Stop_N2*(Radius_First_Stop_N2)); | |
2261 Low_Bound = Radius_First_Stop_N2; | |
2262 High_Bound = Radius_First_Stop_N2* root_factor;//pow(Amb_Press_First_Stop_Pascals/Amb_Press_Next_Stop_Pascals,1.0/3.0); | |
2263 | |
2264 //High_Bound = Radius_First_Stop_N2*exp(log(Amb_Press_First_Stop_Pascals/Amb_Press_Next_Stop_Pascals)/3); | |
2265 radius_root_finder(&A,&B,&C, &Low_Bound, &High_Bound, | |
2266 &Ending_Radius); | |
2267 | |
2268 // Radius2_N2[i] = Ending_Radius; | |
2269 Deco_Gradient_Pascals = (2.0f * SURFACE_TENSION_GAMMA) / | |
2270 Ending_Radius; | |
2271 | |
2272 deco_gradient_n2[i] = (Deco_Gradient_Pascals / 101325.0f)* | |
2273 UNITS_FACTOR; | |
2274 } | |
2275 } | |
2276 | |
2277 /* =============================================================================== */ | |
292 | 2278 // vpm_calc_ndl |
2279 // Purpose: This function computes NDL (time where no decostops are needed) | |
38 | 2280 //=============================================================================== |
291
24ff72e627f4
Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents:
290
diff
changeset
|
2281 #define MAX_NDL 240 |
24ff72e627f4
Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents:
290
diff
changeset
|
2282 |
292 | 2283 static int vpm_calc_ndl(void) |
38 | 2284 { |
2285 static float future_helium_pressure[16]; | |
2286 static float future_nitrogen_pressure[16]; | |
2287 static int temp_segment_time; | |
2288 static int mix_number; | |
2289 static float inspired_helium_pressure; | |
2290 static float inspired_nitrogen_pressure; | |
2291 | |
2292 float previous_helium_pressure[16]; | |
2293 float previous_nitrogen_pressure[16]; | |
2294 float ambient_pressure; | |
2295 float fraction_helium_begin; | |
2296 float fraction_nitrogen_begin; | |
2297 int i = 0; | |
2298 int count = 0; | |
2299 int status = CALC_END; | |
291
24ff72e627f4
Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents:
290
diff
changeset
|
2300 |
38 | 2301 for(i = 0; i < 16;i++) |
2302 { | |
2303 future_helium_pressure[i] = pInput->tissue_helium_bar[i] * 10;//tissue_He_saturation[st_dive][i] * 10; | |
2304 future_nitrogen_pressure[i] = pInput->tissue_nitrogen_bar[i] * 10; | |
2305 } | |
2306 temp_segment_time = 0; | |
2307 | |
2308 mix_number = 0; | |
2309 ambient_pressure = pInput->pressure_ambient_bar * 10; | |
2310 decom_get_inert_gases( ambient_pressure / 10, (&pDiveSettings->decogaslist[mix_number]) , &fraction_nitrogen_begin, &fraction_helium_begin ); | |
2311 inspired_helium_pressure =(ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_helium_begin; | |
2312 inspired_nitrogen_pressure =(ambient_pressure - WATER_VAPOR_PRESSURE) *fraction_nitrogen_begin; | |
2313 | |
2314 status = CALC_END; | |
2315 while (status == CALC_END) | |
2316 { | |
2317 count++; | |
2318 temp_segment_time += 60; | |
291
24ff72e627f4
Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents:
290
diff
changeset
|
2319 if(temp_segment_time >= MAX_NDL) |
38 | 2320 { |
2321 pDecoInfo->output_ndl_seconds = temp_segment_time * 60; | |
292 | 2322 return CALC_NDL; |
38 | 2323 } |
2324 run_time += 60; | |
2325 //goto L700; | |
2326 for (i = 1; i <= 16; ++i) { | |
2327 previous_helium_pressure[i-1] = future_helium_pressure[i - 1]; | |
2328 previous_nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1]; | |
2329 future_helium_pressure[i - 1] = future_helium_pressure[i - 1] + (inspired_helium_pressure - future_helium_pressure[i - 1]) * float_buehlmann_He_factor_expositon_one_hour[i-1]; | |
2330 future_nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1] + (inspired_nitrogen_pressure - future_nitrogen_pressure[i - 1]) * float_buehlmann_N2_factor_expositon_one_hour[i-1]; | |
2331 helium_pressure[i - 1] = future_helium_pressure[i - 1]; | |
2332 nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1]; | |
2333 } | |
2334 vpm_calc_deco(); | |
2335 while((status = vpm_calc_critcal_volume(true,true)) == CALC_CRITICAL); | |
2336 | |
2337 } | |
2338 | |
2339 temp_segment_time -= 60; | |
2340 run_time -= 60; | |
2341 for (i = 1; i <= 16; ++i) | |
2342 { | |
2343 future_helium_pressure[i - 1] = previous_helium_pressure[i-1]; | |
2344 future_nitrogen_pressure[i - 1] = previous_nitrogen_pressure[i - 1]; | |
2345 } | |
2346 | |
2347 status = CALC_END; | |
2348 if(temp_segment_time < 60) | |
2349 nullzeit_unter60 = true; | |
2350 | |
2351 while (status == CALC_END) | |
2352 { | |
2353 temp_segment_time += 5; | |
291
24ff72e627f4
Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents:
290
diff
changeset
|
2354 if(temp_segment_time >= MAX_NDL) |
38 | 2355 { |
2356 pDecoInfo->output_ndl_seconds = temp_segment_time * 60; | |
292 | 2357 return CALC_NDL; |
38 | 2358 } |
2359 if(nullzeit_unter60 && temp_segment_time > 60) | |
2360 { | |
2361 nullzeit_unter60 = false; | |
292 | 2362 return CALC_NDL; |
38 | 2363 } |
2364 run_time += 5; | |
2365 //goto L700; | |
2366 for (i = 1; i <= 16; ++i) { | |
2367 previous_helium_pressure[i-1] = future_helium_pressure[i - 1]; | |
2368 previous_nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1]; | |
2369 future_helium_pressure[i - 1] = future_helium_pressure[i - 1] + (inspired_helium_pressure - future_helium_pressure[i - 1]) * float_buehlmann_He_factor_expositon_five_minutes[i-1]; | |
2370 future_nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1] + (inspired_nitrogen_pressure - future_nitrogen_pressure[i - 1]) * float_buehlmann_N2_factor_expositon_five_minutes[i-1]; | |
2371 helium_pressure[i - 1] = future_helium_pressure[i - 1]; | |
2372 nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1]; | |
2373 } | |
2374 vpm_calc_deco(); | |
2375 while((status =vpm_calc_critcal_volume(true,true)) == CALC_CRITICAL); | |
2376 } | |
2377 temp_segment_time -= 5; | |
2378 run_time -= 5; | |
2379 for (i = 1; i <= 16; ++i) { | |
2380 future_helium_pressure[i - 1] = previous_helium_pressure[i-1]; | |
2381 future_nitrogen_pressure[i - 1] = previous_nitrogen_pressure[i - 1]; | |
2382 } | |
2383 status = CALC_END; | |
291
24ff72e627f4
Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents:
290
diff
changeset
|
2384 |
38 | 2385 if(temp_segment_time <= 20) |
2386 { | |
2387 while (status == CALC_END) | |
2388 { | |
2389 temp_segment_time += minimum_deco_stop_time; | |
2390 run_time += minimum_deco_stop_time; | |
2391 //goto L700; | |
2392 for (i = 1; i <= 16; ++i) { | |
2393 future_helium_pressure[i - 1] = future_helium_pressure[i - 1] + (inspired_helium_pressure - future_helium_pressure[i - 1]) * float_buehlmann_He_factor_expositon_one_minute[i-1]; | |
2394 future_nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1] + (inspired_nitrogen_pressure - future_nitrogen_pressure[i - 1]) * float_buehlmann_N2_factor_expositon_one_minute[i-1]; | |
2395 helium_pressure[i - 1] = future_helium_pressure[i - 1]; | |
2396 nitrogen_pressure[i - 1] =future_nitrogen_pressure[i - 1]; | |
2397 | |
2398 } | |
2399 vpm_calc_deco(); | |
2400 while((status =vpm_calc_critcal_volume(true,true)) == CALC_CRITICAL); | |
2401 | |
2402 } | |
2403 } | |
2404 else | |
2405 temp_segment_time += 5; | |
2406 pDecoInfo->output_ndl_seconds = temp_segment_time * 60; | |
2407 if(temp_segment_time > 1) | |
292 | 2408 return CALC_NDL; |
38 | 2409 else |
2410 return CALC_BEGIN; | |
2411 } |