Mercurial > public > ostc4
annotate Discovery/Src/buehlmann.c @ 255:dcf7a3435fe1 bm-3
Buehlmann: cleanup, factor out pBuDiveSettings
And remove another global pointer. Simply pass the attributes we
need as a parameter, instead of using (awful) global data.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Fri, 12 Apr 2019 15:26:14 +0200 |
parents | a17f7fb3b2b5 |
children | d10f53e39374 |
rev | line source |
---|---|
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
1 /* getrennte Gase f�r die verschiedenen Modi |
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
2 um Gaswechsel Eintr�ge zu vereinfachen |
38 | 3 das heisst: |
4 oc == bailout in cc mode | |
5 */ | |
6 | |
7 /* Konvention: | |
8 float extExample_variable_can_be_used_with_extern; | |
9 */ | |
10 | |
11 #include <string.h> | |
12 #include <math.h> | |
13 #include <stdbool.h> | |
14 #include "buehlmann.h" | |
15 #include "decom.h" | |
16 | |
17 extern const float buehlmann_N2_a[]; | |
18 extern const float buehlmann_N2_b[]; | |
19 extern const float buehlmann_He_a[]; | |
20 extern const float buehlmann_He_b[]; | |
21 | |
22 typedef struct | |
23 { | |
24 float depth; | |
25 int id; | |
26 } SStop; | |
27 | |
28 #define DECO_STOPS_MAX_TTS_CALCULATON_IN_SECONDS 59940 // 999 minuten; before: 18000 // 5(h) * 60(min) * 60 sec = 18000 sec | |
29 #define DECO_STOPS_MAX_TTS_FOR_EVERY_SECOND_CALC_IN_SECONDS 7200 | |
30 #define NINETY_NINE_MINUTES_IN_SECONDS 59940 | |
31 | |
32 # define PRESSURE_TEN_METER 1.0f | |
33 # define PRESSURE_THREE_METER 0.333334f | |
34 # define PRESSURE_150_CM 0.15f | |
35 # define PRESSURE_HALF_METER 0.05f | |
36 | |
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
37 static void buehlmann_backup_and_restore(_Bool backup_restore_otherwise); |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
38 static float tissue_tolerance(void); |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
39 static void ambient_bar_to_deco_stop_depth_bar(SDiveSettings *pDiveSettings, float ceiling); |
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
40 static int ascend_with_all_gaschanges(SDiveSettings *pDiveSettings, float pressure_decrease); |
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
41 static float next_stop_depth_input_is_actual_stop_id(SDiveSettings *pDiveSettings, int actual_id); |
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
42 static float get_gf_at_pressure(SDiveSettings *pDiveSettings, float pressure); |
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
43 static void buehlmann_calc_ndl(SDiveSettings *pDiveSettings); |
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
44 static _Bool dive1_check_deco(SDiveSettings *pDiveSettings); |
38 | 45 |
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
46 static SDecoinfo gDecotable; |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
47 static float gSurface_pressure_bar; |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
48 static float gPressure; |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
49 static int gGas_id; |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
50 static float gTTS; |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
51 static float gTissue_nitrogen_bar[16]; |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
52 static float gTissue_helium_bar[16]; |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
53 static float gGF_value; |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
54 static float gCNS; |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
55 static int gNDL; |
38 | 56 |
57 float gGF_low_depth_bar; | |
58 SStop gStop; | |
59 | |
60 void buehlmann_init(void) | |
61 { | |
62 } | |
63 | |
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
64 static void buehlmann_backup_and_restore(_Bool backup_restore_otherwise) |
38 | 65 { |
66 static float pressure; | |
67 static float gas_id; | |
68 static float tts; | |
69 static float tissue_nitrogen_bar[16]; | |
70 static float tissue_helium_bar[16]; | |
71 static float gf_value; | |
72 static int ndl; | |
73 static float cns; | |
74 | |
75 if(backup_restore_otherwise) | |
76 { | |
77 pressure = gPressure; | |
78 gas_id = gGas_id; | |
79 tts = gTTS; | |
80 gf_value = gGF_value; | |
81 ndl = gNDL; | |
82 cns = gCNS; | |
83 memcpy(tissue_nitrogen_bar, gTissue_nitrogen_bar, (4*16)); | |
84 memcpy(tissue_helium_bar, gTissue_helium_bar, (4*16)); | |
85 } | |
86 else | |
87 { | |
88 gPressure = pressure; | |
89 gGas_id = gas_id; | |
90 gTTS = tts; | |
91 gGF_value = gf_value; | |
92 gNDL = ndl; | |
93 gCNS = cns; | |
94 memcpy(gTissue_nitrogen_bar, tissue_nitrogen_bar, (4*16)); | |
95 memcpy(gTissue_helium_bar, tissue_helium_bar, (4*16)); | |
96 } | |
97 | |
98 } | |
99 | |
100 float buehlmann_get_gCNS(void) | |
101 { | |
102 return gCNS; | |
103 } | |
104 | |
105 void buehlmann_calc_deco(SLifeData* pLifeData, SDiveSettings * pDiveSettings, SDecoinfo * pDecoInfo) | |
106 { | |
107 float ceiling; | |
108 int ascend_time; | |
109 int tts_seconds; | |
110 float pressure_delta; | |
111 float next_depth; | |
112 _Bool deco_reached = false; | |
113 unsigned short *stoplist; | |
114 int i; | |
115 | |
116 gCNS = 0; | |
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
117 pDecoInfo->output_time_to_surface_seconds = 0; |
38 | 118 pDecoInfo->output_ndl_seconds = 0; |
119 for(int i=0;i<DECOINFO_STRUCT_MAX_STOPS;i++) | |
120 { | |
121 pDecoInfo->output_stop_length_seconds[i] = 0; | |
122 } | |
123 | |
124 /* internal copying */ | |
125 gSurface_pressure_bar = pLifeData->pressure_surface_bar; | |
126 | |
127 gPressure = pLifeData->pressure_ambient_bar; | |
128 gGas_id = 0; | |
129 memcpy(gTissue_nitrogen_bar, pLifeData->tissue_nitrogen_bar, (4*16)); | |
130 memcpy(gTissue_helium_bar, pLifeData->tissue_helium_bar, (4*16)); | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
131 gGF_value = ((float)pDiveSettings->gf_low) / 100.0f; |
38 | 132 |
133 // | |
254
a17f7fb3b2b5
Buehlmann: cleanup, remove global pDecolistBuehlmann
Jan Mulder <jlmulder@xs4all.nl>
parents:
253
diff
changeset
|
134 memcpy(&gDecotable, pDecoInfo, sizeof(SDecoinfo)); |
38 | 135 stoplist = gDecotable.output_stop_length_seconds; |
136 | |
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
137 if(pLifeData->dive_time_seconds < 60) |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
138 return; |
38 | 139 |
140 // clean stop list | |
141 for(i = 0; i < DECOINFO_STRUCT_MAX_STOPS; i++) | |
142 stoplist[i] = 0; | |
143 gTTS = 0; | |
144 gNDL = 0; | |
145 | |
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
146 if(pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero >= (gPressure - PRESSURE_150_CM)) |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
147 { |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
148 deco_reached = true; |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
149 } |
38 | 150 |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
151 gGF_value = ((float)pDiveSettings->gf_high) / 100.0f; |
38 | 152 buehlmann_backup_and_restore(true); // includes backup for gGF_value |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
153 if(!dive1_check_deco(pDiveSettings) ) |
38 | 154 { |
155 buehlmann_backup_and_restore(false); | |
156 // no deco | |
254
a17f7fb3b2b5
Buehlmann: cleanup, remove global pDecolistBuehlmann
Jan Mulder <jlmulder@xs4all.nl>
parents:
253
diff
changeset
|
157 pDecoInfo->output_time_to_surface_seconds = 0; |
38 | 158 for(i = 0; i < DECOINFO_STRUCT_MAX_STOPS; i++) |
254
a17f7fb3b2b5
Buehlmann: cleanup, remove global pDecolistBuehlmann
Jan Mulder <jlmulder@xs4all.nl>
parents:
253
diff
changeset
|
159 pDecoInfo->output_stop_length_seconds[i] = 0; |
38 | 160 // calc NDL |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
161 buehlmann_calc_ndl(pDiveSettings); |
254
a17f7fb3b2b5
Buehlmann: cleanup, remove global pDecolistBuehlmann
Jan Mulder <jlmulder@xs4all.nl>
parents:
253
diff
changeset
|
162 pDecoInfo->output_ndl_seconds = gNDL; |
38 | 163 return; |
164 } | |
165 buehlmann_backup_and_restore(false); | |
254
a17f7fb3b2b5
Buehlmann: cleanup, remove global pDecolistBuehlmann
Jan Mulder <jlmulder@xs4all.nl>
parents:
253
diff
changeset
|
166 pDecoInfo->output_ndl_seconds = 0; |
38 | 167 |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
168 gGF_value = get_gf_at_pressure(pDiveSettings, gPressure); |
38 | 169 //current ceiling at actual position |
170 ceiling = tissue_tolerance(); | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
171 ambient_bar_to_deco_stop_depth_bar(pDiveSettings, ceiling); |
38 | 172 |
173 // set the base for all upcoming parameters | |
174 ceiling = gStop.depth + gSurface_pressure_bar; | |
175 tts_seconds = 0; | |
176 | |
177 // modify parameters if there is ascend or parameter fine adjustment | |
178 if(ceiling < (gPressure - PRESSURE_150_CM)) // more than 1.5 meter below ceiling | |
179 { | |
180 // ascend within 10 mtr to GF_low // speed 12 mtr/min -> 50 sec / 10 mtr; 15 sec / 3 mtr. | |
181 if(ceiling < (gPressure - PRESSURE_TEN_METER) ) | |
182 { do { | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
183 ascend_time = ascend_with_all_gaschanges(pDiveSettings, PRESSURE_TEN_METER); |
38 | 184 tts_seconds += ascend_time; |
185 ceiling = tissue_tolerance(); | |
186 if(tts_seconds > DECO_STOPS_MAX_TTS_CALCULATON_IN_SECONDS) | |
187 { | |
254
a17f7fb3b2b5
Buehlmann: cleanup, remove global pDecolistBuehlmann
Jan Mulder <jlmulder@xs4all.nl>
parents:
253
diff
changeset
|
188 pDecoInfo->output_time_to_surface_seconds = NINETY_NINE_MINUTES_IN_SECONDS; |
38 | 189 return;// NINETY_NINE_MINUTES_IN_SECONDS; |
190 } | |
191 } while ((ascend_time > 0 ) && ((gPressure - PRESSURE_TEN_METER ) > gSurface_pressure_bar) && (ceiling < (gPressure - PRESSURE_TEN_METER))); | |
192 } | |
193 do { | |
194 buehlmann_backup_and_restore(true); | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
195 ascend_time = ascend_with_all_gaschanges(pDiveSettings, PRESSURE_THREE_METER); |
38 | 196 tts_seconds += ascend_time; |
197 ceiling = tissue_tolerance(); | |
198 if(tts_seconds > DECO_STOPS_MAX_TTS_CALCULATON_IN_SECONDS) | |
199 { | |
254
a17f7fb3b2b5
Buehlmann: cleanup, remove global pDecolistBuehlmann
Jan Mulder <jlmulder@xs4all.nl>
parents:
253
diff
changeset
|
200 pDecoInfo->output_time_to_surface_seconds = NINETY_NINE_MINUTES_IN_SECONDS; |
38 | 201 return;// NINETY_NINE_MINUTES_IN_SECONDS; |
202 } | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
203 ambient_bar_to_deco_stop_depth_bar(pDiveSettings, ceiling); |
38 | 204 } while ((ascend_time > 0 ) && ((gStop.depth + gSurface_pressure_bar) < gPressure)); |
205 | |
206 if(gStop.depth + gSurface_pressure_bar > gPressure) | |
207 { | |
208 gPressure += PRESSURE_THREE_METER; | |
209 buehlmann_backup_and_restore(false); | |
210 tts_seconds -= ascend_time; | |
211 } | |
212 // calculate first stop based on tissue saturation within 10 meters of stop | |
213 //ambient_bar_to_deco_stop_depth_bar(ceiling); | |
214 } | |
215 else | |
216 { | |
217 // initial values, upper code might not be executed (is within 150 cm) | |
218 } | |
219 | |
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
220 if (ceiling > gSurface_pressure_bar) |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
221 { |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
222 ceiling = gStop.depth + gSurface_pressure_bar; |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
223 // ascend the last meters to first stop (especially consider any gas changes around) |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
224 pressure_delta = gPressure - ceiling; |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
225 ascend_time = (int) ceil(pressure_delta * 50.0f); |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
226 tts_seconds += ascend_with_all_gaschanges(pDiveSettings, pressure_delta); |
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
227 } |
38 | 228 // NDL check |
229 if(ceiling <= gSurface_pressure_bar) | |
230 { | |
231 // NDL with GF_low | |
254
a17f7fb3b2b5
Buehlmann: cleanup, remove global pDecolistBuehlmann
Jan Mulder <jlmulder@xs4all.nl>
parents:
253
diff
changeset
|
232 pDecoInfo->output_time_to_surface_seconds = 0; |
38 | 233 return; |
234 } | |
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
235 if (ceiling > pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero) |
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
236 pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = ceiling; |
38 | 237 |
238 // calc gf loop | |
239 if(deco_reached) | |
240 gGF_low_depth_bar = pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero - gSurface_pressure_bar; | |
241 else | |
242 gGF_low_depth_bar = ceiling - gSurface_pressure_bar; | |
243 | |
244 while(gStop.depth > 0) | |
245 { | |
246 do | |
247 { | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
248 next_depth = next_stop_depth_input_is_actual_stop_id(pDiveSettings, gStop.id); |
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
249 gGF_value = get_gf_at_pressure(pDiveSettings, next_depth + gSurface_pressure_bar); |
38 | 250 buehlmann_backup_and_restore(true); |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
251 ascend_time = ascend_with_all_gaschanges(pDiveSettings, gStop.depth - next_depth); |
38 | 252 ceiling = tissue_tolerance(); |
253 /* pre check actual limit */ | |
254 if(gDecotable.output_stop_length_seconds[gStop.id] >= 999*60) | |
255 { | |
256 tts_seconds -= 999*60 - gDecotable.output_stop_length_seconds[gStop.id]; | |
257 gDecotable.output_stop_length_seconds[gStop.id] = 999*60; | |
258 } | |
259 else | |
260 /* more deco on the actual depth */ | |
261 if(ceiling > next_depth + gSurface_pressure_bar) | |
262 { | |
263 next_depth = -1; | |
264 buehlmann_backup_and_restore(false); | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
265 decom_tissues_exposure2(10, &pDiveSettings->decogaslist[gGas_id], gPressure,gTissue_nitrogen_bar,gTissue_helium_bar); // some seconds at least at each stop |
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
266 decom_oxygen_calculate_cns_exposure(10, &pDiveSettings->decogaslist[gGas_id], gPressure, &gCNS); |
38 | 267 gDecotable.output_stop_length_seconds[gStop.id] += 10; |
268 tts_seconds += 10; | |
269 } | |
270 } while(next_depth == -1); | |
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
271 tts_seconds += ascend_time; |
38 | 272 gStop.depth = next_depth; |
273 for(i = gGas_id + 1; i < BUEHLMANN_STRUCT_MAX_GASES; i++) | |
274 { | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
275 if(pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero == 0) |
38 | 276 break; |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
277 float pressureChange = ((float)pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero) / 10; |
38 | 278 if(gStop.depth <= pressureChange + 0.00001f) |
279 { | |
280 gGas_id = i; | |
281 } | |
282 else | |
283 { | |
284 break; | |
285 } | |
286 } | |
287 gStop.id--; | |
288 } | |
289 | |
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
290 gDecotable.output_time_to_surface_seconds = tts_seconds; |
254
a17f7fb3b2b5
Buehlmann: cleanup, remove global pDecolistBuehlmann
Jan Mulder <jlmulder@xs4all.nl>
parents:
253
diff
changeset
|
291 memcpy(pDecoInfo, &gDecotable, sizeof(SDecoinfo)); |
38 | 292 } |
293 | |
294 | |
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
295 static float tissue_tolerance(void) |
38 | 296 { |
297 float tissue_inertgas_saturation; | |
298 float inertgas_a; | |
299 float inertgas_b; | |
300 float ceiling; | |
301 float global_ceiling; | |
302 int ci; | |
303 | |
304 global_ceiling = -1; | |
305 | |
306 for (ci = 0; ci < 16; ci++) | |
307 { | |
308 if(gTissue_helium_bar[ci] == 0) | |
309 { | |
310 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci]; | |
311 // | |
312 inertgas_a = buehlmann_N2_a[ci]; | |
313 inertgas_b = buehlmann_N2_b[ci]; | |
314 } | |
315 else | |
316 { | |
317 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci] + gTissue_helium_bar[ci]; | |
318 // | |
319 inertgas_a = ( ( buehlmann_N2_a[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_a[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation; | |
320 inertgas_b = ( ( buehlmann_N2_b[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_b[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation; | |
321 } | |
322 // | |
323 ceiling = (inertgas_b * ( tissue_inertgas_saturation - gGF_value * inertgas_a ) ) / (gGF_value - (inertgas_b * gGF_value) + inertgas_b); | |
324 if(ceiling > global_ceiling) | |
325 global_ceiling = ceiling; | |
326 } | |
327 return global_ceiling; | |
328 } | |
329 | |
246
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
330 void buehlmann_super_saturation_calculator(SLifeData* pLifeData, SDecoinfo * pDecoInfo) |
38 | 331 { |
332 float tissue_inertgas_saturation; | |
333 float inertgas_a; | |
334 float inertgas_b; | |
335 float ceiling; | |
246
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
336 float super_saturation; |
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
337 float pres_respiration = pLifeData->pressure_ambient_bar; |
38 | 338 int ci; |
339 | |
246
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
340 pDecoInfo->super_saturation = 0; |
38 | 341 |
342 for (ci = 0; ci < 16; ci++) | |
343 { | |
344 if(gTissue_helium_bar[ci] == 0) | |
345 { | |
346 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci]; | |
347 inertgas_a = buehlmann_N2_a[ci]; | |
348 inertgas_b = buehlmann_N2_b[ci]; | |
349 } | |
350 else | |
351 { | |
352 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci] + gTissue_helium_bar[ci]; | |
353 inertgas_a = ( ( buehlmann_N2_a[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_a[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation; | |
354 inertgas_b = ( ( buehlmann_N2_b[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_b[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation; | |
355 } | |
246
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
356 |
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
357 ceiling = pres_respiration / inertgas_b + inertgas_a; |
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
358 if(tissue_inertgas_saturation > pres_respiration) |
38 | 359 { |
246
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
360 super_saturation = |
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
361 (tissue_inertgas_saturation - pres_respiration) / (ceiling - pres_respiration); |
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
362 |
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
363 if (super_saturation > pDecoInfo->super_saturation) |
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
364 pDecoInfo->super_saturation = super_saturation; |
38 | 365 } |
366 } | |
367 } | |
368 | |
369 | |
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
370 static float buehlmann_tissue_test_tolerance(float depth_in_bar_absolute) |
38 | 371 { |
372 float tissue_inertgas_saturation; | |
373 float inertgas_a; | |
374 float inertgas_b; | |
375 float inertgas_tolerance; | |
376 float gf_minus_1; | |
377 | |
378 gf_minus_1 = gGF_value - 1.0f; | |
379 | |
380 for (int ci = 0; ci < 16; ci++) | |
381 { | |
382 if(gTissue_helium_bar[ci] == 0) | |
383 { | |
384 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci]; | |
385 inertgas_a = buehlmann_N2_a[ci]; | |
386 inertgas_b = buehlmann_N2_b[ci]; | |
387 } | |
388 else | |
389 { | |
390 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci] + gTissue_helium_bar[ci]; | |
391 inertgas_a = ( ( buehlmann_N2_a[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_a[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation; | |
392 inertgas_b = ( ( buehlmann_N2_b[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_b[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation; | |
393 } | |
394 inertgas_tolerance = ( (gGF_value / inertgas_b - gf_minus_1) * depth_in_bar_absolute ) + ( gGF_value * inertgas_a ); | |
395 if(inertgas_tolerance < tissue_inertgas_saturation) | |
250
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
396 return tissue_inertgas_saturation - inertgas_tolerance; // positive |
38 | 397 } |
250
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
398 return tissue_inertgas_saturation - inertgas_tolerance; // negative |
38 | 399 } |
400 | |
401 | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
402 static void ambient_bar_to_deco_stop_depth_bar(SDiveSettings *pDiveSettings, float ceiling) |
38 | 403 { |
404 int i; | |
405 | |
406 ceiling -= gSurface_pressure_bar; | |
407 | |
408 if(ceiling <= 0) | |
409 { | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
410 gStop.depth = pDiveSettings->last_stop_depth_bar; |
38 | 411 gStop.id = 0; |
412 return; | |
413 } | |
414 | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
415 if((ceiling - pDiveSettings->last_stop_depth_bar) <= 0) |
38 | 416 { |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
417 gStop.depth = pDiveSettings->last_stop_depth_bar; |
38 | 418 gStop.id = 0; |
419 return; | |
420 } | |
421 | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
422 gStop.depth = pDiveSettings->input_second_to_last_stop_depth_bar; |
38 | 423 gStop.id = 1; |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
424 ceiling -= pDiveSettings->input_second_to_last_stop_depth_bar; |
38 | 425 |
426 if(ceiling <= 0) | |
427 return; | |
428 | |
429 for(i = 1; i < (DECOINFO_STRUCT_MAX_STOPS - 2); i++) | |
430 { | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
431 ceiling -= pDiveSettings->input_next_stop_increment_depth_bar; |
38 | 432 if(ceiling <= 0) |
433 break; | |
434 } | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
435 gStop.depth += i * pDiveSettings->input_next_stop_increment_depth_bar; |
38 | 436 gStop.id += i; |
437 return; | |
438 } | |
439 | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
440 static float next_stop_depth_input_is_actual_stop_id(SDiveSettings *pDiveSettings, int actual_id) |
38 | 441 { |
442 if(actual_id == 0) | |
443 return 0; | |
444 | |
445 if(actual_id == 1) | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
446 return pDiveSettings->last_stop_depth_bar; |
38 | 447 |
448 actual_id -= 2; | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
449 return pDiveSettings->input_second_to_last_stop_depth_bar + (actual_id * pDiveSettings->input_next_stop_increment_depth_bar); |
38 | 450 } |
451 | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
452 static int ascend_with_all_gaschanges(SDiveSettings *pDiveSettings, float pressure_decrease) |
38 | 453 { |
454 float pressureTop, pressureTop_tmp, pressureBottom, pressureChange, ascendrate_in_seconds_for_one_bar, pressure_difference; | |
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
455 int time_for_ascend = 0; |
38 | 456 int seconds; |
457 int i; | |
458 | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
459 ascendrate_in_seconds_for_one_bar = 60 * 10 / pDiveSettings->ascentRate_meterperminute; |
38 | 460 |
461 if(fabsf(gPressure - gSurface_pressure_bar) < PRESSURE_HALF_METER) | |
462 { | |
463 gPressure = gSurface_pressure_bar; | |
464 return 0; | |
465 } | |
466 | |
467 pressureTop = gPressure - pressure_decrease; | |
468 if( gSurface_pressure_bar > pressureTop) | |
469 pressureTop = gSurface_pressure_bar; | |
470 pressureBottom = gPressure; | |
471 seconds = 0; | |
472 do{ | |
473 pressureTop_tmp = pressureTop; | |
474 for(i = gGas_id + 1; i < BUEHLMANN_STRUCT_MAX_GASES; i++) | |
475 { | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
476 if(pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero == 0) |
38 | 477 break; |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
478 pressureChange = gSurface_pressure_bar + ((float)pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero) / 10; |
38 | 479 if(pressureBottom <= pressureChange) |
480 { | |
481 gGas_id = i; | |
482 } | |
483 else | |
484 { | |
485 break; | |
486 } | |
487 | |
488 } | |
489 for(i = gGas_id + 1; i < BUEHLMANN_STRUCT_MAX_GASES; i++) | |
490 { | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
491 if(pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero == 0) |
38 | 492 break; |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
493 pressureChange = gSurface_pressure_bar + ((float)pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero)/ 10; |
38 | 494 if((pressureChange < pressureBottom) && (pressureChange > pressureTop)) |
495 { | |
496 pressureTop_tmp = pressureChange; | |
497 } | |
498 } | |
499 pressure_difference = pressureBottom - pressureTop_tmp; | |
500 if(pressure_difference > 0.0001f) | |
501 { | |
502 time_for_ascend = (int)ceilf(pressure_difference * ascendrate_in_seconds_for_one_bar); | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
503 decom_tissues_exposure_stage_schreiner(time_for_ascend, &pDiveSettings->decogaslist[gGas_id], |
38 | 504 pressureBottom, pressureTop_tmp, gTissue_nitrogen_bar, gTissue_helium_bar); |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
505 decom_oxygen_calculate_cns_stage_SchreinerStyle(time_for_ascend,&pDiveSettings->decogaslist[gGas_id], |
38 | 506 pressureBottom, pressureTop_tmp, &gCNS); |
507 } | |
508 pressureBottom = pressureTop_tmp; | |
509 seconds += time_for_ascend; | |
510 }while(pressureTop_tmp > pressureTop); | |
511 gPressure = pressureTop; | |
512 return seconds; | |
513 } | |
514 | |
515 | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
516 static float get_gf_at_pressure(SDiveSettings *pDiveSettings, float pressure) |
38 | 517 { |
518 float gfSteigung = 0.0f; | |
519 | |
520 if(gGF_low_depth_bar < 0) | |
521 gGF_low_depth_bar = PRESSURE_THREE_METER; // just to prevent erratic behaviour if variable is not set | |
522 | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
523 gfSteigung = ((float)(pDiveSettings->gf_high - pDiveSettings->gf_low))/ gGF_low_depth_bar; |
38 | 524 |
525 | |
526 if((pressure - gSurface_pressure_bar) <= PRESSURE_HALF_METER) | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
527 return ((float)pDiveSettings->gf_high) / 100.0f; |
38 | 528 |
529 if(pressure >= gSurface_pressure_bar + gGF_low_depth_bar) | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
530 return ((float)pDiveSettings->gf_low) / 100.0f; |
38 | 531 |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
532 return (pDiveSettings->gf_high - gfSteigung * (pressure - gSurface_pressure_bar) )/ 100.0f; |
38 | 533 } |
534 | |
535 | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
536 static void buehlmann_calc_ndl(SDiveSettings *pDiveSettings) |
38 | 537 { |
538 float local_tissue_nitrogen_bar[16]; | |
539 float local_tissue_helium_bar[16]; | |
540 int i; | |
541 | |
542 gNDL = 0; | |
543 //Check ndl always use gHigh | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
544 gGF_value = ((float)pDiveSettings->gf_high) / 100.0f; |
38 | 545 //10 minutes steps |
546 while(gNDL < (300 * 60)) | |
547 { | |
548 memcpy(local_tissue_nitrogen_bar, gTissue_nitrogen_bar, (4*16)); | |
549 memcpy(local_tissue_helium_bar, gTissue_helium_bar, (4*16)); | |
550 // | |
551 gNDL += 600; | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
552 decom_tissues_exposure2(600, &pDiveSettings->decogaslist[gGas_id], gPressure,gTissue_nitrogen_bar,gTissue_helium_bar); |
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
553 decom_oxygen_calculate_cns_exposure(600,&pDiveSettings->decogaslist[gGas_id],gPressure,&gCNS); |
38 | 554 //tissues_exposure_at_gPressure_seconds(600); |
555 buehlmann_backup_and_restore(true); | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
556 if(dive1_check_deco(pDiveSettings)) |
38 | 557 { |
558 buehlmann_backup_and_restore(false); | |
559 break; | |
560 } | |
561 buehlmann_backup_and_restore(false); | |
562 } | |
563 | |
564 if(gNDL < (300 * 60)) | |
565 gNDL -= 600; | |
566 | |
567 if(gNDL > (150 * 60)) | |
568 return; | |
569 | |
570 // refine | |
571 memcpy(gTissue_nitrogen_bar, local_tissue_nitrogen_bar, (4*16)); | |
572 memcpy(gTissue_helium_bar, local_tissue_helium_bar, (4*16)); | |
573 | |
574 //One minutes step | |
575 for(i = 0; i < 20; i++) | |
576 { | |
577 gNDL += 60; | |
578 //tissues_exposure_at_gPressure_seconds(60); | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
579 decom_tissues_exposure2(60, &pDiveSettings->decogaslist[gGas_id], gPressure,gTissue_nitrogen_bar,gTissue_helium_bar); |
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
580 decom_oxygen_calculate_cns_exposure(60,&pDiveSettings->decogaslist[gGas_id],gPressure,&gCNS); |
38 | 581 buehlmann_backup_and_restore(true); |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
582 if(dive1_check_deco(pDiveSettings)) |
38 | 583 break; |
584 buehlmann_backup_and_restore(false); | |
585 } | |
586 //gNDL -= 60; | |
587 return; | |
588 } | |
589 | |
590 | |
591 // =============================================================================== | |
592 // dive1_check_deco | |
593 /// @brief for NDL calculations | |
594 /// 160614 using ceilingOther and not ceiling | |
595 // =============================================================================== | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
596 static _Bool dive1_check_deco(SDiveSettings *pDiveSettings) |
38 | 597 { |
598 // gGF_value is set in call routine; | |
599 // internes Backup! | |
600 | |
601 // calc like in deco | |
602 float ceiling; | |
603 float ceilingOther; // new hw 160614 | |
604 | |
605 ceiling = tissue_tolerance(); | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
606 ambient_bar_to_deco_stop_depth_bar(pDiveSettings, ceiling); // this will set gStop.depth :-) (and gStop.id) |
38 | 607 |
608 // set the base for all upcoming parameters | |
609 ceilingOther = gStop.depth + gSurface_pressure_bar; | |
610 | |
611 // modify parameters if there is ascend or parameter fine adjustment | |
612 if(ceilingOther < (gPressure - PRESSURE_150_CM)) // more than 1.5 meter below ceiling | |
613 { | |
614 // ascend within 10 mtr to GF_low // speed 12 mtr/min -> 50 sec / 10 mtr; 15 sec / 3 mtr. | |
615 while(((gPressure - PRESSURE_TEN_METER ) > gSurface_pressure_bar) && (ceiling < (gPressure - PRESSURE_TEN_METER))) | |
616 { | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
617 ascend_with_all_gaschanges(pDiveSettings, PRESSURE_TEN_METER); |
38 | 618 ceiling = tissue_tolerance(); |
619 } | |
620 while(((gPressure - PRESSURE_THREE_METER )> gSurface_pressure_bar) && (ceiling < gPressure)) | |
621 { | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
622 ascend_with_all_gaschanges(pDiveSettings, PRESSURE_THREE_METER); |
38 | 623 ceiling = tissue_tolerance(); |
624 } | |
625 } | |
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
626 return ceiling > gSurface_pressure_bar; |
38 | 627 } |
628 | |
250
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
629 // compute ceiling recursively, with a resolution of 10cm. Notice |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
630 // that the initial call shall guarantee that the found ceiling |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
631 // is between low and high parameters. |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
632 static float compute_ceiling(float low, float high) |
38 | 633 { |
250
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
634 if ((high - low) < 0.01) |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
635 return low; |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
636 else { |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
637 float next_pressure_absolute = (low + high)/2; |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
638 float test_result = buehlmann_tissue_test_tolerance(next_pressure_absolute); |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
639 if (test_result < 0) |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
640 return compute_ceiling(low, next_pressure_absolute); |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
641 else |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
642 return compute_ceiling(next_pressure_absolute, high); |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
643 } |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
644 } |
38 | 645 |
250
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
646 void buehlmann_ceiling_calculator(SLifeData *pLifeData, SDecoinfo *pDecoInfo) |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
647 { |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
648 float ceiling; |
224
ceecabfddb57
Bugfix, deco: fix 2 (small) problems with calculated ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
130
diff
changeset
|
649 |
250
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
650 // this is just performance optimizing. The code below runs just fine |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
651 // without this. There is never a ceiling in NDL deco state |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
652 if (!pDecoInfo->output_time_to_surface_seconds) { |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
653 pDecoInfo->output_ceiling_meter = 0; |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
654 return; |
38 | 655 } |
656 | |
657 memcpy(gTissue_nitrogen_bar, pLifeData->tissue_nitrogen_bar, (4*16)); | |
658 memcpy(gTissue_helium_bar, pLifeData->tissue_helium_bar, (4*16)); | |
224
ceecabfddb57
Bugfix, deco: fix 2 (small) problems with calculated ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
130
diff
changeset
|
659 |
250
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
660 ceiling = compute_ceiling(pLifeData->pressure_surface_bar, 1.0f + pLifeData->max_depth_meter/10.0f); |
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
661 pDecoInfo->output_ceiling_meter = (ceiling - pLifeData->pressure_surface_bar) * 10.0f; |
38 | 662 } |