2017-04-27 18:18:03 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2024-03-07 10:09:40 +00:00
|
|
|
/* planner.cpp
|
2013-01-05 07:11:42 +00:00
|
|
|
*
|
|
|
|
* code that allows us to plan future dives
|
|
|
|
*
|
|
|
|
* (c) Dirk Hohndel 2013
|
|
|
|
*/
|
2023-12-03 21:59:21 +00:00
|
|
|
#include <stdlib.h>
|
2013-12-07 22:54:14 +00:00
|
|
|
#include <assert.h>
|
2013-01-07 19:23:14 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <ctype.h>
|
2013-10-05 07:29:09 +00:00
|
|
|
#include <string.h>
|
2020-05-01 11:43:52 +00:00
|
|
|
#include "dive.h"
|
|
|
|
#include "divelist.h" // for init_decompression()
|
2024-06-18 20:23:57 +00:00
|
|
|
#include "divelog.h"
|
2020-10-25 12:28:55 +00:00
|
|
|
#include "sample.h"
|
2018-05-11 15:25:41 +00:00
|
|
|
#include "subsurface-string.h"
|
2016-03-23 16:53:44 +00:00
|
|
|
#include "deco.h"
|
2019-08-05 17:41:15 +00:00
|
|
|
#include "errorhelper.h"
|
2020-10-25 08:14:16 +00:00
|
|
|
#include "event.h"
|
2020-10-25 17:14:23 +00:00
|
|
|
#include "interpolate.h"
|
2013-04-08 03:20:25 +00:00
|
|
|
#include "planner.h"
|
2024-05-28 19:31:11 +00:00
|
|
|
#include "range.h"
|
2020-05-01 12:07:59 +00:00
|
|
|
#include "subsurface-time.h"
|
2013-10-06 15:55:58 +00:00
|
|
|
#include "gettext.h"
|
2014-04-30 05:37:19 +00:00
|
|
|
#include "libdivecomputer/parser.h"
|
2018-02-24 22:28:13 +00:00
|
|
|
#include "qthelper.h"
|
2017-03-31 06:14:36 +00:00
|
|
|
#include "version.h"
|
2013-01-05 07:11:42 +00:00
|
|
|
|
2024-11-20 21:21:59 +00:00
|
|
|
#define DEBUG_PLAN 255
|
|
|
|
|
2024-03-08 10:33:38 +00:00
|
|
|
static constexpr int base_timestep = 2; // seconds
|
2014-04-18 14:08:33 +00:00
|
|
|
|
2019-06-04 16:25:38 +00:00
|
|
|
static int decostoplevels_metric[] = { 0, 3000, 6000, 9000, 12000, 15000, 18000, 21000, 24000, 27000,
|
|
|
|
30000, 33000, 36000, 39000, 42000, 45000, 48000, 51000, 54000, 57000,
|
|
|
|
60000, 63000, 66000, 69000, 72000, 75000, 78000, 81000, 84000, 87000,
|
|
|
|
90000, 100000, 110000, 120000, 130000, 140000, 150000, 160000, 170000,
|
|
|
|
180000, 190000, 200000, 220000, 240000, 260000, 280000, 300000,
|
|
|
|
320000, 340000, 360000, 380000 };
|
|
|
|
static int decostoplevels_imperial[] = { 0, 3048, 6096, 9144, 12192, 15240, 18288, 21336, 24384, 27432,
|
|
|
|
30480, 33528, 36576, 39624, 42672, 45720, 48768, 51816, 54864, 57912,
|
|
|
|
60960, 64008, 67056, 70104, 73152, 76200, 79248, 82296, 85344, 88392,
|
|
|
|
91440, 101600, 111760, 121920, 132080, 142240, 152400, 162560, 172720,
|
|
|
|
182880, 193040, 203200, 223520, 243840, 264160, 284480, 304800,
|
|
|
|
325120, 345440, 365760, 386080 };
|
Planner deco stops are at 10ft increments when measured in feet
When using feet as depth unit, deco stop levels should be at 10 ft rather
than 3 m increments.
For shallow stops, rounding means the difference is not apparent. However,
with stops deeper than 30 feet, using 3 m increments leads stops at 39ft,
49ft, ..., 98ft, etc.
Apart from making plans look messy, the old behaviour makes it harder to
benchmark the planner against published profiles in imperial units.
This revised patch uses the help macro M_OR_FT(6, 20) to set the last stop
at the correct depth.
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-04 13:10:34 +00:00
|
|
|
|
2013-01-07 20:49:07 +00:00
|
|
|
#if DEBUG_PLAN
|
2024-05-04 16:45:55 +00:00
|
|
|
void dump_plan(struct diveplan *diveplan)
|
2013-01-07 20:49:07 +00:00
|
|
|
{
|
|
|
|
if (!diveplan) {
|
2014-02-28 04:09:57 +00:00
|
|
|
printf("Diveplan NULL\n");
|
2013-01-07 20:49:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-11-20 21:21:59 +00:00
|
|
|
struct tm tm;
|
2013-01-07 20:49:07 +00:00
|
|
|
utc_mkdate(diveplan->when, &tm);
|
|
|
|
|
2013-01-08 22:05:25 +00:00
|
|
|
printf("\nDiveplan @ %04d-%02d-%02d %02d:%02d:%02d (surfpres %dmbar):\n",
|
2016-04-28 22:13:30 +00:00
|
|
|
tm.tm_year, tm.tm_mon + 1, tm.tm_mday,
|
2014-02-28 04:09:57 +00:00
|
|
|
tm.tm_hour, tm.tm_min, tm.tm_sec,
|
2024-09-09 11:55:37 +00:00
|
|
|
diveplan->surface_pressure.mbar);
|
2024-11-20 21:21:59 +00:00
|
|
|
for (auto &dp: diveplan->dp) {
|
|
|
|
printf("\t%3u:%02u: %6dmm cylid: %2d setpoint: %d\n", FRACTION_TUPLE(dp.time, 60), dp.depth.mm, dp.cylinderid, dp.setpoint);
|
2013-01-07 20:49:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-09-04 05:36:05 +00:00
|
|
|
diveplan::diveplan()
|
2014-05-30 22:40:13 +00:00
|
|
|
{
|
2024-09-04 05:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
diveplan::~diveplan()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-09-07 12:25:48 +00:00
|
|
|
bool diveplan::is_empty() const
|
2024-09-04 05:36:05 +00:00
|
|
|
{
|
2024-09-07 12:25:48 +00:00
|
|
|
return std::none_of(dp.begin(), dp.end(), [](const divedatapoint &dp) { return dp.time != 0; });
|
2014-05-30 22:40:13 +00:00
|
|
|
}
|
|
|
|
|
2016-07-06 12:40:28 +00:00
|
|
|
/* get the cylinder index at a certain time during the dive */
|
2024-05-04 16:45:55 +00:00
|
|
|
int get_cylinderid_at_time(struct dive *dive, struct divecomputer *dc, duration_t time)
|
2016-07-06 12:40:28 +00:00
|
|
|
{
|
|
|
|
// we start with the first cylinder unless an event tells us otherwise
|
|
|
|
int cylinder_idx = 0;
|
2024-05-25 06:16:57 +00:00
|
|
|
for (const auto &event: dc->events) {
|
|
|
|
if (event.time.seconds > time.seconds)
|
|
|
|
break;
|
|
|
|
if (event.name == "gaschange")
|
2024-06-25 05:43:32 +00:00
|
|
|
cylinder_idx = dive->get_cylinder_index(event);
|
2016-07-06 12:40:28 +00:00
|
|
|
}
|
|
|
|
return cylinder_idx;
|
|
|
|
}
|
|
|
|
|
2022-11-01 11:12:19 +00:00
|
|
|
static int get_gasidx(struct dive *dive, struct gasmix mix)
|
2013-01-10 00:01:15 +00:00
|
|
|
{
|
2024-05-28 19:31:11 +00:00
|
|
|
return find_best_gasmix_match(mix, dive->cylinders);
|
2013-01-10 00:01:15 +00:00
|
|
|
}
|
|
|
|
|
2019-08-05 19:37:31 +00:00
|
|
|
static void interpolate_transition(struct deco_state *ds, struct dive *dive, duration_t t0, duration_t t1, depth_t d0, depth_t d1, struct gasmix gasmix, o2pressure_t po2, enum divemode_t divemode)
|
2014-04-17 08:54:55 +00:00
|
|
|
{
|
2017-12-17 17:12:08 +00:00
|
|
|
int32_t j;
|
2014-04-17 08:54:55 +00:00
|
|
|
|
2014-07-18 18:25:00 +00:00
|
|
|
for (j = t0.seconds; j < t1.seconds; j++) {
|
|
|
|
int depth = interpolate(d0.mm, d1.mm, j - t0.seconds, t1.seconds - t0.seconds);
|
2024-06-20 20:09:47 +00:00
|
|
|
add_segment(ds, dive->depth_to_bar(depth), gasmix, 1, po2.mbar, divemode, prefs.bottomsac, true);
|
2014-04-17 08:54:55 +00:00
|
|
|
}
|
2015-08-29 11:51:35 +00:00
|
|
|
if (d1.mm > d0.mm)
|
2024-06-20 20:09:47 +00:00
|
|
|
calc_crushing_pressure(ds, dive->depth_to_bar(d1.mm));
|
2014-04-17 08:54:55 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 07:11:42 +00:00
|
|
|
/* returns the tissue tolerance at the end of this (partial) dive */
|
2024-04-25 20:16:08 +00:00
|
|
|
static int tissue_at_end(struct deco_state *ds, struct dive *dive, const struct divecomputer *dc, deco_state_cache &cache)
|
2013-01-05 07:11:42 +00:00
|
|
|
{
|
2024-05-19 10:38:38 +00:00
|
|
|
depth_t lastdepth;
|
|
|
|
duration_t t0;
|
2017-10-02 09:17:10 +00:00
|
|
|
int surface_interval = 0;
|
2013-01-05 07:11:42 +00:00
|
|
|
|
|
|
|
if (!dive)
|
2017-01-03 14:14:42 +00:00
|
|
|
return 0;
|
2024-03-07 18:08:22 +00:00
|
|
|
if (cache) {
|
|
|
|
cache.restore(ds, true);
|
2013-01-06 19:13:46 +00:00
|
|
|
} else {
|
2024-06-18 20:23:57 +00:00
|
|
|
surface_interval = divelog.dives.init_decompression(ds, dive, true);
|
2024-03-07 18:08:22 +00:00
|
|
|
cache.cache(ds);
|
2013-01-06 19:13:46 +00:00
|
|
|
}
|
2024-05-19 10:38:38 +00:00
|
|
|
if (dc->samples.empty())
|
2017-01-03 14:14:42 +00:00
|
|
|
return 0;
|
2014-07-19 01:37:28 +00:00
|
|
|
|
2024-05-19 10:38:38 +00:00
|
|
|
const struct sample *psample = nullptr;
|
2024-05-27 15:09:48 +00:00
|
|
|
divemode_loop loop(*dc);
|
2024-05-19 10:38:38 +00:00
|
|
|
for (auto &sample: dc->samples) {
|
|
|
|
o2pressure_t setpoint = psample ? psample->setpoint
|
|
|
|
: sample.setpoint;
|
2015-09-14 09:22:32 +00:00
|
|
|
|
2024-05-19 10:38:38 +00:00
|
|
|
duration_t t1 = sample.time;
|
2024-06-25 05:43:32 +00:00
|
|
|
struct gasmix gas = dive->get_gasmix_at_time(*dc, t0);
|
2024-05-19 10:38:38 +00:00
|
|
|
if (psample)
|
2014-07-17 19:16:49 +00:00
|
|
|
lastdepth = psample->depth;
|
2015-09-12 02:10:54 +00:00
|
|
|
|
|
|
|
/* The ceiling in the deeper portion of a multilevel dive is sometimes critical for the VPM-B
|
|
|
|
* Boyle's law compensation. We should check the ceiling prior to ascending during the bottom
|
|
|
|
* portion of the dive. The maximum ceiling might be reached while ascending, but testing indicates
|
|
|
|
* that it is only marginally deeper than the ceiling at the start of ascent.
|
|
|
|
* Do not set the first_ceiling_pressure variable (used for the Boyle's law compensation calculation)
|
|
|
|
* at this stage, because it would interfere with calculating the ceiling at the end of the bottom
|
|
|
|
* portion of the dive.
|
|
|
|
* Remember the value for later.
|
|
|
|
*/
|
2024-05-19 10:38:38 +00:00
|
|
|
if ((decoMode(true) == VPMB) && (lastdepth.mm > sample.depth.mm)) {
|
2015-09-12 02:10:54 +00:00
|
|
|
pressure_t ceiling_pressure;
|
2017-11-22 19:42:33 +00:00
|
|
|
nuclear_regeneration(ds, t0.seconds);
|
|
|
|
vpmb_start_gradient(ds);
|
2024-06-20 20:09:47 +00:00
|
|
|
ceiling_pressure.mbar = dive->depth_to_mbar(deco_allowed_depth(tissue_tolerance_calc(ds, dive,
|
|
|
|
dive->depth_to_bar(lastdepth.mm), true),
|
2015-09-12 02:10:54 +00:00
|
|
|
dive->surface_pressure.mbar / 1000.0,
|
|
|
|
dive,
|
2024-06-20 20:09:47 +00:00
|
|
|
1));
|
2017-11-22 19:42:33 +00:00
|
|
|
if (ceiling_pressure.mbar > ds->max_bottom_ceiling_pressure.mbar)
|
|
|
|
ds->max_bottom_ceiling_pressure.mbar = ceiling_pressure.mbar;
|
2015-09-12 02:10:54 +00:00
|
|
|
}
|
|
|
|
|
2024-09-03 07:48:49 +00:00
|
|
|
divemode_t divemode = loop.at(t0.seconds + 1);
|
2024-05-19 10:38:38 +00:00
|
|
|
interpolate_transition(ds, dive, t0, t1, lastdepth, sample.depth, gas, setpoint, divemode);
|
|
|
|
psample = &sample;
|
2013-01-05 07:11:42 +00:00
|
|
|
t0 = t1;
|
|
|
|
}
|
2017-01-03 14:14:42 +00:00
|
|
|
return surface_interval;
|
2013-01-05 07:11:42 +00:00
|
|
|
}
|
|
|
|
|
2014-05-29 21:36:14 +00:00
|
|
|
/* calculate the new end pressure of the cylinder, based on its current end pressure and the
|
|
|
|
* latest segment. */
|
2018-05-08 14:24:51 +00:00
|
|
|
static void update_cylinder_pressure(struct dive *d, int old_depth, int new_depth, int duration, int sac, cylinder_t *cyl, bool in_deco, enum divemode_t divemode)
|
2014-05-29 21:36:14 +00:00
|
|
|
{
|
|
|
|
volume_t gas_used;
|
|
|
|
pressure_t delta_p;
|
|
|
|
depth_t mean_depth;
|
2015-01-15 22:22:12 +00:00
|
|
|
int factor = 1000;
|
|
|
|
|
2018-05-08 14:23:07 +00:00
|
|
|
if (divemode == PSCR)
|
2015-01-15 22:22:12 +00:00
|
|
|
factor = prefs.pscr_ratio;
|
2014-05-29 21:36:14 +00:00
|
|
|
|
2014-06-01 16:59:38 +00:00
|
|
|
if (!cyl)
|
2014-05-29 21:36:14 +00:00
|
|
|
return;
|
|
|
|
mean_depth.mm = (old_depth + new_depth) / 2;
|
2024-06-20 20:09:47 +00:00
|
|
|
gas_used.mliter = lrint(d->depth_to_atm(mean_depth.mm) * sac / 60 * duration * factor / 1000);
|
2024-09-02 18:42:05 +00:00
|
|
|
cyl->gas_used += gas_used;
|
2014-07-01 07:37:49 +00:00
|
|
|
if (in_deco)
|
2024-09-02 18:42:05 +00:00
|
|
|
cyl->deco_gas_used += gas_used;
|
2014-06-02 20:14:59 +00:00
|
|
|
if (cyl->type.size.mliter) {
|
2018-08-16 17:10:10 +00:00
|
|
|
delta_p.mbar = lrint(gas_used.mliter * 1000.0 / cyl->type.size.mliter * gas_compressibility_factor(cyl->gasmix, cyl->end.mbar / 1000.0));
|
2024-09-02 18:42:05 +00:00
|
|
|
cyl->end -= delta_p;
|
2014-06-01 16:59:38 +00:00
|
|
|
}
|
2013-01-05 07:11:42 +00:00
|
|
|
}
|
|
|
|
|
2019-08-06 09:25:15 +00:00
|
|
|
/* overwrite the data in dive
|
2014-07-03 20:39:06 +00:00
|
|
|
* return false if something goes wrong */
|
2024-09-04 05:36:05 +00:00
|
|
|
static void create_dive_from_plan(struct diveplan &diveplan, struct dive *dive, struct divecomputer *dc, bool track_gas)
|
2013-01-05 07:11:42 +00:00
|
|
|
{
|
2014-05-29 21:36:14 +00:00
|
|
|
cylinder_t *cyl;
|
2013-01-29 03:54:05 +00:00
|
|
|
int oldpo2 = 0;
|
Improve profile display in planner
This patch allows the planner to save the last manually-entered
dive planner point of a dive plan. When the plan has been saved
and re-opened for edit, the time of the last-entered dive planner
point is used to ensure that dive planning continues from the same
point in the profile as was when the original dive plan was saved.
Mechanism:
1) In dive.h, create a new dc attribute dc->last_manual_time
with data type of duration_t.
2) In diveplanner.c, ensure that the last manually-entered
dive planner point is saved in dc->last_manual_time.
3) In save-xml.c, create a new XML attribute for the <divecomputer>
element, named last-manual-time. For dive plans, the element would
now look like:
<divecomputer model='planned dive' last-manual-time='31:17 min'>
4) In parse-xml.c, insert code that recognises the last-manual-time
XML attribute, reads the time value and assigns this time to
dc->last_manual_time.
5) In diveplannermodel.cpp, method DiveplannerPointModel::loadfromdive,
insert code that sets the appropriate boolean value to dp->entered
by comparing newtime (i.e. time of dp) with dc->last_manual_time.
6) Diveplannermodel.cpp also accepts profile data from normal dives in
the dive log, whether hand-entered or loaded from dive computer. It
looks like the reduction of dive points for dives with >100 points
continues to work ok.
The result is that when a dive plan is saved with manually entered
points up to e.g. 10 minutes into the dive, it can be re-opened for edit
in the dive planner and the planner re-creates the plan with manually
entered points up to 10 minutes. The rest of the points are "soft"
points, shaped by the deco calculations of the planner.
Improvements: Improve code for profile display in dive planner
This responds to #1052.
Change load-git.c and save-git.c so that the last-manual-time is
also saved in the git-format dive log.
Several stylistic changes in text for consistent C source code.
Improvement of dive planner profile display:
Do some simplification of my alterations to diveplannermodel.cpp
Two small style changes in planner.c and diveplannermodel.cpp
as requested ny @neolit123
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-15 12:51:47 +00:00
|
|
|
int lasttime = 0, last_manual_point = 0;
|
2024-09-03 15:04:48 +00:00
|
|
|
depth_t lastdepth;
|
2017-10-08 03:21:31 +00:00
|
|
|
int lastcylid;
|
2024-04-25 20:16:08 +00:00
|
|
|
enum divemode_t type = dc->divemode;
|
2013-01-05 07:11:42 +00:00
|
|
|
|
2024-09-04 05:36:05 +00:00
|
|
|
if (diveplan.dp.empty())
|
2014-07-03 20:39:06 +00:00
|
|
|
return;
|
2013-01-08 16:52:48 +00:00
|
|
|
#if DEBUG_PLAN & 4
|
2013-01-10 00:01:15 +00:00
|
|
|
printf("in create_dive_from_plan\n");
|
2024-11-20 21:21:59 +00:00
|
|
|
dump_plan(&diveplan);
|
2013-01-08 16:52:48 +00:00
|
|
|
#endif
|
2024-09-04 05:36:05 +00:00
|
|
|
dive->salinity = diveplan.salinity;
|
2014-07-04 06:50:59 +00:00
|
|
|
// reset the cylinders and clear out the samples and events of the
|
2019-08-06 09:25:15 +00:00
|
|
|
// dive-to-be-planned so we can restart
|
2017-08-28 21:59:58 +00:00
|
|
|
reset_cylinders(dive, track_gas);
|
2024-09-04 05:36:05 +00:00
|
|
|
dc->when = dive->when = diveplan.when;
|
2024-09-09 11:55:37 +00:00
|
|
|
dc->surface_pressure = diveplan.surface_pressure;
|
2024-09-04 05:36:05 +00:00
|
|
|
dc->salinity = diveplan.salinity;
|
2024-05-19 10:38:38 +00:00
|
|
|
dc->samples.clear();
|
2024-05-25 06:16:57 +00:00
|
|
|
dc->events.clear();
|
2017-12-17 17:12:08 +00:00
|
|
|
/* Create first sample at time = 0, not based on dp because
|
2017-10-08 03:21:31 +00:00
|
|
|
* there is no real dp for time = 0, set first cylinder to 0
|
|
|
|
* O2 setpoint for this sample will be filled later from next dp */
|
2024-06-30 20:39:52 +00:00
|
|
|
cyl = dive->get_or_create_cylinder(0);
|
2024-05-19 10:38:38 +00:00
|
|
|
struct sample *sample = prepare_sample(dc);
|
2015-01-16 12:49:12 +00:00
|
|
|
sample->sac.mliter = prefs.bottomsac;
|
2014-07-17 06:04:30 +00:00
|
|
|
if (track_gas && cyl->type.workingpressure.mbar)
|
2017-07-20 21:39:02 +00:00
|
|
|
sample->pressure[0].mbar = cyl->end.mbar;
|
2014-08-20 02:07:43 +00:00
|
|
|
sample->manually_entered = true;
|
2017-10-08 03:21:31 +00:00
|
|
|
lastcylid = 0;
|
2024-09-04 05:36:05 +00:00
|
|
|
for (auto &dp: diveplan.dp) {
|
|
|
|
int po2 = dp.setpoint;
|
|
|
|
int time = dp.time;
|
|
|
|
depth_t depth = dp.depth;
|
2013-01-07 21:13:10 +00:00
|
|
|
|
2013-01-08 23:03:37 +00:00
|
|
|
if (time == 0) {
|
|
|
|
/* special entries that just inform the algorithm about
|
|
|
|
* additional gases that are available */
|
|
|
|
continue;
|
|
|
|
}
|
2013-01-07 21:13:10 +00:00
|
|
|
|
2013-02-02 17:40:29 +00:00
|
|
|
/* Check for SetPoint change */
|
2013-02-02 17:03:26 +00:00
|
|
|
if (oldpo2 != po2) {
|
2015-03-08 19:28:45 +00:00
|
|
|
/* this is a bad idea - we should get a different SAMPLE_EVENT type
|
|
|
|
* reserved for this in libdivecomputer... overloading SMAPLE_EVENT_PO2
|
|
|
|
* with a different meaning will only cause confusion elsewhere in the code */
|
2024-09-04 05:36:05 +00:00
|
|
|
if (dp.divemode == type)
|
2018-05-17 20:01:12 +00:00
|
|
|
add_event(dc, lasttime, SAMPLE_EVENT_PO2, 0, po2, QT_TRANSLATE_NOOP("gettextFromC", "SP change"));
|
2013-02-02 17:03:26 +00:00
|
|
|
oldpo2 = po2;
|
|
|
|
}
|
|
|
|
|
2014-06-01 23:27:19 +00:00
|
|
|
/* Make sure we have the new gas, and create a gas change event */
|
2024-09-04 05:36:05 +00:00
|
|
|
if (dp.cylinderid != lastcylid) {
|
2014-06-01 17:02:38 +00:00
|
|
|
/* need to insert a first sample for the new gas */
|
2024-09-04 05:36:05 +00:00
|
|
|
add_gas_switch_event(dive, dc, lasttime + 1, dp.cylinderid);
|
|
|
|
cyl = dive->get_cylinder(dp.cylinderid); // FIXME: This actually may get one past the last cylinder for "surface air".
|
2020-04-27 19:12:24 +00:00
|
|
|
if (!cyl) {
|
2024-09-04 05:36:05 +00:00
|
|
|
report_error("Invalid cylinder in create_dive_from_plan(): %d", dp.cylinderid);
|
2020-04-27 19:12:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-05-29 21:36:14 +00:00
|
|
|
sample = prepare_sample(dc);
|
2014-10-19 14:07:07 +00:00
|
|
|
sample[-1].setpoint.mbar = po2;
|
2021-08-18 21:38:15 +00:00
|
|
|
if (po2)
|
|
|
|
sample[-1].o2sensor[0].mbar = po2;
|
2014-06-01 17:02:38 +00:00
|
|
|
sample->time.seconds = lasttime + 1;
|
2017-03-10 12:37:54 +00:00
|
|
|
sample->depth = lastdepth;
|
2024-09-04 05:36:05 +00:00
|
|
|
sample->manually_entered = dp.entered;
|
|
|
|
sample->sac.mliter = dp.entered ? prefs.bottomsac : prefs.decosac;
|
|
|
|
lastcylid = dp.cylinderid;
|
2013-01-05 07:11:42 +00:00
|
|
|
}
|
2024-09-04 05:36:05 +00:00
|
|
|
if (dp.divemode != type) {
|
|
|
|
type = dp.divemode;
|
2020-03-02 20:32:12 +00:00
|
|
|
add_event(dc, lasttime, SAMPLE_EVENT_BOOKMARK, 0, type, "modechange");
|
2018-03-28 20:50:28 +00:00
|
|
|
}
|
|
|
|
|
2013-01-07 21:13:10 +00:00
|
|
|
/* Create sample */
|
2013-01-05 07:11:42 +00:00
|
|
|
sample = prepare_sample(dc);
|
2013-01-29 03:54:05 +00:00
|
|
|
/* set po2 at beginning of this segment */
|
|
|
|
/* and keep it valid for last sample - where it likely doesn't matter */
|
2014-11-25 13:27:09 +00:00
|
|
|
sample[-1].setpoint.mbar = po2;
|
2014-12-12 13:51:25 +00:00
|
|
|
sample->setpoint.mbar = po2;
|
2014-06-01 17:02:38 +00:00
|
|
|
sample->time.seconds = lasttime = time;
|
2024-09-04 05:36:05 +00:00
|
|
|
if (dp.entered) last_manual_point = dp.time;
|
2017-03-10 12:37:54 +00:00
|
|
|
sample->depth = lastdepth = depth;
|
2024-09-04 05:36:05 +00:00
|
|
|
sample->manually_entered = dp.entered;
|
|
|
|
sample->sac.mliter = dp.entered ? prefs.bottomsac : prefs.decosac;
|
2014-11-25 13:27:09 +00:00
|
|
|
if (track_gas && !sample[-1].setpoint.mbar) { /* Don't track gas usage for CCR legs of dive */
|
2017-08-28 21:59:58 +00:00
|
|
|
update_cylinder_pressure(dive, sample[-1].depth.mm, depth.mm, time - sample[-1].time.seconds,
|
2024-09-04 05:36:05 +00:00
|
|
|
dp.entered ? diveplan.bottomsac : diveplan.decosac, cyl, !dp.entered, type);
|
2014-07-17 06:04:30 +00:00
|
|
|
if (cyl->type.workingpressure.mbar)
|
2017-07-20 21:39:02 +00:00
|
|
|
sample->pressure[0].mbar = cyl->end.mbar;
|
2014-07-04 18:26:31 +00:00
|
|
|
}
|
2013-01-05 07:11:42 +00:00
|
|
|
}
|
2024-04-25 20:16:08 +00:00
|
|
|
dc->last_manual_time.seconds = last_manual_point;
|
Improve profile display in planner
This patch allows the planner to save the last manually-entered
dive planner point of a dive plan. When the plan has been saved
and re-opened for edit, the time of the last-entered dive planner
point is used to ensure that dive planning continues from the same
point in the profile as was when the original dive plan was saved.
Mechanism:
1) In dive.h, create a new dc attribute dc->last_manual_time
with data type of duration_t.
2) In diveplanner.c, ensure that the last manually-entered
dive planner point is saved in dc->last_manual_time.
3) In save-xml.c, create a new XML attribute for the <divecomputer>
element, named last-manual-time. For dive plans, the element would
now look like:
<divecomputer model='planned dive' last-manual-time='31:17 min'>
4) In parse-xml.c, insert code that recognises the last-manual-time
XML attribute, reads the time value and assigns this time to
dc->last_manual_time.
5) In diveplannermodel.cpp, method DiveplannerPointModel::loadfromdive,
insert code that sets the appropriate boolean value to dp->entered
by comparing newtime (i.e. time of dp) with dc->last_manual_time.
6) Diveplannermodel.cpp also accepts profile data from normal dives in
the dive log, whether hand-entered or loaded from dive computer. It
looks like the reduction of dive points for dives with >100 points
continues to work ok.
The result is that when a dive plan is saved with manually entered
points up to e.g. 10 minutes into the dive, it can be re-opened for edit
in the dive planner and the planner re-creates the plan with manually
entered points up to 10 minutes. The rest of the points are "soft"
points, shaped by the deco calculations of the planner.
Improvements: Improve code for profile display in dive planner
This responds to #1052.
Change load-git.c and save-git.c so that the last-manual-time is
also saved in the git-format dive log.
Several stylistic changes in text for consistent C source code.
Improvement of dive planner profile display:
Do some simplification of my alterations to diveplannermodel.cpp
Two small style changes in planner.c and diveplannermodel.cpp
as requested ny @neolit123
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-15 12:51:47 +00:00
|
|
|
|
2013-01-10 00:01:15 +00:00
|
|
|
#if DEBUG_PLAN & 32
|
2024-11-20 21:21:59 +00:00
|
|
|
save_dive(stdout, *dive, false);
|
2013-01-10 00:01:15 +00:00
|
|
|
#endif
|
2014-07-03 20:39:06 +00:00
|
|
|
return;
|
2013-01-05 07:11:42 +00:00
|
|
|
}
|
|
|
|
|
2024-09-07 12:25:48 +00:00
|
|
|
divedatapoint::divedatapoint(int time_incr, int depth, int cylinderid, int po2, bool entered) :
|
|
|
|
time(time_incr),
|
|
|
|
depth{ .mm = depth },
|
|
|
|
cylinderid(cylinderid),
|
2024-09-09 11:55:37 +00:00
|
|
|
minimum_gas(0_bar),
|
2024-09-07 12:25:48 +00:00
|
|
|
setpoint(po2),
|
|
|
|
entered(entered),
|
|
|
|
divemode(OC)
|
2013-01-05 07:11:42 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-09-04 05:36:05 +00:00
|
|
|
static void add_to_end_of_diveplan(struct diveplan &diveplan, const struct divedatapoint &dp)
|
2013-01-05 07:11:42 +00:00
|
|
|
{
|
2024-09-04 05:36:05 +00:00
|
|
|
auto maxtime = std::max_element(diveplan.dp.begin(), diveplan.dp.end(),
|
|
|
|
[] (const divedatapoint &p1, const divedatapoint &p2)
|
|
|
|
{ return p1.time < p2.time; });
|
|
|
|
int lasttime = maxtime != diveplan.dp.end() ? maxtime->time : 0;
|
|
|
|
diveplan.dp.push_back(dp);
|
|
|
|
diveplan.dp.back().time += lasttime;
|
2013-01-05 07:11:42 +00:00
|
|
|
}
|
|
|
|
|
2024-09-04 05:36:05 +00:00
|
|
|
void plan_add_segment(struct diveplan &diveplan, int duration, int depth, int cylinderid, int po2, bool entered, enum divemode_t divemode)
|
2013-01-05 07:11:42 +00:00
|
|
|
{
|
2024-09-07 12:25:48 +00:00
|
|
|
struct divedatapoint dp(duration, depth, cylinderid, divemode == CCR ? po2 : 0, entered);
|
2024-09-04 05:36:05 +00:00
|
|
|
dp.divemode = divemode;
|
2013-01-05 07:11:42 +00:00
|
|
|
add_to_end_of_diveplan(diveplan, dp);
|
|
|
|
}
|
|
|
|
|
2013-01-10 00:01:15 +00:00
|
|
|
struct gaschanges {
|
2016-03-23 15:16:33 +00:00
|
|
|
int depth;
|
2013-01-10 00:01:15 +00:00
|
|
|
int gasidx;
|
|
|
|
};
|
|
|
|
|
2021-02-21 16:43:26 +00:00
|
|
|
// Return new setpoint if cylinderi is a setpoint change an 0 if not
|
|
|
|
|
|
|
|
static int setpoint_change(struct dive *dive, int cylinderid)
|
|
|
|
{
|
2024-06-25 05:43:32 +00:00
|
|
|
cylinder_t *cylinder = dive->get_cylinder(cylinderid);
|
2024-05-28 19:31:11 +00:00
|
|
|
if (cylinder->type.description.empty())
|
2021-02-21 16:43:26 +00:00
|
|
|
return 0;
|
2024-05-28 19:31:11 +00:00
|
|
|
if (starts_with(cylinder->type.description, "SP ")) {
|
2021-02-21 16:43:26 +00:00
|
|
|
float sp;
|
2024-05-28 19:31:11 +00:00
|
|
|
sscanf(cylinder->type.description.c_str() + 3, "%f", &sp);
|
|
|
|
return (int) (sp * 1000.0);
|
2021-02-21 16:43:26 +00:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 05:36:05 +00:00
|
|
|
static std::vector<gaschanges> analyze_gaslist(const struct diveplan &diveplan, struct dive *dive, int dcNr,
|
|
|
|
int depth, int *asc_cylinder, bool ccr, bool &inappropriate_cylinder_use)
|
2013-01-08 16:52:48 +00:00
|
|
|
{
|
2024-03-07 20:03:27 +00:00
|
|
|
size_t nr = 0;
|
|
|
|
std::vector<gaschanges> gaschanges;
|
2024-09-04 05:36:05 +00:00
|
|
|
const struct divedatapoint *best_ascent_dp = nullptr;
|
2017-02-09 17:12:44 +00:00
|
|
|
bool total_time_zero = true;
|
2024-05-15 05:23:39 +00:00
|
|
|
const divecomputer *dc = dive->get_dc(dcNr);
|
2024-09-04 05:36:05 +00:00
|
|
|
for (auto &dp: diveplan.dp) {
|
|
|
|
inappropriate_cylinder_use = inappropriate_cylinder_use || !is_cylinder_use_appropriate(*dc, *dive->get_cylinder(dp.cylinderid), false);
|
2024-05-15 05:23:39 +00:00
|
|
|
|
2024-09-04 05:36:05 +00:00
|
|
|
if (dp.time == 0 && total_time_zero && (ccr == (bool) setpoint_change(dive, dp.cylinderid))) {
|
|
|
|
if (dp.depth.mm <= depth) {
|
2014-05-30 15:09:05 +00:00
|
|
|
int i = 0;
|
|
|
|
nr++;
|
2024-03-07 20:03:27 +00:00
|
|
|
gaschanges.resize(nr);
|
|
|
|
while (i < static_cast<int>(nr) - 1) {
|
2024-09-04 05:36:05 +00:00
|
|
|
if (dp.depth.mm < gaschanges[i].depth) {
|
2024-03-07 20:03:27 +00:00
|
|
|
for (int j = static_cast<int>(nr) - 2; j >= i; j--)
|
|
|
|
gaschanges[j + 1] = gaschanges[j];
|
2014-05-30 15:09:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
2013-01-10 00:01:15 +00:00
|
|
|
}
|
2024-09-04 05:36:05 +00:00
|
|
|
gaschanges[i].depth = dp.depth.mm;
|
|
|
|
gaschanges[i].gasidx = dp.cylinderid;
|
2014-05-30 15:09:05 +00:00
|
|
|
assert(gaschanges[i].gasidx != -1);
|
|
|
|
} else {
|
|
|
|
/* is there a better mix to start deco? */
|
2024-09-04 05:36:05 +00:00
|
|
|
if (!best_ascent_dp || dp.depth.mm < best_ascent_dp->depth.mm) {
|
|
|
|
best_ascent_dp = &dp;
|
2013-01-10 00:01:15 +00:00
|
|
|
}
|
2014-05-30 15:09:05 +00:00
|
|
|
}
|
2017-02-09 17:12:44 +00:00
|
|
|
} else {
|
|
|
|
total_time_zero = false;
|
2013-01-08 16:52:48 +00:00
|
|
|
}
|
2013-01-10 00:01:15 +00:00
|
|
|
}
|
2024-09-04 05:36:05 +00:00
|
|
|
if (best_ascent_dp)
|
2023-02-16 02:53:17 +00:00
|
|
|
*asc_cylinder = best_ascent_dp->cylinderid;
|
2013-01-10 00:01:15 +00:00
|
|
|
#if DEBUG_PLAN & 16
|
2024-03-07 20:03:27 +00:00
|
|
|
for (size_t nr = 0; nr < gaschanges.size(); nr++) {
|
2014-06-02 01:25:44 +00:00
|
|
|
int idx = gaschanges[nr].gasidx;
|
2024-11-20 21:21:59 +00:00
|
|
|
printf("gaschange nr %zu: @ %5.2lfm gasidx %d (%s)\n", nr, gaschanges[nr].depth / 1000.0,
|
|
|
|
idx, dive->get_cylinder(idx)->gasmix.name().c_str());
|
2014-06-02 01:25:44 +00:00
|
|
|
}
|
2013-01-10 00:01:15 +00:00
|
|
|
#endif
|
|
|
|
return gaschanges;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sort all the stops into one ordered list */
|
2024-03-07 20:03:27 +00:00
|
|
|
static std::vector<int> sort_stops(int dstops[], size_t dnr, std::vector<gaschanges> gstops)
|
2013-01-10 00:01:15 +00:00
|
|
|
{
|
2024-03-07 20:03:27 +00:00
|
|
|
int total = dnr + gstops.size();
|
|
|
|
std::vector<int> stoplevels(total);
|
|
|
|
|
|
|
|
/* Can't happen. */
|
|
|
|
if (dnr == 0)
|
|
|
|
return std::vector<int>();
|
2013-01-10 00:01:15 +00:00
|
|
|
|
|
|
|
/* no gaschanges */
|
2024-03-07 20:03:27 +00:00
|
|
|
if (gstops.empty()) {
|
|
|
|
std::copy(dstops, dstops + dnr, stoplevels.begin());
|
2013-01-10 00:01:15 +00:00
|
|
|
return stoplevels;
|
|
|
|
}
|
2024-03-07 20:03:27 +00:00
|
|
|
int i = static_cast<int>(total) - 1;
|
|
|
|
int gi = static_cast<int>(gstops.size()) - 1;
|
|
|
|
int di = static_cast<int>(dnr) - 1;
|
2013-01-10 00:01:15 +00:00
|
|
|
while (i >= 0) {
|
|
|
|
if (dstops[di] > gstops[gi].depth) {
|
|
|
|
stoplevels[i] = dstops[di];
|
|
|
|
di--;
|
|
|
|
} else if (dstops[di] == gstops[gi].depth) {
|
|
|
|
stoplevels[i] = dstops[di];
|
|
|
|
di--;
|
|
|
|
gi--;
|
|
|
|
} else {
|
|
|
|
stoplevels[i] = gstops[gi].depth;
|
|
|
|
gi--;
|
|
|
|
}
|
|
|
|
i--;
|
|
|
|
if (di < 0) {
|
|
|
|
while (gi >= 0)
|
|
|
|
stoplevels[i--] = gstops[gi--].depth;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (gi < 0) {
|
|
|
|
while (di >= 0)
|
|
|
|
stoplevels[i--] = dstops[di--];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (i >= 0)
|
|
|
|
stoplevels[i--] = 0;
|
|
|
|
|
|
|
|
#if DEBUG_PLAN & 16
|
|
|
|
int k;
|
2024-03-07 20:03:27 +00:00
|
|
|
for (k = static_cast<int>(gstops.size()) + dnr - 1; k >= 0; k--) {
|
2014-02-28 04:09:57 +00:00
|
|
|
printf("stoplevel[%d]: %5.2lfm\n", k, stoplevels[k] / 1000.0);
|
2013-01-10 00:01:15 +00:00
|
|
|
if (stoplevels[k] == 0)
|
|
|
|
break;
|
2013-01-08 16:52:48 +00:00
|
|
|
}
|
2013-01-10 00:01:15 +00:00
|
|
|
#endif
|
|
|
|
return stoplevels;
|
2013-01-08 16:52:48 +00:00
|
|
|
}
|
|
|
|
|
2024-05-04 16:45:55 +00:00
|
|
|
int ascent_velocity(int depth, int avg_depth, int)
|
2014-04-17 08:54:55 +00:00
|
|
|
{
|
|
|
|
/* We need to make this configurable */
|
2014-04-26 15:29:40 +00:00
|
|
|
|
|
|
|
/* As an example (and possibly reasonable default) this is the Tech 1 provedure according
|
|
|
|
* to http://www.globalunderwaterexplorers.org/files/Standards_and_Procedures/SOP_Manual_Ver2.0.2.pdf */
|
|
|
|
|
2014-06-24 22:08:36 +00:00
|
|
|
if (depth * 4 > avg_depth * 3) {
|
|
|
|
return prefs.ascrate75;
|
|
|
|
} else {
|
|
|
|
if (depth * 2 > avg_depth) {
|
|
|
|
return prefs.ascrate50;
|
|
|
|
} else {
|
|
|
|
if (depth > 6000)
|
|
|
|
return prefs.ascratestops;
|
|
|
|
else
|
|
|
|
return prefs.ascratelast6m;
|
|
|
|
}
|
|
|
|
}
|
2014-04-17 08:54:55 +00:00
|
|
|
}
|
|
|
|
|
2019-08-06 09:33:01 +00:00
|
|
|
static void track_ascent_gas(int depth, struct dive *dive, int cylinder_id, int avg_depth, int bottom_time, bool safety_stop, enum divemode_t divemode)
|
2015-04-04 16:38:56 +00:00
|
|
|
{
|
2024-06-25 05:43:32 +00:00
|
|
|
cylinder_t *cylinder = dive->get_cylinder(cylinder_id);
|
2015-04-04 16:38:56 +00:00
|
|
|
while (depth > 0) {
|
2024-03-08 10:33:38 +00:00
|
|
|
int deltad = ascent_velocity(depth, avg_depth, bottom_time) * base_timestep;
|
2015-04-04 16:38:56 +00:00
|
|
|
if (deltad > depth)
|
|
|
|
deltad = depth;
|
2024-03-08 10:33:38 +00:00
|
|
|
update_cylinder_pressure(dive, depth, depth - deltad, base_timestep, prefs.decosac, cylinder, true, divemode);
|
2015-05-21 17:55:28 +00:00
|
|
|
if (depth <= 5000 && depth >= (5000 - deltad) && safety_stop) {
|
2019-08-06 09:33:01 +00:00
|
|
|
update_cylinder_pressure(dive, 5000, 5000, 180, prefs.decosac, cylinder, true, divemode);
|
2015-04-08 17:18:54 +00:00
|
|
|
safety_stop = false;
|
|
|
|
}
|
2015-04-04 16:38:56 +00:00
|
|
|
depth -= deltad;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-27 12:06:02 +00:00
|
|
|
// Determine whether ascending to the next stop will break the ceiling. Return true if the ascent is ok, false if it isn't.
|
2019-08-05 19:37:31 +00:00
|
|
|
static bool trial_ascent(struct deco_state *ds, int wait_time, int trial_depth, int stoplevel, int avg_depth, int bottom_time, struct gasmix gasmix, int po2, double surface_pressure, struct dive *dive, enum divemode_t divemode)
|
2015-03-31 12:52:37 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
bool clear_to_ascend = true;
|
2024-03-07 18:08:22 +00:00
|
|
|
deco_state_cache trial_cache;
|
2015-03-31 12:52:37 +00:00
|
|
|
|
2015-08-29 14:07:22 +00:00
|
|
|
// For consistency with other VPM-B implementations, we should not start the ascent while the ceiling is
|
|
|
|
// deeper than the next stop (thus the offgasing during the ascent is ignored).
|
|
|
|
// However, we still need to make sure we don't break the ceiling due to on-gassing during ascent.
|
2024-03-07 18:08:22 +00:00
|
|
|
trial_cache.cache(ds);
|
2017-08-24 21:45:33 +00:00
|
|
|
if (wait_time)
|
2024-06-20 20:09:47 +00:00
|
|
|
add_segment(ds, dive->depth_to_bar(trial_depth),
|
2017-08-24 21:45:33 +00:00
|
|
|
gasmix,
|
2021-02-12 16:39:46 +00:00
|
|
|
wait_time, po2, divemode, prefs.decosac, true);
|
2021-02-12 17:19:24 +00:00
|
|
|
if (decoMode(true) == VPMB) {
|
2024-06-20 20:09:47 +00:00
|
|
|
double tolerance_limit = tissue_tolerance_calc(ds, dive, dive->depth_to_bar(stoplevel), true);
|
2019-08-05 21:23:10 +00:00
|
|
|
update_regression(ds, dive);
|
|
|
|
if (deco_allowed_depth(tolerance_limit, surface_pressure, dive, 1) > stoplevel) {
|
2024-03-07 18:08:22 +00:00
|
|
|
trial_cache.restore(ds, false);
|
2019-08-05 21:23:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-05-25 22:45:53 +00:00
|
|
|
}
|
2015-08-18 07:07:50 +00:00
|
|
|
|
2015-03-31 12:52:37 +00:00
|
|
|
while (trial_depth > stoplevel) {
|
2019-08-05 21:23:10 +00:00
|
|
|
double tolerance_limit;
|
2024-03-08 10:33:38 +00:00
|
|
|
int deltad = ascent_velocity(trial_depth, avg_depth, bottom_time) * base_timestep;
|
2015-03-31 12:52:37 +00:00
|
|
|
if (deltad > trial_depth) /* don't test against depth above surface */
|
|
|
|
deltad = trial_depth;
|
2024-06-20 20:09:47 +00:00
|
|
|
add_segment(ds, dive->depth_to_bar(trial_depth),
|
2015-08-31 21:25:28 +00:00
|
|
|
gasmix,
|
2024-03-08 10:33:38 +00:00
|
|
|
base_timestep, po2, divemode, prefs.decosac, true);
|
2024-06-20 20:09:47 +00:00
|
|
|
tolerance_limit = tissue_tolerance_calc(ds, dive, dive->depth_to_bar(trial_depth), true);
|
2021-02-12 17:19:24 +00:00
|
|
|
if (decoMode(true) == VPMB)
|
2019-08-05 21:23:10 +00:00
|
|
|
update_regression(ds, dive);
|
|
|
|
if (deco_allowed_depth(tolerance_limit, surface_pressure, dive, 1) > trial_depth - deltad) {
|
2015-03-31 12:52:37 +00:00
|
|
|
/* We should have stopped */
|
|
|
|
clear_to_ascend = false;
|
2015-07-03 21:24:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-03-31 12:52:37 +00:00
|
|
|
trial_depth -= deltad;
|
|
|
|
}
|
2024-03-07 18:08:22 +00:00
|
|
|
trial_cache.restore(ds, false);
|
2015-03-31 12:52:37 +00:00
|
|
|
return clear_to_ascend;
|
|
|
|
}
|
|
|
|
|
2015-07-27 12:06:02 +00:00
|
|
|
/* Determine if there is enough gas for the dive. Return true if there is enough.
|
|
|
|
* Also return true if this cannot be calculated because the cylinder doesn't have
|
|
|
|
* size or a starting pressure.
|
|
|
|
*/
|
2019-08-06 09:35:56 +00:00
|
|
|
static bool enough_gas(const struct dive *dive, int current_cylinder)
|
2015-04-04 16:38:56 +00:00
|
|
|
{
|
2024-05-28 19:31:11 +00:00
|
|
|
if (current_cylinder < 0 || static_cast<size_t>(current_cylinder) >= dive->cylinders.size())
|
2019-08-04 16:44:57 +00:00
|
|
|
return false;
|
2024-06-25 05:43:32 +00:00
|
|
|
const cylinder_t *cyl = dive->get_cylinder(current_cylinder);
|
2015-04-04 16:38:56 +00:00
|
|
|
|
|
|
|
if (!cyl->start.mbar)
|
|
|
|
return true;
|
|
|
|
if (cyl->type.size.mliter)
|
Unify float calulations: use double
Internal floating point (FP) calculations should be performed using double
unless there is a very good reason. This avoids headaches with conversions.
Indeed, the vast majority of FP calculations were already done using double.
This patch adapts most remaining calculations. Not converted where things
that were based on binary representations and variables which weren't used
anyway.
An analysis of all instances follows:
core/plannernotes.c, l.404:
This was a comparison between two floats. On the left side, first an integer
was cast to float then multiplied with and integer and divided by a constant
double. The right hand side was an integer cast to a float. Simply divide by
1000.0 first to convert to double and continue with calculations. On the right
hand side, remove the cast, because the integer will be implicitely cast to
double for comparison. This conversion actually emits less instructions,
because no conversion to double and back is performed.
core/planner.c, l.613:
Same analysis as previous case.
subsurface-desktop-main.cpp, l.155:
A local variable representing the version OpenGL version. Turn this into
integer logic. Not only does this avoid dreaded FP rounding issues, it also
works correctly for minor version > 10 (not that such a thing is to be
expected anytime soon).
abstractpreferenceswidget.[h/cpp]:
A widget where the position is described as a float. Turn into double.
desktop-widgets/divelogexportdialog.cpp, l.313:
total_weight is described as float. Use double arithmetics instead. This
instance fixes a truncation warning emitted by gcc.
2017-11-20 20:39:50 +00:00
|
|
|
return (cyl->end.mbar - prefs.reserve_gas) / 1000.0 * cyl->type.size.mliter > cyl->deco_gas_used.mliter;
|
2015-04-04 16:38:56 +00:00
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-24 21:45:33 +00:00
|
|
|
/* Do a binary search for the time the ceiling is clear to ascent to target_depth.
|
|
|
|
* Minimal solution is min + 1, and the solution should be an integer multiple of stepsize.
|
|
|
|
* leap is a guess for the maximum but there is no guarantee that leap is an upper limit.
|
|
|
|
* So we always test at the upper bundary, not in the middle!
|
|
|
|
*/
|
2019-08-05 19:37:31 +00:00
|
|
|
static int wait_until(struct deco_state *ds, struct dive *dive, int clock, int min, int leap, int stepsize, int depth, int target_depth, int avg_depth, int bottom_time, struct gasmix gasmix, int po2, double surface_pressure, enum divemode_t divemode)
|
2017-08-24 21:45:33 +00:00
|
|
|
{
|
2017-11-27 20:56:22 +00:00
|
|
|
// When a deco stop exceeds two days, there is something wrong...
|
|
|
|
if (min >= 48 * 3600)
|
|
|
|
return 50 * 3600;
|
2017-08-24 21:45:33 +00:00
|
|
|
// Round min + leap up to the next multiple of stepsize
|
|
|
|
int upper = min + leap + stepsize - 1 - (min + leap - 1) % stepsize;
|
|
|
|
// Is the upper boundary too small?
|
2018-04-09 06:49:56 +00:00
|
|
|
if (!trial_ascent(ds, upper - clock, depth, target_depth, avg_depth, bottom_time, gasmix, po2, surface_pressure, dive, divemode))
|
|
|
|
return wait_until(ds, dive, clock, upper, leap, stepsize, depth, target_depth, avg_depth, bottom_time, gasmix, po2, surface_pressure, divemode);
|
2017-08-24 21:45:33 +00:00
|
|
|
|
|
|
|
if (upper - min <= stepsize)
|
|
|
|
return upper;
|
|
|
|
|
2018-04-09 06:49:56 +00:00
|
|
|
return wait_until(ds, dive, clock, min, leap / 2, stepsize, depth, target_depth, avg_depth, bottom_time, gasmix, po2, surface_pressure, divemode);
|
2017-08-24 21:45:33 +00:00
|
|
|
}
|
|
|
|
|
2024-09-04 05:36:05 +00:00
|
|
|
static void average_max_depth(const struct diveplan &dive, int *avg_depth, int *max_depth)
|
2019-08-05 18:43:06 +00:00
|
|
|
{
|
|
|
|
int integral = 0;
|
|
|
|
int last_time = 0;
|
|
|
|
int last_depth = 0;
|
|
|
|
|
|
|
|
*max_depth = 0;
|
|
|
|
|
2024-09-04 05:36:05 +00:00
|
|
|
for (auto &dp: dive.dp) {
|
|
|
|
if (dp.time) {
|
2019-08-05 18:43:06 +00:00
|
|
|
/* Ignore gas indication samples */
|
2024-09-04 05:36:05 +00:00
|
|
|
integral += (dp.depth.mm + last_depth) * (dp.time - last_time) / 2;
|
|
|
|
last_time = dp.time;
|
|
|
|
last_depth = dp.depth.mm;
|
|
|
|
if (dp.depth.mm > *max_depth)
|
|
|
|
*max_depth = dp.depth.mm;
|
2019-08-05 18:43:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (last_time)
|
|
|
|
*avg_depth = integral / last_time;
|
|
|
|
else
|
|
|
|
*avg_depth = *max_depth = 0;
|
|
|
|
}
|
|
|
|
|
2024-09-07 13:32:06 +00:00
|
|
|
std::vector<decostop> plan(struct deco_state *ds, struct diveplan &diveplan, struct dive *dive, int dcNr, int timestep, deco_state_cache &cache, bool is_planner, bool show_disclaimer)
|
2013-01-05 07:11:42 +00:00
|
|
|
{
|
2017-11-22 19:42:33 +00:00
|
|
|
|
2015-07-03 22:13:34 +00:00
|
|
|
int bottom_depth;
|
|
|
|
int bottom_gi;
|
|
|
|
int bottom_stopidx;
|
|
|
|
bool is_final_plan = true;
|
2017-11-02 20:32:28 +00:00
|
|
|
int bottom_time;
|
2015-07-03 22:13:34 +00:00
|
|
|
int previous_deco_time;
|
2024-03-07 18:08:22 +00:00
|
|
|
deco_state_cache bottom_cache;
|
2014-06-02 00:45:00 +00:00
|
|
|
int po2;
|
2013-10-08 05:37:32 +00:00
|
|
|
int transitiontime, gi;
|
2017-11-02 13:15:46 +00:00
|
|
|
int current_cylinder, stop_cylinder;
|
2024-03-07 20:03:27 +00:00
|
|
|
size_t stopidx;
|
2014-04-18 20:06:21 +00:00
|
|
|
int depth;
|
2016-03-23 15:16:33 +00:00
|
|
|
int *decostoplevels;
|
2024-03-07 20:03:27 +00:00
|
|
|
size_t decostoplevelcount;
|
|
|
|
std::vector<int> stoplevels;
|
2014-04-17 08:54:55 +00:00
|
|
|
bool stopping = false;
|
2015-06-22 12:43:20 +00:00
|
|
|
bool pendinggaschange = false;
|
2014-04-17 08:54:55 +00:00
|
|
|
int clock, previous_point_time;
|
2017-10-26 23:06:11 +00:00
|
|
|
int avg_depth, max_depth;
|
2016-03-23 15:16:33 +00:00
|
|
|
int last_ascend_rate;
|
2023-02-16 02:53:17 +00:00
|
|
|
int best_first_ascend_cylinder = -1;
|
2015-07-03 22:13:34 +00:00
|
|
|
struct gasmix gas, bottom_gas;
|
2017-11-02 13:15:46 +00:00
|
|
|
bool o2break_next = false;
|
2017-10-10 07:46:34 +00:00
|
|
|
int break_cylinder = -1, breakfrom_cylinder = 0;
|
2017-11-08 19:59:47 +00:00
|
|
|
bool last_segment_min_switch = false;
|
2024-05-15 05:23:39 +00:00
|
|
|
planner_error_t error = PLAN_OK;
|
2016-11-23 10:50:50 +00:00
|
|
|
int first_stop_depth = 0;
|
2017-08-24 21:45:33 +00:00
|
|
|
int laststoptime = timestep;
|
2017-08-24 22:08:14 +00:00
|
|
|
bool o2breaking = false;
|
2024-06-30 18:38:12 +00:00
|
|
|
struct divecomputer *dc = dive->get_dc(dcNr);
|
2024-04-25 20:16:08 +00:00
|
|
|
enum divemode_t divemode = dc->divemode;
|
2013-01-05 07:11:42 +00:00
|
|
|
|
2024-09-04 05:36:05 +00:00
|
|
|
set_gf(diveplan.gflow, diveplan.gfhigh);
|
|
|
|
set_vpmb_conservatism(diveplan.vpmb_conservatism);
|
2023-06-02 05:16:14 +00:00
|
|
|
|
2024-09-09 11:55:37 +00:00
|
|
|
if (diveplan.surface_pressure.mbar == 0) {
|
2023-06-02 05:16:14 +00:00
|
|
|
// Lets use dive's surface pressure in planner, if have one...
|
2024-09-09 11:55:37 +00:00
|
|
|
if (dc->surface_pressure.mbar != 0) { // First from DC...
|
|
|
|
diveplan.surface_pressure = dc->surface_pressure;
|
|
|
|
} else if (dive->surface_pressure.mbar != 0) { // After from user...
|
|
|
|
diveplan.surface_pressure = dive->surface_pressure;
|
|
|
|
} else {
|
|
|
|
diveplan.surface_pressure = 1_atm;
|
2023-06-02 05:16:14 +00:00
|
|
|
}
|
|
|
|
}
|
2024-04-25 20:16:08 +00:00
|
|
|
|
2021-02-12 16:52:31 +00:00
|
|
|
clear_deco(ds, dive->surface_pressure.mbar / 1000.0, true);
|
2024-09-03 15:04:48 +00:00
|
|
|
ds->max_bottom_ceiling_pressure = ds->first_ceiling_pressure = 0_bar;
|
2024-04-25 20:16:08 +00:00
|
|
|
create_dive_from_plan(diveplan, dive, dc, is_planner);
|
2013-01-05 07:11:42 +00:00
|
|
|
|
2015-07-27 12:06:02 +00:00
|
|
|
// Do we want deco stop array in metres or feet?
|
2024-03-07 10:09:40 +00:00
|
|
|
if (prefs.units.length == units::METERS ) {
|
2015-07-26 03:34:43 +00:00
|
|
|
decostoplevels = decostoplevels_metric;
|
2024-03-07 20:03:27 +00:00
|
|
|
decostoplevelcount = std::size(decostoplevels_metric);
|
2015-07-04 12:14:10 +00:00
|
|
|
} else {
|
2015-07-26 03:34:43 +00:00
|
|
|
decostoplevels = decostoplevels_imperial;
|
2024-03-07 20:03:27 +00:00
|
|
|
decostoplevelcount = std::size(decostoplevels_imperial);
|
2015-07-04 12:14:10 +00:00
|
|
|
}
|
2015-04-05 12:17:26 +00:00
|
|
|
|
2015-07-27 12:06:02 +00:00
|
|
|
/* If the user has selected last stop to be at 6m/20', we need to get rid of the 3m/10' stop.
|
|
|
|
* Otherwise reinstate the last stop 3m/10' stop.
|
2024-03-07 20:03:27 +00:00
|
|
|
* Remark: not reentrant, but the user probably won't change preferences while this is running.
|
2015-07-27 12:06:02 +00:00
|
|
|
*/
|
Planner deco stops are at 10ft increments when measured in feet
When using feet as depth unit, deco stop levels should be at 10 ft rather
than 3 m increments.
For shallow stops, rounding means the difference is not apparent. However,
with stops deeper than 30 feet, using 3 m increments leads stops at 39ft,
49ft, ..., 98ft, etc.
Apart from making plans look messy, the old behaviour makes it harder to
benchmark the planner against published profiles in imperial units.
This revised patch uses the help macro M_OR_FT(6, 20) to set the last stop
at the correct depth.
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-04 13:10:34 +00:00
|
|
|
if (prefs.last_stop)
|
2015-07-26 03:34:43 +00:00
|
|
|
*(decostoplevels + 1) = 0;
|
|
|
|
else
|
|
|
|
*(decostoplevels + 1) = M_OR_FT(3,10);
|
Planner deco stops are at 10ft increments when measured in feet
When using feet as depth unit, deco stop levels should be at 10 ft rather
than 3 m increments.
For shallow stops, rounding means the difference is not apparent. However,
with stops deeper than 30 feet, using 3 m increments leads stops at 39ft,
49ft, ..., 98ft, etc.
Apart from making plans look messy, the old behaviour makes it harder to
benchmark the planner against published profiles in imperial units.
This revised patch uses the help macro M_OR_FT(6, 20) to set the last stop
at the correct depth.
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-04 13:10:34 +00:00
|
|
|
|
2014-04-18 14:08:33 +00:00
|
|
|
/* Let's start at the last 'sample', i.e. the last manually entered waypoint. */
|
2024-05-19 10:38:38 +00:00
|
|
|
const struct sample &sample = dc->samples.back();
|
2014-07-17 19:16:50 +00:00
|
|
|
|
2017-11-02 06:59:20 +00:00
|
|
|
/* Keep time during the ascend */
|
2024-05-19 10:38:38 +00:00
|
|
|
bottom_time = clock = previous_point_time = sample.time.seconds;
|
2017-11-02 06:59:20 +00:00
|
|
|
|
2024-05-19 10:38:38 +00:00
|
|
|
current_cylinder = get_cylinderid_at_time(dive, dc, sample.time);
|
2019-03-18 19:57:05 +00:00
|
|
|
// Find the divemode at the end of the dive
|
2024-05-25 06:16:57 +00:00
|
|
|
divemode_loop loop(*dc);
|
2024-09-03 07:48:49 +00:00
|
|
|
divemode = loop.at(bottom_time);
|
2024-06-25 05:43:32 +00:00
|
|
|
gas = dive->get_cylinder(current_cylinder)->gasmix;
|
2014-07-17 19:16:50 +00:00
|
|
|
|
2024-05-19 10:38:38 +00:00
|
|
|
po2 = sample.setpoint.mbar;
|
|
|
|
depth = sample.depth.mm;
|
2015-04-02 08:49:24 +00:00
|
|
|
average_max_depth(diveplan, &avg_depth, &max_depth);
|
2017-11-02 20:32:28 +00:00
|
|
|
last_ascend_rate = ascent_velocity(depth, avg_depth, bottom_time);
|
2013-09-19 03:40:34 +00:00
|
|
|
|
2013-12-10 06:50:19 +00:00
|
|
|
/* if all we wanted was the dive just get us back to the surface */
|
2014-07-04 18:26:31 +00:00
|
|
|
if (!is_planner) {
|
2018-05-05 14:34:50 +00:00
|
|
|
/* Attn: for manually entered dives, we depend on the last segment having the
|
|
|
|
* same ascent rate as in fake_dc(). If you change it here, also change it there.
|
|
|
|
*/
|
|
|
|
transitiontime = lrint(depth / (double)prefs.ascratelast6m);
|
2018-03-28 20:50:28 +00:00
|
|
|
plan_add_segment(diveplan, transitiontime, 0, current_cylinder, po2, false, divemode);
|
2024-04-25 20:16:08 +00:00
|
|
|
create_dive_from_plan(diveplan, dive, dc, is_planner);
|
2024-09-07 13:32:06 +00:00
|
|
|
return {};
|
2013-09-19 03:40:34 +00:00
|
|
|
}
|
2014-04-17 08:54:55 +00:00
|
|
|
|
2013-01-08 22:05:25 +00:00
|
|
|
#if DEBUG_PLAN & 4
|
2024-07-02 10:38:36 +00:00
|
|
|
printf("gas %s\n", gas.name().c_str());
|
2014-07-04 04:02:39 +00:00
|
|
|
printf("depth %5.2lfm \n", depth / 1000.0);
|
2016-07-06 12:40:28 +00:00
|
|
|
printf("current_cylinder %i\n", current_cylinder);
|
2013-01-08 16:52:48 +00:00
|
|
|
#endif
|
2014-04-17 08:54:55 +00:00
|
|
|
|
2014-04-18 14:08:33 +00:00
|
|
|
/* Find the gases available for deco */
|
2014-11-21 10:10:19 +00:00
|
|
|
|
2024-05-15 05:23:39 +00:00
|
|
|
bool inappropriate_cylinder_use = false;
|
|
|
|
std::vector<gaschanges> gaschanges = analyze_gaslist(diveplan, dive, dcNr, depth, &best_first_ascend_cylinder, divemode == CCR && !prefs.dobailout, inappropriate_cylinder_use);
|
|
|
|
if (inappropriate_cylinder_use) {
|
|
|
|
error = PLAN_ERROR_INAPPROPRIATE_GAS;
|
|
|
|
}
|
2021-02-21 16:43:26 +00:00
|
|
|
|
2014-04-18 14:08:33 +00:00
|
|
|
/* Find the first potential decostopdepth above current depth */
|
2015-07-26 03:34:43 +00:00
|
|
|
for (stopidx = 0; stopidx < decostoplevelcount; stopidx++)
|
2021-05-07 08:05:43 +00:00
|
|
|
if (decostoplevels[stopidx] > depth)
|
2013-01-05 07:11:42 +00:00
|
|
|
break;
|
2013-11-08 12:40:59 +00:00
|
|
|
if (stopidx > 0)
|
|
|
|
stopidx--;
|
2014-04-18 14:08:33 +00:00
|
|
|
/* Stoplevels are either depths of gas changes or potential deco stop depths. */
|
2024-03-07 20:03:27 +00:00
|
|
|
stoplevels = sort_stops(decostoplevels, stopidx + 1, gaschanges);
|
|
|
|
stopidx += gaschanges.size();
|
2013-01-10 00:01:15 +00:00
|
|
|
|
2024-03-07 20:03:27 +00:00
|
|
|
gi = static_cast<int>(gaschanges.size()) - 1;
|
2015-07-03 21:07:58 +00:00
|
|
|
|
2015-08-29 11:54:22 +00:00
|
|
|
/* Set tissue tolerance and initial vpmb gradient at start of ascent phase */
|
2024-09-04 05:36:05 +00:00
|
|
|
diveplan.surface_interval = tissue_at_end(ds, dive, dc, cache);
|
2017-11-22 19:42:33 +00:00
|
|
|
nuclear_regeneration(ds, clock);
|
|
|
|
vpmb_start_gradient(ds);
|
2021-02-12 17:19:24 +00:00
|
|
|
if (decoMode(true) == RECREATIONAL) {
|
2015-04-02 08:49:24 +00:00
|
|
|
bool safety_stop = prefs.safetystop && max_depth >= 10000;
|
2019-08-06 09:33:01 +00:00
|
|
|
track_ascent_gas(depth, dive, current_cylinder, avg_depth, bottom_time, safety_stop, divemode);
|
2015-03-31 12:52:37 +00:00
|
|
|
// How long can we stay at the current depth and still directly ascent to the surface?
|
2015-10-12 20:03:50 +00:00
|
|
|
do {
|
2024-06-20 20:09:47 +00:00
|
|
|
add_segment(ds, dive->depth_to_bar(depth),
|
2024-06-25 05:43:32 +00:00
|
|
|
dive->get_cylinder(current_cylinder)->gasmix,
|
2021-02-12 16:39:46 +00:00
|
|
|
timestep, po2, divemode, prefs.bottomsac, true);
|
2024-06-25 05:43:32 +00:00
|
|
|
update_cylinder_pressure(dive, depth, depth, timestep, prefs.bottomsac, dive->get_cylinder(current_cylinder), false, divemode);
|
2017-08-23 20:43:33 +00:00
|
|
|
clock += timestep;
|
2024-06-25 05:43:32 +00:00
|
|
|
} while (trial_ascent(ds, 0, depth, 0, avg_depth, bottom_time, dive->get_cylinder(current_cylinder)->gasmix,
|
2024-09-09 11:55:37 +00:00
|
|
|
po2, diveplan.surface_pressure.mbar / 1000.0, dive, divemode) &&
|
2019-08-06 09:35:56 +00:00
|
|
|
enough_gas(dive, current_cylinder) && clock < 6 * 3600);
|
2015-10-12 20:03:50 +00:00
|
|
|
|
2024-03-08 10:18:17 +00:00
|
|
|
// We did stay one timestep too many.
|
2015-10-12 20:03:50 +00:00
|
|
|
// In the best of all worlds, we would roll back also the last add_segment in terms of caching deco state, but
|
|
|
|
// let's ignore that since for the eventual ascent in recreational mode, nobody looks at the ceiling anymore,
|
|
|
|
// so we don't really have to compute the deco state.
|
2024-06-25 05:43:32 +00:00
|
|
|
update_cylinder_pressure(dive, depth, depth, -timestep, prefs.bottomsac, dive->get_cylinder(current_cylinder), false, divemode);
|
2017-08-23 20:43:33 +00:00
|
|
|
clock -= timestep;
|
2018-03-28 20:50:28 +00:00
|
|
|
plan_add_segment(diveplan, clock - previous_point_time, depth, current_cylinder, po2, true, divemode);
|
2015-03-31 12:52:37 +00:00
|
|
|
previous_point_time = clock;
|
|
|
|
do {
|
|
|
|
/* Ascend to surface */
|
2024-03-08 10:33:38 +00:00
|
|
|
int deltad = ascent_velocity(depth, avg_depth, bottom_time) * base_timestep;
|
2017-11-02 20:32:28 +00:00
|
|
|
if (ascent_velocity(depth, avg_depth, bottom_time) != last_ascend_rate) {
|
2018-03-28 20:50:28 +00:00
|
|
|
plan_add_segment(diveplan, clock - previous_point_time, depth, current_cylinder, po2, false, divemode);
|
2015-03-31 12:52:37 +00:00
|
|
|
previous_point_time = clock;
|
2017-11-02 20:32:28 +00:00
|
|
|
last_ascend_rate = ascent_velocity(depth, avg_depth, bottom_time);
|
2015-03-31 12:52:37 +00:00
|
|
|
}
|
2016-03-23 15:16:33 +00:00
|
|
|
if (depth - deltad < 0)
|
2015-03-31 12:52:37 +00:00
|
|
|
deltad = depth;
|
|
|
|
|
2024-03-08 10:33:38 +00:00
|
|
|
clock += base_timestep;
|
2015-03-31 12:52:37 +00:00
|
|
|
depth -= deltad;
|
2016-03-23 15:16:33 +00:00
|
|
|
if (depth <= 5000 && depth >= (5000 - deltad) && safety_stop) {
|
2018-03-28 20:50:28 +00:00
|
|
|
plan_add_segment(diveplan, clock - previous_point_time, 5000, current_cylinder, po2, false, divemode);
|
2015-04-02 09:17:57 +00:00
|
|
|
previous_point_time = clock;
|
|
|
|
clock += 180;
|
2018-03-28 20:50:28 +00:00
|
|
|
plan_add_segment(diveplan, clock - previous_point_time, 5000, current_cylinder, po2, false, divemode);
|
2015-04-02 09:17:57 +00:00
|
|
|
previous_point_time = clock;
|
|
|
|
safety_stop = false;
|
|
|
|
}
|
2015-03-31 12:52:37 +00:00
|
|
|
} while (depth > 0);
|
2018-03-28 20:50:28 +00:00
|
|
|
plan_add_segment(diveplan, clock - previous_point_time, 0, current_cylinder, po2, false, divemode);
|
2024-04-25 20:16:08 +00:00
|
|
|
create_dive_from_plan(diveplan, dive, dc, is_planner);
|
2024-09-07 12:25:48 +00:00
|
|
|
diveplan.add_plan_to_notes(*dive, show_disclaimer, error);
|
2024-05-27 15:09:48 +00:00
|
|
|
fixup_dc_duration(*dc);
|
2015-03-31 12:52:37 +00:00
|
|
|
|
2024-09-07 13:32:06 +00:00
|
|
|
return {};
|
2015-03-31 12:52:37 +00:00
|
|
|
}
|
2014-04-17 08:54:55 +00:00
|
|
|
|
2023-02-16 02:53:17 +00:00
|
|
|
if (best_first_ascend_cylinder != -1 && best_first_ascend_cylinder != current_cylinder) {
|
2014-05-30 15:09:05 +00:00
|
|
|
current_cylinder = best_first_ascend_cylinder;
|
2024-06-25 05:43:32 +00:00
|
|
|
gas = dive->get_cylinder(current_cylinder)->gasmix;
|
2014-10-19 14:07:07 +00:00
|
|
|
|
2014-05-30 15:09:05 +00:00
|
|
|
#if DEBUG_PLAN & 16
|
|
|
|
printf("switch to gas %d (%d/%d) @ %5.2lfm\n", best_first_ascend_cylinder,
|
2024-11-20 21:21:59 +00:00
|
|
|
(get_o2(gas) + 5) / 10, (get_he(gas) + 5) / 10, gaschanges[best_first_ascend_cylinder].depth / 1000.0);
|
2014-05-30 15:09:05 +00:00
|
|
|
#endif
|
|
|
|
}
|
2015-07-03 21:54:57 +00:00
|
|
|
|
|
|
|
// VPM-B or Buehlmann Deco
|
2024-04-25 20:16:08 +00:00
|
|
|
tissue_at_end(ds, dive, dc, cache);
|
2019-06-26 20:30:34 +00:00
|
|
|
if ((divemode == CCR || divemode == PSCR) && prefs.dobailout) {
|
|
|
|
divemode = OC;
|
|
|
|
po2 = 0;
|
2024-03-23 08:16:59 +00:00
|
|
|
int bailoutsegment = std::max(prefs.min_switch_duration, 60 * prefs.problemsolvingtime);
|
2024-06-20 20:09:47 +00:00
|
|
|
add_segment(ds, dive->depth_to_bar(depth),
|
2024-06-25 05:43:32 +00:00
|
|
|
dive->get_cylinder(current_cylinder)->gasmix,
|
2021-02-12 16:39:46 +00:00
|
|
|
bailoutsegment, po2, divemode, prefs.bottomsac, true);
|
2020-06-02 09:52:25 +00:00
|
|
|
plan_add_segment(diveplan, bailoutsegment, depth, current_cylinder, po2, false, divemode);
|
2020-09-21 08:51:19 +00:00
|
|
|
bottom_time += bailoutsegment;
|
2019-06-26 20:30:34 +00:00
|
|
|
}
|
2015-07-03 22:13:34 +00:00
|
|
|
previous_deco_time = 100000000;
|
2017-11-22 19:42:33 +00:00
|
|
|
ds->deco_time = 10000000;
|
2024-03-07 18:08:22 +00:00
|
|
|
bottom_cache.cache(ds); // Lets us make several iterations
|
2015-07-03 22:13:34 +00:00
|
|
|
bottom_depth = depth;
|
|
|
|
bottom_gi = gi;
|
|
|
|
bottom_gas = gas;
|
|
|
|
bottom_stopidx = stopidx;
|
2015-08-22 04:41:53 +00:00
|
|
|
|
2015-07-03 22:13:34 +00:00
|
|
|
//CVA
|
2024-09-07 13:32:06 +00:00
|
|
|
std::vector<decostop> decostoptable;
|
2015-07-03 22:13:34 +00:00
|
|
|
do {
|
2024-09-07 12:56:34 +00:00
|
|
|
decostoptable.clear();
|
2021-02-12 17:19:24 +00:00
|
|
|
is_final_plan = (decoMode(true) == BUEHLMANN) || (previous_deco_time - ds->deco_time < 10); // CVA time converges
|
2017-11-22 19:42:33 +00:00
|
|
|
if (ds->deco_time != 10000000)
|
2024-09-09 11:55:37 +00:00
|
|
|
vpmb_next_gradient(ds, ds->deco_time, diveplan.surface_pressure.mbar / 1000.0, true);
|
2015-08-15 12:16:48 +00:00
|
|
|
|
2017-11-22 19:42:33 +00:00
|
|
|
previous_deco_time = ds->deco_time;
|
2024-03-07 18:08:22 +00:00
|
|
|
bottom_cache.restore(ds, true);
|
2015-07-03 22:13:34 +00:00
|
|
|
|
|
|
|
depth = bottom_depth;
|
|
|
|
gi = bottom_gi;
|
2017-11-02 20:32:28 +00:00
|
|
|
clock = previous_point_time = bottom_time;
|
2015-07-03 22:13:34 +00:00
|
|
|
gas = bottom_gas;
|
|
|
|
stopping = false;
|
2024-09-07 13:32:06 +00:00
|
|
|
bool decodive = false;
|
2016-11-23 10:50:50 +00:00
|
|
|
first_stop_depth = 0;
|
2015-07-03 22:13:34 +00:00
|
|
|
stopidx = bottom_stopidx;
|
2024-06-20 20:09:47 +00:00
|
|
|
ds->first_ceiling_pressure.mbar = dive->depth_to_mbar(
|
|
|
|
deco_allowed_depth(tissue_tolerance_calc(ds, dive, dive->depth_to_bar(depth), true),
|
2024-09-09 11:55:37 +00:00
|
|
|
diveplan.surface_pressure.mbar / 1000.0, dive, 1));
|
2017-11-22 19:42:33 +00:00
|
|
|
if (ds->max_bottom_ceiling_pressure.mbar > ds->first_ceiling_pressure.mbar)
|
|
|
|
ds->first_ceiling_pressure.mbar = ds->max_bottom_ceiling_pressure.mbar;
|
2015-08-27 12:13:12 +00:00
|
|
|
|
2017-11-02 20:32:28 +00:00
|
|
|
last_ascend_rate = ascent_velocity(depth, avg_depth, bottom_time);
|
2017-10-09 21:38:38 +00:00
|
|
|
/* Always prefer the best_first_ascend_cylinder if it has the right gasmix.
|
|
|
|
* Otherwise take first cylinder from list with rightgasmix */
|
2024-06-25 05:43:32 +00:00
|
|
|
if (best_first_ascend_cylinder != -1 && same_gasmix(gas, dive->get_cylinder(best_first_ascend_cylinder)->gasmix))
|
2017-10-09 21:38:38 +00:00
|
|
|
current_cylinder = best_first_ascend_cylinder;
|
|
|
|
else
|
2018-08-16 17:10:10 +00:00
|
|
|
current_cylinder = get_gasidx(dive, gas);
|
2017-10-09 21:38:38 +00:00
|
|
|
if (current_cylinder == -1) {
|
2024-07-02 10:38:36 +00:00
|
|
|
report_error(translate("gettextFromC", "Can't find gas %s"), gas.name().c_str());
|
2015-07-03 22:13:34 +00:00
|
|
|
current_cylinder = 0;
|
|
|
|
}
|
2019-08-05 21:23:10 +00:00
|
|
|
reset_regression(ds);
|
2024-05-15 05:23:39 +00:00
|
|
|
while (error == PLAN_OK) {
|
2015-07-03 22:13:34 +00:00
|
|
|
/* We will break out when we hit the surface */
|
|
|
|
do {
|
|
|
|
/* Ascend to next stop depth */
|
2024-03-08 10:33:38 +00:00
|
|
|
int deltad = ascent_velocity(depth, avg_depth, bottom_time) * base_timestep;
|
2017-11-02 20:32:28 +00:00
|
|
|
if (ascent_velocity(depth, avg_depth, bottom_time) != last_ascend_rate) {
|
2015-07-03 22:13:34 +00:00
|
|
|
if (is_final_plan)
|
2018-03-28 20:50:28 +00:00
|
|
|
plan_add_segment(diveplan, clock - previous_point_time, depth, current_cylinder, po2, false, divemode);
|
2015-07-03 22:13:34 +00:00
|
|
|
previous_point_time = clock;
|
|
|
|
stopping = false;
|
2017-11-02 20:32:28 +00:00
|
|
|
last_ascend_rate = ascent_velocity(depth, avg_depth, bottom_time);
|
2015-07-03 22:13:34 +00:00
|
|
|
}
|
2016-03-23 15:16:33 +00:00
|
|
|
if (depth - deltad < stoplevels[stopidx])
|
2015-07-03 22:13:34 +00:00
|
|
|
deltad = depth - stoplevels[stopidx];
|
|
|
|
|
2024-06-20 20:09:47 +00:00
|
|
|
add_segment(ds, dive->depth_to_bar(depth),
|
2024-06-25 05:43:32 +00:00
|
|
|
dive->get_cylinder(current_cylinder)->gasmix,
|
2024-03-08 10:33:38 +00:00
|
|
|
base_timestep, po2, divemode, prefs.decosac, true);
|
2017-11-08 19:59:47 +00:00
|
|
|
last_segment_min_switch = false;
|
2024-03-08 10:33:38 +00:00
|
|
|
clock += base_timestep;
|
2015-07-03 22:13:34 +00:00
|
|
|
depth -= deltad;
|
2024-03-07 10:09:40 +00:00
|
|
|
/* Print VPM-Gradient as gradient factor, this has to be done from within deco.cpp */
|
2016-11-23 10:50:50 +00:00
|
|
|
if (decodive)
|
2019-08-05 21:23:10 +00:00
|
|
|
ds->plot_depth = depth;
|
2016-03-23 15:16:33 +00:00
|
|
|
} while (depth > 0 && depth > stoplevels[stopidx]);
|
2015-07-03 22:13:34 +00:00
|
|
|
|
|
|
|
if (depth <= 0)
|
|
|
|
break; /* We are at the surface */
|
|
|
|
|
|
|
|
if (gi >= 0 && stoplevels[stopidx] <= gaschanges[gi].depth) {
|
|
|
|
/* We have reached a gas change.
|
|
|
|
* Record this in the dive plan */
|
2014-04-17 08:54:55 +00:00
|
|
|
|
2015-07-03 22:13:34 +00:00
|
|
|
/* Check we need to change cylinder.
|
|
|
|
* We might not if the cylinder was chosen by the user
|
|
|
|
* or user has selected only to switch only at required stops.
|
|
|
|
* If current gas is hypoxic, we want to switch asap */
|
2015-08-03 15:29:05 +00:00
|
|
|
|
2015-07-03 22:13:34 +00:00
|
|
|
if (current_cylinder != gaschanges[gi].gasidx) {
|
|
|
|
if (!prefs.switch_at_req_stop ||
|
2017-11-22 19:42:33 +00:00
|
|
|
!trial_ascent(ds, 0, depth, stoplevels[stopidx - 1], avg_depth, bottom_time,
|
2024-09-09 11:55:37 +00:00
|
|
|
dive->get_cylinder(current_cylinder)->gasmix, po2, diveplan.surface_pressure.mbar / 1000.0, dive, divemode) || get_o2(dive->get_cylinder(current_cylinder)->gasmix) < 160) {
|
2019-09-08 14:55:00 +00:00
|
|
|
if (is_final_plan)
|
|
|
|
plan_add_segment(diveplan, clock - previous_point_time, depth, current_cylinder, po2, false, divemode);
|
|
|
|
stopping = true;
|
|
|
|
previous_point_time = clock;
|
2015-07-03 22:13:34 +00:00
|
|
|
current_cylinder = gaschanges[gi].gasidx;
|
2021-02-21 16:43:26 +00:00
|
|
|
if (divemode == CCR)
|
|
|
|
po2 = setpoint_change(dive, current_cylinder);
|
2015-07-03 22:13:34 +00:00
|
|
|
#if DEBUG_PLAN & 16
|
2024-06-25 05:43:32 +00:00
|
|
|
gas = dive->get_cylinder(current_cylinder)->gasmix;
|
2015-07-03 22:13:34 +00:00
|
|
|
printf("switch to gas %d (%d/%d) @ %5.2lfm\n", gaschanges[gi].gasidx,
|
2024-11-20 21:21:59 +00:00
|
|
|
(get_o2(gas) + 5) / 10, (get_he(gas) + 5) / 10, gaschanges[gi].depth / 1000.0);
|
2015-07-03 22:13:34 +00:00
|
|
|
#endif
|
2017-11-02 13:15:46 +00:00
|
|
|
/* Stop for the minimum duration to switch gas unless we switch to o2 */
|
2024-06-25 05:43:32 +00:00
|
|
|
if (!last_segment_min_switch && get_o2(dive->get_cylinder(current_cylinder)->gasmix) != 1000) {
|
2024-06-20 20:09:47 +00:00
|
|
|
add_segment(ds, dive->depth_to_bar(depth),
|
2024-06-25 05:43:32 +00:00
|
|
|
dive->get_cylinder(current_cylinder)->gasmix,
|
2021-02-12 16:39:46 +00:00
|
|
|
prefs.min_switch_duration, po2, divemode, prefs.decosac, true);
|
2017-10-30 21:10:57 +00:00
|
|
|
clock += prefs.min_switch_duration;
|
2017-11-08 19:59:47 +00:00
|
|
|
last_segment_min_switch = true;
|
2017-10-30 21:10:57 +00:00
|
|
|
}
|
2015-07-03 22:13:34 +00:00
|
|
|
} else {
|
2015-07-27 12:06:02 +00:00
|
|
|
/* The user has selected the option to switch gas only at required stops.
|
|
|
|
* Remember that we are waiting to switch gas
|
|
|
|
*/
|
2015-07-03 22:13:34 +00:00
|
|
|
pendinggaschange = true;
|
|
|
|
}
|
|
|
|
}
|
2015-08-03 15:29:05 +00:00
|
|
|
gi--;
|
2015-07-03 22:13:34 +00:00
|
|
|
}
|
|
|
|
--stopidx;
|
|
|
|
|
|
|
|
/* Save the current state and try to ascend to the next stopdepth */
|
|
|
|
while (1) {
|
|
|
|
/* Check if ascending to next stop is clear, go back and wait if we hit the ceiling on the way */
|
2017-11-22 19:42:33 +00:00
|
|
|
if (trial_ascent(ds, 0, depth, stoplevels[stopidx], avg_depth, bottom_time,
|
2024-09-09 11:55:37 +00:00
|
|
|
dive->get_cylinder(current_cylinder)->gasmix, po2, diveplan.surface_pressure.mbar / 1000.0, dive, divemode)) {
|
2024-09-07 12:56:34 +00:00
|
|
|
decostoptable.push_back( decostop { depth, 0 });
|
2015-07-03 22:13:34 +00:00
|
|
|
break; /* We did not hit the ceiling */
|
2017-08-28 21:59:58 +00:00
|
|
|
}
|
2015-07-03 22:13:34 +00:00
|
|
|
|
|
|
|
/* Add a minute of deco time and then try again */
|
2016-11-23 10:50:50 +00:00
|
|
|
if (!decodive) {
|
|
|
|
decodive = true;
|
|
|
|
first_stop_depth = depth;
|
|
|
|
}
|
2015-07-03 22:13:34 +00:00
|
|
|
if (!stopping) {
|
|
|
|
/* The last segment was an ascend segment.
|
|
|
|
* Add a waypoint for start of this deco stop */
|
|
|
|
if (is_final_plan)
|
2018-03-28 20:50:28 +00:00
|
|
|
plan_add_segment(diveplan, clock - previous_point_time, depth, current_cylinder, po2, false, divemode);
|
2015-07-03 22:13:34 +00:00
|
|
|
previous_point_time = clock;
|
|
|
|
stopping = true;
|
|
|
|
}
|
2015-07-27 12:06:02 +00:00
|
|
|
|
|
|
|
/* Are we waiting to switch gas?
|
|
|
|
* Occurs when the user has selected the option to switch only at required stops
|
|
|
|
*/
|
2015-07-03 22:13:34 +00:00
|
|
|
if (pendinggaschange) {
|
|
|
|
current_cylinder = gaschanges[gi + 1].gasidx;
|
2021-02-21 16:43:26 +00:00
|
|
|
if (divemode == CCR)
|
|
|
|
po2 = setpoint_change(dive, current_cylinder);
|
2013-01-10 00:01:15 +00:00
|
|
|
#if DEBUG_PLAN & 16
|
2024-06-25 05:43:32 +00:00
|
|
|
gas = dive->get_cylinder(current_cylinder)->gasmix;
|
2015-07-03 22:13:34 +00:00
|
|
|
printf("switch to gas %d (%d/%d) @ %5.2lfm\n", gaschanges[gi + 1].gasidx,
|
2024-11-20 21:21:59 +00:00
|
|
|
(get_o2(gas) + 5) / 10, (get_he(gas) + 5) / 10, gaschanges[gi + 1].depth / 1000.0);
|
2013-01-10 00:01:15 +00:00
|
|
|
#endif
|
2017-11-02 13:15:46 +00:00
|
|
|
/* Stop for the minimum duration to switch gas unless we switch to o2 */
|
2024-06-25 05:43:32 +00:00
|
|
|
if (!last_segment_min_switch && get_o2(dive->get_cylinder(current_cylinder)->gasmix) != 1000) {
|
2024-06-20 20:09:47 +00:00
|
|
|
add_segment(ds, dive->depth_to_bar(depth),
|
2024-06-25 05:43:32 +00:00
|
|
|
dive->get_cylinder(current_cylinder)->gasmix,
|
2021-02-12 16:39:46 +00:00
|
|
|
prefs.min_switch_duration, po2, divemode, prefs.decosac, true);
|
2017-10-30 21:10:57 +00:00
|
|
|
clock += prefs.min_switch_duration;
|
|
|
|
}
|
2015-07-03 22:13:34 +00:00
|
|
|
pendinggaschange = false;
|
2015-06-22 12:43:20 +00:00
|
|
|
}
|
2013-10-07 00:32:50 +00:00
|
|
|
|
2018-04-09 19:37:03 +00:00
|
|
|
int new_clock = wait_until(ds, dive, clock, clock, laststoptime * 2 + 1, timestep, depth, stoplevels[stopidx], avg_depth,
|
2024-09-09 11:55:37 +00:00
|
|
|
bottom_time, dive->get_cylinder(current_cylinder)->gasmix, po2, diveplan.surface_pressure.mbar / 1000.0, divemode);
|
2017-08-24 21:45:33 +00:00
|
|
|
laststoptime = new_clock - clock;
|
2015-07-03 22:13:34 +00:00
|
|
|
/* Finish infinite deco */
|
2017-11-27 20:56:22 +00:00
|
|
|
if (laststoptime >= 48 * 3600 && depth >= 6000) {
|
2024-05-15 05:23:39 +00:00
|
|
|
error = PLAN_ERROR_TIMEOUT;
|
|
|
|
|
2015-07-03 22:13:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-08-24 22:08:14 +00:00
|
|
|
|
|
|
|
o2breaking = false;
|
2017-11-02 13:15:46 +00:00
|
|
|
stop_cylinder = current_cylinder;
|
2017-11-02 20:00:54 +00:00
|
|
|
if (prefs.doo2breaks && prefs.last_stop) {
|
2015-07-27 12:06:02 +00:00
|
|
|
/* The backgas breaks option limits time on oxygen to 12 minutes, followed by 6 minutes on
|
2017-10-10 07:46:34 +00:00
|
|
|
* backgas. This could be customized if there were demand.
|
2015-07-27 12:06:02 +00:00
|
|
|
*/
|
2017-10-10 07:46:34 +00:00
|
|
|
if (break_cylinder == -1) {
|
2024-06-25 05:43:32 +00:00
|
|
|
if (best_first_ascend_cylinder != -1 && get_o2(dive->get_cylinder(best_first_ascend_cylinder)->gasmix) <= 320)
|
2017-10-10 07:46:34 +00:00
|
|
|
break_cylinder = best_first_ascend_cylinder;
|
|
|
|
else
|
|
|
|
break_cylinder = 0;
|
|
|
|
}
|
2024-06-25 05:43:32 +00:00
|
|
|
if (get_o2(dive->get_cylinder(current_cylinder)->gasmix) == 1000) {
|
2017-08-24 22:08:14 +00:00
|
|
|
if (laststoptime >= 12 * 60) {
|
|
|
|
laststoptime = 12 * 60;
|
2017-10-18 21:51:14 +00:00
|
|
|
new_clock = clock + laststoptime;
|
2017-08-24 22:08:14 +00:00
|
|
|
o2breaking = true;
|
2017-11-02 13:15:46 +00:00
|
|
|
o2break_next = true;
|
2017-10-10 07:46:34 +00:00
|
|
|
breakfrom_cylinder = current_cylinder;
|
2015-07-03 22:13:34 +00:00
|
|
|
if (is_final_plan)
|
2018-03-28 20:50:28 +00:00
|
|
|
plan_add_segment(diveplan, laststoptime, depth, current_cylinder, po2, false, divemode);
|
2017-08-24 22:08:14 +00:00
|
|
|
previous_point_time = clock + laststoptime;
|
2017-10-10 07:46:34 +00:00
|
|
|
current_cylinder = break_cylinder;
|
2015-07-03 22:13:34 +00:00
|
|
|
}
|
2017-11-02 13:15:46 +00:00
|
|
|
} else if (o2break_next) {
|
|
|
|
if (laststoptime >= 6 * 60) {
|
|
|
|
laststoptime = 6 * 60;
|
|
|
|
new_clock = clock + laststoptime;
|
|
|
|
o2breaking = true;
|
|
|
|
o2break_next = false;
|
|
|
|
if (is_final_plan)
|
2018-03-28 20:50:28 +00:00
|
|
|
plan_add_segment(diveplan, laststoptime, depth, current_cylinder, po2, false, divemode);
|
2017-11-02 13:15:46 +00:00
|
|
|
previous_point_time = clock + laststoptime;
|
|
|
|
current_cylinder = breakfrom_cylinder;
|
2014-07-02 20:07:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-06-25 05:43:32 +00:00
|
|
|
add_segment(ds, dive->depth_to_bar(depth), dive->get_cylinder(stop_cylinder)->gasmix,
|
2021-02-12 16:39:46 +00:00
|
|
|
laststoptime, po2, divemode, prefs.decosac, true);
|
2017-11-08 19:59:47 +00:00
|
|
|
last_segment_min_switch = false;
|
2024-09-07 12:56:34 +00:00
|
|
|
decostoptable.push_back(decostop { depth, laststoptime } );
|
2017-10-18 21:51:14 +00:00
|
|
|
|
2017-10-30 21:46:01 +00:00
|
|
|
clock += laststoptime;
|
2017-08-24 22:08:14 +00:00
|
|
|
if (!o2breaking)
|
|
|
|
break;
|
2014-07-02 20:07:38 +00:00
|
|
|
}
|
2015-07-03 22:13:34 +00:00
|
|
|
if (stopping) {
|
|
|
|
/* Next we will ascend again. Add a waypoint if we have spend deco time */
|
|
|
|
if (is_final_plan)
|
2018-03-28 20:50:28 +00:00
|
|
|
plan_add_segment(diveplan, clock - previous_point_time, depth, current_cylinder, po2, false, divemode);
|
2015-07-03 22:13:34 +00:00
|
|
|
previous_point_time = clock;
|
|
|
|
stopping = false;
|
|
|
|
}
|
2014-04-17 08:54:55 +00:00
|
|
|
}
|
2017-11-02 08:34:45 +00:00
|
|
|
/* When calculating deco_time, we should pretend the final ascent rate is always the same,
|
|
|
|
* otherwise odd things can happen, such as CVA causing the final ascent to start *later*
|
|
|
|
* if the ascent rate is slower, which is completely nonsensical.
|
|
|
|
* Assume final ascent takes 20s, which is the time taken to ascend at 9m/min from 3m */
|
2022-11-10 11:33:11 +00:00
|
|
|
ds->deco_time = clock - bottom_time - (M_OR_FT(3,10) * ( prefs.last_stop ? 2 : 1)) / last_ascend_rate + 20;
|
2024-05-15 05:23:39 +00:00
|
|
|
} while (!is_final_plan && error == PLAN_OK);
|
2015-07-03 22:13:34 +00:00
|
|
|
|
2018-03-28 20:50:28 +00:00
|
|
|
plan_add_segment(diveplan, clock - previous_point_time, 0, current_cylinder, po2, false, divemode);
|
2021-02-12 17:19:24 +00:00
|
|
|
if (decoMode(true) == VPMB) {
|
2024-09-04 05:36:05 +00:00
|
|
|
diveplan.eff_gfhigh = lrint(100.0 * regressionb(ds));
|
|
|
|
diveplan.eff_gflow = lrint(100.0 * (regressiona(ds) * first_stop_depth + regressionb(ds)));
|
2016-11-23 10:50:50 +00:00
|
|
|
}
|
|
|
|
|
2019-08-25 18:05:05 +00:00
|
|
|
if (prefs.surface_segment != 0) {
|
2020-04-27 19:12:24 +00:00
|
|
|
// Switch to an empty air cylinder for breathing air at the surface.
|
|
|
|
// FIXME: This is incredibly silly and emulates the old code when
|
|
|
|
// we had a fixed cylinder table: It uses an extra fake cylinder
|
|
|
|
// past the regular cylinder table, which is not visible to the UI.
|
|
|
|
// Fix this as soon as possible!
|
2024-05-28 19:31:11 +00:00
|
|
|
current_cylinder = static_cast<int>(dive->cylinders.size());
|
2019-08-25 18:05:05 +00:00
|
|
|
plan_add_segment(diveplan, prefs.surface_segment, 0, current_cylinder, 0, false, OC);
|
|
|
|
}
|
2024-04-25 20:16:08 +00:00
|
|
|
create_dive_from_plan(diveplan, dive, dc, is_planner);
|
2024-09-07 12:25:48 +00:00
|
|
|
diveplan.add_plan_to_notes(*dive, show_disclaimer, error);
|
2024-05-27 15:09:48 +00:00
|
|
|
fixup_dc_duration(*dc);
|
2024-09-07 13:32:06 +00:00
|
|
|
return decostoptable;
|
2013-01-05 07:11:42 +00:00
|
|
|
}
|