annotate src/p2_deco.c @ 613:8077ee960199

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