annotate src/p2_deco-TESTING.c @ 601:08a0162d3ca1

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