annotate src/p2_deco.c @ 641:1212d39c9f6f

3.14 beta work
author heinrichsweikamp
date Sat, 21 Nov 2020 17:46:29 +0100
parents 8c1f1f334275
children 1e695355dfc4
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 // ***************************************************************************
640
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 635
diff changeset
2 // p2_deco.c combined next generation V3.12.1
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
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
15 // the Free Software Foundation, either version 3 of the License, or
0
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
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0
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
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
24 // along with this program. If not, see <http://www.gnu.org/licenses/>.
0
heinrichsweikamp
parents:
diff changeset
25 //
heinrichsweikamp
parents:
diff changeset
26 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
27
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
28 // History:
0
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
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
33 // 03/13/25 v101: CNS_fraction_real calculation
0
heinrichsweikamp
parents:
diff changeset
34 // 03/13/26 v101: optimization of tissue calc routines
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
35 // 07/xx/2008 v102a: debug of bottom time routine
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
36 // 09/xx/2008 v102d: Gradient Factor Model implementation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
37 // 10/10/2008 v104: renamed to build v103 for v118 stable
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
38 // 10/14/2008 v104: integration of char_I_last_stop_depth for Gradient Model
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
39 // 03/31/2009 v107: integration of FONT Incon24
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
40 // 05/23/2010 v109: 5 gas changes & 1 min timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
41 // 07/13/2010 v110: cns vault added
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
42 // 12/25/2010 v110: split in three files (deco.c, main.c, definitions.h)
0
heinrichsweikamp
parents:
diff changeset
43 // 2011/01/20: [jDG] Create a common file included in ASM and C code.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
44 // 2011/01/24: [jDG] Make ascent time an short. No more overflow!
0
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.
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
50 // 2011/04/15: [jDG] Store GF_depth in 32 bits (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
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
61 // 2012/10/05: [jDG] Better calc_gas_needs_ascent accuracy (average depth, switch between stop).
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
62 // 2013/03/05: [jDG] Should vault GF_depth too.
0
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
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
90
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
91 #include <math.h>
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
92 #include "p2_definitions.h"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
93 #define TEST_MAIN
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
94 #include "shared_definitions.h"
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
95 #include "configuration.inc"
0
heinrichsweikamp
parents:
diff changeset
96
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
97
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
98 // *********************************************************************************************************************************
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 // 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
101 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
102 // *********************************************************************************************************************************
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
103
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
104
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
105 // deco engine scheduling
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
106 #define INVOKES_PER_SECOND 2 // number of invocations of the deco engine per second (use powers of 2 only: 1, 2, 4, ...)
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
107
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
108 #ifdef _hwos_sport
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
109 #define BUDGET_PER_SECOND 320 // [ms] total time budget per second for the deco engine, each invocation will preempt after BUDGET_PER_SECOND / INVOKES_PER_SECOND
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
110 #else
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
111 #define BUDGET_PER_SECOND 640 // [ms] total time budget per second for the deco engine, each invocation will preempt after BUDGET_PER_SECOND / INVOKES_PER_SECOND
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
112 #endif
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
113
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
114 // ambient pressure at different mountain heights
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
115 #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
116 #define P_ambient_2000m 0.782 // [bar]
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
117 #define P_ambient_3000m 0.695 // [bar]
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
118
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
119 // ambient pressure in aircraft cabin during flying - worst case according to Buhlmann
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
120 #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
121 // 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
122 // -----
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
123 // 0.135 bar safety margin
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
124
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
125 // constants and factors
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
126 #define ppWater 0.06270 // water vapor partial pressure in the lungs
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
127 #define METER_TO_BAR 0.09807 // conversion factor (1 m water column = 0.09807 bar)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
128 #define BAR_TO_METER 10.19716 // conversion factor (1 bar = 10.19716 m )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
129 #define SURFACE_DESAT_FACTOR 0.70420 // surface desaturation safety factor
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
130 #define HYST 1.0E-06 // threshold for tissue graphics on-gassing / off-gassing visualization
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
131
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
132 // thresholds
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
133 #define CNS_LIMIT_WARNING 100 // threshold for CNS warning
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
134 #define CNS_LIMIT_ATTENTION 70 // threshold for CNS attention
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
135 #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
136 #define PRESSURE_LIMIT_ATTENTION 500 // threshold for pressure reading attention: 50.0 bar
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
137 #define GAS_NEEDS_ATTENTION 0.7 // threshold for gas needs attention [1 = 100%]
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
138 #define O2_CONSUMPTION_LIMIT_ATTENTION 20 // threshold for O2 "SAC" attention: 2.0 l/min
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
139 #define ppO2_GAP_TO_SETPOINT 10 // gap between setpoint and max. ppO2 of the pure diluent [cbar]
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
140 #define ppO2_MARGIN_ON_MAX 3 // [cbar] margin on ppO2 max to compensate for surface pressures > 1.000 mbar
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
141 #define STOP_CHAINING_LIMIT 3 // max. number of chained stop table entries before deco calculation is aborted
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
142
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
143
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
144 // deco engine states and modes - (char_O_)main_status: controls current tissue and deco status calculation (as-is situation)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
145 #define CALC_VOLUME 0x01 // =1: calculate gas needs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
146 #define CALCULATE_BOTTOM 0x02 // =1: calculate gas needs in deco calculator mode, =0: in dive mode
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
147 #define CAVE_MODE 0x04 // =1: calculate return path and gas needs using backtracking data
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
148 #define GAS_CONTINGENCY 0x08 // =1: use a second best gas if best gas is all used up
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
149 #define TR_FUNCTIONS 0x10 // =1: calculate TR functions (pressure reading) processing
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
150 #define EXTENDED_STOPS 0x20 // =1: allow placement of gas switches below the depth of the 1st stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
151
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
152 #define MODE_MASK 0xC0 // mask for real tissues mode selection
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
153 #define MODE_LOOP 0x40 // =1: CCR (MODE_PSCR needs to be cleared) or pSCR mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
154 #define MODE_CCR 0x40 // to be used with == operator in combination with MODE_MASK only!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
155 #define MODE_PSCR 0x80 // =1: pSCR mode (MODE_LOOP needs to be set, too)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
156
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
157 // deco engine states and modes - (char_O_)deco_status: controls deco plan calculation (to-be scenario)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
158 #define PLAN_MASK 0x03 // bit mask covering normal & alternative plan flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
159 #define COMMAND_MASK 0x07 // bit mask covering all command flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
160 #define CALCULATING 0x00 // calculations are ongoing
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
161 #define START_NORM 0x01 // input: start calculation of a normal deco plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
162 #define CALC_NORM 0x01 // internal: calculating a normal deco plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
163 #define COMPLETED_NORM 0x01 // output: calculation of a normal deco plan has completed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
164 #define START_ALT 0x02 // input: start calculation of an alternative deco plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
165 #define CALC_ALT 0x02 // internal: calculating an alternative deco plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
166 #define COMPLETED_ALT 0x02 // output: calculation of an alternative deco plan has completed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
167 #define INITIALIZE 0x04 // input: initialize deco engine
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
168 #define INITIALIZE_START_NORM 0x05 // input: initialize deco engine and start calculation of a normal deco plan
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
169 #define INITIALIZE_START_ALT 0x06 // input: initialize deco engine and start calculation of an alternative deco plan
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
170 #define DECO_CALCULATOR_MODE 0x08 // input: deco engine is run from deco calculator
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
171
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
172 #define BAILOUT_MODE 0x10 // =1: allow gas switches before first deco stop
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
173 #define DELAYED_ASCENT 0x20 // =1: figure in a delayed ascent / delayed turn of the dive (fTTS)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
174
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
175 // MODE_MASK 0xC0 // mask for simulated tissues mode selection
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
176 // MODE_LOOP 0x40 // =1: CCR (MODE_PSCR needs to be cleared) or pSCR mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
177 // MODE_CCR 0x40 // to be used with == operator in combination with MODE_MASK only!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
178 // MODE_PSCR 0x80 // =1: pSCR mode (MODE_LOOP needs to be set, too)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
179
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
180
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
181 // deco engine warnings - (char_O_)deco_warnings
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
182 #define DECO_WARNING_IBCD 0x01 // IBCD occurring now
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
183 #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
184 #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
185 #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
186 #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
187 #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
188 #define DECO_ATTENTION_OUTSIDE 0x40 // tissue pressures are very close to the Buhlmann limit
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
189 #define DECO_WARNING_INCOMPLETE 0x80 // deco calculation incomplete due to too long compute time
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
190
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
191 // deco engine status (char_O_)deco_info
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
192 #define DECO_MODE 0x01 // =1: deco ppO2 levels are permitted
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
193 #define IND_DOUBLE_SWITCH_FLAG 0x02 // =1: switch to other tank advice active
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
194 #define GAS_NEEDS_fTTS 0x04 // =1: gas needs are calculated in fTTS mode
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
195 #define DECO_ZONE 0x08 // =1: fTTS < TTS (not updated when in bailout mode)
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
196 #define DECO_CEILING 0x10 // =1: deco obligation (ceiling > 0)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
197 #define DECO_STOPS_NORM 0x20 // =1: deco stops found in normal plan
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
198 #define DECO_STOPS_ALT 0x40 // =1: deco stops found in alternative plan
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
199 #define GAS_NEEDS_CAVE 0x80 // =1: indicated gas needs are calculated in cave mode
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
200
604
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 // deco engine control - tissue_increment
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
203 #define TIME_MASK 0x7F // =0: time increment is 2 or 6 seconds, 1..127: time increments is 1..127 minutes
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
204 #define TISSUE_SELECTOR 0x80 // =0: calculate on simulated tissues, 1 : calculate on real tissues
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
205
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
206
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
207 // deco engine control - next_planning_phase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
208 #define PHASE_00_DONE 0x00 // calculation cycle finished
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
209 #define PHASE_10_DIVE_INIT 0x10 // once-per-dive initialization of the deco engine
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
210 #define PHASE_20_CYCLIC_INIT 0x20 // once-every-cycle initialization of the deco engine
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
211 #define PHASE_30_EXTENDED_BOTTOM_TIME 0x30 // calculate extended bottom time
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
212 #define PHASE_40_BOTTOM_GAS_NEED 0x40 // calculate gas needs for bottom segment
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
213 #define PHASE_50_NDL_TIME 0x50 // calculate NDL time
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
214 #define PHASE_70_ASCENT_OR_RETURN 0x70 // calculate open water ascent or cave return
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
215 #define PHASE_80_RESULTS 0x80 // results - initialization
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
216 #define PHASE_81_RESULTS_STOPS_TABLE 0x81 // results - publish stops table
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
217 #define PHASE_82_RESULTS_NDL 0x82 // results - publish data / within NDL
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
218 #define PHASE_83_RESULTS_DECO 0x83 // results - publish data / in deco
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
219 #define PHASE_84_GAS_NEEDS_PRESSURES 0x84 // results - convert gas needs from volumes to pressures
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
220 #define PHASE_85_GAS_NEEDS_CAVE 0x85 // results - tag gas needs as calculated in cave or open water mode
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
221 #define PHASE_90_FINISH 0x90 // finish calculation cycle
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
222
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
223
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
224 // gas & diluent - type and availability state
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
225 // 0x01 // | 0: disabled, 1: first, 2: normal/work, 3: deco
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
226 // 0x02 // |
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
227 #define GAS_TYPE_MASK 0x03 // bit mask covering the type enumerator
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
228 #define GAS_AVAIL_LOST 0x04 // =1: gas/diluent lost flag (permanently unavailable)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
229 #define GAS_AVAIL_STAGED 0x08 // =1: gas/diluent staged flag (temporary unavailable)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
230 #define GAS_AVAIL_MASK 0x0C // bit mask covering the availability flags
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
231 #define GAS_NEED_ATTENTION 0x10 // =1: gas need >= attention threshold
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
232 #define GAS_NEED_WARNING 0x20 // =1: gas need >= warning threshold
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
233 #define GAS_NEED_MASK 0x30 // bit mask covering the need flags
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
234 #define GAS_NEARLY_USED_UP 0x40 // =1: the gas is nearly used up (= at attention threshold)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
235 #define GAS_FULLY_USED_UP 0x80 // =1: the gas is fully used up (= at warning threshold)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
236
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
237
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
238 // flags used with integer numbers
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
239 #define INT_FLAG_INVALID 0x0400 // =1: value not valid
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
240 #define INT_FLAG_NOT_COMPUTED_YET 0x0800 // =1: value not computed yet
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
241 #define INT_FLAG_ZERO 0x0800 // =1: value is zero
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
242 #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
243 #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
244 #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
245 #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
246 #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
247 #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
248 #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
249
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
250
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
251
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
252 // *********************************************************************************************************************************
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 // ** 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
255 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
256 // 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
257 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
258 // *********************************************************************************************************************************
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
259
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
260 // Functions used in Surface Mode
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
261 static void calc_interval(PARAMETER unsigned char time_increment);
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
262 // Calculates the tissue off-gassing under surface conditions.
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
263 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
264 static void clear_tissue(void); // Resets all tissues to surface pressure equilibrium state.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
265 static void init_output_vars(void); // Initializes all deco engine output variables to defaults
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
266
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
267 // Main entry point in Dive Mode
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
268 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
269
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
270 // Functions dedicated to the real Tissues
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
271 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
272
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
273 // Functions combined for real Tissues & Deco Calculations
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
274 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
275 // needs either calc_hauptroutine_data_input() be called beforehand or
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
276 // gas_take_current() or gas_find_best()/gas_take_best() and gas_set_ratios().
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
277 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
278 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
279 static void calc_limit(PARAMETER float GF_current);
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
280 // Calculates ceiling, current supersaturation factor and some more data.
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
281
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
282 // Functions for TR
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
283 #ifdef _rx_functions
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
284 static void calc_TR_functions(void); // Calculates SAC etc.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
285 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
286
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
287 // Functions for Cave Mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
288 #ifdef _cave_mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
289 static void read_backtrack_data(void); // Gets the data of the next backtracking data set
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
290 #endif
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
291
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
292 // Functions dedicated to Deco Calculations
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
293 static void clear_deco_table(void); // Clears the deco stops table, invoked at the start of each calculation cycle.
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
294 static void gas_take_current(void); // Take the actual currently used gas for ascent & deco calculation
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
295 static unsigned char gas_find_best(void); // Searches for the best gas available.
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
296 static void gas_take_best(void); // Switches to the best gas that has been found found before by gas_find_best().
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
297 static void gas_set_ratios(void); // Sets the gas ratios for use in deco calculation (simulated tissues),
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
298 // needs to be called after each gas change (gas_take_current/_better).
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
299 static void calc_NDL_time_tissue(void); // Calculates the remaining NDL time for a given tissue.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
300 static unsigned char find_next_stop(void); // Finds the next stop when in a deco ascent.
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
301 static void update_deco_table(PARAMETER unsigned char time_increment);
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
302 // Enters a new stop or extends an existing stop in the deco stops table.
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
303 static void calc_required_volume(void); // Calculates gas volume required for a given depth, time and usage (SAC rate).
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
304 static void convert_volume_to_pressure(void); // Converts gas volumes into pressures and sets respective flags.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
305
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
306 // Functions for Results Reporting
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
307 static void publish_deco_table(void); // Copies the internal deco stops table to the export interface.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
308 static void convert_cur_CNS_for_display(void); // Converts the current CNS value from float to integer.
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
309 static void convert_sim_CNS_for_display(void); // Converts the end-of-dive CNS value from float to integer.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
310 static void convert_sat_for_display(void); // Converts leading tissue saturation value from float to integer, 1.0 = 100%.
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
311 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
312
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
313
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
314 // internal helper Functions
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
315 static void load_tmr5(void); // Loads a hardware timer which is used for preemptive scheduling.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
316 static void read_tmr5(void); // Reads a hardware timer which is used for preemptive scheduling.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
317 static void read_CNS_ab_coefficient(void); // Reads the CNS a and b coefficients from a ROM table.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
318 static void read_CNS_c_coefficient(void); // Reads the CNS c coefficient from a ROM table.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
319 static void read_Buhlmann_coefficients(void); // Reads the Buhlmann a and b coefficients from a ROM table.
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
320 static void read_Buhlmann_times(PARAMETER char period);
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
321 // 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
322 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
323 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
324 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
325 static void pull_tissues_from_vault(void); // Restores the state of the real tissues after a simulator run.
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
326 static void calc_N2_equilibrium(void); // Calculate partial pressure of N2 in respired air at surface pressure.
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
327 static void get_saturation_factors(void); // Get, safeguard and convert the saturation and desaturation factors.
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
328 static void apply_saturation_factors(void); // Applies saturation and desaturation factors.
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
329
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
330
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
331 // *********************************************************************************************************************************
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
332 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
333 // 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
334 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
335 // *********************************************************************************************************************************
0
heinrichsweikamp
parents:
diff changeset
336
heinrichsweikamp
parents:
diff changeset
337 //---- Bank 5 parameters -----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
338 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
339 # pragma udata bank5=0x500
heinrichsweikamp
parents:
diff changeset
340 #endif
heinrichsweikamp
parents:
diff changeset
341
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
342 // Data that go into the deco data vault (4 byte)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
343
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
344 static float CNS_fraction_real; // || current real CNS (1.00 = 100%)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
345
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
346
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
347 // Environmental and Gas Data (51 byte)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
348
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
349 static float pres_surface; // absolute pressure at the surface
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
350
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
351 static float float_depth_real; // current real depth in meters, float
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
352 static unsigned char char_depth_real; // current real depth in meters, integer
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
353 static unsigned char char_depth_start; // start value of simulated depth in meters, integer
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
354 static unsigned char char_depth_sim; // current value of simulated depth in meters, integer
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
355
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
356 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
357 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
358 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
359 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
360 static float real_pSCR_drop; // real ppO2 drop in pSCR loop
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
361
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
362 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
363 static float sim_O2_ratio; // simulated breathed gas oxygen ratio
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
364 static float sim_N2_ratio; // simulated breathed gas nitrogen ratio
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
365 static float sim_He_ratio; // simulated breathed gas helium ratio
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
366 static float sim_pSCR_drop; // simulated ppO2 drop in pSCR loop
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
367
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
368
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
369 // general Deco Parameters (64 byte)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
370
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
371 static float GF_low; // gradient factor to determine 1st stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
372 static float GF_high; // gradient factor to determine surfacing
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
373
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
374 static unsigned char GF_low_last; // last GF low, used to detect a GF change
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
375 static unsigned char GF_high_last; // last GF high, used to detect a GF change
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
376
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
377 static unsigned char GF_depth; // GF low reference depth in current calculation cycle
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
378 static unsigned char GF_depth_norm; // GF low reference depth in normal plan
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
379 static unsigned char GF_depth_alt; // GF low reference depth in alternative plan
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
380
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
381 static float GF_slope; // (GF_high - GF_low) / GF_depth in current calculation cycle
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
382 static float GF_slope_norm; // (GF_high - GF_low) / GF_depth_norm in normal plan
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
383 static float GF_slope_alt; // (GF_high - GF_low) / GF_depth_alt in alternative plan
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
384
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
385 static float float_saturation_multiplier; // safety factor for on-gassing rates
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
386 static float float_desaturation_multiplier; // safety factor for off-gassing rates
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
387
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
388 static unsigned char split_N2_He[NUM_COMP]; // used for calculating the desaturation time
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
389 static unsigned char deco_gas_type[NUM_GAS]; // type and state of the deco gases
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
390 static unsigned char peer_tank[NUM_GAS]; // bit flag vector indicating peer tanks holding same gas
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
391
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
392
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
393 // real Context: what we are doing now (12 byte)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
394
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
395 static unsigned short IBCD_tissue_vector; // 16 bit vector to memorize all tissues that experience IBCD
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
396
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
397 static float pres_respiration_sac; // used in SAC calculation: current depth in absolute pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
398 static float float_sac; // used in SAC calculation: SAC value in float
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
399 static unsigned short max_sac_rate; // used in SAC calculation: threshold for SAC rate attention
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
400
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
401
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
402 // simulated Context: used to calculate Ascent (11 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
403
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
404 static float CNS_fraction_sim; // CNS after predicted ascent, 0.01 = 1%, as float
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
405 static unsigned short int_sim_CNS_fraction; // CNS after predicted ascent, 1 = 1%, as integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
406 static unsigned char NDL_tissue_start_norm; // tissue to start with when calculating the normal NDL time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
407 static unsigned char NDL_tissue_start_alt; // tissue to start with when calculating the alternative NDL time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
408 static unsigned char NDL_tissue_start; // tissue to start with in current cycle
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
409 static unsigned char NDL_tissue_lead; // tissue with the shortest NDL time found in current cycle
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
410 static unsigned char NDL_tissue; // tissue for which the NDL is calculated right now
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
411
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
412
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
413 // Result Values from Calculation Functions (9 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
414
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
415 static float ceiling; // minimum tolerated relative pressure (i.e. without surface pressure)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
416 static float lead_supersat; // supersaturation of the leading tissue, 1.0 = 100%
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
417 static unsigned char lead_tissue; // number of the leading tissue (0-15)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
418
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
419
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
420 // Transfer Variables between calc_desaturation_time() and calc_desaturation_time_helper() (18 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
421
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
422 static float desat_factor; // used to cache a pre-computed factor
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
423 static float var_ht; // half-time factor for the compartment
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
424 static float pres_target; // target pressure for the compartment
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
425 static float pres_actual; // current pressure of the compartment
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
426 static unsigned short int_time; // time it takes for the compartment to reach the target pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
427
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
428
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
429 // Gas in Use and Gas Needs (67 byte)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
430
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
431 static unsigned char start_gas_num; // number of the gas/dil to start with
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
432
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
433 static unsigned char sim_gas_last_num; // number of the last used gas
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
434 static unsigned char sim_gas_current_num; // number of the currently used gas
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
435 static unsigned char sim_gas_current_depth; // change depth of the currently used gas
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
436
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
437 static unsigned char sim_gas_best_num; // number of the best gas available
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
438 static unsigned char sim_gas_best_depth; // change depth of the best gas available
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
439
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
440 static unsigned char gas_needs_gas_index; // index to the gas and tank data arrays
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
441 static float gas_volume_need[NUM_GAS]; // gas volumes required for ascent / cave return in liters
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
442 static float gas_volume_avail[NUM_GAS]; // gas volumes available for ascent / cave return in liters
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
443 static float gas_volume_atten[NUM_GAS]; // attention threshold for gas volumes available
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
444
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
445
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
446 // Transfer Variables for calc_required_volume() (7 byte)
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
447
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
448 static unsigned char gas_needs_depth; // depth of the stop or half-way point
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
449 static unsigned char gas_needs_time; // duration of the stop, ascent or travel phase
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
450 static unsigned char gas_needs_usage_rate; // gas usage in l/min
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
451 static float gas_needs_volume_due; // computed amount of required gas volume
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
452
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
453
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
454 // 243 byte used, 13 byte left in this bank (4 bytes per float, 2 bytes per short, 1 byte per char)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
455
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
456
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
457 //---- Bank 6 parameters -----------------------------------------------------
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
458 #ifndef UNIX
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
459 # pragma udata bank6=0x600
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
460 #endif
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
461
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
462 // Timer5 Interface (3 byte) - Attention: keep order and keep at beginning of bank 6, i.e. at address 0x600 !
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
463
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
464 static volatile unsigned short tmr5_value; // | timer 5 value buffer MUST be at address 0x600
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
465 static volatile unsigned char tmr5_overflow; // | timer 5 overflow flag MUST be at address 0x602
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
466
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
467
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
468 // Modes, Sequencing and Indexing (14 byte)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
469
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
470 static unsigned char main_status; // shadow register for char_O_main_status
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
471 static unsigned char deco_status; // shadow register for char_O_deco_status
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
472 static unsigned char deco_info; // shadow register for char_O_deco_info
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
473 static unsigned char deco_warnings; // shadow register for char_O_deco_warnings
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
474 static unsigned char next_planning_phase; // next calculation phase to be executed
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
475 static unsigned char tissue_increment; // selector for real/simulated tissues and time increment
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
476 static unsigned char sequence_timer; // timer to sequence deco engine tasks
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
477 static unsigned char ci; // index to the Buhlmann tables (compartment index)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
478 static unsigned char cns_i; // index to the CNS tables (ppO2 range index)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
479 static unsigned char i; // general purpose loop counter and index
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
480 static unsigned char j; // general purpose loop counter and index
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
481 static unsigned char stop_index; // current stop table position
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
482 static unsigned char chained_stops; // counter for chained stop entries
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
483 static unsigned char backtrack_index; // index into the depth backtracking array char_I_backtrack_storage
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
484 static unsigned char backtrack_target_depth; // current backtracking target depth
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
485 static unsigned char backtrack_step_counter; // counter for number of 1/10 minute steps done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
486
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
487
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
488 // Result Values from Calculation Functions (28 byte)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
489
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
490 static float ppO2_O2; // ppO2 calculated for breathing pure oxygen in OC mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
491 static float ppO2_OC; // ppO2 calculated for breathing current gas in OC mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
492 static float ppO2_pSCR; // ppO2 calculated for breathing current gas in pSCR mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
493
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
494 static float ppO2; // partial pressure of breathed oxygen
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
495 static float ppN2; // partial pressure of breathed nitrogen
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
496 static float ppHe; // partial pressure of breathed helium
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
497
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
498 static unsigned char char_ppO2; // partial pressure of breathed oxygen, 100 = 1.00 bar
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
499 static unsigned char NDL_time; // time in full minutes until reaching no-deco limit (NDL)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
500 static unsigned short TTS_time; // time in 1/10 minutes until finishing ascent / cave return
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
501 static unsigned short TST_time; // time in full minutes of all stops in ascent / cave return
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
502
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
503
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
504 // Buhlmann Model Parameters (40 byte)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
505
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
506 static float var_N2_a; // Buhlmann a for current N2 tissue
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
507 static float var_N2_b; // Buhlmann b for current N2 tissue
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
508 static float var_He_a; // Buhlmann a for current He tissue
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
509 static float var_He_b; // Buhlmann b for current He tissue
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
510 static float var_a; // Buhlmann a adopted to current N2/He ratio
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
511 static float var_b; // Buhlmann b adopted to current N2/He ratio
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
512 static float var_N2_e; // exposition for current N2 tissue
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
513 static float var_He_e; // exposition for current He tissue
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
514 static float var_N2_ht; // half-time for current N2 tissue
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
515 static float var_He_ht; // half-time for current He tissue
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
516
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
517
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
518 // CNS Coefficients (10 byte)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
519
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
520 static float var_cns_gain; // two coefficients approximation, gain
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
521 static float var_cns_offset; // two coefficients approximation, offset
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
522 static unsigned short var_cns_value; // one coefficient approximation, value
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
523
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
524
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
525 // Auxiliary Variables for Data Buffering (28 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
526
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
527 static float N2_equilibrium; // used for N2 tissue graphics scaling
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
528 static float temp_tissue; // auxiliary variable to buffer tissue pressures
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
529 static float float_pSCR_factor; // pre-computed factor for pSCR ppO2 drop calculation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
530 static float calc_pres_tissue_N2; // auxiliary variable to buffer tissue N2 pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
531 static float calc_pres_tissue_He; // auxiliary variable to buffer tissue He pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
532 static float pres_tissue; // auxiliary variable to buffer total tissue pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
533 static float old_pres_respiration; // auxiliary variable to buffer sim_pres_respiration
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
534
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
535
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
536 // Transfer Values for convert_float_to_int() (6 byte)
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
537
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
538 static float float_value; // input value, float
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
539 static unsigned short int_value; // output value, 16 bit
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
540
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
541
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
542 // Performance Profiling (4 byte)
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
543
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
544 static unsigned short profiling_runtime; // performance measurement: runtime of current invocation
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
545 static unsigned char profiling_runs; // performance measurement: invocations per deco calculation cycle
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
546 static unsigned char profiling_phase; // performance measurement: current calculation phase
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
547
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
548
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
549 // 7 byte occupied by compiler-placed vars
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
550
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
551
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
552 // 139 byte used, 117 byte left in this bank (4 bytes per float, 2 bytes per short, 1 byte per char)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
553
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
554
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
555
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
556 //---- Bank 12 parameters -----------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
557 #ifndef UNIX
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
558 # pragma udata bank12=0xc00
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
559 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
560
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
561 // stops table (96 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
562
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
563 static unsigned char internal_deco_depth[NUM_STOPS]; // depths of the stops in meters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
564 static unsigned char internal_deco_time[NUM_STOPS]; // durations of the stops in minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
565 static unsigned char internal_deco_gas[NUM_STOPS]; // gases used on the stops (0 / 1-5)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
566
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
567
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
568 // Vault to back-up & restore Tissue related Data (134 byte)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
569
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
570 static float vault_pres_tissue_N2[NUM_COMP]; // stores the nitrogen tissue pressures
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
571 static float vault_pres_tissue_He[NUM_COMP]; // stores the helium tissue pressures
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
572 static float vault_CNS_fraction_real; // stores CNS percentage (1.0 = 100%)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
573 static unsigned char vault_deco_warnings; // stores warnings status
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
574 static unsigned char vault_deco_info; // stores info status
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
575
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
576 // 230 byte used, 26 byte left in this bank (4 bytes per float, 2 bytes per short, 1 byte per char)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
577
0
heinrichsweikamp
parents:
diff changeset
578
heinrichsweikamp
parents:
diff changeset
579 //---- Bank 7 parameters -----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
580 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
581 # pragma udata bank7=0x700
heinrichsweikamp
parents:
diff changeset
582 #endif
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
583
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
584 // Keep order and position of the variables in bank 7 as they are backed-up to & restored from EEPROM
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
585
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
586 static float real_pres_tissue_N2[NUM_COMP]; // 16 floats = 64 bytes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
587 static float real_pres_tissue_He[NUM_COMP]; // 16 floats = 64 bytes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
588
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
589 static float sim_pres_tissue_N2[NUM_COMP]; // 16 floats = 64 bytes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
590 static float sim_pres_tissue_He[NUM_COMP]; // 16 floats = 64 bytes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
591
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
592 // 256 byte used, bank is full
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
593
0
heinrichsweikamp
parents:
diff changeset
594
heinrichsweikamp
parents:
diff changeset
595 //---- Bank 8 parameters -----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
596 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
597 # pragma udata overlay bank8=0x800
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
598
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
599 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
600
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
601 # define C_STACK md_pi_subst
0
heinrichsweikamp
parents:
diff changeset
602 #endif
heinrichsweikamp
parents:
diff changeset
603
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
604
0
heinrichsweikamp
parents:
diff changeset
605 // Back to bank6 for further tmp data
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
606 // Do not delete this assignment, it is needed by the compiler/linker.
0
heinrichsweikamp
parents:
diff changeset
607 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
608 # pragma udata bank6
heinrichsweikamp
parents:
diff changeset
609 #endif
heinrichsweikamp
parents:
diff changeset
610
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
611
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
612 // *********************************************************************************************************************************
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
613 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
614 // 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
615 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
616 // *********************************************************************************************************************************
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
617
0
heinrichsweikamp
parents:
diff changeset
618 #ifndef UNIX
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
619 # pragma romdata Buhlmann_ht = 0x1DC00 // needs to be in the UPPER bank
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
620 #endif
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
621
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
622 rom const float Buhlmann_ht[2*16] = {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
623 // Compartment half-times, in minutes
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
624 //--- N2 ---- He ----------------------
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
625 4.0, 1.51,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
626 8.0, 3.02,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
627 12.5, 4.72,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
628 18.5, 6.99,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
629 27.0, 10.21,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
630 38.3, 14.48,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
631 54.3, 20.53,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
632 77.0, 29.11,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
633 109.0, 41.20,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
634 146.0, 55.19,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
635 187.0, 70.69,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
636 239.0, 90.34,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
637 305.0, 115.29,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
638 390.0, 147.42,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
639 498.0, 188.24,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
640 635.0, 240.03
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
641 };
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
642
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
643
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
644 #ifndef UNIX
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
645 # pragma romdata CNS_tables = 0x1DC80 // needs to be in the UPPER bank
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
646 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
647
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
648 rom const float CNS_2_approx[2*11] = {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
649 // 2 coefficient approximation for ppO2 = 51 ... 160 cbar
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
650 // CNS increment per 2 sec = 1 / (gain*ppO2 + offset) with ppO2 in [cbar]
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
651 // gain offset for ppO2 cbar range
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
652 -533.07, 54000, // 51 - 60 (index 0)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
653 -444.22, 48600, // 61 - 70 (index 1)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
654 -355.38, 42300, // 71 - 80 (index 2)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
655 -266.53, 35100, // 81 - 90 (index 3)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
656 -177.69, 27000, // 91 - 100 (index 4)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
657 -177.69, 27000, // 101 - 110 (index 5)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
658 -88.84, 17100, // 111 - 120 (index 6)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
659 -88.84, 17100, // 121 - 130 (index 7)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
660 -88.84, 17100, // 131 - 140 (index 8)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
661 -88.84, 17100, // 141 - 150 (index 9)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
662 -222.11, 37350 // 151 - 160 (index 10)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
663 };
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
664
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
665 rom const unsigned short CNS_1_approx[1*18] = {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
666 // 1 coefficient approximation for ppO2 = 161 ... 250 cbar
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
667 // CNS increment per 2 sec = c / 100000.0
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
668 // value in [1/100000] for ppO2 cbar range
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
669 75, // 161 - 165 (index 0)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
670 102, // 166 - 170 (index 1)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
671 136, // 171 - 175 (index 2)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
672 180, // 176 - 180 (index 3)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
673 237, // 181 - 185 (index 4)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
674 310, // 186 - 190 (index 5)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
675 401, // 191 - 195 (index 6)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
676 517, // 196 - 200 (index 7)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
677 760, // 201 - 205 (index 8)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
678 1100, // 206 - 210 (index 9)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
679 1500, // 211 - 215 (index 10)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
680 2090, // 216 - 220 (index 11)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
681 2900, // 221 - 225 (index 12)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
682 3900, // 226 - 230 (index 13)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
683 4820, // 231 - 235 (index 14)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
684 4820, // 236 - 240 (index 15)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
685 4820, // 241 - 245 (index 16)
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
686 4820 // 246 - 250 (index 17)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
687 };
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
688
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
689
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
690 #ifndef UNIX
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
691 # pragma romdata Buhlmann_ab = 0x1DD00 // needs to be in the UPPER bank
0
heinrichsweikamp
parents:
diff changeset
692 #endif
heinrichsweikamp
parents:
diff changeset
693
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
694 rom const float Buhlmann_ab[4*16] = {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
695 // Compartment a and b factors
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
696 // Data ZH-L16C, from Bühlmann Tauchmedizin 2002, option 1a (4mn)
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
697 // a for N2 b for N2 a for He b for He
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
698 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
699 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
700 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
701 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
702 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
703 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
704 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
705 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
706 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
707 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
708 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
709 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
710 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
711 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
712 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
713 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
714 };
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
715
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
716
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
717 #ifndef UNIX
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
718 # pragma romdata e_tables = 0x1DE00 // needs to be in the UPPER bank
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
719 #endif
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
720
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
721 rom const float e2sec[2*16] = {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
722 // Integration constants for 2 seconds,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
723 // result of 1 - 2^(-(2sec/60sec / HT))
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
724 //---- N2 ------------- He ------------
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
725 5.75958E-03, 1.51848E-02,
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
726 2.88395E-03, 7.62144E-03,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
727 1.84669E-03, 4.88315E-03,
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
728 1.24813E-03, 3.29997E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
729 8.55371E-04, 2.26041E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
730 6.03079E-04, 1.59437E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
731 4.25414E-04, 1.12479E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
732 3.00019E-04, 7.93395E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
733 2.11949E-04, 5.60641E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
734 1.58240E-04, 4.18555E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
735 1.23548E-04, 3.26795E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
736 9.66686E-05, 2.55722E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
737 7.57509E-05, 2.00387E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
738 5.92416E-05, 1.56716E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
739 4.63943E-05, 1.22734E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
740 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
741 //-------------------------------------
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
742 };
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
743
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
744 rom const float e6sec[2*16] = {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
745 // Integration constants for 6 seconds,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
746 // result of 1 - 2^(-(6sec/60sec / HT))
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
747 //---- N2 ------------- He ------------
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
748 1.71794E-02, 4.48661E-02,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
749 8.62691E-03, 2.26905E-02,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
750 5.52983E-03, 1.45780E-02,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
751 3.73973E-03, 9.86726E-03,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
752 2.56392E-03, 6.76591E-03,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
753 1.80815E-03, 4.77549E-03,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
754 1.27570E-03, 3.37057E-03,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
755 8.99786E-04, 2.37830E-03,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
756 6.35713E-04, 1.68098E-03,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
757 4.74646E-04, 1.25514E-03,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
758 3.70598E-04, 9.80064E-04,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
759 2.89978E-04, 7.66971E-04,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
760 2.27236E-04, 6.01040E-04,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
761 1.77714E-04, 4.70075E-04,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
762 1.39176E-04, 3.68157E-04,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
763 1.09151E-04, 2.88734E-04
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
764 //-------------------------------------
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
765 };
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
766
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
767 rom const float e1min[2*16] = {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
768 // Integration constants for 1 minute,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
769 // result of 1 - 2^(-(1min / HT))
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
770 //----- N2 --------- e 1min He --------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
771 1.59104E-01, 3.68109E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
772 8.29960E-02, 2.05084E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
773 5.39424E-02, 1.36579E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
774 3.67742E-02, 9.44046E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
775 2.53454E-02, 6.56359E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
776 1.79351E-02, 4.67416E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
777 1.26840E-02, 3.31991E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
778 8.96152E-03, 2.35301E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
779 6.33897E-03, 1.66832E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
780 4.73633E-03, 1.24808E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
781 3.69981E-03, 9.75753E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
782 2.89600E-03, 7.64329E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
783 2.27003E-03, 5.99417E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
784 1.77572E-03, 4.69082E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
785 1.39089E-03, 3.67548E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
786 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
787 //-------------------------------------
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
788 };
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
789
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
790 rom const float e10min[2*16] = {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
791 // Integration constants for 10 minutes,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
792 // result of 1 - 2^(-(10min / HT))
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
793 //---- N2 -------------- He -----------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
794 8.23223E-01, 9.89851E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
795 5.79552E-01, 8.99258E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
796 4.25651E-01, 7.69737E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
797 3.12487E-01, 6.29027E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
798 2.26416E-01, 4.92821E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
799 1.65547E-01, 3.80407E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
800 1.19840E-01, 2.86538E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
801 8.60863E-02, 2.11886E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
802 6.16117E-02, 1.54849E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
803 4.63665E-02, 1.18026E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
804 3.63881E-02, 9.34005E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
805 2.85855E-02, 7.38569E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
806 2.24698E-02, 5.83504E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
807 1.76160E-02, 4.59303E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
808 1.38222E-02, 3.61528E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
809 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
810 //-------------------------------------
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
811 };
0
heinrichsweikamp
parents:
diff changeset
812
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
813
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
814 // *********************************************************************************************************************************
0
heinrichsweikamp
parents:
diff changeset
815 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
816 // 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
817 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
818 // *********************************************************************************************************************************
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
819
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
820
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
821 // p2deco code moved from 0x0D000 to 0x0C000 in v.108
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
822 // moved from 0x0C000 to 0x0B000 in v3.09
0
heinrichsweikamp
parents:
diff changeset
823 #ifndef UNIX
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
824 # pragma code p2_deco = 0x0B000
0
heinrichsweikamp
parents:
diff changeset
825 #endif
heinrichsweikamp
parents:
diff changeset
826
heinrichsweikamp
parents:
diff changeset
827
heinrichsweikamp
parents:
diff changeset
828 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
829 // Bump to blue-screen when an assert is wrong
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
830 #ifdef _DEBUG
0
heinrichsweikamp
parents:
diff changeset
831 void assert_failed(PARAMETER short int line)
heinrichsweikamp
parents:
diff changeset
832 {
heinrichsweikamp
parents:
diff changeset
833 }
heinrichsweikamp
parents:
diff changeset
834 #endif
heinrichsweikamp
parents:
diff changeset
835
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
836
0
heinrichsweikamp
parents:
diff changeset
837 //////////////////////////////////////////////////////////////////////////////
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
838 // When calling C code from ASM context, the C data stack pointer need to be
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
839 // reset. The C stack is located in bank 8.
0
heinrichsweikamp
parents:
diff changeset
840
heinrichsweikamp
parents:
diff changeset
841 #ifdef CROSS_COMPILE
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
842 # define RESET_C_STACK
0
heinrichsweikamp
parents:
diff changeset
843 #else
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
844 # ifdef _DEBUG
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
845 # define RESET_C_STACK fillDataStack();
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
846 void fillDataStack(void)
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
847 {
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
848 _asm
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
849 LFSR 1,C_STACK
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
850 MOVLW 0xCC
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
851 loop: MOVWF POSTINC1,0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
852 TSTFSZ FSR1L,0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
853 BRA loop
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
854
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
855 LFSR 1,C_STACK
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
856 LFSR 2,C_STACK
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
857 _endasm
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
858 }
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
859 # else
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
860 # define RESET_C_STACK \
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
861 _asm \
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
862 LFSR 1,C_STACK \
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
863 LFSR 2,C_STACK \
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
864 _endasm
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
865 # endif
0
heinrichsweikamp
parents:
diff changeset
866 #endif
heinrichsweikamp
parents:
diff changeset
867
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
868
0
heinrichsweikamp
parents:
diff changeset
869 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
870 // Reset timer 5
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
871 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
872 // Note: TMR5 is configured in 16 bit mode: a value written to TMR5H is buffered
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
873 // and will be written to TMR5 together with a successive write to TMR5L.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
874 // As we don't know in which bank the code will be executed, we use either
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
875 // the bank-save "movff" command, or address mapping via access bank (",0").
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
876 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
877 static void load_tmr5(void)
0
heinrichsweikamp
parents:
diff changeset
878 {
heinrichsweikamp
parents:
diff changeset
879 #ifndef CROSS_COMPILE
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
880 _asm
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
881 movff 0x601,0xF7D // bank-safe load TMR5H from C variable tmr5_value first
640
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 635
diff changeset
882 movff 0x600,0xF7C // bank-safe load TMR5L from C variable tmr5_value thereafter
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
883 bcf 0xFBA,1,0 // clear timer 5 overrun flag (0xFBA = PIR5, bit 1 = TMR5IF)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
884 _endasm
0
heinrichsweikamp
parents:
diff changeset
885 #else
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
886 return;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
887 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
888 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
889
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
890
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
891 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
892 // Read timer 5
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
893 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
894 // Note: TMR5 reads in multiples of 1/32 ms, 30.51757813 us/bit to be precise.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
895 // TMR5 is configured in 16 bit mode: on reading of TMR5L the contents of
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
896 // TMR5H is latched and can be read afterwards without potential rollover.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
897 // As we don't know in which bank the code will be executed, we use either
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
898 // the bank-save "movff" command, or address mapping via access bank (",0").
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
899 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
900 static void read_tmr5(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
901 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
902 #ifndef CROSS_COMPILE
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
903 _asm
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
904 movff 0xF7C,0x600 // copy TMR5L to C variable tmr5_value, low byte first
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
905 movff 0xF7D,0x601 // copy TMR5H to C variable tmr5_value, high byte thereafter
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
906 clrf WREG,0 // clear WREG to 0x00 = no overrun by default
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
907 btfsc 0xFBA,1,0 // did timer 5 overrun? (0xFBA = PIR5, bit 1 = TMR5IF)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
908 setf WREG,0 // YES - set WREG to 0xff = overrun detected
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
909 movff WREG,0x602 // copy WREG to C variable tmr5_overflow
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
910 _endasm
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
911 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
912 return;
0
heinrichsweikamp
parents:
diff changeset
913 #endif
heinrichsweikamp
parents:
diff changeset
914 }
heinrichsweikamp
parents:
diff changeset
915
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
916
0
heinrichsweikamp
parents:
diff changeset
917 //////////////////////////////////////////////////////////////////////////////
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
918 // Read CNS coefficients gain and offset
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
919 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
920 static void read_CNS_ab_coefficient(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
921 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
922 #ifndef CROSS_COMPILE
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
923 // Note: We don't use far ROM pointer, because handling
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
924 // 24 bit is to complex, hence we have to set the
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
925 // UPPER page ourself...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
926 // -> set to zero if tables are moved to lower pages!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
927 _asm
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
928 movlw 1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
929 movwf TBLPTRU,0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
930 _endasm
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
931 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
932
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
933 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
934 overlay rom const float* ptr = &CNS_2_approx[2*cns_i];
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
935 var_cns_gain = *ptr++;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
936 var_cns_offset = *ptr++;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
937 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
938 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
939
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
940
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
941 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
942 // Read CNS coefficient c
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
943 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
944 static void read_CNS_c_coefficient(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
945 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
946 #ifndef CROSS_COMPILE
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
947 // Note: We don't use far ROM pointer, because handling
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
948 // 24 bit is to complex, hence we have to set the
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
949 // UPPER page ourself...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
950 // -> set to zero if tables are moved to lower pages!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
951 _asm
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
952 movlw 1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
953 movwf TBLPTRU,0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
954 _endasm
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
955 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
956
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
957 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
958 overlay rom const unsigned short* ptr = &CNS_1_approx[cns_i];
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
959 var_cns_value = *ptr++;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
960 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
961 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
962
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
963 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
964 // Read Buhlmann coefficients a and b for compartment ci
0
heinrichsweikamp
parents:
diff changeset
965 //
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
966 static void read_Buhlmann_coefficients(void)
0
heinrichsweikamp
parents:
diff changeset
967 {
heinrichsweikamp
parents:
diff changeset
968 #ifndef CROSS_COMPILE
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
969 // 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
970 // 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
971 // UPPER page ourself...
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
972 // -> set to zero if tables are moved to lower pages!
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
973 _asm
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
974 movlw 1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
975 movwf TBLPTRU,0
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
976 _endasm
0
heinrichsweikamp
parents:
diff changeset
977 #endif
heinrichsweikamp
parents:
diff changeset
978
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
979 assert( ci < NUM_COMP );
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
980
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
981 // use an interleaved array (AoS) to access coefficients with a single addressing
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
982 {
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
983 overlay rom const float* ptr = &Buhlmann_ab[4*ci];
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
984 var_N2_a = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
985 var_N2_b = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
986 var_He_a = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
987 var_He_b = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
988 }
0
heinrichsweikamp
parents:
diff changeset
989 }
heinrichsweikamp
parents:
diff changeset
990
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
991
0
heinrichsweikamp
parents:
diff changeset
992 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
993 // Read Buhlmann increments for compartment ci
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
994 // If period == 0 : 2 sec interval
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
995 // 1 : 1 min interval
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
996 // 2 : 10 min interval
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
997 static void read_Buhlmann_times(PARAMETER char period)
0
heinrichsweikamp
parents:
diff changeset
998 {
heinrichsweikamp
parents:
diff changeset
999 #ifndef CROSS_COMPILE
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1000 // 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
1001 // 24 bit is to complex, hence we have to set the
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1002 // UPPER page by hand...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1003 // -> set to zero if tables are moved to lower pages!
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1004 _asm
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1005 movlw 1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1006 movwf TBLPTRU,0
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1007 _endasm
0
heinrichsweikamp
parents:
diff changeset
1008 #endif
heinrichsweikamp
parents:
diff changeset
1009
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1010 assert( ci < NUM_COMP );
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1011
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1012 // Integration Intervals
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1013 switch(period)
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1014 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1015 case 0: //---- 2 or 6 seconds --------------------------------------------
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1016 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1017 // check which tissues are selected
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1018 if(tissue_increment & TISSUE_SELECTOR)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1019 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1020 // real tissues - 2 seconds
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1021 overlay rom const float* ptr = &e2sec[2*ci];
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1022 var_N2_e = *ptr++;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1023 var_He_e = *ptr++;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1024 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1025 else
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1026 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1027 // simulated tissues - 6 seconds
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1028 overlay rom const float* ptr = &e6sec[2*ci];
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1029 var_N2_e = *ptr++;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1030 var_He_e = *ptr++;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1031 }
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1032 }
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1033 break;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1034
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1035 case 1: //---- 1 minutes -------------------------------------------------
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1036 {
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1037 overlay rom const float* ptr = &e1min[2*ci];
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1038 var_N2_e = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1039 var_He_e = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1040 }
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1041 break;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1042
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1043 case 2: //---- 10 minutes ------------------------------------------------
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1044 {
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1045 overlay rom const float* ptr = &e10min[2*ci];
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1046 var_N2_e = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1047 var_He_e = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1048 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1049 break;
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1050
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1051 default:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1052 assert(0); // code execution shall never pass along here!
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1053 }
0
heinrichsweikamp
parents:
diff changeset
1054 }
heinrichsweikamp
parents:
diff changeset
1055
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1056
0
heinrichsweikamp
parents:
diff changeset
1057 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1058 // Read Buhlmann half-times for compartment ci
0
heinrichsweikamp
parents:
diff changeset
1059 //
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1060 static void read_Buhlmann_ht(void)
0
heinrichsweikamp
parents:
diff changeset
1061 {
heinrichsweikamp
parents:
diff changeset
1062
heinrichsweikamp
parents:
diff changeset
1063 #ifndef CROSS_COMPILE
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1064 // 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
1065 // 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
1066 // UPPER page ourself...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1067 // -> Set to zero if tables are moved to lower pages!
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1068 _asm
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1069 movlw 1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1070 movwf TBLPTRU,0
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1071 _endasm
0
heinrichsweikamp
parents:
diff changeset
1072 #endif
heinrichsweikamp
parents:
diff changeset
1073
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1074 assert( ci < NUM_COMP );
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1075 {
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1076 overlay rom const float* ptr = &Buhlmann_ht[2*ci];
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1077 var_N2_ht = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1078 var_He_ht = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1079 }
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1080
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1081 assert( 4.0 <= var_N2_ht && var_N2_ht <= 635.0 );
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1082 assert( 1.5099 <= var_He_ht && var_He_ht <= 240.03 );
0
heinrichsweikamp
parents:
diff changeset
1083 }
heinrichsweikamp
parents:
diff changeset
1084
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1085
0
heinrichsweikamp
parents:
diff changeset
1086 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1087 // Calculate adopted Buhlmann coefficients
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1088 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1089 // Input: var_N2_a, var_N2_b coefficients for N2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1090 // var_He_a, var_He_b coefficients for He
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1091 // calc_pres_tissue_N2 partial pressure of N2 in tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1092 // calc_pres_tissue_He partial pressure of He in tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1093 // pres_tissue total pressure in tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1094 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1095 // Output: var_a, var_b coefficients adopted by N2/He ratio
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1096 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1097 static void adopt_Buhlmann_coefficients(void)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1098 {
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1099 // adopt a and b coefficients to current N2/He ratio inside the tissue
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1100
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1101 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1102
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1103 var_a = (var_N2_a * calc_pres_tissue_N2 + var_He_a * calc_pres_tissue_He) / pres_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1104 var_b = (var_N2_b * calc_pres_tissue_N2 + var_He_b * calc_pres_tissue_He) / pres_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1105
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1106 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1107
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1108 var_a = var_N2_a;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1109 var_b = var_N2_b;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1110
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1111 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1112
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1113 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1114
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1115
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1116 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1117 // Calculate partial pressure of N2 in respired air at surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1118 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1119 // Input: pres_surface surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1120 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1121 // Output: N2_equilibrium partial pressure of N2 in surface air
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1122 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1123 static void calc_N2_equilibrium(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1124 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1125 N2_equilibrium = 0.7902 * (pres_surface - ppWater);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1126 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1127
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1128
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1129 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1130 // Get, safeguard and convert the saturation and desaturation factors
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1131 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1132 // Input: char_I_saturation_multiplier saturation factor (integer)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1133 // char_I_desaturation_multiplier desaturation factor (integer)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1134 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1135 // Output: float_saturation_multiplier saturation factor (float)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1136 // float_desaturation_multiplier desaturation factor (float)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1137 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1138 static void get_saturation_factors(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1139 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1140 // safeguard input parameters that are constant during the course of the dive
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1141 if( char_I_saturation_multiplier < 100 ) char_I_saturation_multiplier = 100;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1142 if( char_I_saturation_multiplier > 140 ) char_I_saturation_multiplier = 140;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1143
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1144 if( char_I_desaturation_multiplier < 60 ) char_I_desaturation_multiplier = 60;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1145 if( char_I_desaturation_multiplier > 100 ) char_I_desaturation_multiplier = 100;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1146
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1147 // convert input parameters to float numbers
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1148 float_saturation_multiplier = 0.01 * char_I_saturation_multiplier;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1149 float_desaturation_multiplier = 0.01 * char_I_desaturation_multiplier;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1150 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1151
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1152
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1153 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1154 // apply_saturation_factors
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1155 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1156 // Apply safety factors for both ZH-L16 models.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1157 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1158 // Modified: temp_tissue safeguarded tissue increment/decrement
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1159 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1160 static void apply_saturation_factors(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1161 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1162 assert( 0.0 < float_desaturation_multiplier && float_desaturation_multiplier <= 1.0 );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1163 assert( 1.0 <= float_saturation_multiplier && float_saturation_multiplier <= 2.0 );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1164
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1165 if ( temp_tissue < 0.0 ) temp_tissue *= float_desaturation_multiplier;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1166 else temp_tissue *= float_saturation_multiplier;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1167 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1168
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1169
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1170 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1171 // convert_float_to_int
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1172 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1173 // Converts a float within range 0.0 - 9.99 into 16 bit integer scaled in 1/100.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1174 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1175 static void convert_float_to_int(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1176 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1177 if ( float_value < 0.005 ) int_value = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1178 else if ( float_value >= 9.985 ) int_value = 999;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1179 else int_value = (unsigned short)(100 * float_value + 0.5);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1180 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1181
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1182
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1183
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1184 // *********************************************************************************************************************************
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1185 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1186 // 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
1187 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1188 // *********************************************************************************************************************************
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1189
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1190
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1191 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1192 // deco_calc_hauptroutine
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1193 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1194 // called from: divemode.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1195 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1196 // Called two times per second during diving, updates the
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1197 // tissues every second (i.e. on every second invocation).
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1198 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1199 // On each computation cycle:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1200 // - Updates deco table (char_O_deco_time/depth) with new values,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1201 // - updates ascent time, and
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1202 // - sets status to zero (so we can check a cycle has finished).
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1203 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1204 void deco_calc_hauptroutine(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1205 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1206 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1207 calc_hauptroutine();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1208 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1209
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1210
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1211 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1212 // deco_init_output_vars
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1213 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1214 // called from divemode.asm
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1215 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1216 // Initializes all output variables to their default values.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1217 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1218 void deco_init_output_vars(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1219 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1220 RESET_C_STACK
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1221 init_output_vars();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1222 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1223
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1224
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1225 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1226 // deco_clear_tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1227 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1228 // called from: start.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1229 // menu_tree.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1230 // simulator.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1231 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1232 // Sets all tissues to equilibrium with air at ambient pressure,
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1233 // resets all CNS values, any warnings and resets all model output.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1234 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1235 void deco_clear_tissue(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1236 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1237 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1238 clear_tissue();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1239 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1240
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1241
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1242 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1243 // deco_calc_dive_interval
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1244 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1245 // called from: simulator.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1246 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1247 // Updates tissues and CNS value for char_I_dive_interval minutes on air at
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1248 // ambient pressure and calculates resulting saturation and ceiling for a
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1249 // GF-high of 100% (ceiling and saturation not used by simulator.asm)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1250 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1251 void deco_calc_dive_interval(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1252 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1253 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1254 calc_interval(char_I_dive_interval);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1255 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1256
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1257
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1258 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1259 // deco_calc_dive_interval_1min
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1260 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1261 // called from: start.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1262 // sleepmode.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1263 // surfmode.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1264 // menu_tree.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1265 // ghostwriter.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1266 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1267 // Updates tissues and CNS value for 1 minute on air at ambient pressure and
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1268 // calculates resulting saturation and ceiling for a GF-high of 100%.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1269 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1270 void deco_calc_dive_interval_1min(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1271 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1272 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1273 calc_interval(1);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1274 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1275
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1276
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1277 //////////////////////////////////////////////////////////////////////////////
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1278 // deco_calc_dive_interval_10min
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1279 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1280 // called from: sleepmode.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1281 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1282 // Updates tissues and CNS value for 10 minutes on air at ambient pressure and
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1283 // calculates resulting saturation and ceiling for a GF-high of 100%.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1284 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1285 void deco_calc_dive_interval_10min(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1286 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1287 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1288 calc_interval(10);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1289 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1290
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1291
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1292 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1293 // deco_calc_desaturation_time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1294 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1295 // called from: start.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1296 // surfmode.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1297 // menu_tree.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1298 // ghostwriter.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1299 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1300 // Computes desaturation and no-fly times.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1301 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1302 void deco_calc_desaturation_time(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1303 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1304 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1305 calc_desaturation_time();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1306 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1307
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1308
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1309 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1310 // deco_push_tissues_to_vault
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1311 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1312 // called from: simulator.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1313 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1314 // 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
1315 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1316 void deco_push_tissues_to_vault(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1317 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1318 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1319 push_tissues_to_vault();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1320 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1321
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1322
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1323 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1324 // deco_pull_tissues_from_vault
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1325 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1326 // called from: simulator.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1327 // ghostwriter.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1328 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1329 // 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
1330 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1331 void deco_pull_tissues_from_vault(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1332 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1333 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1334 pull_tissues_from_vault();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1335 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1336
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1337
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1338 // *********************************************************************************************************************************
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1339 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1340 // 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
1341 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1342 // *********************************************************************************************************************************
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1343
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1344
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1345 //////////////////////////////////////////////////////////////////////////////
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1346 // Calculate the next deco stop
0
heinrichsweikamp
parents:
diff changeset
1347 //
heinrichsweikamp
parents:
diff changeset
1348 // INPUT, fixed during dive:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1349 // pres_surface : surface pressure (as absolute pressure)
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1350 // char_I_last_stop_depth : depth of the last deco stop
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1351 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1352 // INPUT, may change during dive:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1353 // GF_high : GF high factor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1354 // GF_low : GF low factor
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1355 // GF_depth : GF low reference depth
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1356 // GF_slope : GF slope
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1357 //
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1358 // MODIFIED
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1359 // char_depth_sim : simulated depth in meters
0
heinrichsweikamp
parents:
diff changeset
1360 //
heinrichsweikamp
parents:
diff changeset
1361 // OUTPUT
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1362 // GF_depth_norm/_alt : updated GF low depth reference
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1363 // GF_slope_norm/_alt : updated GF slope
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1364 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1365 // RETURN
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1366 // TRUE: a deco stop is required, FALSE: no deco stop required
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1367 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1368 static unsigned char find_next_stop(void)
0
heinrichsweikamp
parents:
diff changeset
1369 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1370 overlay unsigned char depth_1min;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1371 overlay unsigned char depth_limit;
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1372 overlay unsigned char stop_depth;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1373 overlay unsigned char next_stop;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1374
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1375
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1376 // calculate the current deco ceiling (minimum relative pressure)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1377 if( char_I_model == 0 ) calc_limit(1.0); // straight Buhlmann
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1378 else if( NDL_time ) calc_limit(GF_high); // with GF: not in deco
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1379 else if( char_depth_sim >= GF_depth ) calc_limit(GF_low); // in deco, below or at low depth reference
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1380 else calc_limit(GF_high - GF_slope * (float)char_depth_sim); // in deco, above low depth reference
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1381
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1382 // convert the deco ceiling from relative pressure to meters,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1383 // rounded up (i.e. made deeper) to the next full meter
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1384 depth_limit = (unsigned char)(ceiling * BAR_TO_METER + 0.99);
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1385
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1386
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1387 #ifdef _cave_mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1388 // in cave or open water mode?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1389 if( main_status & CAVE_MODE )
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1390 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1391 // cave mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1392
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1393 // does backtracking require descent or keeping depth?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1394 if( backtrack_target_depth >= char_depth_sim )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1395 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1396 // YES - decent to target depth or stay at current depth
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1397 char_depth_sim = backtrack_target_depth;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1398
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1399 // - done, no stop required
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1400 return(0);
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1401 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1402 else
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1403 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1404 // NO
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1405
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1406 // target depth requires an ascent - determine ascent limit due to deco obligation
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1407 stop_depth = depth_limit;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1408
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1409 // apply correction for the shallowest stop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1410 if( stop_depth && (stop_depth < char_I_last_stop_depth) ) stop_depth = char_I_last_stop_depth;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1411 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1412 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1413 else
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1414 #endif
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1415 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1416 // open water vertical ascent mode - determine the stop depth
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1417
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1418 // stop depth is depth limit rounded up (made deeper) to the next multiple of 3 meters
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1419 stop_depth = 3 * ( (depth_limit + 2) / 3 );
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1420
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1421 // apply correction for the shallowest stop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1422 if( stop_depth == 3 ) stop_depth = char_I_last_stop_depth;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1423 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1424
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1425 // is the stop depth shallower than the current depth (can we ascent)?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1426 if( stop_depth < char_depth_sim )
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1427 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1428 // YES - ascent by 1 meter
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1429 char_depth_sim--;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1430
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1431 // done, no stop needed
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1432 return(0);
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1433 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1434
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1435 // -----------------------------------------------------------------------
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1436 // we need to make a stop because we are not allowed to ascent any further
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1437 // -----------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1438
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1439 // set depth to stop depth
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1440 char_depth_sim = stop_depth;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1441
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1442 // Apply correction in case the stop is to be placed deeper than a
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1443 // previously recorded stop for a gas change. This may happen because
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1444 // the deco stops are placed at the next deeper multiple of 3 meters
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1445 // instead of the real stop's depth. Correction is to relocate the
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1446 // deco stop to the depth of the last gas change. The resulting combined
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1447 // stop's duration will be the sum of the configured gas change time plus
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1448 // the duration of the deco stop itself.
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1449 if( 0 < internal_deco_depth[stop_index] )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1450 if( char_depth_sim > internal_deco_depth[stop_index] )
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1451 char_depth_sim = internal_deco_depth[stop_index];
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1452
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1453 // if using straight Buhlmann: done, stop needed
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1454 if( char_I_model == 0 ) return(1);
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1455
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1456 // -----------------------------------------------------------------------
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1457 // we need to make or hold a stop and we are using the GF extension
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1458 // -----------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1459
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1460 // is the stop_depth deeper than the GF low depth reference used up to now?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1461 if( stop_depth > GF_depth )
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1462 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1463 // YES - update the GF low depth reference
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1464 GF_depth = stop_depth;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1465 GF_slope = (GF_high - GF_low) / (float)GF_depth;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1466
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1467 // store for use in next cycles
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1468 if( deco_status & CALC_NORM )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1469 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1470 GF_depth_norm = GF_depth;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1471 GF_slope_norm = GF_slope;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1472 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1473 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1474 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1475 GF_depth_alt = GF_depth;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1476 GF_slope_alt = GF_slope;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1477 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1478 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1479
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1480 #ifdef _cave_mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1481 // if in cave mode: done, stop needed
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1482 if( main_status & CAVE_MODE ) return(1);
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1483 #endif
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1484
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1485 // We have a stop depth candidate. But with a steep GF slope, the stop(s) after
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1486 // this first stop may be allowed to ascent to, too. This is because the gradient
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1487 // factor that will be used at the next depth(s) will allow more tissue super-
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1488 // saturation, maybe so much more that the next stop(s) will be allowed to ascent
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1489 // to. So we have to probe the next stops that are within the reach of 1 minute
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1490 // of ascent as well.
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1491
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1492 // compute depth in meters that is reachable within 1 minute of ascent at 10 m/min
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1493 depth_1min = ( char_depth_sim > 10 ) ? char_depth_sim - 10 : 0;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1494
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1495 // probe all stop depths that are in reach of 1 minute of ascent
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1496 next_stop = stop_depth;
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1497
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1498 while(next_stop > 0)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1499 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1500 // compute the depth of the next stop to probe
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1501 if ( next_stop <= char_I_last_stop_depth ) next_stop = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1502 else if ( next_stop == 6 ) next_stop = char_I_last_stop_depth;
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1503 else next_stop -= 3;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1504
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1505 // done if the next stop would be above the 1 minute limit
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1506 if( next_stop < depth_1min ) return(1);
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1507
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1508 // compute the ceiling for the next stop depth
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1509 calc_limit(GF_high - GF_slope * (float)next_stop);
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1510
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1511 // done if the next stop would be above the ceiling
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1512 if( next_stop < (unsigned char)(ceiling * BAR_TO_METER + 0.99) ) return(1);
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1513
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1514 // the next stop depth is allowed, ascent to it and redo trying further stop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1515 char_depth_sim = next_stop;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1516 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1517
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1518 // reached the surface, done with no further stop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1519 return(0);
0
heinrichsweikamp
parents:
diff changeset
1520 }
heinrichsweikamp
parents:
diff changeset
1521
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1522
0
heinrichsweikamp
parents:
diff changeset
1523 //////////////////////////////////////////////////////////////////////////////
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1524 // Take the actual currently used gas for ascent & deco calculation
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1525 //
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1526 // Input: start_gas_num number of the gas/dil to start with (1..5 or 6)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1527 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1528 // Output: sim_gas_current_num 1..6 or 0 for the manually configured gas/dil
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1529 // 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
1530 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1531 static void gas_take_current(void)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1532 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1533 assert( 1 <= start_gas_num && start_gas_num <= 6 );
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1534
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1535
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1536 // check origin of the gas/diluent to start with
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1537 if( start_gas_num <= NUM_GAS )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1538 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1539 // pre-configured gas/diluent
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1540
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1541 // set gas number
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1542 sim_gas_current_num = sim_gas_last_num = start_gas_num;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1543
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1544 // set change depth
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1545 sim_gas_current_depth = char_I_deco_gas_change[start_gas_num-1];
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1546
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1547 // capture case of non-configured change depth
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1548 if( sim_gas_current_depth == 0 ) sim_gas_current_depth = 255;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1549 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1550 else
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1551 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1552 // on-the-fly configured gas/diluent ("gas 6")
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1553
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1554 // set gas number
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1555 sim_gas_current_num = sim_gas_last_num = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1556
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1557 // set change depth
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1558 sim_gas_current_depth = char_I_gas6_depth;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1559 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1560 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1561
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1562
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1563 //////////////////////////////////////////////////////////////////////////////
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1564 // Find the 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
1565 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1566 // Input: char_depth_sim simulated depth in meters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1567 // sim_gas_current_num number of the currently used gas/dil
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1568 // deco_gas_type[] types and state of the gases/dils
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1569 // char_I_deco_gas_change[] change depths of the gases/dils
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1570 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1571 // Modified: sim_gas_best_num index of the gas (1..5) - only if return value is true
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1572 // sim_gas_best_depth switch depth - only if return value is true
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1573 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1574 // Return value is TRUE if a better gas is available
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1575 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1576 static unsigned char gas_find_best(void)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1577 {
641
1212d39c9f6f 3.14 beta work
heinrichsweikamp
parents: 640
diff changeset
1578 overlay unsigned char switch_depth = sim_gas_current_depth;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1579 overlay unsigned char switch_gas = 0;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1580
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1581
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1582 // loop over all gases to find the shallowest one below or at current depth
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1583 for( j = 0; j < NUM_GAS; ++j )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1584 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1585 // is this gas available?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1586 if( ( deco_gas_type[j] & GAS_TYPE_MASK ) // gas enabled (type > 0) ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1587 && !( deco_gas_type[j] & GAS_AVAIL_MASK ) // neither lost nor staged ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1588 )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1589
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1590 // is it not a deco gas unless:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1591 // extended stops are activated
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1592 // OR we are on a deco stop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1593 // OR we are in bailout but not in cave mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1594 if( ( ( deco_gas_type[j] & GAS_TYPE_MASK ) < 3 )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1595 || ( ( main_status & EXTENDED_STOPS ) )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1596 || ( ( deco_status & CALC_NORM ) && ( deco_info & DECO_STOPS_NORM ) )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1597 || ( ( deco_status & CALC_ALT ) && ( deco_info & DECO_STOPS_ALT ) )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1598 || ( ( deco_status & BAILOUT_MODE ) && !( main_status & CAVE_MODE ) )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1599 )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1600
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1601 // is the change depth of the this gas deeper than or
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1602 // at least equal to the current depth?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1603 if( char_I_deco_gas_change[j] >= char_depth_sim )
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1604
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1605 // is the change depth of this gas shallower than
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1606 // the change depth of the best gas found so far,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1607 // or is it the first better gas found?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1608 if( char_I_deco_gas_change[j] < switch_depth )
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1609
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1610 #ifdef _gas_contingency
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1611 // is there still enough of this gas or shall we don't care?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1612 if( !(deco_gas_type[j] & GAS_FULLY_USED_UP )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1613 || !( main_status & GAS_CONTINGENCY )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1614 || !( main_status & CALC_VOLUME )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1615 )
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1616 #endif
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1617
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1618 // 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
1619 {
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1620 // memorize this gas (1..5) and its change depth
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1621 switch_gas = j+1;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1622 switch_depth = char_I_deco_gas_change[j];
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1623 }
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1624
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1625 } // continue looping through all gases to eventually find an even better gas
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1626
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1627 // has a best gas been found?
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1628 if( switch_gas )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1629 {
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1630 // YES - export the best gas and its change depth
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1631 sim_gas_best_num = switch_gas;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1632 sim_gas_best_depth = switch_depth;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1633
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1634 // is the best gas different from the current gas?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1635 if( sim_gas_best_num != sim_gas_current_num )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1636 {
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1637 // YES - signal advice for a gas change
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1638 return 1;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1639 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1640 }
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1641
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1642 // no best gas found or current gas is the best gas
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1643 return 0;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1644 }
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1645
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1646
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1647 //////////////////////////////////////////////////////////////////////////////
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1648 // Switch to the best gas
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1649 //
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1650 // Input: sim_gas_best_num index of the best gas (1..5)
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1651 // sim_gas_best_depth switch depth of the best gas
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1652 //
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1653 // Modified: sim_gas_current_num index of the new gas (1..5)
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1654 // sim_gas_current_depth switch depth of the new gas
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1655 //
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1656 static void gas_take_best(void)
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1657 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1658 // memorize current gas as last gas used
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1659 sim_gas_last_num = sim_gas_current_num;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1660
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1661 // set new gas
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1662 sim_gas_current_num = sim_gas_best_num;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1663 sim_gas_current_depth = sim_gas_best_depth;
0
heinrichsweikamp
parents:
diff changeset
1664 }
heinrichsweikamp
parents:
diff changeset
1665
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1666
0
heinrichsweikamp
parents:
diff changeset
1667 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1668 // Set calc_N2/He/O2_ratios by sim_gas_current_num
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1669 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1670 // Input: sim_gas_current_num index of gas to use
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1671 // real_O2_ratio, real_He_ratio if gas = 0 (the manually set gas)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1672 // char_I_deco_O2/He_ratio[] if gas = 1..5 (the configured gases)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1673 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1674 // Output: sim_N2_ratio, sim_He_ratio ratios of the inert gases
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1675 // sim_pSCR_drop ppO2 drop in pSCR loop
0
heinrichsweikamp
parents:
diff changeset
1676 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1677 static void gas_set_ratios(void)
0
heinrichsweikamp
parents:
diff changeset
1678 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1679 overlay float sim_IG_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1680
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1681 assert( 0 <= sim_gas_current_num <= NUM_GAS );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1682
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1683
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1684 #ifdef _helium
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1685 // get gas ratios
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1686 if( sim_gas_current_num == 0 )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1687 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1688 sim_O2_ratio = real_O2_ratio;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1689 sim_He_ratio = real_He_ratio;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1690 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1691 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1692 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1693 sim_O2_ratio = 0.01 * char_I_deco_O2_ratio[sim_gas_current_num-1];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1694 sim_He_ratio = 0.01 * char_I_deco_He_ratio[sim_gas_current_num-1];
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1695 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1696
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1697 // inert gas ratio (local helper variable)
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1698 sim_IG_ratio = 1.00 - sim_O2_ratio;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1699
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1700 // N2 ratio
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1701 sim_N2_ratio = sim_IG_ratio - sim_He_ratio;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1702 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1703 // get O2 ratio
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1704 sim_O2_ratio = ( sim_gas_current_num == 0 ) ? real_O2_ratio : 0.01 * char_I_deco_O2_ratio[sim_gas_current_num-1];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1705
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1706 // set H2 ratio to zero
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1707 sim_He_ratio = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1708
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1709 // inert gas ratio (local helper variable)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1710 sim_IG_ratio = 1.00 - sim_O2_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1711
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1712 // N2 ratio
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1713 sim_N2_ratio = sim_IG_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1714 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1715
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1716 #ifdef _ccr_pscr
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1717 // ppO2 drop in pSCR loop
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1718 sim_pSCR_drop = sim_IG_ratio * float_pSCR_factor;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1719 #endif
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1720
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1721
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1722 assert( 0.0 <= sim_N2_ratio && sim_N2_ratio <= 0.95 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1723 assert( 0.0 <= sim_He_ratio && sim_He_ratio <= 0.95 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1724 assert( (sim_N2_ratio + sim_He_ratio) <= 0.95 );
0
heinrichsweikamp
parents:
diff changeset
1725 }
heinrichsweikamp
parents:
diff changeset
1726
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1727
0
heinrichsweikamp
parents:
diff changeset
1728 //////////////////////////////////////////////////////////////////////////////
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1729 // Compute respired ppO2, ppN2 and ppHe
0
heinrichsweikamp
parents:
diff changeset
1730 //
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1731 // Input: tissue_increment : selector for simulated/real tissues and gases
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1732 // main_status : breathing mode for real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1733 // deco_status : breathing mode for simulated tissues
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1734 // sim_/real_O2_ratio : (simulated) O2 ratio breathed
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1735 // sim_/real_N2_ratio : (simulated) N2 ratio breathed
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1736 // sim_/real_He_ratio : (simulated) He ratio breathed
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1737 // sim_/real_pres_respiration : (simulated) respiration pressure [bar]
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1738 // sim_/real_pSCR_drop : (simulated) pSCR O2 drop
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1739 // pres_surface : surface pressure [bar]
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1740 // 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
1741 // ppWater : water-vapor pressure inside respiratory tract [bar]
0
heinrichsweikamp
parents:
diff changeset
1742 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1743 // Output: ppN2 : respired N2 partial pressure
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1744 // ppHe : respired He partial pressure
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1745 // char_ppO2 : breathed ppO2 in %, used for CNS calculation
0
heinrichsweikamp
parents:
diff changeset
1746 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1747 void calc_alveolar_pressures(void)
0
heinrichsweikamp
parents:
diff changeset
1748 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1749 overlay float calc_pres_respiration;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1750 overlay float calc_O2_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1751 overlay float calc_N2_ratio;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1752
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1753 #ifdef _helium
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1754 overlay float calc_He_ratio;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1755 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1756
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1757 #ifdef _ccr_pscr
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1758 overlay float calc_pSCR_drop;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1759 #endif
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1760
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1761 overlay unsigned char status;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1762
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1763
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1764 assert( 0.00 <= real_N2_ratio && real_N2_ratio <= 1.00 );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1765 assert( 0.00 <= real_He_ratio && real_He_ratio <= 1.00 );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1766 assert( (real_N2_ratio + real_He_ratio) <= 1.00 );
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1767 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
1768
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1769 assert( 0.00 <= sim_N2_ratio && real_N2_ratio <= 1.00 );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1770 assert( 0.00 <= sim_He_ratio && real_He_ratio <= 1.00 );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1771 assert( (sim_N2_ratio + sim_He_ratio) <= 1.00 );
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1772 assert( 0.800 < sim_pres_respiration && sim_pres_respiration < 14.0 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1773
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1774
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1775 // get input data according to context
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1776 if( tissue_increment & TISSUE_SELECTOR )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1777 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1778 //---- real tissues -----------------------------------------------------------
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1779 calc_pres_respiration = real_pres_respiration;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1780
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1781 status = main_status;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1782 calc_O2_ratio = real_O2_ratio;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1783 calc_N2_ratio = real_N2_ratio;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1784
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1785 #ifdef _helium
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1786 calc_He_ratio = real_He_ratio;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1787 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1788
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1789 #ifdef _ccr_pscr
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1790 calc_pSCR_drop = real_pSCR_drop;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1791 #endif
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1792 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1793 else
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1794 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1795 //---- simulated tissues ------------------------------------------------------
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1796
640
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 635
diff changeset
1797 #ifdef _cave_mode
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 635
diff changeset
1798 // in cave mode?
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 635
diff changeset
1799 if( !(main_status & CAVE_MODE) )
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 635
diff changeset
1800 {
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 635
diff changeset
1801 #endif
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 635
diff changeset
1802
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 635
diff changeset
1803 // (NO) - correct sim_pres_respiration if shallower than calculated stop depth
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 635
diff changeset
1804 calc_pres_respiration = ( real_pres_respiration < sim_pres_respiration ) ? real_pres_respiration : sim_pres_respiration;
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 635
diff changeset
1805
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 635
diff changeset
1806 #ifdef _cave_mode
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 635
diff changeset
1807 }
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 635
diff changeset
1808 #endif
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 635
diff changeset
1809
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1810
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1811 status = deco_status;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1812 calc_O2_ratio = sim_O2_ratio;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1813 calc_N2_ratio = sim_N2_ratio;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1814
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1815 #ifdef _helium
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1816 calc_He_ratio = sim_He_ratio;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1817 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1818
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1819 #ifdef _ccr_pscr
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1820 calc_pSCR_drop = sim_pSCR_drop;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1821 #endif
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1822 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1823
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1824 //---- OC, CCR and Bailout Mode Gas Calculations -----------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1825
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1826 // calculate ppO2 of pure oxygen
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1827 ppO2_O2 = calc_pres_respiration - ppWater;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1828
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1829 // capture failure condition in case real_pres_respiration is < ppWater (should never happen...)
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1830 if( ppO2_O2 < 0.0 ) ppO2_O2 = 0.0;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1831
602
ab88a7e3de94 2.98 release
heinrichsweikamp
parents: 597
diff changeset
1832 // calculate ppO2 of the pure gas (OC, diluent)
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1833 ppO2_OC = ppO2_O2 * calc_O2_ratio;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1834
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1835 #ifdef _ccr_pscr
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1836
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1837 // calculate pSCR ppO2
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1838 ppO2_pSCR = ppO2_OC - calc_pSCR_drop;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1839
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1840 // capture failure condition in case ppO2_pSCR becomes negative
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1841 if( ppO2_pSCR < 0.0 ) ppO2_pSCR = 0.0;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1842
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1843
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1844 //---- Loop modes : adjust ppN2 and ppHe for change in ppO2 due to setpoint (CCR) or drop (pSCR) ---
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1845 if( status & MODE_LOOP )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1846 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1847 overlay float const_ppO2;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1848 overlay float max_ppO2;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1849
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1850 // 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
1851 const_ppO2 = 0.01 * char_I_const_ppO2;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1852
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1853 // Limit the setpoint to the maximum physically possible ppO2. This prevents for
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1854 // 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
1855 // Additionally, the ppO2 can be further reduced to account for exhaled inert gases
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1856 // accumulating in the loop by the user-adjustable setting char_I_CC_max_frac_O2.
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1857 // (ppWater is neglected here)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1858 max_ppO2 = 0.01 * char_I_CC_max_frac_O2 * calc_pres_respiration;
604
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 if( const_ppO2 > max_ppO2 ) const_ppO2 = max_ppO2;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1861
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1862 // check which kind of loop we are on
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1863 if( status & MODE_PSCR )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1864 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1865 //---- pSCR Mode --------------------------------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1866
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1867 // Use the sensor value if available and in real tissue context, else use calculated ppO2.
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1868 ppO2 = ( char_I_const_ppO2 && (tissue_increment & TISSUE_SELECTOR)) ? const_ppO2 : ppO2_pSCR;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1869 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1870 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1871 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1872 //---- CCR Mode ---------------------------------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1873
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1874 // 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
1875 ppO2 = const_ppO2;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1876 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1877
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1878 // 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
1879 // capture potential failure conditions first:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1880 if( ( calc_pres_respiration < ppO2 ) // sensor reading or selected setpoint is higher than ambient pressure
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1881 || ( calc_O2_ratio > 0.995 ) ) // diluent is pure O2, i.e. calc_N2_ratio + calc_He_ratio = 0 would give a div/0
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1882 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1883 // failure condition present, set predetermined result
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1884 calc_pres_respiration = 0.0;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1885 }
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1886 else
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 // no failure conditions present, equation can be executed
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1889 calc_pres_respiration -= ppO2;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1890 #ifdef _helium
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1891 calc_pres_respiration /= calc_N2_ratio + calc_He_ratio;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1892 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1893 calc_pres_respiration /= calc_N2_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1894 #endif
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1895 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1896 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1897 else
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1898 #endif // _ccr_pscr
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1899 {
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1900 //---- OC mode ---------------------------------------------------------------------------------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1901
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1902 // breathed ppO2 is ppO2 of pure gas
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1903 ppO2 = ppO2_OC;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1904 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1905
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1906
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1907 //---- derive char_ppO2 in [cbar], used for calculating CNS% ---------------------------------------
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1908
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1909 if ( ppO2 < 0.01 ) char_ppO2 = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1910 else if ( ppO2 >= 2.545 ) char_ppO2 = 255;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1911 else char_ppO2 = (unsigned char)(100 * ppO2 + 0.5);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1912
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1913
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1914 //---- calculate ppN2 and ppHe ---------------------------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1915
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1916 // compute ppN2 and ppHe, capture potential failure conditions first:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1917 if( calc_pres_respiration > ppWater )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1918 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1919 // subtract water vapor pressure
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1920 calc_pres_respiration -= ppWater;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1921
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1922 // calculate partial pressures
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1923 ppN2 = calc_N2_ratio * calc_pres_respiration;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1924
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1925 #ifdef _helium
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1926 ppHe = calc_He_ratio * calc_pres_respiration;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1927 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1928 ppHe = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1929 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1930
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1931 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1932 else
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1933 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1934 // 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
1935 ppN2 = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1936 ppHe = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1937 }
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1938
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
1939 #ifdef _ccr_pscr
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1940 // calculating real tissues?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1941 if( tissue_increment & TISSUE_SELECTOR )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1942 {
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1943 overlay unsigned char temp;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1944
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1945 // compute gas density of current mix in multiples of 0.01 grams per liter
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1946 int_O_gas_density = (unsigned int)( 17.9 * ppHe + 125.1 * ppN2 + 142.8 * ppO2 );
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1947
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
1948 // convert gas density into an 8 bit integer, scaling 0.1 grams per liter
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1949 temp = (unsigned char)( (int_O_gas_density + 9) / 10 );
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1950
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1951 // limit to display max and set warning or attention flag
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
1952 if( temp > 99 ) int_O_gas_density = 999 | INT_FLAG_WARNING;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
1953 else if( temp >= char_I_gas_density_warn ) int_O_gas_density |= INT_FLAG_WARNING;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
1954 else if( temp >= char_I_gas_density_att ) int_O_gas_density |= INT_FLAG_ATTENTION;
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1955 }
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
1956 #endif
0
heinrichsweikamp
parents:
diff changeset
1957 }
heinrichsweikamp
parents:
diff changeset
1958
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1959
0
heinrichsweikamp
parents:
diff changeset
1960 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1961 // Initializes all output variables to their default values
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1962 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1963 static void init_output_vars(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1964 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1965 // clear the internal stops table from remains lasting from the previous dive or deco calculator run
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1966 clear_deco_table();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1967
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1968 // publish the cleared stops table to the display functions
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1969 publish_deco_table();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1970
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1971 // clear the published gas needs in volume and pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1972 for( i = 0; i < NUM_GAS; ++i )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1973 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1974 int_O_gas_need_vol[i] = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1975 int_O_gas_need_pres[i] = 0 + INT_FLAG_ZERO + INT_FLAG_INVALID;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1976 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1977
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1978 // values initially to be set to zero
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1979 int_O_ceiling = 0; // ceiling depth in mbar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1980 char_O_deco_info = 0; // clear all deco information flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1981 char_O_deco_warnings = 0; // clear all deco warning flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1982
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1983 // default desaturation time to 24 hours (it will not be computed during a dive)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1984 int_O_desaturation_time = 1440;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1985
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1986 // initialize CNS values
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1987 int_O_CNS_norm = 0 + INT_FLAG_INVALID;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1988 int_O_CNS_alt = 0 + INT_FLAG_INVALID;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1989
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1990 // initialize NDL times
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1991 int_O_NDL_norm = 240;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1992 int_O_NDL_alt = 240;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1993
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1994 // initialize stop times
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1995 int_O_TST_norm = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1996 int_O_TST_alt = 0 + INT_FLAG_INVALID + INT_FLAG_NOT_COMPUTED_YET + INT_FLAG_ZERO;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1997
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1998
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
1999 // initialize ascent / return times
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2000 int_O_TTS_norm = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2001 int_O_TTS_alt = 0 + INT_FLAG_INVALID + INT_FLAG_NOT_COMPUTED_YET;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2002
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2003 #ifdef _rx_functions
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2004 // clear TR values
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2005 int_O_SAC_measured = 0 + INT_FLAG_NOT_AVAIL; // SAC rate
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2006 int_O_pressure_need[0] = 0 + INT_FLAG_NOT_AVAIL; // pressure need to reading 1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2007 int_O_pressure_need[1] = 0 + INT_FLAG_NOT_AVAIL; // pressure need to reading 2
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2008 int_O_tank_pressure = 0; // tank pressure for logging
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2009 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2010
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2011 #ifdef _helium
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2012 int_O_gas_density = 0;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2013 #endif
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2014
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2015 // also clear any time++ request
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2016 char_I_sim_advance_time = 0;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2017 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2018
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2019
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2020 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2021 // Reset all tissues to surface pressure equilibrium state
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2022 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2023 // Input: int_I_pres_surface current surface pressure in hPa (mbar)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2024 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2025 // Output: real_pres_tissue_N2[] partial pressure of N2 in real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2026 // real_pres_tissue_He[] partial pressure of He in real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2027 // char_O_tissue_pres_N2[] partial pressure of N2 for tissue graphics
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2028 // char_O_tissue_pres_He[] partial pressure of He for tissue graphics
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2029 // char_O_tissue_pressure[] total pressure for tissue graphics
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2030 // CNS_fraction_real internal CNS value
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2031 // int_O_CNS_current current CNS value
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2032 // int_O_CNS_norm CNS value at end of normal dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2033 // int_O_CNS_alt CNS value at end of alternative dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2034 // char_O_deco_warnings deco warnings vector
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2035 // int_O_NDL_norm remaining NDL time in normal dive plan
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2036 // int_O_NDL_alt remaining NDL time in alternative dive plan
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2037 // int_O_TTS_norm ascent time (TTS) in normal dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2038 // int_O_TTS_alt ascent time (TTS) in alternative dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2039 // int_O_lead_supersat supersaturation of the leading tissue
0
heinrichsweikamp
parents:
diff changeset
2040 //
heinrichsweikamp
parents:
diff changeset
2041 static void clear_tissue(void)
heinrichsweikamp
parents:
diff changeset
2042 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2043 // safeguard and convert the surface pressure (mbar -> bar) (*)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2044 if( int_I_pres_surface < 500 ) pres_surface = 0.500;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2045 else pres_surface = 0.001 * int_I_pres_surface;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2046
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2047 // calculate partial pressure of N2 in respired air at surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2048 calc_N2_equilibrium();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2049
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2050 // cycle through the 16 Buhlmann tissues
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2051 for( ci = 0; ci < NUM_COMP; ci++ )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2052 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2053 // reset tissue pressures
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2054 real_pres_tissue_He[ci] = 0.0; // He
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2055 real_pres_tissue_N2[ci] = N2_equilibrium; // N2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2056
629
237931377539 3.07 stable release
heinrichsweikamp
parents: 628
diff changeset
2057 // reset tissue pressures for scaled tissue graphics
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2058 char_O_tissue_pres_He[ci] = 0; // He
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2059 char_O_tissue_pres_N2[ci] = 10; // N2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2060 char_O_tissue_pressure[ci] = 10; // combined
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2061 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2062
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2063 // reset CNS values
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2064 CNS_fraction_real = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2065 int_O_CNS_current = int_O_CNS_norm = int_O_CNS_alt = 0;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2066
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2067 // reset some more vars to their defaults
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2068 int_O_NDL_norm = 240;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2069 int_O_NDL_alt = 240;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2070 int_O_TST_norm = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2071 int_O_TST_alt = 0 + INT_FLAG_ZERO;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2072 int_O_TTS_norm = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2073 int_O_TTS_alt = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2074 int_O_lead_supersat = 0;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2075
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2076 // reset all warning and info flags
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2077 char_O_deco_warnings = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2078 char_O_deco_info = 0;
0
heinrichsweikamp
parents:
diff changeset
2079 }
heinrichsweikamp
parents:
diff changeset
2080
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2081
0
heinrichsweikamp
parents:
diff changeset
2082 //////////////////////////////////////////////////////////////////////////////
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2083 // Deco engine main code
0
heinrichsweikamp
parents:
diff changeset
2084 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2085 // This is the major code in dive mode, it calculates the tissue pressures,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2086 // the bottom time, and it calculates the ascend with all deco stops, etc.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2087 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2088 // Input: char_O_main_status deco engine control and real tissues mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2089 // char_O_deco_status deco engine control and simulated tissues mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2090 // char_I_sim_advance_time mailbox for bottom time incrementing
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2091 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2092 // char_I_SAC_work gas usage rate during working phase in l/min
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2093 // char_I_SAC_deco gas usage rate during deco stops phase in l/min
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2094 //
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2095 // char_I_model selector for GF extension
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2096 // char_I_saturation_multiplier safety factor for tissue saturation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2097 // char_I_desaturation_multiplier safety factor for tissue desaturation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2098 //
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2099 // char_I_pressure_gas[] amount of gas available for ascent / cave return in bar
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2100 // int_I_pressure_drop[] pressure drop used to calculate SAC rate
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2101 // char_I_gas_avail_size[] size of the tanks in liters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2102 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2103 // Output: int_O_O2_ppO2 partial pressure of pure O2 at current depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2104 // int_O_pure_ppO2 partial pressure of O2 in gas at current depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2105 // int_O_pSCR_ppO2 partial pressure of O2 in gas at current depth, corrected for pSCR mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2106 // int_O_breathed_ppO2 partial pressure of O2 currently breathed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2107 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2108 // char_O_deco_status deco engine computations status
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2109 // char_O_deco_info deco engine information vector
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2110 // char_O_deco_warnings deco engine warnings vector
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2111 //
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2112 // int_O_NDL_norm remaining NDL time in normal dive plan
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2113 // int_O_NDL_alt remaining NDL time in alternative dive plan
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2114 // int_O_TTS_norm ascent time (TTS) in normal dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2115 // int_O_TTS_alt ascent time (TTS) in alternative dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2116 // int_O_CNS_norm CNS value at end of normal dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2117 // int_O_CNS_alt CNS value at end of alternative dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2118 //
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2119 // int_O_gas_need_vol[] calculated gas volumes needed for ascent / cave return
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2120 // int_O_gas_need_pres[] calculated gas pressures needed for ascent / cave return
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2121 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2122 // int_O_SAC_measured measured surface air consumption (SAC) rate in l/min
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2123 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2124 // Modified: int_IO_pressure_value[] warning flags added to pressure reading 1 & 2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2125 // int_IO_pressure_need[] pressure needs to pressure reading 1 & 2
0
heinrichsweikamp
parents:
diff changeset
2126 //
heinrichsweikamp
parents:
diff changeset
2127 static void calc_hauptroutine(void)
heinrichsweikamp
parents:
diff changeset
2128 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2129 overlay unsigned short int_ppO2_min;
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2130 overlay unsigned short int_ppO2_max_warn;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2131 overlay unsigned short int_ppO2_max_att;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2132 overlay unsigned short int_ppO2_max_dil;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2133 overlay float EAD_pres;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2134 overlay float END_pres;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2135
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2136 //=============================================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2137
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2138 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2139 //--- Setup Part ---------------------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2140 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2141
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2142 // set time limit for preempting deco calculations, timer is 16 bit and increments every 1/32 ms
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2143 tmr5_value = 65535 - (32 * BUDGET_PER_SECOND / INVOKES_PER_SECOND);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2144
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2145 // load timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2146 load_tmr5();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2147
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2148 // read command flags and set up what to do
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2149 switch( char_O_deco_status & COMMAND_MASK )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2150 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2151
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2152 case INITIALIZE:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2153 case INITIALIZE_START_NORM:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2154 case INITIALIZE_START_ALT:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2155
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2156 // copy master modes to shadow registers
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2157 main_status = char_O_main_status;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2158 deco_status = char_O_deco_status;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2159
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2160 // clear all command flags on the master mode to signal that the command is read
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2161 char_O_deco_status &= ~COMMAND_MASK;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2162
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2163 // clear the initialization flag on the shadow copy
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2164 deco_status &= ~INITIALIZE;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2165
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2166 // initialize the sequence timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2167 sequence_timer = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2168
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2169 // set the calculation phase to start with to doing the once-per-dive initialization
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2170 next_planning_phase = PHASE_10_DIVE_INIT;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2171
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2172 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2173
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2174
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2175 case START_NORM:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2176 case START_ALT:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2177
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2178 // copy master modes to shadow registers
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2179 main_status = char_O_main_status;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2180 deco_status = char_O_deco_status;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2181
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2182 // clear all command flags on the master mode to signal that the command is read
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2183 char_O_deco_status &= ~COMMAND_MASK;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2184
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2185 // set the calculation phase to start with to doing the cyclic initialization
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2186 next_planning_phase = PHASE_20_CYCLIC_INIT;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2187
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2188 // continue in CALCULATING
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2189
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2190
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2191 case CALCULATING:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2192
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2193 // keep current calculation phase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2194
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2195 // step the sequence timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2196 sequence_timer = (sequence_timer < INVOKES_PER_SECOND * 2 - 1) ? sequence_timer + 1 : 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2197
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2198 break;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2199 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2200
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2201
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2202 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2203 //--- End of Setup Part -----------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2204 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2205
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2206 //=============================================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2207
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2208 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2209 //---- Calculations Part (real Tissues) -------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2210 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2211
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2212
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2213 // target the real tissues with 2 second increments by default
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2214 tissue_increment = TISSUE_SELECTOR | 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2215
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2216
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2217 // Tasks every second, if more than 1 invocation per second: on the first section of the second.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2218 // Requests for tissue "fast forward" are executed immediately.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2219 #if (INVOKES_PER_SECOND > 1)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2220 if( ( sequence_timer == 0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2221 || ( sequence_timer == INVOKES_PER_SECOND )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2222 || ( char_I_sim_advance_time > 0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2223 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2224 #endif
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
2225 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2226 // acquire current environmental data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2227 calc_hauptroutine_data_input();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2228
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2229 // calculate ppO2, ppN2 and ppHe for real tissues
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2230 calc_alveolar_pressures();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2231
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2232 // add decent calculation here and include trigger in above if-statement
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2233 // TODO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2234
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2235 } // tasks every second, on the first section of the second
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2236
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2237
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2238 // Tasks every 2 seconds, on the first section of the respective second.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2239 // Requests for tissue "fast forward" are executed immediately.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2240 if( ( sequence_timer == 0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2241 || ( char_I_sim_advance_time > 0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2242 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2243 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2244 // Tissue and CNS updates are based on 2 seconds periods!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2245
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2246 // 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
2247 // sim+5' function and deco calculator bottom time calculation.
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2248 if( char_I_sim_advance_time > 0 )
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 // configure "fast forward" tissue updating
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2251 tissue_increment = TISSUE_SELECTOR | char_I_sim_advance_time;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2252
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2253 // clear the request
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2254 char_I_sim_advance_time = 0;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2255 }
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2256
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
2257 // calculate the real tissues
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
2258 calc_tissues();
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
2259
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2260 // update the CNS value for the real tissues
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2261 calc_CNS();
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2262
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2263 // calculate ceiling (at GF_high or 100%) and leading tissue supersaturation
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2264 if ( char_I_model ) calc_limit(GF_high); // GF factors enabled
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2265 else calc_limit( 1.0 ); // classic Buhlmann
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2266
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2267 // convert the ceiling value to integer
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2268 convert_ceiling_for_display();
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2269
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2270 // convert the saturation value of the leading tissue to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2271 convert_sat_for_display();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2272
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2273 // convert the CNS value to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2274 convert_cur_CNS_for_display();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2275
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2276 } // tasks every 2 seconds
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2277
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2278
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2279 // Tasks every second, if more than 1 invocation per second: on the first section of the second.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2280 #if (INVOKES_PER_SECOND > 1)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2281 if( ( sequence_timer == 0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2282 || ( sequence_timer == INVOKES_PER_SECOND )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2283 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2284 #endif
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2285 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2286 //---- Calculate and Export EAD and END ------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2287
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2288 // calculate EAD (Equivalent Air Depth) as pressure in [bar]:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2289 // equivalent depth for the same N2 level with plain air
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2290 EAD_pres = ppN2 / 0.7902 + ppWater - pres_surface;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2291
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2292 // calculate END (Equivalent Narcotic Depth) as pressure in [bar]:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2293 // as before, but with O2 treated as narcotic, too
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2294 // Source: The Physiology and Medicine of Diving by Peter Bennett and David Elliott,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2295 // 4th edition, 1993, W.B.Saunders Company Ltd, London.
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2296 END_pres = real_pres_respiration - ppHe - pres_surface;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2297
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2298
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2299 // export EAD, factor 10 is because conversion delivers in [cbar] but we need [mbar]
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2300 float_value = EAD_pres; convert_float_to_int(); int_O_EAD_pres = int_value * 10;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2301
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2302 // export END, factor 10 is because conversion delivers in [cbar] but we need [mbar]
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2303 float_value = END_pres; convert_float_to_int(); int_O_END_pres = int_value * 10;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2304
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2305
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2306 //---- Compute ppO2 Values in [cbar] ---------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2307
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2308 float_value = ppO2; convert_float_to_int(); int_O_breathed_ppO2 = int_value; // breathed gas
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2309 #ifdef _ccr_pscr
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2310 float_value = ppO2_O2; convert_float_to_int(); int_O_O2_ppO2 = int_value; // pure oxygen
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2311 float_value = ppO2_OC; convert_float_to_int(); int_O_pure_ppO2 = int_value; // pure gas
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2312 float_value = ppO2_pSCR; convert_float_to_int(); int_O_pSCR_ppO2 = int_value; // pSCR calculated
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2313 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2314
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2315
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2316 //---- Set/Clear Deco Mode ------------------------------------------------------------------
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2317
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2318 // Clear the deco mode flag if:
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2319 // deco mode is set
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2320 // AND we are deeper than 7 meters below the deepest deco stop
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2321 // (7 meters chosen as to be 2 stop depth intervals plus 1 additional meter below)
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2322 if ( ( deco_info & DECO_MODE ) > 0 )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2323 if ( ( char_depth_real ) > char_O_deco_depth[0] + 7 )
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2324 deco_info &= ~DECO_MODE;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2325
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2326 // Set the deco mode flag if:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2327 // deco mode is not set
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2328 // AND breathing an OC deco gas (gas type 3)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2329 // OR breathing a gas or diluent that officially is disabled (type 0)
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2330 // OR there is a deco stop
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2331 //
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2332 // Remark: when breathing a gas, its lost & staged flags are cleared
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2333 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2334 if ( ( deco_info & DECO_MODE ) == 0 )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2335 if ( ( char_I_current_gas_type == 3 )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2336 || ( char_I_current_gas_type == 0 )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2337 || ( char_O_deco_depth[0] > 0 )
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2338 )
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2339 deco_info |= DECO_MODE;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2340
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2341
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2342 //---- Compute ppO2 Warnings ------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2343
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2344 // compute conditional min value
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2345 #ifdef _ccr_pscr
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2346 int_ppO2_min = ( main_status & MODE_LOOP ) ? (unsigned short)char_I_ppO2_min_loop : (unsigned short)char_I_ppO2_min;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2347 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2348 int_ppO2_min = (unsigned short)char_I_ppO2_min;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2349 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2350
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2351 // determine the absolute max value (should be the deco one, but who knows...)
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2352 int_ppO2_max_warn = ( char_I_ppO2_max_work > char_I_ppO2_max_deco) ? char_I_ppO2_max_work : char_I_ppO2_max_deco;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2353
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2354 // add some margin to compensate for surface pressures > 1.000 mbar
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2355 int_ppO2_max_warn += ppO2_MARGIN_ON_MAX;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2356
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2357 // determine the normal max value
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2358 int_ppO2_max_att = ( deco_info & DECO_MODE ) ? (unsigned short)char_I_ppO2_max_deco : (unsigned short)char_I_ppO2_max_work;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2359
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2360 // add some margin to compensate for surface pressures > 1.000 mbar
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2361 int_ppO2_max_att += ppO2_MARGIN_ON_MAX;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2362
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2363 #ifdef _ccr_pscr
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2364 // default value for the upper diluent ppO2 warning threshold is the upper warning threshold
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2365 int_ppO2_max_dil = int_ppO2_max_warn;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2366
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2367 // when enabled and in CCR mode, the upper diluent warning threshold gets adjust according to the current setpoint
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2368 if( char_I_dil_check )
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2369 if( (main_status & MODE_MASK) == MODE_CCR )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2370 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2371 overlay unsigned short max_dil;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2372
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2373 // The upper diluent ppO2 threshold is ppO2_GAP_TO_SETPOINT below the setpoint...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2374 // (the condition protects from negative numbers which would cause a wrap-around in unsigned integers)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2375 max_dil = (char_I_const_ppO2 > ppO2_GAP_TO_SETPOINT) ? (unsigned short)(char_I_const_ppO2 - ppO2_GAP_TO_SETPOINT) : 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2376
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2377 // ...but never above int_ppO2_max_warn
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2378 if( max_dil < int_ppO2_max_warn ) int_ppO2_max_dil = max_dil;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2379
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2380 // We do not need to guard int_ppO2_max_dil against becoming lower than char_I_ppO2_min because the check
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2381 // against char_I_ppO2_min is done first and will then raise a low warning and inhibit further checks.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2382 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2383 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2384
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2385 // check for safe range of breathed gas
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2386 if ( int_O_breathed_ppO2 <= int_ppO2_min ) int_O_breathed_ppO2 |= INT_FLAG_WARNING + INT_FLAG_LOW;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2387 else if ( int_O_breathed_ppO2 >= int_ppO2_max_warn ) int_O_breathed_ppO2 |= INT_FLAG_WARNING + INT_FLAG_HIGH;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2388 else if ( deco_info & DECO_MODE ) ; // no attention generated in deco mode
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2389 else if ( main_status & MODE_LOOP ) ; // no attention generated in loop modes
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2390 else if ( int_O_breathed_ppO2 >= int_ppO2_max_att ) int_O_breathed_ppO2 |= INT_FLAG_ATTENTION;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2391
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2392 #ifdef _ccr_pscr
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2393 // check for safe range of pure oxygen
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2394 if ( int_O_O2_ppO2 >= int_ppO2_max_warn ) int_O_O2_ppO2 |= INT_FLAG_WARNING + INT_FLAG_HIGH;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2395
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2396 // check for safe range of pure diluent
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2397 if ( int_O_pure_ppO2 <= (unsigned short)char_I_ppO2_min ) int_O_pure_ppO2 |= INT_FLAG_WARNING + INT_FLAG_LOW;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2398 else if ( int_O_pure_ppO2 >= int_ppO2_max_warn ) int_O_pure_ppO2 |= INT_FLAG_WARNING + INT_FLAG_HIGH;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2399 else if ( int_O_pure_ppO2 >= int_ppO2_max_dil ) int_O_pure_ppO2 |= INT_FLAG_ATTENTION;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2400
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2401 // check for safe range of calculated pSCR loop gas
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2402 if ( int_O_pSCR_ppO2 <= int_ppO2_min ) int_O_pSCR_ppO2 |= INT_FLAG_WARNING + INT_FLAG_LOW;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2403 else if ( int_O_pSCR_ppO2 >= int_ppO2_max_warn ) int_O_pSCR_ppO2 |= INT_FLAG_WARNING + INT_FLAG_HIGH;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2404 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2405
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2406 } // tasks every second / on the first section of the second
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2407
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 #ifdef _rx_functions
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2410
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2411 // only when TR functions are enabled
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2412 if( main_status & TR_FUNCTIONS )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2413
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2414 // Tasks every second, if more than 1 invocation per second: on the second section of the second.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2415 #if (INVOKES_PER_SECOND > 1)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2416 if( ( sequence_timer == 1 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2417 || ( sequence_timer == INVOKES_PER_SECOND + 1 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2418 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2419 #endif
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2420 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2421 calc_TR_functions();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2422 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2423
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2424 #endif // _rx_functions
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2425
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2426
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2427 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2428 //---- End of Computations for the real Tissues -----------------------------------------------
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2429 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2430
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2431 //=============================================================================================
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2432
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2433 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2434 //---- Begin of Computations for Ascent and Decompression (simulated Tissues) -----------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2435 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2436
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2437 // Dispatcher: select what to do based on the current calculation phase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2438 do
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2439 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2440
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2441 #ifdef _profiling
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2442 profiling_phase = next_planning_phase;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2443 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2444
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2445 switch( next_planning_phase )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2446 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2447
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2448 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2449 //---- once-per-dive Initialization of the Deco Engine ------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2450 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2451 case PHASE_10_DIVE_INIT:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2452
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2453 // initialize all output variables to defaults
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2454 init_output_vars();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2455
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2456 // initialize values that will be recalculated later on periodically
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2457 deco_warnings = 0; // reset all deco warnings
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2458 deco_info = 0; // reset all deco infos
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2459 IBCD_tissue_vector = 0; // reset tissue IBCD vector
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2460 NDL_tissue_start_norm = 0; // initialize the tissue to start with when calculating normal NDL time
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2461 NDL_tissue_start_alt = 0; // initialize the tissue to start with when calculating alternative NDL time
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2462
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2463 // enforce initialization of GF data on first cyclic initialization
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2464 GF_high_last = 255;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2465 GF_low_last = 255;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2466
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2467
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2468 // calculate volumes available for each gas
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2469 for( i = 0; i < NUM_GAS; i++ )
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2470 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2471 // total available volume = tank size * fill press, char_I_gas_avail_pres is in multiples of 10 bar
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2472 gas_volume_avail[i] = (float)char_I_gas_avail_size[i] * (float)char_I_gas_avail_pres[i] * 10.0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2473
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2474 // attention threshold
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2475 gas_volume_atten[i] = gas_volume_avail[i] * GAS_NEEDS_ATTENTION;
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2476 }
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2477
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2478
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2479 #ifdef _profiling
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2480 int_O_profiling_overrun_max = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2481 char_O_profiling_runs_norm = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2482 char_O_profiling_runs_alt = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2483 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2484
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2485
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2486 // the next calculation phase will do the cyclic initialization of the deco engine if a
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2487 // normal or alternative plan shall be calculated, else the calculation cycle is done.
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2488 if( deco_status & PLAN_MASK ) next_planning_phase = PHASE_20_CYCLIC_INIT;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2489 else next_planning_phase = PHASE_00_DONE;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2490
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2491 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2492
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2493
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2494 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2495 //---- once-per-cycle Initialization of the Deco Engine -----------------------------------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2496 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2497 case PHASE_20_CYCLIC_INIT:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2498
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2499 // target the simulated tissues (flag bit 7 = 0)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2500 tissue_increment = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2501
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2502 // clear the internal stops table
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2503 clear_deco_table();
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2504
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2505 // clear deco stops info
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2506 if( deco_status & CALC_NORM ) deco_info &= ~DECO_STOPS_NORM;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2507 else deco_info &= ~DECO_STOPS_ALT;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2508
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2509 // 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
2510 for( i = 0; i < NUM_COMP; i++ )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2511 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2512 sim_pres_tissue_N2[i] = real_pres_tissue_N2[i];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2513 sim_pres_tissue_He[i] = real_pres_tissue_He[i];
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2514 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2515
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2516 // initialize the gas types
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2517 for( i = 0; i < NUM_GAS; i++ )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2518 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2519 deco_gas_type[i] = char_I_deco_gas_type[i];
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2520 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2521
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2522 #ifdef _gas_contingency
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2523 // if in gas contingency mode,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2524 // check if there are multiple tanks with the same gas
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2525 // (or at least with the same change depth...)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2526 if( main_status & GAS_CONTINGENCY )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2527 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2528 for( i = 0; i < NUM_GAS; i++ )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2529 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2530 // default to no peer tanks existing
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2531 peer_tank[i] = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2532
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2533 // tank enabled?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2534 if( char_I_deco_gas_type[i] )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2535 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2536 // YES - check for peer tanks
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2537 for( j = 0; j < NUM_GAS; j++ )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2538 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2539 // do not check a tank against itself
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2540 if( i == j ) continue;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2541
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2542 // is the other tank also enabled and does it have the same change depth?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2543 if( char_I_deco_gas_type[j] & GAS_TYPE_MASK )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2544 if( char_I_deco_gas_change[i] == char_I_deco_gas_change[j] )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2545 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2546 // YES - memorize it as a peer tank
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2547 peer_tank[i] |= (1 << j);
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2548 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2549 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2550 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2551 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2552 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2553 #endif
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2554
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2555 // initialize GF parameters if using GF model
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2556 if( char_I_model != 0 )
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2557 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2558 // update GF parameters (GFs may have been switched between GF and aGF)
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2559 if( (char_I_GF_Low_percentage != GF_low_last) || (char_I_GF_High_percentage != GF_high_last) )
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2560 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2561 // store new values in integer format
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2562 GF_low_last = char_I_GF_Low_percentage;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2563 GF_high_last = char_I_GF_High_percentage;
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2564
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2565 // safeguard and store new values in float format
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2566 GF_low = ( GF_low_last > 10 ) ? 0.01 * GF_low_last : 0.10 ;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2567 GF_high = ( GF_high_last > GF_low_last ) ? 0.01 * GF_high_last : GF_low;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2568
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2569
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2570 // reset low depth references and slopes
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2571 GF_depth_norm = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2572 GF_depth_alt = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2573 GF_slope_norm = 0.0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2574 GF_slope_alt = 0.0;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2575 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2576
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2577 // retrieve GF parameters for current calculation cycle
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2578 if( deco_status & CALC_NORM )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2579 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2580 GF_depth = GF_depth_norm;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2581 GF_slope = GF_slope_norm;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2582 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2583 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2584 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2585 GF_depth = GF_depth_alt;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2586 GF_slope = GF_slope_alt;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2587 }
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2588 }
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2589
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2590 // initialize the simulated CNS value with the current CNS value of the real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2591 CNS_fraction_sim = CNS_fraction_real;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2592
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2593 // initialize the simulated pressure with the current real pressure
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2594 sim_pres_respiration = real_pres_respiration;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2595
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2596 // initialize the simulated depth with the current real depth
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2597 char_depth_sim = char_depth_start = char_depth_real;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2598
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2599 // cache the gas/dil to start calculations with
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2600 start_gas_num = char_I_current_gas_num;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2601
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2602
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2603 // Lookup the gas that is currently breathed with the real tissues and set it as
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2604 // the gas to be used with the simulated tissues, too. This gas will be used until
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2605 // gas_find_best()/gas_take_best() is invoked and switches to a better gas.
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2606 gas_take_current();
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2607
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2608 // Setup the calculation ratio's for N2, He and O2 (sim_N2/He/_O2_ratio).
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2609 // These ratios can be kept until a gas switch is done. Thus, if a call to
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2610 // gas_find_best() has found a better gas and this gas is taken by a call
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2611 // to gas_take_best(), gas_set_ratios() needs to be called again.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2612 gas_set_ratios();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2613
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2614 // compute ppO2, ppN2 and ppHe for current depth from sim_pres_respiration
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2615 calc_alveolar_pressures();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2616
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2617 // initialize the no decompression limit (NDL) time to 240 minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2618 NDL_time = 240;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2619
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2620 // clear the Total Time to Surface (TTS) and the Total Stops Time (TST)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2621 TTS_time = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2622 TST_time = 0;
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2623
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2624 // retrieve the tissue that had the shortest NDL time during last calculation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2625 NDL_tissue_start = ( deco_status & CALC_NORM ) ? NDL_tissue_start_norm : NDL_tissue_start_alt;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2626
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2627 // start calculating NDL time with the tissue that had the shortest NDL last time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2628 NDL_tissue = NDL_tissue_start;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2629 NDL_tissue_lead = NDL_tissue_start;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2630
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2631 // initialization for convert_volume_to_pressure()
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2632 gas_needs_gas_index = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2633
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2634 // tag gas needs as not calculated in fTTS mode by default
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2635 deco_info &= ~GAS_NEEDS_fTTS;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2636
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2637 // shall calculate gas needs?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2638 if( main_status & CALC_VOLUME )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2639 {
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2640 // set the usage rate (SAC rate), starting with working part of the dive
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2641 gas_needs_usage_rate = char_I_SAC_work;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2642
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2643 // clear the gas volume needs for gases 1-5
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2644 for( i = 0; i < NUM_GAS; ++i ) gas_volume_need[i] = 0.0;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2645
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2646 #ifdef _rx_functions
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2647 // only for OSTC TR model with TR functions enabled
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2648 if( main_status & TR_FUNCTIONS )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2649 {
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2650 // invalidate pressure needs to pressure readings
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2651 int_O_pressure_need[0] = 0 + INT_FLAG_NOT_AVAIL;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2652 int_O_pressure_need[1] = 0 + INT_FLAG_NOT_AVAIL;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2653 }
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2654 #endif
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2655 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2656
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2657
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2658 #ifdef _cave_mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2659 if( main_status & CAVE_MODE )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2660 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2661 // get the position of the first data set to start the backtracking from
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2662 backtrack_index = char_I_backtrack_index;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2663
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2664 // get the first backtracking data set
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2665 read_backtrack_data();
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2666 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2667 #endif
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2668
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2669
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2670 #ifdef _profiling
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2671 profiling_runs = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2672 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2673
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2674 // The next calculation phase will
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2675 // - calculate the extended bottom segment if extended bottom time is configured (fTTS),
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2676 // - calculate the bottom segment gas need if gas needs calculation is configured,
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2677 // - proceed with calculating the NDL time else.
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2678 if ( deco_status & DELAYED_ASCENT ) next_planning_phase = PHASE_30_EXTENDED_BOTTOM_TIME;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2679 else if ( main_status & CALC_VOLUME ) next_planning_phase = PHASE_40_BOTTOM_GAS_NEED;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2680 else next_planning_phase = PHASE_50_NDL_TIME;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2681
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2682 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2683
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2684
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2685 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2686 //---- extended Bottom Time ---------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2687 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2688 case PHASE_30_EXTENDED_BOTTOM_TIME:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2689
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2690 // tag gas needs as calculated in fTTS mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2691 deco_info |= GAS_NEEDS_fTTS;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2692
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2693 // program interval on simulated tissues (flag bit 7 = 0)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2694 tissue_increment = char_I_extra_time;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2695
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2696 // update the simulated tissues for tissue_increment (char_I_extra_time) minutes at depth,
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2697 // calc_alveolar_pressures() has already been called in cyclic initialization
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2698 calc_tissues();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2699
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2700 // update the CNS value for tissue_increment (char_I_extra_time) minutes at depth
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2701 calc_CNS();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2702
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2703 // the next calculation phase will
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2704 // - calculate the extended bottom segment gas needs if gas needs calculation is configured,
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2705 // - proceed with calculating the NDL time else.
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2706 if ( main_status & CALC_VOLUME ) next_planning_phase = PHASE_40_BOTTOM_GAS_NEED;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2707 else next_planning_phase = PHASE_50_NDL_TIME;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2708
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2709 break;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2710
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2711
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2712 //
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2713 //---- Bottom Segment Gas Need ------------------------------------------------------------
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2714 //
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2715 case PHASE_40_BOTTOM_GAS_NEED:
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2716
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2717 // on gas 1-5 ?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2718 if( sim_gas_current_num )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2719 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2720 // YES - take either the whole bottom time or just the fTTS/bailout extra time
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2721 gas_needs_time = ( main_status & CALCULATE_BOTTOM ) ? char_I_bottom_time : char_I_extra_time;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2722
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2723 // any time to do?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2724 if( gas_needs_time )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2725 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2726 // YES - set the bottom depth
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2727 gas_needs_depth = char_depth_start;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2728
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2729 // calculate required gas volume
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2730 calc_required_volume();
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2731
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2732 // take the result
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2733 gas_volume_need[sim_gas_current_num-1] = gas_needs_volume_due;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2734 }
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2735 }
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2736
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2737
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2738 // the next calculation phase will calculate the NDL time
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2739 next_planning_phase = PHASE_50_NDL_TIME;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2740
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2741 break;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2742
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2743
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2744 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2745 //---- NDL Time ---------------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2746 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2747 case PHASE_50_NDL_TIME:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2748
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2749 // Calculate the remaining no decompression limit (NDL) time for the tissue NDL_tissue.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2750 // NDL_time will be updated if the NDL time found is shorter than the current NDL_time.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2751 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2752 // In the initialization phase of the calculation cycle:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2753 // - NDL_time had been initialized to 240 (minutes),
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2754 // - NDL_tissue had been initialized to the tissue with
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2755 // the shortest NDL time in the last cycle.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2756 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2757 calc_NDL_time_tissue();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2758
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2759 // advance to next tissue, wrapping around after last tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2760 NDL_tissue = (NDL_tissue + 1) & (NUM_COMP - 1);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2761
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2762 // did we run out of NDL time or did we have probed all tissues?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2763 if( (NDL_time == 0) || (NDL_tissue == NDL_tissue_start) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2764 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2765 // YES
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2766
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2767 // set the tissue with the shortest NDL time found as
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2768 // the one to start with in the next calculation cycle
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2769 if( deco_status & CALC_NORM ) NDL_tissue_start_norm = NDL_tissue_lead;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2770 else NDL_tissue_start_alt = NDL_tissue_lead;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2771
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2772 // done with calculating NDL time, next phase will calculate the ascent / cave return
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2773 next_planning_phase = PHASE_70_ASCENT_OR_RETURN;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2774 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2775
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2776 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2777
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2778
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2779 //
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2780 //---- Ascent or Return (cave mode) -------------------------------------------------------
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2781 //
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2782 case PHASE_70_ASCENT_OR_RETURN:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2783
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2784 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2785 overlay unsigned char doing_deco_stop = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2786 overlay unsigned char doing_gas_change = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2787
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2788
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2789 // target simulated tissues, default is 1 minute interval
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2790 tissue_increment = 1;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2791
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2792 // check if a deco stop is required:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2793 // - stays at the current depth if a stop is required,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2794 // - ascents to the next stop if possible, else
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2795 // - ascents by 1 meter
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2796 if( find_next_stop() )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2797 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2798 //---- stop required --------------------
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2799
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2800 // memorize doing a deco stop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2801 doing_deco_stop = 1;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2802
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2803 // set flag for deco stops found
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2804 if( deco_status & CALC_NORM ) deco_info |= DECO_STOPS_NORM;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2805 else deco_info |= DECO_STOPS_ALT;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2806
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2807 // encountered a deco stop, so switch to deco usage rate (SAC deco)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2808 gas_needs_usage_rate = char_I_SAC_deco;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2809
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2810 // check if there is a better gas to switch to
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2811 if( gas_find_best() )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2812 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2813 // YES - memorize doing a gas change
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2814 doing_gas_change = 1;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2815
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2816 // take the gas
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2817 gas_take_best();
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2818
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2819 // set the new calculation ratios for N2, He and O2
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2820 gas_set_ratios();
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2821
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2822 // add the gas change time to the stop time
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2823 tissue_increment += char_I_gas_change_time;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2824 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2825
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2826 // add the stop to an existing stop or add a new stop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2827 update_deco_table(tissue_increment);
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2828 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2829 else
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2830 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2831 //---- no stop required -----------------
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2832
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2833 // switch to 1/10 minute interval
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2834 tissue_increment = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2835
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2836 // memorize not doing a deco stop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2837 doing_deco_stop = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2838
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2839 // check if there is a better gas to switch to, but only:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2840 //
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2841 // if extended stops are activated OR if cave mode is enabled OR if in bailout
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2842 // AND if the actual depth (char_depth_start) is deeper or at the change
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2843 // depth of the better gas (change depth has not been passed yet) *)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2844 // AND if the depth of the last stop is above (shallower) or at the change
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2845 // depth of the better gas (do not switch on final ascent) *)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2846 //
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2847 // *) skipped when calculating in cave mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2848 //
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2849 // Attention: do not use a && formula over all 'if' terms, the
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2850 // conditions need to be evaluated in the given order!
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2851 //
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2852 if( ( main_status & EXTENDED_STOPS )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2853 || ( main_status & CAVE_MODE )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2854 || ( deco_status & BAILOUT_MODE )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2855 )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2856 if( gas_find_best() )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2857 #ifdef _cave_mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2858 if( ( char_depth_start >= sim_gas_best_depth ) || ( main_status & CAVE_MODE ) )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2859 if( ( char_I_last_stop_depth <= sim_gas_best_depth ) || ( main_status & CAVE_MODE ) )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2860 #else
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2861 if( ( char_depth_start >= sim_gas_best_depth ) )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2862 if( ( char_I_last_stop_depth <= sim_gas_best_depth ) )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2863 #endif
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2864 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2865 // YES - memorize doing a gas change
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2866 doing_gas_change = 1;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2867
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2868 // take the gas
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2869 gas_take_best();
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2870
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2871 // set the new calculation values for N2, He and O2
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2872 gas_set_ratios();
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2873
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2874 // create a stop lasting the gas change time
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2875 tissue_increment = char_I_gas_change_time;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2876
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2877 // if in deco and run from the deco calculator:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2878 // create a stop for the gas change in the stops table
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2879 if( !NDL_time && (deco_status & DECO_CALCULATOR_MODE) )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2880 update_deco_table(tissue_increment);
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2881 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2882
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2883 } // stop / no stop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2884
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2885
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2886 #ifdef _cave_mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2887 // cave mode actions
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2888 if( main_status & CAVE_MODE )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2889 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2890 // doing a deco stop?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2891 if( doing_deco_stop )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2892 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2893 // YES - not moving, reset the 1/10 minute steps counter
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2894 backtrack_step_counter = 10;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2895 }
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2896 else
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2897 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2898 // NO - on the move, switch back to SAC work
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2899 gas_needs_usage_rate = char_I_SAC_work;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2900
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2901 // - decrement the 1/10 minute steps counter if not already zero
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2902 if( backtrack_step_counter ) backtrack_step_counter--;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2903
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2904 // - target backtracking depth reached?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2905 if( char_depth_sim == backtrack_target_depth )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2906 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2907 // YES - on target depth
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2908
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2909 // target depth reached within first 1/10 minute?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2910 if( backtrack_step_counter == 9 )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2911 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2912 // YES - will not change depth any more while remaining 9/10 of
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2913 // the minute, so can do the full full minute in one step
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2914 tissue_increment = 1;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2915 backtrack_step_counter = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2916 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2917
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2918 // on the move for a minute or more now?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2919 // (incl. doing full minute in one step)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2920 if( backtrack_step_counter == 0 )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2921 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2922 // YES - get the data of the next backtracking data set
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2923 read_backtrack_data();
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2924 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2925 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2926 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2927 } // cave mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2928 #endif
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2929
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2930 // shall calculate gas needs?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2931 if( main_status & CALC_VOLUME )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2932 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2933 overlay unsigned char index_last_gas = sim_gas_last_num-1;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2934 overlay unsigned char index_curr_gas = sim_gas_current_num-1;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2935
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2936 #ifdef _cave_mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2937 // in cave mode?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2938 if( main_status & CAVE_MODE )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2939 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2940 // YES - set the depth for the gas needs calculation to the
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2941 // simulated stop / on-the-move depth
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2942 gas_needs_depth = char_depth_sim;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2943 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2944 else
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2945 #endif
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2946 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2947 // NO - set the depth for the gas needs calculation to the shallower
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2948 // one of the actual depth (char_depth_start, current real depth)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2949 // and the simulated (stop) depth, as we may on purpose dive
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2950 // shallower than we should to conserve on a low running gas supply
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2951 gas_needs_depth = ( char_depth_start < char_depth_sim ) ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2952 char_depth_start : char_depth_sim;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2953 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2954
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2955 // doing a gas change and a gas change time is set?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2956 if( doing_gas_change && char_I_gas_change_time )
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2957 {
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2958 // YES - set time it takes for switching the gas
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2959 gas_needs_time = char_I_gas_change_time;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2960
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2961 // - calculate required gas volume for the gas change
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2962 calc_required_volume();
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2963
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2964 // - add gas change demand to overall demand on the last gas
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2965 if( sim_gas_last_num ) gas_volume_need[index_last_gas] += gas_needs_volume_due;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2966
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2967 // - add gas change demand to overall demand on the current gas
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2968 if( sim_gas_current_num ) gas_volume_need[index_curr_gas] += gas_needs_volume_due;
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2969 }
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2970
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2971 // current gas is 1-5 ? (i.e. not 0 aka gas 6)
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2972 if( sim_gas_current_num )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2973 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2974 // set time: doing a deco stop -> 1 minute, encoded by tissue_increment = 1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2975 // no deco stop -> 1/10 minute, encoded by tissue_increment = 0
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2976 gas_needs_time = tissue_increment;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2977
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2978 // calculate required gas volume for the stop, ascent or travel
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2979 calc_required_volume();
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2980
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2981 // add the demand to the overall demand on the current gas
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2982 gas_volume_need[index_curr_gas] += gas_needs_volume_due;
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2983 }
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2984
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2985 #ifdef _gas_contingency
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2986 // in gas contingency mode?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2987 if( main_status & GAS_CONTINGENCY )
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
2988 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2989 overlay unsigned char all_peer_tanks_used_up = 1;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2990
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2991
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2992 // when doing a gas change and the there is an overdraw on the last gas,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2993 // then transfer the overdraw to the current gas if the current gas has
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2994 // an equal or deeper change depth than the overdrawn gas
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2995 if( doing_gas_change )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2996 if( gas_volume_need[index_last_gas] >= gas_volume_avail[index_last_gas] )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2997 if( char_I_deco_gas_change[index_last_gas] <= char_I_deco_gas_change[index_curr_gas] )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2998 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
2999 overlay float overdraw;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3001 // calculate overdraw
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3002 overdraw = gas_volume_need[index_last_gas] - gas_volume_avail[index_last_gas];
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3003
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3004 // transfer overdraw
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3005 gas_volume_need[index_last_gas] -= overdraw;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3006 gas_volume_need[index_curr_gas] += overdraw;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3007
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3008 // tag last gas as fully used up
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3009 deco_gas_type[index_last_gas] |= GAS_FULLY_USED_UP;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3010 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3011
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3012 // if there are peer tanks with the current gas (i.e. other tanks that have the same
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3013 // change depth), check if there is at least one tank that is not yet fully used up
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3014 if( peer_tank[index_curr_gas] )
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3015 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3016 // scan all tanks
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3017 for( i = 0; i < NUM_GAS; i++ )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3018 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3019 // check if
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3020 // - tank is a peer tank
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3021 // - tank is currently neither staged nor lost
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3022 // - tank is not fully used up yet
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3023 if( (peer_tank[index_curr_gas] & (1 << i) ) )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3024 if( !(deco_gas_type[i] & GAS_AVAIL_MASK ) )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3025 if( !(deco_gas_type[i] & GAS_FULLY_USED_UP) )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3026 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3027 // found a peer tank that is available and not fully used up yet
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3028 all_peer_tanks_used_up = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3029 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3030 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3031 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3032
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3033 // select which threshold is sensible to check for
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3034 if ( deco_gas_type[index_curr_gas] & GAS_FULLY_USED_UP )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3035 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3036 // already found as fully used up, nothing to do any more
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3037 }
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3038 else if( deco_gas_type[index_curr_gas] & GAS_NEARLY_USED_UP )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3039 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3040 // check for fully used up threshold
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3041 if( gas_volume_need[index_curr_gas] >= gas_volume_avail[index_curr_gas] )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3042 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3043 // tag the gas as fully used up
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3044 deco_gas_type[index_curr_gas] |= GAS_FULLY_USED_UP;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3045
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3046 // set warning if all peer tanks are fully used up, too
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3047 if( all_peer_tanks_used_up ) deco_gas_type[index_curr_gas] |= GAS_NEED_WARNING;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3048 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3049 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3050 else
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3051 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3052 // check for nearly used up threshold
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3053 if( gas_volume_need[index_curr_gas] >= gas_volume_atten[index_curr_gas] )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3054 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3055 // tag the gas as nearly used up
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3056 deco_gas_type[index_curr_gas] |= GAS_NEARLY_USED_UP;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3057
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3058 // set attention if all peer tanks are already fully used up
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3059 if( all_peer_tanks_used_up ) deco_gas_type[index_curr_gas] |= GAS_NEED_ATTENTION;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3060 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3061 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3062 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3063 #endif // _gas_contingency
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3064
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3065 } // gas needs
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3066
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3067 // update the total stops time
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3068 if( doing_deco_stop )
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3069 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3070 // total stops time is counted in full minutes, add 1 minute
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3071 TST_time += 1;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3072 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3073
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3074 // update the total ascent / cave return time
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3075 if( tissue_increment )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3076 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3077 // total time to surface is counted in 1/10 minutes, add 1 minute
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3078 TTS_time += 10 * tissue_increment;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3079 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3080 else
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3081 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3082 // total time to surface is counted in 1/10 minutes, add 1/10 minute
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3083 TTS_time += 1;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3084 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3085
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3086 } // overlay
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3087
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3088 // calculate absolute pressure at the current depth
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3089 sim_pres_respiration = (float)char_depth_sim * METER_TO_BAR + pres_surface;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3090
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3091 // compute current ppO2, ppN2 and ppHe
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3092 calc_alveolar_pressures();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3093
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3094 // update the tissues
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3095 calc_tissues();
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3096
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3097 // update the CNS
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3098 calc_CNS();
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3099
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3100 // finish stops calculation if the surface is reached or
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3101 // if the deco table is full / calculations took too long
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3102 if( (char_depth_sim == 0) || (deco_warnings & DECO_WARNING_INCOMPLETE) )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3103 next_planning_phase = PHASE_80_RESULTS;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3104
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3105 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3106
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3107
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3108 ///
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3109 //--- Results - Initialization ------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3110 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3111 case PHASE_80_RESULTS:
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3112
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3113 // convert the CNS value to integer
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3114 convert_sim_CNS_for_display();
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3115
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3116 // normal or alternative plan?
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3117 if( deco_status & CALC_NORM )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3118 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3119 // normal plan - export the integer CNS value
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3120 int_O_CNS_norm = int_sim_CNS_fraction;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3121 }
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3122 else
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3123 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3124 // alternative plan - export the integer CNS value
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3125 int_O_CNS_alt = int_sim_CNS_fraction;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3126 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3127
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3128 // limit total time to surface to display max. and rescale to full minutes
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3129 if( TTS_time < 9995 ) TTS_time = (TTS_time + 5) / 10;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3130 else TTS_time = 999 | INT_FLAG_INVALID;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3131
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3132 // The next calculation phase will
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3133 // - publish the stops table if in normal plan mode,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3134 // - proceed with remaining results dependent on if within NDL, or
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3135 // - in deco
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3136 if ( deco_status & CALC_NORM ) next_planning_phase = PHASE_81_RESULTS_STOPS_TABLE;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3137 else if ( NDL_time ) next_planning_phase = PHASE_82_RESULTS_NDL;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3138 else next_planning_phase = PHASE_83_RESULTS_DECO;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3139
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3140 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3141
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3142
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3143 ///
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3144 //--- Publish Stops Table -----------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3145 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3146 case PHASE_81_RESULTS_STOPS_TABLE:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3147
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3148 // publish the stops table to the display functions
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3149 publish_deco_table();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3150
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3151 // When entering deco and the ceiling depth becomes > 0 but the
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3152 // deco calculation reveals no distinct deco stop yet because
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3153 // the deco obligation will vanish during the ascent, create an
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3154 // artificial stop to signal that expedite surfacing ("popping
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3155 // up") is not allowed anymore.
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3156 if( char_O_deco_depth[0] == 0 ) // simulated ascent reveals no required stops
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3157 if( int_O_ceiling > 0 ) // real tissues have a ceiling
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3158 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3159 // set a pro forma stop at the configured last stop depth
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3160 char_O_deco_depth[0] = char_I_last_stop_depth;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3161
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3162 // set a stop time of 0 minutes, this will be displayed as "..'"
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3163 char_O_deco_time[0] = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3164 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3165
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3166 // The next calculation phase will publish the main results dependent on being
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3167 // - within NDL,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3168 // - in deco.
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3169 if ( NDL_time ) next_planning_phase = PHASE_82_RESULTS_NDL;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3170 else next_planning_phase = PHASE_83_RESULTS_DECO;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3171
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3172 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3173
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3174
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3175 ///
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3176 //--- Results - within NDL ----------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3177 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3178 case PHASE_82_RESULTS_NDL:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3179
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3180 // normal or alternative plan?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3181 if( deco_status & CALC_NORM )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3182 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3183 // normal plan - output the NDL and TTS time
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3184 int_O_NDL_norm = NDL_time;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3185 int_O_TTS_norm = TTS_time;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3186
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3187 // clear the stops time
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3188 int_O_TST_norm = 0;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3189 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3190 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3191 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3192 // alternative plan - output the NDL time
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3193 int_O_NDL_alt = NDL_time;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3194 int_O_TTS_alt = TTS_time;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3195
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3196 // clear the alternative TTS and stops time
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3197 int_O_TST_alt = 0 + INT_FLAG_ZERO;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3198 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3199
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3200 // The next calculation phase will
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3201 // - convert the gas needs from volume to pressure if gas needs calculation is configured
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3202 // - else finish the calculation cycle
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3203 if ( main_status & CALC_VOLUME ) next_planning_phase = PHASE_84_GAS_NEEDS_PRESSURES;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3204 else next_planning_phase = PHASE_90_FINISH;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3205
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3206 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3207
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3208
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3209 ///
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3210 //--- Results - in Deco -------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3211 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3212 case PHASE_83_RESULTS_DECO:
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3213
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3214 // limit total stops time to display max.
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3215 if( TST_time > 999 ) TST_time = 999 | INT_FLAG_INVALID;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3216
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3217
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3218 // normal or alternative plan?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3219 if( deco_status & CALC_NORM )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3220 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3221 // normal plan - clear the normal NDL time
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3222 int_O_NDL_norm = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3223
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3224 // export the TTS and total stops time
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3225 int_O_TTS_norm = TTS_time;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3226 int_O_TST_norm = TST_time;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3227 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3228 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3229 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3230 // alternative plan - clear the alternative NDL time
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3231 int_O_NDL_alt = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3232
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3233 // export the TTS and total stops time
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3234 int_O_TTS_alt = TTS_time;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3235 int_O_TST_alt = TST_time;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3236 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3237
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3238 // The next calculation phase will
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3239 // - convert the gas needs from volume to pressure if gas needs calculation is configured
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3240 // - else finish the calculation cycle
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3241 if ( main_status & CALC_VOLUME ) next_planning_phase = PHASE_84_GAS_NEEDS_PRESSURES;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3242 else next_planning_phase = PHASE_90_FINISH;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3243
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3244 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3245
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3246
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3247 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3248 //--- Results - convert Gas Needs Volumes to Pressures ------------------------------------
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3249 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3250 case PHASE_84_GAS_NEEDS_PRESSURES:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3251
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3252 // convert required volume of the gas pointed to by gas_needs_gas_index
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3253 // into the respective pressure and set the flags
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3254 convert_volume_to_pressure();
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3255
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3256 // increment index to address next gas
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3257 gas_needs_gas_index++;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3258
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3259 // if all gases have been converted, advance to next calculation phase
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3260 #ifdef _cave_mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3261 if( gas_needs_gas_index == NUM_GAS ) next_planning_phase = PHASE_85_GAS_NEEDS_CAVE;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3262 #else
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3263 if( gas_needs_gas_index == NUM_GAS ) next_planning_phase = PHASE_90_FINISH;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3264 #endif
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3265
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3266 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3267
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3268
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3269 #ifdef _cave_mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3270 //
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3271 //--- Results - tag Gas Needs as Cave or Open Water Mode ----------------------------------
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3272 //
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3273 case PHASE_85_GAS_NEEDS_CAVE:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3274
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3275 // in cave mode?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3276 if( main_status & CAVE_MODE )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3277 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3278 // YES - tag gas needs as calculated in cave mode (return along recorded depth profile)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3279 deco_info |= GAS_NEEDS_CAVE;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3280 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3281 else
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3282 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3283 // NO - tag gas needs as calculated in open water mode (vertical ascent)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3284 deco_info &= ~GAS_NEEDS_CAVE;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3285 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3286
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3287 // advance to next calculation phase
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3288 next_planning_phase = PHASE_90_FINISH;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3289
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3290 break;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3291 #endif
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3292
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3293
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3294 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3295 //--- finish Calculation Cycle ------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3296 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3297 case PHASE_90_FINISH:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3298
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3299 // Check if deco obligation is steady state or decreasing.
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3300 // Update the result only:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3301 // - if an alternative plan is enabled, and
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3302 // - if a valid alternative plan TTS exists, and
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3303 // - if it is not a bailout plan
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3304 if( (deco_status & CALC_ALT ) )
635
9a64914a8fca 3.10 re-release addressing some minor issues and language fixes
heinrichsweikamp
parents: 634
diff changeset
3305 if( !(int_O_TTS_alt & INT_FLAG_INVALID) )
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3306 if( !(deco_status & BAILOUT_MODE ) )
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3307 {
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3308 if( int_O_TTS_alt < int_O_TTS_norm ) deco_info |= DECO_ZONE;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3309 if( int_O_TTS_alt > int_O_TTS_norm ) deco_info &= ~DECO_ZONE;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3310 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3311
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3312 // export updated deco infos and warnings
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3313 char_O_deco_info = deco_info;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3314 char_O_deco_warnings = deco_warnings;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3315
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3316 // restore command flag to indicate that deco calculation cycle has finished
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3317 char_O_deco_status = deco_status;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3318
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3319 // signal end of deco calculation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3320 next_planning_phase = PHASE_00_DONE;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3321
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3322 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3323
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3324 } // switch
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3325
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3326 // read timer 5, result will be stored in tmr5_value (in 1/32 ms) and tmr5_overflow
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3327 read_tmr5();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3328
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3329 } // sequence calculation phases while not timed out and calculation cycle is not finished
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3330 while( (tmr5_overflow == 0) && ( next_planning_phase != PHASE_00_DONE ) );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3331
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3332 // report where we are in terms of depth reached, used in deco calculator to show deco calculation progress
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3333 char_O_depth_sim = char_depth_sim;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3334
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3335
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3336 #ifdef _profiling
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3337
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3338 //---- Performance Measurement -------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3339
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3340 // convert timer 5 readout into ms
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3341 profiling_runtime = tmr5_value / 32;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3342
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3343 // actual runtime longer than target runtime?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3344 if( tmr5_overflow )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3345 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3346 // YES - report excess
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3347 int_O_profiling_overrun = profiling_runtime;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3348
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3349 // - excess > max we had so far?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3350 if( int_O_profiling_overrun > int_O_profiling_overrun_max )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3351 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3352 // YES - update max
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3353 int_O_profiling_overrun_max = int_O_profiling_overrun;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3354
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3355 // - store the causing phase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3356 char_O_profiling_overrun_phase = profiling_phase;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3357 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3358 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3359 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3360 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3361 // NO - calculate unused budget and flag it to be under-run time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3362 int_O_profiling_overrun = (2048 - profiling_runtime) | 0x8000;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3363 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3364
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3365 // increment number of runs in current cycle
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3366 profiling_runs += 1;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3367
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3368 // planning cycle completed?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3369 if( next_planning_phase == PHASE_00_DONE )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3370 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3371 // YES - export number of runs it took
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3372 if( deco_status & COMPLETED_NORM ) char_O_profiling_runs_norm = profiling_runs;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3373 else char_O_profiling_runs_alt = profiling_runs;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3374 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3375
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3376 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3377
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3378 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3379
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3380
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3381 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3382 // calc_hauptroutine_data_input
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3383 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3384 // Set all C-code dive parameters from their ASM-code values.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3385 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3386 void calc_hauptroutine_data_input(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3387 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3388 overlay float IG_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3389
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3390 // safeguard and convert the surface pressure (mbar -> bar) (*)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3391 if( int_I_pres_surface < 500 ) pres_surface = 0.500;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3392 else pres_surface = 0.001 * int_I_pres_surface;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3393
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3394 // safeguard and convert the current real pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3395 if( int_I_pres_respiration < 500 ) real_pres_respiration = 0.500;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3396 else real_pres_respiration = 0.001 * int_I_pres_respiration;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3397
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3398 // safeguard further parameters to protect the tissue-flag and the stop table
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3399 if( char_I_sim_advance_time > 127 ) char_I_sim_advance_time = 127;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3400 if( char_I_extra_time > 127 ) char_I_extra_time = 127;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3401 if( char_I_gas_change_time > 99 ) char_I_gas_change_time = 99;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3402
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3403
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3404 // compute the depth in meters where we are now
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3405 float_depth_real = (real_pres_respiration - pres_surface) * BAR_TO_METER;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3406
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3407 // convert to integer and round up to next full meter
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3408 char_depth_real = (unsigned char)(float_depth_real + 0.99);
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3409
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
3410
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3411 // calculate partial pressure of N2 in respired air at surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3412 calc_N2_equilibrium();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3413
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3414 // get, safeguard and convert the saturation and desaturation factors
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3415 get_saturation_factors();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3416
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3417 #ifdef _ccr_pscr
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3418 // compute a factor that will be used later on for pSCR ppO2 drop calculation (*)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3419 float_pSCR_factor = 0.01 * char_I_PSCR_drop * char_I_PSCR_lungratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3420 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3421
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3422 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3423 // get the currently breathed gas ratios
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3424 real_O2_ratio = 0.01 * char_I_O2_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3425 real_He_ratio = 0.01 * char_I_He_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3426
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3427 // calculate the inert gas ratio (local helper variable)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3428 IG_ratio = 1.00 - real_O2_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3429
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3430 // calculate the N2 ratio
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3431 real_N2_ratio = IG_ratio - real_He_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3432 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3433 // get the currently breathed O2 ratio
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3434 real_O2_ratio = 0.01 * char_I_O2_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3435
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3436 // set the He ratio to zero
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3437 real_He_ratio = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3438
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3439 // calculate the N2 / inert gas ratio
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3440 real_N2_ratio = IG_ratio = 1.00 - real_O2_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3441 #endif // _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3442
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3443 #ifdef _ccr_pscr
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3444 // calculate ppO2 drop in pSCR loop for real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3445 real_pSCR_drop = IG_ratio * float_pSCR_factor;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3446 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3447
0
heinrichsweikamp
parents:
diff changeset
3448 }
heinrichsweikamp
parents:
diff changeset
3449
heinrichsweikamp
parents:
diff changeset
3450
heinrichsweikamp
parents:
diff changeset
3451 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3452 // calc_tissues
0
heinrichsweikamp
parents:
diff changeset
3453 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3454 // INPUT: ppN2 partial pressure of inspired N2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3455 // ppHe partial pressure of inspired He
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3456 // tissue_increment tissue selector (real or simulated) and interval time
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3457 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3458 // MODIFIED: real_pres_tissue_N2[] tissue N2 pressures (in real tissues context)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3459 // real_pres_tissue_He[] tissue He pressures (in real tissues context)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3460 // sim_pres_tissue_N2[] tissue N2 pressures (in simulated tissues context)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3461 // sim_pres_tissue_He[] tissue He pressures (in simulated tissues context)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3462 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3463 // OUTPUT: char_O_tissue_pres_N2[] tissue N2 pressures scaled for display purpose (in real tissues context)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3464 // char_O_tissue_pres_He[] tissue He pressures scaled for display purpose (in real tissues context)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3465 // char_O_tissue_pressure[] combined tissue pressures scaled for display purpose (in real tissue context)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3466 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3467 static void calc_tissues()
0
heinrichsweikamp
parents:
diff changeset
3468 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3469 overlay unsigned char period;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3470 overlay float temp_tissue_N2;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3471
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3472 #ifdef _helium
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3473 overlay float temp_tissue_He;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3474 #endif
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3475
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3476
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3477 assert( 0.00 <= ppN2 && ppN2 < 11.2 ); // 80% N2 at 130m
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3478 assert( 0.00 <= ppHe && ppHe < 12.6 ); // 90% He at 130m
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3479
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3480
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3481 for( ci=0; ci < NUM_COMP; ci++ ) // iterate through all compartments
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3482 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3483 i = tissue_increment & TIME_MASK; // i > 0: do a number of i full minutes
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3484 // I = 0: do 2 (real tissues) or 6 (simulated tissues) seconds
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3485
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3486 if( i == 0 ) // check if we shall do one 2 or 6 seconds interval
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3487 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3488 read_Buhlmann_times(0); // YES - program coefficients for a 2 or 6 seconds period
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3489 period = 1; // - set period length (in cycles)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3490 i = 1; // - and one cycle to do
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 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
3493 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3494 read_Buhlmann_times(2); // YES - program coefficients for 10 minutes periods
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3495 period = 10; // set period length (in cycles) to ten
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3496 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3497 else // last but not lease, do 1 to 9 minutes
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3498 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3499 read_Buhlmann_times(1); // NO - program coefficients for 1 minute periods
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3500 period = 1; // - set period length (in cycles) to one
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3501 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3502
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3503 do
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3504 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3505 //---- N2 --------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3506
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3507 temp_tissue = (tissue_increment & TISSUE_SELECTOR) ? real_pres_tissue_N2[ci] : sim_pres_tissue_N2[ci];
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3508
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3509 temp_tissue = (ppN2 - temp_tissue) * var_N2_e;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3510
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3511 apply_saturation_factors();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3512
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3513 if( tissue_increment & TISSUE_SELECTOR )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3514 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3515 temp_tissue_N2 = temp_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3516 real_pres_tissue_N2[ci] += temp_tissue;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3517 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3518 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3519 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3520 sim_pres_tissue_N2[ci] += temp_tissue;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3521 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3522
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3523 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3524 //---- He --------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3525
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3526 temp_tissue = (tissue_increment & TISSUE_SELECTOR) ? real_pres_tissue_He[ci] : sim_pres_tissue_He[ci];
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3527
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3528 temp_tissue = (ppHe - temp_tissue) * var_He_e;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3529
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3530 apply_saturation_factors();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3531
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3532 if( tissue_increment & TISSUE_SELECTOR )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3533 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3534 temp_tissue_He = temp_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3535 real_pres_tissue_He[ci] += temp_tissue;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3536 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3537 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3538 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3539 sim_pres_tissue_He[ci] += temp_tissue;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3540 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3541 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3542
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3543 //---- decrement loop counter and adjust step size ---------------
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3544
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3545 // decrement loop counter
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3546 i -= period;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3547
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3548 // 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
3549 if( (i > 0) && (period = 10) && (i < 10) )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3550 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3551 read_Buhlmann_times(1); // program coefficients for 1 minute periods
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3552 period = 1; // set period length (in cycles) to one
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3553 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3554 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3555 while( i );
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3556
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3557
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3558 // have the computations been done for the "real" tissues?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3559 if( tissue_increment & TISSUE_SELECTOR )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3560 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3561
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3562 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3563
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3564 // net tissue balance
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3565 temp_tissue = temp_tissue_N2 + temp_tissue_He;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3566
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3567
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3568 // 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
3569 //
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
3570 if ( temp_tissue < -HYST ) // check if the tissue is off-gassing
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3571 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3572 // tag tissue as not experiencing mentionable IBCD
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3573 IBCD_tissue_vector &= ~(1 << ci);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3574 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3575 else if ( temp_tissue > +HYST ) // check if the tissue in on-gassing
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3576 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3577 // check for counter diffusion
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3578 if( ((temp_tissue_N2 > 0.0) && (temp_tissue_He < 0.0))
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3579 || ((temp_tissue_N2 < 0.0) && (temp_tissue_He > 0.0)) )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3580 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3581 // tag tissue as experiencing mentionable IBCD
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3582 IBCD_tissue_vector |= (1 << ci);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3583 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3584 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3585
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3586 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3587
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3588 // For N2 tissue pressure display purpose:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3589
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3590 // basically keep the on-gassing / off-gassing flag from last invocation, but flip
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3591 // it in case the rate exceeds a set hysteresis (actual value: see #define of HYST)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3592 char_O_tissue_pres_N2[ci] &= 128;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3593 if ( temp_tissue_N2 > +HYST ) char_O_tissue_pres_N2[ci] = 128; // set flag for tissue pressure is increasing
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3594 else if ( temp_tissue_N2 < -HYST ) char_O_tissue_pres_N2[ci] = 0; // clear flag (-> tissue pressure is decreasing)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3595
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3596 // scale N2 tissue pressure such that the surface steady-state tissue loading
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3597 // of [0.7902 * (1013 hPa - ppWater)] bar will give a 8, which aligns with
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3598 // the 2nd scale line.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3599 temp_tissue_N2 = (8 / (0.7902 * (1.013 - ppWater))) * real_pres_tissue_N2[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3600
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3601 // limit to 127 to protect the uppermost bit which holds the sat/desat flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3602 if (temp_tissue_N2 > 127) temp_tissue_N2 = 127;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3603
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3604 // convert to integer and combine with sat/desat flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3605 char_O_tissue_pres_N2[ci] += (unsigned char)temp_tissue_N2;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3606
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3607 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3608
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3609 // For He tissue pressure display purpose:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3610
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3611 // basically keep the on-gassing / off-gassing flag from last invocation, but flip
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3612 // it in case the rate exceeds a set hysteresis (actual value: see #define of HYST)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3613 char_O_tissue_pres_He[ci] &= 128;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3614 if ( temp_tissue_He > +HYST ) char_O_tissue_pres_He[ci] = 128; // set flag for tissue pressure is increasing
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3615 else if ( temp_tissue_He < -HYST ) char_O_tissue_pres_He[ci] = 0; // clear flag (-> tissue pressure is decreasing)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3616
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3617 // scale He tissue pressure alike it is done for N2.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3618 // With no He in a tissue, the result will be 0.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3619 temp_tissue_He = (8 / (0.7902 * (1.013 - ppWater))) * real_pres_tissue_He[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3620
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3621 // limit to 127 to protect the uppermost bit which holds the sat/desat flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3622 if (temp_tissue_He > 127) temp_tissue_He = 127;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3624 // convert to integer and combine with sat/desat flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3625 char_O_tissue_pres_He[ci] += (unsigned char)temp_tissue_He;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3626
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3627
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3628 // For combined tissue pressure display purpose:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3629
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3630 // basically keep the on-gassing / off-gassing flag from last invocation, but flip
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3631 // it in case the rate exceeds a set hysteresis (actual value: see #define of HYST)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3632 char_O_tissue_pressure[ci] &= 128;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3633 if ( temp_tissue > +HYST ) char_O_tissue_pressure[ci] = 128; // set flag for tissue pressure is increasing
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3634 else if ( temp_tissue < -HYST ) char_O_tissue_pressure[ci] = 0; // clear flag (-> tissue pressure is decreasing)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3635
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3636 // add the two scaled pressures.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3637 temp_tissue = temp_tissue_N2 + temp_tissue_He;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3638
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3639 // limit to 127 to protect the uppermost bit which holds the sat/desat flag
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3640 if (temp_tissue > 127) temp_tissue = 127;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3641
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3642 // convert to integer and combine with sat/desat flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3643 char_O_tissue_pressure[ci] += (unsigned char)temp_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3644
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3645 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3646
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3647 // He tissue pressure is zero
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3648 char_O_tissue_pres_He[ci] = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3649
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3650 // combined tissue pressure equals N2 tissue pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3651 char_O_tissue_pressure[ci] = char_O_tissue_pres_N2[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3652
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3653 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3654
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3655 } //if
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3656
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3657 } // for
0
heinrichsweikamp
parents:
diff changeset
3658 }
heinrichsweikamp
parents:
diff changeset
3659
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3660
0
heinrichsweikamp
parents:
diff changeset
3661 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
3662 // calc_limit
heinrichsweikamp
parents:
diff changeset
3663 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3664 // Input: GF_parameter gradient factor to be used, negative values activate surface mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3665 // tissue_increment selector for context: real or simulated tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3666 // sim_pres_tissue_N2/_He tissue pressures (used in simulated tissues context)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3667 // real_pres_tissue_N2/_He tissue pressures (used in real tissues context)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3668 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3669 // Output: lead_supersat highest supersaturation found among all tissues, 1.0 = 100%
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3670 // lead_tissue number of the leading tissue (0-15)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3671 // ceiling ceiling in bar relative pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3672 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3673 // Modified: deco_warnings for IBCD, micro bubbles and outside warning (only in real tissues context)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3674 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3675 static void calc_limit(PARAMETER float GF_parameter)
0
heinrichsweikamp
parents:
diff changeset
3676 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3677 overlay float pres_ambient_min_overall = 0.0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3678 overlay unsigned char surface_mode = 0; // 0: off, 1: on
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3679
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3680
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3681 // check mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3682 if( GF_parameter < 0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3683 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3684 // activate surface mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3685 surface_mode = 1;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3686
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3687 // normalize parameter
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3688 GF_parameter = -GF_parameter;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3689 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3690
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3691 // set leading tissue number to tissue 1 (it has the index 0)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3692 lead_tissue = 0;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3693
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3694 // initialize leading tissue supersaturation value to null
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3695 lead_supersat = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3696
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3697 // next code section is relevant only when invoked on the real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3698 if( tissue_increment & TISSUE_SELECTOR )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3699 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3700 // clear IBCD, micro-bubbles and outside warning flags (locked warnings will be preserved)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3701 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
3702 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3703
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3704 // loop over all tissues
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3705 for( ci = 0; ci < NUM_COMP; ci++ )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3706 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3707 overlay float pres_ambient_min_tissue;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3708
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3709
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3710 // get the coefficients for tissue ci
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3711 read_Buhlmann_coefficients();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3712
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3713 #ifdef _helium
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3714
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3715 // get the tissue pressures
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3716 // adopt_Buhlmann_coefficients needs calc_pres_tissue_N2/He when compiled for helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3717 if( tissue_increment & TISSUE_SELECTOR )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3718 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3719 // context is real tissues
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3720 calc_pres_tissue_N2 = real_pres_tissue_N2[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3721 calc_pres_tissue_He = real_pres_tissue_He[ci];
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3722 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3723 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3724 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3725 // context is simulated tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3726 calc_pres_tissue_N2 = sim_pres_tissue_N2[ci];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3727 calc_pres_tissue_He = sim_pres_tissue_He[ci];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3728 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3729
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3730 // overall tissue pressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3731 pres_tissue = calc_pres_tissue_N2 + calc_pres_tissue_He;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3732
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3733 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3734
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3735 // get the tissue pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3736 pres_tissue = ( tissue_increment & TISSUE_SELECTOR ) ? real_pres_tissue_N2[ci] : sim_pres_tissue_N2[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3737
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3738 #endif
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3739
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3740 // 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
3741 adopt_Buhlmann_coefficients();
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3742
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3743 // next calculations are only relevant when invoked on the real tissues
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3744 if( tissue_increment & TISSUE_SELECTOR )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3745 {
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3746 overlay float pres_tissue_max;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3747 overlay float supersat;
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
3748 overlay float baseline_threshold;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3749
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3750
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3751 // check if tissue is in supersaturation
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3752 if( pres_tissue > real_pres_respiration )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3753 {
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3754 // calculate maximum allowed tissue pressure at current ambient pressure
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3755 pres_tissue_max = real_pres_respiration / var_b + var_a;
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3756
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3757 // calculate current supersaturation value (1.0 = 100%) of this tissue according to straight Buhlmann
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3758 supersat = ( pres_tissue - real_pres_respiration )
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3759 / ( pres_tissue_max - real_pres_respiration );
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3760
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3761 // calculate supersaturation value for display purpose: 1.35 = 135% = 86 pixel
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3762 if( supersat <= 1.35 ) char_O_tissue_saturation[ci] = (unsigned char)(supersat * 64);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3763 else char_O_tissue_saturation[ci] = 86;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3764
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3765 // memorize highest supersaturation found
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3766 if( supersat > lead_supersat ) lead_supersat = supersat;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3767
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
3768 // tissue-dependent baseline threshold for micro bubbles and outside warnings
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
3769 baseline_threshold = 0.02 * ci + 1.0;
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
3770
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
3771 // micro bubbles warning: supersaturation > baseline threshold
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
3772 if( supersat > baseline_threshold )
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3773 deco_warnings |= (DECO_WARNING_MBUBBLES + DECO_WARNING_MBUBBLES_lock);
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3774
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
3775 // outside warning: supersaturation > baseline threshold + additional 5% margin
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3776 if( supersat > (baseline_threshold + 0.05) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3777 deco_warnings |= (DECO_WARNING_OUTSIDE + DECO_WARNING_OUTSIDE_lock );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3778 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3779 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3780 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3781 // supersaturation is defined as zero while tissue pressure <= ambient pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3782 supersat = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3783 char_O_tissue_saturation[ci] = 0;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3784 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3785
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3786 // next only when in surface mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3787 if( surface_mode )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3788 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3789 // tag tissue whether it is beyond the M-line limit or not
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3790 if( supersat > 1.0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3791 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3792 char_O_tissue_pres_N2[ci] |= 128;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3793 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3794 char_O_tissue_pres_He[ci] |= 128;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3795 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3796 char_O_tissue_pressure[ci] |= 128;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3797 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3798 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3799 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3800 char_O_tissue_pres_N2[ci] &= ~128;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3801 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3802 char_O_tissue_pres_He[ci] &= ~128;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3803 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3804 char_O_tissue_pressure[ci] &= ~128;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3805 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3806 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3807 } // real tissues
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3808
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3809 // calculate the minimum ambient pressure that the tissue can withstand
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3810 if( char_I_model == 0 )
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3811 {
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3812 // straight Buhlmann
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3813 pres_ambient_min_tissue = (pres_tissue - var_a) * var_b;
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3814 }
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3815 else
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3816 {
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3817 // Buhlmann with Eric Baker's varying gradient factor correction
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3818 // note: this equation [1] is the inverse of equation [2]
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3819 pres_ambient_min_tissue = ( pres_tissue - (var_a * GF_parameter) )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3820 / ( 1.0 - GF_parameter + (GF_parameter / var_b ) );
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3821 }
560
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 // check if this tissue requires a higher ambient pressure than was found to be needed up to now
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3824 if( pres_ambient_min_tissue > pres_ambient_min_overall )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3825 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3826 pres_ambient_min_overall = pres_ambient_min_tissue;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3827 lead_tissue = ci;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3828 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3829 } // for
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3830
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3831 // compute ceiling in bar relative pressure
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3832 ceiling = pres_ambient_min_overall - pres_surface;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3833
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3834 // limit ceiling to positive values
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3835 if( ceiling < 0.0 ) ceiling = 0.0;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3836
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3837 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3838 // IBCD is checked for real tissues only
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3839 if( tissue_increment & TISSUE_SELECTOR )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3840 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3841 // check if the leading tissue is in IBCD condition
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3842 if( (IBCD_tissue_vector & (1 << lead_tissue))
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3843 && ((real_pres_tissue_N2[lead_tissue] + real_pres_tissue_He[lead_tissue]) > real_pres_respiration) )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3844 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3845 // leading tissue is in IBCD condition and in super-saturation, so issue a warning.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3846 deco_warnings |= (DECO_WARNING_IBCD + DECO_WARNING_IBCD_lock);
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3847 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3848 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3849 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3850
0
heinrichsweikamp
parents:
diff changeset
3851 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3852
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3853
0
heinrichsweikamp
parents:
diff changeset
3854 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3855 // calc_NDL_time_tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3856 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3857 // calculation of the remaining no decompression limit (NDL) time for a tissue
0
heinrichsweikamp
parents:
diff changeset
3858 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3859 // NOTE: Erik Baker's closed formula works for Nitrox. Trimix adds a second
0
heinrichsweikamp
parents:
diff changeset
3860 // exponential term to the M-value equation, making it impossible to
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3861 // invert. So we have to solve the problem with a search approach.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3862 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3863 // Input: NDL_tissue tissue for which to calculate remaining NDL time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3864 // GF_high gradient factor used when GF factors are enabled
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3865 // ppN2, ppHe partial pressures of N2 and He breathed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3866 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3867 // Modified: NDL_time shortest NDL time found so far
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3868 // NDL_tissue_lead leading tissue, i.e. tissue with the shortest NDL
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3869 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3870 static void calc_NDL_time_tissue(void)
0
heinrichsweikamp
parents:
diff changeset
3871 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3872 overlay unsigned char NDL_time_tissue = 0; // NDL time of this tissue, starting with 0 minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3873 overlay unsigned char step_size = 10; // step size in searching, starting with 10 minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3874 overlay float pres_limit; // max. tissue pressure allowed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3875
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3876 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3877 overlay float last_pres_tissue_N2; // last tissue pressure for N2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3878 overlay float last_pres_tissue_He; // last tissue pressure for He
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3879 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3880 overlay float last_pres_tissue; // last tissue pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3881 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3882
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3883
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3884 // set the compartment index ci for reading the Buhlmann increments and coefficients
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3885 ci = NDL_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3886
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3887 // read the tissue increments for a step size of 10 minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3888 read_Buhlmann_times(2);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3889
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3890 // read Buhlmann a and b coefficients for tissue ci
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3891 read_Buhlmann_coefficients();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3892
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3893 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3894
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3895 // get the current simulated tissue pressures
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3896 calc_pres_tissue_N2 = last_pres_tissue_N2 = sim_pres_tissue_N2[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3897 calc_pres_tissue_He = last_pres_tissue_He = sim_pres_tissue_He[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3898
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3899 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3900
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3901 // get the current simulated tissue pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3902 pres_tissue = last_pres_tissue = sim_pres_tissue_N2[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3903
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3904 // set the a and b coefficients
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3905 adopt_Buhlmann_coefficients();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3906
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3907 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3908
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3909 // simulate an increasing bottom time and check when the NDL is hit
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3910 for(;;)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3911 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3912
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3913 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3914
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3915 // calculate the total tissue pressure
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3916 pres_tissue = calc_pres_tissue_N2 + calc_pres_tissue_He;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3917
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3918 // adopt a and b coefficients to current N2/He ratio inside the tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3919 adopt_Buhlmann_coefficients();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3920
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3921 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3922
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3923 // compute the maximum tissue pressure allowed to be exposed to an
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3924 // ambient pressure equaling the surface pressure
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
3925 if( char_I_model != 0 )
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3926 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3927 // GF model enabled, this equation [2] is the inverse of equation [1]
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3928 pres_limit = (1.0 - GF_high + GF_high / var_b) * pres_surface + GF_high * var_a;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3929 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3930 else
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3931 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3932 // straight Buhlmann
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3933 pres_limit = pres_surface / var_b + var_a;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3934 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3935
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3936 // is the tissue pressure higher than the maximum tissue pressure allowed?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3937 if( pres_tissue > pres_limit)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3938 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3939 // YES - tissue is outside NDL
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3940
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3941 // was the tissue outside NDL right from the start?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3942 if( NDL_time_tissue == 0 )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3943 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3944 // YES - search can be aborted
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3945
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3946 // at least one tissue is outside NDL, so overall NDL time is zero
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3947 NDL_time = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3948
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3949 // store the number of this tissue as being the leading one
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3950 NDL_tissue_lead = NDL_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3951
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3952 // done
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3953 break;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3954 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3955
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3956 // when code execution passes here, the tissue has become
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3957 // being outside NDL after doing one or more search steps
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3958
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3959 // still searching with a step size of 10 minutes?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3960 if( step_size == 10 )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3961 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3962 // YES - retry with smaller step size
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3963
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3964 // go back to last NDL time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3965 NDL_time_tissue -= 10;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3966
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3967 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3968
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3969 // go back to last pressures
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3970 calc_pres_tissue_N2 = last_pres_tissue_N2;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3971 calc_pres_tissue_He = last_pres_tissue_He;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3972
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3973 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3974
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3975 // go back to last pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3976 pres_tissue = last_pres_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3977
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3978 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3979
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3980 // reduce step size to 1 minute
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3981 step_size = 1;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3982
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3983 // read the tissue increments for a step size of 1 minute
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3984 read_Buhlmann_times(1);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3985
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3986 // redo search from last pressure & time within NDL with smaller step size
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3987 continue;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3988 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3989 else
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3990 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3991 // NO - already tried with a step size of 1 minute
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3992
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3993 // go back to last NDL time that was within NDL
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3994 NDL_time_tissue -= 1;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3995
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3996 // is the NDL time of this tissue shorter than the overall NDL time found so far?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3997 if( NDL_time_tissue < NDL_time )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3998 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3999 // YES - set this tissue's NDL time as the new overall NDL time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4000 NDL_time = NDL_time_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4001
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4002 // - store the number of this tissue as being the leading one
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4003 NDL_tissue_lead = NDL_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4004 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4005
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4006 // done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4007 break;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4008 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4009 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4010 else
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4011 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4012 // NO - tissue is still within NDL
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4013
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4014 // The search can be terminated when the NDL time of this tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4015 // exceeds the overall NDL time, thus when a shorter NDL time has
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4016 // already been found with another tissue.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4017 if( NDL_time_tissue >= NDL_time ) break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4018
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4019 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4020
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4021 // back-up current tissue pressures
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4022 last_pres_tissue_N2 = calc_pres_tissue_N2;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4023 last_pres_tissue_He = calc_pres_tissue_He;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4024
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4025 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4026
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4027 // back-up current tissue pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4028 last_pres_tissue = pres_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4029
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4030 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4031
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4032 // step forward NDL time of current tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4033 NDL_time_tissue += step_size;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4034
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4035 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4036
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4037 // step forward tissue pressure - N2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4038 temp_tissue = (ppN2 - calc_pres_tissue_N2) * var_N2_e; // pressure delta breathed - tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4039 apply_saturation_factors(); // apply safety factor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4040 calc_pres_tissue_N2 += temp_tissue; // add pressure delta to tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4041
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4042 // step forward tissue pressure - He
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4043 temp_tissue = (ppHe - calc_pres_tissue_He) * var_He_e; // pressure delta breathed - tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4044 apply_saturation_factors(); // apply safety factor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4045 calc_pres_tissue_He += temp_tissue; // add pressure delta to tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4046
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4047 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4048
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4049 // step forward tissue pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4050 temp_tissue = (ppN2 - pres_tissue ) * var_N2_e; // pressure delta breathed - tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4051 apply_saturation_factors(); // apply safety factor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4052 pres_tissue += temp_tissue; // add pressure delta to tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4053
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4054 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4055
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4056 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4057 }
0
heinrichsweikamp
parents:
diff changeset
4058 }
heinrichsweikamp
parents:
diff changeset
4059
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4060
0
heinrichsweikamp
parents:
diff changeset
4061 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
4062 // clear_deco_table
heinrichsweikamp
parents:
diff changeset
4063 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4064 // Modified: internal_deco_time[] stop durations
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4065 // internal_deco_depth[] stop depths
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4066 // internal_deco_gas[] gases used at stops
0
heinrichsweikamp
parents:
diff changeset
4067 //
heinrichsweikamp
parents:
diff changeset
4068 static void clear_deco_table(void)
heinrichsweikamp
parents:
diff changeset
4069 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4070 for( i = 0; i < NUM_STOPS; ++i )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4071 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4072 internal_deco_time [i] = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4073 internal_deco_depth[i] = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4074 internal_deco_gas[i] = 0;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4075 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4076
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4077 // reset stop table index and chained stops counter
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4078 stop_index = 0;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4079 chained_stops = 0;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4080
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4081 // clear stop table overflow warning
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4082 deco_warnings &= ~DECO_WARNING_INCOMPLETE;
0
heinrichsweikamp
parents:
diff changeset
4083 }
heinrichsweikamp
parents:
diff changeset
4084
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4085
0
heinrichsweikamp
parents:
diff changeset
4086 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
4087 // update_deco_table
heinrichsweikamp
parents:
diff changeset
4088 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4089 // Add time to a stop at char_depth_sim
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4090 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4091 // 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
4092 // 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
4093 // to have reached the end of the list is depth == 0.
0
heinrichsweikamp
parents:
diff changeset
4094 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4095 // Input: char_depth_sim stop's depth, in meters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4096 // sim_gas_current_num gas used at stop, as index 1..5 or 0 for gas 6
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4097 // time_increment number of minutes to add to the stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4098 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4099 // Updated: internal_deco_depth[] depth (in meters) of each stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4100 // internal_deco_time [] time (in minutes) of each stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4101 // internal_deco_gas [] gas used (index 1-5) at each stop
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4102 //
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4103 static void update_deco_table(PARAMETER unsigned char time_increment)
0
heinrichsweikamp
parents:
diff changeset
4104 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4105 assert( char_depth_sim > 0 ); // no stop at surface
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4106
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4107
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4108 // is there already a stop entry matching with the current depth and gas?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4109 if( internal_deco_depth[stop_index] == char_depth_sim )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4110 if( internal_deco_gas [stop_index] == sim_gas_current_num )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4111 {
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4112 // YES - increment stop time if possible, stop time entries are
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4113 // limited to 99 minutes because of display constraints
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4114 if( internal_deco_time[stop_index] < (100 - time_increment) )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4115 {
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4116 // YES - time increment fits into current stop entry,
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4117 // increment stop time
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4118 internal_deco_time[stop_index] += time_increment;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4119
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4120 // done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4121 return;
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4122 }
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4123 else
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4124 {
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4125 // NO - A chained stop entry will be created further down in the
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4126 // code to continue the stop, but we will limit the number
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4127 // of chained stop table entries in order to abort an ever-
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4128 // running deco calculation. Too many chained entries?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4129 if( ++chained_stops >= STOP_CHAINING_LIMIT )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4130 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4131 // YES - set warning that calculations took too long
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4132 deco_warnings |= DECO_WARNING_INCOMPLETE;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4133
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4134 // done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4135 return;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4136 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4137 }
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4138 }
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4139
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4140 // the current stop entry does not match the current depth and gas,
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4141 // or hasn't enough room left for the time increment
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4142
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4143 // is the current stop entry in use?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4144 if( internal_deco_depth[stop_index] > 0 )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4145 {
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4146 // YES - current entry is in use, need to move on
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4147 // to next entry position if possible
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4148
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4149 // have all entry positions been used up?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4150 if( stop_index < (NUM_STOPS - 1) )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4151 {
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4152 // NO - move on to next entry position
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4153 stop_index += 1;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4154 }
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4155 else
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4156 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4157 // YES - if run in deco calculator mode, set a warning that there is an overflow in the stops table
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4158 if( main_status & CALCULATE_BOTTOM ) deco_warnings |= DECO_WARNING_INCOMPLETE;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4159
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4160 // limit runtime via reached TTS (scaled in 1/10 minutes here)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4161 if( TTS_time > 9999 ) deco_warnings |= DECO_WARNING_INCOMPLETE;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4162
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4163 // done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4164 return;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4165 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4166 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4167
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4168 // initial use of a new (or the very first) stop entry, store all stop data
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4169 internal_deco_time [stop_index] = time_increment;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4170 internal_deco_depth[stop_index] = char_depth_sim;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4171 internal_deco_gas [stop_index] = sim_gas_current_num;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4172
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4173 // done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4174 return;
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4175 }
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4176
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4177
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4178 //////////////////////////////////////////////////////////////////////////////
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4179 // publish_deco_table
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4180 //
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4181 // Input: internal_deco_depth[] depth in internal stops table
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4182 // internal_deco_time[] times ...
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4183 // internal_deco_gas[] gases ...
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4184 //
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4185 // Output: char_O_deco_depth[] depth in the external stops table
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4186 // char_O_deco_time[] times ...
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4187 // char_O_deco_gas[] gases ...
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4188 // char_O_deco_time_for_log times in reverse order
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4189 //
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4190 static void publish_deco_table(void)
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4191 {
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4192 overlay unsigned char x = stop_index;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4193 overlay unsigned char y;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4194
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4195
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4196 // copy depth, time and gas from internal to external stops table
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4197 for( y = 0; y < NUM_STOPS; y++ )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4198 {
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4199 char_O_deco_depth[y] = internal_deco_depth[y];
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4200 char_O_deco_time [y] = internal_deco_time [y];
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4201 char_O_deco_gas [y] = internal_deco_gas [y];
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4202 }
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4203
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4204 // copy times of shallowest stops to logging table
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4205 for(y = 0; y < NUM_STOPS_LOG; x-- )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4206 {
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4207 // copy all stops that have a non-null stop time
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4208 if( internal_deco_time[x] )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4209 char_O_deco_time_for_log[y++] = internal_deco_time[x];
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4210
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4211 // abort if all stops are copied
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4212 if( x == 0) break;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4213 }
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4214
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4215 // fill the remainder of the logging table with null
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4216 // if it is not completely filled already
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4217 while( y < NUM_STOPS_LOG )
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4218 {
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4219 char_O_deco_time_for_log[y++] = 0;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4220 }
0
heinrichsweikamp
parents:
diff changeset
4221 }
heinrichsweikamp
parents:
diff changeset
4222
heinrichsweikamp
parents:
diff changeset
4223
heinrichsweikamp
parents:
diff changeset
4224 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4225 // calc_desaturation_time_helper
0
heinrichsweikamp
parents:
diff changeset
4226 //
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4227 // Helper function
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4228 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4229 // Input: pres_actual current tissue pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4230 // pres_target target tissue pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4231 // var_ht half-time of the tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4232 // desat_factor desaturation factor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4233 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4234 // Output: int_time time needed by tissue to reach target pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4235 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4236 static void calc_desaturation_time_helper(void)
0
heinrichsweikamp
parents:
diff changeset
4237 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4238 // check if actual pressure is higher then target pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4239 if( pres_actual > pres_target )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4240 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4241 // YES - compute remaining time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4242
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4243 overlay float pres_ratio;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4244
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4245 // compute pressure ratio to archive
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4246 pres_ratio = pres_actual / pres_target;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4247
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4248 // Compute desaturation time with result rounded up to multiples of 10 minutes.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4249 // 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
4250 // one minute steps any more but get constantly re-computed according to current
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4251 // 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
4252 // backwards as ambient pressure rises/falls and N2/He ratio is being adjusted.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4253 int_time = (unsigned short)( (var_ht * log(pres_ratio) / desat_factor) + 0.9 );
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4254 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4255 else
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4256 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4257 // NO - desaturation state reached, no remaining time
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4258 int_time = 0;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4259 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4260 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4261
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4262
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4263 /////////////////////////////////////////////////////////////////////////////
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4264 // calc_desaturation_time
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4265 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4266 // Calculates the time needed for the tissues to equilibrate with
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4267 // surface pressure and the no-fly / no-altitude time.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4268 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4269 // Input: int_I_pres_surface
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4270 // char_I_desaturation_multiplier
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4271 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4272 // Output: int_O_desaturation_time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4273 // int_O_nofly_time
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4274 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4275 void calc_desaturation_time(void)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4276 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4277 overlay float P_ambient_altitude;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4278
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4279 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
4280 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
4281
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4282
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4283 // safeguard and convert surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4284 if( int_I_pres_surface < 500) pres_surface = 0.5;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4285 else pres_surface = 0.001 * int_I_pres_surface;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4286
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4287 // calculate partial pressure of N2 in respired air at surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4288 calc_N2_equilibrium();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4289
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4290 // get, safeguard and convert the saturation and desaturation factors
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4291 get_saturation_factors();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4292
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4293 // pre-computed term for later use: 10 [Min] * 0.6931 [=log(2)] * 1 [Desat Factor] * ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4294 desat_factor = (6.931 * SURFACE_DESAT_FACTOR) * float_desaturation_multiplier;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4295
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4296 // initialize vars
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4297 int_O_desaturation_time = 0;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4298 int_O_nofly_time = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4299
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4300 // get selected target altitude
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4301 switch( char_I_altitude_wait )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4302 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4303 case 1: P_ambient_altitude = P_ambient_1000m; break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4304 case 2: P_ambient_altitude = P_ambient_2000m; break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4305 case 3: P_ambient_altitude = P_ambient_3000m; break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4306 default: P_ambient_altitude = P_ambient_fly; break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4307 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4308
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4309 // loop over all compartments in order slowest to fastest
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4310 for( ci = NUM_COMP; ci > 0; )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4311 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4312 overlay float pres_tissue_max;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4313 overlay unsigned short nofly_last = ~0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4314 overlay unsigned short nofly_N2 = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4315
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4316 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4317 overlay signed char search_direction;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4318 overlay unsigned short nofly_He = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4319 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4320
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4321
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4322 // decrement compartment index
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4323 ci -= 1;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4324
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4325 // get the Buhlmann halftimes and coefficients
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4326 read_Buhlmann_ht();
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4327 read_Buhlmann_coefficients();
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4328
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4329
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4330 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4331 // Desaturation time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4332 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4333
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4334 // calculate desaturation time for N2 in tissue,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4335 // desaturated state is defined as residual tissue pressure <= 1.05 x ppN2 respired
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4336
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4337 // current tissue pressure above equilibrium pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4338 pres_actual = real_pres_tissue_N2[ci] - N2_equilibrium;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4339
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4340 // target pressure above equilibrium pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4341 pres_target = 0.05 * N2_equilibrium;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4342
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4343 // half-time of the current tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4344 var_ht = var_N2_ht;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4345
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4346 // calculate desaturation time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4347 calc_desaturation_time_helper();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4348
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4349 // store desaturation time if it is longer than longest found so far
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4350 if( int_time > int_O_desaturation_time) int_O_desaturation_time = int_time;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4351
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4352
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4353 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4354
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4355 // calculate desaturation time for He in the tissue,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4356 // desaturated state is defined as residual tissue pressure <= 0.05 x ppN2 respired
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4357
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4358 // actual tissue pressure above equilibrium: equilibrium for He is 0 bar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4359 pres_actual = real_pres_tissue_He[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4360
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4361 // target pressure above equilibrium pressure: use same target pressure as for N2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4362 pres_target = 0.05 * N2_equilibrium;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4363
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4364 // half-time of the current tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4365 var_ht = var_He_ht;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4366
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4367 // calculate desaturation time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4368 calc_desaturation_time_helper();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4369
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4370 // store desaturation time if it is longer than longest found so far
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4371 if( int_time > int_O_desaturation_time) int_O_desaturation_time = int_time;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4372
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4373 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4374
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4375 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4376 // no-fly time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4377 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4378
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4379 // 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
4380 // 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
4381 // 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
4382 // safe side, too.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4383 pres_tissue_max = (P_ambient_altitude/var_N2_b + var_N2_a);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4384
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4385 // adjust target pressure by GF-high in case the GF model is in use, but not
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4386 // for the no-fly time as it's target pressure is hard to reach anyhow
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4387 if( char_I_model && char_I_altitude_wait )
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4388 pres_tissue_max = P_ambient_altitude +
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4389 0.01 * char_I_GF_High_percentage * (pres_tissue_max - P_ambient_altitude);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4390
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4391
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4392 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4393
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4394 //---- Variant with Helium -------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4395
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4396 // initialize split_N2_He in case there was a hard reboot / memory clear
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4397 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
4398
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4399 // initialize search direction
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4400 search_direction = 0;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4401
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4402 for(;;)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4403 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4404 // Calculate no-fly time for N2 in the tissue.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4405 // 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
4406
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4407 // current tissue pressure above equilibrium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4408 pres_actual = real_pres_tissue_N2[ci] - N2_equilibrium;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4409
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4410 // target pressure above equilibrium pressure, weighted by N2/He split
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4411 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
4412
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4413 // half-time of the current tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4414 var_ht = var_N2_ht;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4415
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4416 // check if desaturation to target pressure is possible at all
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4417 if( pres_target < 0.0 )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4418 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4419 // NO - set no-fly time to 288 * 10 min = 48 h
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4420 int_O_nofly_time = 288;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4421 break;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4422 }
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4423 else
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4424 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4425 // YES - calculate desaturation time
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4426 calc_desaturation_time_helper();
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4427
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4428 // store time found
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4429 nofly_N2 = int_time;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4430 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4431
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4432 // calculate no-fly time for He in the tissue,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4433 // flying is permitted when the He pressure fits into the assigned fraction
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4434
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4435 // current tissue pressure above equilibrium: equilibrium for He is 0 bar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4436 pres_actual = real_pres_tissue_He[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4437
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4438 // target pressure above equilibrium pressure, weighted by N2/He split
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4439 pres_target = ((100 - split_N2_He[ci]) * 0.01) * (pres_tissue_max - N2_equilibrium);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4440
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4441 // half-time of the current tissue
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4442 var_ht = var_He_ht;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4443
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4444 // calculate desaturation time
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4445 calc_desaturation_time_helper();
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4446
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4447 // store time found
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4448 nofly_He = int_time;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4449
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4450
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4451 // 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
4452 // no-fly time calculation, each gas gets assigned a fraction of the available total pressure
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4453 // limit. The optimum split between the two gases can not be computed by a single formula,
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4454 // 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
4455 // 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
4456 // 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
4457 // 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
4458 // at best.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4459
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4460 // 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
4461 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
4462
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4463 // check if the N2 requires more waiting time than the He
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4464 if( nofly_N2 >= nofly_He )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4465 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4466 // 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
4467 // 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
4468 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
4469 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4470 // either the just completed iteration was more close to the optimum or the one before
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4471 // was, so we take the best (i.e. shortest) time of both as the final no-fly time
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4472 int_O_nofly_time = (nofly_N2 < nofly_last) ? nofly_N2 : nofly_last;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4473
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4474 // done
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4475 break;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4476 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4477
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4478 // store the no-fly time found in this iteration
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4479 nofly_last = nofly_N2;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4480
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4481 // increase the N2 fraction of the split
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4482 split_N2_He[ci] += 1;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4483
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4484 // set search direction towards more N2
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4485 search_direction = +1;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4486 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4487 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4488 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4489 // 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
4490 // 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
4491 if( (search_direction > 0) || (split_N2_He[ci] == 1) )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4492 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4493 // either the just completed iteration was more close to the optimum or the one before
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4494 // was, so we take the best (i.e. shortest) time of both as the final no-fly time
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4495 int_O_nofly_time = (nofly_He < nofly_last) ? nofly_He : nofly_last;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4496
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4497 // done
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4498 break;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4499 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4500
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4501 // store the no-fly time found in this iteration
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4502 nofly_last = nofly_He;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4503
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4504 // decrease the N2 fraction of the split
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4505 split_N2_He[ci] -= 1;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4506
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4507 // set search direction towards less N2
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4508 search_direction = -1;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4509 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4510
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4511 } // for(;;)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4512
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4513 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4514
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4515 //---- Variant without Helium ----------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4516
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4517 // current tissue pressure above equilibrium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4518 pres_actual = real_pres_tissue_N2[ci] - N2_equilibrium;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4519
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4520 // target pressure above equilibrium pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4521 pres_target = pres_tissue_max - N2_equilibrium;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4522
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4523 // half-time of the current tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4524 var_ht = var_N2_ht;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4525
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4526 // check if desaturation to target pressure is possible at all
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4527 if( pres_target < 0.0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4528 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4529 // NO - set no-fly time to 288 * 10 min = 48 h
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4530 int_O_nofly_time = 288;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4531 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4532 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4533 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4534 // YES - calculate desaturation time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4535 calc_desaturation_time_helper();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4536
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4537 // - extend desaturation time if this tissue needs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4538 // more time than already found to be needed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4539 if( int_time > int_O_nofly_time ) int_O_nofly_time = int_time;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4540 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4541
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4542 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4543
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4544 } // for(compartments)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4545
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4546
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4547 // rescale int_O_desaturation_time and int_O_nofly_time to full minutes for display purpose
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4548 int_O_desaturation_time *= 10;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4549 int_O_nofly_time *= 10;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4550
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4551 // limit int_O_desaturation_time and int_O_nofly_time to 5999 = 99 hours + 59 minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4552 // because of display space constraints and rounding done above
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4553 if( int_O_desaturation_time > 5999 ) int_O_desaturation_time = 5999;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4554 if( int_O_nofly_time > 5999 ) int_O_nofly_time = 5999;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4555
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4556
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4557 // Clear the micro bubbles warning when the current gradient factor is < 100%.
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4558 // 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
4559 // 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
4560 // attention color instead of warning color.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4561 if( int_O_lead_supersat < 100 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4562 deco_warnings &= ~DECO_WARNING_MBUBBLES;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4563
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4564 // clear some warnings when the desaturation time has become zero
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4565 if( int_O_desaturation_time == 0 )
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4566 deco_warnings &= ~( DECO_WARNING_IBCD + DECO_WARNING_IBCD_lock
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4567 + DECO_WARNING_MBUBBLES + DECO_WARNING_MBUBBLES_lock
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4568 + DECO_WARNING_OUTSIDE + DECO_WARNING_OUTSIDE_lock
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4569 + DECO_ATTENTION_OUTSIDE );
0
heinrichsweikamp
parents:
diff changeset
4570 }
heinrichsweikamp
parents:
diff changeset
4571
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4572
0
heinrichsweikamp
parents:
diff changeset
4573 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4574 // Calculate desaturation of the real tissues for a given time interval
0
heinrichsweikamp
parents:
diff changeset
4575 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4576 // Caution: Works on the real tissues!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4577 // If in doubt, use this function only inside a context surrounded with
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4578 // push_tissues_to_vault() / pull_tissues_from_vault() !
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4579 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4580 // Input: int_I_pres_surface surface pressure in mbar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4581 // time_interval time interval in minutes, must be limited to 254 at max
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4582 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4583 // Modified: tissue pressures N2 and He pressures of the tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4584 // CNS_fraction_real current real CNS value
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4585 // ceiling minimum allowed depth in bar relative pressure
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4586 // lead_supersat supersaturation of the leading tissue (float)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4587 // int_O_lead_supersat supersaturation of the leading tissue (integer)
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4588 // char_O_lead_tissue number of the leading tissue
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4589 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4590 static void calc_interval(PARAMETER unsigned char time_interval)
0
heinrichsweikamp
parents:
diff changeset
4591 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4592 overlay unsigned char time;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4593
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4594 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
4595 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
4596 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
4597
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4598
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4599 // safeguard and convert surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4600 if( int_I_pres_surface < 500) pres_surface = 0.500;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4601 else pres_surface = 0.001 * int_I_pres_surface;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4602
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4603 // safeguard time interval
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4604 if( time_interval > 254 ) time_interval = 254;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4605
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4606 // set breathed pressure to surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4607 real_pres_respiration = pres_surface;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4608
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4609 // calculate partial pressure of N2 in respired air at surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4610 calc_N2_equilibrium();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4611
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4612 // calculate partial pressures (0.7902 is fraction of N2 in atmosphere as of Buhlmann)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4613 ppN2 = N2_equilibrium;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4614 ppHe = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4615
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4616 // get, safeguard and convert the saturation and desaturation factors
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4617 get_saturation_factors();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4618
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4619 // adjust desaturation factor to surface mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4620 float_desaturation_multiplier *= SURFACE_DESAT_FACTOR;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4621
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4622 // Calculate the tissues:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4623 // Because calc_tissues() can calculate for 127 minutes at max,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4624 // the tissue updating may need to be done in two chunks.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4625
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4626 time = time_interval;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4627
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4628 // first chunk for the part exceeding 127 minutes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4629 if( time > 127)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4630 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4631 // do a full 127 minutes on the real tissues
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4632 tissue_increment = TISSUE_SELECTOR | 127;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4633 calc_tissues();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4634
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4635 // determine the remaining time
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4636 time -= 127;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4637 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4638
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4639 // program the remaining time (or full time if not exceeding 127 minutes) on the real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4640 tissue_increment = TISSUE_SELECTOR | time;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4641
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4642 // update the N2 and He pressures in the tissues
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4643 calc_tissues();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4644
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4645
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4646 // Calculate CNS:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4647 // 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
4648 // 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
4649
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4650 time = time_interval;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4651
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4652 while( time )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4653 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4654 if( time > 9 )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4655 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4656 CNS_fraction_real *= 0.925874712; // half-time = 90 min -> 10 min: (1/2)^(1/9)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4657 time -= 10; // fast speed looping
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4658 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4659 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4660 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4661 CNS_fraction_real *= 0.992327946; // half-time = 90 min -> 1 min: (1/2)^(1/90)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4662 time -= 1; // slow speed looping
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4663 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4664 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4665
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4666 // convert the CNS value to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4667 convert_cur_CNS_for_display();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4668
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4669 // calculate the supersaturation of the leading tissue, the
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4670 // negative argument puts calc_limit() into surface mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4671 // Attention: do not pass char_I_GF_High_percentage as an argument
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4672 // here because it is not configured outside dive mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4673 calc_limit(-1.0);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4674
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4675 // convert the saturation value of the leading tissue to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4676 convert_sat_for_display();
0
heinrichsweikamp
parents:
diff changeset
4677 }
heinrichsweikamp
parents:
diff changeset
4678
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4679
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4680 //////////////////////////////////////////////////////////////////////////////
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4681 // calc_CNS
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4682 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4683 // Input: char_ppO2 current ppO2 [in 0.1 bars]
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4684 // tissue_increment tissue selector and time interval
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4685 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4686 // Modified: CNS_fraction_real accumulated CNS (real tissue context)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4687 // CNS_fraction_sim accumulated CNS (simulated tissue context)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4688 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4689 static void calc_CNS(void)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4690 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4691 overlay float CNS_fraction_inc; // increment of CNS load, 0.01 = 1%
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4692
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4693
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4694 // calculate CNS increment for a 2 seconds interval
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4695 if( char_ppO2 > 160 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4696 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4697 // step-wise CNS increment
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4698
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4699 // calculate index for increment look-up (uses integer division)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4700 cns_i = (char_ppO2 - 161) / 5;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4701
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4702 // indexes > 17 use increment of index 17
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4703 if( cns_i > 17 ) cns_i = 17;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4704
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4705 // read coefficient (increment)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4706 read_CNS_c_coefficient();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4707
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4708 // re-scale coefficient from storage format in [1/100000] to productive value
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4709 CNS_fraction_inc = (float)var_cns_value / 100000.0;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4710 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4711 else if( char_ppO2 > 50 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4712 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4713 // range wise CNS increment approximation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4714
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4715 // calculate index for approximation coefficients look-up (uses integer division)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4716 cns_i = (char_ppO2 - 51) / 10;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4717
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4718 // read coefficients
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4719 read_CNS_ab_coefficient();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4720
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4721 // calculate the CNS increment
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4722 CNS_fraction_inc = 1.0 / (var_cns_gain * char_ppO2 + var_cns_offset );
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4723 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4724 else
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4725 { // no increment for a ppO2 of up to 0.5 bar
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4726 CNS_fraction_inc = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4727 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4728
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4729 // apply a time factor in case of:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4730 // - simulated tissues and interval = 0 (i.e. 6 seconds to do) -> factor 3
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4731 // - any tissues and interval > 0 (i.e. i minutes to do) -> factor 30 * i
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4732 if( tissue_increment == 0 ) CNS_fraction_inc *= 3.0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4733 else if( tissue_increment & TIME_MASK ) CNS_fraction_inc *= 30.0 * (float)(tissue_increment & TIME_MASK);
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4734
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4735
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4736 // update the CNS accumulator
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4737 if ( tissue_increment & TISSUE_SELECTOR ) CNS_fraction_real += CNS_fraction_inc; // real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4738 else CNS_fraction_sim += CNS_fraction_inc; // simulated tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4739 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4740
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4741
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4742 //////////////////////////////////////////////////////////////////////////////
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4743 // calc_required_volume
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4744 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4745 // Calculates the gas volume required for a given depth, time and usage (SAC)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4746 // rate. It uses a fixed surface pressure of 1.0 bar to deliver stable results
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4747 // when used through the deco calculator.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4748 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4749 // Input: gas_needs_depth depth in meters
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4750 // gas_needs_time time in minutes (0 encodes 1/10 minute)
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4751 // gas_needs_usage_rate gas usage in liters per minute at surface pressure
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4752 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4753 // Output: gas_needs_volume_due required gas volume in liters
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4754 //
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4755 static void calc_required_volume(void)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4756 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4757 // calculate volume for 1 minute
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4758 gas_needs_volume_due = ((float)gas_needs_depth * METER_TO_BAR + pres_surface) * gas_needs_usage_rate;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4759
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4760 // multiply 1-minute-volume with time factor if time factor <> 1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4761 if ( gas_needs_time == 0 ) gas_needs_volume_due *= 0.1; // 1/10 minute
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4762 else if ( gas_needs_time > 1 ) gas_needs_volume_due *= gas_needs_time; // multiple minutes
0
heinrichsweikamp
parents:
diff changeset
4763 }
heinrichsweikamp
parents:
diff changeset
4764
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4765
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4766
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4767 #ifdef _rx_functions
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4768
0
heinrichsweikamp
parents:
diff changeset
4769 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4770 // calc_TR_functions
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4771 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4772 // Process Pressure Readings (OSTC TR only)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4773 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4774 // Input: todo
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4775 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4776 // Output: todo
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4777 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4778 static void calc_TR_functions(void)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4779 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4780 // pressure warnings for reading 1, but only if enabled and pressure value available
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4781 if( (char_I_pressure_gas[0] > 0) && !(int_IO_pressure_value[0] & INT_FLAG_NOT_AVAIL) )
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4782 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4783 overlay unsigned short pressure_value = int_IO_pressure_value[0] & ~INT_FLAG_OUTDATED;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4784
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4785 if( (char_I_pressure_gas[0] < 6 ) && !(int_O_pressure_need[0] & INT_FLAG_NOT_AVAIL) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4786 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4787 // not a diluent and need available: warning & attention by need
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4788 if ( pressure_value <= int_O_pressure_need[0])
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4789 int_IO_pressure_value[0] |= INT_FLAG_WARNING;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4790 else if( pressure_value <= int_O_pressure_need[0] + int_O_pressure_need[0] / 2 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4791 int_IO_pressure_value[0] |= INT_FLAG_ATTENTION;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4792 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4793 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4794 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4795 // a diluent or need not available: warning & attention by fixed thresholds
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4796 if ( pressure_value <= PRESSURE_LIMIT_WARNING ) int_IO_pressure_value[0] |= INT_FLAG_WARNING;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4797 else if ( pressure_value <= PRESSURE_LIMIT_ATTENTION ) int_IO_pressure_value[0] |= INT_FLAG_ATTENTION;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4798 }
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4799 }
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4800
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4801 // pressure warnings for reading 2, but only if enabled and pressure value available
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4802 if( (char_I_pressure_gas[1] > 0) && !(int_IO_pressure_value[1] & INT_FLAG_NOT_AVAIL) )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4803 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4804 overlay unsigned short pressure_value = int_IO_pressure_value[1] & ~INT_FLAG_OUTDATED;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4805
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4806 if( (char_I_pressure_gas[1] < 6 ) && !(int_O_pressure_need[1] & INT_FLAG_NOT_AVAIL) )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4807 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4808 // not a diluent and need available: warning & attention by need
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4809 if ( pressure_value <= int_O_pressure_need[1])
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4810 int_IO_pressure_value[1] |= INT_FLAG_WARNING;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4811 else if ( pressure_value <= int_O_pressure_need[1] + int_O_pressure_need[1] / 2 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4812 int_IO_pressure_value[1] |= INT_FLAG_ATTENTION;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4813 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4814 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4815 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4816 // a diluent or need not available: warning & attention by fixed thresholds
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4817 if ( pressure_value <= PRESSURE_LIMIT_WARNING ) int_IO_pressure_value[1] |= INT_FLAG_WARNING;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4818 else if ( pressure_value <= PRESSURE_LIMIT_ATTENTION ) int_IO_pressure_value[1] |= INT_FLAG_ATTENTION;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4819 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4820 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4821
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4822 //--- SAC Calculation ---------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4823 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4824 // char_I_SAC_mode =0: disabled
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4825 // =1: SAC from 1st reading
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4826 // =2: SAC from 2nd reading
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4827 // =3: SAC from higher one of both pressure drops (independent double mode)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4828 // =4: SAC (O2 usage) from 2nd reading without real_pres_respiration term
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4829
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4830 // set SAC rate to not available by default
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4831 int_O_SAC_measured = 0 + INT_FLAG_NOT_AVAIL;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4832
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4833 // get a copy of the current absolute pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4834 pres_respiration_sac = real_pres_respiration;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4835
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4836 // set threshold for SAC rate attention
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4837 max_sac_rate = (deco_info & DECO_MODE) ? char_I_SAC_deco : char_I_SAC_work;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4838
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4839 // char_I_SAC_deco / char_I_SAC_work are in l/min, max_sac_rate is in 0.1 l/min
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4840 max_sac_rate *= 10;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4841
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4842
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4843 // pre-process SAC mode 3 (independent double)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4844 if( char_I_SAC_mode == 3 )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4845 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4846 overlay unsigned char reading1_gas;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4847 overlay unsigned char reading2_gas;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4848 overlay unsigned char reading1_tanksize;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4849 overlay unsigned char reading2_tanksize;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4850 overlay unsigned short reading1_press;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4851 overlay unsigned short reading2_press;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4852 overlay unsigned short reading1_drop;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4853 overlay unsigned short reading2_drop;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4854
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4855 // get gas numbers (1-10) of both readings
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4856 reading1_gas = char_I_pressure_gas[0];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4857 reading2_gas = char_I_pressure_gas[1];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4858
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4859 // default to no SAC calculation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4860 char_I_SAC_mode = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4861
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4862 // clear switch advice by default
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4863 deco_info &= ~IND_DOUBLE_SWITCH_FLAG;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4864
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4865 // check if both readings are configured and available
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4866 if( reading1_gas )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4867 if( reading2_gas )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4868 if( !(int_IO_pressure_value[0] & INT_FLAG_NOT_AVAIL) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4869 if( !(int_IO_pressure_value[1] & INT_FLAG_NOT_AVAIL) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4870 if( !(int_I_pressure_drop[0] & INT_FLAG_NOT_AVAIL) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4871 if( !(int_I_pressure_drop[1] & INT_FLAG_NOT_AVAIL) )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4872 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4873 // get tank pressures, stripping flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4874 reading1_press = int_IO_pressure_value[0] & 0x0FFF; // in 0.1 bar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4875 reading2_press = int_IO_pressure_value[1] & 0x0FFF; // in 0.1 bar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4876
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4877 // get pressure drops as integers, stripping flags and shifting right
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4878 // to avoid an overflow when multiplying with the tank size later on
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4879 reading1_drop = (int_I_pressure_drop[0] & 0x0FFF) >> 2;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4880 reading2_drop = (int_I_pressure_drop[1] & 0x0FFF) >> 2;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4881
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4882 // get tank sizes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4883 reading1_tanksize = char_I_gas_avail_size[reading1_gas-1];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4884 reading2_tanksize = char_I_gas_avail_size[reading2_gas-1];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4885
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4886 // set mode to calculate SAC on the reading with the higher absolute drop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4887 char_I_SAC_mode = (reading1_drop * reading1_tanksize > reading2_drop * reading2_tanksize) ? 1 : 2;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4888
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4889 // compute switch advice if pressure (in 0.1 bar) of tank breathed from is
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4890 // more than char_I_max_pres_diff (in bar) below pressure of the other tank.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4891 if( char_I_SAC_mode == 1 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4892 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4893 // breathing from reading 1, switch advice if pressure on reading 1 lower than on 2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4894 if( (reading1_press + 10*char_I_max_pres_diff) <= reading2_press )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4895 deco_info |= IND_DOUBLE_SWITCH_FLAG;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4896 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4897 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4898 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4899 // breathing from reading 2, switch advice if pressure on reading 2 lower than on 1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4900 if( (reading2_press + 10*char_I_max_pres_diff) <= reading1_press )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4901 deco_info |= IND_DOUBLE_SWITCH_FLAG;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4902 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4903 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4904 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4905
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4906
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4907 // pre-process SAC mode 4 (O2 usage by reading 2)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4908 if( char_I_SAC_mode == 4 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4909 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4910 // O2 usage on CCR is independent from absolute pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4911 pres_respiration_sac = 1.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4912
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4913 // O2 pressure drop is measured via reading 2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4914 char_I_SAC_mode = 2;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4915
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4916 // reconfigure max SAC rate to O2 consumption attention threshold
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4917 max_sac_rate = O2_CONSUMPTION_LIMIT_ATTENTION;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4918 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4919
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4920
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4921 // select which pressure reading to log
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4922 if( char_I_SAC_mode == 1 ) int_O_tank_pressure = int_IO_pressure_value[0];
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4923 else if( char_I_SAC_mode == 2 ) int_O_tank_pressure = int_IO_pressure_value[1];
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4924 else int_O_tank_pressure = 0;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4925
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4926 // strip flags
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4927 int_O_tank_pressure &= 0x0FFF;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4928
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4929 // scale to recording format of full bar only
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4930 int_O_tank_pressure /= 10;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4931
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
4932
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4933 // calculate SAC - modes 1 & 2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4934 if( (char_I_SAC_mode == 1) || (char_I_SAC_mode == 2) )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4935 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4936 overlay unsigned char reading_index;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4937 overlay unsigned char reading_gas;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4938 overlay unsigned char reading_tanksize;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4939 overlay float reading_drop;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4940
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4941 // set index: char_I_SAC_mode = 1 -> reading one, index 0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4942 // = 2 -> two, 1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4943 reading_index = char_I_SAC_mode - 1;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4944
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4945 // get gas number (1-10)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4946 reading_gas = char_I_pressure_gas[reading_index];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4947
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4948 // check if reading is configured and available
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4949 if( reading_gas )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4950 if( !(int_I_pressure_drop[reading_index] & INT_FLAG_NOT_AVAIL) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4951 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4952 // get tank size (in liter)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4953 reading_tanksize = char_I_gas_avail_size[reading_gas-1];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4954
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4955 // get pressure drop as float, stripping flags (in 1/5120 bar/sec)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4956 reading_drop = (float)(int_I_pressure_drop[reading_index] & 0x0FFF);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4957
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4958 // check if pressure drop is within range
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4959 if( !(int_I_pressure_drop[reading_index] & INT_FLAG_OUT_OF_RANGE) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4960 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4961 // calculate SAC, 10 is factor to have result in 0.1 liter/min
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4962 // 60 is factor for 60 seconds per 1 minute,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4963 // 5120 accounts for reading_drop being in 1/5120 bar/sec
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4964 // 10*60/5120 = 60/512 = 15/128
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4965 float_sac = reading_drop * 15/128 * reading_tanksize / pres_respiration_sac;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4966
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4967 // limit result to 999 (99.9 liter/min)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4968 if ( float_sac >= 998.5 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4969 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4970 int_O_SAC_measured = 999 + INT_FLAG_ATTENTION;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4971 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4972 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4973 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4974 // convert float to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4975 int_O_SAC_measured = (unsigned short)(float_sac + 0.5);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4976
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4977 // set attention flag if exceeding SAC threshold, but only if pressure drop is not outdated
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4978 if( !(int_I_pressure_drop[reading_index] & INT_FLAG_OUTDATED) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4979 if( int_O_SAC_measured >= max_sac_rate )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4980 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4981 int_O_SAC_measured |= INT_FLAG_ATTENTION;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4982 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4983 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4984 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4985 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4986 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4987 // pressure drop is out of range, so SAC will be set out of range, too
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4988 int_O_SAC_measured = 999 + INT_FLAG_ATTENTION;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4989 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4990
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4991 // copy outdated flag from int_I_pressure_drop to int_O_SAC_measured
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4992 if( int_I_pressure_drop[reading_index] & INT_FLAG_OUTDATED )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4993 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4994 int_O_SAC_measured |= INT_FLAG_OUTDATED;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4995 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4996 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4997 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4998 }
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
4999 #endif // _rx_functions
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5001
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5002 #ifdef _cave_mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5003
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5004 //////////////////////////////////////////////////////////////////////////////
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5005 // read_backtrack_data
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5006 //
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5007 // Gets the data of the next backtracking data set
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5008 //
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5009 // Modified: backtrack_index last current position in backtracking storage
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5010 //
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5011 // Output: backtrack_step_counter number of 1/10 min calculation steps to do on next target depth
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5012 // backtrack_target_depth next target depth
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5013 //
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5014 static void read_backtrack_data(void)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5015 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5016 overlay unsigned char firstround = 1;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5017
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5018
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5019 // load the step counter with the default of ten 1/10 minute steps to go between two depth samples
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5020 backtrack_step_counter = 10;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5021
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5022 // repeat until having read the whole data set or having reached the first storage position
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5023 while(backtrack_index)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5024 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5025 // backtracking data recording format:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5026 // ---------------------------------------------------------------------------
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5027 // 0ddddddd -> datum is a depth recording with d = 0..127 depth in meters
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5028 // 10tttttt -> delta time with t = 0.. 59 time in seconds
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5029 // 110ggggg -> gas staging status with g = 1 gas staged
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5030 // 111nnnnn -> waypoint marker with n = 1.. 31 waypoint number
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5031 //
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5032 // gas availability vector: LSB : gas 1 (and so on)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5033 // waypoint marker : 1 - 30: user waypoints, last waypoint is turn point
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5034 // : 31: spare for turn point if all 30 waypoints used up
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5035 // : 0: reserved
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5036
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5037 // read recording entry and then advance (backward direction!) the reading index
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5038 overlay unsigned char datum = char_I_backtrack_storage[backtrack_index--];
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5039
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5040 // is it a target depth?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5041 if( datum < 128 )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5042 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5043 // YES - assign the target depth
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5044 backtrack_target_depth = datum;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5045
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5046 // a depth entry closes a data set, so done with this data set
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5047 return;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5048 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5049
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5050 // is it a delta time entry?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5051 else if( datum < 128 + 64 )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5052 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5053 // YES - When a delta time entry is contained in a data set, the time
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5054 // stored in the delta time entry is the time that has elapsed
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5055 // between storage of the depth that is part of this data set
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5056 // and the previous depth recording.
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5057 // This entry is stored whenever the delta time is shorter than
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5058 // the default 1 minute depth sampling interval time.
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5059
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5060 // assign the delta time to the step counter: remove entry tag and
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5061 // convert datum from 0..59 seconds to 0..9 steps by integer division
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5062 backtrack_step_counter = (datum - 128) / 6;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5063 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5064
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5065 // is it a gas staging status entry?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5066 else if( datum < 128 + 64 + 32 )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5067 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5068 // YES - extract gas staging status
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5069 overlay unsigned char gas_status = datum - (128 + 64);
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5070
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5071 // decode and update gas staging status
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5072 //
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5073 // bit set : gas is staged (not available) during next section of backtracking,
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5074 // bit cleared: gas is not staged ( available) during next section of backtracking.
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5075 //
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5076 // bit 0 corresponds to gas 1, ..., bit 4 corresponds to gas 5
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5077 //
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5078 for( i = 0; i < NUM_GAS; i++ )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5079 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5080 if ( gas_status & (1 << i) ) deco_gas_type[i] |= GAS_AVAIL_STAGED; // staged
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5081 else deco_gas_type[i] &= ~GAS_AVAIL_STAGED; // not staged
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5082 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5083 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5084
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5085 // must be waypoint marker entry then
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5086 else
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5087 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5088 // set step counter to zero if first entry read is a waypoint entry
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5089 if( firstround ) backtrack_step_counter = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5090 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5091
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5092 // first round done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5093 firstround = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5094
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5095 } // while
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5096
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5097 // first storage position reached, by convention it contains
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5098 // the final target depth which is zero meters aka the surface
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5099 backtrack_target_depth = 0;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5100 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5101
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5102 #endif // _cave_mode
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5103
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5104
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5105
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5106 //////////////////////////////////////////////////////////////////////////////
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5107 // convert_volume_to_pressure
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5108 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5109 // Converts gas volumes into pressures and sets respective flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5110 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5111 // Input: gas_needs_gas_index index of the gas to convert (0-4)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5112 // gas_volume_need[] needed gas volume in liters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5113 // char_I_gas_avail_pres[] available gas volume in bar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5114 // char_I_gas_avail_size[] size of the tanks in liters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5115 // char_I_pressure_gas[] gas configured on reading 1/2 (TR only)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5116 //
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5117 // Output: int_O_gas_need_vol[] required gas amount in liters
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5118 // int_O_gas_need_pres[] required gas amount in bar, including flags
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5119 // int_O_pressure_need[] required gas amount for reading 1/2 (TR only)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5120 //
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5121 static void convert_volume_to_pressure(void)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5122 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5123 // just to make the code more readable...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5124 i = gas_needs_gas_index;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5125
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5126 if( gas_volume_need[i] >= 65534.5 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5127 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5128 int_O_gas_need_vol[i] = 65535; // clip at 65535 liters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5129 int_O_gas_need_pres[i] = 999 | INT_FLAG_WARNING | INT_FLAG_HIGH; // 999 bar + warning flag + >999 flag
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
5130 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
5131 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
5132 {
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5133 // convert gas volume need from float to integer [in liter]
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5134 int_O_gas_need_vol[i] = (unsigned short)( gas_volume_need[i] + 0.5 );
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5135
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5136 // compute how much pressure in the tank will be needed [in bar]
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5137 int_O_gas_need_pres[i] = (unsigned short)( gas_volume_need[i] / char_I_gas_avail_size[i] + 0.5 );
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5138
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5139 // limit result to 999 bar because of display constraints
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5140 if( int_O_gas_need_pres[i] > 999 ) int_O_gas_need_pres[i] = 999 | INT_FLAG_HIGH;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5141
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5142 // set flags for fast evaluation by output routine
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5143 if( int_O_gas_need_pres[i] == 0 ) int_O_gas_need_pres[i] |= INT_FLAG_ZERO;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5144 else
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5145 #ifdef _gas_contingency
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5146 if( main_status & GAS_CONTINGENCY )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5147 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5148 // take warning and attention computed en-route
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5149 if ( deco_gas_type[i] & GAS_NEED_WARNING )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5150 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5151 // tag the tank with a warning
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5152 int_O_gas_need_pres[i] |= INT_FLAG_WARNING;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5153
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5154 // tag the peer tanks with a warning, too
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5155 for( j = 0; j < NUM_GAS; j++ )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5156 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5157 if( peer_tank[i] & (1 << j) ) int_O_gas_need_pres[j] |= INT_FLAG_WARNING;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5158 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5159 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5160 else if( deco_gas_type[i] & GAS_NEED_ATTENTION )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5161 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5162 // tag the tank with an attention
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5163 int_O_gas_need_pres[i] |= INT_FLAG_ATTENTION;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5164
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5165 // tag the peer tanks with an attention, too
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5166 for( j = 0; j < NUM_GAS; j++ )
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5167 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5168 if( peer_tank[i] & (1 << j) ) int_O_gas_need_pres[j] |= INT_FLAG_ATTENTION;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5169 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5170 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5171 }
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5172 else
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5173 #endif
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5174 {
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5175 // compute warning and attention now
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5176 if ( gas_volume_need[i] >= gas_volume_avail[i] ) int_O_gas_need_pres[i] |= INT_FLAG_WARNING;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5177 else if( gas_volume_need[i] >= gas_volume_atten[i] ) int_O_gas_need_pres[i] |= INT_FLAG_ATTENTION;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5178 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
5179 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
5180
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5181 // set invalid flag if there is an overflow in the stops table or calculation took too long
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
5182 if( deco_warnings & DECO_WARNING_INCOMPLETE ) int_O_gas_need_pres[i] |= INT_FLAG_INVALID;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
5183
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5184 #ifdef _rx_functions
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5185 // only for OSTC TR model with TR functions enabled
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5186 if( main_status & TR_FUNCTIONS )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
5187 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5188 // char_I_pressure_gas[] uses gas indexes from 1-10, loop variable i runs from 0 to 4
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5189 j = i+1;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5190
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5191 // check if the current gas is configured on pressure reading 1 or 2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5192 if( (char_I_pressure_gas[0] == j) || (char_I_pressure_gas[1] == j) )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
5193 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5194 // get a copy of the required pressure in full bar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5195 overlay unsigned short int_pres_need = int_O_gas_need_pres[i];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5196
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5197 // strip all flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5198 int_pres_need &= 1023;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5199
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5200 // limit to 400 bar and multiply by 10 to get required pressure in 0.1 bar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5201 int_pres_need = (int_pres_need > 400) ? 4000 | INT_FLAG_OUT_OF_RANGE : 10 * int_pres_need;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5202
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5203 // tag as not available if there is an overflow in the stops table or calculation took too long
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
5204 if( deco_warnings & DECO_WARNING_INCOMPLETE ) int_pres_need |= INT_FLAG_NOT_AVAIL;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5205
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5206 // copy to reading data (in both readings the same gas could be configured)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5207 if( char_I_pressure_gas[0] == j ) int_O_pressure_need[0] = int_pres_need;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5208 if( char_I_pressure_gas[1] == j ) int_O_pressure_need[1] = int_pres_need;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5209 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5210 } // TR functions
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5211 #endif
0
heinrichsweikamp
parents:
diff changeset
5212 }
heinrichsweikamp
parents:
diff changeset
5213
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5214
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5215 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5216 // convert the real CNS value to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5217 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5218 // Input CNS_fraction_real current CNS value as float
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5219 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5220 // Output: int_O_CNS_current current CNS value as integer including flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5221 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5222 static void convert_cur_CNS_for_display(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5223 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5224 // convert to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5225 float_value = CNS_fraction_real; convert_float_to_int(); int_O_CNS_current = int_value;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5226
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5227 // set warning & attention flags
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
5228 if ( int_O_CNS_current >= CNS_LIMIT_WARNING ) int_O_CNS_current |= INT_FLAG_WARNING;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
5229 else if ( int_O_CNS_current >= CNS_LIMIT_ATTENTION ) int_O_CNS_current |= INT_FLAG_ATTENTION;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5230 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5231
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5232
0
heinrichsweikamp
parents:
diff changeset
5233 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5234 // convert the simulated CNS value to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5235 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5236 // Input: CNS_fraction_sim CNS value after predicted ascent in float
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5237 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5238 // Output: int_sim_CNS_fraction CNS value after predicted ascent in integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5239 // including flags, will be routed to
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5240 // int_O_{normal,alternative}_CNS_fraction
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5241 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5242 static void convert_sim_CNS_for_display(void)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5243 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5244 // convert to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5245 float_value = CNS_fraction_sim; convert_float_to_int(); int_sim_CNS_fraction = int_value;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5246
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5247 // set warning & attention flags
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
5248 if ( int_sim_CNS_fraction >= CNS_LIMIT_WARNING ) int_sim_CNS_fraction |= INT_FLAG_WARNING;
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
5249 else if ( int_sim_CNS_fraction >= CNS_LIMIT_ATTENTION ) int_sim_CNS_fraction |= INT_FLAG_ATTENTION;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5250
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5251 // set invalid flag if there is an overflow in the stops table or calculation took too long
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
5252 if ( deco_warnings & DECO_WARNING_INCOMPLETE ) int_sim_CNS_fraction |= INT_FLAG_INVALID;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5253 }
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5254
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5255
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5256 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5257 // convert the saturation value of the leading tissue to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5258 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5259 // Input lead_supersat saturation of the leading tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5260 // lead_tissue number of the leading tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5261 // char_I_GF_High_percentage GF high factor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5262 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5263 // Output: int_O_lead_supersat saturation of the leading tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5264 // char_O_lead_tissue number of the leading tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5265 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5266 // Modified: deco_warnings deco engine warnings vector
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5267 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5268 static void convert_sat_for_display(void)
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5269 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5270 // convert supersaturation of the leading tissue to int_O_lead_supersat in % (1.0 = 100%)
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5271 // limit to 255 because of constraints in ghostwriter code
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5272 if ( lead_supersat <= 0.000 ) int_O_lead_supersat = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5273 else if ( lead_supersat > 2.545 ) int_O_lead_supersat = 255;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5274 else int_O_lead_supersat = (unsigned short)(100 * lead_supersat + 0.5);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5275
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5276 // set warning & attention flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5277 if( int_O_lead_supersat > 100 )
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5278 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5279 int_O_lead_supersat |= INT_FLAG_WARNING; // make GF factor shown in red
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5280 deco_warnings |= DECO_WARNING_OUTSIDE; // make depth shown in red
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5281 }
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5282 else if( (char_I_model != 0) && (int_O_lead_supersat > char_I_GF_High_percentage)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
5283 || (char_I_model == 0) && (int_O_lead_supersat > 99 ) )
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5284 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5285 int_O_lead_supersat |= INT_FLAG_ATTENTION; // make GF factor shown in yellow
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5286 deco_warnings |= DECO_ATTENTION_OUTSIDE; // make depth shown in yellow
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5287 }
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5288
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5289 // export also the number of the leading tissue
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5290 char_O_lead_tissue = lead_tissue;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5291 }
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5292
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5293
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5294 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5295 // convert the ceiling value to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5296 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5297 // Input: ceiling minimum depth permitted in float
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5298 //
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
5299 // Output: int_O_ceiling minimum depth permitted in mbar (cm)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5300 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5301 // Modified: deco_info deco engine information vector
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5302 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5303 static void convert_ceiling_for_display(void)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5304 {
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5305 // 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
5306 // 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
5307 // 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
5308 // with TTS switching back to NDL time.
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
5309 // The +1.5 term figures in the conversion factor of 10.015 m/bar
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
5310 // which is used inside the deco engine but not outside of it.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5311 if ( ceiling <= 0.0 ) int_O_ceiling = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5312 else if ( ceiling > 16.0 ) int_O_ceiling = 16000;
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
5313 else int_O_ceiling = (unsigned short)(ceiling * (1000+1.5) + 9);
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5314
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5315 // set/reset ceiling flag
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5316 if ( int_O_ceiling ) deco_info |= DECO_CEILING;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5317 else deco_info &= ~DECO_CEILING;
0
heinrichsweikamp
parents:
diff changeset
5318 }
heinrichsweikamp
parents:
diff changeset
5319
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5320
0
heinrichsweikamp
parents:
diff changeset
5321 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5322 // push_tissues_to_vault & pull_tissues_from_vault
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5323 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5324 // ATTENTION: Do not use from inside the deco engine!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5325 // The vault is exclusively reserved to back-up and restore the real
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5326 // tissues and related data when entering / leaving simulation mode!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5327 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5328 // Input/Output: CNS_fraction_real current real CNS value
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5329 // char_O_deco_warnings deco engine warnings vector
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5330 // real_pres_tissue_N2[] partial pressure of N2 in real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5331 // real_pres_tissue_He[] partial pressure of He in real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5332 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5333 // Output: int_O_CNS_current current CNS value as integer including flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5334 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5335 static void push_tissues_to_vault(void)
0
heinrichsweikamp
parents:
diff changeset
5336 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5337 // store the current CNS value and deco warnings
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5338 vault_CNS_fraction_real = CNS_fraction_real;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5339 vault_deco_warnings = char_O_deco_warnings;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5340 vault_deco_info = char_O_deco_info;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5341
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5342 // store the tissue pressures
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5343 for( i = 0; i < NUM_COMP; i++ )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5344 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5345 vault_pres_tissue_N2[i] = real_pres_tissue_N2[i];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5346 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5347 vault_pres_tissue_He[i] = real_pres_tissue_He[i];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5348 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5349 vault_pres_tissue_He[i] = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5350 #endif
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5351 }
0
heinrichsweikamp
parents:
diff changeset
5352 }
heinrichsweikamp
parents:
diff changeset
5353
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5354 static void pull_tissues_from_vault(void)
0
heinrichsweikamp
parents:
diff changeset
5355 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5356 // restore the CNS value and deco warnings
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5357 CNS_fraction_real = vault_CNS_fraction_real;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5358 char_O_deco_warnings = vault_deco_warnings;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5359 char_O_deco_info = vault_deco_info;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5360
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5361 // convert the CNS value to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5362 convert_cur_CNS_for_display();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5363
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5364 // restore the tissue pressures
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5365 for( i = 0; i < NUM_COMP; i++ )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5366 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5367 real_pres_tissue_N2[i] = vault_pres_tissue_N2[i];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5368 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5369 real_pres_tissue_He[i] = vault_pres_tissue_He[i];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5370 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5371 real_pres_tissue_He[i] = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5372 #endif
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5373 }
0
heinrichsweikamp
parents:
diff changeset
5374 }
heinrichsweikamp
parents:
diff changeset
5375
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5376
0
heinrichsweikamp
parents:
diff changeset
5377 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
5378 //
heinrichsweikamp
parents:
diff changeset
5379 #ifndef CROSS_COMPILE
heinrichsweikamp
parents:
diff changeset
5380 void main() {}
heinrichsweikamp
parents:
diff changeset
5381 #endif