annotate src/p2_deco.c @ 627:bf5fee575701

minor cleanup, reset rx circuity
author heinrichsweikamp
date Sun, 30 Jun 2019 23:22:32 +0200
parents c40025d8e750
children cd58f7fc86db
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 // ***************************************************************************
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2 // p2_deco.c combined next generation V3.03.4
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
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
38 // 10/14/2008 v104: integration of char_I_depth_last_deco for Gradient Model
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.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
50 // 2011/04/15: [jDG] Store GF_low_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).
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
62 // 2013/03/05: [jDG] Should vault GF_low_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, ...)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
107 #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
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
108
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
109
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
110 // ambient pressure at different mountain heights
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
111 #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
112 #define P_ambient_2000m 0.782 // [bar]
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
113 #define P_ambient_3000m 0.695 // [bar]
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
114
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
115 // ambient pressure in aircraft cabin during flying - worst case according to Buhlmann
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
116 #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
117 // 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
118 // -----
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
119 // 0.135 bar safety margin
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
120
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
121 // constants and factors
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
122 #define ppWater 0.06270 // water vapor partial pressure in the lungs
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
123 #define METER_TO_BAR 0.09985 // conversion factor
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
124 #define BAR_TO_METER 10.0150 // conversion factor (1.0/METER_TO_BAR)
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
125 #define SURFACE_DESAT_FACTOR 0.70420 // surface desaturation safety factor
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
126 #define HYST 1.0E-06 // threshold for tissue graphics on-gassing / off-gassing visualization
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
127
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
128 // thresholds
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
129 #define CNS_WARNING_THRESHOLD 100 // threshold for CNS warning
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
130 #define CNS_ATTENTION_THRESHOLD 70 // threshold for CNS attention
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
131 #define ppO2_GAP_TO_SETPOINT 10 // gap between setpoint and max. ppO2 of the pure diluent [cbar]
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
132 #define GAS_NEEDS_ATTENTION_THRESHOLD 0.70 // threshold for gas needs attention [1.00 = 100%]
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
133 #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
134 #define PRESSURE_LIMIT_ATTENTION 500 // threshold for pressure reading attention: 50.0 bar
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
135 #define O2_CONSUMPTION_LIMIT_ATTENTION 20 // threshold for O2 "SAC" attention: 2.0 l/min
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
136 #define ppO2_MARGIN_ON_MAX 3 // [cbar] margin on ppO2 max to compensate for surface pressures > 1.000 mbar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
137
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
138 // 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
139 #define CALC_VOLUME 0x01 // =1: calculate gas needs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
140 #define CALCULATE_BOTTOM 0x02 // =1: calculate gas needs in deco calculator mode, =0: in dive mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
141 #define CAVE_MODE 0x04 // =1: calculate ascent and gas needs using backtracking data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
142 #define USE_Z_FACTOR 0x08 // =1: calculate with Z factor when converting gas volumes <-> pressures
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
143
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
144 #define TR_FUNCTIONS 0x10 // =1: calculate TR functions (pressure reading) processing
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
145 #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
146
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
147 #define MODE_MASK 0xC0 // mask for real tissues mode selection
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
148 #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
149 #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
150 #define MODE_PSCR 0x80 // =1: pSCR mode (MODE_LOOP needs to be set, too)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
151
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
152 // 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
153 #define PLAN_MASK 0x03 // bit mask covering normal & alternative plan flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
154 #define COMMAND_MASK 0x07 // bit mask covering all command flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
155 #define CALCULATING 0x00 // calculations are ongoing
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
156 #define START_NORM 0x01 // input: start calculation of a normal deco plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
157 #define CALC_NORM 0x01 // internal: calculating a normal deco plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
158 #define COMPLETED_NORM 0x01 // output: calculation of a normal deco plan has completed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
159 #define START_ALT 0x02 // input: start calculation of an alternative deco plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
160 #define CALC_ALT 0x02 // internal: calculating an alternative deco plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
161 #define COMPLETED_ALT 0x02 // output: calculation of an alternative deco plan has completed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
162 #define INITIALIZE 0x04 // input: initialize deco engine
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
163 #define INITIALIZE_START_NORM 0x05 // input: initialize deco engine and start calculation of a normal deco plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
164 #define INITIALIZE_START_ALT 0x06 // input: initialize deco engine and start calculation of an alternative deco plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
165 // 0x08 // unused - reserved for further deco engine commands
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
166
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
167 #define BAILOUT_MODE 0x10 // =1: allow gas switches before first deco stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
168 #define DELAYED_ASCENT 0x20 // =1: figure in a delayed ascent (fTTS)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
169
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
170 // MODE_MASK 0xC0 // mask for simulated tissues mode selection
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
171 // MODE_LOOP 0x40 // =1: CCR (MODE_PSCR needs to be cleared) or pSCR mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
172 // MODE_CCR 0x40 // to be used with == operator in combination with MODE_MASK only!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
173 // MODE_PSCR 0x80 // =1: pSCR mode (MODE_LOOP needs to be set, too)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
174
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
175
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
176 // deco engine warnings - (char_O_)deco_warnings
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
177 #define DECO_WARNING_IBCD 0x01 // IBCD occurring now
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
178 #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
179 #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
180 #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
181 #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
182 #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
183 #define DECO_ATTENTION_OUTSIDE 0x40 // tissue pressures are very close to the Buhlmann limit
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
184 #define DECO_WARNING_STOPTABLE_OVERFLOW 0x80 // internal error: no more space in the deco stops table
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
185
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
186 // deco engine status (char_O_)deco_info
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
187 #define DECO_FLAG 0x01 // =1: deco ppO2 levels are permitted
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
188 #define IND_DOUBLE_SWITCH_FLAG 0x02 // =1: switch to other tank advice active
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
189 // 0x04 // --- unused
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
190 #define DECO_ZONE 0x08 // =1: fTTS < TTS (not updated when in bailout mode)
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
191 #define DECO_CEILING 0x10 // =1: ceiling depth > 0
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
192 #define DECO_STOPS 0x20 // =1: deco stops found
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
193 #define GAS_NEEDS_CAVE 0x40 // =1: indicated gas needs are calculated in cave mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
194 // 0x80 // --- unused
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
195
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
196
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
197 // deco engine control - tissue_increment
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
198 #define TIME_MASK 0x7F // =0: time increment is 2 seconds, 1..127: time increments is 1..127 minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
199 #define TISSUE_SELECTOR 0x80 // =1: calculate on real tissues, =0: calculate on simulated tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
200
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
201
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
202 // deco engine control - next_planning_phase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
203 #define PHASE_00_DONE 0x00 // calculation cycle finished
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
204 #define PHASE_10_DIVE_INIT 0x10 // once-per-dive initialization of the deco engine
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
205 #define PHASE_11_CYCLIC_INIT 0x11 // once-every-cycle initialization of the deco engine
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
206 #define PHASE_20_EXTENDED_BOTTOM_TIME 0x20 // calculate extended bottom time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
207 #define PHASE_30_NDL_TIME 0x30 // calculate NDL time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
208 #define PHASE_40_CAVE_ASCENT 0x40 // calculate cave mode return/ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
209 #define PHASE_60_DECO_ASCENT 0x60 // calculate open water deco ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
210 #define PHASE_70_RESULTS 0x70 // results - initialization
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
211 #define PHASE_71_RESULTS_STOPS_TABLE 0x71 // results - publish stops table
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
212 #define PHASE_72_RESULTS_NDL 0x72 // results - publish data / within NDL
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
213 #define PHASE_73_RESULTS_DECO 0x73 // results - publish data / in deco
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
214 #define PHASE_80_GAS_NEEDS_SWITCHES 0x80 // calculate gas needs - find gas switches in NDL bailout mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
215 #define PHASE_81_GAS_NEEDS_ASCENT 0x81 // calculate gas needs - needs of bottom segment and ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
216 #define PHASE_82_GAS_NEEDS_PRESSURES 0x82 // calculate gas needs - conversion from volumes to pressures
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
217 #define PHASE_90_FINISH 0x90 // finish calculation cycle
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
218
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
219
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
220 // gas needs calculation - gas_needs_next_phase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
221 #define GAS_NEEDS_INIT 0x00 // initialization
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
222 #define GAS_NEEDS_BOTTOM_SEGMENT 0x10 // demand during bottom segment
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
223 #define GAS_NEEDS_INITIAL_ASCENT 0x20 // demand of initial ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
224 #define GAS_NEEDS_STOP 0x30 // demand on a stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
225 #define GAS_NEEDS_INTERMEDIATE_ASCENT 0x40 // demand on ascent between two stops
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
226 #define GAS_NEEDS_FINAL_ASCENT 0x50 // demand during final ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
227 #define GAS_NEEDS_DONE 0x60 // calculation finished
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
228
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
229
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
230 // flags used with integer numbers
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
231 #define INT_FLAG_INVALID 0x0400 // =1: value not valid
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
232 #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
233 #define INT_FLAG_ZERO 0x0800 // =1: value is zero
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
234 #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
235 #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
236 #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
237 #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
238 #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
239 #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
240 #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
241
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
242
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
243
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
244 // *********************************************************************************************************************************
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
245 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
246 // ** 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
247 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
248 // 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
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
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
252 // Functions used in Surface Mode
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
253 static void calc_interval(PARAMETER unsigned char time_increment);
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
254 // Calculates the tissue off-gassing under surface conditions.
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
255 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
256 static void clear_tissue(void); // Resets all tissues to surface pressure equilibrium state.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
257 static void init_output_vars(void); // Initializes all deco engine output variables to defaults
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
258
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
259 // Main entry point in Dive Mode
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
260 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
261
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
262 // Functions dedicated to the real Tissues
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
263 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
264
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
265 // Functions combined for real Tissues & Deco Calculations
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
266 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
267 // needs either calc_hauptroutine_data_input() be called beforehand or
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
268 // gas_find_current()/gas_find_better() and gas_set_ratios().
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
269 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
270 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
271 static void calc_limit(PARAMETER float GF_current);
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
272 // Calculates ceiling, current GF (supersaturation) and some more data.
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
273
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
274 // Functions for TR
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
275 #ifdef _rx_functions
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
276 static void calc_TR_functions(void); // Calculates SAC etc.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
277 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
278
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
279 // Functions dedicated to Deco Calculations
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
280 static void clear_deco_table(void); // Clears the deco stops table, invoked at the start of each calculation cycle.
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
281 static void gas_find_current(void); // Sets the first gas used for deco calculation, invoked at start of cycle, too.
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
282 static unsigned char gas_find_better(void); // Checks for, and eventually switches to, a better gas.
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
283 static void gas_set_ratios(void); // Sets the gas ratios for use in deco calculation (simulated tissues),
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
284 // needs to be called after each gas change (gas_find_current/_better).
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
285 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
286 static void find_NDL_gas_changes(void); // Finds the gas changes in an OC bailout ascent that is within NDL.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
287 static unsigned char find_next_stop(void); // Finds the next stop when in a deco ascent.
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
288 static unsigned char update_deco_table(PARAMETER unsigned char time_increment);
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
289 // Enters a new stop or extends an existing stop in the deco stops table.
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
290 static void calc_ascenttime(void); // Calculates the ascent time from current depth and deco stop times.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
291 static void calc_gas_needs_ascent(void); // Calculates required gas volumes and pressures from the data in stops table.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
292 static void calc_due_by_depth_time_sac(void); // Calculates gas volume required for a given depth, time and usage (SAC rate).
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
293 static void convert_gas_needs_to_press(void); // Converts gas volumes into pressures and sets respective flags.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
294
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
295 // Functions for Results Reporting
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
296 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
297 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
298 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
299 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
300 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
301
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
302
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
303 // internal helper Functions
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
304 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
305 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
306 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
307 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
308 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
309 static void read_Buhlmann_times(PARAMETER char period);
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
310 // 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
311 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
312 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
313 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
314 static void pull_tissues_from_vault(void); // Restores the state of the real tissues after a simulator run.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
315 static void calc_N2_equilibrium(void); // Calculate partial pressure of N2 in respired air at surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
316 static void get_saturation_factors(void); // Get, safeguard and convert the saturation and desaturation factors
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
317 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
318
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
319
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
320 // *********************************************************************************************************************************
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
321 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
322 // 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
323 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
324 // *********************************************************************************************************************************
0
heinrichsweikamp
parents:
diff changeset
325
heinrichsweikamp
parents:
diff changeset
326 //---- Bank 5 parameters -----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
327 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
328 # pragma udata bank5=0x500
heinrichsweikamp
parents:
diff changeset
329 #endif
heinrichsweikamp
parents:
diff changeset
330
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
331 // Environmental and Gas Data (52 byte)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
332
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
333 static float pres_surface; // absolute pressure at the surface
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
334
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
335 static float float_depth_real; // current real depth in meters, float
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
336 static unsigned char char_depth_real; // current real depth in meters, integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
337 static unsigned char char_depth_sim; // current simulated depth in meters, integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
338 static unsigned char char_depth_last; // last simulated depth in meters, integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
339 static unsigned char char_depth_bottom; // bottom depth in meters, integer
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
340
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
341 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
342 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
343 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
344 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
345 static float real_pSCR_drop; // real ppO2 drop in pSCR loop
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
346
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
347 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
348 static float sim_O2_ratio; // simulated breathed gas oxygen ratio
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
349 static float sim_N2_ratio; // simulated breathed gas nitrogen ratio
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
350 static float sim_He_ratio; // simulated breathed gas helium ratio
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
351 static float sim_pSCR_drop; // simulated ppO2 drop in pSCR loop
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
352
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
353
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
354 // general Deco Parameters (57 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
355
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
356 static float GF_low; // gradient factor to determine 1st stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
357 static float GF_high; // gradient factor to determine surfacing
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
358
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
359 static unsigned char GF_low_last; // last GF low, used to detect changes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
360 static unsigned char GF_high_last; // last GF high, used to detect changes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
361
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
362 static unsigned char GF_low_depth; // GF low reference depth in current calculation cycle
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
363 static unsigned char GF_low_depth_norm; // GF low reference depth in normal plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
364 static unsigned char GF_low_depth_alt; // GF low reference depth in alternative plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
365
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
366 static float GF_slope; // (GF_high - GF_low) / GF_low_depth in current calculation cycle
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
367 static float GF_slope_norm; // (GF_high - GF_low) / GF_low_depth_norm in normal plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
368 static float GF_slope_alt; // (GF_high - GF_low) / GF_low_depth_alt in alternative plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
369
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
370 static float float_ascent_speed; // ascent speed from options_table (5.0 .. 10.0 m/min)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
371 static float float_deco_distance; // additional depth below stop depth for tissue, CNS and gas volume calculation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
372 static float float_saturation_multiplier; // safety factor for on-gassing rates
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
373 static float float_desaturation_multiplier; // safety factor for off-gassing rates
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
374
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
375 static unsigned char split_N2_He[NUM_COMP]; // used for calculating the desaturation time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
376
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
377
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
378 // real Context: what we are doing now (16 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
379
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
380 static float CNS_fraction_real; // current real CNS (1.00 = 100%)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
381 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
382
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
383 static float pres_respiration_sac; // used in SAC calculation: current depth in absolute pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
384 static float float_sac; // used in SAC calculation: SAC value in float
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
385 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
386
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
387
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
388 // simulated Context: used to calculate Ascent (11 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
389
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
390 static float CNS_fraction_sim; // CNS after predicted ascent, 0.01 = 1%, as float
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
391 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
392 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
393 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
394 static unsigned char NDL_tissue_start; // tissue to start with in current cycle
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
395 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
396 static unsigned char NDL_tissue; // tissue for which the NDL is calculated right now
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
397
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
398 // Result Values from Calculation Functions (9 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
399
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
400 static float ceiling; // minimum tolerated relative pressure (i.e. without surface pressure)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
401 static float lead_supersat; // supersaturation of the leading tissue, 1.0 = 100%
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
402 static unsigned char lead_tissue; // number of the leading tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
403
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
404
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
405 // Transfer Variables between calc_desaturation_time() and calc_desaturation_time_helper() (18 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
406
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
407 static float desat_factor; // used to cache a pre-computed factor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
408 static float var_ht; // buffer for a half-time factor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
409 static float pres_target; // target pressure for a compartment
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
410 static float pres_actual; // current pressure of the compartment
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
411 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
412
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
413
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
414 // Gas in Use and Gas Needs (30 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
415
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
416 static unsigned char sim_gas_current_num; // number of the currently used gas
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
417 static unsigned char sim_gas_current_depth; // change depth of the currently used gas
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
418
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
419 static unsigned char gas_needs_stop_time; // duration of the stop in minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
420 static unsigned char gas_needs_stop_gas; // gas used now (1-5 or 0)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
421 static unsigned char gas_needs_stop_gas_last; // gas used before (1-5 or 0)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
422 static unsigned char gas_needs_stop_depth; // depth of the stop in meters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
423 static unsigned char gas_needs_stop_depth_last; // depth of the last stop in meters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
424 static unsigned char gas_needs_stop_index; // index to the stop table
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
425 static unsigned char gas_needs_gas_index; // index to the gas and tank data arrays
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
426 static unsigned char gas_needs_next_phase; // next phase within the ascent gas needs calculation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
427
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
428 static float gas_volume_need[NUM_GAS]; // gas volumes required for return/ascent in liters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
429
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
430
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
431 // Transfer Variables between calc_gas_needs_ascent() and calc_due_by_depth_time_sac() (13 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
432
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
433 static float gas_needs_float_depth; // depth of the stop or half-way point
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
434 static float gas_needs_float_time; // duration of the stop or ascent phase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
435 static unsigned char gas_needs_stop_usage; // gas usage in l/min
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
436 static float gas_needs_volume_due; // computed due of gas volume required
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
437
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
438
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
439 // CNS Coefficients (10 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
440
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
441 static float var_cns_a; // two coefficients approximation, gain
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
442 static float var_cns_b; // two coefficients approximation, offset
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
443 static unsigned short var_cns_c; // one coefficient approximation, value
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
444
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
445
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
446 // Transfer values for convert_float_int and convert_float_to_char() (7 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
447
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
448 static float float_value; // input value, float
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
449 static unsigned short int_value; // output value, 16 bit
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
450 static unsigned char char_value; // output value, 8 bit
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
451
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
452
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
453 // Auxiliary Variables for Data Buffering (28 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
454
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
455 static float N2_equilibrium; // used for N2 tissue graphics scaling
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
456 static float temp_tissue; // auxiliary variable to buffer tissue pressures
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
457 static float float_pSCR_factor; // pre-computed factor for pSCR ppO2 drop calculation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
458 static float calc_pres_tissue_N2; // auxiliary variable to buffer tissue N2 pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
459 static float calc_pres_tissue_He; // auxiliary variable to buffer tissue He pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
460 static float pres_tissue; // auxiliary variable to buffer total tissue pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
461 static float old_pres_respiration; // auxiliary variable to buffer sim_pres_respiration
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
462
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
463
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
464 // Performance Profiling (4 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
465
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
466 static unsigned short profiling_runtime; // performance measurement: runtime of current invocation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
467 static unsigned char profiling_runs; // performance measurement: invocations per deco calculation cycle
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
468 static unsigned char profiling_phase; // performance measurement: current calculation phase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
469
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
470
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
471 // 255 byte used, 1 byte left in this bank (4 bytes per float, 2 bytes per short, 1 byte per char)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
472
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
473
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
474 //---- Bank 6 parameters -----------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
475 #ifndef UNIX
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
476 # pragma udata bank6=0x600
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
477 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
478
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
479 // Timer5 Interface (3 byte) - Attention: keep order and keep at beginning of bank 6, i.e. at address 0x600 !
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
480
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
481 static volatile unsigned short tmr5_value; // timer 5 value buffer MUST be at address 0x600
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
482 static volatile unsigned char tmr5_overflow; // timer 5 overflow flag MUST be at address 0x602
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
483
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
484
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
485 // Modes, Sequencing and Indexing (11 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
486
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
487 static unsigned char main_status; // shadow register for char_O_main_status
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
488 static unsigned char deco_status; // shadow register for char_O_deco_status
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
489 static unsigned char deco_info; // shadow register for char_O_deco_info
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
490 static unsigned char deco_warnings; // shadow register for char_O_deco_warnings
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
491 static unsigned char next_planning_phase; // next calculation phase to be executed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
492 static unsigned char tissue_increment; // selector for real/simulated tissues and time increment
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
493 static unsigned char sequence_timer; // timer to sequence deco engine tasks
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
494 static unsigned char ci; // index to the Buhlmann tables (compartment index)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
495 static unsigned char cns_i; // index to the CNS tables (ppO2 range index)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
496 static unsigned char i; // general purpose loop counter and index
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
497 static unsigned char fast; // selects 1 minute or 2 second ascent steps
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
498
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
499
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
500 // Result Values from Calculation Functions (28 byte)
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
501
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
502 static float O2_ppO2; // ppO2 - calculated for pure oxygen at current depth
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
503 static float OC_ppO2; // ppO2 - calculated for breathing in OC mode
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
504 static float pSCR_ppO2; // ppO2 - calculated for breathing in pSCR mode
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
505
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
506 static float ppO2; // partial pressure of breathed oxygen
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
507 static float ppN2; // partial pressure of breathed nitrogen
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
508 static float ppHe; // partial pressure of breathed helium
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
509
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
510 static unsigned char char_ppO2; // partial pressure of breathed oxygen, as integer 100 = 1.00 bar
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
511 static unsigned char NDL_time; // time in minutes until reaching NDL
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
512 static unsigned short ascent_time; // time in minutes needed for the ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
513
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
514
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
515 // Buhlmann Model Parameters (40 byte)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
516
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
517 static float var_N2_a; // Buhlmann a, for current N2 tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
518 static float var_N2_b; // Buhlmann b, for current N2 tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
519 static float var_He_a; // Buhlmann a, for current He tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
520 static float var_He_b; // Buhlmann b, for current He tissue
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
521 static float var_a; // Buhlmann a, adopted to current N2/He ratio
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
522 static float var_b; // Buhlmann b, adopted to current N2/He ratio
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
523 static float var_N2_e; // exposition, for current N2 tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
524 static float var_He_e; // exposition, for current He tissue
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
525 static float var_N2_ht; // half-time, for current N2 tissue
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
526 static float var_He_ht; // half-time, for current He tissue
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
527
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
528
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
529 // Vault to back-up & restore Tissue related Data (134 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
530
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
531 static float vault_pres_tissue_N2[NUM_COMP]; // stores the nitrogen tissue pressures
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
532 static float vault_pres_tissue_He[NUM_COMP]; // stores the helium tissue pressures
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
533 static float vault_CNS_fraction_real; // stores current CNS (float representation)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
534 static unsigned char vault_deco_warnings; // stores warnings status
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
535 static unsigned char vault_deco_info; // stores info status
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
536
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
537
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
538 // 7 byte occupied by compiler-placed vars
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
539
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
540
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
541 // 223 byte used, 33 byte left in this bank (4 bytes per float, 2 bytes per short, 1 byte per char)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
542
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
543
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
544
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
545 //---- Bank 12 parameters -----------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
546 #ifndef UNIX
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
547 # pragma udata bank12=0xc00
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
548 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
549
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
550 // stops table (96 byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
551
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
552 static unsigned char internal_deco_depth[NUM_STOPS]; // depths of the stops in meters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
553 static unsigned char internal_deco_time[NUM_STOPS]; // durations of the stops in minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
554 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
555
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
556
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
557 // 96 byte used, 160 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
558
0
heinrichsweikamp
parents:
diff changeset
559
heinrichsweikamp
parents:
diff changeset
560 //---- Bank 7 parameters -----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
561 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
562 # pragma udata bank7=0x700
heinrichsweikamp
parents:
diff changeset
563 #endif
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
564
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
565 // 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
566
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
567 static float real_pres_tissue_N2[NUM_COMP]; // 16 floats = 64 bytes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
568 static float real_pres_tissue_He[NUM_COMP]; // 16 floats = 64 bytes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
569
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
570 static float sim_pres_tissue_N2[NUM_COMP]; // 16 floats = 64 bytes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
571 static float sim_pres_tissue_He[NUM_COMP]; // 16 floats = 64 bytes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
572
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
573 // 256 byte used, bank is full
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
574
0
heinrichsweikamp
parents:
diff changeset
575
heinrichsweikamp
parents:
diff changeset
576 //---- Bank 8 parameters -----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
577 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
578 # pragma udata overlay bank8=0x800
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
579
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
580 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
581
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
582 # define C_STACK md_pi_subst
0
heinrichsweikamp
parents:
diff changeset
583 #endif
heinrichsweikamp
parents:
diff changeset
584
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
585
0
heinrichsweikamp
parents:
diff changeset
586 // Back to bank6 for further tmp data
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
587 // Do not delete this assignment, it is needed by the compiler/linker.
0
heinrichsweikamp
parents:
diff changeset
588 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
589 # pragma udata bank6
heinrichsweikamp
parents:
diff changeset
590 #endif
heinrichsweikamp
parents:
diff changeset
591
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
592
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
593 // *********************************************************************************************************************************
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
594 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
595 // 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
596 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
597 // *********************************************************************************************************************************
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
598
0
heinrichsweikamp
parents:
diff changeset
599 #ifndef UNIX
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
600 # pragma romdata CNS_tables = 0x1DC80 // needs to be in the UPPER bank
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
601 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
602
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
603 rom const float CNS_ab[2*11] = {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
604 // CNS increment per 2sec = 1 / (a*ppO2 + b) with ppO2 in [cbar]
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
605 // a b for ppO2 cbar range
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
606 -533.07, 54000, // 51 - 60 (index 0)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
607 -444.22, 48600, // 61 - 70 (index 1)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
608 -355.38, 42300, // 71 - 80 (index 2)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
609 -266.53, 35100, // 81 - 90 (index 3)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
610 -177.69, 27000, // 91 - 100 (index 4)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
611 -177.69, 27000, // 101 - 110 (index 5)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
612 -88.84, 17100, // 111 - 120 (index 6)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
613 -88.84, 17100, // 121 - 130 (index 7)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
614 -88.84, 17100, // 131 - 140 (index 8)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
615 -88.84, 17100, // 141 - 150 (index 9)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
616 -222.11, 37350 // 151 - 160 (index 10)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
617 };
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
618
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
619 rom const unsigned short CNS_c[1*20] = {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
620 // CNS increment per 2sec = c / 100000.0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
621 // c in [1/100000] for ppO2 cbar range
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
622 75, // 161 - 165 (index 0)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
623 102, // 166 - 170 (index 1)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
624 136, // 171 - 175 (index 2)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
625 180, // 176 - 180 (index 3)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
626 237, // 181 - 185 (index 4)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
627 310, // 186 - 190 (index 5)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
628 401, // 191 - 195 (index 6)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
629 517, // 196 - 200 (index 7)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
630 760, // 201 - 205 (index 8)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
631 1100, // 206 - 210 (index 9)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
632 1500, // 211 - 215 (index 10)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
633 2090, // 216 - 220 (index 11)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
634 2900, // 221 - 225 (index 12)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
635 3900, // 226 - 230 (index 13)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
636 4820, // 231 - 235 (index 14)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
637 4820, // 236 - 240 (index 15)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
638 4820, // 241 - 245 (index 16)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
639 4820, // 246 - 250 (index 17)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
640 4820, // 251 - 255 (index 18)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
641 0 // not used, just to fill up the memory block
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
642 };
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
643
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
644
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
645 #ifndef UNIX
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
646 # pragma romdata Buhlmann_tables = 0x1DD00 // needs to be in the UPPER bank
0
heinrichsweikamp
parents:
diff changeset
647 #endif
heinrichsweikamp
parents:
diff changeset
648
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
649 rom const float Buhlmann_ab[4*16] = {
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
650 // Data ZH-L16C, from Bühlmann Tauchmedizin 2002, option 1a (4mn)
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
651 // a for N2 b for N2 a of He b for He
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
652 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
653 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
654 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
655 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
656 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
657 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
658 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
659 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
660 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
661 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
662 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
663 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
664 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
665 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
666 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
667 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
668 };
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
669
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
670 rom const float Buhlmann_ht[2*16] = {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
671 // Compartment half-life, in minute
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
672 //--- N2 ---- He ----------------------
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
673 4.0, 1.51,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
674 8.0, 3.02,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
675 12.5, 4.72,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
676 18.5, 6.99,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
677 27.0, 10.21,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
678 38.3, 14.48,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
679 54.3, 20.53,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
680 77.0, 29.11,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
681 109.0, 41.20,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
682 146.0, 55.19,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
683 187.0, 70.69,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
684 239.0, 90.34,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
685 305.0, 115.29,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
686 390.0, 147.42,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
687 498.0, 188.24,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
688 635.0, 240.03
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
689 };
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
690
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
691 rom const float e2secs[2*16] = {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
692 // result of 1 - 2^(-1/(2sec*HT))
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
693 //---- N2 ------------- He ------------
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
694 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
695 2.88395E-03, 7.62144E-03,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
696 1.84669E-03, 4.88315E-03,
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
697 1.24813E-03, 3.29997E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
698 8.55371E-04, 2.26041E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
699 6.03079E-04, 1.59437E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
700 4.25414E-04, 1.12479E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
701 3.00019E-04, 7.93395E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
702 2.11949E-04, 5.60641E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
703 1.58240E-04, 4.18555E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
704 1.23548E-04, 3.26795E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
705 9.66686E-05, 2.55722E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
706 7.57509E-05, 2.00387E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
707 5.92416E-05, 1.56716E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
708 4.63943E-05, 1.22734E-04,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
709 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
710 //-------------------------------------
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
711 };
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
712
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
713 rom const float e1min[2*16] = {
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
714 // Integration constant for 1 minute,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
715 // Ie. 1- 2^(-1/HT)
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
716 //----- N2 --------- e 1min He --------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
717 1.59104E-01, 3.68109E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
718 8.29960E-02, 2.05084E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
719 5.39424E-02, 1.36579E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
720 3.67742E-02, 9.44046E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
721 2.53454E-02, 6.56359E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
722 1.79351E-02, 4.67416E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
723 1.26840E-02, 3.31991E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
724 8.96152E-03, 2.35301E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
725 6.33897E-03, 1.66832E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
726 4.73633E-03, 1.24808E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
727 3.69981E-03, 9.75753E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
728 2.89600E-03, 7.64329E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
729 2.27003E-03, 5.99417E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
730 1.77572E-03, 4.69082E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
731 1.39089E-03, 3.67548E-03,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
732 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
733 //-------------------------------------
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
734 };
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
735
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
736 rom const float e10min[2*16] = {
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
737 // The 10 min Value in float notation:
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
738 // result of 1 - 2^(-10/ht)
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
739 //---- N2 -------------- He -----------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
740 8.23223E-01, 9.89851E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
741 5.79552E-01, 8.99258E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
742 4.25651E-01, 7.69737E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
743 3.12487E-01, 6.29027E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
744 2.26416E-01, 4.92821E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
745 1.65547E-01, 3.80407E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
746 1.19840E-01, 2.86538E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
747 8.60863E-02, 2.11886E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
748 6.16117E-02, 1.54849E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
749 4.63665E-02, 1.18026E-01,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
750 3.63881E-02, 9.34005E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
751 2.85855E-02, 7.38569E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
752 2.24698E-02, 5.83504E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
753 1.76160E-02, 4.59303E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
754 1.38222E-02, 3.61528E-02,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
755 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
756 //-------------------------------------
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
757 };
0
heinrichsweikamp
parents:
diff changeset
758
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
759
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
760 // *********************************************************************************************************************************
0
heinrichsweikamp
parents:
diff changeset
761 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
762 // 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
763 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
764 // *********************************************************************************************************************************
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
765
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
766
0
heinrichsweikamp
parents:
diff changeset
767 // moved from 0x0D000 to 0x0C000 in v.108
heinrichsweikamp
parents:
diff changeset
768 #ifndef UNIX
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
769 # pragma code p2_deco = 0x0C000
0
heinrichsweikamp
parents:
diff changeset
770 #endif
heinrichsweikamp
parents:
diff changeset
771
heinrichsweikamp
parents:
diff changeset
772
heinrichsweikamp
parents:
diff changeset
773 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
774 // Bump to blue-screen when an assert is wrong
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
775 #ifdef _DEBUG
0
heinrichsweikamp
parents:
diff changeset
776 void assert_failed(PARAMETER short int line)
heinrichsweikamp
parents:
diff changeset
777 {
heinrichsweikamp
parents:
diff changeset
778 }
heinrichsweikamp
parents:
diff changeset
779 #endif
heinrichsweikamp
parents:
diff changeset
780
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
781
0
heinrichsweikamp
parents:
diff changeset
782 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
783 // When calling C code from ASM context, the data stack pointer and
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
784 // frames should be reset. Bank 8 is used by stack.
0
heinrichsweikamp
parents:
diff changeset
785
heinrichsweikamp
parents:
diff changeset
786 #ifdef CROSS_COMPILE
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
787 # define RESET_C_STACK
0
heinrichsweikamp
parents:
diff changeset
788 #else
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
789 # ifdef _DEBUG
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
790 # define RESET_C_STACK fillDataStack();
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
791 void fillDataStack(void)
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
792 {
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
793 _asm
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
794 LFSR 1,C_STACK
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
795 MOVLW 0xCC
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
796 loop: MOVWF POSTINC1,0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
797 TSTFSZ FSR1L,0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
798 BRA loop
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
799
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
800 LFSR 1,C_STACK
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
801 LFSR 2,C_STACK
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
802 _endasm
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
803 }
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
804 # else
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
805 # define RESET_C_STACK \
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
806 _asm \
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
807 LFSR 1,C_STACK \
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
808 LFSR 2,C_STACK \
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
809 _endasm
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
810 # endif
0
heinrichsweikamp
parents:
diff changeset
811 #endif
heinrichsweikamp
parents:
diff changeset
812
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
813
0
heinrichsweikamp
parents:
diff changeset
814 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
815 // Reset timer 5
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
816 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
817 // 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
818 // and will be written to TMR5 together with a successive write to TMR5L.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
819 // 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
820 // the bank-save "movff" command, or address mapping via access bank (",0").
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
821 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
822 static void load_tmr5(void)
0
heinrichsweikamp
parents:
diff changeset
823 {
heinrichsweikamp
parents:
diff changeset
824 #ifndef CROSS_COMPILE
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
825 _asm
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
826 movff 0x601,0xF7D // bank-safe load TMR5H from C variable tmr5_value first
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
827 movff 0x600,0xF7C // bank-safe load TMR5L from c variable tmr5_value thereafter
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
828 bcf 0xFBA,1,0 // clear timer 5 overrun flag (0xFBA = PIR5, bit 1 = TMR5IF)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
829 _endasm
0
heinrichsweikamp
parents:
diff changeset
830 #else
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
831 return;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
832 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
833 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
834
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
835
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
836 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
837 // Read timer 5
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
838 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
839 // 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
840 // TMR5 is configured in 16 bit mode: on reading of TMR5L the contents of
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
841 // TMR5H is latched and can be read afterwards without potential rollover.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
842 // 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
843 // the bank-save "movff" command, or address mapping via access bank (",0").
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
844 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
845 static void read_tmr5(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
846 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
847 #ifndef CROSS_COMPILE
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
848 _asm
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
849 movff 0xF7C,0x600 // copy TMR5L to C variable tmr5_value, low byte first
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
850 movff 0xF7D,0x601 // copy TMR5H to C variable tmr5_value, high byte thereafter
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
851 clrf WREG,0 // clear WREG to 0x00 = no overrun by default
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
852 btfsc 0xFBA,1,0 // did timer 5 overrun? (0xFBA = PIR5, bit 1 = TMR5IF)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
853 setf WREG,0 // YES - set WREG to 0xff = overrun detected
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
854 movff WREG,0x602 // copy WREG to C variable tmr5_overflow
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
855 _endasm
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
856 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
857 return;
0
heinrichsweikamp
parents:
diff changeset
858 #endif
heinrichsweikamp
parents:
diff changeset
859 }
heinrichsweikamp
parents:
diff changeset
860
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
861
0
heinrichsweikamp
parents:
diff changeset
862 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
863 // Read CNS coefficients a and b
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
864 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
865 static void read_CNS_ab_coefficient(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
866 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
867 #ifndef CROSS_COMPILE
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
868 // Note: We don't use far ROM pointer, because handling
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
869 // 24 bit is to complex, hence we have to set the
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
870 // UPPER page ourself...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
871 // -> set to zero if tables are moved to lower pages!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
872 _asm
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
873 movlw 1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
874 movwf TBLPTRU,0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
875 _endasm
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
876 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
877
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
878 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
879 overlay rom const float* ptr = &CNS_ab[2*cns_i];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
880 var_cns_a = *ptr++;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
881 var_cns_b = *ptr++;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
882 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
883 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
884
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
885
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
886 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
887 // Read CNS coefficient c
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
888 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
889 static void read_CNS_c_coefficient(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
890 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
891 #ifndef CROSS_COMPILE
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
892 // Note: We don't use far ROM pointer, because handling
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
893 // 24 bit is to complex, hence we have to set the
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
894 // UPPER page ourself...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
895 // -> set to zero if tables are moved to lower pages!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
896 _asm
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
897 movlw 1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
898 movwf TBLPTRU,0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
899 _endasm
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
900 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
901
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
902 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
903 overlay rom const unsigned short* ptr = &CNS_c[cns_i];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
904 var_cns_c = *ptr++;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
905 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
906 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
907
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
908 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
909 // Read Buhlmann coefficients a and b for compartment ci
0
heinrichsweikamp
parents:
diff changeset
910 //
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
911 static void read_Buhlmann_coefficients(void)
0
heinrichsweikamp
parents:
diff changeset
912 {
heinrichsweikamp
parents:
diff changeset
913 #ifndef CROSS_COMPILE
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
914 // 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
915 // 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
916 // UPPER page ourself...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
917 // -> Set to zero if tables are moved to lower pages!
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
918 _asm
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
919 movlw 1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
920 movwf TBLPTRU,0
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
921 _endasm
0
heinrichsweikamp
parents:
diff changeset
922 #endif
heinrichsweikamp
parents:
diff changeset
923
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
924 assert( ci < NUM_COMP );
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
925
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
926 // use an interleaved array (AoS) to access coefficients with a single addressing
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
927 {
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
928 overlay rom const float* ptr = &Buhlmann_ab[4*ci];
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
929 var_N2_a = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
930 var_N2_b = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
931 var_He_a = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
932 var_He_b = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
933 }
0
heinrichsweikamp
parents:
diff changeset
934 }
heinrichsweikamp
parents:
diff changeset
935
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
936
0
heinrichsweikamp
parents:
diff changeset
937 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
938 // Read Buhlmann increments for compartment ci
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
939 // If period == 0 : 2 sec interval
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
940 // 1 : 1 min interval
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
941 // 2 : 10 min interval
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
942 static void read_Buhlmann_times(PARAMETER char period)
0
heinrichsweikamp
parents:
diff changeset
943 {
heinrichsweikamp
parents:
diff changeset
944 #ifndef CROSS_COMPILE
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
945 // 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
946 // 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
947 // UPPER page ourself...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
948 // -> set to zero if tables are moved to lower pages!
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
949 _asm
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
950 movlw 1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
951 movwf TBLPTRU,0
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
952 _endasm
0
heinrichsweikamp
parents:
diff changeset
953 #endif
heinrichsweikamp
parents:
diff changeset
954
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
955 assert( ci < NUM_COMP );
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
956
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
957 // Integration Intervals
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
958 switch(period)
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
959 {
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
960 case 0: //---- 2 sec -----------------------------------------------------
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
961 {
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
962 overlay rom const float* ptr = &e2secs[2*ci];
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
963 var_N2_e = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
964 var_He_e = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
965 }
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
966 break;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
967
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
968 case 1: //---- 1 min -----------------------------------------------------
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
969 {
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
970 overlay rom const float* ptr = &e1min[2*ci];
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
971 var_N2_e = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
972 var_He_e = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
973 }
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
974 break;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
975
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
976 case 2: //---- 10 min ----------------------------------------------------
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
977 {
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
978 overlay rom const float* ptr = &e10min[2*ci];
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
979 var_N2_e = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
980 var_He_e = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
981 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
982 break;
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
983
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
984 default:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
985 assert(0); // code execution shall never pass along here!
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
986 }
0
heinrichsweikamp
parents:
diff changeset
987 }
heinrichsweikamp
parents:
diff changeset
988
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
989
0
heinrichsweikamp
parents:
diff changeset
990 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
991 // Read Buhlmann half-times for compartment ci
0
heinrichsweikamp
parents:
diff changeset
992 //
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
993 static void read_Buhlmann_ht(void)
0
heinrichsweikamp
parents:
diff changeset
994 {
heinrichsweikamp
parents:
diff changeset
995
heinrichsweikamp
parents:
diff changeset
996 #ifndef CROSS_COMPILE
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
997 // 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
998 // 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
999 // UPPER page ourself...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1000 // -> Set to zero if tables are moved to lower pages!
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1001 _asm
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1002 movlw 1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1003 movwf TBLPTRU,0
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1004 _endasm
0
heinrichsweikamp
parents:
diff changeset
1005 #endif
heinrichsweikamp
parents:
diff changeset
1006
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1007 assert( ci < NUM_COMP );
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1008 {
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1009 overlay rom const float* ptr = &Buhlmann_ht[2*ci];
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1010 var_N2_ht = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1011 var_He_ht = *ptr++;
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1012 }
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1013
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1014 assert( 4.0 <= var_N2_ht && var_N2_ht <= 635.0 );
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
1015 assert( 1.5099 <= var_He_ht && var_He_ht <= 240.03 );
0
heinrichsweikamp
parents:
diff changeset
1016 }
heinrichsweikamp
parents:
diff changeset
1017
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1018
0
heinrichsweikamp
parents:
diff changeset
1019 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1020 // Calculate adopted Buhlmann coefficients
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1021 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1022 // Input: var_N2_a, var_N2_b coefficients for N2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1023 // var_He_a, var_He_b coefficients for He
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1024 // calc_pres_tissue_N2 partial pressure of N2 in tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1025 // calc_pres_tissue_He partial pressure of He in tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1026 // pres_tissue total pressure in tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1027 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1028 // 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
1029 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1030 static void adopt_Buhlmann_coefficients(void)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1031 {
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1032 // adopt a and b coefficients to current N2/He ratio inside the tissue
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1033
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1034 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1035
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1036 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
1037 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
1038
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1039 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1040
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1041 var_a = var_N2_a;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1042 var_b = var_N2_b;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1043
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1044 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1045
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1046 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1047
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1048
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1049 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1050 // Calculate partial pressure of N2 in respired air at surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1051 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1052 // Input: pres_surface surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1053 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1054 // Output: N2_equilibrium partial pressure of N2 in surface air
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1055 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1056 static void calc_N2_equilibrium(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1057 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1058 N2_equilibrium = 0.7902 * (pres_surface - ppWater);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1059 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1060
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1061
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1062 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1063 // Get, safeguard and convert the saturation and desaturation factors
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1064 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1065 // Input: char_I_saturation_multiplier saturation factor (integer)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1066 // char_I_desaturation_multiplier desaturation factor (integer)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1067 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1068 // Output: float_saturation_multiplier saturation factor (float)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1069 // float_desaturation_multiplier desaturation factor (float)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1070 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1071 static void get_saturation_factors(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1072 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1073 // safeguard input parameters that are constant during the course of the dive
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1074 if( char_I_saturation_multiplier < 100 ) char_I_saturation_multiplier = 100;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1075 if( char_I_saturation_multiplier > 140 ) char_I_saturation_multiplier = 140;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1076
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1077 if( char_I_desaturation_multiplier < 60 ) char_I_desaturation_multiplier = 60;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1078 if( char_I_desaturation_multiplier > 100 ) char_I_desaturation_multiplier = 100;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1079
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1080 // convert input parameters to float numbers
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1081 float_saturation_multiplier = 0.01 * char_I_saturation_multiplier;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1082 float_desaturation_multiplier = 0.01 * char_I_desaturation_multiplier;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1083 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1084
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1085
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1086 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1087 // apply_saturation_factors
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1088 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1089 // Apply safety factors for both ZH-L16 models.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1090 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1091 // Modified: temp_tissue safeguarded tissue increment/decrement
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1092 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1093 static void apply_saturation_factors(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1094 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1095 assert( 0.0 < float_desaturation_multiplier && float_desaturation_multiplier <= 1.0 );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1096 assert( 1.0 <= float_saturation_multiplier && float_saturation_multiplier <= 2.0 );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1097
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1098 if ( temp_tissue < 0.0 ) temp_tissue *= float_desaturation_multiplier;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1099 else temp_tissue *= float_saturation_multiplier;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1100 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1101
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1102
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1103 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1104 // convert_float_to_int
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1105 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1106 // 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
1107 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1108 static void convert_float_to_int(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1109 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1110 if ( float_value < 0.005 ) int_value = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1111 else if ( float_value >= 9.985 ) int_value = 999;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1112 else int_value = (unsigned short)(100 * float_value + 0.5);
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 // convert_float_to_char
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1118 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1119 // Converts a float within range 0.0 - 255 into 8 bit integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1120 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1121 static void convert_float_to_char(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1122 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1123 if (float_value < 0.0) char_value = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1124 else if (float_value >= 254.5) char_value = 255;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1125 else char_value = (unsigned char)(float_value + 0.5);
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1126 }
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1127
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1128
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1129 // *********************************************************************************************************************************
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1130 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1131 // 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
1132 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1133 // *********************************************************************************************************************************
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1134
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1135
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1136 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1137 // deco_calc_hauptroutine
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1138 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1139 // called from: divemode.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1140 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1141 // Called every second during diving,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1142 // updates tissues on every second invocation.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1143 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1144 // Every few seconds (or slower when TTS > 16):
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1145 // - Updates deco table (char_O_deco_time/depth) with new values,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1146 // - updates ascent time, and
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1147 // - sets status to zero (so we can check there is new results).
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1148 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1149 void deco_calc_hauptroutine(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1150 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1151 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1152 calc_hauptroutine();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1153 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1154
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1155
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1156 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1157 // deco_init_output_vars
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1158 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1159 // called from divemode.asm
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1160 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1161 // Initializes all output variables to their default values.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1162 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1163 void deco_init_output_vars(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1164 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1165 RESET_C_STACK
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1166 init_output_vars();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1167 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1168
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1169 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1170 // deco_clear_tissue
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1171 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1172 // called from: start.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1173 // menu_tree.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1174 // simulator.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1175 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1176 // Sets all tissues to equilibrium with Air at ambient pressure,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1177 // resets all CNS values, any warnings and resets all model output.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1178 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1179 void deco_clear_tissue(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1180 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1181 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1182 clear_tissue();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1183 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1184
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1185
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1186 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1187 // deco_calc_dive_interval
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1188 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1189 // called from: simulator.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1190 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1191 // Updates tissues and CNS value for char_I_dive_interval minutes on air
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1192 // at ambient pressure and calculates resulting GF factor and ceiling for
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1193 // a GF-high of 100% (ceiling and GF factor not used by simulator.asm)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1194 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1195 void deco_calc_dive_interval(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1196 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1197 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1198 calc_interval(char_I_dive_interval);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1199 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1200
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1201
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1202 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1203 // deco_calc_dive_interval_1min
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1204 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1205 // called from: start.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1206 // sleepmode.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1207 // surfmode.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1208 // menu_tree.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1209 // ghostwriter.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1210 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1211 // Updates tissues and CNS value for 1 minute on air at ambient pressure and
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1212 // calculates resulting GF factor and ceiling for a GF-high of 100% (ceiling
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1213 // is not used by *.asm files).
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1214 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1215 void deco_calc_dive_interval_1min(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1216 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1217 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1218 calc_interval(1);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1219 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1220
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1221
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1222 //////////////////////////////////////////////////////////////////////////////
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1223 // deco_calc_dive_interval_10min
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1224 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1225 // called from: sleepmode.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1226 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1227 // Updates tissues and CNS value for 10 minutes on air at ambient pressure and
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1228 // calculates resulting GF factor and ceiling for a GF-high of 100% (ceiling
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1229 // is not used by sleepmode.asm).
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1230 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1231 void deco_calc_dive_interval_10min(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1232 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1233 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1234 calc_interval(10);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1235 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1236
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1237
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1238 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1239 // deco_calc_desaturation_time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1240 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1241 // called from: start.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1242 // surfmode.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1243 // menu_tree.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1244 // ghostwriter.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1245 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1246 // Computes desaturation and no-fly times.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1247 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1248 void deco_calc_desaturation_time(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1249 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1250 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1251 calc_desaturation_time();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1252 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1253
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1254
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1255 //////////////////////////////////////////////////////////////////////////////
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1256 // deco_push_tissues_to_vault
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1257 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1258 // called from: simulator.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1259 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1260 // 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
1261 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1262 void deco_push_tissues_to_vault(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1263 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1264 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1265 push_tissues_to_vault();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1266 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1267
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1268
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 // deco_pull_tissues_from_vault
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1271 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1272 // called from: simulator.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1273 // ghostwriter.asm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1274 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1275 // 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
1276 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1277 void deco_pull_tissues_from_vault(void)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1278 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1279 RESET_C_STACK
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1280 pull_tissues_from_vault();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1281 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1282
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1283
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1284 // *********************************************************************************************************************************
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1285 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1286 // 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
1287 //
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1288 // *********************************************************************************************************************************
582
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 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1292 // find_next_stop
0
heinrichsweikamp
parents:
diff changeset
1293 //
heinrichsweikamp
parents:
diff changeset
1294 // INPUT, fixed during dive:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1295 // pres_surface : surface pressure (as absolute pressure)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1296 // char_I_depth_last_deco : depth of the last deco stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1297 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1298 // INPUT, changing during dive:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1299 // float_depth_real : current real depth in meters (float)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1300 // char_depth_real : current real depth in meters (integer)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1301 // GF_high : GF high factor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1302 // GF_low : GF low factor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1303 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1304 // INPUT & OUTPUT
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1305 // char_depth_sim : simulated depth in meters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1306 // GF_low_depth : GF low depth in current calculation cycle
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1307 // GF_slope : GF slope in current calculation cycle
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1308 // GF_low_depth_norm/_alt : frozen GF low depth reference
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1309 // GF_slope_norm/_alt : frozen GF slope
0
heinrichsweikamp
parents:
diff changeset
1310 //
heinrichsweikamp
parents:
diff changeset
1311 // OUTPUT
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1312 // char_depth_last : depth we came from
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1313 // sim_pres_respiration : simulated depth in absolute pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1314 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1315 // RETURN
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1316 // TRUE: a stop is needed, FALSE: no stop needed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1317 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1318 static unsigned char find_next_stop(void)
0
heinrichsweikamp
parents:
diff changeset
1319 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1320 overlay unsigned char depth_1min;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1321 overlay unsigned char depth_limit;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1322 overlay unsigned char first_stop;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1323 overlay unsigned char need_stop;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1324
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1325
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1326 // -----------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1327 // we start with the assumption that a stop is not required
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1328 // -----------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1329
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1330 need_stop = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1331
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1332 // remember the depth we came from
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1333 char_depth_last = char_depth_sim;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1334
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1335 // calculate the limit for the current depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1336 if( char_I_deco_model == 0 ) calc_limit(1.0); // straight Buhlmann
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1337 else if( char_depth_sim >= GF_low_depth ) calc_limit(GF_low); // with GF, below low depth reference
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1338 else calc_limit(GF_high - GF_slope * (float)char_depth_sim); // with GF, above low depth reference
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1339
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1340 // check if we can surface directly
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1341 if( ceiling <= 0.0 )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1342 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1343 // YES - ascent to surface is allowed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1344 char_depth_sim = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1345
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1346 // - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1347 goto done;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1348 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1349
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1350 // -----------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1351 // a stop is required, but maybe not yet within the running minute
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1352 // -----------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1353
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1354 // convert the depth we can ascent to from relative pressure to meters,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1355 // rounded up (i.e. made deeper) to next full meter.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1356 depth_limit = (unsigned char)(ceiling * BAR_TO_METER + 0.99);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1357
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1358 // calculate the stop depth, i.e. round up to the next multiple of 3 meters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1359 // using integer arithmetics
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1360 first_stop = 3 * ( (depth_limit + 2) / 3 );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1361
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1362 // apply correction for the shallowest stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1363 if( first_stop == 3 ) first_stop = char_I_depth_last_deco;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1364
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1365 // compute depth in meters that will be reached in 1 minute of ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1366 // at a speed of char_I_ascent_speed (5..10 m/min)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1367 if( char_depth_sim > char_I_ascent_speed )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1368 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1369 depth_1min = char_depth_sim - char_I_ascent_speed;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1370 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1371 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1372 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1373 depth_1min = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1374 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1375
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1376 // is the stop shallower than the depth that can be reached within 1 minute?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1377 if( depth_1min > first_stop )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1378 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1379 // YES - report the depth that will be reached within 1 minute of ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1380 char_depth_sim = depth_1min;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1381
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1382 // - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1383 goto done;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1384 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1385
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1386 // -----------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1387 // we need to make a stop now
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1388 // -----------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1389
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1390 // set stop data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1391 need_stop = 1;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1392 char_depth_sim = first_stop;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1393
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1394 // done so far if using straight Buhlmann
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1395 if( char_I_deco_model == 0 ) goto done;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1396
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1397 // -----------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1398 // we need to make a stop now and we are using the GF extension
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1399 // -----------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1400
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1401 // is the depth limit deeper than the GF low depth reference used up to now?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1402 if( depth_limit > GF_low_depth )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1403 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1404 // YES - update the reference
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1405 GF_low_depth = depth_limit;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1406 GF_slope = (GF_high - GF_low) / (float)GF_low_depth;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1407
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1408 // store for use in next cycles
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1409 if( deco_status & CALC_NORM )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1410 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1411 GF_low_depth_norm = GF_low_depth;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1412 GF_slope_norm = GF_slope;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1413 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1414 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1415 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1416 GF_low_depth_alt = GF_low_depth;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1417 GF_slope_alt = GF_slope;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1418 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1419 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1420
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1421 // keep the stop as it is when it is the first stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1422 // (i.e. there are no stops in the stops table yet)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1423 if( internal_deco_depth[0] == 0 ) goto done;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1424
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1425 // keep the stop as it is when extended stops are activated
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1426 if( main_status & EXTENDED_STOPS ) goto done;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1427
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1428 // We have a (first) stop. But with a steep GF slope, the stop(s) after this
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1429 // first stop may be allowed to ascent to, too. This is because the gradient
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1430 // factor that will be used at the next depth(s) will allow more tissue super-
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1431 // saturation, maybe so much more that the next stop(s) will be allowed to
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1432 // ascent to. So we have to probe the next stops that are within the reach of
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1433 // 1 minute of ascent as well.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1434
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1435 // no need to probe for a stop that is beyond 1 minute of ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1436 while( first_stop >= (depth_1min + 3) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1437 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1438 overlay unsigned char next_stop;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1439
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1440 // compute the depth of the next stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1441 if ( first_stop <= char_I_depth_last_deco ) next_stop = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1442 else if ( first_stop == 6 ) next_stop = char_I_depth_last_deco;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1443 else next_stop = first_stop - 3;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1444
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1445 // compute the depth limit at the next stop depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1446 calc_limit(GF_high - GF_slope * (float)next_stop);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1447
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1448 // check if ascent to the next stop is allowed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1449 if( next_stop < (unsigned char)(ceiling * BAR_TO_METER + 0.99) )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1450 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1451 // NO - the next stop would be too shallow
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1452 break;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1453 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1454 else
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1455 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1456 // YES - the next stop is allowed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1457 char_depth_sim = next_stop;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1458
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1459 // - ascent to next stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1460 first_stop = next_stop;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1461
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1462 // - loop to probe the stop following next
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1463 continue;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1464 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1465 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1466
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1467
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1468 // -----------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1469 // common end for straight Buhlmann and Buhlmann with GF extension
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1470 // -----------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1471
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1472 done:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1473
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1474 // calculate absolute pressure at the depth found
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1475 sim_pres_respiration = char_depth_sim * METER_TO_BAR + pres_surface;
0
heinrichsweikamp
parents:
diff changeset
1476
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1477 return need_stop;
0
heinrichsweikamp
parents:
diff changeset
1478 }
heinrichsweikamp
parents:
diff changeset
1479
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1480
0
heinrichsweikamp
parents:
diff changeset
1481 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1482 // publish_deco_table
0
heinrichsweikamp
parents:
diff changeset
1483 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1484 // Input: internal_deco_depth[] depth in internal stops table
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1485 // internal_deco_time[] times ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1486 // internal_deco_gas[] gases ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1487 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1488 // Output: char_O_deco_depth[] depth in the external stops table
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1489 // char_O_deco_time[] times ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1490 // char_O_deco_gas[] gases ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1491 // char_O_deco_time_for_log times in reverse order
0
heinrichsweikamp
parents:
diff changeset
1492 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1493 static void publish_deco_table(void)
0
heinrichsweikamp
parents:
diff changeset
1494 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1495 overlay unsigned char x = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1496 overlay unsigned char y;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1497
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1498
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1499 // copy all entries from internal to external stops table
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1500 for( y = 0; y < NUM_STOPS; y++ )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1501 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1502 // remember index of last entry with a non-null depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1503 if( internal_deco_depth[y] > 0 ) x = y;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1504
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1505 // copy depth, time and gas
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1506 char_O_deco_depth[y] = internal_deco_depth[y];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1507 char_O_deco_time [y] = internal_deco_time [y];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1508 char_O_deco_gas [y] = internal_deco_gas [y];
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1509 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1510
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1511
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1512 // copy times of shallowest stops to logging table
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1513 for( y = 0; y < NUM_STOPS_LOG; y++, --x )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1514 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1515 char_O_deco_time_for_log[y] = internal_deco_time [x];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1516
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1517 // stop when all entries are copied
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1518 if( x == 0 ) break;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1519 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1520
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1521 // fill the remainder of the logging table with null
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1522 // if it is not completely filled already
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1523 for( y++; y < NUM_STOPS_LOG; y++ )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1524 char_O_deco_time_for_log[y] = 0;
0
heinrichsweikamp
parents:
diff changeset
1525 }
heinrichsweikamp
parents:
diff changeset
1526
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1527
0
heinrichsweikamp
parents:
diff changeset
1528 //////////////////////////////////////////////////////////////////////////////
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1529 // Find current gas in the list (if any) and get its change depth
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1530 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1531 // Input: char_I_current_gas_num number of current gas (1..5 or 6)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1532 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1533 // 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
1534 // 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
1535 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1536 static void gas_find_current(void)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1537 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1538 assert( 1 <= char_I_current_gas_num && char_I_current_gas_num <= 6 );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1539
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1540 if( char_I_current_gas_num <= NUM_GAS ) // gas/diluent 1-5
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1541 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1542 sim_gas_current_num = char_I_current_gas_num;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1543 sim_gas_current_depth = char_I_deco_gas_change[sim_gas_current_num-1];
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1544 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1545 else
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1546 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1547 sim_gas_current_num = 0;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1548 sim_gas_current_depth = char_I_gas6_depth;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1549 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1550 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1551
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1552
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1553 //////////////////////////////////////////////////////////////////////////////
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1554 // Find the deco gas with the shallowest change depth below or at the current depth
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1555 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1556 // Input: char_depth_sim simulated depth in meters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1557 // sim_gas_current_num number of the currently used gas/dil
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1558 // sim_gas_current_depth change depth of the currently used gas/dil
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1559 // char_I_deco_gas_type[] types of the gases/dils
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1560 // char_I_deco_gas_change[] change depths of the gases/dils
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1561 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1562 // Modified: sim_gas_current_num index of the gas (1..5) - only if return value is true
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1563 // sim_gas_current_depth switch depth - only if return value is true
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1564 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1565 // Return value is TRUE if a better gas is available
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1566 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1567 static unsigned char gas_find_better(void)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1568 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1569 overlay unsigned char switch_depth = 255;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1570 overlay unsigned char switch_gas = 0;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1571 overlay unsigned char j;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1572
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1573 // // no automatic gas changes in CCR mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1574 // if( (deco_status & MODE_MASK) == MODE_CCR ) return 0;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1575
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1576 // loop over all deco gases to find the shallowest one below or at current depth
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1577 for( j = 0; j < NUM_GAS; ++j )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1578 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1579 // Is this gas not the one we are already breathing?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1580 if( j+1 != sim_gas_current_num )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1581
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1582 // Is this gas available?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1583 if( char_I_deco_gas_type[j] > 0 )
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1584
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1585 // Is the change depth of the this gas deeper than or
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1586 // at least equal to the current depth?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1587 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
1588
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1589 // Is the change depth of this gas shallower than the
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1590 // change depth of the gas we are currently on?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1591 if( char_I_deco_gas_change[j] < sim_gas_current_depth )
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1592
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1593 // Is the change depth of this gas shallower than the change
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1594 // depth of the best gas found so far, or is it the first
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1595 // better gas found?
587
e81cf407261a V2.97 SP1
heinrichsweikamp
parents: 585
diff changeset
1596 if( char_I_deco_gas_change[j] < switch_depth )
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1597
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1598 // 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
1599 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1600 switch_gas = j+1; // remember this gas (1..5)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1601 switch_depth = char_I_deco_gas_change[j]; // remember its change depth
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1602 }
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1603
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1604 } // continue looping through all gases to eventually find an even better gas
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1605
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1606 // has a better gas been found?
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1607 if( switch_gas )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1608 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1609 // YES - set the better gas as the new gas
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1610 sim_gas_current_num = switch_gas;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1611
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1612 // set its change depth as the last used change depth
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1613 sim_gas_current_depth = switch_depth;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1614
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1615 assert( sim_gas_current_depth < switch_depth );
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1616
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1617 // signal a better gas was found
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1618 return 1;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1619 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1620 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1621 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1622 // NO - signal no better gas was found
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1623 return 0;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1624 }
0
heinrichsweikamp
parents:
diff changeset
1625 }
heinrichsweikamp
parents:
diff changeset
1626
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1627
0
heinrichsweikamp
parents:
diff changeset
1628 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1629 // Set calc_N2/He/O2_ratios by sim_gas_current_num
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1630 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1631 // Input: sim_gas_current_num index of gas to use
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1632 // real_O2_ratio, real_He_ratio if gas = 0 (the manually set gas)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1633 // char_I_deco_O2/He_ratio[] if gas = 1..5 (the configured gases)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1634 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1635 // Output: sim_N2_ratio, sim_He_ratio ratios of the inert gases
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1636 // sim_pSCR_drop ppO2 drop in pSCR loop
0
heinrichsweikamp
parents:
diff changeset
1637 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1638 static void gas_set_ratios(void)
0
heinrichsweikamp
parents:
diff changeset
1639 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1640 overlay float sim_IG_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1641
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1642 assert( 0 <= sim_gas_current_num <= NUM_GAS );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1643
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1644
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1645 #ifdef _helium
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1646 // get gas ratios
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1647 if( sim_gas_current_num == 0 )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1648 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1649 sim_O2_ratio = real_O2_ratio;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1650 sim_He_ratio = real_He_ratio;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1651 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1652 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1653 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1654 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
1655 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
1656 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1657
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1658 // inert gas ratio (local helper variable)
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1659 sim_IG_ratio = 1.00 - sim_O2_ratio;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1660
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1661 // N2 ratio
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1662 sim_N2_ratio = sim_IG_ratio - sim_He_ratio;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1663 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1664 // get O2 ratio
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1665 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
1666
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1667 // set H2 ratio to zero
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1668 sim_He_ratio = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1669
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1670 // inert gas ratio (local helper variable)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1671 sim_IG_ratio = 1.00 - sim_O2_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1672
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1673 // N2 ratio
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1674 sim_N2_ratio = sim_IG_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1675 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1676
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1677 #ifdef _ccr_pscr
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1678 // ppO2 drop in pSCR loop
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1679 sim_pSCR_drop = sim_IG_ratio * float_pSCR_factor;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1680 #endif
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1681
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1682
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1683 assert( 0.0 <= sim_N2_ratio && sim_N2_ratio <= 0.95 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1684 assert( 0.0 <= sim_He_ratio && sim_He_ratio <= 0.95 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1685 assert( (sim_N2_ratio + sim_He_ratio) <= 0.95 );
0
heinrichsweikamp
parents:
diff changeset
1686 }
heinrichsweikamp
parents:
diff changeset
1687
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1688
0
heinrichsweikamp
parents:
diff changeset
1689 //////////////////////////////////////////////////////////////////////////////
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1690 // Compute respired ppO2, ppN2 and ppHe
0
heinrichsweikamp
parents:
diff changeset
1691 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1692 // Input: tissue_increment : selector for targeting simulated or real tissues
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1693 // main_status : breathing mode for real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1694 // deco_status : breathing mode for simulated tissues
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1695 // sim_/real_O2_ratio : (simulated) O2 ratio breathed
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1696 // sim_/real_N2_ratio : (simulated) N2 ratio breathed
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1697 // sim_/real_He_ratio : (simulated) He ratio breathed
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1698 // sim_/real_pres_respiration : (simulated) respiration pressure [bar]
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1699 // sim_/real_pSCR_drop : (simulated) pSCR O2 drop
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1700 // pres_surface : surface pressure [bar]
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1701 // 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
1702 // float_deco_distance : safety factor, additional depth below stop depth [bar]
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1703 // ppWater : water-vapor pressure inside respiratory tract [bar]
0
heinrichsweikamp
parents:
diff changeset
1704 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1705 // Output: ppN2 : respired N2 partial pressure
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1706 // ppHe : respired He partial pressure
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1707 // char_ppO2 : breathed ppO2 in %, used for CNS calculation
0
heinrichsweikamp
parents:
diff changeset
1708 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1709 void calc_alveolar_pressures(void)
0
heinrichsweikamp
parents:
diff changeset
1710 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1711 overlay float calc_pres_respiration;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1712 overlay float calc_O2_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1713 overlay float calc_N2_ratio;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1714
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1715 #ifdef _helium
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1716 overlay float calc_He_ratio;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1717 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1718
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1719 #ifdef _ccr_pscr
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1720 overlay float calc_pSCR_drop;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1721 #endif
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1722
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1723 overlay unsigned char status;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1724
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1725
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1726 assert( 0.00 <= real_N2_ratio && real_N2_ratio <= 1.00 );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1727 assert( 0.00 <= real_He_ratio && real_He_ratio <= 1.00 );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1728 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
1729 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
1730
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1731 assert( 0.00 <= sim_N2_ratio && real_N2_ratio <= 1.00 );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1732 assert( 0.00 <= sim_He_ratio && real_He_ratio <= 1.00 );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1733 assert( (sim_N2_ratio + sim_He_ratio) <= 1.00 );
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1734 assert( 0.800 < sim_pres_respiration && sim_pres_respiration < 14.0 );
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1735
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1736
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1737 // get input data according to context
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1738 if( tissue_increment & TISSUE_SELECTOR )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1739 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1740 //---- real tissues -----------------------------------------------------------
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1741 calc_pres_respiration = real_pres_respiration;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1742
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1743 status = main_status;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1744 calc_O2_ratio = real_O2_ratio;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1745 calc_N2_ratio = real_N2_ratio;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1746
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1747 #ifdef _helium
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1748 calc_He_ratio = real_He_ratio;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1749 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1750
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1751 #ifdef _ccr_pscr
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1752 calc_pSCR_drop = real_pSCR_drop;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1753 #endif
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1754 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1755 else
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1756 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1757 //---- simulated tissues ------------------------------------------------------
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1758
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1759 // correct sim_pres_respiration if shallower than calculated stop depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1760 calc_pres_respiration = ( real_pres_respiration < sim_pres_respiration ) ? real_pres_respiration : sim_pres_respiration;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1761
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1762 status = deco_status;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1763 calc_O2_ratio = sim_O2_ratio;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1764 calc_N2_ratio = sim_N2_ratio;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1765
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1766 #ifdef _helium
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1767 calc_He_ratio = sim_He_ratio;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1768 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1769
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1770 #ifdef _ccr_pscr
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1771 calc_pSCR_drop = sim_pSCR_drop;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1772 #endif
582
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 //---- OC, CCR and Bailout Mode Gas Calculations -----------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1776
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1777 // calculate ppO2 of pure oxygen
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1778 O2_ppO2 = calc_pres_respiration - ppWater;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1779
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1780 // capture failure condition in case real_pres_respiration is < ppWater (should never happen...)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1781 if( O2_ppO2 < 0.0 ) O2_ppO2 = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1782
602
ab88a7e3de94 2.98 release
heinrichsweikamp
parents: 597
diff changeset
1783 // calculate ppO2 of the pure gas (OC, diluent)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1784 OC_ppO2 = O2_ppO2 * calc_O2_ratio;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1785
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1786 #ifdef _ccr_pscr
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1787
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1788 // calculate pSCR ppO2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1789 pSCR_ppO2 = OC_ppO2 - calc_pSCR_drop;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1790
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1791 // capture failure condition in case pSCR_ppO2 becomes negative
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1792 if( pSCR_ppO2 < 0.0 ) pSCR_ppO2 = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1793
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1794
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1795 //---- 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
1796 if( status & MODE_LOOP )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1797 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1798 overlay float const_ppO2;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1799 overlay float max_ppO2;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1800
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1801 // 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
1802 const_ppO2 = 0.01 * char_I_const_ppO2;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1803
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1804 // Limit the setpoint to the maximum physically possible ppO2. This prevents for
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1805 // 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
1806 // Additionally, the ppO2 can be further reduced to account for exhaled inert gases
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1807 // 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
1808 // (ppWater is neglected here)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1809 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
1810
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1811 if( const_ppO2 > max_ppO2 ) const_ppO2 = max_ppO2;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1812
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1813 // check which kind of loop we are on
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1814 if( status & MODE_PSCR )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1815 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1816 //---- pSCR Mode --------------------------------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1817
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1818 // Use the sensor value if available, but only in real tissue context!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1819 // In all other cases use calculated ppO2.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1820 if ( char_I_const_ppO2 && (tissue_increment & TISSUE_SELECTOR)) ppO2 = const_ppO2;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1821 else ppO2 = pSCR_ppO2;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1822 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1823 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1824 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1825 //---- CCR Mode ---------------------------------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1826
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1827 // 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
1828 ppO2 = const_ppO2;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1829 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1830
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1831 // 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
1832 // capture potential failure conditions first:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1833 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
1834 || ( 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
1835 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1836 // failure condition present, set predetermined result
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1837 calc_pres_respiration = 0.0;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1838 }
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1839 else
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1840 {
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1841 // no failure conditions present, equation can be executed
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1842 calc_pres_respiration -= ppO2;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1843 #ifdef _helium
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1844 calc_pres_respiration /= calc_N2_ratio + calc_He_ratio;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1845 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1846 calc_pres_respiration /= calc_N2_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1847 #endif
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1848 }
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 else
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1851 #endif // _ccr_pscr
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1852 {
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1853 //---- OC mode ---------------------------------------------------------------------------------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1854
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1855 // breathed ppO2 is ppO2 of pure gas
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1856 ppO2 = OC_ppO2;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1857 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
1858
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1859
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1860 //---- derive char_ppO2 in [cbar], used for calculating CNS% ---------------------------------------
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1861
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1862 if ( ppO2 < 0.01 ) char_ppO2 = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1863 else if ( ppO2 >= 2.545 ) char_ppO2 = 255;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1864 else char_ppO2 = (unsigned char)(100 * ppO2 + 0.5);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1865
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1866
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1867 //---- calculate ppN2 and ppHe ---------------------------------------------------------------------
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1868
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1869 // add deco safety distance when working on simulated tissues
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1870 if( !(tissue_increment & TISSUE_SELECTOR) ) calc_pres_respiration += float_deco_distance;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1871
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1872 // compute ppN2 and ppHe, capture potential failure conditions first:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1873 if( calc_pres_respiration > ppWater )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1874 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1875 // subtract water vapor pressure
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1876 calc_pres_respiration -= ppWater;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1877
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1878 // calculate partial pressures
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1879 ppN2 = calc_N2_ratio * calc_pres_respiration;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1880
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1881 #ifdef _helium
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1882 ppHe = calc_He_ratio * calc_pres_respiration;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1883 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1884 ppHe = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1885 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1886
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1887 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1888 else
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1889 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1890 // 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
1891 ppN2 = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1892 ppHe = 0.0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1893 }
0
heinrichsweikamp
parents:
diff changeset
1894 }
heinrichsweikamp
parents:
diff changeset
1895
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1896
0
heinrichsweikamp
parents:
diff changeset
1897 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1898 // init_output_vars
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1899 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1900 // Initializes all output variables to their default values
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1901 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1902 static void init_output_vars(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1903 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1904 // 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
1905 clear_deco_table();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1906
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1907 // publish the cleared stops table to the display functions
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1908 publish_deco_table();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1909
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1910 // clear the published gas needs in volume and pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1911 for( i = 0; i < NUM_GAS; ++i )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1912 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1913 int_O_gas_need_vol[i] = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1914 int_O_gas_need_pres[i] = 0 + INT_FLAG_ZERO + INT_FLAG_INVALID;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1915 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1916
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1917 // values initially to be set to zero
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1918 int_O_ceiling = 0; // ceiling depth in mbar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1919 char_O_deco_info = 0; // clear all deco information flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1920 char_O_deco_warnings = 0; // clear all deco warning flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1921
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1922 // default desaturation time to 24 hours (it will not be computed during a dive)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1923 int_O_desaturation_time = 1440;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1924
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1925 // initialize CNS values
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1926 int_O_CNS_norm = 0 + INT_FLAG_INVALID;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1927 int_O_CNS_alt = 0 + INT_FLAG_INVALID;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1928
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1929 // initialize NDL times
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1930 char_O_NDL_norm = 240;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1931 char_O_NDL_alt = 240;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1932
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1933 // initialize ascent times
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1934 int_O_TTS_norm = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1935 int_O_TTS_alt = 0 + INT_FLAG_INVALID + INT_FLAG_NOT_COMPUTED_YET;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1936
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1937 #ifdef _rx_functions
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1938 // clear TR values
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1939 int_O_SAC_measured = 0 + INT_FLAG_NOT_AVAIL; // SAC rate
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1940 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
1941 int_O_pressure_need[1] = 0 + INT_FLAG_NOT_AVAIL; // pressure need to reading 2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1942 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1943
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1944 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1945
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1946
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1947 //////////////////////////////////////////////////////////////////////////////
0
heinrichsweikamp
parents:
diff changeset
1948 // clear_tissue
heinrichsweikamp
parents:
diff changeset
1949 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1950 // Reset all tissues to surface pressure equilibrium state
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1951 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1952 // Input: int_I_pres_surface current surface pressure in hPa (mbar)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1953 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1954 // Output: real_pres_tissue_N2[] partial pressure of N2 in real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1955 // real_pres_tissue_He[] partial pressure of He in real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1956 // char_O_tissue_pres_N2[] partial pressure of N2 for tissue graphics
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1957 // char_O_tissue_pres_He[] partial pressure of He for tissue graphics
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1958 // char_O_tissue_pressure[] total pressure for tissue graphics
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1959 // CNS_fraction_real internal CNS value
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1960 // int_O_CNS_current current CNS value
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1961 // int_O_CNS_norm CNS value at end of normal dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1962 // int_O_CNS_alt CNS value at end of alternative dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1963 // char_O_deco_warnings deco warnings vector
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1964 // char_O_NDL_norm remaining NDL time in normal dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1965 // char_O_NDL_alt remaining NDL time in alternative dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1966 // int_O_TTS_norm ascent time (TTS) in normal dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1967 // int_O_TTS_alt ascent time (TTS) in alternative dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1968 // int_O_lead_supersat supersaturation of the leading tissue
0
heinrichsweikamp
parents:
diff changeset
1969 //
heinrichsweikamp
parents:
diff changeset
1970 static void clear_tissue(void)
heinrichsweikamp
parents:
diff changeset
1971 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1972 // safeguard and convert the surface pressure (mbar -> bar) (*)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1973 if( int_I_pres_surface < 500 ) pres_surface = 0.500;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1974 else pres_surface = 0.001 * int_I_pres_surface;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1975
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1976 // calculate partial pressure of N2 in respired air at surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1977 calc_N2_equilibrium();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1978
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1979 // cycle through the 16 Buhlmann tissues
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
1980 for( ci = 0; ci < NUM_COMP; ci++ )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1981 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1982 // reset tissue pressures
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1983 real_pres_tissue_He[ci] = 0.0; // He
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1984 real_pres_tissue_N2[ci] = N2_equilibrium; // N2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1985
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1986 // reset tissue pressures for scaled for tissue graphics
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1987 char_O_tissue_pres_He[ci] = 0; // He
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1988 char_O_tissue_pres_N2[ci] = 10; // N2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1989 char_O_tissue_pressure[ci] = 10; // combined
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1990 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1991
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1992 // reset CNS values
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1993 CNS_fraction_real = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1994 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
1995
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
1996 // reset some more vars to their defaults
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1997 char_O_NDL_norm = 240;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1998 char_O_NDL_alt = 240;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
1999 int_O_TTS_norm = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2000 int_O_TTS_alt = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2001 int_O_lead_supersat = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2002
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2003 // reset all warning and info flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2004 char_O_deco_warnings = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2005 char_O_deco_info = 0;
0
heinrichsweikamp
parents:
diff changeset
2006 }
heinrichsweikamp
parents:
diff changeset
2007
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2008
0
heinrichsweikamp
parents:
diff changeset
2009 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
2010 // calc_hauptroutine
heinrichsweikamp
parents:
diff changeset
2011 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2012 // This is the major code in dive mode, it calculates the tissue pressures,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2013 // the bottom time, and it calculates the ascend with all deco stops, etc.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2014 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2015 // Input: char_O_main_status deco engine control and real tissues mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2016 // char_O_deco_status deco engine control and simulated tissues mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2017 // char_I_sim_advance_time mailbox for bottom time incrementing
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2018 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2019 // char_I_SAC_work gas usage rate during working phase in l/min
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2020 // char_I_SAC_deco gas usage rate during deco stops phase in l/min
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2021 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2022 // char_I_deco_model selector for GF extension
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2023 // char_I_ascent_speed ascent speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2024 // char_I_deco_distance safety distance between stop depth and calculated depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2025 // char_I_saturation_multiplier safety factor for tissue saturation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2026 // char_I_desaturation_multiplier safety factor for tissue desaturation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2027 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2028 // char_I_pressure_gas[] amount of gas available for ascent in bar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2029 // int_I_pressure_drop[] pressure drop used to calculate SAC rate
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2030 // char_I_gas_avail_size[] size of the tanks in liters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2031 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2032 // Output: int_O_O2_ppO2 partial pressure of pure O2 at current depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2033 // int_O_pure_ppO2 partial pressure of O2 in gas at current depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2034 // 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
2035 // int_O_breathed_ppO2 partial pressure of O2 currently breathed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2036 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2037 // char_O_deco_status deco engine computations status
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2038 // char_O_deco_info deco engine information vector
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2039 // char_O_deco_warnings deco engine warnings vector
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2040 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2041 // char_O_NDL_norm remaining NDL time in normal dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2042 // char_O_NDL_alt remaining NDL time in alternative dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2043 // int_O_TTS_norm ascent time (TTS) in normal dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2044 // int_O_TTS_alt ascent time (TTS) in alternative dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2045 // int_O_CNS_norm CNS value at end of normal dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2046 // int_O_CNS_alt CNS value at end of alternative dive plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2047 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2048 // int_O_gas_need_vol calculated gas volumes needed for ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2049 // int_O_gas_need_pres calculated gas pressures needed for ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2050 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2051 // int_O_SAC_measured measured surface air consumption (SAC) rate in l/min
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2052 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2053 // Modified: int_IO_pressure_value[] warning flags added to pressure reading 1 & 2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2054 // int_IO_pressure_need[] pressure needs to pressure reading 1 & 2
0
heinrichsweikamp
parents:
diff changeset
2055 //
heinrichsweikamp
parents:
diff changeset
2056 static void calc_hauptroutine(void)
heinrichsweikamp
parents:
diff changeset
2057 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2058 overlay unsigned short int_ppO2_min;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2059 overlay unsigned short int_ppO2_max;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2060 overlay unsigned short int_ppO2_max_dil;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2061 overlay unsigned short int_ppO2_max_max;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2062 overlay float EAD;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2063 overlay float END;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2064
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2065 //=============================================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2066
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2067 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2068 //--- Setup Part ---------------------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2069 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2070
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2071 // 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
2072 tmr5_value = 65535 - (32 * BUDGET_PER_SECOND / INVOKES_PER_SECOND);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2073
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2074 // load timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2075 load_tmr5();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2076
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2077 // read command flags and set up what to do
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2078 switch( char_O_deco_status & COMMAND_MASK )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2079 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2080
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2081 case INITIALIZE:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2082 case INITIALIZE_START_NORM:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2083 case INITIALIZE_START_ALT:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2084
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2085 // copy master modes to shadow registers
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2086 main_status = char_O_main_status;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2087 deco_status = char_O_deco_status;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2088
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2089 // 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
2090 char_O_deco_status &= ~COMMAND_MASK;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2091
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2092 // clear the initialization flag on the shadow copy
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2093 deco_status &= ~INITIALIZE;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2094
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2095 // initialize the sequence timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2096 sequence_timer = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2097
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2098 // set the calculation phase to start with to doing the once-per-dive initialization
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2099 next_planning_phase = PHASE_10_DIVE_INIT;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2100
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2101 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2102
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2103
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2104 case START_NORM:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2105 case START_ALT:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2106
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2107 // copy master modes to shadow registers
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2108 main_status = char_O_main_status;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2109 deco_status = char_O_deco_status;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2110
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2111 // 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
2112 char_O_deco_status &= ~COMMAND_MASK;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2113
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2114 // set the calculation phase to start with to doing the cyclic initialization
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2115 next_planning_phase = PHASE_11_CYCLIC_INIT;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2116
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2117 // continue in CALCULATING
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2118
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2119
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2120 case CALCULATING:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2121
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2122 // keep current calculation phase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2123
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2124 // step the sequence timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2125 sequence_timer = (sequence_timer < INVOKES_PER_SECOND * 2 - 1) ? sequence_timer + 1 : 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2126
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2127 break;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2128 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2129
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2130
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2131 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2132 //--- End of Setup Part -----------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2133 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2134
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 //---- Calculations Part (real Tissues) -------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2139 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2140
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2141
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2142 // target the real tissues with 2 second increments by default
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2143 tissue_increment = TISSUE_SELECTOR | 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2144
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2145
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2146 // 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
2147 // Requests for tissue "fast forward" are executed immediately.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2148 #if (INVOKES_PER_SECOND > 1)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2149 if( ( sequence_timer == 0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2150 || ( sequence_timer == INVOKES_PER_SECOND )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2151 || ( char_I_sim_advance_time > 0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2152 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2153 #endif
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
2154 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2155 // acquire current environmental data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2156 calc_hauptroutine_data_input();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2157
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2158 // calculate ppO2, ppN2 and ppHe
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2159 calc_alveolar_pressures();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2160
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2161 // add decent calculation here and include trigger in above if-statement
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2162 // TODO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2163
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2164 } // tasks every second, on the first section of the second
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2165
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2166
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2167 // Tasks every 2 seconds, on the first section of the respective second.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2168 // Requests for tissue "fast forward" are executed immediately.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2169 if( ( sequence_timer == 0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2170 || ( char_I_sim_advance_time > 0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2171 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2172 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2173 // Tissue and CNS updates are based on 2 seconds periods!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2174
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2175 // 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
2176 // sim+5' function and deco calculator bottom time calculation.
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2177 if( char_I_sim_advance_time > 0 )
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2178 {
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2179 // configure "fast forward" tissue updating
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2180 tissue_increment = TISSUE_SELECTOR | char_I_sim_advance_time;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2181
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2182 // clear the request
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2183 char_I_sim_advance_time = 0;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2184 }
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2185
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
2186 // calculate the real tissues
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
2187 calc_tissues();
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
2188
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2189 // update the CNS value for the real tissues
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2190 calc_CNS();
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2191
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2192 // calculate ceiling (at GF_high or 100%) and leading tissue supersaturation
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2193 if ( char_I_deco_model ) calc_limit(GF_high); // GF factors enabled
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2194 else calc_limit( 1.0 ); // classic Buhlmann
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2195
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2196 // convert the ceiling value to integer
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2197 convert_ceiling_for_display();
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2198
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2199 // convert the saturation value of the leading tissue to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2200 convert_sat_for_display();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2201
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2202 // convert the CNS value to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2203 convert_cur_CNS_for_display();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2204
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2205 } // tasks every 2 seconds
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 // 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
2209 #if (INVOKES_PER_SECOND > 1)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2210 if( ( sequence_timer == 0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2211 || ( sequence_timer == INVOKES_PER_SECOND )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2212 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2213 #endif
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2214 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2215 //---- Calculate and Export EAD and END ------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2216
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2217 // calculate EAD (Equivalent Air Depth): equivalent depth for the same N2 level with plain air
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2218 EAD = (ppN2 / 0.7902 + ppWater - pres_surface) * BAR_TO_METER;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2219
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2220 // calculate END (Equivalent Narcotic Depth): here O2 is treated as narcotic, too
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2221 // Source cited: The Physiology and Medicine of Diving by Peter Bennett and David Elliott,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2222 // 4th edition, 1993, W.B.Saunders Company Ltd, London.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2223 END = (real_pres_respiration - ppHe - pres_surface) * BAR_TO_METER;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2224
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2225 // export EAD
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2226 float_value = EAD; convert_float_to_char(); char_O_EAD = char_value;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2227
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2228 // export END
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2229 float_value = END; convert_float_to_char(); char_O_END = char_value;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2230
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2231
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2232 //---- Compute ppO2 Values in [cbar] ---------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2233
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2234 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
2235 #ifdef _ccr_pscr
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2236 float_value = O2_ppO2; convert_float_to_int(); int_O_O2_ppO2 = int_value; // pure oxygen
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2237 float_value = OC_ppO2; convert_float_to_int(); int_O_pure_ppO2 = int_value; // pure gas
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2238 float_value = pSCR_ppO2; convert_float_to_int(); int_O_pSCR_ppO2 = int_value; // pSCR calculated
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2239 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2240
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2241
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2242 //---- Set/Reset Deco Mode --------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2243
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2244 // Set the deco mode flag if:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2245 // deco mode is not set
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2246 // AND breathing an OC deco gas (gas type 3)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2247 // OR breathing a gas or diluent that officially is disabled (type 0)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2248 // OR there is a deco stop and we are less deep than 1 meter below the deepest deco stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2249 if ( ( deco_info & DECO_FLAG ) == 0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2250 if ( ( char_I_current_gas_type == 3 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2251 || ( char_I_current_gas_type == 0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2252 || ( ( char_O_deco_depth[0] > 0 ) && ( char_depth_real <= char_O_deco_depth[0] + 1 ) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2253 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2254 deco_info |= DECO_FLAG;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2255
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2256 // Clear the deco mode flag if:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2257 // deco mode is set
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2258 // AND deeper than 7 meters below deepest deco stop (7 meters = 2 stop depth intervals plus 1 meter below stop)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2259 if ( ( deco_info & DECO_FLAG ) > 0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2260 if ( ( char_depth_real > char_O_deco_depth[0] + 7 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2261 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2262 deco_info &= ~DECO_FLAG;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2263
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2264
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2265 //---- Compute ppO2 Warnings ------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2266
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2267 // compute conditional min values
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2268 #ifdef _ccr_pscr
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2269 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
2270 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2271 int_ppO2_min = (unsigned short)char_I_ppO2_min;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2272 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2273
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2274 // compute conditional max values
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2275 int_ppO2_max = ( deco_info & DECO_FLAG ) ? (unsigned short)char_I_ppO2_max_deco : (unsigned short)char_I_ppO2_max_work;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2276
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2277 // add some margin on ppO2 max to compensate for surface pressures > 1.000 mbar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2278 int_ppO2_max += ppO2_MARGIN_ON_MAX;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2279
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2280 // get biggest of char_I_ppO2_max_work / char_I_ppO2_max_deco
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2281 int_ppO2_max_max = ( char_I_ppO2_max_deco > char_I_ppO2_max_work ) ? char_I_ppO2_max_deco : char_I_ppO2_max_work;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2282
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2283 #ifdef _ccr_pscr
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2284 // default value for the upper diluent ppO2 warning threshold is the normal upper warning threshold
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2285 int_ppO2_max_dil = int_ppO2_max;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2286
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2287 // when in CCR mode, the upper diluent warning threshold gets adjust according to the current setpoint
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2288 if( (main_status & MODE_MASK) == MODE_CCR )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2289 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2290 overlay unsigned short max_dil;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2291
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2292 // The upper diluent ppO2 threshold is ppO2_GAP_TO_SETPOINT below the setpoint...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2293 // (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
2294 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
2295
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2296 // ...but never above int_ppO2_max.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2297 if( max_dil < int_ppO2_max ) int_ppO2_max_dil = max_dil;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2298
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2299 // 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
2300 // 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
2301 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2302 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2303
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2304 // check for safe range of breathed gas
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2305 if ( int_O_breathed_ppO2 <= int_ppO2_min ) int_O_breathed_ppO2 |= INT_FLAG_WARNING + INT_FLAG_LOW;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2306 else if ( int_O_breathed_ppO2 >= int_ppO2_max_max ) int_O_breathed_ppO2 |= INT_FLAG_WARNING + INT_FLAG_HIGH;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2307 else if ( deco_info & DECO_FLAG ) ; // no attention generated in deco mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2308 else if ( main_status & MODE_LOOP ) ; // no attention generated in loop modes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2309 else if ( int_O_breathed_ppO2 >= (unsigned short)char_I_ppO2_max_work ) int_O_breathed_ppO2 |= INT_FLAG_ATTENTION;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2310
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2311 #ifdef _ccr_pscr
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2312 // check for safe range of pure oxygen
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2313 if ( int_O_O2_ppO2 >= int_ppO2_max ) int_O_O2_ppO2 |= INT_FLAG_WARNING + INT_FLAG_HIGH;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2314
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2315 // check for safe range of pure diluent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2316 if ( int_O_pure_ppO2 <= (unsigned short)char_I_ppO2_min ) int_O_pure_ppO2 |= INT_FLAG_WARNING + INT_FLAG_LOW;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2317 else if ( int_O_pure_ppO2 >= int_ppO2_max ) int_O_pure_ppO2 |= INT_FLAG_WARNING + INT_FLAG_HIGH;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2318 else if ( int_O_pure_ppO2 >= int_ppO2_max_dil ) int_O_pure_ppO2 |= INT_FLAG_ATTENTION;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2319
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2320 // check for safe range of calculated pSCR loop gas
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2321 if ( int_O_pSCR_ppO2 <= int_ppO2_min ) int_O_pSCR_ppO2 |= INT_FLAG_WARNING + INT_FLAG_LOW;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2322 else if ( int_O_pSCR_ppO2 >= int_ppO2_max ) int_O_pSCR_ppO2 |= INT_FLAG_WARNING + INT_FLAG_HIGH;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2323 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2324
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2325 } // 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
2326
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2327
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2328 #ifdef _rx_functions
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2329
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2330 // only when TR functions are enabled
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2331 if( main_status & TR_FUNCTIONS )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2332
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2333 // 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
2334 #if (INVOKES_PER_SECOND > 1)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2335 if( ( sequence_timer == 1 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2336 || ( sequence_timer == INVOKES_PER_SECOND + 1 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2337 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2338 #endif
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2339 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2340 calc_TR_functions();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2341 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2342
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2343 #endif // _rx_functions
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2344
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2345
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2346 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2347 //---- End of Computations for the real Tissues -----------------------------------------------
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2348 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2349
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2350 //=============================================================================================
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2351
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2352 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2353 //---- Begin of Computations for Ascent and Decompression (simulated Tissues) -----------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2354 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2355
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2356 // Dispatcher: select what to do based on the current calculation phase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2357 do
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2358 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2359
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2360 #ifdef _profiling
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2361 profiling_phase = next_planning_phase;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2362 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2363
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2364 switch( next_planning_phase )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2365 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2366
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2367 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2368 //---- once-per-dive Initialization of the Deco Engine ------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2369 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2370 case PHASE_10_DIVE_INIT:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2371
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2372 // initialize all output variables to defaults
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2373 init_output_vars();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2374
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2375 // safeguard input parameters that are constant during the course of the dive
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2376 if( char_I_deco_distance > 20 ) char_I_deco_distance = 20;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2377 if( char_I_ascent_speed < 5 ) char_I_ascent_speed = 5;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2378 if( char_I_ascent_speed > 10 ) char_I_ascent_speed = 10;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2379
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2380 // convert input parameters to float numbers
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2381 float_deco_distance = 0.01 * char_I_deco_distance;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2382 float_ascent_speed = 1.00 * char_I_ascent_speed;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2383
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2384 // initialize values that will be recalculated later on periodically
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2385 deco_warnings = 0; // reset all deco warnings
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2386 deco_info = 0; // reset all deco infos
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2387 IBCD_tissue_vector = 0; // reset tissue IBCD vector
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2388 NDL_tissue_start_norm = 0; // initialize the tissue to start with when calculating normal NDL time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2389 NDL_tissue_start_alt = 0; // initialize the tissue to start with when calculating alternative NDL time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2390
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2391 // enforce initialization of GF data on first cyclic initialization
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2392 GF_high_last = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2393 GF_low_last = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2394
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2395
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2396 #ifdef _cave_mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2397 char_I_backtrack_time = 0; //clear backtracking time (index to char_I_backtrack_depth)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2398 char_I_backtrack_depth = 0; //prime first entry with a depth of 0 meter
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2399 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2400
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2401 #ifdef _profiling
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2402 int_O_profiling_overrun_max = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2403 char_O_profiling_runs_norm = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2404 char_O_profiling_runs_alt = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2405 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2406
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2407
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2408 // 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
2409 // normal or alternative plan shall be calculated, else the calculation cycle is done.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2410 if( deco_status & PLAN_MASK ) next_planning_phase = PHASE_11_CYCLIC_INIT;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2411 else next_planning_phase = PHASE_00_DONE;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2412
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2413 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2414
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2415
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2416 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2417 //---- once-per-cycle Initialization of the Deco Engine------------------------------------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2418 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2419 case PHASE_11_CYCLIC_INIT:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2420
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2421 // target the simulated tissues (flag bit 7 = 0)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2422 tissue_increment = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2423
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2424 // clear the internal stops table
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2425 clear_deco_table();
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2426
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2427 // 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
2428 for( i = 0; i < NUM_COMP; i++ )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2429 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2430 sim_pres_tissue_N2[i] = real_pres_tissue_N2[i];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2431 sim_pres_tissue_He[i] = real_pres_tissue_He[i];
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2432 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2433
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2434 // initialize GF parameters if using GF model
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2435 if( char_I_deco_model != 0 )
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2436 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2437 // update GF parameters (GFs may have been switched between GF and aGF)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2438 if( (char_I_GF_High_percentage != GF_high_last) || (char_I_GF_Low_percentage != GF_low_last) )
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2439 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2440 // store new values in integer format
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2441 GF_high_last = char_I_GF_High_percentage;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2442 GF_low_last = char_I_GF_Low_percentage;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2443
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2444 // store new values in float format
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2445 GF_high = 0.01 * char_I_GF_High_percentage;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2446 GF_low = 0.01 * char_I_GF_Low_percentage;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2447
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2448 // reset low depth references and slopes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2449 GF_low_depth_norm = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2450 GF_low_depth_alt = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2451 GF_slope_norm = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2452 GF_slope_alt = 0.0;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2453 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2454
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2455 // retrieve GF parameters for current calculation cycle
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2456 if( deco_status & CALC_NORM )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2457 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2458 GF_low_depth = GF_low_depth_norm;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2459 GF_slope = GF_slope_norm;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2460 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2461 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2462 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2463 GF_low_depth = GF_low_depth_alt;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2464 GF_slope = GF_slope_alt;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2465 }
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2466 }
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2467
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2468 // initialize the simulated CNS value with the current CNS value of the real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2469 CNS_fraction_sim = CNS_fraction_real;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2470
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2471 // initialize the simulated depth with the current depth (in absolute pressure)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2472 sim_pres_respiration = real_pres_respiration;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2473
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2474 // compute the depth in meters where we are now
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2475 float_depth_real = (sim_pres_respiration - pres_surface) * BAR_TO_METER;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2476
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2477 // convert to integer and round up to next full meter
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2478 char_depth_real = (unsigned char)(float_depth_real + 0.99);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2479
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2480 // initialize depth for deco ascent calculation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2481 char_depth_sim = char_depth_real;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2482
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2483 // 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
2484 // the gas to be used with the simulated tissues, too. This gas will be used until
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2485 // gas_find_better() is invoked and finds a better gas to switch to.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2486 gas_find_current();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2487
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2488 // Setup the calculation ratio's for N2, He and O2 (sim_N2/He/_O2_ratio). These ratios
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2489 // can be kept until a gas switch is done. Thus, if a call to gas_find_better() has
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2490 // found a better gas and initiated a switch, gas_set_ratios() needs to be called again.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2491 gas_set_ratios();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2492
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2493 // compute ppO2, ppN2 and ppHe for current depth from sim_pres_respiration
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2494 calc_alveolar_pressures();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2495
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2496 // initialize the no decompression limit (NDL) time to 240 minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2497 NDL_time = 240;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2498
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2499 // retrieve the tissue that had the shortest NDL time during last calculation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2500 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
2501
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2502 // start calculating NDL time with the tissue that had the shortest NDL last time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2503 NDL_tissue = NDL_tissue_start;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2504 NDL_tissue_lead = NDL_tissue_start;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2505
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2506 // initialization for calculating the initial ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2507 // start with 1 minute ascent steps when calculating the initial ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2508 fast = 1;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2509
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2510 // initialization for calc_gas_needs_ascent()
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2511 gas_needs_next_phase = GAS_NEEDS_INIT;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2512
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2513 // initialization for convert_gas_needs_to_press()
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2514 gas_needs_gas_index = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2515
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2516
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2517 #ifdef _profiling
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2518 profiling_runs = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2519 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2520
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2521 // The next calculation phase will
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2522 // - calculate the bottom segment if extended bottom time is configured (fTTS),
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2523 // - proceed with calculating the NDL time else.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2524 if ( deco_status & DELAYED_ASCENT ) next_planning_phase = PHASE_20_EXTENDED_BOTTOM_TIME;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2525 else next_planning_phase = PHASE_30_NDL_TIME;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2526
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2527 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2528
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2529
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2530 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2531 //---- extended Bottom Time ---------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2532 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2533 case PHASE_20_EXTENDED_BOTTOM_TIME:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2534
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2535 // program interval on simulated tissues (flag bit 7 = 0)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2536 tissue_increment = char_I_extra_time;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2537
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2538 // calculate ppO2, ppN2 and ppHe
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2539 calc_alveolar_pressures();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2540
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2541 // update the tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2542 calc_tissues();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2543
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2544 // update the CNS value
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2545 calc_CNS();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2546
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2547 // the next calculation phase will calculate the NDL time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2548 next_planning_phase = PHASE_30_NDL_TIME;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2549
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2550 break;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2551
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2552
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2553 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2554 //---- NDL Time ---------------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2555 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2556 case PHASE_30_NDL_TIME:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2557
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2558 // Calculate the remaining no decompression limit (NDL) time for the tissue NDL_tissue.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2559 // 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
2560 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2561 // In the initialization phase of the calculation cycle:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2562 // - NDL_time had been initialized to 240 (minutes),
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2563 // - NDL_tissue had been initialized to the tissue with
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2564 // the shortest NDL time in the last cycle.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2565 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2566 calc_NDL_time_tissue();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2567
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2568 // advance to next tissue, wrapping around after last tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2569 NDL_tissue = (NDL_tissue + 1) & (NUM_COMP - 1);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2570
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2571 // did we run out of NDL time or did we have probed all tissues?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2572 if( (NDL_time == 0) || (NDL_tissue == NDL_tissue_start) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2573 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2574 // YES
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2575
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2576 // set the tissue with the shortest NDL time found as
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2577 // the one to start with in the next calculation cycle
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2578 if( deco_status & CALC_NORM ) NDL_tissue_start_norm = NDL_tissue_lead;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2579 else NDL_tissue_start_alt = NDL_tissue_lead;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2580
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2581 // done with calculating NDL time, set next calculation phase:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2582 // - calculate return and ascent in cave mode if configured, else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2583 // - proceed with gathering the results if within NDL time, or
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2584 // - proceed with the initial ascent if beyond NDL time.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2585 #ifdef _cave_mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2586 if ( main_status & CAVE_MODE ) next_planning_phase = PHASE_40_CAVE_ASCENT;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2587 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2588 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2589 if ( NDL_time ) next_planning_phase = PHASE_70_RESULTS;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2590 else next_planning_phase = PHASE_60_DECO_ASCENT;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2591 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2592
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2593 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2594
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2595
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2596 #ifdef _cave_mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2597 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2598 //---- Cave Mode Return/Ascent ------------------------------------------------------------
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2599 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2600 case PHASE_40_CAVE_ASCENT:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2601
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2602 // TODO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2603
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2604 // the next calculation phase will gather all results
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2605 next_planning_phase = PHASE_70_RESULTS;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2606
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2607 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2608 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2609
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2610
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2611 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2612 //---- Open Water Ascent with Deco Stops --------------------------------------------------
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2613 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2614 case PHASE_60_DECO_ASCENT:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2615
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2616 // program 1 minute interval on simulated tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2617 tissue_increment = 1;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2618
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2619 // ascent to the next stop depth or the depth that is reachable within one minute of ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2620 // and decide if a stop is required (return value = 1/true) or not (return value = 0/false)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2621 if( find_next_stop() )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2622 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2623 //---- stop required --------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2624
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2625 // check if there is a better gas to switch to
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2626 if( gas_find_better() )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2627 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2628 // set the new calculation ratios for N2, He and O2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2629 gas_set_ratios();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2630
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2631 // doing extended stops?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2632 if( main_status & EXTENDED_STOPS )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2633 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2634 // YES - set char_depth_sim to the gas change depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2635 char_depth_sim = sim_gas_current_depth;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2636
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2637 // - adjust absolute pressure down to the change depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2638 sim_pres_respiration = char_depth_sim * METER_TO_BAR + pres_surface;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2639 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2640
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2641 // prime the deco stop with the gas change time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2642 update_deco_table(char_I_gas_change_time);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2643 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2644
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2645 // add one minute to an existing stop or add a new stop at char_depth_sim,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2646 // or abort stops calculation if the deco table is full
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2647 if( !update_deco_table(1) ) next_planning_phase = PHASE_70_RESULTS;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2648 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2649 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2650 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2651 //---- no stop required -----------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2652
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2653 // check if there is a better gas to switch to, but only:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2654 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2655 // if extended stops are activated,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2656 // OR if in bailout mode.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2657 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2658 // Attention: do not use a && formula over both 'if' terms, the extended stops / bailout
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2659 // condition must be checked before a call to gas_find_better() is made!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2660 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2661 if( (main_status & EXTENDED_STOPS) || (deco_status & BAILOUT_MODE) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2662 if( gas_find_better() )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2663 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2664 // set the new calculation values for N2, He and O2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2665 gas_set_ratios();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2666
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2667 // stop duration is the gas change time, a change time of 0 minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2668 // will set a tissue calculation interval of 2 seconds
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2669 tissue_increment += char_I_gas_change_time;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2670
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2671 // set char_depth_sim to the gas change depth, but not deeper than
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2672 // the depth we came from.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2673 // (char_depth_last holds the depth from before the ascent step)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2674 char_depth_sim = (sim_gas_current_depth < char_depth_last) ? sim_gas_current_depth : char_depth_last;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2675
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2676 // adjust sim_pres_respiration to the adjusted value of char_depth_sim
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2677 sim_pres_respiration = char_depth_sim * METER_TO_BAR + pres_surface;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2678
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2679 // create a stop for the gas change in the stops table
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2680 update_deco_table(char_I_gas_change_time);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2681 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2682 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2683
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2684 //---- one minute has passed by now, update the tissues ----------------
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2685
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2686 // compute current ppO2, ppN2 and ppHe
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2687 calc_alveolar_pressures();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2688
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2689 // update the tissues
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
2690 calc_tissues();
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2691
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2692 // update the CNS value
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
2693 calc_CNS();
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2694
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2695 // finish stops calculation if the surface is reached
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2696 if( char_depth_sim == 0 ) next_planning_phase = PHASE_70_RESULTS;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2697
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2698 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2699
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2700
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2701 ///
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2702 //--- Results - Initialization ------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2703 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2704 case PHASE_70_RESULTS:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2705
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2706 // The current depth is needed by calc_ascenttime(), find_NDL_gas_changes() and
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2707 // calc_gas_needs_ascent(). As we don't want it to be calculated multiple times,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2708 // it is done here on stockpile.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2709 char_depth_bottom = (unsigned char)((real_pres_respiration - pres_surface) * BAR_TO_METER + 0.5);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2710
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2711 // The next calculation phase will
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2712 // - publish the stops table if in normal plan mode,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2713 // - proceed with remaining results dependent on if within NDL, or
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2714 // - in deco
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2715 if ( deco_status & CALC_NORM ) next_planning_phase = PHASE_71_RESULTS_STOPS_TABLE;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2716 else if ( NDL_time ) next_planning_phase = PHASE_72_RESULTS_NDL;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2717 else next_planning_phase = PHASE_73_RESULTS_DECO;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2718
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2719 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2720
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2721
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2722 ///
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2723 //--- Publish Stops Table -----------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2724 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2725 case PHASE_71_RESULTS_STOPS_TABLE:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2726
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2727 // publish the stops table to the display functions
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2728 publish_deco_table();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2729
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2730 // When entering deco and the ceiling depth becomes > 0 but the
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2731 // deco calculation reveals no distinct deco stop yet because
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2732 // the deco obligation will vanish during the ascent, create an
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2733 // artificial stop to signal that expedite surfacing ("popping
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2734 // up") is not allowed anymore.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2735 if( char_O_deco_depth[0] == 0 ) // simulated ascent reveals no required stops
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2736 if( int_O_ceiling > 0 ) // real tissues have a ceiling
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2737 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2738 // set a pro forma stop at the configured last stop depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2739 char_O_deco_depth[0] = char_I_depth_last_deco;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2740
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2741 // set a stop time of 0 minutes, this will be displayed as "..'"
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2742 char_O_deco_time[0] = 0;
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 // update deco info vector
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2746 if( char_O_deco_depth[0] ) deco_info |= DECO_STOPS; // set flag for deco stops found
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2747 else deco_info &= ~DECO_STOPS; // clear flag for deco stops found
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2748
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2749 // The next calculation phase will publish the main results dependent on being
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2750 // - within NDL,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2751 // - in deco.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2752 if ( NDL_time ) next_planning_phase = PHASE_72_RESULTS_NDL;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2753 else next_planning_phase = PHASE_73_RESULTS_DECO;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2754
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2755 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2756
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2757
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2758 ///
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2759 //--- Results - within NDL ----------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2760 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2761 case PHASE_72_RESULTS_NDL:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2762
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2763 // results to publish depend on normal or alternative plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2764 if( deco_status & CALC_NORM )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2765 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2766 // output the NDL time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2767 char_O_NDL_norm = NDL_time;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2768
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2769 // clear the normal ascent time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2770 int_O_TTS_norm = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2771
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2772 // as we are in no stop, CNS at end of dive is more or less the same CNS as we have right now
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2773 int_O_CNS_norm = int_O_CNS_current;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2774 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2775 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2776 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2777 // output the NDL time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2778 char_O_NDL_alt = NDL_time;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2779
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2780 // clear the alternative ascent time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2781 int_O_TTS_alt = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2782
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2783 // as we are in no stop, CNS at end of dive is more or less the same CNS as we have right now
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2784 int_O_CNS_alt = int_O_CNS_current;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2785 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2786
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2787 // The next calculation phase will
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2788 // - finish the calculation cycle if no gas needs calculation configured, else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2789 // - find gas switches when in bailout mode (we are in NDL), or
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2790 // - calculate the gas needs along the ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2791 if ( !(main_status & CALC_VOLUME ) ) next_planning_phase = PHASE_90_FINISH;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2792 else if ( (deco_status & BAILOUT_MODE) ) next_planning_phase = PHASE_80_GAS_NEEDS_SWITCHES;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2793 else next_planning_phase = PHASE_81_GAS_NEEDS_ASCENT;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2794
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2795 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2796
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2797
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2798 ///
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2799 //--- Results - in Deco -------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2800 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2801 case PHASE_73_RESULTS_DECO:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2802
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2803 // calculate the ascent time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2804 calc_ascenttime();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2805
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2806 // convert the CNS value to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2807 convert_sim_CNS_for_display();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2808
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2809 // results to publish depend on normal or alternative plan
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2810 if( deco_status & CALC_NORM )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2811 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2812 // clear the normal NDL time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2813 char_O_NDL_norm = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2814
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2815 // export the ascent time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2816 int_O_TTS_norm = ascent_time;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2817
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2818 // export the integer CNS value
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2819 int_O_CNS_norm = int_sim_CNS_fraction;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2820 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2821 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2822 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2823 // clear the alternative NDL time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2824 char_O_NDL_alt = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2825
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2826 // export the ascent time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2827 int_O_TTS_alt = ascent_time;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2828
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2829 // export the integer CNS value
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2830 int_O_CNS_alt = int_sim_CNS_fraction;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2831 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2832
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2833 // The next calculation phase will
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2834 // - finish the calculation cycle if no gas needs calculation configured, else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2835 // - calculate the gas needs along the ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2836 if ( !(main_status & CALC_VOLUME ) ) next_planning_phase = PHASE_90_FINISH;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2837 else next_planning_phase = PHASE_81_GAS_NEEDS_ASCENT;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2838
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2839 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2840
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2841
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2842 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2843 //--- Gas Needs - Switches ----------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2844 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2845 case PHASE_80_GAS_NEEDS_SWITCHES:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2846
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2847 // When in bailout mode and within NDL, find the gas switches along the ascent and put
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2848 // them into the stops table. The stops table can be "polluted" by now because the table
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2849 // has already been published in "clean" state before.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2850 find_NDL_gas_changes();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2851
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2852 // the next calculation phase will calculate the gas needs along the ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2853 next_planning_phase = PHASE_81_GAS_NEEDS_ASCENT;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2854
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2855 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2856
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2857
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2858 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2859 //--- Gas Needs - calculate Ascent Needs using Data from Stop Table -----------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2860 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2861 case PHASE_81_GAS_NEEDS_ASCENT:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2862
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2863 // calculate the gas needs along the ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2864 calc_gas_needs_ascent();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2865
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2866 // if calculation has finished, advance to next calculation phase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2867 if( gas_needs_next_phase == GAS_NEEDS_DONE ) next_planning_phase = PHASE_82_GAS_NEEDS_PRESSURES;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2868
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2869 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2870
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2871
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2872 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2873 //--- Gas Needs - convert Volumes to Pressures --------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2874 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2875 case PHASE_82_GAS_NEEDS_PRESSURES:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2876
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2877 // convert required volume of the gas pointed to by gas_needs_gas_index
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2878 // into the respective pressure and set the flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2879 convert_gas_needs_to_press();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2880
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2881 // increment index to address next gas
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2882 gas_needs_gas_index++;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2883
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2884 // if all gases have been converted, advance to next calculation phase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2885 if( gas_needs_gas_index == NUM_GAS ) next_planning_phase = PHASE_90_FINISH;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2886
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2887 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2888
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2889
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2890 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2891 //--- finish Calculation Cycle ------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2892 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2893 case PHASE_90_FINISH:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2894
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2895 // Check if deco obligation is steady state or decreasing.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2896 // This works only when an alternative plan is enabled and if it is not a bailout plan,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2897 // thus BAILOUT_MODE must not be set while doing the alternative plan.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2898 if( (deco_status & CALC_ALT) && !(deco_status & BAILOUT_MODE) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2899 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2900 if ( int_O_TTS_alt <= int_O_TTS_norm ) deco_info |= DECO_ZONE;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2901 else deco_info &= ~DECO_ZONE;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2902 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2903
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2904 // export updated deco infos and warnings
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2905 char_O_deco_info = deco_info;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2906 char_O_deco_warnings = deco_warnings;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2907
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2908 // restore command flag to indicate that deco calculation cycle has finished
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2909 char_O_deco_status = deco_status;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2910
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2911 // signal end of deco calculation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2912 next_planning_phase = PHASE_00_DONE;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2913
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2914 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2915
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2916 } // switch
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2917
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2918 // 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
2919 read_tmr5();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2920
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2921 } // sequence calculation phases while not timed out and calculation cycle is not finished
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2922 while( (tmr5_overflow == 0) && ( next_planning_phase != PHASE_00_DONE ) );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2923
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2924 // 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
2925 char_O_depth_sim = char_depth_sim;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2926
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2927
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2928 #ifdef _profiling
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2929
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2930 //---- Performance Measurement -------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2931
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2932 // convert timer 5 readout into ms
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2933 profiling_runtime = tmr5_value / 32;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2934
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2935 // actual runtime longer than target runtime?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2936 if( tmr5_overflow )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2937 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2938 // YES - report excess
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2939 int_O_profiling_overrun = profiling_runtime;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2940
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2941 // - excess > max we had so far?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2942 if( int_O_profiling_overrun > int_O_profiling_overrun_max )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2943 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2944 // YES - update max
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2945 int_O_profiling_overrun_max = int_O_profiling_overrun;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2946
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2947 // - store the causing phase
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2948 char_O_profiling_overrun_phase = profiling_phase;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2949 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
2950 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2951 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2952 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2953 // NO - calculate unused budget and flag it to be under-run time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2954 int_O_profiling_overrun = (2048 - profiling_runtime) | 0x8000;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2955 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2956
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2957 // increment number of runs in current cycle
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2958 profiling_runs += 1;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2959
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2960 // planning cycle completed?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2961 if( next_planning_phase == PHASE_00_DONE )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2962 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2963 // YES - export number of runs it took
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2964 if( deco_status & COMPLETED_NORM ) char_O_profiling_runs_norm = profiling_runs;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2965 else char_O_profiling_runs_alt = profiling_runs;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2966 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2967
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2968 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2969
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2970 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2971
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2972
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2973 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2974 // calc_hauptroutine_data_input
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2975 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2976 // Set all C-code dive parameters from their ASM-code values.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2977 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2978 void calc_hauptroutine_data_input(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2979 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2980 overlay float IG_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2981
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2982 // safeguard and convert the surface pressure (mbar -> bar) (*)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2983 if( int_I_pres_surface < 500 ) pres_surface = 0.500;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2984 else pres_surface = 0.001 * int_I_pres_surface;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2985
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2986 // safeguard and convert the current real pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2987 if( int_I_pres_respiration < 500 ) real_pres_respiration = 0.500;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2988 else real_pres_respiration = 0.001 * int_I_pres_respiration;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2989
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2990 // safeguard further parameters to protect the tissue-flag and the stop table
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2991 if( char_I_sim_advance_time > 127 ) char_I_sim_advance_time = 127;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2992 if( char_I_extra_time > 127 ) char_I_extra_time = 127;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2993 if( char_I_gas_change_time > 99 ) char_I_gas_change_time = 99;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2994
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2995 // calculate partial pressure of N2 in respired air at surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2996 calc_N2_equilibrium();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2997
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2998 // get, safeguard and convert the saturation and desaturation factors
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
2999 get_saturation_factors();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3000
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3001 #ifdef _ccr_pscr
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3002 // compute a factor that will be used later on for pSCR ppO2 drop calculation (*)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3003 float_pSCR_factor = 0.01 * char_I_PSCR_drop * char_I_PSCR_lungratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3004 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3005
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3006 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3007 // get the currently breathed gas ratios
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3008 real_O2_ratio = 0.01 * char_I_O2_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3009 real_He_ratio = 0.01 * char_I_He_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3010
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3011 // calculate the inert gas ratio (local helper variable)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3012 IG_ratio = 1.00 - real_O2_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3013
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3014 // calculate the N2 ratio
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3015 real_N2_ratio = IG_ratio - real_He_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3016 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3017 // get the currently breathed O2 ratio
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3018 real_O2_ratio = 0.01 * char_I_O2_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3019
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3020 // set the He ratio to zero
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3021 real_He_ratio = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3022
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3023 // calculate the N2 / inert gas ratio
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3024 real_N2_ratio = IG_ratio = 1.00 - real_O2_ratio;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3025 #endif // _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3026
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3027 #ifdef _ccr_pscr
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3028 // calculate ppO2 drop in pSCR loop for real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3029 real_pSCR_drop = IG_ratio * float_pSCR_factor;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3030 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3031
0
heinrichsweikamp
parents:
diff changeset
3032 }
heinrichsweikamp
parents:
diff changeset
3033
heinrichsweikamp
parents:
diff changeset
3034
heinrichsweikamp
parents:
diff changeset
3035 //////////////////////////////////////////////////////////////////////////////
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3036 // Find gas changes on an NDL ascent
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3037 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3038 // This function is used for finding the gas changes in an OC bailout ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3039 // that is within NDL.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3040 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3041 // Input: char_depth_bottom depth at which the ascent starts, in meters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3042 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3043 // Output: gas change stops put into stops table
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3044 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3045 // Destroyed: char_depth_sim
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3046 // sim_gas_current_num number of current gas
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3047 // sim_gas_current_depth change depth of current gas
0
heinrichsweikamp
parents:
diff changeset
3048 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3049 void find_NDL_gas_changes(void)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3050 {
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3051 overlay unsigned char old_depth_limit;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3052
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3053 // set gas to start with
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3054 gas_find_current();
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3055
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3056 // loop in ascending until reaching a depth of 3 meters, no gas switches considered thereafter
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3057 for( char_depth_sim = char_depth_bottom; char_depth_sim >= 3; )
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3058 {
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3059 // memorize the depth we came from
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3060 old_depth_limit = char_depth_sim;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3061
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3062 // ascent - initially in steps of 10 m, then slowing down to 1 m steps to not miss a O2 gas
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3063 if ( char_depth_sim > 10 ) char_depth_sim -= 10;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3064 else char_depth_sim -= 1;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3065
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3066 // check if there is a better gas to switch to
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3067 if( gas_find_better() )
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3068 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3069 // adjust char_depth_sim to the gas change depth, but not deeper than the depth we came from
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3070 char_depth_sim = (sim_gas_current_depth < old_depth_limit) ? sim_gas_current_depth : old_depth_limit;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3071
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3072 // create a stop for the gas change in the stops table
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3073 update_deco_table(char_I_gas_change_time);
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3074 }
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3075 } // for()
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3076 }
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3077
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3078
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3079 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3080 // calc_tissues
0
heinrichsweikamp
parents:
diff changeset
3081 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3082 // INPUT: ppN2 partial pressure of inspired N2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3083 // ppHe partial pressure of inspired He
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3084 // tissue_increment integration time and tissue selector (real or simulated)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3085 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3086 // MODIFIED: real_pres_tissue_N2[] tissue N2 pressures (in real tissues context)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3087 // real_pres_tissue_He[] tissue He pressures (in real tissues context)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3088 // sim_pres_tissue_N2[] tissue N2 pressures (in simulated tissues context)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3089 // sim_pres_tissue_He[] tissue He pressures (in simulated tissues context)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3090 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3091 // 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
3092 // 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
3093 // 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
3094 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3095 static void calc_tissues()
0
heinrichsweikamp
parents:
diff changeset
3096 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3097 overlay unsigned char period;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3098 overlay float temp_tissue_N2;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3099
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3100 #ifdef _helium
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3101 overlay float temp_tissue_He;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3102 #endif
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3103
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3104
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3105 assert( 0.00 <= ppN2 && ppN2 < 11.2 ); // 80% N2 at 130m
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3106 assert( 0.00 <= ppHe && ppHe < 12.6 ); // 90% He at 130m
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3107
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3108
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3109 for( ci=0; ci < NUM_COMP; ci++ ) // iterate through all compartments
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3110 {
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3111 i = tissue_increment & TIME_MASK; // extract number of minutes to do (if i > 0)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3112 // or if one 2 second period is to do (if i = 0)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3113
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3114 if( i == 0 ) // check if we shall do one 2-seconds period
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3115 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3116 read_Buhlmann_times(0); // YES - program coefficients for a 2 seconds period
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3117 period = 1; // - set period length (in cycles)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3118 i = 1; // - and one cycle to do
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3119 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3120 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
3121 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3122 read_Buhlmann_times(2); // YES - program coefficients for 10 minutes periods
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3123 period = 10; // set period length (in cycles) to ten
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3124 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3125 else // last but not lease, do 1 to 9 minutes
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3126 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3127 read_Buhlmann_times(1); // NO - program coefficients for 1 minute periods
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3128 period = 1; // - set period length (in cycles) to one
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3129 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3130
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3131 do
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3132 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3133 //---- N2 --------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3134
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3135 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
3136
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3137 temp_tissue = (ppN2 - temp_tissue) * var_N2_e;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3138
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3139 apply_saturation_factors();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3140
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3141 if( tissue_increment & TISSUE_SELECTOR )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3142 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3143 temp_tissue_N2 = temp_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3144 real_pres_tissue_N2[ci] += temp_tissue;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3145 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3146 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3147 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3148 sim_pres_tissue_N2[ci] += temp_tissue;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3149 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3150
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3151 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3152 //---- He --------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3153
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3154 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
3155
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3156 temp_tissue = (ppHe - temp_tissue) * var_He_e;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3157
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3158 apply_saturation_factors();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3159
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3160 if( tissue_increment & TISSUE_SELECTOR )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3161 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3162 temp_tissue_He = temp_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3163 real_pres_tissue_He[ci] += temp_tissue;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3164 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3165 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3166 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3167 sim_pres_tissue_He[ci] += temp_tissue;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3168 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3169 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3170
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3171 //---- decrement loop counter and adjust step size ---------------
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3172
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3173 // decrement loop counter
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3174 i -= period;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3175
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3176 // 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
3177 if( (i > 0) && (period = 10) && (i < 10) )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3178 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3179 read_Buhlmann_times(1); // program coefficients for 1 minute periods
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3180 period = 1; // set period length (in cycles) to one
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3181 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3182 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3183 while( i );
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3184
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3185
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3186 // have the computations been done for the "real" tissues?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3187 if( tissue_increment & TISSUE_SELECTOR )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3188 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3189
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3190 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3191
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3192 // net tissue balance
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3193 temp_tissue = temp_tissue_N2 + temp_tissue_He;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3194
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3195
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3196 // 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
3197 //
584
d63dec562d50 CNS fix
heinrichsweikamp
parents: 582
diff changeset
3198 if ( temp_tissue < -HYST ) // check if the tissue is off-gassing
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3199 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3200 // tag tissue as not experiencing mentionable IBCD
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3201 IBCD_tissue_vector &= ~(1 << ci);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3202 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3203 else if ( temp_tissue > +HYST ) // check if the tissue in on-gassing
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3204 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3205 // check for counter diffusion
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3206 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
3207 || ((temp_tissue_N2 < 0.0) && (temp_tissue_He > 0.0)) )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3208 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3209 // tag tissue as experiencing mentionable IBCD
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3210 IBCD_tissue_vector |= (1 << ci);
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3211 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3212 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3213
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3214 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3215
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3216 // For N2 tissue pressure display purpose:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3217
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3218 // basically keep the on-gassing / off-gassing flag from last invocation, but flip
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3219 // 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
3220 char_O_tissue_pres_N2[ci] &= 128;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3221 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
3222 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
3223
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3224 // scale N2 tissue pressure such that the surface steady-state tissue loading
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3225 // of [0.7902 * (1013 hPa - ppWater)] bar will give a 8, which aligns with
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3226 // the 2nd scale line.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3227 temp_tissue_N2 = (8 / (0.7902 * (1.013 - ppWater))) * real_pres_tissue_N2[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3228
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3229 // limit to 127 to protect the uppermost bit which holds the sat/desat flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3230 if (temp_tissue_N2 > 127) temp_tissue_N2 = 127;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3231
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3232 // convert to integer and combine with sat/desat flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3233 char_O_tissue_pres_N2[ci] += (unsigned char)temp_tissue_N2;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3234
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3235 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3236
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3237 // For He tissue pressure display purpose:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3238
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3239 // basically keep the on-gassing / off-gassing flag from last invocation, but flip
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3240 // 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
3241 char_O_tissue_pres_He[ci] &= 128;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3242 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
3243 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
3244
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3245 // scale He tissue pressure alike it is done for N2.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3246 // With no He in a tissue, the result will be 0.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3247 temp_tissue_He = (8 / (0.7902 * (1.013 - ppWater))) * real_pres_tissue_He[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3248
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3249 // limit to 127 to protect the uppermost bit which holds the sat/desat flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3250 if (temp_tissue_He > 127) temp_tissue_He = 127;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3251
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3252 // convert to integer and combine with sat/desat flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3253 char_O_tissue_pres_He[ci] += (unsigned char)temp_tissue_He;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3254
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3255
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3256 // For combined tissue pressure display purpose:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3257
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3258 // basically keep the on-gassing / off-gassing flag from last invocation, but flip
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3259 // 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
3260 char_O_tissue_pressure[ci] &= 128;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3261 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
3262 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
3263
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3264 // add the two scaled pressures.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3265 temp_tissue = temp_tissue_N2 + temp_tissue_He;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3266
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3267 // 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
3268 if (temp_tissue > 127) temp_tissue = 127;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3269
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3270 // convert to integer and combine with sat/desat flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3271 char_O_tissue_pressure[ci] += (unsigned char)temp_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3272
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3273 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3274
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3275 // He tissue pressure is zero
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3276 char_O_tissue_pres_He[ci] = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3277
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3278 // combined tissue pressure equals N2 tissue pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3279 char_O_tissue_pressure[ci] = char_O_tissue_pres_N2[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3280
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3281 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3282
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3283 } //if
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3284
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3285 } // for
0
heinrichsweikamp
parents:
diff changeset
3286 }
heinrichsweikamp
parents:
diff changeset
3287
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3288
0
heinrichsweikamp
parents:
diff changeset
3289 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
3290 // calc_limit
heinrichsweikamp
parents:
diff changeset
3291 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3292 // Input: GF_parameter gradient factor to be used, negative values activate surface mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3293 // tissue_increment selector for context: real or simulated tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3294 // sim_pres_tissue_N2/_He tissue pressures (used in simulated tissues context)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3295 // real_pres_tissue_N2/_He tissue pressures (used in real tissues context)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3296 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3297 // Output: lead_supersat highest supersaturation found among all tissues, 1.0 = 100%
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3298 // lead_tissue number of the leading tissue (0-15)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3299 // ceiling ceiling in bar relative pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3300 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3301 // 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
3302 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3303 static void calc_limit(PARAMETER float GF_parameter)
0
heinrichsweikamp
parents:
diff changeset
3304 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3305 overlay float pres_respiration_min_total = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3306 overlay unsigned char surface_mode = 0; // 0: off, 1: on
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3307
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3308
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3309 // check mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3310 if( GF_parameter < 0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3311 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3312 // activate surface mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3313 surface_mode = 1;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3314
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3315 // normalize parameter
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3316 GF_parameter = -GF_parameter;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3317 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3318
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3319 // set leading tissue number to tissue 1 (it has the index 0)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3320 lead_tissue = 0;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3321
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3322 // initialize leading tissue supersaturation value to null
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3323 lead_supersat = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3324
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3325 // next code section is relevant only when invoked on the real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3326 if( tissue_increment & TISSUE_SELECTOR )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3327 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3328 // clear IBCD, micro-bubbles and outside warning flags (locked warnings will be preserved)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3329 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
3330 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3331
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3332 // loop over all tissues
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3333 for( ci = 0; ci < NUM_COMP; ci++ )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3334 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3335 overlay float pres_respiration_min_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3336
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3337
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3338 // get the coefficients for tissue ci
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3339 read_Buhlmann_coefficients();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3340
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3341 #ifdef _helium
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3342
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3343 // get the tissue pressures
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3344 // adopt_Buhlmann_coefficients needs calc_pres_tissue_N2/He when compiled for helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3345 if( tissue_increment & TISSUE_SELECTOR )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3346 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3347 // context is real tissues
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3348 calc_pres_tissue_N2 = real_pres_tissue_N2[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3349 calc_pres_tissue_He = real_pres_tissue_He[ci];
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3350 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3351 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3352 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3353 // context is simulated tissues
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3354 calc_pres_tissue_N2 = sim_pres_tissue_N2[ci];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3355 calc_pres_tissue_He = sim_pres_tissue_He[ci];
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3356 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3357
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3358 // overall tissue pressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3359 pres_tissue = calc_pres_tissue_N2 + calc_pres_tissue_He;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3360
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3361 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3362
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3363 // get the tissue pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3364 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
3365
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3366 #endif
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3367
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3368 // 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
3369 adopt_Buhlmann_coefficients();
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3370
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3371 // next calculations are only relevant when invoked on the real tissues
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3372 if( tissue_increment & TISSUE_SELECTOR )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3373 {
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3374 overlay float pres_tissue_max;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3375 overlay float supersat;
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
3376 overlay float baseline_threshold;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3377
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3378
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3379 // check if tissue is in supersaturation
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3380 if( pres_tissue > real_pres_respiration )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3381 {
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3382 // calculate maximum allowed tissue pressure at current ambient pressure
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3383 pres_tissue_max = real_pres_respiration / var_b + var_a;
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3384
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3385 // 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
3386 supersat = ( pres_tissue - real_pres_respiration )
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3387 / ( pres_tissue_max - real_pres_respiration );
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3388
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3389 // calculate supersaturation value for display purpose: 1.35 = 135% = 86 pixel
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3390 if( supersat <= 1.35 ) char_O_tissue_saturation[ci] = (unsigned char)(supersat * 64);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3391 else char_O_tissue_saturation[ci] = 86;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3392
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3393 // memorize highest supersaturation found
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3394 if( supersat > lead_supersat ) lead_supersat = supersat;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3395
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
3396 // tissue-dependent baseline threshold for micro bubbles and outside warnings
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
3397 baseline_threshold = 0.02 * ci + 1.0;
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
3398
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
3399 // micro bubbles warning: supersaturation > baseline threshold
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
3400 if( supersat > baseline_threshold )
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3401 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
3402
608
d866684249bd work on 2.99 stable
heinrichsweikamp
parents: 604
diff changeset
3403 // outside warning: supersaturation > baseline threshold + additional 5% margin
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3404 if( supersat > (baseline_threshold + 0.05) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3405 deco_warnings |= (DECO_WARNING_OUTSIDE + DECO_WARNING_OUTSIDE_lock );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3406 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3407 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3408 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3409 // supersaturation is defined as zero while tissue pressure <= ambient pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3410 supersat = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3411 char_O_tissue_saturation[ci] = 0;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3412 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3413
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3414 // next only when in surface mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3415 if( surface_mode )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3416 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3417 // tag tissue whether it is beyond the M-line limit or not
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3418 if( supersat > 1.0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3419 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3420 char_O_tissue_pres_N2[ci] |= 128;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3421 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3422 char_O_tissue_pres_He[ci] |= 128;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3423 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3424 char_O_tissue_pressure[ci] |= 128;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3425 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3426 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3427 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3428 char_O_tissue_pres_N2[ci] &= ~128;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3429 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3430 char_O_tissue_pres_He[ci] &= ~128;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3431 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3432 char_O_tissue_pressure[ci] &= ~128;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3433 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3434 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3435 } // real tissues
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3436
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3437 // calculate the minimum ambient pressure that the tissue can withstand
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3438 if( char_I_deco_model == 0 )
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3439 {
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3440 // straight Buhlmann
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3441 pres_respiration_min_tissue = (pres_tissue - var_a) * var_b;
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3442 }
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3443 else
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3444 {
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3445 // Buhlmann with Eric Baker's varying gradient factor correction
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3446 // note: this equation [1] is the inverse of equation [2]
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3447 pres_respiration_min_tissue = ( pres_tissue - (var_a * GF_parameter) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3448 / ( 1.0 - GF_parameter + (GF_parameter / var_b ) );
618
7b3903536213 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
3449 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3450
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3451 // check if this tissue requires a higher ambient pressure than was found to be needed up to now
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3452 if( pres_respiration_min_tissue > pres_respiration_min_total )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3453 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3454 pres_respiration_min_total = pres_respiration_min_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3455 lead_tissue = ci;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3456 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3457 } // for
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3458
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3459 // compute ceiling for the real tissues in bar relative pressure
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3460 ceiling = pres_respiration_min_total - pres_surface;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3461
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3462 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3463 // IBCD is checked for real tissues only
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3464 if( tissue_increment & TISSUE_SELECTOR )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3465 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3466 // check if the leading tissue is in IBCD condition
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3467 if( (IBCD_tissue_vector & (1 << lead_tissue))
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3468 && ((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
3469 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3470 // leading tissue is in IBCD condition and in super-saturation, so issue a warning.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3471 deco_warnings |= (DECO_WARNING_IBCD + DECO_WARNING_IBCD_lock);
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3472 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3473 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3474 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3475
0
heinrichsweikamp
parents:
diff changeset
3476 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3477
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3478
0
heinrichsweikamp
parents:
diff changeset
3479 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3480 // calc_NDL_time_tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3481 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3482 // calculation of the remaining no decompression limit (NDL) time for a tissue
0
heinrichsweikamp
parents:
diff changeset
3483 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3484 // NOTE: Erik Baker's closed formula works for Nitrox. Trimix adds a second
0
heinrichsweikamp
parents:
diff changeset
3485 // exponential term to the M-value equation, making it impossible to
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3486 // invert. So we have to solve the problem with a search approach.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3487 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3488 // Input: NDL_tissue tissue for which to calculate remaining NDL time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3489 // GF_high gradient factor used when GF factors are enabled
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3490 // ppN2, ppHe partial pressures of N2 and He breathed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3491 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3492 // Modified: NDL_time shortest NDL time found so far
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3493 // NDL_tissue_lead leading tissue, i.e. tissue with the shortest NDL
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3494 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3495 static void calc_NDL_time_tissue(void)
0
heinrichsweikamp
parents:
diff changeset
3496 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3497 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
3498 overlay unsigned char step_size = 10; // step size in searching, starting with 10 minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3499 overlay float pres_limit; // max. tissue pressure allowed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3500
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3501 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3502 overlay float last_pres_tissue_N2; // last tissue pressure for N2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3503 overlay float last_pres_tissue_He; // last tissue pressure for He
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3504 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3505 overlay float last_pres_tissue; // last tissue pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3506 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3507
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3508
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3509 // set the compartment index ci for reading the Buhlmann increments and coefficients
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3510 ci = NDL_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3511
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3512 // read the tissue increments for a step size of 10 minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3513 read_Buhlmann_times(2);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3514
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3515 // read Buhlmann a and b coefficients for tissue ci
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3516 read_Buhlmann_coefficients();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3517
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3518 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3519
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3520 // get the current simulated tissue pressures
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3521 calc_pres_tissue_N2 = last_pres_tissue_N2 = sim_pres_tissue_N2[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3522 calc_pres_tissue_He = last_pres_tissue_He = sim_pres_tissue_He[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3523
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3524 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3525
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3526 // get the current simulated tissue pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3527 pres_tissue = last_pres_tissue = sim_pres_tissue_N2[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3528
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3529 // set the a and b coefficients
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3530 adopt_Buhlmann_coefficients();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3531
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3532 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3533
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3534 // simulate an increasing bottom time and check when the NDL is hit
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3535 for(;;)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3536 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3537
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3538 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3539
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3540 // calculate the total tissue pressure
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3541 pres_tissue = calc_pres_tissue_N2 + calc_pres_tissue_He;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3542
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3543 // adopt a and b coefficients to current N2/He ratio inside the tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3544 adopt_Buhlmann_coefficients();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3545
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3546 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3547
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3548 // compute the maximum tissue pressure allowed to be exposed to an
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3549 // ambient pressure equaling the surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3550 if( char_I_deco_model != 0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3551 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3552 // GF model enabled, this equation [2] is the inverse of equation [1]
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3553 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
3554 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3555 else
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3556 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3557 // straight Buhlmann
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3558 pres_limit = pres_surface / var_b + var_a;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3559 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3560
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3561 // is the tissue pressure higher than the maximum tissue pressure allowed?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3562 if( pres_tissue > pres_limit)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3563 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3564 // YES - tissue is outside NDL
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3565
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3566 // was the tissue outside NDL right from the start?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3567 if( NDL_time_tissue == 0 )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3568 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3569 // YES - search can be aborted
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3570
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3571 // at least one tissue is outside NDL, so overall NDL time is zero
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3572 NDL_time = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3573
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3574 // store the number of this tissue as being the leading one
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3575 NDL_tissue_lead = NDL_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3576
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3577 // done
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3578 break;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3579 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3580
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3581 // when code execution passes here, the tissue has become
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3582 // being outside NDL after doing one or more search steps
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3583
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3584 // still searching with a step size of 10 minutes?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3585 if( step_size == 10 )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3586 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3587 // YES - retry with smaller step size
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3588
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3589 // go back to last NDL time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3590 NDL_time_tissue -= 10;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3591
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3592 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3593
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3594 // go back to last pressures
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3595 calc_pres_tissue_N2 = last_pres_tissue_N2;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3596 calc_pres_tissue_He = last_pres_tissue_He;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3597
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3598 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3599
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3600 // go back to last pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3601 pres_tissue = last_pres_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3602
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3603 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3604
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3605 // reduce step size to 1 minute
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3606 step_size = 1;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3607
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3608 // read the tissue increments for a step size of 1 minute
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3609 read_Buhlmann_times(1);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3610
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3611 // redo search from last pressure & time within NDL with smaller step size
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3612 continue;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3613 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3614 else
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3615 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3616 // NO - already tried with a step size of 1 minute
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3617
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3618 // go back to last NDL time that was within NDL
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3619 NDL_time_tissue -= 1;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3620
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3621 // 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
3622 if( NDL_time_tissue < NDL_time )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3623 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3624 // YES - set this tissue's NDL time as the new overall NDL time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3625 NDL_time = NDL_time_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3626
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3627 // - store the number of this tissue as being the leading one
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3628 NDL_tissue_lead = NDL_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3629 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3630
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3631 // done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3632 break;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3633 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3634 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3635 else
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3636 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3637 // NO - tissue is still within NDL
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3638
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3639 // The search can be terminated when the NDL time of this tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3640 // exceeds the overall NDL time, thus when a shorter NDL time has
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3641 // already been found with another tissue.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3642 if( NDL_time_tissue >= NDL_time ) break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3643
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3644 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3645
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3646 // back-up current tissue pressures
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3647 last_pres_tissue_N2 = calc_pres_tissue_N2;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3648 last_pres_tissue_He = calc_pres_tissue_He;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3649
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3650 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3651
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3652 // back-up current tissue pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3653 last_pres_tissue = pres_tissue;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3654
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3655 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3656
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3657 // step forward NDL time of current tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3658 NDL_time_tissue += step_size;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3659
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3660 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3661
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3662 // step forward tissue pressure - N2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3663 temp_tissue = (ppN2 - calc_pres_tissue_N2) * var_N2_e; // pressure delta breathed - tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3664 apply_saturation_factors(); // apply safety factor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3665 calc_pres_tissue_N2 += temp_tissue; // add pressure delta to tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3666
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3667 // step forward tissue pressure - He
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3668 temp_tissue = (ppHe - calc_pres_tissue_He) * var_He_e; // pressure delta breathed - tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3669 apply_saturation_factors(); // apply safety factor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3670 calc_pres_tissue_He += temp_tissue; // add pressure delta to tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3671
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3672 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3673
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3674 // step forward tissue pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3675 temp_tissue = (ppN2 - pres_tissue ) * var_N2_e; // pressure delta breathed - tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3676 apply_saturation_factors(); // apply safety factor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3677 pres_tissue += temp_tissue; // add pressure delta to tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3678
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3679 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3680
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3681 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3682 }
0
heinrichsweikamp
parents:
diff changeset
3683 }
heinrichsweikamp
parents:
diff changeset
3684
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3685
0
heinrichsweikamp
parents:
diff changeset
3686 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
3687 // calc_ascenttime
heinrichsweikamp
parents:
diff changeset
3688 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3689 // Sum up ascent from bottom to surface at char_I_ascent_speed, slowing down
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3690 // to 1 minute per meter for the final ascent when in deco, and all stop times.
0
heinrichsweikamp
parents:
diff changeset
3691 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3692 // Input: char_I_depth_last_deco
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3693 // char_I_ascent_speed
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3694 // char_depth_bottom
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3695 // internal_deco_depth[]
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3696 // internal_deco_time[]
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3697 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3698 // Output: ascent_time
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3699 //
0
heinrichsweikamp
parents:
diff changeset
3700 static void calc_ascenttime(void)
heinrichsweikamp
parents:
diff changeset
3701 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3702 // check if there are stops
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3703 if( internal_deco_depth[0] )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3704 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3705 // YES - stops / in deco
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3706
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3707 // check if already at last stop depth or shallower
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3708 if( char_depth_bottom <= char_I_depth_last_deco)
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3709 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3710 // YES - final ascent part only
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3711 ascent_time = char_depth_bottom;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3712 }
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3713 else
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3714 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3715 // NO - ascent part from bottom to last stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3716 ascent_time = (char_depth_bottom - char_I_depth_last_deco) / char_I_ascent_speed + 1;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3717
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3718 // - ascent part from last stop to surface at 1 meter per minute
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3719 ascent_time += char_I_depth_last_deco;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3720 }
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3721
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3722 // add all stop times
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3723 for( i=0; i < NUM_STOPS && internal_deco_depth[i]; i++ )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3724 ascent_time += internal_deco_time[i];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3725
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3726 // limit result to display max.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3727 if( ascent_time > 999) ascent_time = 999;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3728
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3729 // tag result as invalid if there is an overflow in the stops table
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3730 if( deco_warnings & DECO_WARNING_STOPTABLE_OVERFLOW ) ascent_time |= INT_FLAG_INVALID;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3731 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3732 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3733 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3734 // NO - no stops / within NDL
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3735 ascent_time = char_depth_bottom / char_I_ascent_speed + 1;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3736 }
0
heinrichsweikamp
parents:
diff changeset
3737 }
heinrichsweikamp
parents:
diff changeset
3738
heinrichsweikamp
parents:
diff changeset
3739
heinrichsweikamp
parents:
diff changeset
3740 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
3741 // clear_deco_table
heinrichsweikamp
parents:
diff changeset
3742 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3743 // Modified: internal_deco_time[] stop durations
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3744 // internal_deco_depth[] stop depths
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3745 // internal_deco_gas[] gases used at stops
0
heinrichsweikamp
parents:
diff changeset
3746 //
heinrichsweikamp
parents:
diff changeset
3747 static void clear_deco_table(void)
heinrichsweikamp
parents:
diff changeset
3748 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3749 for( i = 0; i < NUM_STOPS; ++i )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3750 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3751 internal_deco_time [i] = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3752 internal_deco_depth[i] = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3753 internal_deco_gas[i] = 0;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3754 }
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3755
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3756 // clear stop table overflow warning
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3757 deco_warnings &= ~DECO_WARNING_STOPTABLE_OVERFLOW;
0
heinrichsweikamp
parents:
diff changeset
3758 }
heinrichsweikamp
parents:
diff changeset
3759
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3760
0
heinrichsweikamp
parents:
diff changeset
3761 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
3762 // update_deco_table
heinrichsweikamp
parents:
diff changeset
3763 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3764 // Add time to a stop at char_depth_sim
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3765 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3766 // 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
3767 // 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
3768 // to have reached the end of the list is depth == 0.
0
heinrichsweikamp
parents:
diff changeset
3769 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3770 // Input: char_depth_sim stop's depth, in meters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3771 // 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
3772 // time_increment number of minutes to add to the stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3773 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3774 // Updated: internal_deco_depth[] depth (in meters) of each stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3775 // internal_deco_time [] time (in minutes) of each stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3776 // internal_deco_gas [] gas used (index 1-5) at each stop
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3777 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3778 static unsigned char update_deco_table(PARAMETER unsigned char time_increment)
0
heinrichsweikamp
parents:
diff changeset
3779 {
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3780 overlay unsigned char x;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3781
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3782 assert( char_depth_sim > 0 ); // no stop at surface
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3783
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3784 // loop through internal deco table
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3785 for( x = 0; x < NUM_STOPS; ++x )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3786 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3787 // In case the first deco stop is to be placed deeper than previously recorded
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3788 // stops for gas changes during the initial ascent (this may happen because the
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3789 // deco stops are placed at the next deeper multiple of 3 meters instead of the
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3790 // real stop's depth), relocate the deco stop to the depth of the last gas change.
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3791 // The resulting combined stop's duration will be the sum of the configured gas
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3792 // change time plus the duration of the deco stop itself.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3793 if( internal_deco_depth[x] && (char_depth_sim > internal_deco_depth[x]) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3794 char_depth_sim = internal_deco_depth[x];
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3795
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3796 // Is there already a stop entry for our current depth?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3797 if( internal_deco_depth[x] == char_depth_sim )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3798 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3799 // Yes - increment stop time if possible
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3800 // Stop time entries are limited to 99 minutes because of display constraints.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3801 if( internal_deco_time[x] < (100 - time_increment) )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3802 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3803 internal_deco_time[x] += time_increment; // increment stop time
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3804 return 1; // return with status 'success'
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3805 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3806 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3807
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3808 // If program flow passes here, there is either no stop entry for the current depth yet, or
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3809 // the existing entry is saturated with 99 minutes. So we are looking for the next unused
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3810 // table entry.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3811 if( internal_deco_depth[x] == 0 )
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3812 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3813 internal_deco_time[x] = time_increment; // initialize entry with first stop's time,
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3814 internal_deco_depth[x] = char_depth_sim; // ... depth, and
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3815 internal_deco_gas[x] = sim_gas_current_num; // ... gas
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3816 return 1; // return with status 'success'
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3817 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3818 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3819
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3820 // If program flow passes here, all deco table entries are used up.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3821
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3822 // set overflow warning
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3823 deco_warnings |= DECO_WARNING_STOPTABLE_OVERFLOW;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3824
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3825 // return with status 'failed'.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3826 return 0;
0
heinrichsweikamp
parents:
diff changeset
3827 }
heinrichsweikamp
parents:
diff changeset
3828
heinrichsweikamp
parents:
diff changeset
3829
heinrichsweikamp
parents:
diff changeset
3830 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3831 // calc_desaturation_time_helper
0
heinrichsweikamp
parents:
diff changeset
3832 //
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3833 // Helper function
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3834 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3835 // Input: pres_actual current tissue pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3836 // pres_target target tissue pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3837 // var_ht half-time of the tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3838 // desat_factor desaturation factor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3839 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3840 // Output: int_time time needed by tissue to reach target pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3841 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3842 static void calc_desaturation_time_helper(void)
0
heinrichsweikamp
parents:
diff changeset
3843 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3844 // check if actual pressure is higher then target pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3845 if( pres_actual > pres_target )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3846 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3847 // YES - compute remaining time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3848
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3849 overlay float pres_ratio;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3850
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3851 // compute pressure ratio to archive
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3852 pres_ratio = pres_actual / pres_target;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3853
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3854 // Compute desaturation time with result rounded up to multiples of 10 minutes.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3855 // 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
3856 // one minute steps any more but get constantly re-computed according to current
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3857 // 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
3858 // backwards as ambient pressure rises/falls and N2/He ratio is being adjusted.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3859 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
3860 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3861 else
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3862 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3863 // NO - desaturation state reached, no remaining time
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3864 int_time = 0;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3865 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3866 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3867
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3868
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3869 /////////////////////////////////////////////////////////////////////////////
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3870 // calc_desaturation_time
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3871 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3872 // Calculates the time needed for the tissues to equilibrate with
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3873 // surface pressure and the no-fly / no-altitude time.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3874 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3875 // Input: int_I_pres_surface
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3876 // char_I_desaturation_multiplier
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3877 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3878 // Output: int_O_desaturation_time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3879 // int_O_nofly_time
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3880 //
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3881 void calc_desaturation_time(void)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3882 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3883 overlay float P_ambient_altitude;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3884
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3885 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
3886 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
3887
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
3888
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3889 // safeguard and convert surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3890 if( int_I_pres_surface < 500) pres_surface = 0.5;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3891 else pres_surface = 0.001 * int_I_pres_surface;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3892
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3893 // calculate partial pressure of N2 in respired air at surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3894 calc_N2_equilibrium();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3895
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3896 // get, safeguard and convert the saturation and desaturation factors
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3897 get_saturation_factors();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3898
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3899 // 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
3900 desat_factor = (6.931 * SURFACE_DESAT_FACTOR) * float_desaturation_multiplier;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3901
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3902 // initialize vars
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3903 int_O_desaturation_time = 0;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3904 int_O_nofly_time = 0;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3905
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3906 // get selected target altitude
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3907 switch( char_I_altitude_wait )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3908 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3909 case 1: P_ambient_altitude = P_ambient_1000m; break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3910 case 2: P_ambient_altitude = P_ambient_2000m; break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3911 case 3: P_ambient_altitude = P_ambient_3000m; break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3912 default: P_ambient_altitude = P_ambient_fly; break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3913 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3914
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3915 // 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
3916 for( ci = NUM_COMP; ci > 0; )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3917 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3918 overlay float pres_tissue_max;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3919 overlay unsigned short nofly_last = ~0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3920 overlay unsigned short nofly_N2 = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3921
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3922 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3923 overlay signed char search_direction;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3924 overlay unsigned short nofly_He = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3925 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3926
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3927
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3928 // decrement compartment index
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3929 ci -= 1;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3930
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3931 // get the Buhlmann halftimes and coefficients
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3932 read_Buhlmann_ht();
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3933 read_Buhlmann_coefficients();
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3934
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3935
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3936 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3937 // Desaturation time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3938 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3939
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3940 // calculate desaturation time for N2 in tissue,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3941 // desaturated state is defined as residual tissue pressure <= 1.05 x ppN2 respired
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3942
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3943 // current tissue pressure above equilibrium pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3944 pres_actual = real_pres_tissue_N2[ci] - N2_equilibrium;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3945
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3946 // target pressure above equilibrium pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3947 pres_target = 0.05 * N2_equilibrium;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3948
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3949 // half-time of the current tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3950 var_ht = var_N2_ht;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3951
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3952 // calculate desaturation time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3953 calc_desaturation_time_helper();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3954
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3955 // store desaturation time if it is longer than longest found so far
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3956 if( int_time > int_O_desaturation_time) int_O_desaturation_time = int_time;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3957
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3958
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3959 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3960
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3961 // calculate desaturation time for He in the tissue,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3962 // desaturated state is defined as residual tissue pressure <= 0.05 x ppN2 respired
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3963
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3964 // actual tissue pressure above equilibrium: equilibrium for He is 0 bar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3965 pres_actual = real_pres_tissue_He[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3966
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3967 // target pressure above equilibrium pressure: use same target pressure as for N2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3968 pres_target = 0.05 * N2_equilibrium;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3969
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3970 // half-time of the current tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3971 var_ht = var_He_ht;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3972
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3973 // calculate desaturation time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3974 calc_desaturation_time_helper();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3975
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3976 // store desaturation time if it is longer than longest found so far
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3977 if( int_time > int_O_desaturation_time) int_O_desaturation_time = int_time;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3978
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3979 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3980
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3981 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3982 // no-fly time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3983 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3984
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
3985 // 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
3986 // 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
3987 // 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
3988 // safe side, too.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3989 pres_tissue_max = (P_ambient_altitude/var_N2_b + var_N2_a);
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
3990
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3991 // 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
3992 // for the no-fly time as it's target pressure is hard to reach anyhow
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3993 if( char_I_deco_model && char_I_altitude_wait )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3994 pres_tissue_max = P_ambient_altitude +
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3995 0.01 * char_I_GF_High_percentage * (pres_tissue_max - P_ambient_altitude);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3996
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3997
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3998 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
3999
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4000 //---- Variant with Helium -------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4001
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4002 // 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
4003 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
4004
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4005 // initialize search direction
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4006 search_direction = 0;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4007
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4008 for(;;)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4009 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4010 // Calculate no-fly time for N2 in the tissue.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4011 // 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
4012
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4013 // current tissue pressure above equilibrium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4014 pres_actual = real_pres_tissue_N2[ci] - N2_equilibrium;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4015
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4016 // target pressure above equilibrium pressure, weighted by N2/He split
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4017 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
4018
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4019 // half-time of the current tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4020 var_ht = var_N2_ht;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4021
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4022 // check if desaturation to target pressure is possible at all
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4023 if( pres_target < 0.0 )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4024 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4025 // NO - set no-fly time to 288 * 10 min = 48 h
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4026 int_O_nofly_time = 288;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4027 break;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4028 }
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4029 else
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4030 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4031 // YES - calculate desaturation time
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4032 calc_desaturation_time_helper();
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4033
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4034 // store time found
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4035 nofly_N2 = int_time;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4036 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4037
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4038 // calculate no-fly time for He in the tissue,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4039 // flying is permitted when the He pressure fits into the assigned fraction
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4040
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4041 // current tissue pressure above equilibrium: equilibrium for He is 0 bar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4042 pres_actual = real_pres_tissue_He[ci];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4043
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4044 // target pressure above equilibrium pressure, weighted by N2/He split
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4045 pres_target = ((100 - split_N2_He[ci]) * 0.01) * (pres_tissue_max - N2_equilibrium);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4046
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4047 // half-time of the current tissue
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4048 var_ht = var_He_ht;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4049
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4050 // calculate desaturation time
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4051 calc_desaturation_time_helper();
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4052
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4053 // store time found
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4054 nofly_He = int_time;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4055
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4056
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4057 // 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
4058 // 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
4059 // 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
4060 // 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
4061 // 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
4062 // 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
4063 // 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
4064 // at best.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4065
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4066 // 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
4067 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
4068
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4069 // check if the N2 requires more waiting time than the He
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4070 if( nofly_N2 >= nofly_He )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4071 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4072 // 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
4073 // 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
4074 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
4075 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4076 // 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
4077 // 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
4078 int_O_nofly_time = (nofly_N2 < nofly_last) ? nofly_N2 : nofly_last;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4079
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4080 // done
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4081 break;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4082 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4083
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4084 // store the no-fly time found in this iteration
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4085 nofly_last = nofly_N2;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4086
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4087 // increase the N2 fraction of the split
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4088 split_N2_He[ci] += 1;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4089
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4090 // set search direction towards more N2
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4091 search_direction = +1;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4092 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4093 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4094 {
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4095 // 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
4096 // 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
4097 if( (search_direction > 0) || (split_N2_He[ci] == 1) )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4098 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4099 // 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
4100 // 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
4101 int_O_nofly_time = (nofly_He < nofly_last) ? nofly_He : nofly_last;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4102
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4103 // done
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4104 break;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4105 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4106
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4107 // store the no-fly time found in this iteration
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4108 nofly_last = nofly_He;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4109
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4110 // decrease the N2 fraction of the split
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4111 split_N2_He[ci] -= 1;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4112
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4113 // set search direction towards less N2
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4114 search_direction = -1;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4115 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4116
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4117 } // for(;;)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4118
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4119 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4120
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4121 //---- Variant without Helium ----------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4122
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4123 // current tissue pressure above equilibrium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4124 pres_actual = real_pres_tissue_N2[ci] - N2_equilibrium;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4125
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4126 // target pressure above equilibrium pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4127 pres_target = pres_tissue_max - N2_equilibrium;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4128
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4129 // half-time of the current tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4130 var_ht = var_N2_ht;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4131
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4132 // check if desaturation to target pressure is possible at all
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4133 if( pres_target < 0.0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4134 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4135 // NO - set no-fly time to 288 * 10 min = 48 h
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4136 int_O_nofly_time = 288;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4137 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4138 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4139 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4140 // YES - calculate desaturation time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4141 calc_desaturation_time_helper();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4142
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4143 // - extend desaturation time if this tissue needs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4144 // more time than already found to be needed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4145 if( int_time > int_O_nofly_time ) int_O_nofly_time = int_time;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4146 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4147
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4148 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4149
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4150 } // for(compartments)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4151
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4152
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4153 // 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
4154 int_O_desaturation_time *= 10;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4155 int_O_nofly_time *= 10;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4156
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4157 // 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
4158 // because of display space constraints and rounding done above
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4159 if( int_O_desaturation_time > 5999 ) int_O_desaturation_time = 5999;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4160 if( int_O_nofly_time > 5999 ) int_O_nofly_time = 5999;
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4161
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4162
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4163 // 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
4164 // 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
4165 // 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
4166 // attention color instead of warning color.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4167 if( int_O_lead_supersat < 100 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4168 deco_warnings &= ~DECO_WARNING_MBUBBLES;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4169
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4170 // clear some warnings when the desaturation time has become zero
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4171 if( int_O_desaturation_time == 0 )
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4172 deco_warnings &= ~( DECO_WARNING_IBCD + DECO_WARNING_IBCD_lock
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4173 + DECO_WARNING_MBUBBLES + DECO_WARNING_MBUBBLES_lock
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4174 + DECO_WARNING_OUTSIDE + DECO_WARNING_OUTSIDE_lock
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4175 + DECO_ATTENTION_OUTSIDE );
0
heinrichsweikamp
parents:
diff changeset
4176 }
heinrichsweikamp
parents:
diff changeset
4177
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4178
0
heinrichsweikamp
parents:
diff changeset
4179 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4180 // Calculate desaturation of the real tissues for a given time interval
0
heinrichsweikamp
parents:
diff changeset
4181 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4182 // Caution: Works on the real tissues!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4183 // If in doubt, use this function only inside a context surrounded with
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4184 // push_tissues_to_vault() / pull_tissues_from_vault() !
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4185 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4186 // Input: int_I_pres_surface surface pressure in mbar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4187 // time_interval time interval in minutes, must be limited to 254 at max
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4188 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4189 // Modified: tissue pressures N2 and He pressures of the tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4190 // CNS_fraction_real current real CNS value
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4191 // ceiling minimum allowed depth in mbar relative pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4192 // lead_supersat supersaturation of the leading tissue (float)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4193 // int_O_lead_supersat supersaturation of the leading tissue (integer)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4194 //
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4195 static void calc_interval(PARAMETER unsigned char time_interval)
0
heinrichsweikamp
parents:
diff changeset
4196 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4197 overlay unsigned char time;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4198
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4199 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
4200 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
4201 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
4202
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4203
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4204 // safeguard and convert surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4205 if( int_I_pres_surface < 500) pres_surface = 0.500;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4206 else pres_surface = 0.001 * int_I_pres_surface;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4207
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4208 // set breathed pressure to surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4209 real_pres_respiration = pres_surface;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4210
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4211 // calculate partial pressure of N2 in respired air at surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4212 calc_N2_equilibrium();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4213
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4214 // calculate partial pressures (0.7902 is fraction of N2 in atmosphere as of Buhlmann)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4215 ppN2 = N2_equilibrium;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4216 ppHe = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4217
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4218 // get, safeguard and convert the saturation and desaturation factors
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4219 get_saturation_factors();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4220
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4221 // adjust desaturation factor to surface mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4222 float_desaturation_multiplier *= SURFACE_DESAT_FACTOR;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4223
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4224 // Calculate the tissues:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4225 // Because calc_tissues() can calculate for 127 minutes at max,
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4226 // the tissue updating may need to be done in two chunks.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4227
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4228 time = time_interval;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4229
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4230 // first chunk for the part exceeding 127 minutes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4231 if( time > 127)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4232 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4233 // do a full 127 minutes on the real tissues
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4234 tissue_increment = TISSUE_SELECTOR | 127;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4235 calc_tissues();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4236
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4237 // determine the remaining time
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4238 time -= 127;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4239 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4240
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4241 // 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
4242 tissue_increment = TISSUE_SELECTOR | time;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4243
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4244 // update the N2 and He pressures in the tissues
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4245 calc_tissues();
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4246
560
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 // Calculate CNS:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4249 // 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
4250 // 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
4251
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4252 time = time_interval;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4253
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4254 while( time )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4255 {
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4256 if( time > 9 )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4257 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4258 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
4259 time -= 10; // fast speed looping
560
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 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4262 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4263 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
4264 time -= 1; // slow speed looping
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4265 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4266 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4267
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4268 // convert the CNS value to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4269 convert_cur_CNS_for_display();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4270
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4271 // calculate the supersaturation of the leading tissue, the
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4272 // negative argument puts calc_limit() into surface mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4273 // Attention: do not pass char_I_GF_High_percentage as an argument
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4274 // here because it is not configured outside dive mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4275 calc_limit(-1.0);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4276
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4277 // convert the saturation value of the leading tissue to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4278 convert_sat_for_display();
0
heinrichsweikamp
parents:
diff changeset
4279 }
heinrichsweikamp
parents:
diff changeset
4280
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4281
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4282 //////////////////////////////////////////////////////////////////////////////
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4283 // calc_CNS
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4284 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4285 // Input: char_ppO2 current ppO2 [in 0.1 bars]
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4286 // tissue_increment time increment and tissue selector
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4287 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4288 // Modified: CNS_fraction_real accumulated CNS (real tissue context)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4289 // CNS_fraction_sim accumulated CNS (simulated tissue context)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4290 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4291 static void calc_CNS(void)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4292 {
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4293 overlay float CNS_fraction_inc; // increment of CNS load, 0.01 = 1%
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4294
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4295
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4296 // calculate CNS increment for 2 seconds interval
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4297 if( char_ppO2 > 160 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4298 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4299 // step-wise CNS increment
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4300
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4301 // calculate index for increment look-up
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4302 cns_i = (char_ppO2 - 161) / 5; // integer division
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4303
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4304 // read coefficient (increment)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4305 read_CNS_c_coefficient();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4306
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4307 // re-scale coefficient from storage format in [1/100000] to productive value
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4308 CNS_fraction_inc = (float)var_cns_c / 100000.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4309 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4310 else if( char_ppO2 > 50 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4311 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4312 // range wise CNS increment approximation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4313
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4314 // calculate index for approximation coefficients look-up
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4315 cns_i = (char_ppO2 - 51) / 10; // integer division
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4316
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4317 // read coefficients
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4318 read_CNS_ab_coefficient();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4319
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4320 // calculate the CNS increment
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4321 CNS_fraction_inc = 1.0 / (var_cns_a * char_ppO2 + var_cns_b );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4322 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4323 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4324 { // no increment up to 0.5 bar ppO2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4325 CNS_fraction_inc = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4326 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4327
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4328 // apply a time factor in case of minute-based interval (factor = N * 30.0)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4329 if( tissue_increment & TIME_MASK )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4330 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4331 CNS_fraction_inc *= (float)(tissue_increment & TIME_MASK) * 30.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4332 }
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4333
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4334 // update the CNS accumulator
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4335 if ( tissue_increment & TISSUE_SELECTOR ) CNS_fraction_real += CNS_fraction_inc; // real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4336 else CNS_fraction_sim += CNS_fraction_inc; // simulated tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4337 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4338
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4339
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4340 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4341 // calc_due_by_depth_time_sac (Helper Function saving Code Space)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4342 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4343 // Calculates the gas volume required for a given depth, time and usage (SAC)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4344 // 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
4345 // when used through the deco calculator.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4346 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4347 // Input: gas_needs_float_depth depth in meters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4348 // gas_needs_float_time time in minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4349 // gas_needs_stop_usage gas usage in liters per minute at surface pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4350 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4351 // Output: gas_needs_volume_due required gas volume in liters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4352 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4353 static void calc_due_by_depth_time_sac(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4354 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4355 gas_needs_volume_due = (gas_needs_float_depth * METER_TO_BAR + 1.0) * gas_needs_float_time * gas_needs_stop_usage;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4356 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4357
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4358
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4359 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4360 // calc_gas_needs_ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4361 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4362 // calculates the gas needs along the ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4363 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4364 // Input: char_depth_bottom depth of the bottom segment
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4365 // char_I_bottom_time duration of the bottom segment
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4366 // char_I_extra_time extra bottom time for fTTS / delayed ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4367 // float_ascent_speed ascent speed, in meters/minute
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4368 // internal_deco_depth[] depth of the stops
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4369 // internal_deco_time[] duration of the stops
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4370 // internal_deco_gas[] gas breathed at the stops
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4371 // NDL_time remaining NDL time, used to adjust speed of final ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4372 // char_I_SAC_work gas consumption during bottom part and initial ascent, in liters/minute
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4373 // char_I_SAC_deco gas consumption during stops and following ascents, in liters/minute
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4374 // char_I_gas_avail_size[] size of the tanks for gas 1-5, in liters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4375 // char_I_gas_avail_pres[] fill pressure of the tanks
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4376 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4377 // Output: gas_volume_need[] amount of gas needed, in liters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4378 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4379 static void calc_gas_needs_ascent(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4380 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4381 switch (gas_needs_next_phase)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4382 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4383 //---------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4384
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4385 case GAS_NEEDS_INIT:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4386
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4387 // set index to the first stop table entry
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4388 gas_needs_stop_index = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4389
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4390 // clear the gas volume needs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4391 for( i = 0; i < NUM_GAS; ++i ) gas_volume_need[i] = 0.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4392
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4393 #ifdef _rx_functions
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4394 // only for OSTC TR model with TR functions enabled
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4395 if( main_status & TR_FUNCTIONS )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4396 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4397 // invalidate pressure needs to pressure readings
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4398 int_O_pressure_need[0] = 0 + INT_FLAG_NOT_AVAIL;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4399 int_O_pressure_need[1] = 0 + INT_FLAG_NOT_AVAIL;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4400 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4401 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4402
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4403 // terminate if in loop mode (CCR, pSCR) as there are no gas needs to calculate,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4404 // else continue with the gas needs of the bottom segment
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4405 if ( deco_status & MODE_LOOP ) gas_needs_next_phase = GAS_NEEDS_DONE;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4406 else gas_needs_next_phase = GAS_NEEDS_BOTTOM_SEGMENT;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4407
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4408 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4409
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4410 //---------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4411
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4412 case GAS_NEEDS_BOTTOM_SEGMENT:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4413
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4414 // sim_gas_current_num gas used during bottom segment (0, 1-5)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4415 // char_depth_bottom depth of the bottom segment
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4416
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4417 // get the gas used during bottom segment
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4418 gas_find_current();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4419
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4420 // initialize variables
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4421 gas_needs_stop_gas_last = gas_needs_stop_gas = sim_gas_current_num;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4422
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4423 // set the usage (SAC rate) to bottom usage rate for bottom part and initial ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4424 gas_needs_stop_usage = char_I_SAC_work;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4425
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4426 // volumes are only calculated for gases 1-5, but not the manually configured one
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4427 if( gas_needs_stop_gas )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4428 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4429 // set the bottom depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4430 gas_needs_float_depth = (float)char_depth_bottom;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4431
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4432 // calculate either whole bottom time or just the fTTS/bailout extra time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4433 gas_needs_float_time = ( main_status & CALCULATE_BOTTOM ) ? (float)char_I_bottom_time : (float)char_I_extra_time;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4434
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4435 // calculate gas demand
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4436 calc_due_by_depth_time_sac();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4437
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4438 // take result
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4439 gas_volume_need[gas_needs_stop_gas-1] = gas_needs_volume_due;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4440 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4441
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4442 // continue with initial ascent demand
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4443 gas_needs_next_phase = GAS_NEEDS_INITIAL_ASCENT;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4444
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4445 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4446
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4447
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4448 //---------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4449
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4450 case GAS_NEEDS_INITIAL_ASCENT:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4451
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4452 // gas_needs_stop_gas : gas from bottom segment
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4453 // char_depth_bottom : depth of the bottom segment
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4454 // internal_deco_depth[0]: depth of the first stop, may be 0 if no stop exists
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4455
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4456 // get the data of the first stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4457 gas_needs_stop_depth = internal_deco_depth[0];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4458 gas_needs_stop_time = internal_deco_time[0];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4459
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4460 // volumes are only calculated for gases 1-5, but not the manually configured one
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4461 if( gas_needs_stop_gas )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4462 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4463 // compute distance between bottom and first stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4464 gas_needs_float_depth = (float)char_depth_bottom - (float)gas_needs_stop_depth;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4465
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4466 // initial ascent exists only if ascent distance is > 0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4467 if( gas_needs_float_depth > 0.0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4468 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4469 // compute ascent time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4470 gas_needs_float_time = gas_needs_float_depth / float_ascent_speed;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4471
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4472 // compute average depth between bottom and first stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4473 gas_needs_float_depth = (float)char_depth_bottom - gas_needs_float_depth * 0.5;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4474
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4475 // calculate gas demand
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4476 calc_due_by_depth_time_sac();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4477
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4478 // add to overall demand
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4479 gas_volume_need[gas_needs_stop_gas-1] += gas_needs_volume_due;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4480 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4481 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4482
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4483 // switch the usage (SAC rate) to deco usage rate
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4484 // for stops, intermediate and final ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4485 gas_needs_stop_usage = char_I_SAC_deco;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4486
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4487 // is there a (first) stop?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4488 if( gas_needs_stop_depth )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4489 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4490 // YES - continue with stop demand
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4491 gas_needs_next_phase = GAS_NEEDS_STOP;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4492
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4493 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4494 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4495 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4496 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4497 // NO - add demand of a 3 minutes safety stop at 5 meters, at least for contingency...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4498 gas_needs_float_time = 3.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4499 gas_needs_float_depth = 5.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4500
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4501 // calculate gas demand
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4502 calc_due_by_depth_time_sac();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4503
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4504 // add to overall demand
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4505 gas_volume_need[gas_needs_stop_gas-1] += gas_needs_volume_due;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4506
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4507 // calculation finished
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4508 gas_needs_next_phase = GAS_NEEDS_DONE;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4509
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4510 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4511 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4512
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4513
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4514 //---------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4515
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4516 case GAS_NEEDS_STOP:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4517
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4518 // correct stop depth if shallower than calculated stop depth and convert to float
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4519 gas_needs_float_depth = ( char_depth_bottom < gas_needs_stop_depth ) ? (float)char_depth_bottom : (float)gas_needs_stop_depth;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4520
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4521 // get the gas on this stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4522 gas_needs_stop_gas = internal_deco_gas[gas_needs_stop_index];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4523
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4524 // do we have a gas change?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4525 if( gas_needs_stop_gas_last && (gas_needs_stop_gas != gas_needs_stop_gas_last) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4526 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4527 // YES - spend an additional char_I_gas_change_time on the old gas
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4528 gas_needs_float_time = (float)char_I_gas_change_time;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4529
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4530 // calculate gas demand
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4531 calc_due_by_depth_time_sac();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4532
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4533 // add to overall demand
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4534 gas_volume_need[gas_needs_stop_gas_last-1] += gas_needs_volume_due;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4535 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4536
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4537 // calculate demand of (new) gas for the full stop duration
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4538 if( gas_needs_stop_gas )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4539 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4540 // get the duration of the stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4541 gas_needs_float_time = (float)gas_needs_stop_time;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4542
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4543 // calculate gas demand
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4544 calc_due_by_depth_time_sac();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4545
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4546 // add to overall demand
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4547 gas_volume_need[gas_needs_stop_gas-1] += gas_needs_volume_due;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4548 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4549
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4550 // Continue with the demand of the intermediate ascent to the next stop.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4551 // If there is no further stop, it will divert by itself to final ascent.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4552 gas_needs_next_phase = GAS_NEEDS_INTERMEDIATE_ASCENT;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4553
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4554 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4555
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4556
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4557 //---------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4558
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4559 case GAS_NEEDS_INTERMEDIATE_ASCENT:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4560
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4561 // store last stop depth and last gas
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4562 gas_needs_stop_depth_last = gas_needs_stop_depth;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4563 gas_needs_stop_gas_last = gas_needs_stop_gas;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4564
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4565 // check if end of stop table is reached
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4566 if( gas_needs_stop_index < NUM_STOPS-1 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4567 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4568 // NO - check if there is another stop entry
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4569 if( internal_deco_depth[gas_needs_stop_index+1] == 0 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4570 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4571 // NO - continue with final ascent demand
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4572 gas_needs_next_phase = GAS_NEEDS_FINAL_ASCENT;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4573
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4574 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4575 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4576 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4577 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4578 // YES - goto next stop entry
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4579 gas_needs_stop_index++;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4580
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4581 // get the depth of the next stop entry
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4582 gas_needs_stop_depth = internal_deco_depth[gas_needs_stop_index];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4583
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4584 // get the duration of the next stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4585 gas_needs_stop_time = internal_deco_time[gas_needs_stop_index];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4586 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4587 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4588 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4589 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4590 // YES - end of stop table reached
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4591 // We are stranded at some stop depth and do not know how many more
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4592 // stops there may be in front of us and how long they may be. So as
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4593 // as last resort to calculate at least something, we assume that the
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4594 // rest of the ascent will be done in deco final ascent pace, i.e. at
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4595 // 1 meter per minute. Because of the stop table overflow, the result
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4596 // will be flagged as being invalid later on.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4597 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4598 gas_needs_next_phase = GAS_NEEDS_FINAL_ASCENT;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4599
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4600 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4601 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4602
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4603 // volumes are only calculated for gases 1-5, but not the manually configured one
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4604 if( gas_needs_stop_gas_last )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4605 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4606 // compute distance between the two stops
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4607 gas_needs_float_depth = (float)(gas_needs_stop_depth_last - gas_needs_stop_depth);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4608
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4609 // compute ascent time
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4610 gas_needs_float_time = gas_needs_float_depth / float_ascent_speed;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4611
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4612 // compute average depth between the two stops
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4613 gas_needs_float_depth = (float)gas_needs_stop_depth_last - gas_needs_float_depth * 0.5;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4614
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4615 // calculate gas demand
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4616 calc_due_by_depth_time_sac();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4617
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4618 // add to overall demand
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4619 gas_volume_need[gas_needs_stop_gas_last-1] += gas_needs_volume_due;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4620 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4621
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4622 // continue with calculation stop demand
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4623 gas_needs_next_phase = GAS_NEEDS_STOP;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4624
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4625 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4626
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4627
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4628 //---------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4629
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4630 case GAS_NEEDS_FINAL_ASCENT:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4631
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4632 // gas_needs_float_depth: still holds depth of the last stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4633 // gas_needs_stop_gas : still holds gas from last stop (0 or 1-5)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4634
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4635 // volumes are only calculated for gases 1-5, but not the manually configured one
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4636 if( gas_needs_stop_gas )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4637 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4638 // set ascent time dependent on deco status
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4639 if( NDL_time )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4640 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4641 // within NDL - ascent with float_ascent_speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4642 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4643 // Remark: When calculating a bailout ascent, there may be stops
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4644 // for gas changes although the dive is still within NDL
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4645 // and final ascent thus does not need to be slowed down.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4646 gas_needs_float_time = gas_needs_float_depth / float_ascent_speed;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4647 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4648 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4649 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4650 // in deco - reduce ascent speed to 1 meter per minute
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4651 gas_needs_float_time = gas_needs_float_depth;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4652 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4653
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4654 // set half-way depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4655 gas_needs_float_depth *= 0.5;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4656
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4657 // calculate gas demand
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4658 calc_due_by_depth_time_sac();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4659
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4660 // add to overall demand
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4661 gas_volume_need[gas_needs_stop_gas-1] += gas_needs_volume_due;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4662 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4663
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4664 // calculation finished
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4665 gas_needs_next_phase = GAS_NEEDS_DONE;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4666
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4667 break;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4668
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4669 } // switch
0
heinrichsweikamp
parents:
diff changeset
4670 }
heinrichsweikamp
parents:
diff changeset
4671
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4672
0
heinrichsweikamp
parents:
diff changeset
4673 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4674 // calc_TR_functions
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4675 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4676 // Process Pressure Readings (OSTC TR only)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4677 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4678 // Input: todo
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4679 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4680 // Output: todo
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4681 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4682 #ifdef _rx_functions
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4683 static void calc_TR_functions(void)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4684 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4685 // pressure warnings for reading 1, but only if enabled and pressure value available
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4686 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
4687 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4688 overlay unsigned short pressure_value = int_IO_pressure_value[0] & ~INT_FLAG_OUTDATED;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4689
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4690 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
4691 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4692 // not a diluent and need available: warning & attention by need
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4693 if ( pressure_value <= int_O_pressure_need[0])
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4694 int_IO_pressure_value[0] |= INT_FLAG_WARNING;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4695 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
4696 int_IO_pressure_value[0] |= INT_FLAG_ATTENTION;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4697 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4698 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4699 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4700 // a diluent or need not available: warning & attention by fixed thresholds
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4701 if ( pressure_value <= PRESSURE_LIMIT_WARNING ) int_IO_pressure_value[0] |= INT_FLAG_WARNING;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4702 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
4703 }
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4704 }
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4705
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4706 // pressure warnings for reading 2, but only if enabled and pressure value available
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4707 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
4708 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4709 overlay unsigned short pressure_value = int_IO_pressure_value[1] & ~INT_FLAG_OUTDATED;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4710
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4711 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
4712 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4713 // not a diluent and need available: warning & attention by need
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4714 if ( pressure_value <= int_O_pressure_need[1])
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4715 int_IO_pressure_value[1] |= INT_FLAG_WARNING;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4716 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
4717 int_IO_pressure_value[1] |= INT_FLAG_ATTENTION;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4718 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4719 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4720 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4721 // a diluent or need not available: warning & attention by fixed thresholds
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4722 if ( pressure_value <= PRESSURE_LIMIT_WARNING ) int_IO_pressure_value[1] |= INT_FLAG_WARNING;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4723 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
4724 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4725 }
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
4726
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4727 //--- SAC Calculation ---------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4728 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4729 // char_I_SAC_mode =0: disabled
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4730 // =1: SAC from 1st reading
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4731 // =2: SAC from 2nd reading
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4732 // =3: SAC from higher one of both pressure drops (independent double mode)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4733 // =4: SAC (O2 usage) from 2nd reading without real_pres_respiration term
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4734
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4735 // set SAC rate to not available by default
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4736 int_O_SAC_measured = 0 + INT_FLAG_NOT_AVAIL;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4737
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4738 // get a copy of the current absolute pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4739 pres_respiration_sac = real_pres_respiration;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4740
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4741 // set threshold for SAC rate attention
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4742 max_sac_rate = (deco_info & DECO_FLAG) ? char_I_SAC_deco : char_I_SAC_work;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4743
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4744 // 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
4745 max_sac_rate *= 10;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4746
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4747
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4748 // pre-process SAC mode 3 (independent double)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4749 if( char_I_SAC_mode == 3 )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4750 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4751 overlay unsigned char reading1_gas;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4752 overlay unsigned char reading2_gas;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4753 overlay unsigned char reading1_tanksize;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4754 overlay unsigned char reading2_tanksize;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4755 overlay unsigned short reading1_press;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4756 overlay unsigned short reading2_press;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4757 overlay unsigned short reading1_drop;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4758 overlay unsigned short reading2_drop;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4759
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4760 // get gas numbers (1-10) of both readings
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4761 reading1_gas = char_I_pressure_gas[0];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4762 reading2_gas = char_I_pressure_gas[1];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4763
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4764 // default to no SAC calculation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4765 char_I_SAC_mode = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4766
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4767 // clear switch advice by default
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4768 deco_info &= ~IND_DOUBLE_SWITCH_FLAG;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4769
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4770 // check if both readings are configured and available
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4771 if( reading1_gas )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4772 if( reading2_gas )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4773 if( !(int_IO_pressure_value[0] & INT_FLAG_NOT_AVAIL) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4774 if( !(int_IO_pressure_value[1] & INT_FLAG_NOT_AVAIL) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4775 if( !(int_I_pressure_drop[0] & INT_FLAG_NOT_AVAIL) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4776 if( !(int_I_pressure_drop[1] & INT_FLAG_NOT_AVAIL) )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4777 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4778 // get tank pressures, stripping flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4779 reading1_press = int_IO_pressure_value[0] & 0x0FFF; // in 0.1 bar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4780 reading2_press = int_IO_pressure_value[1] & 0x0FFF; // in 0.1 bar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4781
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4782 // get pressure drops as integers, stripping flags and shifting right
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4783 // to avoid an overflow when multiplying with the tank size later on
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4784 reading1_drop = (int_I_pressure_drop[0] & 0x0FFF) >> 2;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4785 reading2_drop = (int_I_pressure_drop[1] & 0x0FFF) >> 2;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4786
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4787 // get tank sizes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4788 reading1_tanksize = char_I_gas_avail_size[reading1_gas-1];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4789 reading2_tanksize = char_I_gas_avail_size[reading2_gas-1];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4790
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4791 // set mode to calculate SAC on the reading with the higher absolute drop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4792 char_I_SAC_mode = (reading1_drop * reading1_tanksize > reading2_drop * reading2_tanksize) ? 1 : 2;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4793
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4794 // compute switch advice if pressure (in 0.1 bar) of tank breathed from is
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4795 // 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
4796 if( char_I_SAC_mode == 1 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4797 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4798 // 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
4799 if( (reading1_press + 10*char_I_max_pres_diff) <= reading2_press )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4800 deco_info |= IND_DOUBLE_SWITCH_FLAG;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4801 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4802 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4803 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4804 // 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
4805 if( (reading2_press + 10*char_I_max_pres_diff) <= reading1_press )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4806 deco_info |= IND_DOUBLE_SWITCH_FLAG;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4807 }
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4808 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4809 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4810
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4811
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4812 // pre-process SAC mode 4 (O2 usage by reading 2)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4813 if( char_I_SAC_mode == 4 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4814 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4815 // O2 usage on CCR is independent from absolute pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4816 pres_respiration_sac = 1.0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4817
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4818 // O2 pressure drop is measured via reading 2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4819 char_I_SAC_mode = 2;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4820
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4821 // reconfigure max SAC rate to O2 consumption attention threshold
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4822 max_sac_rate = O2_CONSUMPTION_LIMIT_ATTENTION;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4823 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4824
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4825
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4826 // calculate SAC - modes 1 & 2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4827 if( (char_I_SAC_mode == 1) || (char_I_SAC_mode == 2) )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4828 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4829 overlay unsigned char reading_index;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4830 overlay unsigned char reading_gas;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4831 overlay unsigned char reading_tanksize;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4832 overlay float reading_drop;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4833
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4834 // set index: char_I_SAC_mode = 1 -> reading one, index 0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4835 // = 2 -> two, 1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4836 reading_index = char_I_SAC_mode - 1;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4837
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4838 // get gas number (1-10)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4839 reading_gas = char_I_pressure_gas[reading_index];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4840
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4841 // check if reading is configured and available
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4842 if( reading_gas )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4843 if( !(int_I_pressure_drop[reading_index] & INT_FLAG_NOT_AVAIL) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4844 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4845 // get tank size (in liter)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4846 reading_tanksize = char_I_gas_avail_size[reading_gas-1];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4847
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4848 // get pressure drop as float, stripping flags (in 1/5120 bar/sec)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4849 reading_drop = (float)(int_I_pressure_drop[reading_index] & 0x0FFF);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4850
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4851 // check if pressure drop is within range
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4852 if( !(int_I_pressure_drop[reading_index] & INT_FLAG_OUT_OF_RANGE) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4853 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4854 // calculate SAC, 10 is factor to have result in 0.1 liter/min
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4855 // 60 is factor for 60 seconds per 1 minute,
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4856 // 5120 accounts for reading_drop being in 1/5120 bar/sec
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4857 // 10*60/5120 = 60/512 = 15/128
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4858 float_sac = reading_drop * 15/128 * reading_tanksize / pres_respiration_sac;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4859
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4860 // limit result to 999 (99.9 liter/min)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4861 if ( float_sac >= 998.5 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4862 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4863 int_O_SAC_measured = 999 + INT_FLAG_ATTENTION;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4864 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4865 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4866 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4867 // convert float to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4868 int_O_SAC_measured = (unsigned short)(float_sac + 0.5);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4869
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4870 // 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
4871 if( !(int_I_pressure_drop[reading_index] & INT_FLAG_OUTDATED) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4872 if( int_O_SAC_measured >= max_sac_rate )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4873 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4874 int_O_SAC_measured |= INT_FLAG_ATTENTION;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4875 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4876 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4877 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4878 else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4879 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4880 // 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
4881 int_O_SAC_measured = 999 + INT_FLAG_ATTENTION;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4882 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4883
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4884 // copy outdated flag from int_I_pressure_drop to int_O_SAC_measured
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4885 if( int_I_pressure_drop[reading_index] & INT_FLAG_OUTDATED )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4886 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4887 int_O_SAC_measured |= INT_FLAG_OUTDATED;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4888 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4889 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4890 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4891 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4892 #endif
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4893
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4894
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4895 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4896 // convert_gas_needs_to_press
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4897 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4898 // Converts gas volumes into pressures and sets respective flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4899 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4900 // Input: gas_needs_gas_index index of the gas to convert (0-4)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4901 // gas_volume_need[] needed gas volume in liters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4902 // char_I_gas_avail_pres[] available gas volume in bar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4903 // char_I_gas_avail_size[] size of the tanks in liters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4904 // char_I_pressure_gas[] gas configured on reading 1/2 (TR only)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4905 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4906 // Output: int_O_gas_need_vol[] required gas amount in liters, including flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4907 // int_O_gas_need_pres[] required gas amount in bar, including flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4908 // int_O_pressure_need[] required gas amount for reading 1/2 (TR only)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4909 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4910 static void convert_gas_needs_to_press(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4911 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4912
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4913 // just to make the code more readable...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4914 i = gas_needs_gas_index;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4915
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4916 if( gas_volume_need[i] >= 65534.5 )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4917 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4918 int_O_gas_need_vol[i] = 65535; // clip at 65535 liters
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4919 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
4920 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4921 else
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4922 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4923 overlay unsigned short int_pres_warn;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4924 overlay unsigned short int_pres_attn;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4925
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4926 // set warning and attention thresholds
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4927 int_pres_warn = 10.0 * (unsigned short)char_I_gas_avail_pres[i];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4928 int_pres_attn = GAS_NEEDS_ATTENTION_THRESHOLD * int_pres_warn;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4929
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4930 // convert ascent gas volume need from float to integer [in liter]
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4931 int_O_gas_need_vol[i] = (unsigned short)gas_volume_need[i];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4932
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4933 // compute how much pressure in the tank will be needed [in bar]
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4934 int_O_gas_need_pres[i] = (unsigned short)( gas_volume_need[i] / char_I_gas_avail_size[i] + 0.999 );
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4935
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4936 // limit result to 999 bar because of display constraints
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4937 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
4938
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4939 // set flags for fast evaluation by dive mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4940 if ( int_O_gas_need_pres[i] == 0 ) int_O_gas_need_pres[i] |= INT_FLAG_ZERO;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4941 else if ( int_O_gas_need_pres[i] >= int_pres_warn ) int_O_gas_need_pres[i] |= INT_FLAG_WARNING;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4942 else if ( int_O_gas_need_pres[i] >= int_pres_attn ) int_O_gas_need_pres[i] |= INT_FLAG_ATTENTION;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4943 }
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4944
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4945 // set invalid flag if there is an overflow in the stops table
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4946 if( deco_warnings & DECO_WARNING_STOPTABLE_OVERFLOW ) int_O_gas_need_pres[i] |= INT_FLAG_INVALID;
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4947
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4948 #ifdef _rx_functions
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4949 // only for OSTC TR model with TR functions enabled
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4950 if( main_status & TR_FUNCTIONS )
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 554
diff changeset
4951 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4952 // char_I_pressure_gas[] uses gas indexes from 1-10, loop variable i runs from 0 to 4
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4953 overlay unsigned char j = i+1;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4954
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4955 // check if the current gas is configured on pressure reading 1 or 2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4956 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
4957 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4958 // get a copy of the required pressure in full bar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4959 overlay unsigned short int_pres_need = int_O_gas_need_pres[i];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4960
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4961 // strip all flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4962 int_pres_need &= 1023;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4963
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4964 // 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
4965 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
4966
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4967 // tag as not available if there is an overflow in the stops table
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4968 if( deco_warnings & DECO_WARNING_STOPTABLE_OVERFLOW ) int_pres_need |= INT_FLAG_NOT_AVAIL;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4969
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4970 // copy to reading data (in both readings the same gas could be configured)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4971 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
4972 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
4973 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4974 } // TR functions
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
4975 #endif
0
heinrichsweikamp
parents:
diff changeset
4976 }
heinrichsweikamp
parents:
diff changeset
4977
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4978
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4979 //////////////////////////////////////////////////////////////////////////////
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4980 // convert the real CNS value to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4981 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4982 // Input CNS_fraction_real current CNS value as float
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4983 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4984 // Output: int_O_CNS_current current CNS value as integer including flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4985 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4986 static void convert_cur_CNS_for_display(void)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4987 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4988 // convert to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4989 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
4990
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4991 // set warning & attention flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4992 if ( int_O_CNS_current >= CNS_WARNING_THRESHOLD ) int_O_CNS_current |= INT_FLAG_WARNING;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4993 else if ( int_O_CNS_current >= CNS_ATTENTION_THRESHOLD ) int_O_CNS_current |= INT_FLAG_ATTENTION;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4994 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4995
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4996
0
heinrichsweikamp
parents:
diff changeset
4997 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4998 // convert the simulated CNS value to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
4999 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5000 // Input: CNS_fraction_sim CNS value after predicted ascent in float
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5001 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5002 // Output: int_sim_CNS_fraction CNS value after predicted ascent in integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5003 // including flags, will be routed to
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5004 // int_O_{normal,alternative}_CNS_fraction
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5005 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5006 static void convert_sim_CNS_for_display(void)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5007 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5008 // convert to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5009 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
5010
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5011 // set warning & attention flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5012 if ( int_sim_CNS_fraction >= CNS_WARNING_THRESHOLD ) int_sim_CNS_fraction |= INT_FLAG_WARNING;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5013 else if ( int_sim_CNS_fraction >= CNS_ATTENTION_THRESHOLD ) int_sim_CNS_fraction |= INT_FLAG_ATTENTION;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5014
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5015 // set invalid flag if there is an overflow in the stops table
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5016 if ( deco_warnings & DECO_WARNING_STOPTABLE_OVERFLOW ) int_sim_CNS_fraction |= INT_FLAG_INVALID;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5017 }
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5018
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5019
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5020 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5021 // convert the saturation value of the leading tissue to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5022 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5023 // Input lead_supersat saturation of the leading tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5024 // lead_tissue number of the leading tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5025 // char_I_GF_High_percentage GF high factor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5026 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5027 // Output: int_O_lead_supersat saturation of the leading tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5028 // char_O_lead_tissue number of the leading tissue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5029 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5030 // Modified: deco_warnings deco engine warnings vector
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5031 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5032 static void convert_sat_for_display(void)
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5033 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5034 // 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
5035 // limit to 255 because of constraints in ghostwriter code
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5036 if ( lead_supersat <= 0.000 ) int_O_lead_supersat = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5037 else if ( lead_supersat > 2.545 ) int_O_lead_supersat = 255;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5038 else int_O_lead_supersat = (unsigned short)(100 * lead_supersat + 0.5);
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5039
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5040 // set warning & attention flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5041 if( int_O_lead_supersat > 100 )
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5042 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5043 int_O_lead_supersat |= INT_FLAG_WARNING; // make GF factor shown in red
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5044 deco_warnings |= DECO_WARNING_OUTSIDE; // make depth shown in red
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5045 }
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5046 else if( (char_I_deco_model != 0) && (int_O_lead_supersat > char_I_GF_High_percentage)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5047 || (char_I_deco_model == 0) && (int_O_lead_supersat > 99 ) )
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5048 {
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5049 int_O_lead_supersat |= INT_FLAG_ATTENTION; // make GF factor shown in yellow
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5050 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
5051 }
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5052
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5053 // export also the number of the leading tissue
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5054 char_O_lead_tissue = lead_tissue;
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5055 }
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5056
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5057
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5058 //////////////////////////////////////////////////////////////////////////////
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5059 // convert the ceiling value to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5060 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5061 // Input: ceiling minimum depth permitted in float
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5062 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5063 // Output: int_O_ceiling minimum depth permitted in mbar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5064 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5065 // Modified: deco_info deco engine information vector
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5066 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5067 static void convert_ceiling_for_display(void)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5068 {
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5069 // 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
5070 // 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
5071 // 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
5072 // with TTS switching back to NDL time.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5073 if ( ceiling <= 0.0 ) int_O_ceiling = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5074 else if ( ceiling > 16.0 ) int_O_ceiling = 16000;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5075 else int_O_ceiling = (unsigned short)(ceiling * 1000 + 9);
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5076
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5077 // set/reset ceiling flag
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5078 if ( int_O_ceiling ) deco_info |= DECO_CEILING;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5079 else deco_info &= ~DECO_CEILING;
0
heinrichsweikamp
parents:
diff changeset
5080 }
heinrichsweikamp
parents:
diff changeset
5081
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5082
0
heinrichsweikamp
parents:
diff changeset
5083 //////////////////////////////////////////////////////////////////////////////
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5084 // push_tissues_to_vault & pull_tissues_from_vault
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5085 //
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5086 // ATTENTION: Do not use from inside the deco engine!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5087 // The vault is exclusively reserved to back-up and restore the real
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5088 // tissues and related data when entering / leaving simulation mode!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5089 //
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5090 // Input/Output: CNS_fraction_real current real CNS value
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5091 // char_O_deco_warnings deco engine warnings vector
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5092 // real_pres_tissue_N2[] partial pressure of N2 in real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5093 // real_pres_tissue_He[] partial pressure of He in real tissues
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5094 //
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5095 // Output: int_O_CNS_current current CNS value as integer including flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5096 //
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5097 static void push_tissues_to_vault(void)
0
heinrichsweikamp
parents:
diff changeset
5098 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5099 // store the current CNS value and deco warnings
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5100 vault_CNS_fraction_real = CNS_fraction_real;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5101 vault_deco_warnings = char_O_deco_warnings;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5102 vault_deco_info = char_O_deco_info;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5103
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5104 // store the tissue pressures
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5105 for( i = 0; i < NUM_COMP; i++ )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5106 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5107 vault_pres_tissue_N2[i] = real_pres_tissue_N2[i];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5108 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5109 vault_pres_tissue_He[i] = real_pres_tissue_He[i];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5110 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5111 vault_pres_tissue_He[i] = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5112 #endif
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5113 }
0
heinrichsweikamp
parents:
diff changeset
5114 }
heinrichsweikamp
parents:
diff changeset
5115
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 602
diff changeset
5116 static void pull_tissues_from_vault(void)
0
heinrichsweikamp
parents:
diff changeset
5117 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5118 // restore the CNS value and deco warnings
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5119 CNS_fraction_real = vault_CNS_fraction_real;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5120 char_O_deco_warnings = vault_deco_warnings;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5121 char_O_deco_info = vault_deco_info;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5122
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5123 // convert the CNS value to integer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5124 convert_cur_CNS_for_display();
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5125
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5126 // restore the tissue pressures
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5127 for( i = 0; i < NUM_COMP; i++ )
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5128 {
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5129 real_pres_tissue_N2[i] = vault_pres_tissue_N2[i];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5130 #ifdef _helium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5131 real_pres_tissue_He[i] = vault_pres_tissue_He[i];
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5132 #else
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5133 real_pres_tissue_He[i] = 0;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5134 #endif
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 567
diff changeset
5135 }
0
heinrichsweikamp
parents:
diff changeset
5136 }
heinrichsweikamp
parents:
diff changeset
5137
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 618
diff changeset
5138
0
heinrichsweikamp
parents:
diff changeset
5139 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
5140 //
heinrichsweikamp
parents:
diff changeset
5141 #ifndef CROSS_COMPILE
heinrichsweikamp
parents:
diff changeset
5142 void main() {}
heinrichsweikamp
parents:
diff changeset
5143 #endif