annotate src/p2_deco.c @ 582:b455b31ce022

work on 2.97 stable
author heinrichsweikamp
date Mon, 26 Feb 2018 16:40:28 +0100
parents 4ce70e3f00be
children d63dec562d50
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1 // ***************************************************************************
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2 // p2_deco.c REFACTORED VERSION V2.97b
0
heinrichsweikamp
parents:
diff changeset
3 //
heinrichsweikamp
parents:
diff changeset
4 // Created on: 12.05.2009
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
5 // Author: heinrichs weikamp, contributions by Ralph Lembcke and others
0
heinrichsweikamp
parents:
diff changeset
6 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
7 // ***************************************************************************
0
heinrichsweikamp
parents:
diff changeset
8
heinrichsweikamp
parents:
diff changeset
9 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
10 // OSTC - diving computer code
heinrichsweikamp
parents:
diff changeset
11 // Copyright (C) 2011 HeinrichsWeikamp GbR
heinrichsweikamp
parents:
diff changeset
12 //
heinrichsweikamp
parents:
diff changeset
13 // This program is free software: you can redistribute it and/or modify
heinrichsweikamp
parents:
diff changeset
14 // it under the terms of the GNU General Public License as published by
heinrichsweikamp
parents:
diff changeset
15 // the Free Software Foundation, either version 3 of the License, or
heinrichsweikamp
parents:
diff changeset
16 // (at your option) any later version.
heinrichsweikamp
parents:
diff changeset
17 //
heinrichsweikamp
parents:
diff changeset
18 // This program is distributed in the hope that it will be useful,
heinrichsweikamp
parents:
diff changeset
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
heinrichsweikamp
parents:
diff changeset
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
heinrichsweikamp
parents:
diff changeset
21 // GNU General Public License for more details.
heinrichsweikamp
parents:
diff changeset
22 //
heinrichsweikamp
parents:
diff changeset
23 // You should have received a copy of the GNU General Public License
heinrichsweikamp
parents:
diff changeset
24 // along with this program. If not, see <http://www.gnu.org/licenses/>.
heinrichsweikamp
parents:
diff changeset
25 //
heinrichsweikamp
parents:
diff changeset
26 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
27
heinrichsweikamp
parents:
diff changeset
28 // history:
heinrichsweikamp
parents:
diff changeset
29 // 01/03/08 v100: first release candidate
heinrichsweikamp
parents:
diff changeset
30 // 03/13/08 v101: start of programming ppO2 code
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
31 // 03/13/25 v101a: backup of interim version with ppO2 calculation
0
heinrichsweikamp
parents:
diff changeset
32 // 03/13/25 v101: open circuit gas change during deco
heinrichsweikamp
parents:
diff changeset
33 // 03/13/25 v101: CNS_fraction calculation
heinrichsweikamp
parents:
diff changeset
34 // 03/13/26 v101: optimization of tissue calc routines
heinrichsweikamp
parents:
diff changeset
35 // 07/xx/08 v102a: debug of bottom time routine
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
36 // 09/xx/08 v102d: Gradient Factor Model implementation
0
heinrichsweikamp
parents:
diff changeset
37 // 10/10/08 v104: renamed to build v103 for v118 stable
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
38 // 10/14/08 v104: integration of char_I_depth_last_deco for Gradient Model
0
heinrichsweikamp
parents:
diff changeset
39 // 03/31/09 v107: integration of FONT Incon24
heinrichsweikamp
parents:
diff changeset
40 // 05/23/10 v109: 5 gas changes & 1 min timer
heinrichsweikamp
parents:
diff changeset
41 // 07/13/10 v110: cns vault added
heinrichsweikamp
parents:
diff changeset
42 // 12/25/10 v110: split in three files (deco.c, main.c, definitions.h)
heinrichsweikamp
parents:
diff changeset
43 // 2011/01/20: [jDG] Create a common file included in ASM and C code.
heinrichsweikamp
parents:
diff changeset
44 // 2011/01/24: [jDG] Make ascenttime an short. No more overflow!
heinrichsweikamp
parents:
diff changeset
45 // 2011/01/25: [jDG] Fusion deco array for both models.
heinrichsweikamp
parents:
diff changeset
46 // 2011/01/25: [jDG] Use CF(54) to reverse deco order.
heinrichsweikamp
parents:
diff changeset
47 // 2011/02/11: [jDG] Reworked gradient-factor implementation.
heinrichsweikamp
parents:
diff changeset
48 // 2011/02/15: [jDG] Fixed inconsistencies introduced by gas switch delays.
heinrichsweikamp
parents:
diff changeset
49 // 2011/03/21: [jDG] Added gas consumption (CF56 & CF57) evaluation for OCR mode.
heinrichsweikamp
parents:
diff changeset
50 // 2011/04/15: [jDG] Store low_depth in 32bits (w/o rounding), for a better stability.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
51 // 2011/04/25: [jDG] Added 1mn mode for CNS calculation, to allow it for deco planning.
0
heinrichsweikamp
parents:
diff changeset
52 // 2011/04/27: [jDG] Fixed char_O_gradient_factor calculation when model uses gradient-factor.
heinrichsweikamp
parents:
diff changeset
53 // 2011/05/02: [jDG] Added "Future TTS" function (CF58).
heinrichsweikamp
parents:
diff changeset
54 // 2011/05/17: [jDG] Various cleanups.
heinrichsweikamp
parents:
diff changeset
55 // 2011/08/08: [jDG] Computes CNS during deco planning ascent.
heinrichsweikamp
parents:
diff changeset
56 // 2011/11/24: [jDG] Slightly faster and better NDL computation.
heinrichsweikamp
parents:
diff changeset
57 // 2011/12/17: [mH] Remove of the useless debug stuff
heinrichsweikamp
parents:
diff changeset
58 // 2012/02/24: [jDG] Remove missed stop bug.
heinrichsweikamp
parents:
diff changeset
59 // 2012/02/25: [jDG] Looking for a more stable LOW grad factor reference.
heinrichsweikamp
parents:
diff changeset
60 // 2012/09/10: [mH] Fill char_O_deco_time_for_log for logbook write
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
61 // 2012/10/05: [jDG] Better gas_volumes accuracy (average depth, switch between stop).
0
heinrichsweikamp
parents:
diff changeset
62 // 2013/03/05: [jDG] Should vault low_depth too.
heinrichsweikamp
parents:
diff changeset
63 // 2013/03/05: [jDG] Wrobell remark: ascent_to_first_stop works better with finer steps (2sec).
33
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
64 // 2013/05/08: [jDG] A. Salm remark: NOAA tables for CNS are in ATA, not bar.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
65 // 2013/12/21: [jDG] Fix CNS calculation in deco plan w/o marked gas switch
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
66 // 2014/06/16: [jDG] Fix Helium diluent. Fix volumes with many travel mix.
324
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
67 // 2014/06/29: [mH] Compute int_O_ceiling
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
68 // 2015/06/12: [jDG] Fix NDL prediction while desaturating with the Buhlmann model.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
69 // 2017/08/04: [mH] Switch to absolute GF everywhere and apply safety margin parameters to both models (GF and non-GF), fixes from Ralph Lembcke
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
70 // 2017/10/31: [rl] enhancements for pSCR mode and introduction of 2nd deco plan computation
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
71 // 2017/12/31: [rl] completion of 2nd deco plan computation and various up-fixes
0
heinrichsweikamp
parents:
diff changeset
72 //
heinrichsweikamp
parents:
diff changeset
73 //
heinrichsweikamp
parents:
diff changeset
74 // Literature:
313
0ce5fa241b8e FIX minor comment about deco offset unit...
jDG
parents: 298
diff changeset
75 // Buhlmann, Albert: Tauchmedizin; 4. Auflage [2002];
0
heinrichsweikamp
parents:
diff changeset
76 // Schr"oder, Kai & Reith, Steffen; 2000; S"attigungsvorg"ange beim Tauchen, das Modell ZH-L16, Funktionsweise von Tauchcomputern; http://www.achim-und-kai.de/kai/tausim/saett_faq
heinrichsweikamp
parents:
diff changeset
77 // Morrison, Stuart; 2000; DIY DECOMPRESSION; http://www.lizardland.co.uk/DIYDeco.html
heinrichsweikamp
parents:
diff changeset
78 // Balthasar, Steffen; Dekompressionstheorie I: Neo Haldane Modelle; http://www.txfreak.de/dekompressionstheorie_1.pdf
heinrichsweikamp
parents:
diff changeset
79 // Baker, Erik C.; Clearing Up The Confusion About "Deep Stops"
heinrichsweikamp
parents:
diff changeset
80 // Baker, Erik C.; Understanding M-values; http://www.txfreak.de/understanding_m-values.pdf
heinrichsweikamp
parents:
diff changeset
81 //
heinrichsweikamp
parents:
diff changeset
82 //
heinrichsweikamp
parents:
diff changeset
83
heinrichsweikamp
parents:
diff changeset
84 // *********************
heinrichsweikamp
parents:
diff changeset
85 // ** I N C L U D E S **
heinrichsweikamp
parents:
diff changeset
86 // *********************
heinrichsweikamp
parents:
diff changeset
87 #include <math.h>
heinrichsweikamp
parents:
diff changeset
88
heinrichsweikamp
parents:
diff changeset
89 // ***********************************************
heinrichsweikamp
parents:
diff changeset
90 // ** V A R I A B L E S D E F I N I T I O N S **
heinrichsweikamp
parents:
diff changeset
91 // ***********************************************
heinrichsweikamp
parents:
diff changeset
92
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
93 #include "p2_definitions.h"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
94 #define TEST_MAIN
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
95 #include "shared_definitions.h"
0
heinrichsweikamp
parents:
diff changeset
96
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
97
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
98 // ambient pressure at different mountain heights
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
99 #define P_ambient_1000m 0.880 // [bar] based on 990 hPa and 20°C at sea level, 15°C at altitude
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
100 #define P_ambient_2000m 0.782 // [bar]
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
101 #define P_ambient_3000m 0.695 // [bar]
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
102
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
103 // ambient pressure in aircraft cabin during flying - worst case according to Buhlmann
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
104 #define P_ambient_fly 0.600 // [bar], 0.600 bar is the value used by Buhlmann for his flying-after-diving calculations
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
105 // 0.735 bar is a typical cabin pressure for nowadays commercial jet aircrafts
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
106 // -----
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
107 // 0.135 bar safety margin
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
108
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
109 // constants and factors
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
110 #define ppWater 0.0627 // water vapor partial pressure in the lungs
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
111 #define METER_TO_BAR 0.09985 // conversion factor
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
112 #define BAR_TO_METER 10.0150 // conversion factor (1.0/METER_TO_BAR)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
113 #define SURFACE_DESAT_FACTOR 0.7042 // surface desaturation safety factor
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
114 #define HYST 1.0E-06 // threshold for tissue graphics on-gassing / off-gassing visualization
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
115
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
116 // thresholds
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
117 #define GF_WARNING_THRESHOLD 100 // threshold for GF warning (attention threshold is current GF_high)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
118 #define CNS_WARNING_THRESHOLD 100 // threshold for CNS warning
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
119 #define CNS_ATTENTION_THRESHOLD 70 // threshold for CNS attention
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
120 #define ppO2_ATTENTION_THRESHOLD 120 // threshold for ppO2 attention (thresholds for warnings come by options_table.asm)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
121 #define ppO2_GAP_TO_SETPOINT 10 // gap between setpoint and max. ppO2 of the pure diluent [cbar]
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
122 #define GAS_NEEDS_ATTENTION_THRESHOLD 0.70 // threshold for gas needs attention
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
123
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
124 // deco engine states and modes - char_O_deco_status
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
125 #define DECO_STATUS_MASK 0x03
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
126 #define DECO_STATUS_START 0x00
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
127 #define DECO_STATUS_FINISHED 0x00
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
128 #define DECO_STATUS_STOPS 0x01
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
129 #define DECO_STATUS_RESULTS 0x02
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
130 #define DECO_STATUS_INIT 0x03
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
131
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
132 #define DECO_MODE_MASK 0x0C
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
133 #define DECO_MODE_LOOP 0x04
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
134 #define DECO_MODE_CCR 0x04 // to be used with == operator in combination with DECO_MODE_MASK only!
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
135 #define DECO_MODE_PSCR 0x08
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
136
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
137 #define DECO_PLAN_ALTERNATE 0x10
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
138 #define DECO_CNS_CALCULATE 0x20
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
139 #define DECO_VOLUME_CALCULATE 0x40
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
140 #define DECO_ASCENT_DELAYED 0x80
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
141
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
142 // deco engine states and modes - char_O_main_status
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
143 //#define DECO_MODE_MASK 0x0C
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
144 //#define DECO_MODE_LOOP 0x04
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
145 //#define DECO_MODE_CCR 0x04 // to be used with == operator in combination with DECO_MODE_MASK only!
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
146 //#define DECO_MODE_PSCR 0x08
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
147 #define DECO_GASCHANGE_OVRD 0x10
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
148 #define DECO_BOTTOM_CALCULATE 0x40
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
149
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
150 // deco engine states and modes - tissue_increment
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
151 #define TIME_MASK 0x7F // (127 decimal, bits 0-6)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
152 #define TISSUE_FLAG 0x80 // (128 decimal, bit 7 )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
153
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
154 // deco engine warnings
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
155 #define DECO_WARNING_IBCD 0x01
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
156 #define DECO_WARNING_IBCD_lock 0x02
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
157 #define DECO_WARNING_MBUBBLES 0x04
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
158 #define DECO_WARNING_MBUBBLES_lock 0x08
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
159 #define DECO_WARNING_OUTSIDE 0x10
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
160 #define DECO_WARNING_OUTSIDE_lock 0x20
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
161 #define DECO_WARNING_STOPTABLE_OVERFLOW 0x40
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
162 #define DECO_FLAG 0x80
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
163
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
164 // flags used with integer numbers
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
165 #define INT_FLAG_INVALID 0x0400
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
166 #define INT_FLAG_ZERO 0x0800
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
167 #define INT_FLAG_LOW 0x1000
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
168 #define INT_FLAG_HIGH 0x2000
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
169 #define INT_FLAG_ATTENTION 0x4000
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
170 #define INT_FLAG_WARNING 0x8000
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
171
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
172
0
heinrichsweikamp
parents:
diff changeset
173
heinrichsweikamp
parents:
diff changeset
174 // *************************
heinrichsweikamp
parents:
diff changeset
175 // ** P R O T O T Y P E S **
heinrichsweikamp
parents:
diff changeset
176 // *************************
heinrichsweikamp
parents:
diff changeset
177
heinrichsweikamp
parents:
diff changeset
178 static void calc_hauptroutine(void);
heinrichsweikamp
parents:
diff changeset
179 static void calc_hauptroutine_data_input(void);
heinrichsweikamp
parents:
diff changeset
180 static void calc_hauptroutine_update_tissues(void);
heinrichsweikamp
parents:
diff changeset
181 static void calc_hauptroutine_calc_deco(void);
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
182 static void calc_alveolar_pressures(void);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
183 static void calc_tissues(void);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
184 static void calc_NDL_time(void);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
185 static void calc_ascenttime(void);
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
186 static void calc_CNS_increment(void);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
187 static void calc_desaturation_time(void);
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
188 static void calc_ascent_to_first_stop(void);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
189 static void calc_limit(PARAMETER float GF_current);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
190 static void calc_interval(PARAMETER unsigned char time_increment);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
191
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
192 static void gas_find_current(void);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
193 static void gas_set_ratios(void);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
194 static void convert_CNS_for_display(void);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
195 static void convert_sim_CNS_for_display(void);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
196 static void publish_deco_table(void);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
197 static void clear_deco_table(void);
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
198 static void clear_tissue(void);
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
199
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
200 static unsigned char calc_nextdecodepth(void);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
201 static unsigned char gas_find_better(void);
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
202 static unsigned char update_deco_table(PARAMETER unsigned char time_increment);
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
203
0
heinrichsweikamp
parents:
diff changeset
204
heinrichsweikamp
parents:
diff changeset
205 //---- Bank 5 parameters -----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
206 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
207 # pragma udata bank5=0x500
heinrichsweikamp
parents:
diff changeset
208 #endif
heinrichsweikamp
parents:
diff changeset
209
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
210 // general deco parameters
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
211
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
212 static float GF_low; // initialized from deco parameters, constant during all computations
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
213 static float GF_high; // initialized from deco parameters, constant during all computations
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
214 static float GF_delta; // initialized from deco parameters, constant during all computations
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
215 static float locked_GF_step_norm; // GF_delta / low_depth_norm in normal plan
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
216 static float locked_GF_step_alt; // GF_delta / low_depth_alt in alternative plan
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
217
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
218 static float low_depth_norm; // Depth of deepest stop in normal plan
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
219 static float low_depth_alt; // Depth of deepest stop in alternative plan
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
220
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
221 static float float_ascent_speed; // ascent speed from options_table (1.0 .. 10.0 m/min)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
222 static float float_deco_distance; // additional depth below stop depth for tissue, CNS and gas volume calculation
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
223 static float float_saturation_multiplier; // safety factor for on-gassing rates
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
224 static float float_desaturation_multiplier; // safety factor for off-gassing rates
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
225
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
226 // real context: what we are doing now
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
227
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
228 static float ceiling; // minimum tolerated relative pressure (i.e. without surface pressue)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
229 static float CNS_fraction; // current CNS (1.00 = 100%)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
230
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
231 static unsigned short deco_tissue_vector; // 16 bit vector to memories all tissues that are in decompression
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
232 static unsigned short IBCD_tissue_vector; // 16 bit vector to memories all tissues that experience IBCD
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
233
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
234 // simulation context: used to predict ascent
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
235
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
236 static float sim_ceiling; // minimum tolerated relative pressure (i.e. without surface pressue)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
237 static float sim_CNS_fraction; // CNS increase during predicted ascent, 0.01 = 1%
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
238
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
239 static unsigned int int_sim_CNS_fraction; // CNS increase during predicted ascent, in %
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
240
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
241 static unsigned char sim_depth_limit; // depth of next stop in meters, used in deco calculations
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
242 static unsigned char split_N2_He[NUM_COMP]; // used for calculating the desaturation time
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
243 static unsigned char NDL_lead_tissue; // used to cache tissue to start with calculating NDL
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
244
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
245
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
246 // stops table
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
247
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
248 static unsigned char internal_deco_depth[NUM_STOPS]; // depth of the stop
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
249 static unsigned char internal_deco_time[NUM_STOPS]; // duration of the stop
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
250 static unsigned char internal_deco_gas[NUM_STOPS]; // gas used at the stop
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
251
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
252
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
253 // transfer variables between calc_desaturation_time() and calc_desaturation_time_helper()
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
254
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
255 static float desat_factor; // used to cache a pre-computed factor
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
256 static float var_ht; // buffer for a half-time factor
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
257 static float pres_target; // target pressure for a compartment
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
258 static float pres_actual; // current pressure of the compartment
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
259 static unsigned int int_time; // time it takes for the compartment to reach the target pressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
260
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
261
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
262 // transfer variables between gas_volumes() and gas_volumes_helper()
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
263
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
264 static float float_depth; // depth of the stop or half-way point
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
265 static float float_time; // duration of the stop or ascent phase
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
266 static float volume; // computed volume of gas
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
267 static unsigned char usage; // gas usage in l/min
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
268
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
269
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
270 // auxiliary variables for data buffering
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
271
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
272 static float N2_equilibrium; // used for N2 tissue graphics scaling
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
273 static float temp_tissue; // auxiliary variable to buffer tissue pressures
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
274 static float float_pSCR_factor; // pre-computed factor for pSCR ppO2 drop calculation
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
275
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
276
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
277 // 35 byte free space left in this bank (4 bytes per float, 2 bytes per int/short, 1 byte per char)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
278
0
heinrichsweikamp
parents:
diff changeset
279
heinrichsweikamp
parents:
diff changeset
280 //---- Bank 6 parameters -----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
281 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
282 # pragma udata bank6=0x600
heinrichsweikamp
parents:
diff changeset
283 #endif
heinrichsweikamp
parents:
diff changeset
284
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
285 // indexing and sequencing
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
286
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
287 static unsigned char ci; // used as index to the Buhlmann tables
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
288 static unsigned char twosectimer = 0; // used for timing the tissue updating
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
289 static unsigned char tissue_increment; // selector for real/simulated tissues and time increment
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
290
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
291
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
292 // environmental and gas data
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
293
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
294 static float pres_surface; // absolute pressure at the surface
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
295
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
296 static unsigned char bottom_depth; // bottom depth in meters, used by CNS and gas needs calculation
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
297
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
298 static float pres_respiration; // current depth in absolute pressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
299 static float O2_ratio; // real breathed gas oxygen ratio
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
300 static float N2_ratio; // real breathed gas nitrogen ratio
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
301 static float He_ratio; // real breathed gas helium ratio
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
302 static float pSCR_drop; // real ppO2 drop in pSCR loop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
303
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
304 static float sim_pres_respiration; // simulated current depth in abs.pressure, used for deco calculations
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
305 static float sim_O2_ratio; // simulated breathed gas oxygen ratio
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
306 static float sim_N2_ratio; // simulated breathed gas nitrogen ratio
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
307 static float sim_He_ratio; // simulated breathed gas helium ratio
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
308 static float sim_pSCR_drop; // simulated ppO2 drop in pSCR loop
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
309
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
310 static float O2_ppO2; // ppO2 - calculated for pure oxygen at current depth
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
311 static float OC_ppO2; // ppO2 - calculated for breathed in OC mode
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
312 static float pSCR_ppO2; // ppO2 - calculated for breathed from pSCR loop
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
313
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
314 static float ppO2; // partial pressure of breathed oxygen
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
315 static float ppN2; // partial pressure of breathed nitrogen
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
316 static float ppHe; // partial pressure of breathed helium
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
317
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
318
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
319 // Result values from calculation functions
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
320
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
321 static float CNS_fraction_inc; // increment of CNS load, 0.01 = 1%
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
322
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
323 static unsigned char char_ppO2; // partial pressure of breathed oxygen, as integer 100 = 1.00 bar
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
324 static unsigned char NDL_time; // time in minutes until reaching NDL
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
325 static unsigned int ascent_time; // time in minutes needed for the ascent
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
326
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
327
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
328 // Buhlmann model parameters
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
329
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
330 static float var_N2_a; // Buhlmann a, for current N2 tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
331 static float var_N2_b; // Buhlmann b, for current N2 tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
332 static float var_He_a; // Buhlmann a, for current He tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
333 static float var_He_b; // Buhlmann b, for current He tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
334 static float var_N2_e; // exposition, for current N2 tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
335 static float var_He_e; // exposition, for current He tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
336 static float var_N2_ht; // half-time for current N2 tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
337 static float var_He_ht; // half-time for current N2 tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
338
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
339
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
340 // Gas switch history
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
341
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
342 static unsigned char sim_gas_first_used; // Number of first used gas, for bottom segment
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
343 static unsigned char sim_gas_last_used; // number of last used gas
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
344 static unsigned char sim_gas_last_depth; // change depth of last used gas
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
345
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
346
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
347 // Vault to back-up & restore tissue data
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
348
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
349 static float pres_tissue_N2_vault[NUM_COMP]; // stores the nitrogen tissue pressures
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
350 static float pres_tissue_He_vault[NUM_COMP]; // stores the helium tissue pressures
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
351 static float cns_vault_float; // stores current CNS (float representation)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
352 static unsigned char deco_warnings_vault; // stores warnings status
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
353
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
354
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
355 // 8 byte free space left in this bank (4 bytes per float, 2 bytes per int/short, 1 byte per char)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
356
0
heinrichsweikamp
parents:
diff changeset
357
heinrichsweikamp
parents:
diff changeset
358 //---- Bank 7 parameters -----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
359 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
360 # pragma udata bank7=0x700
heinrichsweikamp
parents:
diff changeset
361 #endif
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
362
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
363 // Keep order and position of the variables in bank 7 as they are backed-up to & restored from EEPROM
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
364
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
365 float pres_tissue_N2[NUM_COMP]; // 16 floats = 64 bytes
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
366 float pres_tissue_He[NUM_COMP]; // 16 floats = 64 bytes
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
367
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
368 float sim_pres_tissue_N2[NUM_COMP]; // 16 floats = 64 bytes
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
369 float sim_pres_tissue_He[NUM_COMP]; // 16 floats = 64 bytes
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
370
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
371 // bank is full!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
372
0
heinrichsweikamp
parents:
diff changeset
373
heinrichsweikamp
parents:
diff changeset
374 //---- Bank 8 parameters -----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
375 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
376 # pragma udata overlay bank8=0x800
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
377
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
378 static char md_pi_subst[256]; // Overlay C-code data stack here, too.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
379
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
380 # define C_STACK md_pi_subst
0
heinrichsweikamp
parents:
diff changeset
381 #endif
heinrichsweikamp
parents:
diff changeset
382
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
383
0
heinrichsweikamp
parents:
diff changeset
384 // Back to bank6 for further tmp data
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
385 // Do not delete this assignment, it is needed by the compiler/linker.
0
heinrichsweikamp
parents:
diff changeset
386 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
387 # pragma udata bank6
heinrichsweikamp
parents:
diff changeset
388 #endif
heinrichsweikamp
parents:
diff changeset
389
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
390
0
heinrichsweikamp
parents:
diff changeset
391 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
392 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
393 //////////////// THE LOOKUP TABLES ////////////////
0
heinrichsweikamp
parents:
diff changeset
394 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
395 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
396
0
heinrichsweikamp
parents:
diff changeset
397 #ifndef UNIX
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
398 # pragma romdata Buhlmann_tables = 0x1DD00 // Needs to be in UPPER bank.
0
heinrichsweikamp
parents:
diff changeset
399 #endif
heinrichsweikamp
parents:
diff changeset
400
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
401 rom const float Buhlmann_ab[4*16] = {
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
402 // Data ZH-L16C, from Bühlmann Tauchmedizin 2002, option 1a (4mn)
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
403 // a for N2 b for N2 a of He b for He
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
404 1.2599, 0.5050, 1.7424, 0.4245,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
405 1.0000, 0.6514, 1.3830, 0.5747,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
406 0.8618, 0.7222, 1.1919, 0.6527,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
407 0.7562, 0.7825, 1.0458, 0.7223,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
408 0.6200, 0.8126, 0.9220, 0.7582,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
409 0.5043, 0.8434, 0.8205, 0.7957,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
410 0.4410, 0.8693, 0.7305, 0.8279,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
411 0.4000, 0.8910, 0.6502, 0.8553,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
412 0.3750, 0.9092, 0.5950, 0.8757,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
413 0.3500, 0.9222, 0.5545, 0.8903,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
414 0.3295, 0.9319, 0.5333, 0.8997,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
415 0.3065, 0.9403, 0.5189, 0.9073,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
416 0.2835, 0.9477, 0.5181, 0.9122,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
417 0.2610, 0.9544, 0.5176, 0.9171,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
418 0.2480, 0.9602, 0.5172, 0.9217,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
419 0.2327, 0.9653, 0.5119, 0.9267
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
420 };
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
421
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
422 rom const float Buhlmann_ht[2*16] = {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
423 // Compartment half-life, in minute
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
424 //--- N2 ---- He ----------------------
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
425 4.0, 1.51,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
426 8.0, 3.02,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
427 12.5, 4.72,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
428 18.5, 6.99,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
429 27.0, 10.21,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
430 38.3, 14.48,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
431 54.3, 20.53,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
432 77.0, 29.11,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
433 109.0, 41.20,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
434 146.0, 55.19,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
435 187.0, 70.69,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
436 239.0, 90.34,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
437 305.0, 115.29,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
438 390.0, 147.42,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
439 498.0, 188.24,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
440 635.0, 240.03
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
441 };
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
442
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
443 rom const float e2secs[2*16] = {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
444 // result of 1 - 2^(-1/(2sec*HT))
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
445 //---- N2 ------------- He ------------
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
446 5.75958E-03, 1.51848E-02,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
447 2.88395E-03, 7.62144E-03,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
448 1.84669E-03, 4.88315E-03,
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
449 1.24813E-03, 3.29997E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
450 8.55371E-04, 2.26041E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
451 6.03079E-04, 1.59437E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
452 4.25414E-04, 1.12479E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
453 3.00019E-04, 7.93395E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
454 2.11949E-04, 5.60641E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
455 1.58240E-04, 4.18555E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
456 1.23548E-04, 3.26795E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
457 9.66686E-05, 2.55722E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
458 7.57509E-05, 2.00387E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
459 5.92416E-05, 1.56716E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
460 4.63943E-05, 1.22734E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
461 3.63850E-05, 9.62538E-05
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
462 //-------------------------------------
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
463 };
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
464
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
465 rom const float e1min[2*16] = {
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
466 // Integration constant for 1 minute,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
467 // Ie. 1- 2^(-1/HT)
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
468 //----- N2 --------- e 1min He --------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
469 1.59104E-01, 3.68109E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
470 8.29960E-02, 2.05084E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
471 5.39424E-02, 1.36579E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
472 3.67742E-02, 9.44046E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
473 2.53454E-02, 6.56359E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
474 1.79351E-02, 4.67416E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
475 1.26840E-02, 3.31991E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
476 8.96152E-03, 2.35301E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
477 6.33897E-03, 1.66832E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
478 4.73633E-03, 1.24808E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
479 3.69981E-03, 9.75753E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
480 2.89600E-03, 7.64329E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
481 2.27003E-03, 5.99417E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
482 1.77572E-03, 4.69082E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
483 1.39089E-03, 3.67548E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
484 1.09097E-03, 2.88359E-03
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
485 //-------------------------------------
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
486 };
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
487
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
488 rom const float e10min[2*16] = {
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
489 // The 10 min Value in float notation:
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
490 // result of 1 - 2^(-10/ht)
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
491 //---- N2 -------------- He -----------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
492 8.23223E-01, 9.89851E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
493 5.79552E-01, 8.99258E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
494 4.25651E-01, 7.69737E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
495 3.12487E-01, 6.29027E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
496 2.26416E-01, 4.92821E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
497 1.65547E-01, 3.80407E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
498 1.19840E-01, 2.86538E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
499 8.60863E-02, 2.11886E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
500 6.16117E-02, 1.54849E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
501 4.63665E-02, 1.18026E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
502 3.63881E-02, 9.34005E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
503 2.85855E-02, 7.38569E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
504 2.24698E-02, 5.83504E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
505 1.76160E-02, 4.59303E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
506 1.38222E-02, 3.61528E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
507 1.08563E-02, 2.84646E-02
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
508 //-------------------------------------
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
509 };
0
heinrichsweikamp
parents:
diff changeset
510
heinrichsweikamp
parents:
diff changeset
511 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
512 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
513 //////////////// THE SUBROUTINES ////////////////
0
heinrichsweikamp
parents:
diff changeset
514 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
515 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
516 //
heinrichsweikamp
parents:
diff changeset
517 // all new in v.102
heinrichsweikamp
parents:
diff changeset
518 // moved from 0x0D000 to 0x0C000 in v.108
heinrichsweikamp
parents:
diff changeset
519 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
520 # pragma code p2_deco = 0x0C000
heinrichsweikamp
parents:
diff changeset
521 #endif
heinrichsweikamp
parents:
diff changeset
522
heinrichsweikamp
parents:
diff changeset
523 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
524 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
525 //////////////// U T I L I T I E S ////////////////
0
heinrichsweikamp
parents:
diff changeset
526 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
527 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
528
heinrichsweikamp
parents:
diff changeset
529 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
530 // Bump to blue-screen when an assert is wrong
heinrichsweikamp
parents:
diff changeset
531 #ifdef __DEBUG
heinrichsweikamp
parents:
diff changeset
532 void assert_failed(PARAMETER short int line)
heinrichsweikamp
parents:
diff changeset
533 {
heinrichsweikamp
parents:
diff changeset
534 }
heinrichsweikamp
parents:
diff changeset
535 #endif
heinrichsweikamp
parents:
diff changeset
536
heinrichsweikamp
parents:
diff changeset
537 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
538 // When calling C code from ASM context, the data stack pointer and
heinrichsweikamp
parents:
diff changeset
539 // frames should be reset. Bank8 is used by stack
heinrichsweikamp
parents:
diff changeset
540
heinrichsweikamp
parents:
diff changeset
541 #ifdef CROSS_COMPILE
heinrichsweikamp
parents:
diff changeset
542 # define RESET_C_STACK
heinrichsweikamp
parents:
diff changeset
543 #else
heinrichsweikamp
parents:
diff changeset
544 # ifdef __DEBUG
heinrichsweikamp
parents:
diff changeset
545 # define RESET_C_STACK fillDataStack();
heinrichsweikamp
parents:
diff changeset
546 void fillDataStack(void)
heinrichsweikamp
parents:
diff changeset
547 {
heinrichsweikamp
parents:
diff changeset
548 _asm
heinrichsweikamp
parents:
diff changeset
549 LFSR 1,C_STACK
heinrichsweikamp
parents:
diff changeset
550 MOVLW 0xCC
heinrichsweikamp
parents:
diff changeset
551 loop: MOVWF POSTINC1,0
heinrichsweikamp
parents:
diff changeset
552 TSTFSZ FSR1L,0
heinrichsweikamp
parents:
diff changeset
553 BRA loop
heinrichsweikamp
parents:
diff changeset
554
heinrichsweikamp
parents:
diff changeset
555 LFSR 1,C_STACK
heinrichsweikamp
parents:
diff changeset
556 LFSR 2,C_STACK
heinrichsweikamp
parents:
diff changeset
557 _endasm
heinrichsweikamp
parents:
diff changeset
558 }
heinrichsweikamp
parents:
diff changeset
559 # else
heinrichsweikamp
parents:
diff changeset
560 # define RESET_C_STACK \
heinrichsweikamp
parents:
diff changeset
561 _asm \
heinrichsweikamp
parents:
diff changeset
562 LFSR 1, C_STACK \
heinrichsweikamp
parents:
diff changeset
563 LFSR 2, C_STACK \
heinrichsweikamp
parents:
diff changeset
564 _endasm
heinrichsweikamp
parents:
diff changeset
565 # endif
heinrichsweikamp
parents:
diff changeset
566 #endif
heinrichsweikamp
parents:
diff changeset
567
heinrichsweikamp
parents:
diff changeset
568 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
569 // Fast subroutine to read timer 5.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
570 // Note: result is in 1/32 of milliseconds (30,51757813 us/bit to be precise)
0
heinrichsweikamp
parents:
diff changeset
571 static unsigned short tmr5(void)
heinrichsweikamp
parents:
diff changeset
572 {
heinrichsweikamp
parents:
diff changeset
573 #ifndef CROSS_COMPILE
heinrichsweikamp
parents:
diff changeset
574 _asm
heinrichsweikamp
parents:
diff changeset
575 movff 0xf7c,PRODL // TMR5L
heinrichsweikamp
parents:
diff changeset
576 movff 0xf7d,PRODH // TMR5H
heinrichsweikamp
parents:
diff changeset
577 _endasm // result in PRODH:PRODL.
heinrichsweikamp
parents:
diff changeset
578 #else
heinrichsweikamp
parents:
diff changeset
579 return 0;
heinrichsweikamp
parents:
diff changeset
580 #endif
heinrichsweikamp
parents:
diff changeset
581 }
heinrichsweikamp
parents:
diff changeset
582
heinrichsweikamp
parents:
diff changeset
583 //////////////////////////////////////////////////////////////////////////////
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
584 // read Buhlmann tables A and B for compartment ci
0
heinrichsweikamp
parents:
diff changeset
585 //
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
586 static void read_Buhlmann_coefficients(void)
0
heinrichsweikamp
parents:
diff changeset
587 {
heinrichsweikamp
parents:
diff changeset
588 #ifndef CROSS_COMPILE
heinrichsweikamp
parents:
diff changeset
589 // Note: we don't use far rom pointer, because the
heinrichsweikamp
parents:
diff changeset
590 // 24 bits is too complex, hence we have to set
heinrichsweikamp
parents:
diff changeset
591 // the UPPER page ourself...
heinrichsweikamp
parents:
diff changeset
592 // --> Set zero if tables are moved to lower pages !
heinrichsweikamp
parents:
diff changeset
593 _asm
heinrichsweikamp
parents:
diff changeset
594 movlw 1
heinrichsweikamp
parents:
diff changeset
595 movwf TBLPTRU,0
heinrichsweikamp
parents:
diff changeset
596 _endasm
heinrichsweikamp
parents:
diff changeset
597 #endif
heinrichsweikamp
parents:
diff changeset
598
heinrichsweikamp
parents:
diff changeset
599 assert( ci < NUM_COMP );
heinrichsweikamp
parents:
diff changeset
600
heinrichsweikamp
parents:
diff changeset
601 // Use an interleaved array (AoS) to access coefficients with a
heinrichsweikamp
parents:
diff changeset
602 // single addressing.
heinrichsweikamp
parents:
diff changeset
603 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
604 overlay rom const float* ptr = &Buhlmann_ab[4*ci];
0
heinrichsweikamp
parents:
diff changeset
605 var_N2_a = *ptr++;
heinrichsweikamp
parents:
diff changeset
606 var_N2_b = *ptr++;
heinrichsweikamp
parents:
diff changeset
607 var_He_a = *ptr++;
heinrichsweikamp
parents:
diff changeset
608 var_He_b = *ptr++;
heinrichsweikamp
parents:
diff changeset
609 }
heinrichsweikamp
parents:
diff changeset
610 }
heinrichsweikamp
parents:
diff changeset
611
heinrichsweikamp
parents:
diff changeset
612 //////////////////////////////////////////////////////////////////////////////
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
613 // read Buhlmann tables for compartment ci
0
heinrichsweikamp
parents:
diff changeset
614 // If period == 0 : 2sec interval
heinrichsweikamp
parents:
diff changeset
615 // 1 : 1 min interval
heinrichsweikamp
parents:
diff changeset
616 // 2 : 10 min interval.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
617 static void read_Buhlmann_times(PARAMETER char period)
0
heinrichsweikamp
parents:
diff changeset
618 {
heinrichsweikamp
parents:
diff changeset
619 #ifndef CROSS_COMPILE
heinrichsweikamp
parents:
diff changeset
620 // Note: we don't use far rom pointer, because the
heinrichsweikamp
parents:
diff changeset
621 // 24 bits is to complex, hence we have to set
heinrichsweikamp
parents:
diff changeset
622 // the UPPER page ourself...
heinrichsweikamp
parents:
diff changeset
623 // --> Set zero if tables are moved to lower pages !
heinrichsweikamp
parents:
diff changeset
624 _asm
heinrichsweikamp
parents:
diff changeset
625 movlw 1
heinrichsweikamp
parents:
diff changeset
626 movwf TBLPTRU,0
heinrichsweikamp
parents:
diff changeset
627 _endasm
heinrichsweikamp
parents:
diff changeset
628 #endif
heinrichsweikamp
parents:
diff changeset
629
heinrichsweikamp
parents:
diff changeset
630 assert( ci < NUM_COMP );
heinrichsweikamp
parents:
diff changeset
631
heinrichsweikamp
parents:
diff changeset
632 // Integration intervals.
heinrichsweikamp
parents:
diff changeset
633 switch(period)
heinrichsweikamp
parents:
diff changeset
634 {
heinrichsweikamp
parents:
diff changeset
635 case 0: //---- 2 sec -----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
636 {
heinrichsweikamp
parents:
diff changeset
637 overlay rom const float* ptr = &e2secs[2*ci];
heinrichsweikamp
parents:
diff changeset
638 var_N2_e = *ptr++;
heinrichsweikamp
parents:
diff changeset
639 var_He_e = *ptr++;
heinrichsweikamp
parents:
diff changeset
640 }
heinrichsweikamp
parents:
diff changeset
641 break;
heinrichsweikamp
parents:
diff changeset
642
heinrichsweikamp
parents:
diff changeset
643 case 1: //---- 1 min -----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
644 {
heinrichsweikamp
parents:
diff changeset
645 overlay rom const float* ptr = &e1min[2*ci];
heinrichsweikamp
parents:
diff changeset
646 var_N2_e = *ptr++;
heinrichsweikamp
parents:
diff changeset
647 var_He_e = *ptr++;
heinrichsweikamp
parents:
diff changeset
648 }
heinrichsweikamp
parents:
diff changeset
649 break;
heinrichsweikamp
parents:
diff changeset
650
heinrichsweikamp
parents:
diff changeset
651 case 2: //---- 10 min ----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
652 {
heinrichsweikamp
parents:
diff changeset
653 overlay rom const float* ptr = &e10min[2*ci];
heinrichsweikamp
parents:
diff changeset
654 var_N2_e = *ptr++;
heinrichsweikamp
parents:
diff changeset
655 var_He_e = *ptr++;
heinrichsweikamp
parents:
diff changeset
656 }
heinrichsweikamp
parents:
diff changeset
657 break;
heinrichsweikamp
parents:
diff changeset
658
heinrichsweikamp
parents:
diff changeset
659 default:
heinrichsweikamp
parents:
diff changeset
660 assert(0); // Never go there...
heinrichsweikamp
parents:
diff changeset
661 }
heinrichsweikamp
parents:
diff changeset
662 }
heinrichsweikamp
parents:
diff changeset
663
heinrichsweikamp
parents:
diff changeset
664 //////////////////////////////////////////////////////////////////////////////
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
665 // read Buhlmann tables for compartment ci
0
heinrichsweikamp
parents:
diff changeset
666 //
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
667 static void read_Buhlmann_ht(void)
0
heinrichsweikamp
parents:
diff changeset
668 {
heinrichsweikamp
parents:
diff changeset
669
heinrichsweikamp
parents:
diff changeset
670 #ifndef CROSS_COMPILE
heinrichsweikamp
parents:
diff changeset
671 // Note: we don't use far rom pointer, because the
heinrichsweikamp
parents:
diff changeset
672 // 24 bits is to complex, hence we have to set
heinrichsweikamp
parents:
diff changeset
673 // the UPPER page ourself...
heinrichsweikamp
parents:
diff changeset
674 // --> Set zero if tables are moved to lower pages !
heinrichsweikamp
parents:
diff changeset
675 _asm
heinrichsweikamp
parents:
diff changeset
676 movlw 1
heinrichsweikamp
parents:
diff changeset
677 movwf TBLPTRU,0
heinrichsweikamp
parents:
diff changeset
678 _endasm
heinrichsweikamp
parents:
diff changeset
679 #endif
heinrichsweikamp
parents:
diff changeset
680
heinrichsweikamp
parents:
diff changeset
681 assert( ci < NUM_COMP );
heinrichsweikamp
parents:
diff changeset
682 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
683 overlay rom const float* ptr = &Buhlmann_ht[2*ci];
0
heinrichsweikamp
parents:
diff changeset
684 var_N2_ht = *ptr++;
heinrichsweikamp
parents:
diff changeset
685 var_He_ht = *ptr++;
heinrichsweikamp
parents:
diff changeset
686 }
heinrichsweikamp
parents:
diff changeset
687
heinrichsweikamp
parents:
diff changeset
688 assert( 4.0 <= var_N2_ht && var_N2_ht <= 635.0 );
heinrichsweikamp
parents:
diff changeset
689 assert( 1.5099 <= var_He_ht && var_He_ht <= 240.03 );
heinrichsweikamp
parents:
diff changeset
690 }
heinrichsweikamp
parents:
diff changeset
691
heinrichsweikamp
parents:
diff changeset
692 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
693 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
694 //////////////// THE JUMP-IN CODE for the asm code ////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
695 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
696 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
697
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
698 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
699 // deco_calc_hauptroutine
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
700 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
701 // called from: divemode.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
702 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
703 // Called every second during diving,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
704 // updates tissues on every second invocation.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
705 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
706 // Every few seconds (or slower when TTS > 16):
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
707 // - Updates deco table (char_O_deco_time/depth) with new values,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
708 // - updates ascent time, and
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
709 // - sets status to zero (so we can check there is new results).
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
710 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
711 void deco_calc_hauptroutine(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
712 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
713 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
714 calc_hauptroutine();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
715 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
716
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
717 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
718 // deco_clear_tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
719 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
720 // called from: start.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
721 // menu_tree.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
722 // simulator.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
723 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
724 // Sets all tissues to equilibrium with Air at ambient pressure,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
725 // resets all CNS values, any warnings and resets all model output.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
726 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
727 void deco_clear_tissue(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
728 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
729 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
730 clear_tissue();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
731 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
732
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
733 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
734 // deco_calc_dive_interval
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
735 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
736 // called from: simulator.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
737 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
738 // Updates tissues and CNS value for char_I_dive_interval minutes on Air
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
739 // at ambient pressure and calculates resulting GF factor and ceiling for
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
740 // a GF-high of 100% (ceiling and GF factor not used by simulator.asm)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
741 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
742 void deco_calc_dive_interval(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
743 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
744 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
745 calc_interval(char_I_dive_interval);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
746 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
747
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
748 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
749 // deco_calc_dive_interval_1min
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
750 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
751 // called from: start.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
752 // sleepmode.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
753 // surfmode.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
754 // menu_tree.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
755 // ghostwriter.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
756 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
757 // Updates tissues and CNS value for 1 minute on Air at ambient pressure and
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
758 // calculates resulting GF factor and ceiling for a GF-high of 100% (ceiling
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
759 // is not used by *.asm files).
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
760 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
761 void deco_calc_dive_interval_1min(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
762 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
763 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
764 calc_interval(1);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
765 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
766
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
767
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
768 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
769 // deco_calc_dive_interval_1min
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
770 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
771 // called from: sleepmode.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
772 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
773 // Updates tissues and CNS value for 10 minutes on Air at ambient pressure and
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
774 // calculates resulting GF factor and ceiling for a GF-high of 100% (ceiling
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
775 // is not used by sleepmode.asm).
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
776 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
777 void deco_calc_dive_interval_10min(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
778 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
779 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
780 calc_interval(10);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
781 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
782
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
783
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
784 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
785 // deco_calc_desaturation_time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
786 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
787 // called from: start.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
788 // surfmode.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
789 // menu_tree.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
790 // ghostwriter.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
791 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
792 // Computes desaturation and no-fly times.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
793 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
794 void deco_calc_desaturation_time(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
795 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
796 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
797 calc_desaturation_time();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
798 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
799
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
800 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
801 // deco_push_tissues_to_vault
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
802 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
803 // called from: simulator.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
804 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
805 // Makes a backup of the state of the real tissues and the deco engine.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
806 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
807 void deco_push_tissues_to_vault(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
808 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
809 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
810 push_tissues_to_vault();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
811 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
812
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
813 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
814 // deco_pull_tissues_from_vault
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
815 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
816 // called from: simulator.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
817 // ghostwriter.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
818 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
819 // Restores the state of the real tissues and the deco engine from the backup.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
820 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
821 void deco_pull_tissues_from_vault(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
822 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
823 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
824 pull_tissues_from_vault();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
825 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
826
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
827 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
828 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
829 //////////////// THE FUNCTIONS ////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
830 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
831 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
832
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
833
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
834 //////////////////////////////////////////////////////////////////////////////
0
heinrichsweikamp
parents:
diff changeset
835 // calc_nextdecodepth
heinrichsweikamp
parents:
diff changeset
836 //
heinrichsweikamp
parents:
diff changeset
837 // new in v.102
heinrichsweikamp
parents:
diff changeset
838 //
heinrichsweikamp
parents:
diff changeset
839 // INPUT, changing during dive:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
840 // sim_pres_respiration : current depth in absolute pressure
0
heinrichsweikamp
parents:
diff changeset
841 //
heinrichsweikamp
parents:
diff changeset
842 // INPUT, fixed during dive:
heinrichsweikamp
parents:
diff changeset
843 // pres_surface
heinrichsweikamp
parents:
diff changeset
844 // GF_delta
heinrichsweikamp
parents:
diff changeset
845 // GF_high
heinrichsweikamp
parents:
diff changeset
846 // GF_low
heinrichsweikamp
parents:
diff changeset
847 // char_I_depth_last_deco
heinrichsweikamp
parents:
diff changeset
848 //
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
849 // MODIFIED
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
850 // locked_GF_step_norm/_alt : used for GF model
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
851 // low_depth_norm/_alt : used for GF model
0
heinrichsweikamp
parents:
diff changeset
852 //
heinrichsweikamp
parents:
diff changeset
853 // OUTPUT
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
854 // sim_depth_limit : depth of next stop in meters (if RETURN == true )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
855 // depth we can ascent to without stop (if RETURN == false)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
856 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
857 // RETURN TRUE if a stop is needed.
0
heinrichsweikamp
parents:
diff changeset
858 //
heinrichsweikamp
parents:
diff changeset
859 static unsigned char calc_nextdecodepth(void)
heinrichsweikamp
parents:
diff changeset
860 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
861 overlay unsigned char need_stop;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
862
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
863 // compute current depth in meters
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
864 overlay float depth = (sim_pres_respiration - pres_surface) * BAR_TO_METER;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
865
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
866 // compute depth in meters after 1 minute of ascent at float_ascent_speed (5..10 m/min)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
867 overlay float min_depth = (depth > float_ascent_speed) ? (depth - float_ascent_speed) : 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
868
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
869
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
870 // allow for 200mbar of weather dependent surface pressure change
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
871 assert( depth >= -0.2 );
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
872
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
873
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
874 //---- check if a stop is needed for deco reasons ----------------------------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
875
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
876 // switch on deco model
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
877 if( char_I_deco_model != 0 )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
878 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
879 //---- ZH-L16 + GRADIENT FACTOR Model ------------------------------------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
880
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
881 overlay float locked_GF_step;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
882 overlay float low_depth;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
883 overlay float limit_depth;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
884
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
885 overlay unsigned char first_stop = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
886
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
887
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
888 // calculate minimum depth we can ascent to in bar relative pressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
889 calc_limit(GF_low);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
890
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
891 // check if we can surface directly
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
892 if( sim_ceiling <= 0.0 )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
893 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
894 min_depth = 0.0; // set minimum depth to 0 meters = surface
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
895 goto no_deco_stop; // done.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
896 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
897
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
898 // convert minimum depth we can ascent to from relative pressure to depth in meters
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
899 limit_depth = sim_ceiling * BAR_TO_METER;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
900
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
901 // recall low_depth dependent on current plan
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
902 low_depth = (char_O_deco_status & DECO_PLAN_ALTERNATE) ? low_depth_alt : low_depth_norm;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
903
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
904 // Store the deepest point needing a deco stop as the LOW reference for GF.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
905 // NOTE: following stops will be validated using this LOW-HIGH GF scale,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
906 // so if we want to keep coherency, we should not validate this stop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
907 // yet, but apply the search to it, as for all the following stops afterward.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
908 if( limit_depth > low_depth )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
909 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
910 // update GF parameters
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
911 low_depth = limit_depth;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
912 locked_GF_step = GF_delta / low_depth;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
913
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
914 // store updated GF parameters dependent on current plan
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
915 if( char_O_deco_status & DECO_PLAN_ALTERNATE )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
916 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
917 low_depth_alt = low_depth;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
918 locked_GF_step_alt = locked_GF_step;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
919 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
920 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
921 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
922 low_depth_norm = low_depth;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
923 locked_GF_step_norm = locked_GF_step;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
924 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
925 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
926 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
927 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
928 // recall locked_GF_step dependent on current plan
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
929 locked_GF_step = (char_O_deco_status & DECO_PLAN_ALTERNATE) ? locked_GF_step_alt : locked_GF_step_norm;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
930 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
931
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
932 // invalidate this stop if we can ascent for 1 minute without going above minimum required deco depth
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
933 if( limit_depth < min_depth ) goto no_deco_stop;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
934
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
935
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
936 // if program execution passes here, we need a deco stop
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
937
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
938 // Round to multiple of 3 meters
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
939 first_stop = 3 * (unsigned char)(0.9995 + limit_depth * 0.333333);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
940
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
941 // check a constraint
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
942 assert( first_stop < 128 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
943
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
944 // apply correction for the shallowest stop, use char_I_depth_last_deco (3..6 m) instead
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
945 if( first_stop == 3 ) first_stop = char_I_depth_last_deco;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
946
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
947 // We have a stop candidate.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
948 // But maybe ascending to the next stop will diminish the constraint,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
949 // because the GF might decrease more than the pressure gradient...
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
950 while(first_stop > 0)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
951 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
952 // Next depth
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
953 overlay unsigned char next_stop;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
954
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
955 // invalidate this stop if we can ascent one more minute without going above minimum required deco depth
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
956 if( first_stop <= (unsigned char)min_depth ) goto no_deco_stop;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
957
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
958 // compute depth of next stop
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
959 if ( first_stop <= char_I_depth_last_deco ) next_stop = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
960 else if ( first_stop == 6 ) next_stop = char_I_depth_last_deco;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
961 else next_stop = first_stop - 3;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
962
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
963 // compute limit with the GF of the new stop candidate
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
964 if( (low_depth == 0.0) || (next_stop > low_depth) ) calc_limit(GF_low);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
965 else calc_limit(GF_high - next_stop * locked_GF_step);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
966
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
967 // check if ascent to the next stop candidate is possible
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
968 if( sim_ceiling * BAR_TO_METER >= next_stop ) goto deco_stop_found; // no - ascent to next_stop forbidden
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
969
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
970 // else, validate that stop and loop...
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
971 first_stop = next_stop;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
972 }
0
heinrichsweikamp
parents:
diff changeset
973
heinrichsweikamp
parents:
diff changeset
974 no_deco_stop:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
975 need_stop = 0; // set flag for stop needed to 'no'
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
976 sim_depth_limit = (unsigned char)min_depth; // report depth we can ascent to without stop
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
977 goto done;
0
heinrichsweikamp
parents:
diff changeset
978
342
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
979 deco_stop_found:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
980 need_stop = 1; // set flag for stop needed to 'yes'
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
981 sim_depth_limit = (unsigned char)first_stop; // stop depth, in meters
0
heinrichsweikamp
parents:
diff changeset
982
heinrichsweikamp
parents:
diff changeset
983 done:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
984 ;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
985 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
986 else
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
987 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
988 //---- ZH-L16 model -------------------------------------------------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
989
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
990 overlay float limit_depth;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
991
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
992
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
993 // calculate minimum depth we can ascent to in bar relative pressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
994 calc_limit(1.0);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
995
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
996 // check if we can surface directly
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
997 if (sim_ceiling >= 0)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
998 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
999 // no - set flag for stop needed to 'yes'
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1000 need_stop = 1;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1001
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1002 // convert stop depth in relative pressure to stop index
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1003 limit_depth = sim_ceiling * BAR_TO_METER / 3;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1004
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1005 // convert stop index to depth in meters, rounded to multiple of 3 meters
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1006 sim_depth_limit = 3 * (short)(limit_depth + 0.99);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1007
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1008 // correct last stop to 4m/5m/6m
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1009 if( sim_depth_limit == 3 ) sim_depth_limit = char_I_depth_last_deco;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1010 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1011 else
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1012 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1013 // yes - set flag for stop needed to 'no'
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1014 need_stop = 0;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1015
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1016 // set depth we can ascent to as 0 = surface
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1017 sim_depth_limit = 0;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1018 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1019 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1020
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1021 // After the first deco stop, gas changes are only done at deco stops now!
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1022
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1023 // check if a stop is found and there is a better gas to switch to
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1024 if( need_stop && gas_find_better() )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1025 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1026 // set the new calculation ratios for N2, He and O2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1027 gas_set_ratios();
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1028
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1029 // prime the deco stop with the gas change time
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1030 update_deco_table(char_I_gas_change_time);
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1031 }
0
heinrichsweikamp
parents:
diff changeset
1032
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1033 return need_stop;
0
heinrichsweikamp
parents:
diff changeset
1034 }
heinrichsweikamp
parents:
diff changeset
1035
heinrichsweikamp
parents:
diff changeset
1036 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1037 // publish_deco_table
0
heinrichsweikamp
parents:
diff changeset
1038 //
heinrichsweikamp
parents:
diff changeset
1039 // Buffer the stops, once computed, so we can continue to display them
heinrichsweikamp
parents:
diff changeset
1040 // while computing the next set.
heinrichsweikamp
parents:
diff changeset
1041 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1042 static void publish_deco_table(void)
0
heinrichsweikamp
parents:
diff changeset
1043 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1044 overlay unsigned char x, y;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1045
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1046
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1047 // Copy depth of the first (deepest) stop, because when reversing
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1048 // order, it will be hard to find...
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1049 char_O_first_deco_depth = internal_deco_depth[0];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1050 char_O_first_deco_time = internal_deco_time [0];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1051
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1052 for(x=0; x<NUM_STOPS; x++)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1053 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1054 char_O_deco_depth[x] = internal_deco_depth[x];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1055 char_O_deco_time [x] = internal_deco_time [x];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1056 char_O_deco_gas [x] = internal_deco_gas [x];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1057 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1058
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1059 //Now fill the char_O_deco_time_for_log array
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1060 //---- First: search the first non-null depth
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1061 for(x=(NUM_STOPS-1); x != 0; --x)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1062 if( internal_deco_depth[x] != 0 ) break;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1063
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1064 //---- Second: copy to output table (in reverse order)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1065 for(y=0; y<NUM_STOPS; y++, --x)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1066 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1067 char_O_deco_time_for_log[y] = internal_deco_time [x];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1068
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1069 // Stop only once the last transfer is done.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1070 if( x == 0 ) break;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1071 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1072
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1073 //---- Third: fill table with null until end
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1074 for(y++; y<NUM_STOPS; y++)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1075 char_O_deco_time_for_log[y] = 0;
0
heinrichsweikamp
parents:
diff changeset
1076 }
heinrichsweikamp
parents:
diff changeset
1077
heinrichsweikamp
parents:
diff changeset
1078 //////////////////////////////////////////////////////////////////////////////
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1079 // temp_tissue_safety
0
heinrichsweikamp
parents:
diff changeset
1080 //
heinrichsweikamp
parents:
diff changeset
1081 // outsourced in v.102
heinrichsweikamp
parents:
diff changeset
1082 //
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
1083 // Apply safety factors for both ZH-L16 models.
0
heinrichsweikamp
parents:
diff changeset
1084 //
heinrichsweikamp
parents:
diff changeset
1085 static void temp_tissue_safety(void)
heinrichsweikamp
parents:
diff changeset
1086 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1087 assert( 0.0 < float_desaturation_multiplier && float_desaturation_multiplier <= 1.0 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1088 assert( 1.0 <= float_saturation_multiplier && float_saturation_multiplier <= 2.0 );
0
heinrichsweikamp
parents:
diff changeset
1089
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1090 if( temp_tissue < 0.0 ) temp_tissue *= float_desaturation_multiplier;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1091 else temp_tissue *= float_saturation_multiplier;
0
heinrichsweikamp
parents:
diff changeset
1092 }
heinrichsweikamp
parents:
diff changeset
1093
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1094
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1095
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1096 //////////////////////////////////////////////////////////////////////////////
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1097 // Find current gas in the list (if any) and get its change depth
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1098 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1099 // Input: char_I_current_gas : 1..5 or 6
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1100 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1101 // Output: sim_gas_last_used : 1..6 or 0 if it is the gas set as FIRST
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1102 // sim_gas_last_depth : change depth in meters or 0 if it is the gas set as FIRST
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1103 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1104 static void gas_find_current(void)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1105 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1106 assert( 1 <= char_I_current_gas && char_I_current_gas <= 6 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1107
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1108 if( char_I_current_gas <= NUM_GAS ) // Gas 1-5
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1109 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1110 sim_gas_last_used = sim_gas_first_used = char_I_current_gas;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1111
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1112 // If current gas is a deco gas get it's change depth.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1113 // Set change depth to 0 if the current gas is the first gas or
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1114 // a travel/normal gas, i.e. if it can be breathed at "any" depth.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1115 if( char_I_deco_gas_change[sim_gas_last_used-1] ) sim_gas_last_depth = char_I_deco_gas_change[sim_gas_last_used-1];
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1116 else sim_gas_last_depth = 0;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1117 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1118 else
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1119 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1120 sim_gas_last_used = sim_gas_first_used = 0; // Gas 6 (the manually set one) has number 0 here
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1121 sim_gas_last_depth = 0; // handle it as a travel/normal gas
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1122 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1123 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1124
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1125
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1126 //////////////////////////////////////////////////////////////////////////////
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1127 // Find the deco gas with the shallowest change depth beyond current depth
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1128 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1129 // INPUT sim_depth_limit : current depth in meters
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1130 // char_I_deco_gas_change[] : change depths of the deco gases
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1131 // sim_gas_last_depth : change depth of the currently used gas, 0 if on the gas set as FIRST
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1132 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1133 // OUTPUT sim_gas_last_depth : switch depth - only if return value is true
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1134 // sim_gas_last_used : index of the gas (1..5) - only if return value is true
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1135 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1136 // RETURNS TRUE if a better gas is available
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1137 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1138 static unsigned char gas_find_better(void)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1139 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1140 overlay unsigned char switch_depth = 255;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1141 overlay unsigned char switch_gas = 0;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1142 overlay unsigned char j;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1143
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1144
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1145 // no automatic gas changes in CCR mode and - as of now - in pSCR mode
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1146 if( char_O_deco_status & DECO_MODE_LOOP ) return 0;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1147
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1148 // Loop over all deco gases to find the shallowest one below or at current depth.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1149 for(j=0; j<NUM_GAS; ++j)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1150 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1151 // Is this the gas we are already breathing?
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1152 // If yes, skip this gas.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1153 if( j+1 == sim_gas_last_used ) continue;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1154
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1155 // Is the change depth of the gas shallower than the current depth?
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1156 // If yes, skip this gas as it is not to be used yet.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1157 // Remark: this check will also skip all disabled gases and the gas set
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1158 // as 'first' because these have their change depth set to 0.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1159 if( sim_depth_limit > char_I_deco_gas_change[j] ) continue;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1160
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1161 // Is the change depth of the gas deeper than the change depth of the
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1162 // gas we are currently one?
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1163 // If yes, skip this gas as it is not better than the current one.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1164 // Remark: if there is more than one gas with the same change depth,
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1165 // the last one from the list will be taken.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1166 if( sim_gas_last_depth && (char_I_deco_gas_change[j] > sim_gas_last_depth) ) continue;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1167
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1168 // Is the change depth of the gas shallower or equal to the change depth
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1169 // of the best gas found so far, or is it the first better gas found?
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1170 // If yes, we have a better gas
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1171 if( char_I_deco_gas_change[j] <= switch_depth )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1172 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1173 switch_gas = j+1; // remember this gas (1..5)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1174 switch_depth = char_I_deco_gas_change[j]; // remember its change depth
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1175 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1176 } // continue looping through all gases to eventually find an even better gas
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1177
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1178 // has a better gas been found?
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1179 if( switch_gas )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1180 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1181 // yes
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1182 sim_gas_last_used = switch_gas; // report the index of the better
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1183 sim_gas_last_depth = switch_depth; // report its change depth
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1184
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1185 assert( sim_gas_last_depth < switch_depth );
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1186
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1187 return 1; // signal a better gas was found
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1188 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1189 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1190 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1191 return 0; // signal no better gas was found
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1192 }
0
heinrichsweikamp
parents:
diff changeset
1193 }
heinrichsweikamp
parents:
diff changeset
1194
heinrichsweikamp
parents:
diff changeset
1195 //////////////////////////////////////////////////////////////////////////////
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1196 // Set calc_N2/He/O2_ratios by sim_gas_last_used
0
heinrichsweikamp
parents:
diff changeset
1197 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1198 // Input: sim_gas_last_used : index of gas to use
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1199 // N2_ratio, He_ratio : if gas = 0 (the manually set gas)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1200 // char_I_deco_O2/He_ratio[] : if gas = 1..5 (the configured gases)
0
heinrichsweikamp
parents:
diff changeset
1201 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1202 // Output: sim_N2_ratio, sim_He_ratio : ratios of the inert gases
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1203 // sim_pSCR_drop : ppO2 drop in pSCR loop
0
heinrichsweikamp
parents:
diff changeset
1204 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1205 static void gas_set_ratios(void)
0
heinrichsweikamp
parents:
diff changeset
1206 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1207 overlay float sim_IG_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1208
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1209 assert( 0 <= sim_gas_last_used <= NUM_GAS );
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1210
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1211
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1212 // get gas ratios
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1213 if( sim_gas_last_used == 0 )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1214 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1215 sim_O2_ratio = O2_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1216 sim_He_ratio = He_ratio;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1217 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1218 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1219 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1220 sim_O2_ratio = 0.01 * char_I_deco_O2_ratio[sim_gas_last_used-1];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1221 sim_He_ratio = 0.01 * char_I_deco_He_ratio[sim_gas_last_used-1];
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1222 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1223
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1224 // inert gas ratio (local helper variable)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1225 sim_IG_ratio = 1.00 - sim_O2_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1226
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1227 // N2 ratio
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1228 sim_N2_ratio = sim_IG_ratio - sim_He_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1229
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1230 // ppO2 drop in pSCR loop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1231 sim_pSCR_drop = sim_IG_ratio * float_pSCR_factor;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1232
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1233
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1234 assert( 0.0 <= sim_N2_ratio && sim_N2_ratio <= 0.95 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1235 assert( 0.0 <= sim_He_ratio && sim_He_ratio <= 0.95 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1236 assert( (sim_N2_ratio + sim_He_ratio) <= 0.95 );
0
heinrichsweikamp
parents:
diff changeset
1237 }
heinrichsweikamp
parents:
diff changeset
1238
heinrichsweikamp
parents:
diff changeset
1239 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1240 // Compute respired ppN2 and ppHe
0
heinrichsweikamp
parents:
diff changeset
1241 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1242 // Input: tissue_increment : selector for targeting simulated or real tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1243 // char_O_main_status : breathing mode for real tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1244 // char_O_deco_status : breathing mode for simulated tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1245 // (sim_)O2_ratio : (simulated) O2 ratio breathed
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1246 // (sim_)N2_ratio : (simulated) N2 ratio breathed
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1247 // (sim_)He_ratio : (simulated) He ratio breathed
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1248 // (sim_)pres_respiration : (simulated) respiration pressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1249 // char_I_const_ppO2 : ppO2 reported from sensors or setpoint
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1250 // char_I_PSCR_drop : pSCR parameter
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1251 // char_I_PSCR_lungratio : pSCR parameter
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1252 // pres_surface : surface pressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1253 // float_deco_distance : safety factor
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1254 // ppWater : water-vapor pressure inside respiratory tract
0
heinrichsweikamp
parents:
diff changeset
1255 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1256 // Output: ppN2 : respired N2 partial pressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1257 // ppHe : respired He partial pressure
0
heinrichsweikamp
parents:
diff changeset
1258 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1259 void calc_alveolar_pressures(void)
0
heinrichsweikamp
parents:
diff changeset
1260 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1261 overlay float pres_diluent;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1262 overlay float calc_O2_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1263 overlay float calc_N2_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1264 overlay float calc_He_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1265 overlay float calc_pSCR_drop;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1266
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1267 overlay unsigned char status;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1268
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1269
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1270 assert( 0.00 <= N2_ratio && N2_ratio <= 1.00 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1271 assert( 0.00 <= He_ratio && He_ratio <= 1.00 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1272 assert( (N2_ratio + He_ratio) <= 1.00 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1273 assert( 0.800 < pres_respiration && pres_respiration < 14.0 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1274
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1275 assert( 0.00 <= sim_N2_ratio && N2_ratio <= 1.00 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1276 assert( 0.00 <= sim_He_ratio && He_ratio <= 1.00 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1277 assert( (sim_N2_ratio + sim_He_ratio) <= 1.00 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1278 assert( 0.800 < sim_pres_respiration && sim_pres_respiration < 14.0 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1279
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1280
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1281 // get input data according to context
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1282 if( tissue_increment & TISSUE_FLAG )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1283 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1284 //---- real tissues -----------------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1285 status = char_O_main_status;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1286 pres_diluent = pres_respiration;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1287 calc_pSCR_drop = pSCR_drop;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1288
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1289 calc_O2_ratio = O2_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1290 calc_N2_ratio = N2_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1291 calc_He_ratio = He_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1292 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1293 else
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1294 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1295 //---- simulated tissues ------------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1296 status = char_O_deco_status;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1297 pres_diluent = sim_pres_respiration;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1298 calc_pSCR_drop = sim_pSCR_drop;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1299
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1300 calc_O2_ratio = sim_O2_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1301 calc_N2_ratio = sim_N2_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1302 calc_He_ratio = sim_He_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1303
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1304 // take deco offset into account, but not at surface
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1305 if( pres_diluent > pres_surface ) pres_diluent += float_deco_distance;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1306 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1307
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1308 //---- OC, CCR and Bailout Mode Gas Calculations -----------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1309
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1310 // calculate ppO2 of pure oxygen
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1311 O2_ppO2 = (pres_diluent - ppWater);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1312
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1313 // capture failure condition in case pres_respiration is < ppWater (should never happen...)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1314 if( O2_ppO2 < 0.0 ) O2_ppO2 = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1315
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1316 // calculate ppO2 of the pure gas (diluent)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1317 OC_ppO2 = O2_ppO2 * calc_O2_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1318
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1319 // calculate pSCR ppO2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1320 pSCR_ppO2 = OC_ppO2 - calc_pSCR_drop;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1321
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1322 // capture failure condition in case pSCR_ppO2 becomes negative
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1323 if( pSCR_ppO2 < 0.0 ) pSCR_ppO2 = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1324
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1325
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1326 //---- Loop modes : adjust ppN2 and ppHe for change in ppO2 due to setpoint (CCR) or drop (pSCR) ---
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1327 if( status & DECO_MODE_LOOP )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1328 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1329 overlay float const_ppO2;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1330
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1331 // get the current sensor reading (CCR / pSCR if fitted) or the fixed setpoint (CCR) / a zero (pSCR)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1332 const_ppO2 = 0.01 * char_I_const_ppO2;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1333
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1334 // Limit the setpoint to the maximum physically possible ppO2. This prevents for
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1335 // example calculating with a setpoint of 1.3 bar in only 2 meters of depth.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1336 // Additionally, if limiting occurs, the ppO2 can be further reduced to account
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1337 // for residual inert gases by the user-adjustable setting char_I_cc_max_frac_o2.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1338
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1339 if( const_ppO2 > pres_diluent ) // no ppWater subtracted here to give some margin for
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1340 { // sensors delivering data a little bit over target
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1341 const_ppO2 = 0.01 * char_I_cc_max_frac_o2 * (pres_diluent - ppWater);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1342 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1343
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1344 // check which kind of loop we are on
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1345 if( status & DECO_MODE_PSCR )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1346 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1347 //---- pSCR Mode --------------------------------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1348
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1349 // Use the sensor value if available, but only in real tissue context!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1350 // In all other cases use calculated ppO2.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1351 if( char_I_const_ppO2 && (tissue_increment & TISSUE_FLAG)) ppO2 = const_ppO2;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1352 else ppO2 = pSCR_ppO2;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1353 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1354 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1355 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1356 //---- CCR Mode ---------------------------------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1357
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1358 // derive breathed ppO2 from (char_I_)const_ppO2,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1359 // which holds sensor reading or fixed setpoint
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1360 ppO2 = const_ppO2;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1361 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1362
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1363 // adjust diluent pressure (ppN2 + ppHe) for change
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1364 // in ppO2 due to setpoint (CCR) or drop (pSCR)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1365 pres_diluent -= const_ppO2;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1366 pres_diluent /= calc_N2_ratio + calc_He_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1367
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1368 // capture all failure conditions, including div/0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1369 // in case diluent is pure O2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1370 if( (pres_diluent < 0.0) || (calc_O2_ratio > 99.5) )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1371 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1372 pres_diluent = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1373 ppO2 = OC_ppO2;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1374 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1375 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1376 else
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1377 { //---- OC mode ---------------------------------------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1378
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1379 // breathed ppO2 is ppO2 of pure gas
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1380 ppO2 = OC_ppO2;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1381 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1382
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1383
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1384 // derive char_ppO2 in [cbar], used for calculating CNS%
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1385 if ( ppO2 < 0.01 ) char_ppO2 = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1386 else if ( ppO2 >= 2.545 ) char_ppO2 = 255;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1387 else char_ppO2 = (unsigned char)(100 * ppO2 + 0.5);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1388
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1389
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1390 //---- calculate ppN2 and ppHe ---------------------------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1391
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1392 if( pres_diluent > ppWater )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1393 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1394 ppN2 = calc_N2_ratio * (pres_diluent - ppWater);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1395 ppHe = calc_He_ratio * (pres_diluent - ppWater);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1396 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1397 else
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1398 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1399 ppN2 = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1400 ppHe = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1401 }
0
heinrichsweikamp
parents:
diff changeset
1402 }
heinrichsweikamp
parents:
diff changeset
1403
heinrichsweikamp
parents:
diff changeset
1404 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1405 // clear_tissue
heinrichsweikamp
parents:
diff changeset
1406 //
heinrichsweikamp
parents:
diff changeset
1407 // optimized in v.101 (var_N2_a)
heinrichsweikamp
parents:
diff changeset
1408 //
heinrichsweikamp
parents:
diff changeset
1409 // preload tissues with standard pressure for the given ambient pressure.
heinrichsweikamp
parents:
diff changeset
1410 //
heinrichsweikamp
parents:
diff changeset
1411 static void clear_tissue(void)
heinrichsweikamp
parents:
diff changeset
1412 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1413 pres_respiration = 0.001 * int_I_pres_respiration;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1414 N2_equilibrium = 0.7902 * (pres_respiration - ppWater);
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1415
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1416 for(ci=0; ci<NUM_COMP; ci++)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1417 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1418 // cycle through the 16 Buhlmann N2 tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1419 pres_tissue_N2[ci] = N2_equilibrium; // initialize data for "real" tissue
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1420 char_O_tissue_N2_saturation[ci] = 11; // initialize data for tissue graphics
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1421
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1422 // cycle through the 16 Buhlmann He tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1423 pres_tissue_He[ci] = 0.0; // initialize data for "real" tissue
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1424 char_O_tissue_He_saturation[ci] = 0; // initialize data for tissue graphics
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1425 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1426
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1427 // reset CNS values
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1428 CNS_fraction = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1429 int_O_CNS_fraction = int_O_normal_CNS_fraction = int_O_alternate_CNS_fraction = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1430
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1431
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1432 // reset any warnings
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1433 char_O_deco_warnings = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1434
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1435 // reset some more vars to their defaults
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1436 char_O_nullzeit = 240;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1437 int_O_ascenttime = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1438 int_O_alternate_ascenttime = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1439 int_O_gradient_factor = 0;
0
heinrichsweikamp
parents:
diff changeset
1440 }
heinrichsweikamp
parents:
diff changeset
1441
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1442
0
heinrichsweikamp
parents:
diff changeset
1443 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1444 // calc_hauptroutine
heinrichsweikamp
parents:
diff changeset
1445 //
heinrichsweikamp
parents:
diff changeset
1446 // this is the major code in dive mode calculates:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1447 // the tissues,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1448 // the bottom time,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1449 // and simulates the ascend with all deco stops.
0
heinrichsweikamp
parents:
diff changeset
1450 //
heinrichsweikamp
parents:
diff changeset
1451 static void calc_hauptroutine(void)
heinrichsweikamp
parents:
diff changeset
1452 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1453 overlay unsigned int int_ppO2_min;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1454 overlay unsigned int int_ppO2_max;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1455 overlay unsigned int int_ppO2_max_dil;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1456
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1457 //--- set-up part --------------------------------------------------------------------------------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1458
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1459 // twosectimer:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1460 // calc_hauptroutine is now invoked every second to speed up the deco planning.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1461 // Because the tissue and CNS calculations are based on a 2 seconds period, the
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1462 // the following toggle-timer will be used by the respective routines to skip
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1463 // every 2nd invocation.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1464 twosectimer = (twosectimer) ? 0 : 1; // toggle the toggle-timer
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1465
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1466
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1467 // set up normal tissue updating or "fast forward" updating for simulator sim+5' function
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1468 // and deco calculator bottom time calculation
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1469 if( char_I_sim_advance_time > 0 )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1470 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1471 // configure char_I_sim_advance_time minutes of tissue updating
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1472 tissue_increment = char_I_sim_advance_time // given number of minutes, limited to 127
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1473 | TISSUE_FLAG; // set flag for updating the "real" tissues & CNS
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1474
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1475 char_I_sim_advance_time = 0; // clear "mailbox"
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1476 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1477 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1478 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1479 // configure 2 seconds of tissue updating
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1480 tissue_increment = 0 // encoding for 2 seconds update
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1481 | TISSUE_FLAG; // set flag for updating the "real" tissues & CNS
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1482 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1483
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1484
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1485 //---- calculate the real tissue's data -----------------------------------------------------------------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1486
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1487 // acquire current environment data
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1488 calc_hauptroutine_data_input();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1489
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1490 // update tissue pressures, also sets char_ppO2 for calc_CNS_increment()
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1491 calc_hauptroutine_update_tissues();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1492
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1493 // calculate CNS value increment for the real tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1494 calc_CNS_increment();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1495
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1496 // update the CNS value for the real tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1497 CNS_fraction += CNS_fraction_inc;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1498
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1499 // compute integer copy of CNS value for display purpose
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1500 convert_CNS_for_display();
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1501
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1502
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1503 //---- compute ppO2 warnings ------------------------------------------------------------------------------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1504
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1505 // compute conditional min/max values
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1506 int_ppO2_min = (char_O_main_status & DECO_MODE_LOOP) ? (unsigned int)char_I_ppO2_min_loop : (unsigned int)char_I_ppO2_min;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1507 int_ppO2_max = (char_O_deco_warnings & DECO_FLAG ) ? (unsigned int)char_I_ppO2_max_deco : (unsigned int)char_I_ppO2_max;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1508
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1509 // default value for the upper diluent ppO2 warning threshold is the normal upper warning threshold
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1510 int_ppO2_max_dil = int_ppO2_max;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1511
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1512 // when in CCR mode, the upper diluent warning threshold gets adjust according to the current setpoint
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1513 if( (char_O_main_status & DECO_MODE_MASK) == DECO_MODE_CCR )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1514 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1515 overlay unsigned int max_dil;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1516
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1517 // The upper diluent ppO2 threshold is ppO2_GAP_TO_SETPOINT below the setpoint...
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1518 // (the condition protects from negative numbers which would cause a wrap-around)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1519 max_dil = (char_I_const_ppO2 > ppO2_GAP_TO_SETPOINT) ? (unsigned int)(char_I_const_ppO2 - ppO2_GAP_TO_SETPOINT) : 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1520
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1521 // ...but never above int_ppO2_max.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1522 if( max_dil < int_ppO2_max ) int_ppO2_max_dil = max_dil;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1523
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1524 // We do not need to guard int_ppO2_max_dil against becoming lower than char_I_ppO2_min because the check
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1525 // against char_I_ppO2_min is done first and will then raise a low warning and inhibit further checks.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1526 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1527
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1528 // check for safe range of pure oxygen
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1529 if ( int_O_O2_ppO2 >= int_ppO2_max ) int_O_O2_ppO2 |= INT_FLAG_WARNING + INT_FLAG_HIGH;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1530
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1531 // check for safe range of breathed gas
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1532 if ( int_O_breathed_ppO2 <= int_ppO2_min ) int_O_breathed_ppO2 |= INT_FLAG_WARNING + INT_FLAG_LOW;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1533 else if ( int_O_breathed_ppO2 >= int_ppO2_max ) int_O_breathed_ppO2 |= INT_FLAG_WARNING + INT_FLAG_HIGH;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1534 else if ( char_O_main_status & DECO_MODE_LOOP ) ; // no attention generated in loop modes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1535 else if ( int_O_breathed_ppO2 >= ppO2_ATTENTION_THRESHOLD ) int_O_breathed_ppO2 |= INT_FLAG_ATTENTION;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1536
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1537 // check for safe range of pure diluent
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1538 if ( int_O_pure_ppO2 <= (unsigned int)char_I_ppO2_min ) int_O_pure_ppO2 |= INT_FLAG_WARNING + INT_FLAG_LOW;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1539 else if ( int_O_pure_ppO2 >= int_ppO2_max ) int_O_pure_ppO2 |= INT_FLAG_WARNING + INT_FLAG_HIGH;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1540 else if ( int_O_pure_ppO2 >= int_ppO2_max_dil ) int_O_pure_ppO2 |= INT_FLAG_ATTENTION;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1541
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1542 // check for safe range of calculated pSCR loop gas
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1543 if ( int_O_pSCR_ppO2 <= int_ppO2_min ) int_O_pSCR_ppO2 |= INT_FLAG_WARNING + INT_FLAG_LOW;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1544 else if ( int_O_pSCR_ppO2 >= int_ppO2_max ) int_O_pSCR_ppO2 |= INT_FLAG_WARNING + INT_FLAG_HIGH;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1545
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1546
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1547
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1548 //---- toggle between calculation for NDL (bottom time), ------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1549 //---- deco stops and more deco stops (continue) ------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1550
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1551
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1552 // done with the real tissues, all following operations
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1553 // target the simulated tissues so clear flag in bit 7
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1554 tissue_increment = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1555
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1556 // branch to the code for the current phase the deco calculations are in
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1557 switch( char_O_deco_status & DECO_STATUS_MASK )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1558 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1559 overlay unsigned char i;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1560
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1561 case DECO_STATUS_INIT: //---- At surface: Start a new dive ---------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1562
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1563 // clear the internal stops table from remains lasting from the last dive
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1564 clear_deco_table();
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1565
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1566 // publish the cleared stops table to the display functions
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1567 publish_deco_table();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1568
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1569 // clear the gas needs table
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1570 for(i=0; i<NUM_GAS; ++i)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1571 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1572 int_O_gas_volumes[i] = 0;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1573 int_O_tank_pres_need[i] = 0 + INT_FLAG_ZERO;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1574 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1575
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1576 // initialize the balancing between N2 and He for later no-fly time calculation
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1577 for(i=0; i<NUM_COMP; ++i)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1578 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1579 split_N2_He[i] = 90; // assumes 90% of total tissue pressure will be needed for N2
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1580 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1581
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1582 // ** UNDER CONSTRUCTION - temporary code only **
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1583 char_I_gas_change_time = 1; // TODO: validate proper operation before enabling this options-table parameter
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1584 char_I_ascent_speed = 10; // TODO: validate proper operation before enabling this options-table parameter,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1585 // caution: values < 10 may have an impact on the deco calculation run-times!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1586
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1587 // initialize values that are constant during the course of the dive
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1588 float_ascent_speed = 1.00 * char_I_ascent_speed;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1589 float_desaturation_multiplier = 0.01 * char_I_desaturation_multiplier;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1590 float_saturation_multiplier = 0.01 * char_I_saturation_multiplier;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1591 float_deco_distance = 0.01 * char_I_deco_distance;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1592
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1593 // initialize values that will be recalculated later on periodically
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1594 char_O_nullzeit = 0; // reset NDL time for the normal plan
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1595 char_O_alternate_nullzeit = 0; // reset NDL time for the alternative plan
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1596 int_O_ascenttime = 0; // reset ascent time for the normal plan
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1597 int_O_alternate_ascenttime = 0; // reset ascent time for the alternative plan
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1598 char_O_deco_warnings = 0; // reset all deco warnings
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1599 deco_tissue_vector = 0; // reset tissue deco vector
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1600 IBCD_tissue_vector = 0; // reset tissue IBCD vector
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1601 NDL_lead_tissue = 0; // reset first tissue to look at during NDL calculation
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1602
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1603 // tag desaturation time as invalid (it will not be computed during a dive)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1604 int_O_desaturation_time = 65535;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1605
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1606 // initialize CNS values
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1607 int_O_normal_CNS_fraction = int_O_alternate_CNS_fraction = int_O_CNS_fraction;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1608
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1609 // Values that should be reset just once for the full real dive.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1610 // This is used to record the lowest stop for the whole dive,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1611 // including ACCROSS all simulated ascents.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1612 low_depth_norm = low_depth_alt = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1613 locked_GF_step_norm = locked_GF_step_alt = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1614
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1615 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1616 // --> code execution continues in state DECO_STATUS_START
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1617 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1618
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1619 case DECO_STATUS_START: //---- Bottom Time & initial Ascent --------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1620 default:
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1621
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1622 // clear the internal(!) stops table
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1623 clear_deco_table();
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1624
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1625 // initialize the simulated tissues with the current state of the real tissues
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1626 for(i=0; i<NUM_COMP; i++)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1627 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1628 sim_pres_tissue_N2[i] = pres_tissue_N2[i];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1629 sim_pres_tissue_He[i] = pres_tissue_He[i];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1630 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1631
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1632 // Lookup the current gas and store it also as the first gas used.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1633 // This gas will be used for the bottom segment of the dive and for
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1634 // the period of delayed ascent when calculating fTTS or bailout.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1635 gas_find_current();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1636
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1637 // setup the calculation ratio's for N2, He and O2 (sim_N2/He/O2_ratio)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1638 gas_set_ratios();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1639
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1640 // initialize depth in absolute pressure, it is needed by
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1641 // - calc_alveolar_pressures(),
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1642 // - calc_ascent_to_first_stop(), and
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1643 // - calc_hauptroutine_calc_deco()
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1644 sim_pres_respiration = pres_respiration;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1645
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1646 // calculate ppN2 and ppHe from sim_N2/He_ratio (<- tissue_increment has been set to 0)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1647 calc_alveolar_pressures();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1648
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1649 // calculate the effect of extended bottom time due to delayed ascent
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1650 if( char_O_deco_status & DECO_ASCENT_DELAYED )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1651 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1652 // program interval on simulated tissues (flag bit 7 = 0)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1653 tissue_increment = char_I_extra_time;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1654
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1655 // update the tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1656 calc_tissues();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1657 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1658
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1659 // calculate if we are within no decompression limit (NDL)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1660 calc_NDL_time();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1661
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1662 // Calculate the initial ascent if in deco. calc_NDL_time() is very fast
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1663 // in detecting being beyond NDL, so there is enough time left in this
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1664 // phase to do the initial ascent calculation.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1665 if( NDL_time == 0 )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1666 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1667 //--- in deco --------------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1668
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1669 // calculate ascent to first stop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1670 calc_ascent_to_first_stop();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1671
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1672 // continue with calculating the stops
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1673 char_O_deco_status &= ~DECO_STATUS_MASK; // clear status bits and set status bits for
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1674 char_O_deco_status |= DECO_STATUS_STOPS; // calculation of stops on next invocation
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1675 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1676 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1677 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1678 //--- within NDL -----------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1679
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1680 // continue with gathering all results
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1681 char_O_deco_status &= ~DECO_STATUS_MASK;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1682 char_O_deco_status |= DECO_STATUS_RESULTS;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1683 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1684
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1685 break;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1686
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1687
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1688 case DECO_STATUS_STOPS: //---- Calculate Stops ---------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1689
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1690 // calculate the stops
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1691 calc_hauptroutine_calc_deco();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1692
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1693 // calc_hauptroutine_calc_deco iterates in this phase as long as it is
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1694 // calculating the stops. Once done, it will set the status to doing the
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1695 // results gathering.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1696
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1697 break;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1698
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1699
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1700 case DECO_STATUS_RESULTS: //--- Gathering of all Results -----------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1701
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1702 // if in normal plan, publish the stops table to the display functions
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1703 if( !(char_O_deco_status & DECO_PLAN_ALTERNATE) ) publish_deco_table();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1704
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1705 // The current depth is needed by calc_CNS_planning() and gas_volumes().
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1706 // As it may be needed in different code blocks below but we don't want
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1707 // it to be in the code multiple times, it's done here on stockpile.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1708 bottom_depth = (unsigned char)((pres_respiration - pres_surface) * BAR_TO_METER);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1709
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1710 // Calculate the ascent time.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1711 // When within NDL, potential gas switches will be treated as done "on the fly".
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1712 calc_ascenttime();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1713
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1714 // results to publish depend whether within NDL or in deco
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1715 if( NDL_time )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1716 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1717 //---- within NDL ----------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1718
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1719 // Calculate the initial ascent (not yet done when within NDL) -
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1720 // just to get potential gas switches into the stops table for use
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1721 // by gas_volumes(). The stops table can be polluted by now because
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1722 // the clean table has already been published to the display
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1723 // functions before.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1724 calc_ascent_to_first_stop();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1725
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1726 // check which plan we are on
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1727 if( char_O_deco_status & DECO_PLAN_ALTERNATE )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1728 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1729 //---- alternate dive plan ---------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1730
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1731 // As we are in no stop, CNS at end of dive is more or less
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1732 // the same CNS as we have right now. It's so simple that we
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1733 // don't check if it requested to be computed or not...
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1734 int_O_alternate_CNS_fraction = int_O_CNS_fraction;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1735
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1736 // output NDL time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1737 char_O_alternate_nullzeit = NDL_time;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1738
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1739 // clear ascent time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1740 int_O_alternate_ascenttime = 0;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1741 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1742 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1743 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1744 //---- normal dive plan ------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1745
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1746 // As we are in no stop, CNS at end of dive is more or less
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1747 // the same CNS as we have right now. It's so simple that we
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1748 // don't check if it requested to be computed or not...
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1749 int_O_normal_CNS_fraction = int_O_CNS_fraction;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1750
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1751 // output NDL time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1752 char_O_nullzeit = NDL_time;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1753
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1754 // clear ascent time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1755 int_O_ascenttime = 0;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1756 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1757 } // NDL
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1758 else
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1759 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1760 //---- in DECO -------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1761
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1762 // check which plan we are on
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1763 if( char_O_deco_status & DECO_PLAN_ALTERNATE )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1764 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1765 //---- alternative plan ----------------------------------------------------
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1766
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1767 // shall the CNS at the end of the dive be calculated?
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1768 if( char_O_deco_status & DECO_CNS_CALCULATE )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1769 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1770 // calculate the CNS for the predicted ascent, result in sim_CNS_fraction
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1771 calc_CNS_planning();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1772
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1773 // add current CNS value
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1774 sim_CNS_fraction += CNS_fraction;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1775
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1776 // convert to integer value
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1777 convert_sim_CNS_for_display();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1778
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1779 // export result
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1780 int_O_alternate_CNS_fraction = int_sim_CNS_fraction;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1781 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1782
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1783 // clear NDL time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1784 char_O_alternate_nullzeit = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1785
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1786 // output ascent time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1787 int_O_alternate_ascenttime = ascent_time;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1788
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1789 } // alternative plan
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1790 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1791 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1792 //---- normal plan ---------------------------------------------------------
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1793
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1794 // shall the CNS at the end of the dive be calculated?
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1795 if( char_O_deco_status & DECO_CNS_CALCULATE )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1796 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1797 // calculate the CNS for the predicted ascent, result in sim_CNS_fraction
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1798 calc_CNS_planning();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1799
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1800 // add current CNS value
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1801 sim_CNS_fraction += CNS_fraction;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1802
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1803 // convert to integer value
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1804 convert_sim_CNS_for_display();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1805
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1806 // export result
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1807 int_O_normal_CNS_fraction = int_sim_CNS_fraction;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1808 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1809
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1810 // clear NDL time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1811 char_O_nullzeit = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1812
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1813 // output ascent time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1814 int_O_ascenttime = ascent_time;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1815
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1816 } // normal plan
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1817 } // DECO
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1818
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1819 // if requested, calculate the required gas volumes and tank pressures at the end of the dive
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1820 if( char_O_deco_status & DECO_VOLUME_CALCULATE ) gas_volumes();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1821
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1822 // signal that the computation cycle is finished
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1823 char_O_deco_status &= ~DECO_STATUS_MASK;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1824
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1825 break;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1826
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1827 } // switch
0
heinrichsweikamp
parents:
diff changeset
1828 }
heinrichsweikamp
parents:
diff changeset
1829
heinrichsweikamp
parents:
diff changeset
1830 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1831 // calc_hauptroutine_data_input
heinrichsweikamp
parents:
diff changeset
1832 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1833 // Set all C-code dive parameters from their ASM-code values.
0
heinrichsweikamp
parents:
diff changeset
1834 // Detect gas change condition.
heinrichsweikamp
parents:
diff changeset
1835 //
heinrichsweikamp
parents:
diff changeset
1836 void calc_hauptroutine_data_input(void)
heinrichsweikamp
parents:
diff changeset
1837 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1838 overlay float IG_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1839
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1840 // get the current pressures
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1841 pres_surface = 0.001 * int_I_pres_surface;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1842 pres_respiration = 0.001 * int_I_pres_respiration;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1843
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1844 // N2 tissue pressure at surface equilibrium, used for tissue graphics scaling
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1845 N2_equilibrium = 0.7902 * (pres_surface - ppWater);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1846
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1847 // read the GF settings (they may have been switch between GF/aGF)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1848 GF_high = 0.01 * char_I_GF_High_percentage;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1849 GF_low = 0.01 * char_I_GF_Low_percentage;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1850 GF_delta = GF_high - GF_low;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1851
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1852 // get the currently breathed gas mixture
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1853 O2_ratio = 0.01 * char_I_O2_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1854 He_ratio = 0.01 * char_I_He_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1855
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1856 // inert gas ratio (local helper variable)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1857 IG_ratio = 1.00 - O2_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1858
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1859 // N2 ratio
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1860 N2_ratio = IG_ratio - He_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1861
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1862 // precomputed values for ppO2 drop in pSCR loop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1863 float_pSCR_factor = 0.01 * char_I_PSCR_drop * char_I_PSCR_lungratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1864 pSCR_drop = IG_ratio * float_pSCR_factor;
0
heinrichsweikamp
parents:
diff changeset
1865 }
heinrichsweikamp
parents:
diff changeset
1866
heinrichsweikamp
parents:
diff changeset
1867 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1868 //
heinrichsweikamp
parents:
diff changeset
1869 //
heinrichsweikamp
parents:
diff changeset
1870 void calc_hauptroutine_update_tissues(void)
heinrichsweikamp
parents:
diff changeset
1871 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1872 overlay float EAD, END;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1873
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1874 //---- calculations part ----------------------------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1875
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1876 // calculate ppN2 and ppHe
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1877 calc_alveolar_pressures();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1878
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1879 // calculate the tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1880 calc_tissues();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1881
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1882 // calculate ceiling (at GF_high) and current GF
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1883 calc_limit(GF_high);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1884
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1885 // calculate EAD (Equivalent Air Depth): equivalent depth for the same N2 level with plain air
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1886 EAD = (ppN2 / 0.7902 + ppWater - pres_surface) * BAR_TO_METER;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1887
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1888 // calculate END (Equivalent Narcotic Depth): here O2 is treated as narcotic, too
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1889 // Source cited: The Physiology and Medicine of Diving by Peter Bennett and David Elliott,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1890 // 4th edition, 1993, W.B.Saunders Company Ltd, London.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1891 END = (pres_respiration - ppHe - pres_surface) * BAR_TO_METER;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1892
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1893
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1894 //---- export ppO2 values in [cbar] for warning generation and display purpose ----------------
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1895
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1896 // pure oxygen ppO2
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1897 if ( O2_ppO2 < 0.01 ) int_O_O2_ppO2 = 0;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1898 else if ( O2_ppO2 >= 9.995 ) int_O_O2_ppO2 = 999;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1899 else int_O_O2_ppO2 = (unsigned int)(100 * O2_ppO2 + 0.5);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1900
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1901 // pure gas ppO2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1902 if ( OC_ppO2 < 0.01 ) int_O_pure_ppO2 = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1903 else if ( OC_ppO2 >= 9.995 ) int_O_pure_ppO2 = 999;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1904 else int_O_pure_ppO2 = (unsigned int)(100 * OC_ppO2 + 0.5);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1905
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1906 // calculated pSCR ppO2
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1907 if ( pSCR_ppO2 < 0.01 ) int_O_pSCR_ppO2 = 0;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1908 else if ( pSCR_ppO2 >= 9.995 ) int_O_pSCR_ppO2 = 999;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1909 else int_O_pSCR_ppO2 = (unsigned int)(100 * pSCR_ppO2 + 0.5);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1910
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1911 // breathed ppO2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1912 if ( ppO2 < 0.01 ) int_O_breathed_ppO2 = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1913 else if ( ppO2 >= 9.995 ) int_O_breathed_ppO2 = 999;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1914 else int_O_breathed_ppO2 = (unsigned int)(100 * ppO2 + 0.5);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1915
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1916
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1917 //---- export EAD and END ---------------------------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1918
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1919 // EAD
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1920 if( (EAD < 0.0) || (EAD > 245.5) ) char_O_EAD = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1921 else char_O_EAD = (unsigned char)(EAD + 0.5);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1922
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1923 // END
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1924 if( (END < 0.0) || (END > 245.5) ) char_O_END = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1925 else char_O_END = (unsigned char)(END + 0.5);
0
heinrichsweikamp
parents:
diff changeset
1926 }
heinrichsweikamp
parents:
diff changeset
1927
heinrichsweikamp
parents:
diff changeset
1928
heinrichsweikamp
parents:
diff changeset
1929 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1930 // Compute stops.
heinrichsweikamp
parents:
diff changeset
1931 //
heinrichsweikamp
parents:
diff changeset
1932 // Note: because this can be very long, break on 16 iterations, and set state
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1933 // to DECO_STATUS_FINISHED when finished, or to DECO_STATUS_STOPS when
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1934 // needing to continue.
0
heinrichsweikamp
parents:
diff changeset
1935 // Note: because each iteration might be very long too (~ 66 ms in 1.84beta),
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1936 // break the loop when elapsed time exceeds 512 milliseconds.
0
heinrichsweikamp
parents:
diff changeset
1937 //
heinrichsweikamp
parents:
diff changeset
1938 void calc_hauptroutine_calc_deco(void)
heinrichsweikamp
parents:
diff changeset
1939 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1940 overlay unsigned char loop;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1941
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1942
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1943 for(loop = 0; loop < 16; ++loop)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1944 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1945 // limit loops to 512ms, using timer 5
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1946 if( tmr5() & (512*32) ) break;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1947
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1948 // calc_nextdecodepth()
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1949 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1950 // INPUT sim_pres_respiration : current depth in absolute pressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1951 // OUTPUT sim_depth_limit : depth of next stop in meters
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1952 // RETURN true if a stop is needed
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1953 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1954 // The function manages gas changes by itself, including priming
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1955 // the deco stop with the configured gas change time.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1956 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1957 if( calc_nextdecodepth() )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1958 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1959 if( sim_depth_limit == 0 ) goto Surface; // this check should not bee needed as in
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1960 // this case the RETURN value will be false
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1961
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1962 //---- stop required at sim_depth_limit -------------------------------------
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1963
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1964 // convert stop depth in meters to absolute pressure
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1965 sim_pres_respiration = sim_depth_limit * METER_TO_BAR + pres_surface;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1966
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1967 // add one minute to the current stop, or add a new stop,
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1968 // or abort deco calculation if the deco table is full.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1969 if( !update_deco_table(1) ) goto Surface;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1970 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1971 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1972 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1973 //---- no stop required --------------------------------------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1974
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1975 // ascend by float_ascent_speed for 1 minute
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1976 sim_pres_respiration -= float_ascent_speed * METER_TO_BAR;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1977
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1978 // finish deco calculation if surface is reached
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1979 if( sim_pres_respiration <= pres_surface )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1980 {
0
heinrichsweikamp
parents:
diff changeset
1981 Surface:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1982 // continue with gathering all results in the next calculation phase
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1983 char_O_deco_status &= ~DECO_STATUS_MASK;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1984 char_O_deco_status |= DECO_STATUS_RESULTS;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1985
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1986 return;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1987 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1988 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1989
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1990
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1991 //---- as one minute as passed now, update the tissues ----------------------
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1992
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1993 // program 1 minute interval on simulated tissues (Flagbit 7 = 0)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1994 tissue_increment = 1;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1995
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1996 // compute current ppN2 and ppHe
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1997 calc_alveolar_pressures();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1998
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1999 // update the tissues
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2000 calc_tissues();
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2001 }
0
heinrichsweikamp
parents:
diff changeset
2002 }
heinrichsweikamp
parents:
diff changeset
2003
heinrichsweikamp
parents:
diff changeset
2004
heinrichsweikamp
parents:
diff changeset
2005 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2006 // Calculate ascent to first deco stop.
0
heinrichsweikamp
parents:
diff changeset
2007 //
heinrichsweikamp
parents:
diff changeset
2008 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2009 // Modified: sim_pres_respiration : current depth in ascent and deco simulation, in bar absolute pressure
0
heinrichsweikamp
parents:
diff changeset
2010 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2011 void calc_ascent_to_first_stop(void)
0
heinrichsweikamp
parents:
diff changeset
2012 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2013 overlay unsigned char fast = 1; // 1 = 1 minute steps, 0 = 2 seconds steps
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2014 overlay unsigned char gaschange = 0; // 1 = do a gas change, 0 = no better gas available
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2015
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2016
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2017 //---- Loop until first deco stop or surface is reached ----------
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2018 for(;;)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2019 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2020 // depth in absolute pressure we came from
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2021 overlay float old_deco = sim_pres_respiration;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2022
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2023 // try ascending 1 full minute (fast) or 2 seconds (!fast)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2024 if ( fast ) sim_pres_respiration -= float_ascent_speed * METER_TO_BAR; // 1 min at float_ascent_speed ( 5 .. 10 m/min)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2025 else sim_pres_respiration -= (float_ascent_speed/30.0) * METER_TO_BAR; // 2 sec at float_ascent_speed (17 .. 33 cm/min)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2026
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2027 // but don't go over surface
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2028 if( sim_pres_respiration < pres_surface ) sim_pres_respiration = pres_surface;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2029
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2030 // compute current ceiling of the simulated tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2031 if ( char_I_deco_model != 0 ) calc_limit(GF_low);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2032 else calc_limit(1.0);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2033
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2034 // did we overshoot the first deco stop?
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2035 if( sim_pres_respiration < (sim_ceiling + pres_surface) )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2036 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2037 // YES - back to last depth below first stop
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2038 sim_pres_respiration = old_deco;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2039
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2040 // switch to 2 seconds ascent if not yet in, else done
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2041 if( fast )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2042 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2043 fast = 0; // retry with 2 seconds ascent steps
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2044 continue;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2045 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2046 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2047 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2048 break; // done...
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2049 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2050 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2051
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2052 // If code execution passes along here, we did not overshoot the first stop.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2053
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2054 // did we reach the surface? if yes, done!
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2055 if( sim_pres_respiration == pres_surface ) break;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2056
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2057 // depth in meters where we are now (no round-up)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2058 sim_depth_limit = (unsigned char)((sim_pres_respiration - pres_surface) * BAR_TO_METER);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2059
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2060 // Check if there is a better gas to switch to, but only in alternative plan mode
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2061 // or if override is set. If yes, introduce a stop for the gas change.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2062 if( ((char_O_deco_status & DECO_PLAN_ALTERNATE) || (char_O_main_status & DECO_GASCHANGE_OVRD))
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2063 && gas_find_better() )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2064 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2065 // depth in meters we came from
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2066 overlay unsigned char old_depth_limit = (unsigned char)((old_deco - pres_surface) * BAR_TO_METER);
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2067
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2068 // adjust sim_depth_limit to the gas change depth, but not deeper than the depth we came from
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2069 sim_depth_limit = (sim_gas_last_depth < old_depth_limit) ? sim_gas_last_depth : old_depth_limit;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2070
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2071 // create a stop for the gas change
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2072 update_deco_table(char_I_gas_change_time);
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2073
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2074 // set the new calculation values for N2, He and O2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2075 gas_set_ratios();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2076
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2077 // signal to create a stop for the gas change and update the tissues
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2078 gaschange = char_I_gas_change_time;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2079
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2080 // Adjust the depth for the tissue update to the stop depth. In case of fast mode, this
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2081 // imposes that the ascent from the 'old_deco' depth to this stop took 1 minute although
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2082 // we might have only ascended one or two meters...
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2083 sim_pres_respiration = sim_depth_limit * METER_TO_BAR + pres_surface;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2084 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2085
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2086 // Did one minute pass by and/or do we have a gas change?
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2087 // Remark: The 2 seconds ascent iterations towards the first deco stop in !fast speed may take
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2088 // up to 28 seconds in total - for this rough half of a minute no tissue updates will be computed.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2089 // Well, it could be done by setting tissue_increment = 0 in !fast condition and making calls to
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2090 // calc_alveolar_pressures() and calc_tissues() - see code commented out below.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2091 if( fast || gaschange )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2092 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2093 // program interval on simulated tissues (flag bit 7 = 0)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2094 tissue_increment = fast + gaschange;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2095
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2096 // clear gas change signal
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2097 gaschange = 0;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2098 // }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2099 // else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2100 // {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2101 // // program 2 seconds interval on simulated tissues (flag bit 7 = 0)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2102 // tissue_increment = 0;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2103 // }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2104 // {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2105 // compute ppN2/ppHe for current depth from sim_pres_respiration
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2106 calc_alveolar_pressures();
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2107
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2108 // update the tissues
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2109 calc_tissues();
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2110 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2111 }
0
heinrichsweikamp
parents:
diff changeset
2112 }
heinrichsweikamp
parents:
diff changeset
2113
heinrichsweikamp
parents:
diff changeset
2114
heinrichsweikamp
parents:
diff changeset
2115 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2116 // calc_tissues
0
heinrichsweikamp
parents:
diff changeset
2117 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2118 // INPUT: ppN2 : partial pressure of inspired N2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2119 // ppHe : partial pressure of inspired He
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2120 // tissue_increment : integration time and tissue selector (real or simulated)
0
heinrichsweikamp
parents:
diff changeset
2121 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2122 // MODIFIED: pres_tissue_N2[] : tissue N2 pressures (in real tissues context)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2123 // pres_tissue_He[] : tissue He pressures (in real tissues context)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2124 // sim_pres_tissue_N2[] : tissue N2 pressures (in simulated tissues context)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2125 // sim_pres_tissue_He[] : tissue He pressures (in simulated tissues context)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2126 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2127 // OUTPUT: char_O_tissue_N2_saturation[] : tissue N2 pressures scaled for display purpose (in real tissues context)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2128 // char_O_tissue_He_saturation[] : tissue He pressures scaled for display purpose (in real tissues context)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2129 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2130 static void calc_tissues()
0
heinrichsweikamp
parents:
diff changeset
2131 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2132 overlay float temp_tissue_N2;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2133 overlay float temp_tissue_He;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2134 overlay unsigned char period;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2135 overlay unsigned char i;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2136
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2137
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2138 assert( 0.00 <= ppN2 && ppN2 < 11.2 ); // 80% N2 at 130m
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2139 assert( 0.00 <= ppHe && ppHe < 12.6 ); // 90% He at 130m
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2140
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2141
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2142 for (ci=0;ci<NUM_COMP;ci++) // iterate through all compartments
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2143 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2144 i = tissue_increment & TIME_MASK; // extract number of minutes to do (if i > 0)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2145 // or if one 2 second period is to do (if i = 0)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2146
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2147 if( i == 0 ) // check if we shall do one 2-seconds period
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2148 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2149 read_Buhlmann_times(0); // YES, program coefficients for a 2 seconds period
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2150 period = 1; // set period length (in cycles)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2151 i = 1; // and one cycle to do
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2152 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2153 else if( i > 9 ) // check if we can start with 10 minutes periods
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2154 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2155 read_Buhlmann_times(2); // YES, program coefficients for 10 minutes periods
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2156 period = 10; // set period length (in cycles) to ten
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2157 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2158 else // we shall do 1 to 9 minutes
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2159 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2160 read_Buhlmann_times(1); // program coefficients for 1 minute periods
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2161 period = 1; // set period length (in cycles) to one
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2162 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2163
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2164 do
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2165 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2166 //---- N2 -------------------------------------------------------------------------------
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2167
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2168 temp_tissue = (tissue_increment & TISSUE_FLAG) ? pres_tissue_N2[ci] : sim_pres_tissue_N2[ci];
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2169
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2170 temp_tissue = (ppN2 - temp_tissue) * var_N2_e;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2171
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2172 temp_tissue_safety();
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2173
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2174 if( tissue_increment & TISSUE_FLAG )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2175 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2176 // The temp variable takes on purpose just the tissue increment from the last loop's iteration.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2177 temp_tissue_N2 = temp_tissue;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2178
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2179 // Update the real tissues if either we are on the 2 seconds interval,
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2180 // or if we shall advance the tissues on a one or several minutes basis.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2181 if( twosectimer || (tissue_increment & TIME_MASK) ) pres_tissue_N2[ci] += temp_tissue;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2182 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2183 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2184 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2185 // Updates of the sim-tissues always comes on a 1 minutes basis,
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2186 // so we do not need to check of the 2 seconds interval.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2187 sim_pres_tissue_N2[ci] += temp_tissue;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2188 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2189
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2190
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2191 //---- He -------------------------------------------------------------------------------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2192
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2193 temp_tissue = (tissue_increment & TISSUE_FLAG) ? pres_tissue_He[ci] : sim_pres_tissue_He[ci];
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2194
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2195 temp_tissue = (ppHe - temp_tissue) * var_He_e;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2196
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2197 temp_tissue_safety();
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2198
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2199 if( tissue_increment & TISSUE_FLAG )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2200 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2201 // The temp variable takes on purpose just the tissue increment from the last loop's iteration.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2202 temp_tissue_He = temp_tissue;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2203
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2204 // Update the real tissues if either we are on the 2 seconds interval,
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2205 // or if we shall advance the tissues on a one or several minutes basis.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2206 if( twosectimer || (tissue_increment & TIME_MASK) ) pres_tissue_He[ci] += temp_tissue;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2207 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2208 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2209 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2210 // Updates of the sim-tissues always comes on a 1 minutes basis,
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2211 // so we do not need to check of the 2 seconds interval.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2212 sim_pres_tissue_He[ci] += temp_tissue;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2213 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2214
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2215 // decrement loop counter
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2216 i -= period;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2217
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2218 // check if we need to switch from 10 minute periods to 1 minute periods
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2219 if( (i > 0) && (period = 10) && (i < 10) )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2220 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2221 read_Buhlmann_times(1); // program coefficients for 1 minute periods
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2222 period = 1; // set period length (in cycles) to one
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2223 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2224 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2225 while( i );
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2226
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2227
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2228 // have the computations been done for the "real" tissues?
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2229 if( (tissue_increment & TISSUE_FLAG) && (twosectimer || (tissue_increment & TIME_MASK)) )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2230 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2231 // net tissue balance
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2232 temp_tissue = temp_tissue_N2 + temp_tissue_He;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2233
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2234 // check tissue on-/off-gassing and IBCD with applying a threshold of +/-HYST
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2235 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2236 if ( temp_tissue < -HYST ) // Check if the tissue is off-gassing
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2237 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2238 deco_tissue_vector |= (1 << ci); // tag tissue as being in decompression
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2239 IBCD_tissue_vector &= ~(1 << ci); // tag tissue as not experiencing mentionable IBCD
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2240 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2241 else if ( temp_tissue > +HYST ) // check if the tissue in on-gassing
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2242 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2243 deco_tissue_vector &= ~(1 << ci); // tag tissue as not being in decompression
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2244
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2245 if( ((temp_tissue_N2 > 0.0) && (temp_tissue_He < 0.0)) // check for counter diffusion
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2246 || ((temp_tissue_N2 < 0.0) && (temp_tissue_He > 0.0)) )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2247 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2248 IBCD_tissue_vector |= (1 << ci); // tag tissue as experiencing mentionable IBCD
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2249 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2250 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2251
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2252
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2253 // keep the saturating / desaturating flags from last invocation
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2254 char_O_tissue_N2_saturation[ci] &= 128;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2255 char_O_tissue_He_saturation[ci] &= 128;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2256
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2257 // flip the flags applying a hysteresis of HYST (actual value: see #define of HYST)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2258 if( temp_tissue_N2 > +HYST ) char_O_tissue_N2_saturation[ci] = 128; // set flag for tissue pressure is increasing
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2259 else if( temp_tissue_N2 < -HYST ) char_O_tissue_N2_saturation[ci] = 0; // clear flag (-> tissue pressure is decreasing)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2260
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2261 if( temp_tissue_He > +HYST ) char_O_tissue_He_saturation[ci] = 128; // set flag for tissue pressure is increasing
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2262 else if( temp_tissue_He < -HYST ) char_O_tissue_He_saturation[ci] = 0; // clear flag (-> tissue pressure is decreasing)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2263
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2264
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2265 // For N2 tissue display purpose:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2266 // Scale tissue press so that saturation in 70m on AIR gives a value of approx. 80.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2267 // The surface steady-state tissue loading of [0.7902 * (pres_respiration - ppWater)] bar
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2268 // gives then a 10. If N2 is completely washed out of the tissue, result will be 0.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2269 // This scaling is adapted to the capabilities of the tissue graphics in the custom views.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2270 temp_tissue = (pres_tissue_N2[ci] / N2_equilibrium) * 10;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2271
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2272 // limit to 127 to leave space for sat/desat flag
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2273 if (temp_tissue > 127) temp_tissue = 127;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2274
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2275 // export as integer
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2276 char_O_tissue_N2_saturation[ci] += (unsigned char)temp_tissue;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2277
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2278
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2279 // For H2 tissue display purpose:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2280 // Scale tissue press so that saturation in 120m on TMX 10/70 gives a value of approx. 70.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2281 // With no He in a tissue, result will be 0.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2282 // This scaling is adapted to the capabilities of the tissue graphics in the custom views.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2283 temp_tissue = pres_tissue_He[ci] * 7.7;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2284
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2285 // limit to 127 to leave space for sat/desat flag
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2286 if (temp_tissue > 127) temp_tissue = 127;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2287
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2288 // export as integer
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2289 char_O_tissue_He_saturation[ci] += (unsigned char)temp_tissue;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2290 } //if
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2291
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2292 } // for
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2293
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2294
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2295 // set deco flag if we are in deco and at least one of the real tissues is off-gassing
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2296 // clear deco flag if all of the real tissues are on-gassing
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2297 if ( (char_O_nullzeit == 0) && deco_tissue_vector ) char_O_deco_warnings |= DECO_FLAG;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2298 else if ( !deco_tissue_vector ) char_O_deco_warnings &= ~DECO_FLAG;
0
heinrichsweikamp
parents:
diff changeset
2299 }
heinrichsweikamp
parents:
diff changeset
2300
heinrichsweikamp
parents:
diff changeset
2301 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
2302 // calc_limit
heinrichsweikamp
parents:
diff changeset
2303 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2304 // Input:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2305 // tissue_increment : selector for context: real or simulated tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2306 // sim_pres_tissue_N2/_He : tissue pressures (used in simulated tissues context)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2307 // pres_tissue_N2/_He : tissue pressures (used in real tissues context)
0
heinrichsweikamp
parents:
diff changeset
2308 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2309 // Output:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2310 // sim_ceiling : ceiling in bar relative pressure (only in simulated tissues context)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2311 // ceiling : ceiling in bar relative pressure (only in real tissues context)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2312 // int_O_ceiling : ceiling in mbar relative pressure (only in real tissues context)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2313 // int_O_gradient_factor : gradient factor in % (only in real tissues context)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2314 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2315 // Modified:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2316 // char_O_deco_warnings : for IBCD, microbubbles and outside warning (only in real tissues context)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2317 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2318 static void calc_limit(PARAMETER float GF_parameter)
0
heinrichsweikamp
parents:
diff changeset
2319 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2320 overlay float lead_tissue_limit = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2321 overlay float lead_supersat = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2322
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2323 overlay unsigned char lead_tissue_no = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2324
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2325
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2326 // check context
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2327 if( tissue_increment & TISSUE_FLAG )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2328 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2329 // clear IBCD, microbubbles and outside warning flags (locked warnings will be preserved)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2330 char_O_deco_warnings &= ~(DECO_WARNING_IBCD + DECO_WARNING_MBUBBLES + DECO_WARNING_OUTSIDE);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2331 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2332
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2333
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2334 // loop over all tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2335 for(ci=0; ci<NUM_COMP; ci++)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2336 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2337 overlay float calc_pres_tissue_N2;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2338 overlay float calc_pres_tissue_He;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2339 overlay float pres_tissue;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2340 overlay float pres_min;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2341
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2342 // get the tissue pressures
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2343 if( tissue_increment & TISSUE_FLAG )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2344 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2345 // context is real tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2346 calc_pres_tissue_N2 = pres_tissue_N2[ci];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2347 calc_pres_tissue_He = pres_tissue_He[ci];
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2348 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2349 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2350 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2351 // context is simulated tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2352 calc_pres_tissue_N2 = sim_pres_tissue_N2[ci];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2353 calc_pres_tissue_He = sim_pres_tissue_He[ci];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2354 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2355
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2356 // overall tissue pressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2357 pres_tissue = calc_pres_tissue_N2 + calc_pres_tissue_He;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2358
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2359 // get the coefficients for tissue ci
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2360 read_Buhlmann_coefficients();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2361
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2362 // adapt the coefficients according to the N2/He ratio in the tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2363 var_N2_a = (var_N2_a * calc_pres_tissue_N2 + var_He_a * calc_pres_tissue_He) / pres_tissue;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2364 var_N2_b = (var_N2_b * calc_pres_tissue_N2 + var_He_b * calc_pres_tissue_He) / pres_tissue;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2365
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2366 // calculate minimum ambient pressure that the tissue can withstand according to straight Buhlmann
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2367 pres_min = (pres_tissue - var_N2_a) * var_N2_b;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2368
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2369 // next calculations are only relevant when invoked on the real tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2370 if( tissue_increment & TISSUE_FLAG )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2371 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2372 overlay float supersat;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2373 overlay float threshold;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2374
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2375 // calculate current supersaturation value (1.0 = 100%) of this tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2376 supersat = (pres_tissue - pres_respiration) / (pres_tissue - pres_min);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2377
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2378 // check if tissue is in supersaturation
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2379 if( supersat > 0.0 )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2380 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2381 // memorize highest supersaturation found
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2382 if( supersat > lead_supersat ) lead_supersat = supersat;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2383
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2384 // set a threshold value for the microbubbles and outside warnings
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2385 // ToDo: finalize the definition of the threshold
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2386 threshold = 0.02 * ci + 0.9;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2387
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2388 // check if this tissue is likely to develop microbubbles
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2389 // and/or if this tissue is outside of the Buhlmann model
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2390 if( ci <= 5 )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2391 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2392 if( supersat >= threshold )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2393 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2394 char_O_deco_warnings |= (DECO_WARNING_MBUBBLES + DECO_WARNING_MBUBBLES_lock);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2395
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2396 if( supersat >= 1.0 )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2397 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2398 char_O_deco_warnings |= (DECO_WARNING_OUTSIDE + DECO_WARNING_OUTSIDE_lock);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2399 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2400 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2401 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2402 else // ci > 5
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2403 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2404 if( supersat >= 1.0 )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2405 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2406 char_O_deco_warnings |= (DECO_WARNING_MBUBBLES + DECO_WARNING_MBUBBLES_lock);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2407
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2408 if( supersat >= threshold )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2409 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2410 char_O_deco_warnings |= (DECO_WARNING_OUTSIDE + DECO_WARNING_OUTSIDE_lock);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2411 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2412 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2413 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2414 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2415 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2416
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2417 // Apply the Eric Baker's varying gradient factor correction if the GF-Model is selected.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2418 // Note: the correction factor depends both on GF and b, so that can change who is the
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2419 // leading gas...
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2420 if( char_I_deco_model != 0 ) pres_min = ( pres_tissue - (var_N2_a * GF_parameter) )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2421 / ( 1.0 - GF_parameter + (GF_parameter / var_N2_b ) );
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2422
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2423 // check if this tissue requires a higher ambient pressure than was found to be needed up to now
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2424 if( pres_min > lead_tissue_limit )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2425 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2426 lead_tissue_limit = pres_min;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2427 lead_tissue_no = ci;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2428 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2429 } // for
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2430
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2431
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2432 // compile outputs
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2433 if( tissue_increment & TISSUE_FLAG )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2434 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2435 //--- real tissues -----------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2436
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2437 // check if leading tissue is in IBCD condition
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2438 if( (IBCD_tissue_vector & (1 << lead_tissue_no))
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2439 && ((pres_tissue_N2[lead_tissue_no] + pres_tissue_He[lead_tissue_no]) > pres_respiration) )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2440 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2441 // leading tissue is in IBCD condition and in super-saturation, so issue a warning.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2442 char_O_deco_warnings |= (DECO_WARNING_IBCD + DECO_WARNING_IBCD_lock);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2443 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2444
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2445
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2446 // compute ceiling in bar relative pressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2447 ceiling = lead_tissue_limit - pres_surface;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2448
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2449 // convert ceiling to int_O_ceiling in mbar
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2450 if ( ceiling <= 0 ) int_O_ceiling = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2451 else if ( ceiling > 16 ) int_O_ceiling = 16000;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2452 // Compatibility version
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2453 else int_O_ceiling = (short)(ceiling * 1000);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2454
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2455 // New version: Rounds up to next 10 cm so that the ceiling disappears on the display only when the
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2456 // ceiling limit is really zero. This will coincident then with TTS switching back to NDL time.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2457 // else int_O_ceiling = (short)(ceiling * 1000 + 9);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2458
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2459
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2460 // convert highest supersaturation found to int_O_gradient_factor in % (1.0 = 100%)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2461 // limit to 255 because of constraints in ghostwriter code
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2462 if ( lead_supersat <= 0.0 ) int_O_gradient_factor = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2463 else if( lead_supersat > 2.545 ) int_O_gradient_factor = 255 + INT_FLAG_WARNING;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2464 else
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2465 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2466 int_O_gradient_factor = (unsigned int)(100 * lead_supersat + 0.5);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2467
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2468 if ( int_O_gradient_factor >= GF_WARNING_THRESHOLD )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2469 int_O_gradient_factor |= INT_FLAG_WARNING;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2470
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2471 else if ( int_O_gradient_factor >= char_I_GF_High_percentage )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2472 int_O_gradient_factor |= INT_FLAG_ATTENTION;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2473 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2474 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2475 else
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2476 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2477 //--- simulated tissues ------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2478
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2479 // compute ceiling for the simulated tissues in bar relative pressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2480 sim_ceiling = lead_tissue_limit - pres_surface;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2481 }
0
heinrichsweikamp
parents:
diff changeset
2482 }
heinrichsweikamp
parents:
diff changeset
2483
heinrichsweikamp
parents:
diff changeset
2484 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2485 // calc_NDL_time
0
heinrichsweikamp
parents:
diff changeset
2486 //
heinrichsweikamp
parents:
diff changeset
2487 // calculates the remaining bottom time
heinrichsweikamp
parents:
diff changeset
2488 //
heinrichsweikamp
parents:
diff changeset
2489 // NOTE: Erik Baker's closed formula works for Nitroxes. Trimix adds a second
heinrichsweikamp
parents:
diff changeset
2490 // exponential term to the M-value equation, making it impossible to
heinrichsweikamp
parents:
diff changeset
2491 // invert... So we have to make a fast-simu until we find a better way.
heinrichsweikamp
parents:
diff changeset
2492 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2493 // Input: ppN2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2494 // ppHe
0
heinrichsweikamp
parents:
diff changeset
2495 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2496 // Output: NDL_time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2497 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2498 static void calc_NDL_time(void)
0
heinrichsweikamp
parents:
diff changeset
2499 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2500 overlay unsigned char new_NDL_lead_tissue = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2501 overlay unsigned char i;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2502
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2503
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2504 // initialize NDL_time to 240 minutes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2505 NDL_time = 240;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2506
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2507 for(i=0; i<NUM_COMP; i++)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2508 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2509 overlay float calc_pres_tissue_N2;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2510 overlay float calc_pres_tissue_He;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2511 overlay float pres_tissue;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2512
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2513 overlay unsigned char NDL_tissue;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2514 overlay unsigned char period = 10; // start with 10 minute periods
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2515
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2516
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2517 // check lead tissue from last NDL computation first
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2518 ci = i + NDL_lead_tissue;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2519
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2520 // wrap around after the 16th tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2521 if( ci >= NUM_COMP ) ci -= NUM_COMP;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2522
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2523 // read Buhlmann a and b coefficients for tissue ci
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2524 read_Buhlmann_coefficients();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2525
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2526 // read the loading factors for 10 minute periods
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2527 read_Buhlmann_times(2);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2528
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2529 // get the tissue pressures for N2 and He
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2530 calc_pres_tissue_N2 = sim_pres_tissue_N2[ci];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2531 calc_pres_tissue_He = sim_pres_tissue_He[ci];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2532
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2533 // calculate the total pressure tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2534 pres_tissue = calc_pres_tissue_N2 + calc_pres_tissue_He;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2535
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2536
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2537 // simulate an increasing bottom time and check when we hit the NDL ------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2538 for( NDL_tissue = 0; NDL_tissue < NDL_time; ) // not needed to simulate for longer than the already found NDL
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2539 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2540 overlay float var_a;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2541 overlay float var_b;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2542 overlay float pres_limit;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2543 overlay float delta_pres_tissue_N2;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2544 overlay float delta_pres_tissue_He;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2545
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2546
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2547 // adopt a and b coefficients to current N2/He ratio inside the tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2548 var_a = (var_N2_a * calc_pres_tissue_N2 + var_He_a * calc_pres_tissue_He) / pres_tissue;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2549 var_b = (var_N2_b * calc_pres_tissue_N2 + var_He_b * calc_pres_tissue_He) / pres_tissue;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2550
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2551 // compute pressure limit for tissues under surface pressure conditions
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2552 pres_limit = (var_a + pres_surface / var_b);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2553
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2554 // adopt pressure limit when using the GF extension
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2555 if (char_I_deco_model != 0 ) pres_limit = GF_high * (pres_limit - pres_surface) + pres_surface;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2556
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2557 //---- Check if this tissue is already beyond the NDL
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2558 if( pres_tissue > pres_limit)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2559 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2560 // NO - finish the outer loop,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2561 i = NUM_COMP;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2562
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2563 // and finish the inner loop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2564 break;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2565 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2566
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2567 // compute delta to tissue pressures in 10 or 1 minutes of time ahead
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2568 delta_pres_tissue_N2 = (ppN2 - calc_pres_tissue_N2) * var_N2_e;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2569 delta_pres_tissue_He = (ppHe - calc_pres_tissue_He) * var_He_e;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2570
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2571 // apply safety factors to the pressure deltas
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2572 // NDL can be computed while ascending, so we have to check if we are saturating or desaturating
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2573 if( delta_pres_tissue_N2 > 0.0 ) delta_pres_tissue_N2 *= float_saturation_multiplier;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2574 else delta_pres_tissue_N2 *= float_desaturation_multiplier;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2575
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2576 if( delta_pres_tissue_He > 0.0 ) delta_pres_tissue_He *= float_saturation_multiplier;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2577 else delta_pres_tissue_He *= float_saturation_multiplier;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2578
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2579 // Simulate off-gassing while going to surface
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2580 // TODO !
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2581 // delta_pres_tissue_N2 -= exp( ... ascent time ... ppN2...)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2582 // delta_pres_tissue_He -= exp( ... ascent time ... ppHe...)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2583
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2584 // within NDL now, but still within in 10 or 1 minutes from now?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2585 if( pres_tissue + delta_pres_tissue_N2 + delta_pres_tissue_He <= pres_limit )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2586 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2587 // YES - apply the pressure deltas to tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2588 calc_pres_tissue_N2 += delta_pres_tissue_N2;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2589 calc_pres_tissue_He += delta_pres_tissue_He;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2590
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2591 // update the overall tissue pressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2592 pres_tissue = calc_pres_tissue_N2 + calc_pres_tissue_He;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2593
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2594 // increment the NDL
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2595 NDL_tissue += period;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2596
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2597 // do next loop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2598 continue;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2599 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2600
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2601 // NO - if delta pressures were for 10 minutes of time ahead, try with 1 minute ahead
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2602 if( period == 10 )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2603 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2604 // reduce period to 1 minute
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2605 period = 1;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2606
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2607 // read the loading factors for 1 minute periods
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2608 read_Buhlmann_times(1);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2609
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2610 // do next loop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2611 continue;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2612 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2613
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2614 // NO - not even within NDL in just one more minute, so make a linear approx for the last minute
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2615 // (make a meaningful rounding of NDL, but ONLY if positive: negative casted to unsigned is bad)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2616 if( pres_limit > pres_tissue )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2617 NDL_tissue += (unsigned char)(0.5 + (pres_limit - pres_tissue )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2618 / (delta_pres_tissue_N2 + delta_pres_tissue_He) );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2619
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2620 // finish the inner loop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2621 break;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2622 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2623
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2624 // is the current NDL short than the shortest so far?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2625 if ( NDL_tissue < NDL_time )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2626 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2627 // keep the current's tissue NDL as the new shortest NDL
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2628 NDL_time = NDL_tissue;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2629
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2630 // store the causing tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2631 new_NDL_lead_tissue = ci;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2632 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2633
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2634 // if NDL is > 0 the outer loop will continues with the next tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2635 // if NDL found to be overrun, outer loop will be terminated through i = NUM_COMP statement
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2636 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2637
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2638 // store the NDL dominating tissue for to start with in the next NDL calculation
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2639 NDL_lead_tissue = new_NDL_lead_tissue;
0
heinrichsweikamp
parents:
diff changeset
2640 }
heinrichsweikamp
parents:
diff changeset
2641
heinrichsweikamp
parents:
diff changeset
2642 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
2643 // calc_ascenttime
heinrichsweikamp
parents:
diff changeset
2644 //
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2645 // Sum up ascent from bottom to surface at float_ascent_speed,
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2646 // but 1 minute per meter for the final ascent, and all stops.
0
heinrichsweikamp
parents:
diff changeset
2647 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2648 // Input: char_I_depth_last_deco
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2649 // pres_respiration
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2650 // pres_surface
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2651 // float_ascent_speed
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2652 // internal_deco_depth[]
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2653 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2654 // Output: ascent_time
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2655 //
0
heinrichsweikamp
parents:
diff changeset
2656 static void calc_ascenttime(void)
heinrichsweikamp
parents:
diff changeset
2657 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2658 overlay unsigned char x;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2659
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2660
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2661 // preset final ascent
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2662 overlay float final = (float)char_I_depth_last_deco;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2663
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2664 // calculate depth
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2665 overlay float ascent = (pres_respiration - pres_surface) * BAR_TO_METER;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2666
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2667 // check if we are already in final ascent
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2668 if (ascent <= final)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2669 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2670 // yes - all ascent is final ascent
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2671 final = ascent;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2672 ascent = 0.0;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2673 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2674 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2675 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2676 // no - subtract final ascent part from overall ascent
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2677 ascent -= final;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2678
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2679 // compute time for ascent part without final ascent
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2680 ascent /= float_ascent_speed;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2681 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2682
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2683 // add 1 minute for each meter of final ascent
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2684 ascent += final;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2685
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2686 // convert to integer
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2687 ascent_time = (unsigned short)(ascent + 0.5);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2688
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2689 // add all stop times
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2690 for(x=0; x<NUM_STOPS && internal_deco_depth[x]; x++)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2691 ascent_time += (unsigned short)internal_deco_time[x];
0
heinrichsweikamp
parents:
diff changeset
2692
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2693 // limit result to display max.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2694 if( ascent_time > 999) ascent_time = 999;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2695
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2696 // tag result as invalid if there is an overflow in the stops table
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2697 if( char_O_deco_warnings & DECO_WARNING_STOPTABLE_OVERFLOW ) ascent_time |= INT_FLAG_INVALID;
0
heinrichsweikamp
parents:
diff changeset
2698 }
heinrichsweikamp
parents:
diff changeset
2699
heinrichsweikamp
parents:
diff changeset
2700
heinrichsweikamp
parents:
diff changeset
2701 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
2702 // clear_deco_table
heinrichsweikamp
parents:
diff changeset
2703 //
heinrichsweikamp
parents:
diff changeset
2704 //
heinrichsweikamp
parents:
diff changeset
2705 static void clear_deco_table(void)
heinrichsweikamp
parents:
diff changeset
2706 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2707 overlay unsigned char x;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2708
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2709 for(x=0; x<NUM_STOPS; ++x)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2710 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2711 internal_deco_time [x] = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2712 internal_deco_depth[x] = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2713 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2714
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2715 // clear stop table overflow warning
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2716 char_O_deco_warnings &= ~DECO_WARNING_STOPTABLE_OVERFLOW;
0
heinrichsweikamp
parents:
diff changeset
2717 }
heinrichsweikamp
parents:
diff changeset
2718
heinrichsweikamp
parents:
diff changeset
2719 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
2720 // update_deco_table
heinrichsweikamp
parents:
diff changeset
2721 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2722 // Add time to a stop at sim_depth_limit
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2723 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2724 // It is possible to create stops with a duration of 0 minutes, e.g. to
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2725 // note a gas change "on the fly" while ascending. Therefore the criteria
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2726 // to have reached the end of the list needs always to be depth == 0.
0
heinrichsweikamp
parents:
diff changeset
2727 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2728 // Input: sim_depth_limit : stop's depth, in meters.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2729 // sim_gas_last_used : gas used at stop, as index 1..5 or 0 for gas 6
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2730 // PARAMETER time_increment : number of minutes to add to the stop
0
heinrichsweikamp
parents:
diff changeset
2731 //
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2732 // Updated: internal_deco_depth[] : depth (in meters) of each stop
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2733 // internal_deco_time [] : time (in minutes) of each stop
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2734 // internal_deco_gas [] : gas used (index 1-5) at each stop
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2735 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2736 static unsigned char update_deco_table(PARAMETER unsigned char time_increment)
0
heinrichsweikamp
parents:
diff changeset
2737 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2738 overlay unsigned char x;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2739
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2740 assert( sim_depth_limit > 0 ); // No stop at surface...
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2741
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2742 // loop through internal deco table
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2743 for(x=0; x<NUM_STOPS; ++x)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2744 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2745 // Make sure deco-stops are recorded in order:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2746 assert( !internal_deco_depth[x] || sim_depth_limit <= internal_deco_depth[x] );
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2747
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2748 // Is there already a stop entry for our current depth?
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2749 if( internal_deco_depth[x] == sim_depth_limit )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2750 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2751 // Yes - increment stop time if possible
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2752 // Stop time entries are limited to 99 minutes because of display constraints.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2753 // Else a limit of 254 would account because of constrains in calc_CNS_planning().
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2754 if( internal_deco_time[x] < (100 - time_increment) )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2755 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2756 internal_deco_time[x] += time_increment; // increment stop time
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2757 return 1; // return with status 'success'
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2758 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2759 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2760
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2761 // If program flow passes here, there is either no stop entry for the current depth yet, or
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2762 // the existing entry is saturated with 99 minutes. So we are looking for the next unused
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2763 // table entry.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2764 if( internal_deco_depth[x] == 0 )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2765 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2766 internal_deco_time[x] = time_increment; // initialize entry with first stop's time,
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2767 internal_deco_depth[x] = sim_depth_limit; // ... depth, and
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2768 internal_deco_gas[x] = sim_gas_last_used; // ... gas
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2769 return 1; // return with status 'success'
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2770 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2771 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2772
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2773 // If program flow passes here, all deco table entries are used up.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2774
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2775 // set overflow warning
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2776 char_O_deco_warnings |= DECO_WARNING_STOPTABLE_OVERFLOW;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2777
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2778 // return with status 'failed'.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2779 return 0;
0
heinrichsweikamp
parents:
diff changeset
2780 }
heinrichsweikamp
parents:
diff changeset
2781
heinrichsweikamp
parents:
diff changeset
2782
heinrichsweikamp
parents:
diff changeset
2783 //////////////////////////////////////////////////////////////////////////////
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2784 // calc_desaturation_time
0
heinrichsweikamp
parents:
diff changeset
2785 //
heinrichsweikamp
parents:
diff changeset
2786 // Inputs: int_I_pres_surface, ppWater, char_I_desaturation_multiplier
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2787 // Outputs: int_O_desaturation_time, int_O_nofly_time
0
heinrichsweikamp
parents:
diff changeset
2788 //
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2789 // Helper function
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2790 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2791 void calc_desaturation_time_helper(void)
0
heinrichsweikamp
parents:
diff changeset
2792 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2793 if( pres_actual > pres_target ) // check if actual pressure is higher then target pressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2794 { // YES - compute remaining time
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2795 overlay float pres_ratio;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2796
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2797 pres_ratio = pres_actual / pres_target;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2798
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2799 // Compute desaturation time with result rounded up to multiples of 10 minutes.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2800 // Main purpose is to avoid confusion, because the times do not clock down in
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2801 // one minute steps any more but get constantly re-computed according to current
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2802 // ambient pressure and may therefor make steps of several minutes forwards and
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2803 // backwards as ambient pressure rises and falls.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2804 int_time = (unsigned int)( (var_ht * log(pres_ratio) / desat_factor) + 0.9 );
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2805 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2806 else
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2807 { // NO - desaturation state reached, no remaining time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2808 int_time = 0;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2809 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2810 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2811
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2812 /////////////////////////////////////////////////////////////////////////////
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2813 // Main function
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2814 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2815 void calc_desaturation_time(void)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2816 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2817 assert( 800 < int_I_pres_surface && int_I_pres_surface < 1100 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2818 assert( 0 < char_I_desaturation_multiplier && char_I_desaturation_multiplier <= 100 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2819
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2820 // fraction of inert gases in respired air
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2821 N2_ratio = 0.7902;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2822 He_ratio = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2823
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2824 // surface pressure in bar
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2825 pres_surface = 0.001 * int_I_pres_surface;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2826
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2827 // partial pressure of N2 in respired air
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2828 N2_equilibrium = N2_ratio * (pres_surface - ppWater);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2829
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2830 // pre-computed term for later use: 10 [Min] * 0.01 [%] * 0.6931 [=log(2)] * ...
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2831 desat_factor = 0.06931 * char_I_desaturation_multiplier * SURFACE_DESAT_FACTOR;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2832
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2833 // initialize vars
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2834 int_O_desaturation_time = 0;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2835 int_O_nofly_time = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2836
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2837
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2838 for(ci=NUM_COMP; ci>0;)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2839 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2840 overlay float pres_tissue_max;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2841 overlay float P_ambient_altitude;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2842 overlay signed char search_direction;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2843 overlay unsigned int nofly_N2 = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2844 overlay unsigned int nofly_He = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2845 overlay unsigned int nofly_last = ~0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2846
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2847
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2848 ci -= 1;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2849
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2850 read_Buhlmann_ht();
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2851 read_Buhlmann_coefficients();
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2852
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2853 // get selected target altitude
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2854 switch( char_I_altitude_wait )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2855 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2856 case 1: P_ambient_altitude = P_ambient_1000m; break;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2857 case 2: P_ambient_altitude = P_ambient_2000m; break;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2858 case 3: P_ambient_altitude = P_ambient_3000m; break;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2859 default: P_ambient_altitude = P_ambient_fly; break;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2860 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2861
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2862 // Target pressure for the tissue is the Buhlmann limit. We use the Buhlmann
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2863 // coefficients for N2 also for He because it is easier to calculate and the
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2864 // N2 coefficients are more conservative than those for He, so we are on the
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2865 // safe side, too.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2866 pres_tissue_max = (P_ambient_altitude/var_N2_b + var_N2_a);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2867
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2868 // Adjust target pressure in case the GF model is in use by GF-high
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2869 if( char_I_deco_model != 0 )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2870 pres_tissue_max = P_ambient_altitude +
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2871 0.01 * char_I_GF_High_percentage * (pres_tissue_max - P_ambient_altitude);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2872
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2873
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2874 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2875 // Desaturation time
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2876 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2877
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2878 // N2: actual amount of tissue pressure above equilibrium.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2879 pres_actual = pres_tissue_N2[ci] - N2_equilibrium;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2880
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2881 // N2: half-time of the current tissue
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2882 var_ht = var_N2_ht;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2883
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2884 // Calculate desaturation time for N2 in tissue.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2885 // Desaturated state is defined as residual tissue pressure <= 1.05 x ppN2 respired
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2886
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2887 pres_target = 0.05 * N2_equilibrium;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2888
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2889 calc_desaturation_time_helper();
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2890
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2891 if( int_time > int_O_desaturation_time) int_O_desaturation_time = int_time;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2892
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2893
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2894 // He: actual amount of tissue pressure above equilibrium: equilibrium for He is 0 bar
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2895 pres_actual = pres_tissue_He[ci];
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2896
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2897 // He: half-time of the current tissue
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2898 var_ht = var_He_ht;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2899
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2900 // Calculate desaturation time for He in the tissue.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2901 // Desaturated state is defined as residual tissue pressure <= 0.05 x ppN2 respired
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2902
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2903 pres_target = 0.05 * N2_equilibrium;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2904
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2905 calc_desaturation_time_helper();
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2906
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2907 if( int_time > int_O_desaturation_time) int_O_desaturation_time = int_time;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2908
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2909
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2910 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2911 // no-fly time
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2912 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2913
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2914 // initialize search direction
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2915 search_direction = 0;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2916
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2917 for(;;)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2918 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2919 // N2: actual amount of tissue pressure above equilibrium.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2920 pres_actual = pres_tissue_N2[ci] - N2_equilibrium;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2921
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2922 // N2: half-time of the current tissue
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2923 var_ht = var_N2_ht;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2924
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2925 // Calculate no-fly time for N2 in the tissue.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2926 // Flying is permitted when the N2 pressure fits into the assigned fraction above equilibrium.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2927
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2928 pres_target = (split_N2_He[ci] * 0.01) * (pres_tissue_max - N2_equilibrium);
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2929
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2930 if( pres_target < 0.0 ) // check if desaturation to fly target is possible
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2931 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2932 int_O_nofly_time = 288; // NO - set no-fly time to 288 * 10 min = 48 h
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2933 break; // done for this compartment
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2934 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2935 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2936 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2937 calc_desaturation_time_helper();
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2938 nofly_N2 = int_time;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2939 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2940
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2941 // He: actual amount of tissue pressure above equilibrium - equilibrium for He is 0 bar.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2942 pres_actual = pres_tissue_He[ci];
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2943
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2944 // He: half-time of the current tissue
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2945 var_ht = var_He_ht;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2946
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2947 // Calculate no-fly time for He in the tissue.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2948 // Flying is permitted when the He pressure fits into the assigned fraction.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2949
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2950 pres_target = (0.01 * (100 - split_N2_He[ci])) * (pres_tissue_max - N2_equilibrium);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2951
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2952 calc_desaturation_time_helper();
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2953 nofly_He = int_time;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2954
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2955
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2956 // Because the sum of N2 and He tissue pressures needs to fit into the Buhlmann limit for
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2957 // no-fly time calculation, each gas gets assigned a fraction of the available total pressure
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2958 // limit. The optimum split between the two gases can not be computed by a single formular,
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2959 // because this would require the inversion of a function with two exponential terms, which is
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2960 // not possible. We do not want to do a computational complex simulation here like it is done
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2961 // in the deco calculation code (although we tackle the same base problem here), so we just let
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2962 // the computer try out which split will balance the no-fly times induced by the N2 and the He
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2963 // at best.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2964
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2965 // first of all, skip any optimization in case the current compartment is not the leading one
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2966 if( (nofly_N2 <= int_O_nofly_time) && (nofly_He <= int_O_nofly_time) ) break;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2967
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2968 // check if the N2 requires more waiting time than the He
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2969 if( nofly_N2 >= nofly_He )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2970 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2971 // check if the search direction has changed, which means we are beyond the
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2972 // optimum now, or if we are at the upper stop limit of split_N2_He
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2973 if( (search_direction < 0) || (split_N2_He[ci] == 99) )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2974 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2975 // Either the just completed iteration was more close to the optimum or the one before
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2976 // was, so we take the best (i.e. shortest) time of both as the final no-fly time.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2977 int_O_nofly_time = (nofly_N2 < nofly_last) ? nofly_N2 : nofly_last;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2978 break;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2979 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2980
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2981 // store the no-fly time found in this iteration
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2982 nofly_last = nofly_N2;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2983
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2984 // increase the N2 fraction of the split and set search direction towards more N2
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2985 split_N2_He[ci] += 1;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2986 search_direction = +1;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2987 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2988 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2989 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2990 // check if the search direction has changed, which means we are beyond the
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2991 // optimum now, or if we are at the lower stop limit of split_N2_He
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2992 if( (search_direction > 0) || (split_N2_He[ci] == 1) )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2993 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2994 // Either the just completed iteration was more close to the optimum or the one before
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2995 // was, so we take the best (i.e. shortest) time of both as the final no-fly time.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2996 int_O_nofly_time = (nofly_He < nofly_last) ? nofly_He : nofly_last;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2997 break;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2998 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2999
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3000 // store the no-fly time found in this iteration
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3001 nofly_last = nofly_He;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3002
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3003 // decrease the N2 fraction of the split and set search direction towards less N2
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3004 split_N2_He[ci] -= 1;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3005 search_direction = -1;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3006 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3007
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3008 } // for(;;)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3009
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3010 } // for(compartments)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3011
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3012
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3013 // Rescale int_O_desaturation_time and int_O_nofly_time to full minutes for display purpose
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3014 int_O_desaturation_time *= 10;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3015 int_O_nofly_time *= 10;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3016
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3017 // Limit int_O_desaturation_time and int_O_nofly_time to 5999 = 99 hours + 59 minutes
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3018 // because of display space constraints and rounding done above.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3019 if( int_O_desaturation_time > 5999 ) int_O_desaturation_time = 5999;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3020 if( int_O_nofly_time > 5999 ) int_O_nofly_time = 5999;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3021
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3022
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3023 // Clear the microbubbles warning when the current gradient factor is < GF_WARNING_THRESHOLD.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3024 // As the locked warning will stay set, this will cause the warning be be displayed in attention
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3025 // color instead of warning color.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3026 if( int_O_gradient_factor < GF_WARNING_THRESHOLD )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3027 char_O_deco_warnings &= ~DECO_WARNING_MBUBBLES;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3028
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3029 // clear some warnings when the desaturation time has become zero
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3030 if( int_O_desaturation_time == 0 )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3031 char_O_deco_warnings &= ~( DECO_WARNING_IBCD + DECO_WARNING_IBCD_lock
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3032 + DECO_WARNING_MBUBBLES + DECO_WARNING_MBUBBLES_lock
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3033 + DECO_WARNING_OUTSIDE + DECO_WARNING_OUTSIDE_lock );
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3034
0
heinrichsweikamp
parents:
diff changeset
3035 }
heinrichsweikamp
parents:
diff changeset
3036
heinrichsweikamp
parents:
diff changeset
3037 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3038 // Calculate desaturation of the real tissues for a given time interval
0
heinrichsweikamp
parents:
diff changeset
3039 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3040 // Caution: Works on the real tissues!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3041 // If in doubt, use this function only inside a context surrounded with
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3042 // push_tissues_to_vault() / pull_tissues_from_vault() !
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3043 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3044 // Input: int_I_pres_surface : surface pressure in mbar
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3045 // time_interval : time interval in minutes, must be limited to 254 at max
0
heinrichsweikamp
parents:
diff changeset
3046 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3047 // Modified: tissue pressures
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3048 // CNS value
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3049 // ceiling and current GF
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3050 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3051 static void calc_interval(PARAMETER unsigned char time_interval)
0
heinrichsweikamp
parents:
diff changeset
3052 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3053 overlay unsigned char time;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3054
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3055
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3056 assert( 800 < int_I_pres_surface && int_I_pres_surface < 1100 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3057 assert( 100 <= char_I_saturation_multiplier && char_I_saturation_multiplier < 200 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3058 assert( 0 < char_I_desaturation_multiplier && char_I_desaturation_multiplier <= 100 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3059
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3060
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3061 // setup input data for deco routines
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3062 pres_respiration = pres_surface = 0.001 * int_I_pres_surface ;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3063
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3064 N2_ratio = 0.7902; // according to Buhlmann
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3065 N2_equilibrium = N2_ratio * (pres_surface - ppWater); // used for N2 tissue graphics scaling
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3066 ppN2 = N2_ratio * (pres_respiration - ppWater);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3067 ppHe = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3068
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3069 float_desaturation_multiplier = 0.01 * char_I_desaturation_multiplier * SURFACE_DESAT_FACTOR;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3070 float_saturation_multiplier = 0.01 * char_I_saturation_multiplier;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3071
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3072
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3073 // Calculate the tissues:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3074 // Because calc_tissues() can calculate for 127 minutes at max,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3075 // the tissue updating may need to be done in two chunks.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3076
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3077 time = time_interval;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3078
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3079 // first chunk for the part exceeding 127 minutes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3080 if( time > 127)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3081 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3082 // do a full 127 minutes on the real tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3083 tissue_increment = 127 | TISSUE_FLAG;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3084 calc_tissues();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3085
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3086 // determine the remaining part
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3087 time -= 127;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3088 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3089
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3090 // program the remaining part (or full part if not exceeding 127 minutes)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3091 tissue_increment = time | TISSUE_FLAG;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3092
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3093 // update the N2 and He pressures in the tissues for the remaining part of the time interval
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3094 calc_tissues();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3095
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3096
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3097 // Calculate CNS:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3098 // To speed up things and because on most invocations of this code char_I_dive_interval
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3099 // is a multiple of 10 minutes, we loop the loop-counter down using two speeds.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3100
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3101 time = time_interval;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3102
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3103 while ( time )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3104 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3105 if( time > 9 )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3106 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3107 CNS_fraction *= 0.925874712; // Half-time = 90min -> 10 min: (1/2)^(1/9)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3108 time -= 10; // fast speed looping
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3109 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3110 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3111 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3112 CNS_fraction *= 0.992327946; // Half-time = 90min -> 1 min: (1/2)^(1/90)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3113 time -= 1; // slow speed looping
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3114 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3115 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3116
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3117 // compute integer copy of CNS value
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3118 convert_CNS_for_display();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3119
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3120
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3121 // calculate ceiling (for a GF high of 100%) and gradient factor
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3122 calc_limit(1.0);
0
heinrichsweikamp
parents:
diff changeset
3123 }
heinrichsweikamp
parents:
diff changeset
3124
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3125
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3126 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3127 // calc_CNS_increment
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3128 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3129 // Input: char_ppO2 : current ppO2 [decibars]
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3130 // tissue_increment : time increment and tissue selector
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3131 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3132 // Output: CNS_fraction_inc : increment of the CNS value
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3133 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3134 void calc_CNS_increment(void)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3135 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3136 overlay float time_factor = 1.0; // default is 2sec
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3137
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3138 assert( char_ppO2 > 15 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3139
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3140 // All deco code is now invoked every second. But as the CNS update is based on
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3141 // 2 seconds periods, we skip every 2nd seconds-based invocation of this function.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3142 // TISSUE_FLAG = 128 (flag for "real" CNS) + 0 (2 seconds period)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3143 // To distribute computational load, the CNS% is calculated in "the other second"
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3144 // than the tissues.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3145 if( (tissue_increment == TISSUE_FLAG) && (twosectimer) ) return;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3146
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3147 // adjust time factor if minute-based stepping is commanded, mask out flag bit
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3148 if( tissue_increment & TIME_MASK ) time_factor = 30.0 * (float)(tissue_increment & TIME_MASK);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3149
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3150
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3151 //------------------------------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3152 // Don't increase CNS below 0.5 bar, but keep it steady.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3153 if (char_ppO2 < 50) CNS_fraction_inc = 0; // no CNS increase below 0.5 bar ppO2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3154 //------------------------------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3155 // Below (and including) 1.60 bar
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3156 else if (char_ppO2 < 61) CNS_fraction_inc = time_factor/(-533.07 * char_ppO2 + 54000.0);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3157 else if (char_ppO2 < 71) CNS_fraction_inc = time_factor/(-444.22 * char_ppO2 + 48600.0);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3158 else if (char_ppO2 < 81) CNS_fraction_inc = time_factor/(-355.38 * char_ppO2 + 42300.0);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3159 else if (char_ppO2 < 91) CNS_fraction_inc = time_factor/(-266.53 * char_ppO2 + 35100.0);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3160 else if (char_ppO2 < 111) CNS_fraction_inc = time_factor/(-177.69 * char_ppO2 + 27000.0);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3161 else if (char_ppO2 < 152) CNS_fraction_inc = time_factor/( -88.84 * char_ppO2 + 17100.0);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3162 else if (char_ppO2 < 167) CNS_fraction_inc = time_factor/(-222.11 * char_ppO2 + 37350.0);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3163 //------------------------------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3164 // Arieli et all.(2002): Modeling pulmonary and CNS O2 toxicity:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3165 // J Appl Physiol 92: 248--256, 2002, doi:10.1152/japplphysiol.00434.2001
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3166 // Formula (A1) based on value for 1.55 and c=20
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3167 // example calculation: Sqrt((1.7/1.55)^20)*0.000404
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3168 else if (char_ppO2 < 172) CNS_fraction_inc = time_factor*0.00102;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3169 else if (char_ppO2 < 177) CNS_fraction_inc = time_factor*0.00136;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3170 else if (char_ppO2 < 182) CNS_fraction_inc = time_factor*0.00180;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3171 else if (char_ppO2 < 187) CNS_fraction_inc = time_factor*0.00237;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3172 else if (char_ppO2 < 192) CNS_fraction_inc = time_factor*0.00310;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3173 else if (char_ppO2 < 198) CNS_fraction_inc = time_factor*0.00401;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3174 else if (char_ppO2 < 203) CNS_fraction_inc = time_factor*0.00517;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3175 else if (char_ppO2 < 233) CNS_fraction_inc = time_factor*0.0209;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3176 else CNS_fraction_inc = time_factor*0.0482; // value for 2.5 bar, used for 2.33 bar and above
0
heinrichsweikamp
parents:
diff changeset
3177 }
heinrichsweikamp
parents:
diff changeset
3178
heinrichsweikamp
parents:
diff changeset
3179 //////////////////////////////////////////////////////////////////////////////
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3180 // calc_CNS_planning
0
heinrichsweikamp
parents:
diff changeset
3181 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3182 // Compute CNS increase during predicted ascent
0
heinrichsweikamp
parents:
diff changeset
3183 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3184 // Input: internal_deco_time[], internal_deco_depth[], internal_deco_gas[]
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3185 // Output: sim_CNS_fraction
0
heinrichsweikamp
parents:
diff changeset
3186 //
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3187 void calc_CNS_planning(void)
0
heinrichsweikamp
parents:
diff changeset
3188 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3189 // null sim_CNS_fraction
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3190 sim_CNS_fraction = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3191
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3192 //---- CCR mode : do the full TTS at once ---------------------------------
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3193
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3194 if( ((char_O_deco_status & DECO_MODE_MASK) == DECO_MODE_CCR) )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3195 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3196 overlay unsigned short t; // needs 16 bits here !
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3197
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3198 // get current ppO2 from sensors or setpoint
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3199 char_ppO2 = char_I_const_ppO2;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3200
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3201 // calculate CNS% for the period of additional staying at bottom depth (fTTS / delayed ascent)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3202 if( char_O_deco_status & DECO_ASCENT_DELAYED)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3203 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3204 tissue_increment = char_I_extra_time; // must be limited to 127, is limited by range of char_I_extra_time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3205 calc_CNS_increment(); // calculate the CNS increment
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3206 sim_CNS_fraction += CNS_fraction_inc; // sum up
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3207 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3208
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3209 // get the ascent time dependent on the current plan
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3210 t = (char_O_deco_status & DECO_PLAN_ALTERNATE) ? int_O_alternate_ascenttime : int_O_ascenttime;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3211
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3212 // start simulating CNS% in chunks of 127 minutes
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3213 tissue_increment = 127;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3214
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3215 while( t > 127 )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3216 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3217 t -= 127; // tissue_increment is limited to 127 minutes because of flag in bit 7
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3218 calc_CNS_increment(); // calculate CNS in chunks of full 127 minutes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3219 sim_CNS_fraction += CNS_fraction_inc; // sum up
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3220 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3221
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3222 tissue_increment = (char)t; // get the remaining minutes <= 127
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3223 calc_CNS_increment(); // calculate CNS for the remaining minutes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3224 sim_CNS_fraction += CNS_fraction_inc; // sum up
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3225 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3226 else //---- OC mode and pSCR without sensors: have to follow all gas switches... -----
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3227 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3228 overlay float float_actual_ppO2;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3229 overlay float abs_pres;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3230
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3231 overlay unsigned char stop_depth;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3232 overlay unsigned char last_gas;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3233 overlay unsigned char i; // stop table index
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3234
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3235
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3236 // retrieve bottom gas: 1-5 for the configured gases or 0 for the manually set gas
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3237 last_gas = sim_gas_last_used = sim_gas_first_used;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3238
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3239 // get the calc_N2/He/O2_ratios of the bottom gas
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3240 gas_set_ratios();
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3241
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3242 // calculate absolute pressure
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3243 abs_pres = pres_surface + bottom_depth * METER_TO_BAR;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3244
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3245 // calculate OC ppO2 (ppWater omitted here on purpose)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3246 float_actual_ppO2 = abs_pres * sim_O2_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3247
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3248 // correct ppO2 in case of pSCR mode by drop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3249 if( char_O_deco_status & DECO_MODE_PSCR ) float_actual_ppO2 -= sim_pSCR_drop;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3250
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3251 // convert ppO2 from float to char
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3252 if ( float_actual_ppO2 < 0.0 ) char_ppO2 = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3253 else if ( float_actual_ppO2 > 2.545 ) char_ppO2 = 255;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3254 else char_ppO2 = (unsigned char)(100 * float_actual_ppO2 + 0.5);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3255
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3256
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3257 // simulate extended bottom time (fTTS) / delay before ascent (bailout) if configured
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3258 if( char_O_deco_status & DECO_ASCENT_DELAYED )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3259 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3260 tissue_increment = char_I_extra_time; // must be limited to 127, is limited by range of char_I_extra_time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3261 calc_CNS_increment(); // calculate the CNS increment
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3262 sim_CNS_fraction += CNS_fraction_inc; // sum up
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3263 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3264
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3265
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3266 // For simplicity reason (non-linearity of the relation between ppO2 and CNS increments), the
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3267 // whole ascent is calculated with bottom ppO2. This errs, but it does so to the safe side.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3268
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3269 // calculate ascent time (integer division and generous round-up)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3270 tissue_increment = bottom_depth / char_I_ascent_speed + 1;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3271
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3272 // ** commented out - not needed when char_I_ascent_speed is limited to a minimum
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3273 // ** of 2.something, it is indeed limited to a minimum of 5.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3274 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3275 // // limit tissue_increment to 127 minutes
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3276 // if( tissue_increment > 127 ) tissue_increment = 127;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3277
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3278 // simulate the CNS increase
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3279 calc_CNS_increment(); // calculate the CNS increment
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3280 sim_CNS_fraction += CNS_fraction_inc; // sum up
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3281
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3282
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3283 //---- Stops ---------------------------------------------------------
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3284
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3285 for(i=0; i<NUM_STOPS; ++i)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3286 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3287 // get the depth of the stop
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3288 stop_depth = internal_deco_depth[i];
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3289
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3290 // did we reach the last entry (depth = 0)? if yes, done
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3291 if (stop_depth == 0) break;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3292
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3293 // get the duration of the stop and the gas breathed
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3294 tissue_increment = internal_deco_time[i];
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3295 sim_gas_last_used = internal_deco_gas[i];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3296
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3297 // do we have a gas switch?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3298 if( sim_gas_last_used != last_gas )
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3299 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3300 // yes - get new calculation ratios
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3301 gas_set_ratios();
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3302
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3303 // remember new gas as last gas
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3304 last_gas = sim_gas_last_used;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3305 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3306
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3307 // calculate absolute pressure at stop depth
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3308 abs_pres = pres_surface + stop_depth * METER_TO_BAR;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3309
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3310 // calculate OC ppO2 (ppWater omitted here on purpose)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3311 float_actual_ppO2 = abs_pres * sim_O2_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3312
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3313 // correct ppO2 in case of pSCR mode by drop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3314 if( char_O_deco_status & DECO_MODE_PSCR ) float_actual_ppO2 -= sim_pSCR_drop;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3315
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3316 // convert ppO2 from float to char
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3317 if ( float_actual_ppO2 < 0.0 ) char_ppO2 = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3318 else if ( float_actual_ppO2 > 2.545 ) char_ppO2 = 255;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3319 else char_ppO2 = (unsigned char)(100 * float_actual_ppO2 + 0.5);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3320
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3321 // ** Currently, stop times per stop entry are limited to 99 minutes in update_deco_table(),
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3322 // ** so the following code block is not needed at times.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3323 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3324 // // tissue_increment is limited to 127 when fed to calc_CNS_increment(),
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3325 // // so if the stop is longer than 127 minutes (but not longer than 254 minutes!)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3326 // // we need to calculate the CNS in two chunks.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3327 // if( tissue_increment > 127)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3328 // {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3329 // tissue_increment -= 127; // subtract full 127 minutes and do the "remaining" minutes first
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3330 // calc_CNS_increment(); // calculate the CNS increment
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3331 // sim_CNS_fraction += CNS_fraction_inc; // sum up
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3332 // tissue_increment = 127; // catch up with the previously subtracted full 127 minutes
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3333 // }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3334
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3335 // calculate CNS% for the stop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3336 calc_CNS_increment(); // calculate the CNS increment
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3337 sim_CNS_fraction += CNS_fraction_inc; // sum up
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3338 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3339 }
0
heinrichsweikamp
parents:
diff changeset
3340 }
heinrichsweikamp
parents:
diff changeset
3341
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3342
0
heinrichsweikamp
parents:
diff changeset
3343 //////////////////////////////////////////////////////////////////////////////
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3344 // gas_volumes
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3345 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3346 // calculates volumes and required tank fill pressures for each gas.
0
heinrichsweikamp
parents:
diff changeset
3347 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3348 // Input: bottom_depth depth of the bottom segment
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3349 // char_I_bottom_time duration of the bottom segment
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3350 // char_I_extra_time extra bottom time for fTTS / delayed ascent
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3351 // float_ascent_speed ascent speed, in meters/minute
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3352 // sim_gas_first_used the bottom gas (1-5 for configured gases, 0 for the manual gas)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3353 // internal_deco_depth[] depth of the stops
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3354 // internal_deco_time[] duration of the stops
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3355 // internal_deco_gas[] gas breathed at the stops
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3356 // char_I_bottom_usage gas consumption during bottom part and initial ascent, in liters/minute
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3357 // char_I_deco_usage gas consumption during stops and following ascents, in liters/minute
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3358 // char_I_tank_size[] size of the tanks for gas 1-5, in liters
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3359 // char_I_tank_pres_fill[] fill pressure of the tanks
0
heinrichsweikamp
parents:
diff changeset
3360 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3361 // Output: int_O_gas_volumes[] amount of gas needed, in liters
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3362 // int_O_tank_pres_need[] in bar, + flags for fast evaluation by dive mode warnings:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3363 // 2^15: pres_need >= pres_fill
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3364 // 2^14: pres_need >= press_fill * GAS_NEEDS_ATTENTION_THRESHOLD
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3365 // 2^11: pres_need == 0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3366 // 2^10: pres_need invalid
0
heinrichsweikamp
parents:
diff changeset
3367 //
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3368 void gas_volumes_helper(void)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3369 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3370 // Calculate the gas volume needed at a given depth, time and usage (SAC rate).
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3371 // We use 1.0 for the surface pressure to have stable results when used through
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3372 // the deco calculator (simulation mode).
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3373 volume = (float_depth * METER_TO_BAR + 1.0) * float_time * usage;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3374
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3375 return;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3376 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3377
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3378 void gas_volumes(void)
0
heinrichsweikamp
parents:
diff changeset
3379 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3380 overlay float volumes[NUM_GAS];
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3381
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3382 overlay unsigned char stop_gas;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3383 overlay unsigned char stop_gas_last;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3384 overlay unsigned char stop_time;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3385 overlay unsigned char stop_depth;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3386 overlay unsigned char stop_depth_last;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3387 overlay unsigned char i;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3388
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3389
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3390 //---- initialization ----------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3391
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3392 // null the volume accumulators
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3393 for(i=0; i<NUM_GAS; ++i) volumes[i] = 0.0;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3394
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3395 // quit for CCR and pSCR mode
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3396 if( char_O_deco_status & DECO_MODE_LOOP ) goto done;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3397
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3398
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3399 //---- bottom demand -----------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3400
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3401 // sim_gas_first_used : gas used during bottom segment (0, 1-5)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3402 // bottom_depth: depth of the bottom segment
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3403
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3404 assert(0 <= sim_gas_first_used && sim_gas_first_used <= NUM_GAS);
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3405
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3406 // get the gas used during bottom segment
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3407 stop_gas_last = stop_gas = sim_gas_first_used;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3408
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3409 // set the usage (SAC rate) to bottom usage rate for bottom part and initial ascent
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3410 usage = char_I_bottom_usage;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3411
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3412 // volumes are only calculated for gases 1-5, but not the manually configured one
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3413 if( stop_gas )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3414 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3415 // set the bottom depth
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3416 float_depth = (float)bottom_depth;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3417
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3418 // calculate either bottom segment or just the fTTS/bailout delayed part
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3419 if( char_O_main_status & DECO_BOTTOM_CALCULATE )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3420 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3421 // duration of bottom segment
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3422 float_time = (float)char_I_bottom_time;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3423 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3424 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3425 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3426 // duration of delayed ascent
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3427 float_time = (float)char_I_extra_time;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3428 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3429
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3430 // calculate gas demand
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3431 gas_volumes_helper();
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3432
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3433 // take result
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3434 volumes[stop_gas-1] = volume;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3435 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3436
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3437 // initialize stop index with first stop
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3438 i = 0;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3439
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3440 //---- initial ascent demand ---------------------------------------------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3441
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3442 // stop_gas : gas from bottom segment
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3443 // bottom_depth : depth of the bottom segment
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3444 // internal_deco_depth[i=0]: depth of the first stop, may be 0 if no stop exists
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3445
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3446 // get the data of the first stop
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3447 stop_depth = internal_deco_depth[i];
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3448 stop_time = internal_deco_time[i];
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3449
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3450 // volumes are only calculated for gases 1-5, but not the manually configured one
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3451 if( stop_gas )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3452 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3453 // compute distance between bottom and first stop
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3454 float_depth = (float)bottom_depth - (float)stop_depth;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3455
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3456 // initial ascent exists only if ascent distance is > 0
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3457 if( float_depth > 0.0 )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3458 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3459 // compute ascent time
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3460 float_time = float_depth / float_ascent_speed;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3461
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3462 // compute average depth between bottom and first stop
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3463 float_depth = (float)bottom_depth - float_depth * 0.5;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3464
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3465 // calculate gas demand
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3466 gas_volumes_helper();
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3467
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3468 // add result
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3469 volumes[stop_gas-1] += volume;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3470 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3471 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3472
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3473 // switch the usage (SAC rate) to deco usage rate
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3474 // for stops, intermediate and final ascent
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3475 usage = char_I_deco_usage;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3476
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3477 // is there a (first) stop? if yes, goto stops processing
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3478 if( stop_depth ) goto stops;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3479
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3480 // add demand of a 3 minutes safety stop at 5 meters, at least for contingency...
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3481 float_time = 3.0;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3482 float_depth = 5.0;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3483
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3484 // calculate gas demand
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3485 gas_volumes_helper();
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3486
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3487 // add result
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3488 volumes[stop_gas-1] += volume;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3489
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3490 // proceed to volume conversion and pressure calculations
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3491 goto done;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3492
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3493
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3494 //---- intermediate ascent demand ---------------------------------------
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3495 inter_ascents:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3496
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3497 // store last stop depth and gas
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3498 stop_depth_last = stop_depth;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3499 stop_gas_last = stop_gas;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3500
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3501 // check if we are at the end of the stops table
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3502 if( i < NUM_STOPS-1 )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3503 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3504 // there are more entries - get the next stop data
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3505 i++;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3506
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3507 // get the next stop depth
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3508 stop_depth = internal_deco_depth[i];
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3509
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3510 // check if there is indeed another stop,
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3511 // if not (depth = 0) treat as end of table
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3512 if( stop_depth == 0 ) goto end_of_table;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3513
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3514 // get the next stop duration
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3515 stop_time = internal_deco_time[i];
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3516 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3517 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3518 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3519 end_of_table:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3520
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3521 // End of the stops table reached or no more stops: Split the remaining
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3522 // ascent into an intermediate ascent and a final ascent by creating a
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3523 // dummy stop at the usual last deco stop depth. Stop gas doesn't change.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3524 stop_time = 0;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3525 stop_depth = char_I_depth_last_deco;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3526 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3527
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3528 // volumes are only calculated for gases 1-5, but not the manually configured one
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3529 if( stop_gas_last )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3530 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3531 // compute distance between the two stops:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3532 // last stop will always be deeper than current stop
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3533 float_depth = (float)(stop_depth_last - stop_depth);
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3534
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3535 // compute ascent time
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3536 float_time = float_depth / float_ascent_speed;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3537
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3538 // compute average depth between the two stops
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3539 float_depth = (float)stop_depth_last - float_depth * 0.5;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3540
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3541 // calculate gas demand
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3542 gas_volumes_helper();
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3543
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3544 // add result
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3545 volumes[stop_gas_last-1] += volume;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3546 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3547
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3548
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3549 //---- next stop demand -------------------------------------------------
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3550 stops:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3551
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3552 // convert depth of the stop
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3553 float_depth = (float)stop_depth;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3554
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3555 // get the next gas
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3556 stop_gas = internal_deco_gas[i];
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3557
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3558 // do we we have a gas change?
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3559 if( stop_gas_last && (stop_gas != stop_gas_last) )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3560 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3561 // yes - spend an additional char_I_gas_change_time on the old gas
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3562 float_time = (float)char_I_gas_change_time;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3563
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3564 // calculate gas demand
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3565 gas_volumes_helper();
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3566
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3567 // add result
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3568 volumes[stop_gas_last-1] += volume;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3569 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3570
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3571 // calculate and add demand on new gas for the full stop duration
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3572 if( stop_gas )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3573 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3574 // get the duration of the stop
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3575 float_time = (float)stop_time;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3576
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3577 // calculate gas demand
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3578 gas_volumes_helper();
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3579
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3580 // add result to last gas
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3581 volumes[stop_gas-1] += volume;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3582 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3583
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3584 // continue with the next intermediate ascent if this was not the last stop
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3585 if( stop_depth > char_I_depth_last_deco ) goto inter_ascents;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3586
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3587
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3588 //---- final ascent demand -----------------------------------------------
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3589 final_ascent:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3590
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3591 // float_depth: depth of last stop
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3592 // stop_gas : gas from last stop (0 or 1-5)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3593
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3594 // volumes are only calculated for gases 1-5, but not the manually configured one
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3595 if( stop_gas )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3596 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3597 // set ascent time according to an ascent speed of 1 meter per minute
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3598 float_time = float_depth;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3599
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3600 // set half-way depth
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3601 float_depth *= 0.5;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3602
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3603 // calculate gas demand
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3604 gas_volumes_helper();
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3605
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3606 // add result
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3607 volumes[stop_gas-1] += volume;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3608 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3609
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3610
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3611 //---- convert results for the assembler interface -----------------------------
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3612 done:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3613
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3614 for(i=0; i<NUM_GAS; ++i)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3615 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3616 if( volumes[i] >= 65534.5 )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3617 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3618 int_O_gas_volumes[i] = 65535;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3619 int_O_tank_pres_need[i] = 999 + INT_FLAG_WARNING; // 999 bar + warning flag for > pres_fill
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3620 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3621 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3622 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3623 overlay unsigned short tank_pres_fill = 10.0 * (unsigned short)char_I_tank_pres_fill[i];
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3624
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3625 // No distinct rounding done here because volumes are not accurate to the single liter anyhow
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3626
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3627 // convert gas volumes to integers
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3628 int_O_gas_volumes[i] = (unsigned short)volumes[i];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3629
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3630 // compute how much pressure in the tank will be needed [in bar] (integer-division)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3631 int_O_tank_pres_need[i] = (unsigned short)(int_O_gas_volumes[i] / char_I_tank_size[i]);
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3632
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3633 // limit to 999 bar because of display constraints
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3634 if( int_O_tank_pres_need[i] > 999 ) int_O_tank_pres_need[i] = 999;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3635
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3636 // set flags for fast evaluation by divemode check for warnings
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3637 if ( int_O_tank_pres_need[i] == 0 )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3638 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3639 // set flag for 0 bar
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3640 int_O_tank_pres_need[i] |= INT_FLAG_ZERO;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3641 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3642 else if( int_O_tank_pres_need[i] >= tank_pres_fill )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3643 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3644 // set warning flag
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3645 int_O_tank_pres_need[i] |= INT_FLAG_WARNING;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3646
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3647 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3648 else if( int_O_tank_pres_need[i] >= tank_pres_fill * GAS_NEEDS_ATTENTION_THRESHOLD )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3649 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3650 // set pre-warning flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3651 int_O_tank_pres_need[i] |= INT_FLAG_ATTENTION;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3652 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3653
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3654 // set invalid flag if there is an overflow in the stops table
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3655 if( char_O_deco_warnings & DECO_WARNING_STOPTABLE_OVERFLOW )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3656 int_O_tank_pres_need[i] |= INT_FLAG_INVALID;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3657
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3658 } // if( volumes[i] )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3659 } // for
0
heinrichsweikamp
parents:
diff changeset
3660 }
heinrichsweikamp
parents:
diff changeset
3661
heinrichsweikamp
parents:
diff changeset
3662 //////////////////////////////////////////////////////////////////////////////
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3663
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3664 void convert_CNS_for_display(void)
0
heinrichsweikamp
parents:
diff changeset
3665 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3666 if ( CNS_fraction < 0.01 ) int_O_CNS_fraction = 0;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3667 else if ( CNS_fraction >= 9.985 ) int_O_CNS_fraction = 999 + INT_FLAG_WARNING;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3668 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3669 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3670 // convert float to integer
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3671 int_O_CNS_fraction = (unsigned short)(100 * CNS_fraction + 0.5);
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3672
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3673 // set warnings
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3674 if ( int_O_CNS_fraction >= CNS_WARNING_THRESHOLD ) int_O_CNS_fraction |= INT_FLAG_WARNING;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3675 else if ( int_O_CNS_fraction >= CNS_ATTENTION_THRESHOLD ) int_O_CNS_fraction |= INT_FLAG_ATTENTION;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3676 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3677 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3678
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3679 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3680
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3681 void convert_sim_CNS_for_display(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3682 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3683 if ( sim_CNS_fraction < 0.01 ) int_sim_CNS_fraction = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3684 else if ( sim_CNS_fraction >= 9.985 ) int_sim_CNS_fraction = 999 + INT_FLAG_WARNING;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3685 else
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3686 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3687 // convert float to integer
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3688 int_sim_CNS_fraction = (unsigned short)(100 * sim_CNS_fraction + 0.5);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3689
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3690 // set warning flag if CNS is >= 100%
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3691 if ( int_sim_CNS_fraction >= CNS_WARNING_THRESHOLD ) int_sim_CNS_fraction |= INT_FLAG_WARNING;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3692 else if ( int_sim_CNS_fraction >= CNS_ATTENTION_THRESHOLD ) int_sim_CNS_fraction |= INT_FLAG_ATTENTION;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3693
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3694 // set invalid flag if there is an overflow in the stops table
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3695 if( char_O_deco_warnings & DECO_WARNING_STOPTABLE_OVERFLOW ) int_sim_CNS_fraction |= INT_FLAG_INVALID;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3696 }
0
heinrichsweikamp
parents:
diff changeset
3697 }
heinrichsweikamp
parents:
diff changeset
3698
heinrichsweikamp
parents:
diff changeset
3699 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3700 // push_tissues_to_vault & pull_tissues_from_vault
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3701 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3702 // ATTENTION: Do not use from inside the deco engine!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3703 // The vault is exclusively reserved to back-up and restore the real
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3704 // tissues and related data when entering / leaving simulation mode!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3705 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3706
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3707 void push_tissues_to_vault(void)
0
heinrichsweikamp
parents:
diff changeset
3708 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3709 overlay unsigned char x;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3710
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3711 cns_vault_float = CNS_fraction;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3712 deco_warnings_vault = char_O_deco_warnings;
0
heinrichsweikamp
parents:
diff changeset
3713
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3714 for (x=0;x<NUM_COMP;x++)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3715 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3716 pres_tissue_N2_vault[x] = pres_tissue_N2[x];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3717 pres_tissue_He_vault[x] = pres_tissue_He[x];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3718 }
0
heinrichsweikamp
parents:
diff changeset
3719 }
heinrichsweikamp
parents:
diff changeset
3720
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3721 void pull_tissues_from_vault(void)
0
heinrichsweikamp
parents:
diff changeset
3722 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3723 overlay unsigned char x;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3724
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3725 CNS_fraction = cns_vault_float;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3726 char_O_deco_warnings = deco_warnings_vault;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3727
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3728 convert_CNS_for_display();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3729
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3730 locked_GF_step_norm = GF_delta / low_depth_norm;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3731 locked_GF_step_alt = GF_delta / low_depth_alt;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3732
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3733 for (x=0; x<NUM_COMP; x++)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3734 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3735 pres_tissue_N2[x] = pres_tissue_N2_vault[x];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3736 pres_tissue_He[x] = pres_tissue_He_vault[x];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3737 }
0
heinrichsweikamp
parents:
diff changeset
3738 }
heinrichsweikamp
parents:
diff changeset
3739
heinrichsweikamp
parents:
diff changeset
3740 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
3741 //
heinrichsweikamp
parents:
diff changeset
3742 #ifndef CROSS_COMPILE
heinrichsweikamp
parents:
diff changeset
3743 void main() {}
heinrichsweikamp
parents:
diff changeset
3744 #endif