annotate src/p2_deco.c @ 604:ca4556fb60b9

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