Mercurial > public > ostc4
comparison Discovery/Src/vpm.c @ 295:718e5feded62
Merged in janlmulder/ostc4/div-fixes-6 (pull request #23)
Cleanup VPM, NDL to 240 min, and more cleanup
author | heinrichsweikamp <bitbucket@heinrichsweikamp.com> |
---|---|
date | Mon, 13 May 2019 13:37:34 +0000 |
parents | 02d10d955be2 |
children | 305f251cc981 |
comparison
equal
deleted
inserted
replaced
287:ba9d99a2e310 | 295:718e5feded62 |
---|---|
75 #include <stdlib.h> | 75 #include <stdlib.h> |
76 #include <string.h> | 76 #include <string.h> |
77 #include <math.h> | 77 #include <math.h> |
78 #include <time.h> | 78 #include <time.h> |
79 | 79 |
80 //#include "compiler.h" | |
81 //#include "sdramc.h" | |
82 #include "vpm.h" | 80 #include "vpm.h" |
83 //#include "buehlmann.h" | |
84 | |
85 #include "decom.h" | 81 #include "decom.h" |
86 | |
87 //#include "decompression.h" | |
88 //#include "taskmanagement\tissue_calls.h" | |
89 #define true 1 | |
90 #define false 0 | |
91 | 82 |
92 #define GAS_N2 0 | 83 #define GAS_N2 0 |
93 #define GAS_HE 1 | 84 #define GAS_HE 1 |
94 /* temp vars to simplify UNFMTLISTs */ | 85 |
95 float fO2, fHe, fN2; | 86 static const _Bool buehlmannSafety = true; |
96 float dc, rc, ssc; | |
97 short mc; | |
98 | |
99 const _Bool buehlmannSafety = true; | |
100 /* Common Block Declarations */ | 87 /* Common Block Declarations */ |
101 | 88 |
102 extern const float SURFACE_TENSION_GAMMA; //!Adj. Range: 0.015 to 0.065 N/m | 89 extern const float SURFACE_TENSION_GAMMA; //!Adj. Range: 0.015 to 0.065 N/m |
103 extern const float SKIN_COMPRESSION_GAMMAC; //!Adj. Range: 0.160 to 0.290 N/m | 90 extern const float SKIN_COMPRESSION_GAMMAC; //!Adj. Range: 0.160 to 0.290 N/m |
104 extern const float UNITS_FACTOR; | 91 extern const float UNITS_FACTOR; |
105 extern const float WATER_VAPOR_PRESSURE; // (Schreiner value) based on respiratory quotien | 92 extern const float WATER_VAPOR_PRESSURE; // (Schreiner value) based on respiratory quotien |
106 extern const float CRIT_VOLUME_PARAMETER_LAMBDA; //!Adj. Range: 6500 to 8300 fsw-min | 93 extern const float CRIT_VOLUME_PARAMETER_LAMBDA; //!Adj. Range: 6500 to 8300 fsw-min |
107 extern const float GRADIENT_ONSET_OF_IMPERM_ATM; //!Adj. Range: 5.0 to 10.0 atm | 94 //extern const float GRADIENT_ONSET_OF_IMPERM_ATM; //!Adj. Range: 5.0 to 10.0 atm |
108 extern const float REGENERATION_TIME_CONSTANT; //!Adj. Range: 10080 to 51840 min | 95 extern const float REGENERATION_TIME_CONSTANT; //!Adj. Range: 10080 to 51840 min |
109 extern const float PRESSURE_OTHER_GASES_MMHG; //!Constant value for PO2 up to 2 atm | 96 //extern const float PRESSURE_OTHER_GASES_MMHG; //!Constant value for PO2 up to 2 atm |
110 extern const float CONSTANT_PRESSURE_OTHER_GASES; // PRESSURE_OTHER_GASES_MMHG / 760. * UNITS_FACTOR; | 97 extern const float CONSTANT_PRESSURE_OTHER_GASES; // PRESSURE_OTHER_GASES_MMHG / 760. * UNITS_FACTOR; |
111 | 98 |
112 extern const float HELIUM_TIME_CONSTANT[]; | 99 extern const float HELIUM_TIME_CONSTANT[]; |
113 extern const float NITROGEN_TIME_CONSTANT[]; | 100 extern const float NITROGEN_TIME_CONSTANT[]; |
114 | 101 |
115 float minimum_deco_stop_time; | 102 static float minimum_deco_stop_time; |
116 float run_time, run_time_first_stop; | 103 static float run_time, run_time_first_stop; |
117 float segment_time; | 104 static float segment_time; |
118 short mix_number; | 105 static short mix_number; |
119 float barometric_pressure; | 106 static float barometric_pressure; |
120 _Bool altitude_dive_algorithm_off; | 107 static _Bool altitude_dive_algorithm_off; |
121 _Bool units_equal_fsw, units_equal_msw; | 108 static _Bool units_equal_fsw, units_equal_msw; |
122 | 109 |
123 /* by hw 11.06.2015 to allow */ | 110 /* by hw 11.06.2015 to allow */ |
124 float gCNS_VPM; | 111 static float gCNS_VPM; |
125 | 112 |
126 float helium_pressure[16], nitrogen_pressure[16]; | 113 static float helium_pressure[16], nitrogen_pressure[16]; |
127 //float helium_pressure_crush[16], nitrogen_pressure_crush[16]; | 114 static float surface_phase_volume_time[16]; |
128 //float fraction_helium[MAX_GASMIXES + EXTRA_GASMIXES], fraction_nitrogen[MAX_GASMIXES + EXTRA_GASMIXES]; | 115 static float regenerated_radius_he[16], regenerated_radius_n2[16]; |
129 //float initial_critical_radius_he[16], initial_critical_radius_n2[16]; | 116 static float allowable_gradient_he[16], allowable_gradient_n2[16]; |
130 //float adjusted_critical_radius_he[16], | |
131 //adjusted_critical_radius_n2[16]; | |
132 //float max_crushing_pressure_he[16], | |
133 //max_crushing_pressure_n2[16]; | |
134 float surface_phase_volume_time[16]; | |
135 //float max_actual_gradient[16]; | |
136 //float amb_pressure_onset_of_imperm[16], | |
137 //gas_tension_onset_of_imperm[16]; | |
138 //float initial_helium_pressure_global[16], | |
139 //initial_nitrogen_pressure_global[16]; | |
140 float regenerated_radius_he[16], | |
141 regenerated_radius_n2[16]; | |
142 //float adjusted_crushing_pressure_he[16], | |
143 //adjusted_crushing_pressure_n2[16]; | |
144 float allowable_gradient_he[16], | |
145 allowable_gradient_n2[16]; | |
146 //float initial_allowable_gradient_he[16], | |
147 //initial_allowable_gradient_n2[16]; | |
148 | 117 |
149 //_Bool deco_zone_reached; | 118 //_Bool deco_zone_reached; |
150 _Bool critical_volume_algorithm_off; | 119 static _Bool critical_volume_algorithm_off; |
151 float max_first_stop_depth; | 120 static float max_first_stop_depth; |
152 float max_deco_ceiling_depth; | 121 static float max_deco_ceiling_depth; |
153 long vpm_time_calc_begin = 0; | |
154 //Boylslaw compensation | 122 //Boylslaw compensation |
155 float deco_gradient_he[16]; | 123 static float deco_gradient_he[16]; |
156 float deco_gradient_n2[16]; | 124 static float deco_gradient_n2[16]; |
157 int last_nullzeit; | 125 static int vpm_calc_what; |
158 int vpm_calc_what; | 126 static int count_critical_volume_iteration; |
159 int count_critical_volume_iteration; | 127 static short number_of_changes; |
160 short number_of_changes; | 128 static float depth_change[11]; |
161 float depth_change[11]; | 129 static float step_size_change[11]; |
162 float step_size_change[11]; | 130 static float rate_change[11]; |
163 float rate_change[11]; | 131 static short mix_change[11]; |
164 short mix_change[11]; | 132 |
165 | 133 static const _Bool vpm_b = true; |
166 const _Bool vpm_b = true; | 134 |
167 | |
168 //extern | |
169 /*extern float tissue_N2_saturation[4][16]; | |
170 extern float tissue_He_saturation[4][16]; | |
171 extern long dv_divetime; | |
172 extern dive_data_t dive_data; | |
173 extern int dive_ambient_pressure_mbar; | |
174 extern long dv_seconds_since_last_dive; | |
175 extern int tts[4];*/ | |
176 extern const float float_buehlmann_N2_factor_expositon_20_seconds[]; | 135 extern const float float_buehlmann_N2_factor_expositon_20_seconds[]; |
177 extern const float float_buehlmann_He_factor_expositon_20_seconds[]; | 136 extern const float float_buehlmann_He_factor_expositon_20_seconds[]; |
178 extern const float float_buehlmann_N2_factor_expositon_one_minute[]; | 137 extern const float float_buehlmann_N2_factor_expositon_one_minute[]; |
179 extern const float float_buehlmann_He_factor_expositon_one_minute[]; | 138 extern const float float_buehlmann_He_factor_expositon_one_minute[]; |
180 extern const float float_buehlmann_N2_factor_expositon_five_minutes[]; | 139 extern const float float_buehlmann_N2_factor_expositon_five_minutes[]; |
181 extern const float float_buehlmann_He_factor_expositon_five_minutes[]; | 140 extern const float float_buehlmann_He_factor_expositon_five_minutes[]; |
182 extern const float float_buehlmann_N2_factor_expositon_one_hour[]; | 141 extern const float float_buehlmann_N2_factor_expositon_one_hour[]; |
183 extern const float float_buehlmann_He_factor_expositon_one_hour[]; | 142 extern const float float_buehlmann_He_factor_expositon_one_hour[]; |
184 | 143 |
185 //extern buehlmann_configuration_t buehlmann_config; | 144 static float depth_start_of_deco_calc; |
186 | 145 static float depth_start_of_deco_zone; |
187 extern unsigned char CCR_mode; //0x100 // by tissue_calls.c // uchar | 146 static float first_stop_depth; |
188 | 147 static float run_time_start_of_deco_zone; |
189 //extern gaschange2_t gaschange_CCR_backup[2][BUEHLMANN_STRUCT_MAX_GASES]; | 148 |
190 | 149 static float r_nint(float *x); |
191 | 150 static float r_int(float *x); |
192 float starting_ambient_pressure_global; | 151 static _Bool nullzeit_unter60; |
193 float ending_ambient_pressure_global; | 152 static int vpm_calc_status; |
194 float depth_start_of_deco_calc; | 153 static _Bool buehlmann_wait_exceeded = false; |
195 float depth_start_of_deco_zone; | 154 |
196 float first_stop_depth; | 155 static SLifeData* pInput = NULL; |
197 float run_time_start_of_deco_zone; | 156 static SVpm* pVpm = NULL; |
198 | 157 static SDecoinfo* pDecoInfo = NULL; |
199 float r_nint(float *x); | 158 static SDiveSettings* pDiveSettings = NULL; |
200 float r_int(float *x); | 159 |
201 _Bool repetitive_variables_not_valid = false; | 160 static float r_nint(float *x) |
202 _Bool nullzeit_unter60; | |
203 //enum VPM_CALC_STATUS{CALC_END,CALC_BEGIN,CALC_NULLZEIT }; | |
204 int vpm_calc_status; | |
205 _Bool buehlmann_wait_exceeded = false; | |
206 | |
207 SLifeData* pInput = NULL; | |
208 SVpm* pVpm = NULL; | |
209 SDecoinfo* pDecoInfo = NULL; | |
210 SDiveSettings* pDiveSettings = NULL; | |
211 float r_nint(float *x) | |
212 { | 161 { |
213 return( (*x)>=0 ? | 162 return( (*x)>=0 ? |
214 floorf(*x + 0.5f) : -floorf(0.5f - *x) ); | 163 floorf(*x + 0.5f) : -floorf(0.5f - *x) ); |
215 } | 164 } |
216 | 165 |
217 float r_int(float *x) | 166 static float r_int(float *x) |
218 { | 167 { |
219 return( (*x>0) ? floorf(*x) : -floorf(- *x) ); | 168 return( (*x>0) ? floorf(*x) : -floorf(- *x) ); |
220 } | 169 } |
221 | 170 |
222 /** private functions | 171 /** private functions |
223 */ | 172 */ |
224 int onset_of_impermeability(float *starting_ambient_pressure, float *ending_ambient_pressure, float *rate, short *i); | 173 extern int radius_root_finder (float *a, float *b, float *c,float *low_bound, float *high_bound, float *ending_radius); |
225 int radius_root_finder (float *a, float *b, float *c,float *low_bound, float *high_bound, float *ending_radius); | 174 |
226 int nuclear_regeneration(float *dive_time);// clock_(); | 175 static int nuclear_regeneration(float *dive_time);// clock_(); |
227 int calc_deco_ceiling(float *deco_ceiling_depth,_Bool fallowablw); | 176 static int calc_deco_ceiling(float *deco_ceiling_depth,_Bool fallowablw); |
228 | 177 static int critical_volume(float *deco_phase_volume_time); ; |
229 int calc_barometric_pressure(float *altitude); | 178 static int calc_start_of_deco_zone(float *starting_depth, float *rate, float *depth_start_of_deco_zone); |
230 //extern /* Subroutine */ int vpm_repetitive_algorithm(); | 179 static int calc_initial_allowable_gradient(void); |
231 //extern /* Subroutine */ int gas_loadings_surface_interval(); | 180 static void decompression_stop(float *deco_stop_depth, float *step_size, _Bool final_deco_calculation); |
232 int critical_volume(float *deco_phase_volume_time); ; | 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); |
233 int calc_start_of_deco_zone(float *starting_depth, float *rate, float *depth_start_of_deco_zone); | 182 static int calc_surface_phase_volume_time(void); |
234 | 183 static int calc_max_actual_gradient(float *deco_stop_depth); |
235 int calc_initial_allowable_gradient(void); | 184 static int projected_ascent(float *starting_depth, float *rate, float *deco_stop_depth, float *step_size); |
236 void decompression_stop(float *deco_stop_depth, float *step_size, _Bool final_deco_calculation); | 185 static void vpm_calc_deco(void); |
237 int gas_loadings_ascent_descen(float* helium_pressure, float* nitrogen_pressure, float starting_depth,float ending_depth, float rate,_Bool check_gas_change); | 186 static int vpm_calc_critcal_volume(_Bool begin,_Bool calc_nulltime); |
238 | 187 static int vpm_check_converged(_Bool calc_nulltime); |
239 int calc_surface_phase_volume_time(void); | 188 static int vpm_calc_final_deco(_Bool begin); |
240 int calc_max_actual_gradient(float *deco_stop_depth); | 189 static void BOYLES_LAW_COMPENSATION (float* First_Stop_Depth,float * Deco_Stop_Depth,float* Step_Size); |
241 int projected_ascent(float *starting_depth, float *rate, float *deco_stop_depth, float *step_size); | 190 static int vpm_calc_ndl(void); |
242 void vpm_calc_deco(void); | 191 static void vpm_init_1(void); |
243 int vpm_calc_critcal_volume(_Bool begin,_Bool calc_nulltime); | 192 static void vpm_calc_deco_ceiling(void); |
244 int vpm_check_converged(_Bool calc_nulltime); | 193 |
245 int vpm_calc_final_deco(_Bool begin); | 194 static void vpm_init_1(void) |
246 void BOYLES_LAW_COMPENSATION (float* First_Stop_Depth,float * Deco_Stop_Depth,float* Step_Size); | |
247 int vpm_calc_nullzeit(void); | |
248 int vpm_repetitive_algorithm(float *surface_interval_time); | |
249 void vpm_init_1(void); | |
250 | |
251 void vpm_calc_deco_ceiling(void); | |
252 | |
253 //extern /* Subroutine */ int gas_loadings_constant_depth(); | |
254 //extern /* Subroutine */ int vpm_altitude_dive_algorithm(); | |
255 //extern /* Subroutine */ int calc_max_actual_gradient(), | |
256 //projected_ascent(); | |
257 | |
258 void ______X_X_X___________________________________________________________(void); | |
259 | |
260 //#define ARGGG | |
261 | |
262 void vpm_reset_variables(void) | |
263 { | |
264 repetitive_variables_not_valid = true; | |
265 } | |
266 | |
267 void vpm_init_1(void) | |
268 { | 195 { |
269 units_equal_msw = true; | 196 units_equal_msw = true; |
270 units_equal_fsw = false; | 197 units_equal_fsw = false; |
271 altitude_dive_algorithm_off= true; //!Options: ON or OFF | 198 altitude_dive_algorithm_off= true; //!Options: ON or OFF |
272 minimum_deco_stop_time=1.0; //!Options: float positive number | 199 minimum_deco_stop_time=1.0; //!Options: float positive number |
311 for(int i=0;i<DECOINFO_STRUCT_MAX_STOPS;i++) | 238 for(int i=0;i<DECOINFO_STRUCT_MAX_STOPS;i++) |
312 { | 239 { |
313 pDECOINFO->output_stop_length_seconds[i] = 0; | 240 pDECOINFO->output_stop_length_seconds[i] = 0; |
314 } | 241 } |
315 | 242 |
316 if(pINPUT->dive_time_seconds < 10) | 243 if(pINPUT->dive_time_seconds < 60) |
317 { | 244 { |
318 vpm_calc_status = CALC_NULLZEIT; | 245 vpm_calc_status = CALC_NDL; |
319 return vpm_calc_status; | 246 return vpm_calc_status; |
320 } | 247 } |
321 pVpm = pVPM; | 248 pVpm = pVPM; |
322 pInput = pINPUT; | 249 pInput = pINPUT; |
323 pDecoInfo = pDECOINFO; | 250 pDecoInfo = pDECOINFO; |
324 pDiveSettings = pSettings; | 251 pDiveSettings = pSettings; |
325 | 252 |
326 if(vpm_calc_status == CALC_NULLZEIT) | 253 if(vpm_calc_status == CALC_NDL) |
327 { | 254 { |
328 tmp_calc_status = vpm_calc_nullzeit(); | 255 tmp_calc_status = vpm_calc_ndl(); |
329 } | 256 } |
330 else | 257 else |
331 { | 258 { |
332 tmp_calc_status = CALC_BEGIN; | 259 tmp_calc_status = CALC_BEGIN; |
333 } | 260 } |
334 //Normal Deco calculation | 261 //Normal Deco calculation |
335 if(tmp_calc_status != CALC_NULLZEIT) | 262 if(tmp_calc_status != CALC_NDL) |
336 { | 263 { |
337 max_first_stop_depth = pVpm->max_first_stop_depth_save; | 264 max_first_stop_depth = pVpm->max_first_stop_depth_save; |
338 run_time_start_of_deco_zone = pVpm->run_time_start_of_deco_zone_save; | 265 run_time_start_of_deco_zone = pVpm->run_time_start_of_deco_zone_save; |
339 depth_start_of_deco_zone = pVpm->depth_start_of_deco_zone_save; | 266 depth_start_of_deco_zone = pVpm->depth_start_of_deco_zone_save; |
340 for (int i = 0; i < 16; ++i) { | 267 for (int i = 0; i < 16; ++i) { |
387 /* Purpose: This subprogram applies the Schreiner equation to update the */ | 314 /* Purpose: This subprogram applies the Schreiner equation to update the */ |
388 /* gas loadings (partial pressures of helium and nitrogen) in the half-time */ | 315 /* gas loadings (partial pressures of helium and nitrogen) in the half-time */ |
389 /* compartments due to a linear ascent or descent segment at a constant rate. */ | 316 /* compartments due to a linear ascent or descent segment at a constant rate. */ |
390 /* =============================================================================== */ | 317 /* =============================================================================== */ |
391 | 318 |
392 int gas_loadings_ascent_descen(float* helium_pressure, | 319 static int gas_loadings_ascent_descen(float* helium_pressure, |
393 float* nitrogen_pressure, | 320 float* nitrogen_pressure, |
394 float starting_depth, | 321 float starting_depth, |
395 float ending_depth, | 322 float ending_depth, |
396 float rate,_Bool check_gas_change) | 323 float rate,_Bool check_gas_change) |
397 { | 324 { |
478 } while(ending_depth_tmp > ending_depth); | 405 } while(ending_depth_tmp > ending_depth); |
479 | 406 |
480 return 0; | 407 return 0; |
481 } /* gas_loadings_ascent_descen */ | 408 } /* gas_loadings_ascent_descen */ |
482 | 409 |
483 float last_phase_volume_time[16]; | 410 static float last_phase_volume_time[16]; |
484 float n2_pressure_start_of_deco_zone[16]; | 411 static float n2_pressure_start_of_deco_zone[16]; |
485 float he_pressure_start_of_deco_zone[16]; | 412 static float he_pressure_start_of_deco_zone[16]; |
486 float phase_volume_time[16]; | 413 static float phase_volume_time[16]; |
487 float n2_pressure_start_of_ascent[16]; | 414 static float n2_pressure_start_of_ascent[16]; |
488 float he_pressure_start_of_ascent[16]; | 415 static float he_pressure_start_of_ascent[16]; |
489 float run_time_start_of_deco_calc; | 416 static float run_time_start_of_deco_calc; |
490 float starting_depth; | 417 static float starting_depth; |
491 float last_run_time; | 418 static float last_run_time; |
492 float deco_phase_volume_time; | 419 static float deco_phase_volume_time; |
493 | 420 static float run_time_start_of_ascent; |
494 float run_time_start_of_ascent; | 421 static float rate; |
495 | 422 static float step_size; |
496 float rate; | 423 static _Bool vpm_violates_buehlmann; |
497 float step_size; | 424 |
498 _Bool vpm_violates_buehlmann; | 425 static void vpm_calc_deco(void) |
499 | |
500 void vpm_calc_deco(void) | |
501 { | 426 { |
502 /* System generated locals */ | 427 /* System generated locals */ |
503 | 428 |
504 //float deepest_possible_stop_depth; | 429 //float deepest_possible_stop_depth; |
505 // altitude_of_dive, | 430 // altitude_of_dive, |
660 /* settings (default setting is 7500 fsw-min with adjustability range from */ | 585 /* settings (default setting is 7500 fsw-min with adjustability range from */ |
661 /* from 6500 to 8300 fsw-min according to Bruce Wienke). */ | 586 /* from 6500 to 8300 fsw-min according to Bruce Wienke). */ |
662 /* =============================================================================== */ | 587 /* =============================================================================== */ |
663 /* L50: */ | 588 /* L50: */ |
664 | 589 |
665 float deco_stop_depth; | 590 static float deco_stop_depth; |
666 int vpm_calc_critcal_volume(_Bool begin, | 591 static int vpm_calc_critcal_volume(_Bool begin, |
667 _Bool calc_nulltime) | 592 _Bool calc_nulltime) |
668 { /* loop will run continuous there is an exit stateme */ | 593 { /* loop will run continuous there is an exit stateme */ |
669 | 594 |
670 short i; | 595 short i; |
671 | 596 |
765 for(dp = 0;dp < DECOINFO_STRUCT_MAX_STOPS;dp++) | 690 for(dp = 0;dp < DECOINFO_STRUCT_MAX_STOPS;dp++) |
766 { | 691 { |
767 pDecoInfo->output_stop_length_seconds[dp] = 0; | 692 pDecoInfo->output_stop_length_seconds[dp] = 0; |
768 } | 693 } |
769 pDecoInfo->output_ndl_seconds = 0; | 694 pDecoInfo->output_ndl_seconds = 0; |
770 /*max_first_stop_depth = 0; | 695 } |
771 deco_zone_reached = false; | 696 |
772 depth_start_of_deco_calc = 0; | 697 return CALC_NDL; |
773 depth_start_of_deco_zone = 0; | |
774 first_stop_depth = 0; | |
775 max_first_stop_depth_save = 0; | |
776 depth_start_of_deco_zone_save = 0; | |
777 run_time_start_of_deco_zone_save = 0; | |
778 tts[DECOSTOPS] = 0; | |
779 tts[NULLZEIT] = 0; | |
780 tts[FUTURESTOPS] = 0; | |
781 nullzeit_unter60 = false; | |
782 vpm_calc_status = CALC_NULLZEIT; | |
783 vpm_calc_what = DECOSTOPS; | |
784 float surfacetime = 0; | |
785 vpm_repetitive_algorithm(&surfacetime);*/ | |
786 | |
787 } | |
788 | |
789 return CALC_NULLZEIT; | |
790 /* exit the critical volume l */ | 698 /* exit the critical volume l */ |
791 } | 699 } |
792 | 700 |
793 /* =============================================================================== */ | 701 /* =============================================================================== */ |
794 /* ASSIGN VARIABLES FOR ASCENT FROM START OF DECO ZONE TO FIRST STOP. SAVE */ | 702 /* ASSIGN VARIABLES FOR ASCENT FROM START OF DECO ZONE TO FIRST STOP. SAVE */ |
876 /* by the excess bubble number to represent the amount of free-gas released */ | 784 /* by the excess bubble number to represent the amount of free-gas released */ |
877 /* as a result of allowing a certain number of excess bubbles to form. */ | 785 /* as a result of allowing a certain number of excess bubbles to form. */ |
878 /* =============================================================================== */ | 786 /* =============================================================================== */ |
879 /* end of deco stop loop */ | 787 /* end of deco stop loop */ |
880 | 788 |
881 int vpm_check_converged(_Bool calc_nulltime) | 789 static int vpm_check_converged(_Bool calc_nulltime) |
882 { | 790 { |
883 | 791 |
884 short i; | 792 short i; |
885 float critical_volume_comparison; | 793 float critical_volume_comparison; |
886 float r1; | 794 float r1; |
973 /* end of critical volume decision */ | 881 /* end of critical volume decision */ |
974 /* L100: */ | 882 /* L100: */ |
975 // }/* end of critical vol loop */ | 883 // }/* end of critical vol loop */ |
976 } | 884 } |
977 | 885 |
978 void vpm_calc_deco_ceiling(void) | 886 static void vpm_calc_deco_ceiling(void) |
979 { | 887 { |
980 | 888 |
981 short i; | 889 short i; |
982 // hw 1601209 float r1; | 890 // hw 1601209 float r1; |
983 // hw 1601209 float stop_time; | 891 // hw 1601209 float stop_time; |
1086 | 994 |
1087 /* =============================================================================== */ | 995 /* =============================================================================== */ |
1088 /* DECO STOP LOOP BLOCK FOR FINAL DECOMPRESSION SCHEDULE */ | 996 /* DECO STOP LOOP BLOCK FOR FINAL DECOMPRESSION SCHEDULE */ |
1089 /* =============================================================================== */ | 997 /* =============================================================================== */ |
1090 | 998 |
1091 int vpm_calc_final_deco(_Bool begin) | 999 static int vpm_calc_final_deco(_Bool begin) |
1092 { | 1000 { |
1093 short i; | 1001 short i; |
1094 float r1; | 1002 float r1; |
1095 float stop_time; | 1003 float stop_time; |
1096 int count = 0; | 1004 int count = 0; |
1262 /* radii that takes place over the dive time. The regeneration time constant */ | 1170 /* radii that takes place over the dive time. The regeneration time constant */ |
1263 /* has a time scale of weeks so this will have very little impact on dives of */ | 1171 /* has a time scale of weeks so this will have very little impact on dives of */ |
1264 /* normal length, but will have a major impact for saturation dives. */ | 1172 /* normal length, but will have a major impact for saturation dives. */ |
1265 /* =============================================================================== */ | 1173 /* =============================================================================== */ |
1266 | 1174 |
1267 int nuclear_regeneration(float *dive_time) | 1175 static int nuclear_regeneration(float *dive_time) |
1268 { | 1176 { |
1269 /* Local variables */ | 1177 /* Local variables */ |
1270 float crush_pressure_adjust_ratio_he, | 1178 float crush_pressure_adjust_ratio_he, |
1271 ending_radius_n2, | 1179 ending_radius_n2, |
1272 ending_radius_he; | 1180 ending_radius_he; |
1371 /* The initial allowable gradients are computed directly from the */ | 1279 /* The initial allowable gradients are computed directly from the */ |
1372 /* "regenerated" radii after the Nuclear Regeneration subroutine. These */ | 1280 /* "regenerated" radii after the Nuclear Regeneration subroutine. These */ |
1373 /* gradients are tracked separately for helium and nitrogen. */ | 1281 /* gradients are tracked separately for helium and nitrogen. */ |
1374 /* =============================================================================== */ | 1282 /* =============================================================================== */ |
1375 | 1283 |
1376 int calc_initial_allowable_gradient() | 1284 static int calc_initial_allowable_gradient() |
1377 { | 1285 { |
1378 float initial_allowable_grad_n2_pa, | 1286 float initial_allowable_grad_n2_pa, |
1379 initial_allowable_grad_he_pa; | 1287 initial_allowable_grad_he_pa; |
1380 short i; | 1288 short i; |
1381 | 1289 |
1426 /* finds the deepest deco ceiling across all compartments. This deepest */ | 1334 /* finds the deepest deco ceiling across all compartments. This deepest */ |
1427 /* value (Deco Ceiling Depth) is then used by the Decompression Stop */ | 1335 /* value (Deco Ceiling Depth) is then used by the Decompression Stop */ |
1428 /* subroutine to determine the actual deco schedule. */ | 1336 /* subroutine to determine the actual deco schedule. */ |
1429 /* =============================================================================== */ | 1337 /* =============================================================================== */ |
1430 | 1338 |
1431 int calc_deco_ceiling(float *deco_ceiling_depth,_Bool fallowable) | 1339 static int calc_deco_ceiling(float *deco_ceiling_depth,_Bool fallowable) |
1432 { | 1340 { |
1433 /* System generated locals */ | 1341 /* System generated locals */ |
1434 float r1, r2; | 1342 float r1, r2; |
1435 /* Local variables */ | 1343 /* Local variables */ |
1436 float weighted_allowable_gradient; | 1344 float weighted_allowable_gradient; |
1553 /* repetitive dive to compensate for the bubbling that was allowed on the */ | 1461 /* repetitive dive to compensate for the bubbling that was allowed on the */ |
1554 /* previous dive. The use of the max actual gradients is intended to prevent */ | 1462 /* previous dive. The use of the max actual gradients is intended to prevent */ |
1555 /* the repetitive algorithm from being overly conservative. */ | 1463 /* the repetitive algorithm from being overly conservative. */ |
1556 /* =============================================================================== */ | 1464 /* =============================================================================== */ |
1557 | 1465 |
1558 int calc_max_actual_gradient(float *deco_stop_depth) | 1466 static int calc_max_actual_gradient(float *deco_stop_depth) |
1559 { | 1467 { |
1560 /* System generated locals */ | 1468 /* System generated locals */ |
1561 float r1; | 1469 float r1; |
1562 | 1470 |
1563 /* Local variables */ | 1471 /* Local variables */ |
1600 /* computes the time course of supersaturation gradients on the surface */ | 1508 /* computes the time course of supersaturation gradients on the surface */ |
1601 /* when both helium and nitrogen are present. Refer to separate write-up */ | 1509 /* when both helium and nitrogen are present. Refer to separate write-up */ |
1602 /* for a more detailed explanation of this algorithm. */ | 1510 /* for a more detailed explanation of this algorithm. */ |
1603 /* =============================================================================== */ | 1511 /* =============================================================================== */ |
1604 | 1512 |
1605 int calc_surface_phase_volume_time() | 1513 static int calc_surface_phase_volume_time() |
1606 { | 1514 { |
1607 /* Local variables */ | 1515 /* Local variables */ |
1608 float decay_time_to_zero_gradient; | 1516 float decay_time_to_zero_gradient; |
1609 short i; | 1517 short i; |
1610 float integral_gradient_x_time, | 1518 float integral_gradient_x_time, |
1660 /* Purpose: This subprogram applies the VPM Critical Volume Algorithm. This */ | 1568 /* Purpose: This subprogram applies the VPM Critical Volume Algorithm. This */ |
1661 /* algorithm will compute "relaxed" gradients for helium and nitrogen based */ | 1569 /* algorithm will compute "relaxed" gradients for helium and nitrogen based */ |
1662 /* on the setting of the Critical Volume Parameter Lambda. */ | 1570 /* on the setting of the Critical Volume Parameter Lambda. */ |
1663 /* =============================================================================== */ | 1571 /* =============================================================================== */ |
1664 | 1572 |
1665 int critical_volume(float *deco_phase_volume_time) | 1573 static int critical_volume(float *deco_phase_volume_time) |
1666 { | 1574 { |
1667 /* System generated locals */ | 1575 /* System generated locals */ |
1668 float r1; | 1576 float r1; |
1669 | 1577 |
1670 /* Local variables */ | 1578 /* Local variables */ |
1776 /* which the leading compartment just enters the decompression zone. */ | 1684 /* which the leading compartment just enters the decompression zone. */ |
1777 /* Source: "Numerical Recipes in Fortran 77", Cambridge University Press, */ | 1685 /* Source: "Numerical Recipes in Fortran 77", Cambridge University Press, */ |
1778 /* 1992. */ | 1686 /* 1992. */ |
1779 /* =============================================================================== */ | 1687 /* =============================================================================== */ |
1780 | 1688 |
1781 int calc_start_of_deco_zone(float *starting_depth, | 1689 static int calc_start_of_deco_zone(float *starting_depth, |
1782 float *rate, | 1690 float *rate, |
1783 float *depth_start_of_deco_zone) | 1691 float *depth_start_of_deco_zone) |
1784 { | 1692 { |
1785 /* Local variables */ | 1693 /* Local variables */ |
1786 float last_diff_change, | 1694 float last_diff_change, |
1975 /* gas loading during ascent (on-gassing). If the deco ceiling is violated, */ | 1883 /* gas loading during ascent (on-gassing). If the deco ceiling is violated, */ |
1976 /* the stop depth will be adjusted deeper by the step size until a safe */ | 1884 /* the stop depth will be adjusted deeper by the step size until a safe */ |
1977 /* ascent can be made. */ | 1885 /* ascent can be made. */ |
1978 /* =============================================================================== */ | 1886 /* =============================================================================== */ |
1979 | 1887 |
1980 int projected_ascent(float *starting_depth, | 1888 static int projected_ascent(float *starting_depth, |
1981 float *rate, | 1889 float *rate, |
1982 float *deco_stop_depth, | 1890 float *deco_stop_depth, |
1983 float *step_size) | 1891 float *step_size) |
1984 { | 1892 { |
1985 /* Local variables */ | 1893 /* Local variables */ |
2044 /* SUBROUTINE DECOMPRESSION_STOP */ | 1952 /* SUBROUTINE DECOMPRESSION_STOP */ |
2045 /* Purpose: This subprogram calculates the required time at each */ | 1953 /* Purpose: This subprogram calculates the required time at each */ |
2046 /* decompression stop. */ | 1954 /* decompression stop. */ |
2047 /* =============================================================================== */ | 1955 /* =============================================================================== */ |
2048 | 1956 |
2049 void decompression_stop(float *deco_stop_depth, | 1957 static void decompression_stop(float *deco_stop_depth, |
2050 float *step_size, | 1958 float *step_size, |
2051 _Bool final_deco_calculation) | 1959 _Bool final_deco_calculation) |
2052 { | 1960 { |
2053 /* Local variables */ | 1961 /* Local variables */ |
2054 float inspired_nitrogen_pressure; | 1962 float inspired_nitrogen_pressure; |
2266 // SUROUTINE BOYLES_LAW_COMPENSATION | 2174 // SUROUTINE BOYLES_LAW_COMPENSATION |
2267 // Purpose: This subprogram calculates the reduction in allowable gradients | 2175 // Purpose: This subprogram calculates the reduction in allowable gradients |
2268 // with decreasing ambient pressure during the decompression profile based | 2176 // with decreasing ambient pressure during the decompression profile based |
2269 // on Boyle's Law considerations. | 2177 // on Boyle's Law considerations. |
2270 //=============================================================================== | 2178 //=============================================================================== |
2271 void BOYLES_LAW_COMPENSATION (float* First_Stop_Depth, | 2179 static void BOYLES_LAW_COMPENSATION (float* First_Stop_Depth, |
2272 float* Deco_Stop_Depth, | 2180 float* Deco_Stop_Depth, |
2273 float* Step_Size) | 2181 float* Step_Size) |
2274 { | 2182 { |
2275 short i; | 2183 short i; |
2276 | 2184 |
2365 UNITS_FACTOR; | 2273 UNITS_FACTOR; |
2366 } | 2274 } |
2367 } | 2275 } |
2368 | 2276 |
2369 /* =============================================================================== */ | 2277 /* =============================================================================== */ |
2370 // vpm_calc_nullzeit | 2278 // vpm_calc_ndl |
2371 // Purpose: This function calcs zero time (time where no decostops are needed) | 2279 // Purpose: This function computes NDL (time where no decostops are needed) |
2372 //=============================================================================== | 2280 //=============================================================================== |
2373 int vpm_calc_nullzeit(void) | 2281 #define MAX_NDL 240 |
2282 | |
2283 static int vpm_calc_ndl(void) | |
2374 { | 2284 { |
2375 static float future_helium_pressure[16]; | 2285 static float future_helium_pressure[16]; |
2376 static float future_nitrogen_pressure[16]; | 2286 static float future_nitrogen_pressure[16]; |
2377 static int temp_segment_time; | 2287 static int temp_segment_time; |
2378 static int mix_number; | 2288 static int mix_number; |
2385 float fraction_helium_begin; | 2295 float fraction_helium_begin; |
2386 float fraction_nitrogen_begin; | 2296 float fraction_nitrogen_begin; |
2387 int i = 0; | 2297 int i = 0; |
2388 int count = 0; | 2298 int count = 0; |
2389 int status = CALC_END; | 2299 int status = CALC_END; |
2390 //if(begin) | 2300 |
2391 //{ | |
2392 for(i = 0; i < 16;i++) | 2301 for(i = 0; i < 16;i++) |
2393 { | 2302 { |
2394 future_helium_pressure[i] = pInput->tissue_helium_bar[i] * 10;//tissue_He_saturation[st_dive][i] * 10; | 2303 future_helium_pressure[i] = pInput->tissue_helium_bar[i] * 10;//tissue_He_saturation[st_dive][i] * 10; |
2395 future_nitrogen_pressure[i] = pInput->tissue_nitrogen_bar[i] * 10; | 2304 future_nitrogen_pressure[i] = pInput->tissue_nitrogen_bar[i] * 10; |
2396 } | 2305 } |
2397 temp_segment_time = 0; | 2306 temp_segment_time = 0; |
2398 | 2307 |
2399 mix_number = 0; | 2308 mix_number = 0; |
2400 ambient_pressure = pInput->pressure_ambient_bar * 10; | 2309 ambient_pressure = pInput->pressure_ambient_bar * 10; |
2401 // fraction_helium_begin; | |
2402 // fraction_nitrogen_begin; | |
2403 decom_get_inert_gases( ambient_pressure / 10, (&pDiveSettings->decogaslist[mix_number]) , &fraction_nitrogen_begin, &fraction_helium_begin ); | 2310 decom_get_inert_gases( ambient_pressure / 10, (&pDiveSettings->decogaslist[mix_number]) , &fraction_nitrogen_begin, &fraction_helium_begin ); |
2404 inspired_helium_pressure =(ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_helium_begin; | 2311 inspired_helium_pressure =(ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_helium_begin; |
2405 inspired_nitrogen_pressure =(ambient_pressure - WATER_VAPOR_PRESSURE) *fraction_nitrogen_begin; | 2312 inspired_nitrogen_pressure =(ambient_pressure - WATER_VAPOR_PRESSURE) *fraction_nitrogen_begin; |
2406 | 2313 |
2407 //if(!nullzeit_unter60) | |
2408 //{ | |
2409 status = CALC_END; | 2314 status = CALC_END; |
2410 while (status == CALC_END) | 2315 while (status == CALC_END) |
2411 { | 2316 { |
2412 count++; | 2317 count++; |
2413 //if(count == 7) | |
2414 //return CALC_NULLZEIT2; | |
2415 temp_segment_time += 60; | 2318 temp_segment_time += 60; |
2416 if(temp_segment_time >= 300) | 2319 if(temp_segment_time >= MAX_NDL) |
2417 { | 2320 { |
2418 pDecoInfo->output_ndl_seconds = temp_segment_time * 60; | 2321 pDecoInfo->output_ndl_seconds = temp_segment_time * 60; |
2419 return CALC_NULLZEIT; | 2322 return CALC_NDL; |
2420 } | 2323 } |
2421 run_time += 60; | 2324 run_time += 60; |
2422 //goto L700; | 2325 //goto L700; |
2423 for (i = 1; i <= 16; ++i) { | 2326 for (i = 1; i <= 16; ++i) { |
2424 previous_helium_pressure[i-1] = future_helium_pressure[i - 1]; | 2327 previous_helium_pressure[i-1] = future_helium_pressure[i - 1]; |
2438 for (i = 1; i <= 16; ++i) | 2341 for (i = 1; i <= 16; ++i) |
2439 { | 2342 { |
2440 future_helium_pressure[i - 1] = previous_helium_pressure[i-1]; | 2343 future_helium_pressure[i - 1] = previous_helium_pressure[i-1]; |
2441 future_nitrogen_pressure[i - 1] = previous_nitrogen_pressure[i - 1]; | 2344 future_nitrogen_pressure[i - 1] = previous_nitrogen_pressure[i - 1]; |
2442 } | 2345 } |
2443 //} | |
2444 //} | |
2445 //if(!nullzeit_unter60 || begin || temp_segment_time > 10) | |
2446 //{ | |
2447 | 2346 |
2448 status = CALC_END; | 2347 status = CALC_END; |
2449 if(temp_segment_time < 60) | 2348 if(temp_segment_time < 60) |
2450 nullzeit_unter60 = true; | 2349 nullzeit_unter60 = true; |
2451 | 2350 |
2452 while (status == CALC_END) | 2351 while (status == CALC_END) |
2453 { | 2352 { |
2454 // count++; | |
2455 //if(count >= 5) | |
2456 //return CALC_NULLZEIT2; | |
2457 temp_segment_time += 5; | 2353 temp_segment_time += 5; |
2458 if(temp_segment_time >= 300) | 2354 if(temp_segment_time >= MAX_NDL) |
2459 { | 2355 { |
2460 pDecoInfo->output_ndl_seconds = temp_segment_time * 60; | 2356 pDecoInfo->output_ndl_seconds = temp_segment_time * 60; |
2461 return CALC_NULLZEIT; | 2357 return CALC_NDL; |
2462 } | 2358 } |
2463 if(nullzeit_unter60 && temp_segment_time > 60) | 2359 if(nullzeit_unter60 && temp_segment_time > 60) |
2464 { | 2360 { |
2465 nullzeit_unter60 = false; | 2361 nullzeit_unter60 = false; |
2466 //tts[NULLZEIT] = temp_segment_time * 60; | 2362 return CALC_NDL; |
2467 return CALC_NULLZEIT; | |
2468 } | 2363 } |
2469 run_time += 5; | 2364 run_time += 5; |
2470 //goto L700; | 2365 //goto L700; |
2471 for (i = 1; i <= 16; ++i) { | 2366 for (i = 1; i <= 16; ++i) { |
2472 previous_helium_pressure[i-1] = future_helium_pressure[i - 1]; | 2367 previous_helium_pressure[i-1] = future_helium_pressure[i - 1]; |
2484 for (i = 1; i <= 16; ++i) { | 2379 for (i = 1; i <= 16; ++i) { |
2485 future_helium_pressure[i - 1] = previous_helium_pressure[i-1]; | 2380 future_helium_pressure[i - 1] = previous_helium_pressure[i-1]; |
2486 future_nitrogen_pressure[i - 1] = previous_nitrogen_pressure[i - 1]; | 2381 future_nitrogen_pressure[i - 1] = previous_nitrogen_pressure[i - 1]; |
2487 } | 2382 } |
2488 status = CALC_END; | 2383 status = CALC_END; |
2489 //if(temp_segment_time < 5) | 2384 |
2490 //count = 2; | |
2491 //} | |
2492 //else | |
2493 //count = 1; | |
2494 if(temp_segment_time <= 20) | 2385 if(temp_segment_time <= 20) |
2495 { | 2386 { |
2496 while (status == CALC_END) | 2387 while (status == CALC_END) |
2497 { | 2388 { |
2498 //time_counter = temp_segment_time; | |
2499 //count++; | |
2500 //if(count > 2) | |
2501 //return CALC_NULLZEIT2; | |
2502 temp_segment_time += minimum_deco_stop_time; | 2389 temp_segment_time += minimum_deco_stop_time; |
2503 run_time += minimum_deco_stop_time; | 2390 run_time += minimum_deco_stop_time; |
2504 //goto L700; | 2391 //goto L700; |
2505 for (i = 1; i <= 16; ++i) { | 2392 for (i = 1; i <= 16; ++i) { |
2506 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]; | 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]; |
2516 } | 2403 } |
2517 else | 2404 else |
2518 temp_segment_time += 5; | 2405 temp_segment_time += 5; |
2519 pDecoInfo->output_ndl_seconds = temp_segment_time * 60; | 2406 pDecoInfo->output_ndl_seconds = temp_segment_time * 60; |
2520 if(temp_segment_time > 1) | 2407 if(temp_segment_time > 1) |
2521 return CALC_NULLZEIT; | 2408 return CALC_NDL; |
2522 else | 2409 else |
2523 return CALC_BEGIN; | 2410 return CALC_BEGIN; |
2524 } | 2411 } |