annotate Discovery/Src/vpm.c @ 976:0b81ac558e89 Evo_2_23

Devbugfix UART buffer cleaning: In the previous version a buffer cleaning function was used which resets the ringbuffer read index. As result the processing of data was stopped until the DMA write comes to the index 0. When reaching it the complete buffer was proceeded including possibly invalid data. The usage of the cleanbuffer function was replaced by the flush buffer function (meaning the data is discarded but the data index is maintained). There was already a function for this. Because the function was 99% the same as the read function, it was integrated into the ReadData function. Calling the function with parameter flush = 1 will result in a buffer flush. The workaround of the previous revision was updated to only be applied in case a DiveO2 sensor is operated in stand alone mode.
author Ideenmodellierer
date Wed, 29 Jan 2025 17:21:20 +0100 (2 months ago)
parents 79b522fbabe6
children 22d5b477c903
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 ///////////////////////////////////////////////////////////////////////////////
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 /// -*- coding: UTF-8 -*-
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 /// \file Discovery/Src/vpm.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 /// \brief critical_volume comment by hw
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 /// \author Heinrichs Weikamp, Erik C. Baker
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 /// \date 19-April-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 /// \details
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 /// $Id$
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 ///////////////////////////////////////////////////////////////////////////////
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 /// This program is free software: you can redistribute it and/or modify
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 /// it under the terms of the GNU General Public License as published by
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 /// the Free Software Foundation, either version 3 of the License, or
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 /// (at your option) any later version.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 /// This program is distributed in the hope that it will be useful,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 /// GNU General Public License for more details.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 /// You should have received a copy of the GNU General Public License
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 //////////////////////////////////////////////////////////////////////////////
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 /// \par Varying Permeability Model (VPM) Decompression Program in c (converted from FORTRAN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 /// Author: Erik C. Baker
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 /// "DISTRIBUTE FREELY - CREDIT THE AUTHORS"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 /// This program extends the 1986 VPM algorithm (Yount & Hoffman) to include
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 /// mixed gas, repetitive, and altitude diving. Developments to the algorithm
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 /// were made by David E. Yount, Eric B. Maiken, and Erik C. Baker over a
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 /// period from 1999 to 2001. This work is dedicated in remembrance of
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 /// Professor David E. Yount who passed away on April 27, 2000.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 /// Notes:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 /// 1. This program uses the sixteen (16) half-time compartments of the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 /// Buhlmann ZH-L16 model. The optional Compartment 1b is used here with
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 /// half-times of 1.88 minutes for helium and 5.0 minutes for nitrogen.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 /// 2. This program uses various DEC, IBM, and Microsoft extensions which
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 /// may not be supported by all FORTRAN compilers. Comments are made with
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 /// a capital "C" in the first column or an exclamation point "!" placed
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 /// in a line after code. An asterisk "*" in column 6 is a continuation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 /// of the previous line. All code, except for line numbers, starts in
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 /// column 7.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 /// 3. Comments and suggestions for improvements are welcome. Please
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 /// respond by e-mail to: EBaker@se.aeieng.com
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 /// Acknowledgment: Thanks to Kurt Spaugh for recommendations on how to clean
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 /// up the code.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 /// ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 /// Converted to vpmdeco.c using f2c; R.McGinnis (CABER Swe) 5/01
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 /// ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 /// ************************ Heirichs Weipkamp **************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 /// The original Yount & Baker code has been adjusted for real life calculation.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 /// 1) The original main function has been split in several functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 /// 2) When the deco zone is reached (while ascending) the gradient factors are kept fix
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 /// and critical volume algorithm is switched of. maxfirststopdepth is kept fix
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 /// to make shure Boeyls Law algorithm works correctly
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 /// 4) gas_loadings_ascent_descend heeds all gaschanges and CCR support has been added
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 #include <stdio.h>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 #include <stdlib.h>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 #include <string.h>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 #include <math.h>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 #include <time.h>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 #include "vpm.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 #include "decom.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 #define GAS_N2 0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 #define GAS_HE 1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
86 static const _Bool buehlmannSafety = true;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 /* Common Block Declarations */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 extern const float SURFACE_TENSION_GAMMA; //!Adj. Range: 0.015 to 0.065 N/m
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 extern const float SKIN_COMPRESSION_GAMMAC; //!Adj. Range: 0.160 to 0.290 N/m
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 extern const float UNITS_FACTOR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 extern const float WATER_VAPOR_PRESSURE; // (Schreiner value) based on respiratory quotien
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 extern const float CRIT_VOLUME_PARAMETER_LAMBDA; //!Adj. Range: 6500 to 8300 fsw-min
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
94 //extern const float GRADIENT_ONSET_OF_IMPERM_ATM; //!Adj. Range: 5.0 to 10.0 atm
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 extern const float REGENERATION_TIME_CONSTANT; //!Adj. Range: 10080 to 51840 min
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
96 //extern const float PRESSURE_OTHER_GASES_MMHG; //!Constant value for PO2 up to 2 atm
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 extern const float CONSTANT_PRESSURE_OTHER_GASES; // PRESSURE_OTHER_GASES_MMHG / 760. * UNITS_FACTOR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 extern const float HELIUM_TIME_CONSTANT[];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 extern const float NITROGEN_TIME_CONSTANT[];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
102 static float minimum_deco_stop_time;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
103 static float run_time, run_time_first_stop;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
104 static float segment_time;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
105 static short mix_number;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
106 static float barometric_pressure;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
107 static _Bool altitude_dive_algorithm_off;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
108 static _Bool units_equal_fsw, units_equal_msw;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 /* by hw 11.06.2015 to allow */
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
111 static float gCNS_VPM;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
113 static float helium_pressure[16], nitrogen_pressure[16];
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
114 static float surface_phase_volume_time[16];
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
115 static float regenerated_radius_he[16], regenerated_radius_n2[16];
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
116 static float allowable_gradient_he[16], allowable_gradient_n2[16];
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 //_Bool deco_zone_reached;
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
119 static _Bool critical_volume_algorithm_off;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
120 static float max_first_stop_depth;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
121 static float max_deco_ceiling_depth;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 //Boylslaw compensation
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
123 static float deco_gradient_he[16];
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
124 static float deco_gradient_n2[16];
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
125 static int vpm_calc_what;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
126 static int count_critical_volume_iteration;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
127 static short number_of_changes;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
128 static float depth_change[11];
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
129 static float step_size_change[11];
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
130 static float rate_change[11];
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
131 static short mix_change[11];
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
133 static const _Bool vpm_b = true;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134
907
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
135 static SvpmTableState vpmTableState = VPM_TABLE_INIT;
902
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
136 static SDecoinfo vpmTable;
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
137
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 extern const float float_buehlmann_N2_factor_expositon_20_seconds[];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 extern const float float_buehlmann_He_factor_expositon_20_seconds[];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 extern const float float_buehlmann_N2_factor_expositon_one_minute[];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 extern const float float_buehlmann_He_factor_expositon_one_minute[];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 extern const float float_buehlmann_N2_factor_expositon_five_minutes[];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 extern const float float_buehlmann_He_factor_expositon_five_minutes[];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 extern const float float_buehlmann_N2_factor_expositon_one_hour[];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 extern const float float_buehlmann_He_factor_expositon_one_hour[];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
147 static float depth_start_of_deco_calc;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
148 static float depth_start_of_deco_zone;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
149 static float first_stop_depth;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
150 static float run_time_start_of_deco_zone;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
152 static float r_nint(float *x);
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
153 static float r_int(float *x);
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
154 static _Bool nullzeit_unter60;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
155 static int vpm_calc_status;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
156 static _Bool buehlmann_wait_exceeded = false;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
158 static SLifeData* pInput = NULL;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
159 static SVpm* pVpm = NULL;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
160 static SDecoinfo* pDecoInfo = NULL;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
161 static SDiveSettings* pDiveSettings = NULL;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
162
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
163 static float r_nint(float *x)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 return( (*x)>=0 ?
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 floorf(*x + 0.5f) : -floorf(0.5f - *x) );
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
169 static float r_int(float *x)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 {
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
171 return( (*x>0.0) ? floorf(*x) : -floorf(- *x) );
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 /** private functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 */
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
176 extern int radius_root_finder (float *a, float *b, float *c,float *low_bound, float *high_bound, float *ending_radius);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
178 static int nuclear_regeneration(float *dive_time);// clock_();
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
179 static int calc_deco_ceiling(float *deco_ceiling_depth,_Bool fallowablw);
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
180 static int critical_volume(float *deco_phase_volume_time); ;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
181 static int calc_start_of_deco_zone(float *starting_depth, float *rate, float *depth_start_of_deco_zone);
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
182 static int calc_initial_allowable_gradient(void);
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
183 static void decompression_stop(float *deco_stop_depth, float *step_size, _Bool final_deco_calculation);
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
184 static int gas_loadings_ascent_descen(float* helium_pressure, float* nitrogen_pressure, float starting_depth,float ending_depth, float rate,_Bool check_gas_change);
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
185 static int calc_surface_phase_volume_time(void);
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
186 static int calc_max_actual_gradient(float *deco_stop_depth);
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
187 static int projected_ascent(float *starting_depth, float *rate, float *deco_stop_depth, float *step_size);
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
188 static void vpm_calc_deco(void);
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
189 static int vpm_calc_critcal_volume(_Bool begin,_Bool calc_nulltime);
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
190 static int vpm_check_converged(_Bool calc_nulltime);
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
191 static int vpm_calc_final_deco(_Bool begin);
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
192 static void BOYLES_LAW_COMPENSATION (float* First_Stop_Depth,float * Deco_Stop_Depth,float* Step_Size);
292
bfcea6e2ab3f translate: nullzeit -> ndl
Jan Mulder <jlmulder@xs4all.nl>
parents: 291
diff changeset
193 static int vpm_calc_ndl(void);
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
194 static void vpm_init_1(void);
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
195 static void vpm_calc_deco_ceiling(void);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196
907
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
197 uint8_t vpm_get_decozone(void);
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
198
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
199 static void vpm_init_1(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 units_equal_msw = true;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 units_equal_fsw = false;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 altitude_dive_algorithm_off= true; //!Options: ON or OFF
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 minimum_deco_stop_time=1.0; //!Options: float positive number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 critical_volume_algorithm_off= false; //!Options: ON or OFF
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 run_time = 0.;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 //barometric_pressure = dive_data.surface * 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 //mix_number = dive_data.selected_gas + 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 max_first_stop_depth = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 max_deco_ceiling_depth = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 //deco_zone_reached = false;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 depth_start_of_deco_calc = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 depth_start_of_deco_zone = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 first_stop_depth = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 run_time_start_of_deco_zone = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 gCNS_VPM = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 float vpm_get_CNS(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 return gCNS_VPM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226
902
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
227
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
228 void vpm_maintainTable(SLifeData* pLifeData,SDecoinfo* pDecoInfo)
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
229 {
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
230 static uint32_t lastDiveSecond = 0;
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
231 uint8_t actual_deco_stop = 0;
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
232 int8_t index = 0;
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
233 uint8_t decreaseStopTime = 1;
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
234
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
235 if(lastDiveSecond < pLifeData->dive_time_seconds)
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
236 {
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
237 lastDiveSecond = pLifeData->dive_time_seconds;
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
238 actual_deco_stop = decom_get_actual_deco_stop((SDiveState*)stateUsed);
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
239
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
240 pDecoInfo->output_time_to_surface_seconds = 0;
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
241 for(index = DECOINFO_STRUCT_MAX_STOPS -1 ;index >= 0; index--)
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
242 {
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
243 if(pDecoInfo->output_stop_length_seconds[index] > 0)
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
244 {
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
245 if(decreaseStopTime)
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
246 {
907
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
247 if((pLifeData->depth_meter > (float)(actual_deco_stop - 1.5))
902
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
248 && (pLifeData->depth_meter < (float)actual_deco_stop + 1.5))
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
249 {
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
250 pDecoInfo->output_stop_length_seconds[index]--;
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
251 decreaseStopTime = 0;
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
252 }
907
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
253 else if (pLifeData->depth_meter < (float)(actual_deco_stop - 1.5)) /* missed deco stop */
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
254 {
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
255 vpmTableState = VPM_TABLE_MISSED;
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
256 pDecoInfo->output_stop_length_seconds[index] = 0;
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
257 decreaseStopTime = 0;
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
258 }
902
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
259 }
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
260 pDecoInfo->output_time_to_surface_seconds += pDecoInfo->output_stop_length_seconds[index];
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
261 }
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
262 }
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
263 pDecoInfo->output_time_to_surface_seconds += pLifeData->depth_meter / 10.0 * 60.0;
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
264 }
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
265 else if(lastDiveSecond > pLifeData->dive_time_seconds)
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
266 {
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
267 lastDiveSecond = pLifeData->dive_time_seconds;
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
268 }
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
269 }
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
270
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 int vpm_calc(SLifeData* pINPUT,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 SDiveSettings* pSettings,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 SVpm* pVPM,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 SDecoinfo*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 pDECOINFO,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 int calc_what)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 {
902
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
278 static uint8_t vpmTableActive = 0;
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
279
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 vpm_init_1();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 //decom_CreateGasChangeList(pSettings, pINPUT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 vpm_calc_what = calc_what;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 /**clear decoInfo*/
902
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
284
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
285 if((vpmTableActive) && (vpm_calc_what == DECOSTOPS))
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
286 {
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
287 memcpy(&vpmTable, pDECOINFO, sizeof(SDecoinfo)); /* save changes done by e.g. the simulator */
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
288 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 pDECOINFO->output_time_to_surface_seconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 pDECOINFO->output_ndl_seconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 pDECOINFO->output_ceiling_meter = 0;
247
3949781096d4 feature: Relative GF to Saturation renames
Jan Mulder <jlmulder@xs4all.nl>
parents: 149
diff changeset
292 pDECOINFO->super_saturation = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 uint8_t tmp_calc_status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 for(int i=0;i<DECOINFO_STRUCT_MAX_STOPS;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 pDECOINFO->output_stop_length_seconds[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298
305
305f251cc981 bugfix, consistency: show deco/NDL really after 1 minute divetime
Jan Mulder <jlmulder@xs4all.nl>
parents: 293
diff changeset
299 if(pINPUT->dive_time_seconds_without_surface_time < 60)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 {
292
bfcea6e2ab3f translate: nullzeit -> ndl
Jan Mulder <jlmulder@xs4all.nl>
parents: 291
diff changeset
301 vpm_calc_status = CALC_NDL;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 return vpm_calc_status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 pVpm = pVPM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 pInput = pINPUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 pDecoInfo = pDECOINFO;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 pDiveSettings = pSettings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308
292
bfcea6e2ab3f translate: nullzeit -> ndl
Jan Mulder <jlmulder@xs4all.nl>
parents: 291
diff changeset
309 if(vpm_calc_status == CALC_NDL)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 {
292
bfcea6e2ab3f translate: nullzeit -> ndl
Jan Mulder <jlmulder@xs4all.nl>
parents: 291
diff changeset
311 tmp_calc_status = vpm_calc_ndl();
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 tmp_calc_status = CALC_BEGIN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 //Normal Deco calculation
292
bfcea6e2ab3f translate: nullzeit -> ndl
Jan Mulder <jlmulder@xs4all.nl>
parents: 291
diff changeset
318 if(tmp_calc_status != CALC_NDL)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 max_first_stop_depth = pVpm->max_first_stop_depth_save;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 run_time_start_of_deco_zone = pVpm->run_time_start_of_deco_zone_save;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 depth_start_of_deco_zone = pVpm->depth_start_of_deco_zone_save;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 for (int i = 0; i < 16; ++i) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 helium_pressure[i] = pInput->tissue_helium_bar[i] * 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 nitrogen_pressure[i] = pInput->tissue_nitrogen_bar[i] * 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 vpm_calc_deco();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 tmp_calc_status = vpm_calc_critcal_volume(true,false);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 if(vpm_calc_what == DECOSTOPS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 pVpm->max_first_stop_depth_save = max_first_stop_depth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 pVpm->run_time_start_of_deco_zone_save = run_time_start_of_deco_zone;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 pVpm->depth_start_of_deco_zone_save = depth_start_of_deco_zone;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 //Only Decostops not futute stops
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 if(vpm_calc_what == DECOSTOPS)
902
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
339 {
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 vpm_calc_status = tmp_calc_status;
902
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
341 if(pSettings->vpm_tableMode) /* store the most conservative deco plan and stick to it. */
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
342 {
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
343 if((int16_t)(pDECOINFO->output_time_to_surface_seconds - vpmTable.output_time_to_surface_seconds) > 60)
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
344 {
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
345 memcpy(&vpmTable, pDECOINFO, sizeof(SDecoinfo));
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
346 vpmTableActive = 1;
907
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
347 if(pVpm->deco_zone_reached) /* table should not change after deco zone was entered */
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
348 {
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
349 if(vpmTableState != VPM_TABLE_MISSED)
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
350 {
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
351 vpmTableState = VPM_TABLE_WARNING;
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
352 }
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
353 }
902
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
354 }
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
355 else
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
356 {
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
357 if(vpmTable.output_time_to_surface_seconds > 0)
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
358 {
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
359 vpm_maintainTable(pINPUT, &vpmTable);
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
360 vpmTable.output_ceiling_meter = pDECOINFO->output_ceiling_meter;
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
361 memcpy(pDECOINFO, &vpmTable, sizeof(SDecoinfo));
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
362 }
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
363 }
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
364 }
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
365 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 return vpm_calc_status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 void vpm_saturation_after_ascent(SLifeData* input)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 int i = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 for (i = 0; i < 16; ++i) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 pInput->tissue_helium_bar[i] = helium_pressure[i] / 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 pInput->tissue_nitrogen_bar[i] = nitrogen_pressure[i] / 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 pInput->pressure_ambient_bar = pInput->pressure_surface_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 /* NOTE ABOUT PRESSURE UNITS USED IN CALCULATIONS: */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 /* It is the convention in decompression calculations to compute all gas */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 /* loadings, absolute pressures, partial pressures, etc., in the units of */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 /* depth pressure that you are diving - either feet of seawater (fsw) or */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 /* meters of seawater (msw). This program follows that convention with the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 /* the exception that all VPM calculations are performed in SI units (by */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 /* necessity). Accordingly, there are several conversions back and forth */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 /* between the diving pressure units and the SI units. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 /* FUNCTION SUBPROGRAM FOR GAS LOADING CALCULATIONS - ASCENT AND DESCENT */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 /* SUBROUTINE GAS_LOADINGS_ASCENT_DESCENT */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 /* Purpose: This subprogram applies the Schreiner equation to update the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 /* gas loadings (partial pressures of helium and nitrogen) in the half-time */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 /* compartments due to a linear ascent or descent segment at a constant rate. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
401 static int gas_loadings_ascent_descen(float* helium_pressure,
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 float* nitrogen_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 float starting_depth,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 float ending_depth,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 float rate,_Bool check_gas_change)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 short i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 float initial_inspired_n2_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 initial_inspired_he_pressure, nitrogen_rate,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 last_run_time,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 starting_ambient_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 ending_ambient_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 float initial_helium_pressure[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 float initial_nitrogen_pressure[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 float helium_rate;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 float fraction_helium_begin;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 float fraction_helium_end;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 float fraction_nitrogen_begin;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 float fraction_nitrogen_end;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 float ending_depth_tmp = ending_depth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 float segment_time_tmp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 /* loop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 /* CALCULATIONS */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 segment_time = (ending_depth_tmp - starting_depth) / rate;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 last_run_time = run_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 run_time = last_run_time + segment_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 do {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 ending_depth_tmp = ending_depth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 if (starting_depth > ending_depth && check_gas_change && number_of_changes > 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 for (i = 1; i < number_of_changes; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 if (depth_change[i] < starting_depth && depth_change[i] > ending_depth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 ending_depth_tmp = depth_change[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 for (i = 1; i < number_of_changes; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 if (depth_change[i] >= starting_depth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 mix_number = mix_change[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 segment_time_tmp = (ending_depth_tmp - starting_depth) / rate;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 ending_ambient_pressure = ending_depth_tmp + barometric_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 starting_ambient_pressure = starting_depth + barometric_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 decom_get_inert_gases( starting_ambient_pressure / 10, (&pDiveSettings->decogaslist[mix_number]), &fraction_nitrogen_begin, &fraction_helium_begin );
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 decom_get_inert_gases( ending_ambient_pressure / 10, (&pDiveSettings->decogaslist[mix_number]), &fraction_nitrogen_end, &fraction_helium_end );
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 initial_inspired_he_pressure = (starting_ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_helium_begin;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 initial_inspired_n2_pressure = (starting_ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_nitrogen_begin;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 //helium_rate = *rate * fraction_helium[mix_number - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 helium_rate = ((ending_ambient_pressure - WATER_VAPOR_PRESSURE)* fraction_helium_end - initial_inspired_he_pressure)/segment_time_tmp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 //nitrogen_rate2 = *rate * fraction_nitrogen[mix_number - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 nitrogen_rate = ((ending_ambient_pressure - WATER_VAPOR_PRESSURE)* fraction_nitrogen_end - initial_inspired_n2_pressure)/segment_time_tmp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 decom_oxygen_calculate_cns_stage_SchreinerStyle(segment_time_tmp,&pDiveSettings->decogaslist[mix_number],starting_ambient_pressure/10,ending_ambient_pressure/10,&gCNS_VPM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 //if(fabs(nitrogen_rate - nitrogen_rate2) > 0.000001)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 //return -2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 for (i = 1; i <= 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 initial_helium_pressure[i - 1] = helium_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 initial_nitrogen_pressure[i - 1] = nitrogen_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 helium_pressure[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 schreiner_equation__2(&initial_inspired_he_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 &helium_rate,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 &segment_time,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 &HELIUM_TIME_CONSTANT[i - 1],
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 &initial_helium_pressure[i - 1]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 nitrogen_pressure[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 schreiner_equation__2(&initial_inspired_n2_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 &nitrogen_rate,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 &segment_time,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 &NITROGEN_TIME_CONSTANT[i - 1],
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 &initial_nitrogen_pressure[i - 1]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 //nextround???
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 starting_depth = ending_depth_tmp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 } while(ending_depth_tmp > ending_depth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 } /* gas_loadings_ascent_descen */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
492 static float last_phase_volume_time[16];
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
493 static float n2_pressure_start_of_deco_zone[16];
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
494 static float he_pressure_start_of_deco_zone[16];
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
495 static float phase_volume_time[16];
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
496 static float n2_pressure_start_of_ascent[16];
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
497 static float he_pressure_start_of_ascent[16];
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
498 static float run_time_start_of_deco_calc;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
499 static float starting_depth;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
500 static float last_run_time;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
501 static float deco_phase_volume_time;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
502 static float run_time_start_of_ascent;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
503 static float rate;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
504 static float step_size;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
505 static _Bool vpm_violates_buehlmann;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
507 static void vpm_calc_deco(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 /* System generated locals */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 //float deepest_possible_stop_depth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 // altitude_of_dive,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 short i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 int j = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 // float rounding_operation;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 /* INPUT PARAMETERS TO BE USED FOR STAGED DECOMPRESSION AND SAVE IN ARRAYS. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 /* ASSIGN INITAL PARAMETERS TO BE USED AT START OF ASCENT */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 /* The user has the ability to change mix, ascent rate, and step size in any */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 /* combination at any depth during the ascent. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 run_time = ((float)pInput->dive_time_seconds )/ 60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 count_critical_volume_iteration = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 number_of_changes = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529 barometric_pressure = pInput->pressure_surface_bar * 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530 depth_change[0] =(pInput->pressure_ambient_bar - pInput->pressure_surface_bar)* 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 mix_change[0] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 rate_change[0 ] = -10;// neu 160215 hw, zuvor: -12;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533 step_size_change[0] = 3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534 vpm_violates_buehlmann = false;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 for (i = 1; i < BUEHLMANN_STRUCT_MAX_GASES; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538 depth_change[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 mix_change[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541 j = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 for (i = 1; i < BUEHLMANN_STRUCT_MAX_GASES; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544 {
830
b7d93ff6b3b2 Added selection if an active gas shall be used for deco calculation or not:
Ideenmodellierer
parents: 305
diff changeset
545 if((pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero >= depth_change[0] + 1)
973
79b522fbabe6 Deactivate deco gas calculation option:
Ideenmodellierer
parents: 907
diff changeset
546 #ifdef ENABLE_DECOCALC_OPTION
79b522fbabe6 Deactivate deco gas calculation option:
Ideenmodellierer
parents: 907
diff changeset
547 && (pDiveSettings->gas[pDiveSettings->decogaslist[i].GasIdInSettings].note.ub.decocalc)
79b522fbabe6 Deactivate deco gas calculation option:
Ideenmodellierer
parents: 907
diff changeset
548 #endif
79b522fbabe6 Deactivate deco gas calculation option:
Ideenmodellierer
parents: 907
diff changeset
549 )
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550 continue;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551
830
b7d93ff6b3b2 Added selection if an active gas shall be used for deco calculation or not:
Ideenmodellierer
parents: 305
diff changeset
552 if((pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero <= 0)
973
79b522fbabe6 Deactivate deco gas calculation option:
Ideenmodellierer
parents: 907
diff changeset
553 #ifdef ENABLE_DECOCALC_OPTION
79b522fbabe6 Deactivate deco gas calculation option:
Ideenmodellierer
parents: 907
diff changeset
554 || (pDiveSettings->gas[pDiveSettings->decogaslist[i].GasIdInSettings].note.ub.decocalc == 0)
79b522fbabe6 Deactivate deco gas calculation option:
Ideenmodellierer
parents: 907
diff changeset
555 #endif
79b522fbabe6 Deactivate deco gas calculation option:
Ideenmodellierer
parents: 907
diff changeset
556 )
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559 j++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 number_of_changes ++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 depth_change[j] = pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562 mix_change[j] = i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 rate_change[j] = -10;// neu 160215 hw, zuvor: -12;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 step_size_change[j] = 3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 starting_depth = depth_change[0] ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 mix_number = mix_change[0] ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 rate = rate_change[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570 step_size = step_size_change[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572 for (i = 0; i < 16; ++i) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 he_pressure_start_of_ascent[i ] = helium_pressure[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 n2_pressure_start_of_ascent[i] = nitrogen_pressure[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576 run_time_start_of_ascent = run_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 if(starting_depth <= depth_start_of_deco_zone && vpm_calc_what == DECOSTOPS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579 pVpm->deco_zone_reached = true;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 depth_start_of_deco_calc = starting_depth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581 critical_volume_algorithm_off = true;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 //if(deco_zone_reached)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586 //{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 pVpm->deco_zone_reached = false;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 critical_volume_algorithm_off = false;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 //max_first_stop_depth = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 //max_first_stop_depth_save = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 //}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 /* BEGIN PROCESS OF ASCENT AND DECOMPRESSION */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 /* First, calculate the regeneration of critical radii that takes place over */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595 /* the dive time. The regeneration time constant has a time scale of weeks */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596 /* so this will have very little impact on dives of normal length, but will */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597 /* have major impact for saturation dives. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600 nuclear_regeneration(&run_time);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603 /* CALCULATE INITIAL ALLOWABLE GRADIENTS FOR ASCENT */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604 /* This is based on the maximum effective crushing pressure on critical radii */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 /* in each compartment achieved during the dive profile. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608 calc_initial_allowable_gradient();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611 /* SAVE VARIABLES AT START OF ASCENT (END OF BOTTOM TIME) SINCE THESE WILL */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612 /* BE USED LATER TO COMPUTE THE FINAL ASCENT PROFILE THAT IS WRITTEN TO THE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613 /* OUTPUT FILE. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614 /* The VPM uses an iterative process to compute decompression schedules so */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615 /* there will be more than one pass through the decompression loop. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619 /* CALCULATE THE DEPTH WHERE THE DECOMPRESSION ZONE BEGINS FOR THIS PROFILE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 /* BASED ON THE INITIAL ASCENT PARAMETERS AND WRITE THE DEEPEST POSSIBLE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621 /* DECOMPRESSION STOP DEPTH TO THE OUTPUT FILE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622 /* Knowing where the decompression zone starts is very important. Below */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623 /* that depth there is no possibility for bubble formation because there */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624 /* will be no supersaturation gradients. Deco stops should never start */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625 /* below the deco zone. The deepest possible stop deco stop depth is */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 /* defined as the next "standard" stop depth above the point where the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627 /* leading compartment enters the deco zone. Thus, the program will not */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628 /* base this calculation on step sizes larger than 10 fsw or 3 msw. The */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 /* deepest possible stop depth is not used in the program, per se, rather */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630 /* it is information to tell the diver where to start putting on the brakes */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631 /* during ascent. This should be prominently displayed by any deco program. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634 calc_start_of_deco_zone(&starting_depth, &rate, &depth_start_of_deco_zone);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636 /* TEMPORARILY ASCEND PROFILE TO THE START OF THE DECOMPRESSION ZONE, SAVE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 /* VARIABLES AT THIS POINT, AND INITIALIZE VARIABLES FOR CRITICAL VOLUME LOOP */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638 /* The iterative process of the VPM Critical Volume Algorithm will operate */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639 /* only in the decompression zone since it deals with excess gas volume */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 /* released as a result of supersaturation gradients (not possible below the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641 /* decompression zone). */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 gas_loadings_ascent_descen(helium_pressure,nitrogen_pressure, starting_depth, depth_start_of_deco_zone, rate, true);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 run_time_start_of_deco_zone = run_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646 depth_start_of_deco_calc = depth_start_of_deco_zone;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648 for (i = 0; i < 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650 pVpm->max_actual_gradient[i] = 0.;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654 for (i = 0; i < 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656 surface_phase_volume_time[i] = 0.;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 last_phase_volume_time[i] = 0.;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658 he_pressure_start_of_deco_zone[i] = helium_pressure[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659 n2_pressure_start_of_deco_zone[i] = nitrogen_pressure[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 //pVpm->max_actual_gradient[i] = 0.;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 run_time_start_of_deco_calc = run_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 /* START OF CRITICAL VOLUME LOOP */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666 /* This loop operates between Lines 50 and 100. If the Critical Volume */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667 /* Algorithm is toggled "off" in the program settings, there will only be */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 /* one pass through this loop. Otherwise, there will be two or more passes */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 /* through this loop until the deco schedule is "converged" - that is when a */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670 /* comparison between the phase volume time of the present iteration and the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 /* last iteration is less than or equal to one minute. This implies that */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 /* the volume of released gas in the most recent iteration differs from the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673 /* "critical" volume limit by an acceptably small amount. The critical */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 /* volume limit is set by the Critical Volume Parameter Lambda in the program */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 /* settings (default setting is 7500 fsw-min with adjustability range from */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 /* from 6500 to 8300 fsw-min according to Bruce Wienke). */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 /* L50: */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
680 static float deco_stop_depth;
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
681 static int vpm_calc_critcal_volume(_Bool begin,
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 _Bool calc_nulltime)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 { /* loop will run continuous there is an exit stateme */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 short i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 float rounding_operation2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 //float ending_depth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 float deco_ceiling_depth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 //float deco_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692 int count = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693 _Bool first_stop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 int dp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 float tissue_He_saturation[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696 float tissue_N2_saturation[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 float vpm_buehlmann_safety_gradient = 1.0f - (((float)pDiveSettings->vpm_conservatism) / 40);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 /* CALCULATE CURRENT DECO CEILING BASED ON ALLOWABLE SUPERSATURATION */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 /* GRADIENTS AND SET FIRST DECO STOP. CHECK TO MAKE SURE THAT SELECTED STEP */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 /* SIZE WILL NOT ROUND UP FIRST STOP TO A DEPTH THAT IS BELOW THE DECO ZONE. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 if(begin)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705 if(depth_start_of_deco_calc < max_first_stop_depth )
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 if(vpm_b)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 BOYLES_LAW_COMPENSATION(&max_first_stop_depth, &depth_start_of_deco_calc, &step_size);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711 calc_deco_ceiling(&deco_ceiling_depth, false);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 calc_deco_ceiling(&deco_ceiling_depth, true);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 if (deco_ceiling_depth <= 0.0f) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 deco_stop_depth = 0.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719 } else {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720 rounding_operation2 = deco_ceiling_depth / step_size + ( float)0.5f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 deco_stop_depth = r_nint(&rounding_operation2) * step_size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724 // buehlmann safety
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 if(buehlmannSafety)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727 for (i = 0; i < 16; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 {
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
729 tissue_He_saturation[i] = helium_pressure[i] / 10.0;
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
730 tissue_N2_saturation[i] = nitrogen_pressure[i] / 10.0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 if(!decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (deco_stop_depth / 10.0f) + pInput->pressure_surface_bar))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736 vpm_violates_buehlmann = true;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737 do {
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
738 deco_stop_depth += 3.0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 } while (!decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (deco_stop_depth / 10.0f) + pInput->pressure_surface_bar));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 /* PERFORM A SEPARATE "PROJECTED ASCENT" OUTSIDE OF THE MAIN PROGRAM TO MAKE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 /* SURE THAT AN INCREASE IN GAS LOADINGS DURING ASCENT TO THE FIRST STOP WILL */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746 /* NOT CAUSE A VIOLATION OF THE DECO CEILING. IF SO, ADJUST THE FIRST STOP */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747 /* DEEPER BASED ON STEP SIZE UNTIL A SAFE ASCENT CAN BE MADE. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 /* Note: this situation is a possibility when ascending from extremely deep */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749 /* dives or due to an unusual gas mix selection. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 /* CHECK AGAIN TO MAKE SURE THAT ADJUSTED FIRST STOP WILL NOT BE BELOW THE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 /* DECO ZONE. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 if (deco_stop_depth < depth_start_of_deco_calc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 projected_ascent(&depth_start_of_deco_calc, &rate, &deco_stop_depth, &step_size);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 /*if (deco_stop_depth > depth_start_of_deco_zone) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 printf("\t\n");
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 printf(fmt_905);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 printf(fmt_900);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762 printf("\nPROGRAM TERMINATED\n");
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 exit(1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764 }*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 /* HANDLE THE SPECIAL CASE WHEN NO DECO STOPS ARE REQUIRED - ASCENT CAN BE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 /* MADE DIRECTLY TO THE SURFACE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769 /* Write ascent data to output file and exit the Critical Volume Loop. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 if (deco_stop_depth == 0.0f)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774 if(calc_nulltime)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776 return CALC_END;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 if(pVpm->deco_zone_reached)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780 for(dp = 0;dp < DECOINFO_STRUCT_MAX_STOPS;dp++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782 pDecoInfo->output_stop_length_seconds[dp] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 pDecoInfo->output_ndl_seconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786
292
bfcea6e2ab3f translate: nullzeit -> ndl
Jan Mulder <jlmulder@xs4all.nl>
parents: 291
diff changeset
787 return CALC_NDL;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 /* exit the critical volume l */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 /* ASSIGN VARIABLES FOR ASCENT FROM START OF DECO ZONE TO FIRST STOP. SAVE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793 /* FIRST STOP DEPTH FOR LATER USE WHEN COMPUTING THE FINAL ASCENT PROFILE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 /* =============================================================================== */
877
a0900e4df15c DevBugfix: Exit condition deco_stop_depth
Ideenmodellierer
parents: 863
diff changeset
795 deco_stop_depth = fmaxf(deco_stop_depth,(float)pDiveSettings->last_stop_depth_bar * 10);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796 starting_depth = depth_start_of_deco_calc;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797 first_stop_depth = deco_stop_depth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 first_stop = true;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801 /* DECO STOP LOOP BLOCK WITHIN CRITICAL VOLUME LOOP */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802 /* This loop computes a decompression schedule to the surface during each */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803 /* iteration of the critical volume loop. No output is written from this */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 /* loop, rather it computes a schedule from which the in-water portion of the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805 /* total phase volume time (Deco_Phase_Volume_Time) can be extracted. Also, */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806 /* the gas loadings computed at the end of this loop are used the subroutine */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 /* which computes the out-of-water portion of the total phase volume time */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808 /* (Surface_Phase_Volume_Time) for that schedule. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810 /* Note that exit is made from the loop after last ascent is made to a deco */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 /* stop depth that is less than or equal to zero. A final deco stop less */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812 /* than zero can happen when the user makes an odd step size change during */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 /* ascent - such as specifying a 5 msw step size change at the 3 msw stop! */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 while(true) /* loop will run continuous there is an break statement */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 if(starting_depth > deco_stop_depth )
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 gas_loadings_ascent_descen(helium_pressure, nitrogen_pressure, starting_depth, deco_stop_depth, rate,first_stop);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821 first_stop = false;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822 if (deco_stop_depth <= 0.0f)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826 if (number_of_changes > 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828 int i1 = number_of_changes;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829 for (i = 2; i <= i1; ++i) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 if (depth_change[i - 1] >= deco_stop_depth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 mix_number = mix_change[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 rate = rate_change[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 step_size = step_size_change[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 if(vpm_b)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 float fist_stop_depth2 = fmaxf(first_stop_depth,max_first_stop_depth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 BOYLES_LAW_COMPENSATION(&fist_stop_depth2, &deco_stop_depth, &step_size);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 decompression_stop(&deco_stop_depth, &step_size, false);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844 starting_depth = deco_stop_depth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845
877
a0900e4df15c DevBugfix: Exit condition deco_stop_depth
Ideenmodellierer
parents: 863
diff changeset
846 if(deco_stop_depth == (float)pDiveSettings->last_stop_depth_bar * 10)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847 deco_stop_depth = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 deco_stop_depth = deco_stop_depth - step_size;
877
a0900e4df15c DevBugfix: Exit condition deco_stop_depth
Ideenmodellierer
parents: 863
diff changeset
851 deco_stop_depth = fmaxf(deco_stop_depth,(float)pDiveSettings->last_stop_depth_bar * 10);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854 count++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855 //if(count > 14)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 //return CALC_CRITICAL2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857 /* L60: */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860 return vpm_check_converged(calc_nulltime);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863 /* COMPUTE TOTAL PHASE VOLUME TIME AND MAKE CRITICAL VOLUME COMPARISON */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864 /* The deco phase volume time is computed from the run time. The surface */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865 /* phase volume time is computed in a subroutine based on the surfacing gas */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866 /* loadings from previous deco loop block. Next the total phase volume time */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867 /* (in-water + surface) for each compartment is compared against the previous */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
868 /* total phase volume time. The schedule is converged when the difference is */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869 /* less than or equal to 1 minute in any one of the 16 compartments. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
871 /* Note: the "phase volume time" is somewhat of a mathematical concept. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
872 /* It is the time divided out of a total integration of supersaturation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
873 /* gradient x time (in-water and surface). This integration is multiplied */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874 /* by the excess bubble number to represent the amount of free-gas released */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
875 /* as a result of allowing a certain number of excess bubbles to form. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
876 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
877 /* end of deco stop loop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
878
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
879 static int vpm_check_converged(_Bool calc_nulltime)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
880 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
881
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
882 short i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
883 float critical_volume_comparison;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
884 float r1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
885 _Bool schedule_converged = false;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
886
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888 deco_phase_volume_time = run_time - run_time_start_of_deco_zone;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889 calc_surface_phase_volume_time();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891 for (i = 1; i <= 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893 phase_volume_time[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894 deco_phase_volume_time + surface_phase_volume_time[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895 critical_volume_comparison = (r1 = phase_volume_time[i - 1] - last_phase_volume_time[i - 1], fabs(r1));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
897 if (critical_volume_comparison <= 1.0f)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
898 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
899 schedule_converged = true;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
900 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
901 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
902
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
903 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
904 /* CRITICAL VOLUME DECISION TREE BETWEEN LINES 70 AND 99 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
905 /* There are two options here. If the Critical Volume Agorithm setting is */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
906 /* "on" and the schedule is converged, or the Critical Volume Algorithm */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
907 /* setting was "off" in the first place, the program will re-assign variables */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908 /* to their values at the start of ascent (end of bottom time) and process */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909 /* a complete decompression schedule once again using all the same ascent */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910 /* parameters and first stop depth. This decompression schedule will match */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911 /* the last iteration of the Critical Volume Loop and the program will write */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
912 /* the final deco schedule to the output file. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914 /* Note: if the Critical Volume Agorithm setting was "off", the final deco */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
915 /* schedule will be based on "Initial Allowable Supersaturation Gradients." */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
916 /* If it was "on", the final schedule will be based on "Adjusted Allowable */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
917 /* Supersaturation Gradients" (gradients that are "relaxed" as a result of */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918 /* the Critical Volume Algorithm). */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920 /* If the Critical Volume Agorithm setting is "on" and the schedule is not */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921 /* converged, the program will re-assign variables to their values at the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922 /* start of the deco zone and process another trial decompression schedule. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924 /* L70: */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
925 //Not more than 4 iteration allowed
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
926 count_critical_volume_iteration++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
927 if(count_critical_volume_iteration > 4)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
928 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
929 //return CALC_FINAL_DECO;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
930 if(calc_nulltime)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
931 return CALC_FINAL_DECO;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
932 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
933 return vpm_calc_final_deco(true);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
934 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
935 if (schedule_converged || critical_volume_algorithm_off)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
936 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
937
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
938 //return CALC_FINAL_DECO;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
939 if(calc_nulltime)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
940 return CALC_FINAL_DECO;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
941 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
942 return vpm_calc_final_deco(true);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
943 /* final deco schedule */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
944 /* exit critical volume l */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
945
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
946 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
947 /* IF SCHEDULE NOT CONVERGED, COMPUTE RELAXED ALLOWABLE SUPERSATURATION */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
948 /* GRADIENTS WITH VPM CRITICAL VOLUME ALGORITHM AND PROCESS ANOTHER */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
949 /* ITERATION OF THE CRITICAL VOLUME LOOP */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
950 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
951
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
952 } else {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
953 critical_volume(&deco_phase_volume_time);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
954 deco_phase_volume_time = 0.;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
955 run_time = run_time_start_of_deco_calc;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
956 starting_depth = depth_start_of_deco_calc;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
957 mix_number = mix_change[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
958 rate = rate_change[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
959 step_size = step_size_change[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
960 for (i = 1; i <= 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
961 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
962 last_phase_volume_time[i - 1] = phase_volume_time[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
963 helium_pressure[i - 1] = he_pressure_start_of_deco_zone[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
964 nitrogen_pressure[i - 1] = n2_pressure_start_of_deco_zone[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
965 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
966 if(calc_nulltime)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
967 return CALC_CRITICAL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
968 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
969 return vpm_calc_critcal_volume(true, false);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
970 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
971 /* end of critical volume decision */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
972 /* L100: */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
973 // }/* end of critical vol loop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
974 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
975
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
976 static void vpm_calc_deco_ceiling(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
977 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
978
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
979 short i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
980 // hw 1601209 float r1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
981 // hw 1601209 float stop_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
982 // hw 1601209 int count = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
983 //static int dp_max;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
984 //static float surfacetime;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
985 // _Bool first_stop = false;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
986 float tissue_He_saturation[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
987 float tissue_N2_saturation[16];
877
a0900e4df15c DevBugfix: Exit condition deco_stop_depth
Ideenmodellierer
parents: 863
diff changeset
988 float vpm_buehlmann_safety_gradient = 1.0f - (((float)pDiveSettings->vpm_conservatism) / 40);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
989 //max_first_stop_depth = fmaxf(first_stop_depth,max_first_stop_depth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
990
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
991 /** CALC DECO Ceiling ******************************************************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
992 /** Not when Future stops */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
993 if(vpm_calc_what == DECOSTOPS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
994 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
995
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
996 for (i = 1; i <= 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
997 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
998 helium_pressure[i - 1] = he_pressure_start_of_deco_zone[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
999 nitrogen_pressure[i - 1] = n2_pressure_start_of_deco_zone[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1000 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1001 run_time = run_time_start_of_ascent;// run_time_start_of_ascent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1002 starting_depth = depth_change[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1003 mix_number = mix_change[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1004 rate = rate_change[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1005 //gas_loadings_ascent_descen(helium_pressure,nitrogen_pressure, starting_depth, depth_start_of_deco_calc, rate, true);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1006
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1007 float deco_ceiling_depth = 0.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1008 if(depth_start_of_deco_calc > max_deco_ceiling_depth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1009 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1010 calc_deco_ceiling(&deco_ceiling_depth, true);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1011 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1012 if(buehlmannSafety)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1013 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1014 for (i = 0; i < 16; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1015 {
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1016 tissue_He_saturation[i] = helium_pressure[i] / 10.0;
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1017 tissue_N2_saturation[i] = nitrogen_pressure[i] / 10.0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1018 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1019
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1020 if(!decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (deco_ceiling_depth / 10.0f) + pInput->pressure_surface_bar))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1021 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1022 vpm_violates_buehlmann = true;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1023 do {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1024 deco_ceiling_depth += 0.1f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1025 } while (!decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (deco_ceiling_depth / 10.0f) + pInput->pressure_surface_bar));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1026 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1027 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1028
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1029 if (deco_ceiling_depth < depth_start_of_deco_calc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1030 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1031 projected_ascent(&depth_start_of_deco_calc, &rate, &deco_ceiling_depth, &step_size);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1032 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1033
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1034 max_deco_ceiling_depth = fmaxf(max_deco_ceiling_depth,deco_ceiling_depth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1035
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1036 if(depth_start_of_deco_calc > deco_ceiling_depth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1037 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1038 gas_loadings_ascent_descen(helium_pressure,nitrogen_pressure, depth_start_of_deco_calc,deco_ceiling_depth, rate, true);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1039 //surfacetime += segment_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1040 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1041
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1042 if(vpm_b)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1043 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1044 BOYLES_LAW_COMPENSATION(&max_deco_ceiling_depth, &deco_ceiling_depth, &step_size);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1045 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1046 calc_deco_ceiling(&deco_ceiling_depth, false);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1047
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1048 // buehlmann safety
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1049 if(vpm_violates_buehlmann)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1050 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1051 for (i = 0; i < 16; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1052 {
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1053 tissue_He_saturation[i] = helium_pressure[i] / 10.0;
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1054 tissue_N2_saturation[i] = nitrogen_pressure[i] / 10.0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1055 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1056
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1057 if(!decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (deco_ceiling_depth / 10.0f) + pInput->pressure_surface_bar))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1058 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1059 vpm_violates_buehlmann = true;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1060 do {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1061 deco_ceiling_depth += 0.1f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1062 } while (!decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (deco_ceiling_depth / 10.0f) + pInput->pressure_surface_bar));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1063 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1064 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1065 // output_ceiling_meter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1066 if(deco_ceiling_depth > first_stop_depth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1067 deco_ceiling_depth = first_stop_depth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1068 pDecoInfo->output_ceiling_meter = deco_ceiling_depth ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1069 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1070 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1071 {
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1072 pDecoInfo->output_ceiling_meter = 0.0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1073 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1074
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1075 // fix hw 160627
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1076 if(pDecoInfo->output_ceiling_meter < 0.0)
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1077 pDecoInfo->output_ceiling_meter = 0.0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1078
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1079 /*** End CALC ceiling ***************************************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1080 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1081
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1082
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1083 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1084 /* DECO STOP LOOP BLOCK FOR FINAL DECOMPRESSION SCHEDULE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1085 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1086
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
1087 static int vpm_calc_final_deco(_Bool begin)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1088 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1089 short i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1090 float r1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1091 float stop_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1092 int count = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1093 static int dp_max;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1094 static float surfacetime;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1095 _Bool first_stop = false;
902
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
1096 float roundingValue = 0.0;
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1097
902
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
1098 uint16_t stop_time_seconds;
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1099
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1100 max_first_stop_depth = fmaxf(first_stop_depth,max_first_stop_depth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1101 if(begin)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1102 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1103 gCNS_VPM = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1104 dp_max = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1105 for (i = 1; i <= 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1106 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1107 helium_pressure[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1108 he_pressure_start_of_ascent[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1109 nitrogen_pressure[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1110 n2_pressure_start_of_ascent[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1111 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1112 run_time = run_time_start_of_ascent;// run_time_start_of_ascent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1113 starting_depth = depth_change[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1114 mix_number = mix_change[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1115 rate = rate_change[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1116 step_size = step_size_change[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1117 deco_stop_depth = first_stop_depth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1118 max_first_stop_depth = fmaxf(first_stop_depth,max_first_stop_depth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1119 last_run_time = 0.;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1120
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1121
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1122
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1123 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1124 /* DECO STOP LOOP BLOCK FOR FINAL DECOMPRESSION SCHEDULE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1125 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1126 surfacetime = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1127 first_stop = true;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1128 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1129
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1130 while(true) /* loop will run continuous until there is an break statement */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1131 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1132 if(starting_depth > deco_stop_depth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1133 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1134 gas_loadings_ascent_descen(helium_pressure,nitrogen_pressure, starting_depth,deco_stop_depth, rate, first_stop);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1135 surfacetime += segment_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1136 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1137
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1138 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1139 /* DURING FINAL DECOMPRESSION SCHEDULE PROCESS, COMPUTE MAXIMUM ACTUAL */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1140 /* SUPERSATURATION GRADIENT RESULTING IN EACH COMPARTMENT */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1141 /* If there is a repetitive dive, this will be used later in the VPM */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1142 /* Repetitive Algorithm to adjust the values for critical radii. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1143 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1144 if(vpm_calc_what == DECOSTOPS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1145 calc_max_actual_gradient(&deco_stop_depth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1146
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1147 if (deco_stop_depth <= 0.0f) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1148 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1149 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1150 if (number_of_changes > 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1151 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1152 int i1 = number_of_changes;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1153 for (i = 2; i <= i1; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1154 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1155 if (depth_change[i - 1] >= deco_stop_depth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1156 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1157 mix_number = mix_change[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1158 rate = rate_change[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1159 step_size = step_size_change[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1160 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1161 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1162 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1163
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1164 if(first_stop)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1165 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1166 run_time_first_stop = run_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1167 first_stop = false;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1168 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1169 if(vpm_b)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1170 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1171 BOYLES_LAW_COMPENSATION(&max_first_stop_depth, &deco_stop_depth, &step_size);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1172 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1173 decompression_stop(&deco_stop_depth, &step_size, true);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1174
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1175 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1176 /* This next bit justs rounds up the stop time at the first stop to be in */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1177 /* whole increments of the minimum stop time (to make for a nice deco table). */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1178 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1179
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1180 if (last_run_time == 0.0f)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1181 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1182 r1 = segment_time / minimum_deco_stop_time + 0.5f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1183 stop_time = r_int(&r1) * minimum_deco_stop_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1184 } else {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1185 stop_time = run_time - last_run_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1186 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1187 stop_time = segment_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1188 surfacetime += stop_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1189 if((vpm_calc_what == DECOSTOPS) || (vpm_calc_what == BAILOUTSTOPS))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1190 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1191 int dp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1192 if(deco_stop_depth == (float)pDiveSettings->last_stop_depth_bar * 10)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1193 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1194 dp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1195 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1196 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1197 {
902
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
1198 roundingValue = (deco_stop_depth - (pDiveSettings->input_second_to_last_stop_depth_bar * 10.0)) / step_size;
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
1199 dp = 1 + r_nint(&roundingValue);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1200 }
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1201
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1202 //dp_max = (int)fmaxf(dp_max,dp);
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1203 if(dp > dp_max)
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1204 {
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1205 dp_max = dp;
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1206 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1207 if(dp < DECOINFO_STRUCT_MAX_STOPS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1208 {
902
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
1209 stop_time_seconds = (uint16_t)(fminf((999.9 * 60.0), (stop_time *60.0)));
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1210 //
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1211
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1212 //if(vpm_calc_what == DECOSTOPS)
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1213 pDecoInfo->output_stop_length_seconds[dp] = stop_time_seconds;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1214 //else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1215 //decostop_bailout[dp] = (unsigned short)stop_time_seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1216 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1217 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1218
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1219
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1220 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1221 /* DURING FINAL DECOMPRESSION SCHEDULE, IF MINIMUM STOP TIME PARAMETER IS A */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1222 /* WHOLE NUMBER (i.e. 1 minute) THEN WRITE DECO SCHEDULE USING short */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1223 /* NUMBERS (looks nicer). OTHERWISE, USE DECIMAL NUMBERS. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1224 /* Note: per the request of a noted exploration diver(!), program now allows */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1225 /* a minimum stop time of less than one minute so that total ascent time can */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1226 /* be minimized on very long dives. In fact, with step size set at 1 fsw or */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1227 /* 0.2 msw and minimum stop time set at 0.1 minute (6 seconds), a near */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1228 /* continuous decompression schedule can be computed. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1229 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1230
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1231 starting_depth = deco_stop_depth;
877
a0900e4df15c DevBugfix: Exit condition deco_stop_depth
Ideenmodellierer
parents: 863
diff changeset
1232 if(deco_stop_depth == (float)pDiveSettings->last_stop_depth_bar * 10)
a0900e4df15c DevBugfix: Exit condition deco_stop_depth
Ideenmodellierer
parents: 863
diff changeset
1233 deco_stop_depth = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1234 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1235 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1236 deco_stop_depth = deco_stop_depth - step_size;
877
a0900e4df15c DevBugfix: Exit condition deco_stop_depth
Ideenmodellierer
parents: 863
diff changeset
1237 deco_stop_depth = fmaxf(deco_stop_depth,(float)pDiveSettings->last_stop_depth_bar * 10);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1238 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1239
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1240 last_run_time = run_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1241 count++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1242 //if(count > 14)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1243 //return CALC_FINAL_DECO2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1244 /* L80: */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1245 } /* for final deco sche */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1246
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1247 if( (vpm_calc_what == DECOSTOPS) || (vpm_calc_what == BAILOUTSTOPS))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1248 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1249 for(int dp = dp_max +1;dp < DECOINFO_STRUCT_MAX_STOPS;dp++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1250 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1251 //if(vpm_calc_what == DECOSTOPS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1252 pDecoInfo->output_stop_length_seconds[dp] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1253 //else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1254 //decostop_bailout[dp] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1255 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1256 }
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1257 pDecoInfo->output_time_to_surface_seconds = (int)(surfacetime * 60.0);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1258 pDecoInfo->output_ndl_seconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1259
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1260 vpm_calc_deco_ceiling();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1261 /* end of deco stop lo */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1262 return CALC_END;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1263 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1264
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1265 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1266 /* SUBROUTINE NUCLEAR_REGENERATION */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1267 /* Purpose: This subprogram calculates the regeneration of VPM critical */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1268 /* radii that takes place over the dive time. The regeneration time constant */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1269 /* has a time scale of weeks so this will have very little impact on dives of */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1270 /* normal length, but will have a major impact for saturation dives. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1271 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1272
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
1273 static int nuclear_regeneration(float *dive_time)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1274 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1275 /* Local variables */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1276 float crush_pressure_adjust_ratio_he,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1277 ending_radius_n2,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1278 ending_radius_he;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1279 short i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1280 float crushing_pressure_pascals_n2,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1281 crushing_pressure_pascals_he,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1282 adj_crush_pressure_n2_pascals,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1283 adj_crush_pressure_he_pascals,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1284 crush_pressure_adjust_ratio_n2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1285
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1286 /* loop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1287 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1288 /* CALCULATIONS */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1289 /* First convert the maximum crushing pressure obtained for each compartment */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1290 /* to Pascals. Next, compute the ending radius for helium and nitrogen */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1291 /* critical nuclei in each compartment. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1292 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1293
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1294 for (i = 1; i <= 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1295 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1296 crushing_pressure_pascals_he =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1297 pVpm->max_crushing_pressure_he[i - 1] / UNITS_FACTOR * 101325.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1298 crushing_pressure_pascals_n2 =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1299 pVpm->max_crushing_pressure_n2[i - 1] / UNITS_FACTOR * 101325.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1300 ending_radius_he =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1301 1.0f / (crushing_pressure_pascals_he /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1302 ((SKIN_COMPRESSION_GAMMAC - SURFACE_TENSION_GAMMA) * 2.0f) +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1303 1.0f / pVpm->adjusted_critical_radius_he[i - 1]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1304 ending_radius_n2 =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1305 1.0f / (crushing_pressure_pascals_n2 /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1306 ((SKIN_COMPRESSION_GAMMAC - SURFACE_TENSION_GAMMA) * 2.0f) +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1307 1.0f / pVpm->adjusted_critical_radius_n2[i - 1]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1308
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1309 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1310 /* A "regenerated" radius for each nucleus is now calculated based on the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1311 /* regeneration time constant. This means that after application of */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1312 /* crushing pressure and reduction in radius, a nucleus will slowly grow */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1313 /* back to its original initial radius over a period of time. This */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1314 /* phenomenon is probabilistic in nature and depends on absolute temperature. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1315 /* It is independent of crushing pressure. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1316 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1317
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1318 regenerated_radius_he[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1319 pVpm->adjusted_critical_radius_he[i - 1] +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1320 (ending_radius_he - pVpm->adjusted_critical_radius_he[i - 1]) *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1321 expf(-(*dive_time) / REGENERATION_TIME_CONSTANT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1322 regenerated_radius_n2[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1323 pVpm->adjusted_critical_radius_n2[i - 1] +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1324 (ending_radius_n2 - pVpm->adjusted_critical_radius_n2[i - 1]) *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1325 expf(-(*dive_time) / REGENERATION_TIME_CONSTANT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1326
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1327 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1328 /* In order to preserve reference back to the initial critical radii after */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1329 /* regeneration, an "adjusted crushing pressure" for the nuclei in each */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1330 /* compartment must be computed. In other words, this is the value of */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1331 /* crushing pressure that would have reduced the original nucleus to the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1332 /* to the present radius had regeneration not taken place. The ratio */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1333 /* for adjusting crushing pressure is obtained from algebraic manipulation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1334 /* of the standard VPM equations. The adjusted crushing pressure, in lieu */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1335 /* of the original crushing pressure, is then applied in the VPM Critical */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1336 /* Volume Algorithm and the VPM Repetitive Algorithm. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1337 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1338
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1339 crush_pressure_adjust_ratio_he =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1340 ending_radius_he * (pVpm->adjusted_critical_radius_he[i - 1] -
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1341 regenerated_radius_he[i - 1]) /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1342 (regenerated_radius_he[i - 1] *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1343 (pVpm->adjusted_critical_radius_he[i - 1] -
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1344 ending_radius_he));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1345 crush_pressure_adjust_ratio_n2 =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1346 ending_radius_n2 * (pVpm->adjusted_critical_radius_n2[i - 1] -
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1347 regenerated_radius_n2[i - 1]) /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1348 (regenerated_radius_n2[i - 1] *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1349 (pVpm->adjusted_critical_radius_n2[i - 1] -
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1350 ending_radius_n2));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1351 adj_crush_pressure_he_pascals =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1352 crushing_pressure_pascals_he * crush_pressure_adjust_ratio_he;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1353 adj_crush_pressure_n2_pascals =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1354 crushing_pressure_pascals_n2 * crush_pressure_adjust_ratio_n2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1355 pVpm->adjusted_crushing_pressure_he[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1356 adj_crush_pressure_he_pascals / 101325.0f * UNITS_FACTOR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1357 pVpm->adjusted_crushing_pressure_n2[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1358 adj_crush_pressure_n2_pascals / 101325.0f * UNITS_FACTOR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1359 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1360 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1361 } /* nuclear_regeneration */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1362
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1363 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1364 /* SUBROUTINE CALC_INITIAL_ALLOWABLE_GRADIENT */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1365 /* Purpose: This subprogram calculates the initial allowable gradients for */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1366 /* helium and nitrogren in each compartment. These are the gradients that */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1367 /* will be used to set the deco ceiling on the first pass through the deco */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1368 /* loop. If the Critical Volume Algorithm is set to "off", then these */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1369 /* gradients will determine the final deco schedule. Otherwise, if the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1370 /* Critical Volume Algorithm is set to "on", these gradients will be further */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1371 /* "relaxed" by the Critical Volume Algorithm subroutine. The initial */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1372 /* allowable gradients are referred to as "PssMin" in the papers by Yount */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1373 /* and colleauges, i.e., the minimum supersaturation pressure gradients */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1374 /* that will probe bubble formation in the VPM nuclei that started with the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1375 /* designated minimum initial radius (critical radius). */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1376
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1377 /* The initial allowable gradients are computed directly from the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1378 /* "regenerated" radii after the Nuclear Regeneration subroutine. These */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1379 /* gradients are tracked separately for helium and nitrogen. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1380 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1381
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
1382 static int calc_initial_allowable_gradient()
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1383 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1384 float initial_allowable_grad_n2_pa,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1385 initial_allowable_grad_he_pa;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1386 short i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1387
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1388 /* loop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1389 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1390 /* CALCULATIONS */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1391 /* The initial allowable gradients are computed in Pascals and then converted */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1392 /* to the diving pressure units. Two different sets of arrays are used to */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1393 /* save the calculations - Initial Allowable Gradients and Allowable */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1394 /* Gradients. The Allowable Gradients are assigned the values from Initial */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1395 /* Allowable Gradients however the Allowable Gradients can be changed later */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1396 /* by the Critical Volume subroutine. The values for the Initial Allowable */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1397 /* Gradients are saved in a global array for later use by both the Critical */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1398 /* Volume subroutine and the VPM Repetitive Algorithm subroutine. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1399 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1400
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1401 for (i = 1; i <= 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1402 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1403 initial_allowable_grad_n2_pa =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1404 SURFACE_TENSION_GAMMA * 2.0f *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1405 (SKIN_COMPRESSION_GAMMAC - SURFACE_TENSION_GAMMA) /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1406 (regenerated_radius_n2[i - 1] * SKIN_COMPRESSION_GAMMAC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1407
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1408 initial_allowable_grad_he_pa =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1409 SURFACE_TENSION_GAMMA * 2.0f *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1410 (SKIN_COMPRESSION_GAMMAC - SURFACE_TENSION_GAMMA) /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1411 (regenerated_radius_he[i - 1] * SKIN_COMPRESSION_GAMMAC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1412
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1413 pVpm->initial_allowable_gradient_n2[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1414 initial_allowable_grad_n2_pa / 101325.0f * UNITS_FACTOR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1415
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1416 pVpm->initial_allowable_gradient_he[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1417 initial_allowable_grad_he_pa / 101325.0f * UNITS_FACTOR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1418
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1419 allowable_gradient_he[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1420 pVpm->initial_allowable_gradient_he[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1421
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1422 allowable_gradient_n2[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1423 pVpm->initial_allowable_gradient_n2[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1424 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1425 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1426 } /* calc_initial_allowable_gradient */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1427
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1428 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1429 /* SUBROUTINE CALC_DECO_CEILING */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1430 /* Purpose: This subprogram calculates the deco ceiling (the safe ascent */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1431 /* depth) in each compartment, based on the allowable gradients, and then */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1432 /* finds the deepest deco ceiling across all compartments. This deepest */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1433 /* value (Deco Ceiling Depth) is then used by the Decompression Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1434 /* subroutine to determine the actual deco schedule. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1435 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1436
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
1437 static int calc_deco_ceiling(float *deco_ceiling_depth,_Bool fallowable)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1438 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1439 /* System generated locals */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1440 float r1, r2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1441 /* Local variables */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1442 float weighted_allowable_gradient;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1443 short i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1444 float compartment_deco_ceiling[16],
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1445 gas_loading,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1446 tolerated_ambient_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1447 float gradient_he, gradient_n2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1448
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1449 if(!vpm_b)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1450 fallowable = true;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1451 /* loop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1452 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1453 /* CALCULATIONS */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1454 /* Since there are two sets of allowable gradients being tracked, one for */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1455 /* helium and one for nitrogen, a "weighted allowable gradient" must be */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1456 /* computed each time based on the proportions of helium and nitrogen in */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1457 /* each compartment. This proportioning follows the methodology of */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1458 /* Buhlmann/Keller. If there is no helium and nitrogen in the compartment, */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1459 /* such as after extended periods of oxygen breathing, then the minimum value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1460 /* across both gases will be used. It is important to note that if a */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1461 /* compartment is empty of helium and nitrogen, then the weighted allowable */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1462 /* gradient formula cannot be used since it will result in division by zero. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1463 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1464
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1465 for (i = 1; i <= 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1466 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1467
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1468 // abfrage raus und pointer stattdessen
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1469 if(fallowable){
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1470 gradient_he = allowable_gradient_he[i-1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1471 gradient_n2 = allowable_gradient_n2[i-1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1472 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1473 else{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1474 gradient_he = deco_gradient_he[i-1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1475 gradient_n2 = deco_gradient_n2[i-1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1476 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1477
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1478 gas_loading = helium_pressure[i - 1] + nitrogen_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1479
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1480 if (gas_loading > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1481 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1482 weighted_allowable_gradient =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1483 (gradient_he * helium_pressure[i - 1] +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1484 gradient_n2 * nitrogen_pressure[i - 1]) /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1485 (helium_pressure[i - 1] + nitrogen_pressure[i - 1]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1486
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1487 tolerated_ambient_pressure =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1488 gas_loading +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1489 CONSTANT_PRESSURE_OTHER_GASES -
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1490 weighted_allowable_gradient;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1491 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1492 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1493 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1494 /* Computing MIN */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1495 r1 = gradient_he;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1496 r2 = gradient_n2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1497 weighted_allowable_gradient = fminf(r1,r2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1498
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1499 tolerated_ambient_pressure =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1500 CONSTANT_PRESSURE_OTHER_GASES - weighted_allowable_gradient;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1501 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1502
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1503 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1504 /* The tolerated ambient pressure cannot be less than zero absolute, i.e., */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1505 /* the vacuum of outer space! */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1506 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1507
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1508 if (tolerated_ambient_pressure < 0.0) {
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1509 tolerated_ambient_pressure = 0.0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1510 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1511 compartment_deco_ceiling[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1512 tolerated_ambient_pressure - barometric_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1513 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1514
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1515 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1516 /* The Deco Ceiling Depth is computed in a loop after all of the individual */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1517 /* compartment deco ceilings have been calculated. It is important that the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1518 /* Deco Ceiling Depth (max deco ceiling across all compartments) only be */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1519 /* extracted from the compartment values and not be compared against some */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1520 /* initialization value. For example, if MAX(Deco_Ceiling_Depth . .) was */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1521 /* compared against zero, this could cause a program lockup because sometimes */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1522 /* the Deco Ceiling Depth needs to be negative (but not less than zero */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1523 /* absolute ambient pressure) in order to decompress to the last stop at zero */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1524 /* depth. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1525 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1526
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1527 *deco_ceiling_depth = compartment_deco_ceiling[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1528 for (i = 2; i <= 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1529 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1530 /* Computing MAX */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1531 r1 = *deco_ceiling_depth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1532 r2 = compartment_deco_ceiling[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1533 *deco_ceiling_depth = fmaxf(r1,r2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1534 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1535 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1536 } /* calc_deco_ceiling */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1537
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1538
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1539
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1540 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1541 /* SUBROUTINE CALC_MAX_ACTUAL_GRADIENT */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1542 /* Purpose: This subprogram calculates the actual supersaturation gradient */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1543 /* obtained in each compartment as a result of the ascent profile during */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1544 /* decompression. Similar to the concept with crushing pressure, the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1545 /* supersaturation gradients are not cumulative over a multi-level, staged */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1546 /* ascent. Rather, it will be the maximum value obtained in any one discrete */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1547 /* step of the overall ascent. Thus, the program must compute and store the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1548 /* maximum actual gradient for each compartment that was obtained across all */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1549 /* steps of the ascent profile. This subroutine is invoked on the last pass */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1550 /* through the deco stop loop block when the final deco schedule is being */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1551 /* generated. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1552 /* */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1553 /* The max actual gradients are later used by the VPM Repetitive Algorithm to */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1554 /* determine if adjustments to the critical radii are required. If the max */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1555 /* actual gradient did not exceed the initial alllowable gradient, then no */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1556 /* adjustment will be made. However, if the max actual gradient did exceed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1557 /* the intitial allowable gradient, such as permitted by the Critical Volume */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1558 /* Algorithm, then the critical radius will be adjusted (made larger) on the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1559 /* repetitive dive to compensate for the bubbling that was allowed on the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1560 /* previous dive. The use of the max actual gradients is intended to prevent */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1561 /* the repetitive algorithm from being overly conservative. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1562 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1563
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
1564 static int calc_max_actual_gradient(float *deco_stop_depth)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1565 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1566 /* System generated locals */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1567 float r1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1568
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1569 /* Local variables */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1570 short i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1571 float compartment_gradient;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1572
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1573 /* loop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1574 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1575 /* CALCULATIONS */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1576 /* Note: negative supersaturation gradients are meaningless for this */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1577 /* application, so the values must be equal to or greater than zero. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1578 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1579
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1580 for (i = 1; i <= 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1581 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1582 compartment_gradient =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1583 helium_pressure[i - 1] +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1584 nitrogen_pressure[i - 1] +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1585 CONSTANT_PRESSURE_OTHER_GASES -
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1586 (*deco_stop_depth + barometric_pressure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1587 if (compartment_gradient <= 0.0f) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1588 compartment_gradient = 0.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1589 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1590 /* Computing MAX */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1591 r1 = pVpm->max_actual_gradient[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1592 pVpm->max_actual_gradient[i - 1] = fmaxf(r1, compartment_gradient);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1593 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1594 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1595 } /* calc_max_actual_gradient */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1596
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1597 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1598 /* SUBROUTINE CALC_SURFACE_PHASE_VOLUME_TIME */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1599 /* Purpose: This subprogram computes the surface portion of the total phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1600 /* volume time. This is the time factored out of the integration of */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1601 /* supersaturation gradient x time over the surface interval. The VPM */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1602 /* considers the gradients that allow bubbles to form or to drive bubble */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1603 /* growth both in the water and on the surface after the dive. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1604
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1605 /* This subroutine is a new development to the VPM algorithm in that it */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1606 /* computes the time course of supersaturation gradients on the surface */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1607 /* when both helium and nitrogen are present. Refer to separate write-up */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1608 /* for a more detailed explanation of this algorithm. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1609 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1610
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
1611 static int calc_surface_phase_volume_time()
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1612 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1613 /* Local variables */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1614 float decay_time_to_zero_gradient;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1615 short i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1616 float integral_gradient_x_time,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1617 surface_inspired_n2_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1618
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1619 /* loop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1620 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1621 /* CALCULATIONS */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1622 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1623
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1624 surface_inspired_n2_pressure =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1625 (barometric_pressure - WATER_VAPOR_PRESSURE) * 0.79f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1626 for (i = 1; i <= 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1627 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1628 if (nitrogen_pressure[i - 1] > surface_inspired_n2_pressure)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1629 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1630 surface_phase_volume_time[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1631 (helium_pressure[i - 1] / HELIUM_TIME_CONSTANT[i - 1] +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1632 (nitrogen_pressure[i - 1] - surface_inspired_n2_pressure) /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1633 NITROGEN_TIME_CONSTANT[i - 1]) /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1634 (helium_pressure[i - 1] + nitrogen_pressure[i - 1] -
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1635 surface_inspired_n2_pressure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1636 } else if (nitrogen_pressure[i - 1] <= surface_inspired_n2_pressure &&
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1637 helium_pressure[i - 1] + nitrogen_pressure[i - 1] >= surface_inspired_n2_pressure)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1638 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1639 decay_time_to_zero_gradient =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1640 1.0f / (NITROGEN_TIME_CONSTANT[i - 1] - HELIUM_TIME_CONSTANT[i - 1]) *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1641 log((surface_inspired_n2_pressure - nitrogen_pressure[i - 1]) /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1642 helium_pressure[i - 1]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1643 integral_gradient_x_time =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1644 helium_pressure[i - 1] /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1645 HELIUM_TIME_CONSTANT[i - 1] *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1646 (1.0f - expf(-HELIUM_TIME_CONSTANT[i - 1] *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1647 decay_time_to_zero_gradient)) +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1648 (nitrogen_pressure[i - 1] - surface_inspired_n2_pressure) /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1649 NITROGEN_TIME_CONSTANT[i - 1] *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1650 (1.0f - expf(-NITROGEN_TIME_CONSTANT[i - 1] *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1651 decay_time_to_zero_gradient));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1652 surface_phase_volume_time[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1653 integral_gradient_x_time /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1654 (helium_pressure[i - 1] +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1655 nitrogen_pressure[i - 1] -
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1656 surface_inspired_n2_pressure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1657 } else {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1658 surface_phase_volume_time[i - 1] = 0.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1659 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1660 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1661 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1662 } /* calc_surface_phase_volume_time */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1663
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1664 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1665 /* SUBROUTINE CRITICAL_VOLUME */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1666 /* Purpose: This subprogram applies the VPM Critical Volume Algorithm. This */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1667 /* algorithm will compute "relaxed" gradients for helium and nitrogen based */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1668 /* on the setting of the Critical Volume Parameter Lambda. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1669 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1670
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
1671 static int critical_volume(float *deco_phase_volume_time)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1672 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1673 /* System generated locals */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1674 float r1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1675
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1676 /* Local variables */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1677 float initial_allowable_grad_n2_pa,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1678 initial_allowable_grad_he_pa,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1679 parameter_lambda_pascals, b,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1680 c;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1681 short i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1682 float new_allowable_grad_n2_pascals,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1683 phase_volume_time[16],
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1684 new_allowable_grad_he_pascals,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1685 adj_crush_pressure_n2_pascals,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1686 adj_crush_pressure_he_pascals;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1687
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1688 /* loop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1689 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1690 /* CALCULATIONS */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1691 /* Note: Since the Critical Volume Parameter Lambda was defined in units of */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1692 /* fsw-min in the original papers by Yount and colleauges, the same */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1693 /* convention is retained here. Although Lambda is adjustable only in units */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1694 /* of fsw-min in the program settings (range from 6500 to 8300 with default */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1695 /* 7500), it will convert to the proper value in Pascals-min in this */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1696 /* subroutine regardless of which diving pressure units are being used in */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1697 /* the main program - feet of seawater (fsw) or meters of seawater (msw). */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1698 /* The allowable gradient is computed using the quadratic formula (refer to */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1699 /* separate write-up posted on the Deco List web site). */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1700 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1701
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1702 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1703 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1704 * @brief critical_volume comment by hw
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1705 * @version V0.0.1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1706 * @date 19-April-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1707 * @retval global: allowable_gradient_he[i], allowable_gradient_n2[i]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1708 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1709 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1710
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1711 parameter_lambda_pascals =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1712 CRIT_VOLUME_PARAMETER_LAMBDA / 33.0f * 101325.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1713 for (i = 1; i <= 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1714 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1715 phase_volume_time[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1716 *deco_phase_volume_time + surface_phase_volume_time[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1717 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1718 for (i = 1; i <= 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1719 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1720
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1721 adj_crush_pressure_he_pascals =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1722 pVpm->adjusted_crushing_pressure_he[i - 1] / UNITS_FACTOR * 101325.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1723
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1724 initial_allowable_grad_he_pa =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1725 pVpm->initial_allowable_gradient_he[i - 1] / UNITS_FACTOR * 101325.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1726
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1727 b = initial_allowable_grad_he_pa + parameter_lambda_pascals *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1728 SURFACE_TENSION_GAMMA / (
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1729 SKIN_COMPRESSION_GAMMAC * phase_volume_time[i - 1]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1730
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1731 c = SURFACE_TENSION_GAMMA * (
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1732 SURFACE_TENSION_GAMMA * (
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1733 parameter_lambda_pascals * adj_crush_pressure_he_pascals)) /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1734 (SKIN_COMPRESSION_GAMMAC *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1735 (SKIN_COMPRESSION_GAMMAC * phase_volume_time[i - 1]));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1736 /* Computing 2nd power */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1737
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1738 r1 = b;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1739
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1740 new_allowable_grad_he_pascals =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1741 (b + sqrtf(r1 * r1 - c * 4.0f)) / 2.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1742
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1743 /* modify global variable */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1744 allowable_gradient_he[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1745 new_allowable_grad_he_pascals / 101325.0f * UNITS_FACTOR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1746 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1747
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1748 for (i = 1; i <= 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1749 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1750 adj_crush_pressure_n2_pascals =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1751 pVpm->adjusted_crushing_pressure_n2[i - 1] / UNITS_FACTOR * 101325.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1752
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1753 initial_allowable_grad_n2_pa =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1754 pVpm->initial_allowable_gradient_n2[i - 1] / UNITS_FACTOR * 101325.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1755
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1756 b = initial_allowable_grad_n2_pa + parameter_lambda_pascals *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1757 SURFACE_TENSION_GAMMA / (
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1758 SKIN_COMPRESSION_GAMMAC * phase_volume_time[i - 1]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1759
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1760 c = SURFACE_TENSION_GAMMA *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1761 (SURFACE_TENSION_GAMMA *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1762 (parameter_lambda_pascals * adj_crush_pressure_n2_pascals)) /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1763 (SKIN_COMPRESSION_GAMMAC *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1764 (SKIN_COMPRESSION_GAMMAC * phase_volume_time[i - 1]));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1765 /* Computing 2nd power */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1766
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1767 r1 = b;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1768
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1769 new_allowable_grad_n2_pascals =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1770 (b + sqrtf(r1 * r1 - c * 4.0f)) / 2.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1771
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1772 /* modify global variable */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1773 allowable_gradient_n2[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1774 new_allowable_grad_n2_pascals / 101325.0f * UNITS_FACTOR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1775 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1776 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1777 } /* critical_volume */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1778
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1779 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1780 /* SUBROUTINE CALC_START_OF_DECO_ZONE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1781 /* Purpose: This subroutine uses the Bisection Method to find the depth at */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1782 /* which the leading compartment just enters the decompression zone. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1783 /* Source: "Numerical Recipes in Fortran 77", Cambridge University Press, */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1784 /* 1992. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1785 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1786
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
1787 static int calc_start_of_deco_zone(float *starting_depth,
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1788 float *rate,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1789 float *depth_start_of_deco_zone)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1790 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1791 /* Local variables */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1792 float last_diff_change,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1793 initial_helium_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1794 mid_range_nitrogen_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1795 short i, j;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1796 float initial_inspired_n2_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1797 cpt_depth_start_of_deco_zone,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1798 low_bound,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1799 initial_inspired_he_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1800 high_bound_nitrogen_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1801 nitrogen_rate,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1802 function_at_mid_range,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1803 function_at_low_bound,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1804 high_bound,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1805 mid_range_helium_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1806 mid_range_time,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1807 starting_ambient_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1808 initial_nitrogen_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1809 function_at_high_bound;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1810
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1811 float time_to_start_of_deco_zone,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1812 high_bound_helium_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1813 helium_rate,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1814 differential_change;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1815 float fraction_helium_begin;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1816 float fraction_helium_end;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1817 float fraction_nitrogen_begin;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1818 float fraction_nitrogen_end;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1819 float ending_ambient_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1820 float time_test;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1821
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1822
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1823 /* loop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1824 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1825 /* CALCULATIONS */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1826 /* First initialize some variables */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1827 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1828
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1829 *depth_start_of_deco_zone = 0.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1830 starting_ambient_pressure = *starting_depth + barometric_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1831
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1832 //>>>>>>>>>>>>>>>>>>>>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1833 //Test depth to calculate helium_rate and nitrogen_rate
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1834 ending_ambient_pressure = starting_ambient_pressure/2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1835
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1836 time_test = (ending_ambient_pressure - starting_ambient_pressure) / *rate;
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1837 decom_get_inert_gases(starting_ambient_pressure / 10.0, (&pDiveSettings->decogaslist[mix_number]), &fraction_nitrogen_begin, &fraction_helium_begin );
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1838 decom_get_inert_gases(ending_ambient_pressure / 10.0, (&pDiveSettings->decogaslist[mix_number]), &fraction_nitrogen_end, &fraction_helium_end );
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1839 initial_inspired_he_pressure = (starting_ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_helium_begin;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1840 initial_inspired_n2_pressure = (starting_ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_nitrogen_begin;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1841 helium_rate = ((ending_ambient_pressure - WATER_VAPOR_PRESSURE)* fraction_helium_end - initial_inspired_he_pressure)/time_test;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1842 nitrogen_rate = ((ending_ambient_pressure - WATER_VAPOR_PRESSURE)* fraction_nitrogen_end - initial_inspired_n2_pressure)/time_test;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1843 //>>>>>>>>>>>>>>>>>>>>>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1844 /*initial_inspired_he_pressure =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1845 (starting_ambient_pressure - water_vapor_pressure) *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1846 fraction_helium[mix_number - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1847 initial_inspired_n2_pressure =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1848 (starting_ambient_pressure - water_vapor_pressure) *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1849 fraction_nitrogen[mix_number - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1850 helium_rate = *rate * fraction_helium[mix_number - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1851 nitrogen_rate = *rate * fraction_nitrogen[mix_number - 1];*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1852
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1853 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1854 /* ESTABLISH THE BOUNDS FOR THE ROOT SEARCH USING THE BISECTION METHOD */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1855 /* AND CHECK TO MAKE SURE THAT THE ROOT WILL BE WITHIN BOUNDS. PROCESS */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1856 /* EACH COMPARTMENT INDIVIDUALLY AND FIND THE MAXIMUM DEPTH ACROSS ALL */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1857 /* COMPARTMENTS (LEADING COMPARTMENT) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1858 /* In this case, we are solving for time - the time when the gas tension in */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1859 /* the compartment will be equal to ambient pressure. The low bound for time */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1860 /* is set at zero and the high bound is set at the time it would take to */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1861 /* ascend to zero ambient pressure (absolute). Since the ascent rate is */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1862 /* negative, a multiplier of -1.0 is used to make the time positive. The */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1863 /* desired point when gas tension equals ambient pressure is found at a time */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1864 /* somewhere between these endpoints. The algorithm checks to make sure that */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1865 /* the solution lies in between these bounds by first computing the low bound */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1866 /* and high bound function values. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1867 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1868
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
1869 low_bound = 0.0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1870 high_bound = starting_ambient_pressure / *rate * -1.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1871 for (i = 1; i <= 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1872 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1873 initial_helium_pressure = helium_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1874 initial_nitrogen_pressure = nitrogen_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1875 function_at_low_bound =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1876 initial_helium_pressure +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1877 initial_nitrogen_pressure +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1878 CONSTANT_PRESSURE_OTHER_GASES -
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1879 starting_ambient_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1880 high_bound_helium_pressure =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1881 schreiner_equation__2(&initial_inspired_he_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1882 &helium_rate,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1883 &high_bound,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1884 &HELIUM_TIME_CONSTANT[i - 1],
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1885 &initial_helium_pressure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1886 high_bound_nitrogen_pressure =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1887 schreiner_equation__2(&initial_inspired_n2_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1888 &nitrogen_rate,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1889 &high_bound,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1890 &NITROGEN_TIME_CONSTANT[i - 1],
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1891 &initial_nitrogen_pressure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1892 function_at_high_bound = high_bound_helium_pressure +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1893 high_bound_nitrogen_pressure +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1894 CONSTANT_PRESSURE_OTHER_GASES;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1895 if (function_at_high_bound * function_at_low_bound >= 0.0f)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1896 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1897 printf("\nERROR! ROOT IS NOT WITHIN BRACKETS");
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1898 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1899
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1900 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1901 /* APPLY THE BISECTION METHOD IN SEVERAL ITERATIONS UNTIL A SOLUTION WITH */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1902 /* THE DESIRED ACCURACY IS FOUND */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1903 /* Note: the program allows for up to 100 iterations. Normally an exit will */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1904 /* be made from the loop well before that number. If, for some reason, the */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1905 /* program exceeds 100 iterations, there will be a pause to alert the user. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1906 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1907
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1908 if (function_at_low_bound < 0.0f)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1909 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1910 time_to_start_of_deco_zone = low_bound;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1911 differential_change = high_bound - low_bound;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1912 } else {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1913 time_to_start_of_deco_zone = high_bound;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1914 differential_change = low_bound - high_bound;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1915 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1916 for (j = 1; j <= 100; ++j)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1917 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1918 last_diff_change = differential_change;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1919 differential_change = last_diff_change * 0.5f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1920 mid_range_time =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1921 time_to_start_of_deco_zone +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1922 differential_change;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1923 mid_range_helium_pressure =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1924 schreiner_equation__2(&initial_inspired_he_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1925 &helium_rate,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1926 &mid_range_time,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1927 &HELIUM_TIME_CONSTANT[i - 1],
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1928 &initial_helium_pressure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1929 mid_range_nitrogen_pressure =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1930 schreiner_equation__2(&initial_inspired_n2_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1931 &nitrogen_rate,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1932 &mid_range_time,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1933 &NITROGEN_TIME_CONSTANT[i - 1],
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1934 &initial_nitrogen_pressure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1935 function_at_mid_range =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1936 mid_range_helium_pressure +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1937 mid_range_nitrogen_pressure +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1938 CONSTANT_PRESSURE_OTHER_GASES -
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1939 (starting_ambient_pressure + *rate * mid_range_time);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1940 if (function_at_mid_range <= 0.0f) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1941 time_to_start_of_deco_zone = mid_range_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1942 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1943 if( fabs(differential_change) < 0.001f
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1944 || function_at_mid_range == 0.0f)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1945 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1946 goto L170;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1947 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1948 /* L150: */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1949 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1950 printf("\nERROR! ROOT SEARCH EXCEEDED MAXIMUM ITERATIONS");
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1951 //pause();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1952
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1953 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1954 /* When a solution with the desired accuracy is found, the program jumps out */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1955 /* of the loop to Line 170 and assigns the solution value for the individual */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1956 /* compartment. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1957 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1958
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1959 L170:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1960 cpt_depth_start_of_deco_zone =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1961 starting_ambient_pressure +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1962 *rate * time_to_start_of_deco_zone -
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1963 barometric_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1964
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1965 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1966 /* The overall solution will be the compartment with the maximum depth where */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1967 /* gas tension equals ambient pressure (leading compartment). */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1968 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1969
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1970 *depth_start_of_deco_zone =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1971 fmaxf(*depth_start_of_deco_zone, cpt_depth_start_of_deco_zone);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1972 /* L200: */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1973 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1974 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1975 } /* calc_start_of_deco_zone */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1976
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1977 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1978 /* SUBROUTINE PROJECTED_ASCENT */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1979 /* Purpose: This subprogram performs a simulated ascent outside of the main */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1980 /* program to ensure that a deco ceiling will not be violated due to unusual */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1981 /* gas loading during ascent (on-gassing). If the deco ceiling is violated, */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1982 /* the stop depth will be adjusted deeper by the step size until a safe */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1983 /* ascent can be made. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1984 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1985
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
1986 static int projected_ascent(float *starting_depth,
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1987 float *rate,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1988 float *deco_stop_depth,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1989 float *step_size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1990 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1991 /* Local variables */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1992 float weighted_allowable_gradient,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1993 ending_ambient_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1994 temp_gas_loading[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1995 int i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1996 float allowable_gas_loading[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1997 float temp_nitrogen_pressure[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1998 float temp_helium_pressure[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1999 float run_time_save = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2000
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2001 /* loop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2002 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2003 /* CALCULATIONS */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2004 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2005
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2006
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2007 L665:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2008 ending_ambient_pressure = *deco_stop_depth + barometric_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2009 for (i = 1; i <= 16; ++i) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2010 temp_helium_pressure[i - 1] = helium_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2011 temp_nitrogen_pressure[i - 1] = nitrogen_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2012 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2013 run_time_save = run_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2014 gas_loadings_ascent_descen(temp_helium_pressure, temp_nitrogen_pressure, *starting_depth,*deco_stop_depth,*rate,true);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2015 run_time = run_time_save;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2016
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2017 for (i = 1; i <= 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2018 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2019 temp_gas_loading[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2020 temp_helium_pressure[i - 1] +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2021 temp_nitrogen_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2022 if (temp_gas_loading[i - 1] > 0.0f)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2023 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2024 weighted_allowable_gradient =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2025 (allowable_gradient_he[i - 1] *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2026 temp_helium_pressure[i - 1] +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2027 allowable_gradient_n2[i - 1] *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2028 temp_nitrogen_pressure[i - 1]) / temp_gas_loading[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2029 } else {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2030 /* Computing MIN */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2031 weighted_allowable_gradient = fminf(allowable_gradient_he[i - 1],allowable_gradient_n2[i - 1]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2032 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2033 allowable_gas_loading[i - 1] =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2034 ending_ambient_pressure +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2035 weighted_allowable_gradient -
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2036 CONSTANT_PRESSURE_OTHER_GASES;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2037 /* L670: */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2038 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2039 for (i = 1; i <= 16; ++i) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2040 if (temp_gas_loading[i - 1] > allowable_gas_loading[i - 1]) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2041 *deco_stop_depth += *step_size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2042 goto L665;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2043 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2044 /* L671: */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2045 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2046 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2047 } /* projected_ascent */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2048
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2049 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2050 /* SUBROUTINE DECOMPRESSION_STOP */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2051 /* Purpose: This subprogram calculates the required time at each */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2052 /* decompression stop. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2053 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2054
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
2055 static void decompression_stop(float *deco_stop_depth,
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2056 float *step_size,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2057 _Bool final_deco_calculation)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2058 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2059 /* Local variables */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2060 float inspired_nitrogen_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2061 // short last_segment_number;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2062 // float weighted_allowable_gradient;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2063 float initial_helium_pressure[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2064 /* by hw */
51
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
2065 float initial_CNS = gCNS_VPM;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2066
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2067 //static float time_counter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2068 short i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2069 float ambient_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2070 float inspired_helium_pressure,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2071 next_stop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2072 //last_run_time,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2073 //temp_segment_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2074
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2075 float deco_ceiling_depth,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2076 initial_nitrogen_pressure[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2077 //round_up_operation;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2078 float fraction_helium_begin;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2079 float fraction_nitrogen_begin;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2080 int count = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2081 _Bool buehlmann_wait = false;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2082 float tissue_He_saturation[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2083 float tissue_N2_saturation[16];
877
a0900e4df15c DevBugfix: Exit condition deco_stop_depth
Ideenmodellierer
parents: 863
diff changeset
2084 float vpm_buehlmann_safety_gradient = 1.0f - (((float)pDiveSettings->vpm_conservatism) / 40);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2085 /* loop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2086 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2087 /* CALCULATIONS */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2088 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2089
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2090 segment_time = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2091 // temp_segment_time = segment_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2092 ambient_pressure = *deco_stop_depth + barometric_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2093 //ending_ambient_pressure = ambient_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2094 decom_get_inert_gases(ambient_pressure / 10, (&pDiveSettings->decogaslist[mix_number]), &fraction_nitrogen_begin, &fraction_helium_begin );
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2095
877
a0900e4df15c DevBugfix: Exit condition deco_stop_depth
Ideenmodellierer
parents: 863
diff changeset
2096 if(*deco_stop_depth == (float)(pDiveSettings->last_stop_depth_bar * 10))
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2097 next_stop = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2098 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2099 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2100 next_stop = *deco_stop_depth - *step_size;
877
a0900e4df15c DevBugfix: Exit condition deco_stop_depth
Ideenmodellierer
parents: 863
diff changeset
2101 next_stop = fmaxf(next_stop,(float)pDiveSettings->last_stop_depth_bar * 10);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2102 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2103
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2104 inspired_helium_pressure =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2105 (ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_helium_begin;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2106 inspired_nitrogen_pressure =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2107 (ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_nitrogen_begin;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2108
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2109 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2110 /* Check to make sure that program won't lock up if unable to decompress */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2111 /* to the next stop. If so, write error message and terminate program. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2112 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2113
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2114 //deco_ceiling_depth = next_stop +1; //deco_ceiling_depth = next_stop + 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2115 if(!vpm_violates_buehlmann)
149
e1d66bc78f9a Eliminate warnings
Ideenmodellierer
parents: 51
diff changeset
2116 {
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2117 calc_deco_ceiling(&deco_ceiling_depth, false); //weg, weil auf jeden Fall schleife für safety und so konservativer
149
e1d66bc78f9a Eliminate warnings
Ideenmodellierer
parents: 51
diff changeset
2118 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2119 else
149
e1d66bc78f9a Eliminate warnings
Ideenmodellierer
parents: 51
diff changeset
2120 {
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
2121 deco_ceiling_depth = next_stop + 1.0;
149
e1d66bc78f9a Eliminate warnings
Ideenmodellierer
parents: 51
diff changeset
2122 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2123 if(deco_ceiling_depth > next_stop)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2124 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2125 while (deco_ceiling_depth > next_stop)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2126 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2127
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
2128 segment_time += 60.0;
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
2129 if(segment_time >= 999.0 )
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2130 {
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
2131 segment_time = 999.0 ;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2132 run_time += segment_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2133 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2134 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2135 //goto L700;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2136 initial_CNS = gCNS_VPM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2137 decom_oxygen_calculate_cns_exposure(60*60,&pDiveSettings->decogaslist[mix_number],ambient_pressure/10,&gCNS_VPM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2138 for (i = 0; i < 16; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2139 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2140 initial_helium_pressure[i] = helium_pressure[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2141 initial_nitrogen_pressure[i] = nitrogen_pressure[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2142 helium_pressure[i] += (inspired_helium_pressure - helium_pressure[i]) * float_buehlmann_He_factor_expositon_one_hour[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2143 nitrogen_pressure[i] += (inspired_nitrogen_pressure - nitrogen_pressure[i]) * float_buehlmann_N2_factor_expositon_one_hour[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2144 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2145 calc_deco_ceiling(&deco_ceiling_depth, false);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2146 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2147 if(deco_ceiling_depth < next_stop)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2148 {
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
2149 segment_time -= 60.0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2150 gCNS_VPM = initial_CNS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2151 for (i = 0; i < 16; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2152 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2153 helium_pressure[i] = initial_helium_pressure[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2154 nitrogen_pressure[i] = initial_nitrogen_pressure[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2155 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2156 deco_ceiling_depth = next_stop +1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2157 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2158 count = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2159 while (deco_ceiling_depth > next_stop && count < 13)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2160 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2161 count++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2162 segment_time += 5;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2163 //goto L700;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2164 initial_CNS = gCNS_VPM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2165 decom_oxygen_calculate_cns_exposure(60*5,&pDiveSettings->decogaslist[mix_number],ambient_pressure/10,&gCNS_VPM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2166 for (i = 0; i < 16; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2167 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2168 initial_helium_pressure[i] = helium_pressure[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2169 initial_nitrogen_pressure[i] = nitrogen_pressure[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2170 helium_pressure[i] += (inspired_helium_pressure - helium_pressure[i]) * float_buehlmann_He_factor_expositon_five_minutes[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2171 nitrogen_pressure[i] += (inspired_nitrogen_pressure - nitrogen_pressure[i]) * float_buehlmann_N2_factor_expositon_five_minutes[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2172 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2173 calc_deco_ceiling(&deco_ceiling_depth, false);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2174 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2175 if(deco_ceiling_depth < next_stop)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2176 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2177 segment_time -= 5;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2178 gCNS_VPM = initial_CNS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2179 for (i = 0; i < 16; i++) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2180 helium_pressure[i] = initial_helium_pressure[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2181 nitrogen_pressure[i] = initial_nitrogen_pressure[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2182 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2183 deco_ceiling_depth = next_stop +1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2184 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2185 buehlmann_wait = false;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2186 while (buehlmann_wait || (deco_ceiling_depth > next_stop))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2187 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2188 //time_counter = temp_segment_time;
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
2189 segment_time += 1.0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2190
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
2191 if(segment_time >= 999.0 )
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2192 {
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
2193 segment_time = 999.0 ;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2194 run_time += segment_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2195 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2196 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2197 //goto L700;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2198 initial_CNS = gCNS_VPM;
877
a0900e4df15c DevBugfix: Exit condition deco_stop_depth
Ideenmodellierer
parents: 863
diff changeset
2199 decom_oxygen_calculate_cns_exposure(60*1,&pDiveSettings->decogaslist[mix_number],ambient_pressure/10,&gCNS_VPM);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2200 for (i = 0; i < 16; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2201 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2202 initial_helium_pressure[i] = helium_pressure[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2203 initial_nitrogen_pressure[i] = nitrogen_pressure[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2204 helium_pressure[i] += (inspired_helium_pressure - helium_pressure[i]) * float_buehlmann_He_factor_expositon_one_minute[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2205 nitrogen_pressure[i] += (inspired_nitrogen_pressure - nitrogen_pressure[i]) * float_buehlmann_N2_factor_expositon_one_minute[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2206 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2207 if(!buehlmann_wait)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2208 calc_deco_ceiling(&deco_ceiling_depth, false);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2209
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2210 if(buehlmannSafety && final_deco_calculation && !(deco_ceiling_depth > next_stop))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2211 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2212 for (i = 0; i < 16; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2213 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2214 tissue_He_saturation[i] = helium_pressure[i] / 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2215 tissue_N2_saturation[i] = nitrogen_pressure[i] / 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2216 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2217 if( (fabsf(nitrogen_pressure[15] - inspired_nitrogen_pressure) < 0.00001f) && (fabsf(helium_pressure[15] - inspired_helium_pressure) < 0.00001f)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2218 && (fabsf(nitrogen_pressure[0] - inspired_nitrogen_pressure) < 0.00001f) && (fabsf(helium_pressure[0] - inspired_helium_pressure) < 0.00001f))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2219 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2220 buehlmann_wait_exceeded = true;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2221 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2222 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2223
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2224 if(decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (next_stop / 10.0f) + pInput->pressure_surface_bar))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2225 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2226
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2227 buehlmann_wait = true;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2228 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2229 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2230 if(buehlmann_wait)
149
e1d66bc78f9a Eliminate warnings
Ideenmodellierer
parents: 51
diff changeset
2231 {
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2232 vpm_violates_buehlmann = true;
149
e1d66bc78f9a Eliminate warnings
Ideenmodellierer
parents: 51
diff changeset
2233 }
e1d66bc78f9a Eliminate warnings
Ideenmodellierer
parents: 51
diff changeset
2234 if(!buehlmann_wait)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2235 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2236 if(deco_ceiling_depth < next_stop)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2237 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2238 segment_time -= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2239 gCNS_VPM = initial_CNS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2240 for (i = 0; i < 16; i++) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2241 helium_pressure[i] = initial_helium_pressure[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2242 nitrogen_pressure[i] = initial_nitrogen_pressure[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2243 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2244 deco_ceiling_depth = next_stop +1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2245 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2246 while (deco_ceiling_depth > next_stop)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2247 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2248 //time_counter = temp_segment_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2249 segment_time += (float) 1.0f / 3.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2250 //goto L700;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2251 initial_CNS = gCNS_VPM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2252 decom_oxygen_calculate_cns_exposure(20,&pDiveSettings->decogaslist[mix_number],ambient_pressure/10,&gCNS_VPM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2253 for (i = 0; i < 16; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2254 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2255 helium_pressure[i] += (inspired_helium_pressure - helium_pressure[i]) * float_buehlmann_He_factor_expositon_20_seconds[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2256 nitrogen_pressure[i] += (inspired_nitrogen_pressure - nitrogen_pressure[i]) * float_buehlmann_N2_factor_expositon_20_seconds[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2257 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2258 calc_deco_ceiling(&deco_ceiling_depth, false);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2259 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2260 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2261 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2262
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2263 /*float pressure_save =dive_data.pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2264 dive_data.pressure = ambient_pressure/10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2265 tissues_exposure_stage(st_deco_test,(int)(segment_time * 60), &dive_data, &gaslist);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2266 dive_data.pressure = pressure_save;*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2267 run_time += segment_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2268 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2269 } /* decompression_stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2270
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2271 /* =============================================================================== */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2272 // SUROUTINE BOYLES_LAW_COMPENSATION
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2273 // Purpose: This subprogram calculates the reduction in allowable gradients
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2274 // with decreasing ambient pressure during the decompression profile based
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2275 // on Boyle's Law considerations.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2276 //===============================================================================
290
5e0bb91d4a12 VPM, cleanup: 1st round
Jan Mulder <jlmulder@xs4all.nl>
parents: 247
diff changeset
2277 static void BOYLES_LAW_COMPENSATION (float* First_Stop_Depth,
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2278 float* Deco_Stop_Depth,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2279 float* Step_Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2280 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2281 short i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2282
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2283 float Next_Stop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2284 float Ambient_Pressure_First_Stop, Ambient_Pressure_Next_Stop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2285 float Amb_Press_First_Stop_Pascals, Amb_Press_Next_Stop_Pascals;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2286 float A, B, C, Low_Bound, High_Bound, Ending_Radius;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2287 float Deco_Gradient_Pascals;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2288 float Allow_Grad_First_Stop_He_Pa, Radius_First_Stop_He;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2289 float Allow_Grad_First_Stop_N2_Pa, Radius_First_Stop_N2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2290
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2291 //===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2292 // LO//AL ARRAYS
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2293 //===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2294 // float Radius1_He[16], Radius2_He[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2295 // float Radius1_N2[16], Radius2_N2[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2296 float root_factor;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2297
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2298 //===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2299 // CALCULATIONS
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2300 //===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2301 Next_Stop = *Deco_Stop_Depth - *Step_Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2302
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2303 Ambient_Pressure_First_Stop = *First_Stop_Depth +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2304 barometric_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2305
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2306 Ambient_Pressure_Next_Stop = Next_Stop + barometric_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2307
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2308 Amb_Press_First_Stop_Pascals = (Ambient_Pressure_First_Stop/UNITS_FACTOR) * 101325.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2309
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2310 Amb_Press_Next_Stop_Pascals =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2311 (Ambient_Pressure_Next_Stop/UNITS_FACTOR) * 101325.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2312 root_factor = powf(Amb_Press_First_Stop_Pascals/Amb_Press_Next_Stop_Pascals,1.0f / 3.0f);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2313
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2314 for( i = 0; i < 16;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2315 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2316 Allow_Grad_First_Stop_He_Pa =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2317 (allowable_gradient_he[i]/UNITS_FACTOR) * 101325.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2318
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2319 Radius_First_Stop_He = (2.0f * SURFACE_TENSION_GAMMA) /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2320 Allow_Grad_First_Stop_He_Pa;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2321
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2322 // Radius1_He[i] = Radius_First_Stop_He;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2323 A = Amb_Press_Next_Stop_Pascals;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2324 B = -2.0f * SURFACE_TENSION_GAMMA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2325 C = (Amb_Press_First_Stop_Pascals + (2.0f * SURFACE_TENSION_GAMMA)/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2326 Radius_First_Stop_He)* Radius_First_Stop_He*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2327 (Radius_First_Stop_He*(Radius_First_Stop_He));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2328 Low_Bound = Radius_First_Stop_He;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2329 High_Bound = Radius_First_Stop_He * root_factor;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2330 //*pow(Amb_Press_First_Stop_Pascals/Amb_Press_Next_Stop_Pascals,1.0/3.0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2331 //*(Amb_Press_First_Stop_Pascals/Amb_Press_Next_Stop_Pascals)**(1.0/3.0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2332
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2333 radius_root_finder(&A,&B,&C, &Low_Bound, &High_Bound,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2334 &Ending_Radius);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2335
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2336 // Radius2_He[i] = Ending_Radius;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2337 Deco_Gradient_Pascals = (2.0f * SURFACE_TENSION_GAMMA) /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2338 Ending_Radius;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2339
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2340 deco_gradient_he[i] = (Deco_Gradient_Pascals / 101325.0f)*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2341 UNITS_FACTOR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2342
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2343 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2344
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2345 for( i = 0; i < 16;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2346 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2347 Allow_Grad_First_Stop_N2_Pa =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2348 (allowable_gradient_n2[i]/UNITS_FACTOR) * 101325.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2349
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2350 Radius_First_Stop_N2 = (2.0f * SURFACE_TENSION_GAMMA) /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2351 Allow_Grad_First_Stop_N2_Pa;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2352
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2353 // Radius1_N2[i] = Radius_First_Stop_N2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2354 A = Amb_Press_Next_Stop_Pascals;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2355 B = -2.0f * SURFACE_TENSION_GAMMA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2356 C = (Amb_Press_First_Stop_Pascals + (2.0f * SURFACE_TENSION_GAMMA)/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2357 Radius_First_Stop_N2)* Radius_First_Stop_N2*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2358 (Radius_First_Stop_N2*(Radius_First_Stop_N2));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2359 Low_Bound = Radius_First_Stop_N2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2360 High_Bound = Radius_First_Stop_N2* root_factor;//pow(Amb_Press_First_Stop_Pascals/Amb_Press_Next_Stop_Pascals,1.0/3.0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2361
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2362 //High_Bound = Radius_First_Stop_N2*exp(log(Amb_Press_First_Stop_Pascals/Amb_Press_Next_Stop_Pascals)/3);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2363 radius_root_finder(&A,&B,&C, &Low_Bound, &High_Bound,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2364 &Ending_Radius);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2365
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2366 // Radius2_N2[i] = Ending_Radius;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2367 Deco_Gradient_Pascals = (2.0f * SURFACE_TENSION_GAMMA) /
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2368 Ending_Radius;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2369
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2370 deco_gradient_n2[i] = (Deco_Gradient_Pascals / 101325.0f)*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2371 UNITS_FACTOR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2372 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2373 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2374
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2375 /* =============================================================================== */
292
bfcea6e2ab3f translate: nullzeit -> ndl
Jan Mulder <jlmulder@xs4all.nl>
parents: 291
diff changeset
2376 // vpm_calc_ndl
bfcea6e2ab3f translate: nullzeit -> ndl
Jan Mulder <jlmulder@xs4all.nl>
parents: 291
diff changeset
2377 // Purpose: This function computes NDL (time where no decostops are needed)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2378 //===============================================================================
291
24ff72e627f4 Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents: 290
diff changeset
2379 #define MAX_NDL 240
24ff72e627f4 Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents: 290
diff changeset
2380
292
bfcea6e2ab3f translate: nullzeit -> ndl
Jan Mulder <jlmulder@xs4all.nl>
parents: 291
diff changeset
2381 static int vpm_calc_ndl(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2382 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2383 static float future_helium_pressure[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2384 static float future_nitrogen_pressure[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2385 static int temp_segment_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2386 static int mix_number;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2387 static float inspired_helium_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2388 static float inspired_nitrogen_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2389
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2390 float previous_helium_pressure[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2391 float previous_nitrogen_pressure[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2392 float ambient_pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2393 float fraction_helium_begin;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2394 float fraction_nitrogen_begin;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2395 int i = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2396 int count = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2397 int status = CALC_END;
291
24ff72e627f4 Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents: 290
diff changeset
2398
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2399 for(i = 0; i < 16;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2400 {
863
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
2401 future_helium_pressure[i] = pInput->tissue_helium_bar[i] * 10.0;//tissue_He_saturation[st_dive][i] * 10;
0c89c6fa949c Bugfix empty line in deco plan (VPM only):
Ideenmodellierer
parents: 830
diff changeset
2402 future_nitrogen_pressure[i] = pInput->tissue_nitrogen_bar[i] * 10.0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2403 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2404 temp_segment_time = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2405
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2406 mix_number = 0;
877
a0900e4df15c DevBugfix: Exit condition deco_stop_depth
Ideenmodellierer
parents: 863
diff changeset
2407 ambient_pressure = pInput->pressure_ambient_bar * 10;
a0900e4df15c DevBugfix: Exit condition deco_stop_depth
Ideenmodellierer
parents: 863
diff changeset
2408 decom_get_inert_gases( ambient_pressure / 10, (&pDiveSettings->decogaslist[mix_number]) , &fraction_nitrogen_begin, &fraction_helium_begin );
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2409 inspired_helium_pressure =(ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_helium_begin;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2410 inspired_nitrogen_pressure =(ambient_pressure - WATER_VAPOR_PRESSURE) *fraction_nitrogen_begin;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2411
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2412 status = CALC_END;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2413 while (status == CALC_END)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2414 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2415 count++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2416 temp_segment_time += 60;
291
24ff72e627f4 Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents: 290
diff changeset
2417 if(temp_segment_time >= MAX_NDL)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2418 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2419 pDecoInfo->output_ndl_seconds = temp_segment_time * 60;
292
bfcea6e2ab3f translate: nullzeit -> ndl
Jan Mulder <jlmulder@xs4all.nl>
parents: 291
diff changeset
2420 return CALC_NDL;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2421 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2422 run_time += 60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2423 //goto L700;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2424 for (i = 1; i <= 16; ++i) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2425 previous_helium_pressure[i-1] = future_helium_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2426 previous_nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2427 future_helium_pressure[i - 1] = future_helium_pressure[i - 1] + (inspired_helium_pressure - future_helium_pressure[i - 1]) * float_buehlmann_He_factor_expositon_one_hour[i-1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2428 future_nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1] + (inspired_nitrogen_pressure - future_nitrogen_pressure[i - 1]) * float_buehlmann_N2_factor_expositon_one_hour[i-1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2429 helium_pressure[i - 1] = future_helium_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2430 nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2431 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2432 vpm_calc_deco();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2433 while((status = vpm_calc_critcal_volume(true,true)) == CALC_CRITICAL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2434
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2435 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2436
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2437 temp_segment_time -= 60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2438 run_time -= 60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2439 for (i = 1; i <= 16; ++i)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2440 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2441 future_helium_pressure[i - 1] = previous_helium_pressure[i-1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2442 future_nitrogen_pressure[i - 1] = previous_nitrogen_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2443 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2444
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2445 status = CALC_END;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2446 if(temp_segment_time < 60)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2447 nullzeit_unter60 = true;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2448
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2449 while (status == CALC_END)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2450 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2451 temp_segment_time += 5;
291
24ff72e627f4 Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents: 290
diff changeset
2452 if(temp_segment_time >= MAX_NDL)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2453 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2454 pDecoInfo->output_ndl_seconds = temp_segment_time * 60;
292
bfcea6e2ab3f translate: nullzeit -> ndl
Jan Mulder <jlmulder@xs4all.nl>
parents: 291
diff changeset
2455 return CALC_NDL;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2456 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2457 if(nullzeit_unter60 && temp_segment_time > 60)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2458 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2459 nullzeit_unter60 = false;
292
bfcea6e2ab3f translate: nullzeit -> ndl
Jan Mulder <jlmulder@xs4all.nl>
parents: 291
diff changeset
2460 return CALC_NDL;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2461 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2462 run_time += 5;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2463 //goto L700;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2464 for (i = 1; i <= 16; ++i) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2465 previous_helium_pressure[i-1] = future_helium_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2466 previous_nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2467 future_helium_pressure[i - 1] = future_helium_pressure[i - 1] + (inspired_helium_pressure - future_helium_pressure[i - 1]) * float_buehlmann_He_factor_expositon_five_minutes[i-1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2468 future_nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1] + (inspired_nitrogen_pressure - future_nitrogen_pressure[i - 1]) * float_buehlmann_N2_factor_expositon_five_minutes[i-1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2469 helium_pressure[i - 1] = future_helium_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2470 nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2471 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2472 vpm_calc_deco();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2473 while((status =vpm_calc_critcal_volume(true,true)) == CALC_CRITICAL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2474 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2475 temp_segment_time -= 5;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2476 run_time -= 5;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2477 for (i = 1; i <= 16; ++i) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2478 future_helium_pressure[i - 1] = previous_helium_pressure[i-1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2479 future_nitrogen_pressure[i - 1] = previous_nitrogen_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2480 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2481 status = CALC_END;
291
24ff72e627f4 Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents: 290
diff changeset
2482
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2483 if(temp_segment_time <= 20)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2484 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2485 while (status == CALC_END)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2486 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2487 temp_segment_time += minimum_deco_stop_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2488 run_time += minimum_deco_stop_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2489 //goto L700;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2490 for (i = 1; i <= 16; ++i) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2491 future_helium_pressure[i - 1] = future_helium_pressure[i - 1] + (inspired_helium_pressure - future_helium_pressure[i - 1]) * float_buehlmann_He_factor_expositon_one_minute[i-1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2492 future_nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1] + (inspired_nitrogen_pressure - future_nitrogen_pressure[i - 1]) * float_buehlmann_N2_factor_expositon_one_minute[i-1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2493 helium_pressure[i - 1] = future_helium_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2494 nitrogen_pressure[i - 1] =future_nitrogen_pressure[i - 1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2495
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2496 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2497 vpm_calc_deco();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2498 while((status =vpm_calc_critcal_volume(true,true)) == CALC_CRITICAL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2499
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2500 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2501 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2502 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2503 temp_segment_time += 5;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2504 pDecoInfo->output_ndl_seconds = temp_segment_time * 60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2505 if(temp_segment_time > 1)
292
bfcea6e2ab3f translate: nullzeit -> ndl
Jan Mulder <jlmulder@xs4all.nl>
parents: 291
diff changeset
2506 return CALC_NDL;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2507 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2508 return CALC_BEGIN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2509 }
902
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
2510
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
2511 void vpm_table_init()
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
2512 {
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
2513 vpmTable.output_time_to_surface_seconds = 0;
907
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
2514 vpmTableState = VPM_TABLE_INIT;
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
2515 }
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
2516 uint8_t vpm_get_decozone(void)
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
2517 {
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
2518 return((uint8_t)pVpm->depth_start_of_deco_zone_save);
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
2519 }
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
2520 SvpmTableState vpm_get_TableState(void)
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
2521 {
46a21ff3f5ab Adaptation custom view deco plan for VPM:
ideenmodellierer
parents: 902
diff changeset
2522 return vpmTableState;
902
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
2523 }
d4622533271d VPM table mode:
Ideenmodellierer
parents: 877
diff changeset
2524