Show ascent gas consumption separately in planner

In the worst gase you have to provide gas for your buddy during all the
ascent. So you should have the amount of gas used in ascent as a reserve.
This patch makes the planner notes display that value separately.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Robert C. Helling 2014-07-01 09:37:49 +02:00 committed by Dirk Hohndel
parent 2766ed8093
commit 1b7abab9b9
3 changed files with 14 additions and 6 deletions

1
dive.h
View file

@ -63,6 +63,7 @@ typedef struct
depth_t depth; depth_t depth;
bool manually_added; bool manually_added;
volume_t gas_used; volume_t gas_used;
volume_t deco_gas_used;
} cylinder_t; } cylinder_t;
typedef struct typedef struct

View file

@ -57,7 +57,8 @@ bool cylinder_nodata(cylinder_t *cyl)
!cyl->gasmix.he.permille && !cyl->gasmix.he.permille &&
!cyl->start.mbar && !cyl->start.mbar &&
!cyl->end.mbar && !cyl->end.mbar &&
!cyl->gas_used.mliter; !cyl->gas_used.mliter &&
!cyl->deco_gas_used.mliter;
} }
static bool cylinder_nosamples(cylinder_t *cyl) static bool cylinder_nosamples(cylinder_t *cyl)

View file

@ -217,7 +217,7 @@ static int verify_gas_exists(struct dive *dive, struct gasmix mix_in)
/* calculate the new end pressure of the cylinder, based on its current end pressure and the /* calculate the new end pressure of the cylinder, based on its current end pressure and the
* latest segment. */ * latest segment. */
static void update_cylinder_pressure(struct dive *d, int old_depth, int new_depth, int duration, int sac, cylinder_t *cyl) static void update_cylinder_pressure(struct dive *d, int old_depth, int new_depth, int duration, int sac, cylinder_t *cyl, bool in_deco)
{ {
volume_t gas_used; volume_t gas_used;
pressure_t delta_p; pressure_t delta_p;
@ -228,6 +228,8 @@ static void update_cylinder_pressure(struct dive *d, int old_depth, int new_dept
mean_depth.mm = (old_depth + new_depth) / 2; mean_depth.mm = (old_depth + new_depth) / 2;
gas_used.mliter = depth_to_atm(mean_depth.mm, d) * sac / 60 * duration; gas_used.mliter = depth_to_atm(mean_depth.mm, d) * sac / 60 * duration;
cyl->gas_used.mliter += gas_used.mliter; cyl->gas_used.mliter += gas_used.mliter;
if (in_deco)
cyl->deco_gas_used.mliter += gas_used.mliter;
if (cyl->type.size.mliter) { if (cyl->type.size.mliter) {
delta_p.mbar = gas_used.mliter * 1000.0 / cyl->type.size.mliter; delta_p.mbar = gas_used.mliter * 1000.0 / cyl->type.size.mliter;
cyl->end.mbar -= delta_p.mbar; cyl->end.mbar -= delta_p.mbar;
@ -320,7 +322,7 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive
sample->time.seconds = lasttime = time; sample->time.seconds = lasttime = time;
sample->depth.mm = lastdepth = depth; sample->depth.mm = lastdepth = depth;
update_cylinder_pressure(dive, sample[-1].depth.mm, depth, time - sample[-1].time.seconds, update_cylinder_pressure(dive, sample[-1].depth.mm, depth, time - sample[-1].time.seconds,
dp->entered ? diveplan->bottomsac : diveplan->decosac, cyl); dp->entered ? diveplan->bottomsac : diveplan->decosac, cyl, !dp->entered);
sample->cylinderpressure.mbar = cyl->end.mbar; sample->cylinderpressure.mbar = cyl->end.mbar;
finish_sample(dc); finish_sample(dc);
dp = dp->next; dp = dp->next;
@ -637,15 +639,17 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
snprintf(temp, sizeof(temp), "%s", translate("gettextFromC", "Gas consumption:")); snprintf(temp, sizeof(temp), "%s", translate("gettextFromC", "Gas consumption:"));
len += snprintf(buffer + len, sizeof(buffer) - len, "</tbody></table></div><div><br>%s<br>", temp); len += snprintf(buffer + len, sizeof(buffer) - len, "</tbody></table></div><div><br>%s<br>", temp);
for (gasidx = 0; gasidx < MAX_CYLINDERS; gasidx++) { for (gasidx = 0; gasidx < MAX_CYLINDERS; gasidx++) {
double volume; double volume, deco_volume, deco_pressure;
const char *unit; const char *unit, *pressure_unit;
char warning[1000] = ""; char warning[1000] = "";
cylinder_t *cyl = &dive->cylinder[gasidx]; cylinder_t *cyl = &dive->cylinder[gasidx];
if (cylinder_none(cyl)) if (cylinder_none(cyl))
break; break;
volume = get_volume_units(cyl->gas_used.mliter, NULL, &unit); volume = get_volume_units(cyl->gas_used.mliter, NULL, &unit);
deco_volume = get_volume_units(cyl->deco_gas_used.mliter, NULL, &unit);
if (cyl->type.size.mliter) { if (cyl->type.size.mliter) {
deco_pressure = get_pressure_units(1000.0 * cyl->deco_gas_used.mliter / cyl->type.size.mliter, &pressure_unit);
/* Warn if the plan uses more gas than is available in a cylinder /* Warn if the plan uses more gas than is available in a cylinder
* This only works if we have working pressure for the cylinder * This only works if we have working pressure for the cylinder
* 10bar is a made up number - but it seemed silly to pretend you could breathe cylinder down to 0 */ * 10bar is a made up number - but it seemed silly to pretend you could breathe cylinder down to 0 */
@ -653,8 +657,10 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
snprintf(warning, sizeof(warning), " &mdash; <span style='color: red;'>%s </span> %s", snprintf(warning, sizeof(warning), " &mdash; <span style='color: red;'>%s </span> %s",
translate("gettextFromC", "Warning:"), translate("gettextFromC", "Warning:"),
translate("gettextFromC", "this is more gas than available in the specified cylinder!")); translate("gettextFromC", "this is more gas than available in the specified cylinder!"));
snprintf(temp, sizeof(temp), translate("gettextFromC", "%.0f%s (%.0f%s/%.0f%s in planned ascent) of %s"), volume, unit, deco_volume, unit, deco_pressure, pressure_unit, gasname(&cyl->gasmix));
} else {
snprintf(temp, sizeof(temp), translate("gettextFromC", "%.0f%s (%.0f%s during planned ascent) of %s"), volume, unit, deco_volume, unit, gasname(&cyl->gasmix));
} }
snprintf(temp, sizeof(temp), translate("gettextFromC", "%.0f%s of %s"), volume, unit, gasname(&cyl->gasmix));
len += snprintf(buffer + len, sizeof(buffer) - len, "%s%s<br>", temp, warning); len += snprintf(buffer + len, sizeof(buffer) - len, "%s%s<br>", temp, warning);
} }
dp = diveplan->dp; dp = diveplan->dp;