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