diff options
-rw-r--r-- | deco.c | 8 | ||||
-rw-r--r-- | dive.h | 2 | ||||
-rw-r--r-- | divelist.c | 16 | ||||
-rw-r--r-- | planner.c | 16 | ||||
-rw-r--r-- | print.c | 9 | ||||
-rw-r--r-- | profile.c | 14 |
6 files changed, 39 insertions, 26 deletions
@@ -72,7 +72,7 @@ const double buehlmann_He_factor_expositon_one_second[] = { 2.80360036664540E-004, 2.09299583354805E-004, 1.63410794820518E-004, 1.27869320250551E-004, 1.00198406028040E-004, 7.83611475491108E-005, 6.13689891868496E-005, 4.81280465299827E-005}; -#define WV_PRESSURE 0.0627 /* water vapor pressure */ +#define WV_PRESSURE 0.0627 // water vapor pressure in bar #define DECO_STOPS_MULTIPLIER_MM 3000.0 #define GF_LOW_AT_MAXDEPTH 0 @@ -126,7 +126,7 @@ static double tissue_tolerance_calc(const struct dive *dive) } /* add period_in_seconds at the given pressure and gas to the deco calculation */ -double add_segment(double pressure, struct gasmix *gasmix, int period_in_seconds, double ccpo2, const struct dive *dive) +double add_segment(double pressure, struct gasmix *gasmix, int period_in_seconds, int ccpo2, const struct dive *dive) { int ci; int fo2 = gasmix->o2.permille ? gasmix->o2.permille : O2_IN_AIR; @@ -138,9 +138,9 @@ double add_segment(double pressure, struct gasmix *gasmix, int period_in_seconds gf_low_pressure_this_dive = pressure; #endif - if (ccpo2 > 0.0) { /* CC */ + if (ccpo2) { /* CC */ double rel_o2_amb, f_dilutent; - rel_o2_amb = ccpo2 / pressure; + rel_o2_amb = ccpo2 / pressure / 1000; f_dilutent = (1 - rel_o2_amb) / (1 - fo2 / 1000.0); if (f_dilutent < 0) { /* setpoint is higher than ambient pressure -> pure O2 */ ppn2 = 0.0; @@ -599,7 +599,7 @@ extern void subsurface_command_line_exit(gint *, gchar ***); #define FRACTION(n,x) ((unsigned)(n)/(x)),((unsigned)(n)%(x)) -extern double add_segment(double pressure, struct gasmix *gasmix, int period_in_seconds, double setpoint, const struct dive *dive); +extern double add_segment(double pressure, struct gasmix *gasmix, int period_in_seconds, int setpoint, const struct dive *dive); extern void clear_deco(double surface_pressure); extern void dump_tissues(void); extern unsigned int deco_allowed_depth(double tissues_tolerance, double surface_pressure, struct dive *dive, gboolean smooth); diff --git a/divelist.c b/divelist.c index f7ed6e14d..e50039110 100644 --- a/divelist.c +++ b/divelist.c @@ -646,18 +646,18 @@ static int calculate_otu(struct dive *dive, struct divecomputer *dc) for (i = 1; i < dc->samples; i++) { int t; - double po2; + int po2; struct sample *sample = dc->sample + i; struct sample *psample = sample - 1; t = sample->time.seconds - psample->time.seconds; if (sample->po2) { - po2 = sample->po2 / 1000.0; + po2 = sample->po2; } else { int o2 = active_o2(dive, dc, sample->time); - po2 = o2 / 1000.0 * depth_to_mbar(sample->depth.mm, dive) / 1000.0; + po2 = o2 / 1000.0 * depth_to_mbar(sample->depth.mm, dive); } - if (po2 >= 0.5) - otu += pow(po2 - 0.5, 0.83) * t / 30.0; + if (po2 >= 500) + otu += pow((po2 - 500) / 1000.0, 0.83) * t / 30.0; } return otu + 0.5; } @@ -741,7 +741,7 @@ static void add_dive_to_deco(struct dive *dive) for (j = t0; j < t1; j++) { int depth = interpolate(psample->depth.mm, sample->depth.mm, j - t0, t1 - t0); (void) add_segment(depth_to_mbar(depth, dive) / 1000.0, - &dive->cylinder[sample->sensor].gasmix, 1, sample->po2 / 1000.0, dive); + &dive->cylinder[sample->sensor].gasmix, 1, sample->po2, dive); } } } @@ -802,7 +802,7 @@ double init_decompression(struct dive *dive) if (pdive->when > lasttime) { surface_time = pdive->when - lasttime; lasttime = pdive->when + pdive->dc.duration.seconds; - tissue_tolerance = add_segment(surface_pressure, &air, surface_time, 0.0, dive); + tissue_tolerance = add_segment(surface_pressure, &air, surface_time, 0, dive); #if DECO_CALC_DEBUG & 2 printf("after surface intervall of %d:%02u\n", FRACTION(surface_time,60)); dump_tissues(); @@ -813,7 +813,7 @@ double init_decompression(struct dive *dive) if (lasttime && dive->when > lasttime) { surface_time = dive->when - lasttime; surface_pressure = (dive->dc.surface_pressure.mbar ? dive->dc.surface_pressure.mbar : SURFACE_PRESSURE) / 1000; - tissue_tolerance = add_segment(surface_pressure, &air, surface_time, 0.0, dive); + tissue_tolerance = add_segment(surface_pressure, &air, surface_time, 0, dive); #if DECO_CALC_DEBUG & 2 printf("after surface intervall of %d:%02u\n", FRACTION(surface_time,60)); dump_tissues(); @@ -112,7 +112,7 @@ double tissue_at_end(struct dive *dive, char **cached_datap) for (j = t0; j < t1; j++) { int depth = interpolate(lastdepth, sample->depth.mm, j - t0, t1 - t0); tissue_tolerance = add_segment(depth_to_mbar(depth, dive) / 1000.0, - &dive->cylinder[gasidx].gasmix, 1, sample->po2 / 1000.0, dive); + &dive->cylinder[gasidx].gasmix, 1, sample->po2, dive); } psample = sample; t0 = t1; @@ -139,7 +139,7 @@ int time_at_last_depth(struct dive *dive, int next_stop, char **cached_data_p) while (deco_allowed_depth(tissue_tolerance, surface_pressure, dive, 1) > next_stop) { wait++; tissue_tolerance = add_segment(depth_to_mbar(depth, dive) / 1000.0, - &dive->cylinder[gasidx].gasmix, 1, sample->po2 / 1000.0, dive); + &dive->cylinder[gasidx].gasmix, 1, sample->po2, dive); } return wait; } @@ -202,7 +202,7 @@ struct dive *create_dive_from_plan(struct diveplan *diveplan) add_gas(dive, oldo2, oldhe); while (dp) { int o2 = dp->o2, he = dp->he; - int po2 = dp->po2 ? : oldpo2; + int po2 = dp->po2; int time = dp->time; int depth = dp->depth; @@ -218,11 +218,18 @@ struct dive *create_dive_from_plan(struct diveplan *diveplan) he = oldhe; } + /* Check for SetPoint change */ + if (oldpo2 != po2) { + if (lasttime) + add_event(dc, lasttime, 20, 0, po2, "SP change"); // SAMPLE_EVENT_PO2 + oldpo2 = po2; + } + /* Create new gas, and gas change event if necessary */ if (o2 != oldo2 || he != oldhe) { int value = (o2 / 10) | (he / 10 << 16); add_gas(dive, o2, he); - add_event(dc, lasttime, 11, 0, value, "gaschange"); + add_event(dc, lasttime, 25, 0, value, "gaschange"); // SAMPLE_EVENT_GASCHANGE2 oldo2 = o2; oldhe = he; } @@ -236,7 +243,6 @@ struct dive *create_dive_from_plan(struct diveplan *diveplan) sample->depth.mm = depth; finish_sample(dc); lasttime = time; - oldpo2 = po2; dp = dp->next; } if (dc->samples <= 1) { @@ -487,17 +487,20 @@ static void show_dive_tanks(struct dive *dive, cairo_t *cr, double w, cairo_move_to (cr, w, 3 * line_height + (h * 0.05)); cairo_line_to (cr, 3 * line_width, 3 * line_height + (h * 0.05)); cairo_stroke (cr); + cairo_save (cr); + /* and print OTUs, CNS and weight */ cairo_translate (cr, (3.05 * line_width), height / (6 * (double) PANGO_SCALE)); print_weight_data (dive, cr, maxwidth * 0.90/2 , maxheight, maxheight / 2, font); - cairo_translate (cr, -(3.05 * line_width), -height / (6 * (double) PANGO_SCALE)); - cairo_translate (cr, w, 0); + cairo_restore (cr); + cairo_save(cr); + cairo_translate (cr, w, line_height/4); print_SAC (dive, cr, maxwidth * 0.90/2, maxheight, font); cairo_translate (cr, 0, line_height); print_cns (dive, cr, maxwidth * 0.90/2, maxheight, font); cairo_translate (cr,0, line_height); print_otus (dive, cr, maxwidth * 0.90/2, maxheight, font); - cairo_translate (cr, -w, -2 * line_height); + cairo_restore (cr); } } @@ -391,19 +391,23 @@ static void plot_one_event(struct graphics_context *gc, struct plot_info *pi, st unsigned int he = event->value >> 16; unsigned int o2 = event->value & 0xffff; if (he) { - snprintf(buffer, sizeof(buffer), "%s: (%u/%u)", + snprintf(buffer, sizeof(buffer), "%s:%u/%u", _(event->name), o2, he); } else { if (o2 == 21) - snprintf(buffer, sizeof(buffer), "%s: %s", + snprintf(buffer, sizeof(buffer), "%s:%s", _(event->name), _("air")); else - snprintf(buffer, sizeof(buffer), "%s: %u%% %s", + snprintf(buffer, sizeof(buffer), "%s:%u%% %s", _(event->name), o2, "O" UTF8_SUBSCRIPT_2); } + } else if (event->name && !strcmp(event->name, "SP change")) { + snprintf(buffer, sizeof(buffer), "%s:%0.1f", _(event->name), (double) event->value / 1000); } else { - snprintf(buffer, sizeof(buffer), "%s: %d", _(event->name), event->value); + snprintf(buffer, sizeof(buffer), "%s:%d", _(event->name), event->value); } + } else if (event->name && !strcmp(event->name, "SP change")) { + snprintf(buffer, sizeof(buffer), "Bailing out to OC"); } else { snprintf(buffer, sizeof(buffer), "%s%s", _(event->name), event->flags == SAMPLE_FLAGS_BEGIN ? " begin" : @@ -1873,7 +1877,7 @@ static void calculate_deco_information(struct dive *dive, struct divecomputer *d for (j = t0+1; j <= t1; j++) { int depth = interpolate(entry[-1].depth, entry[0].depth, j - t0, t1 - t0); double min_pressure = add_segment(depth_to_mbar(depth, dive) / 1000.0, - &dive->cylinder[cylinderindex].gasmix, 1, entry->po2, dive); + &dive->cylinder[cylinderindex].gasmix, 1, entry->po2 * 1000, dive); tissue_tolerance = min_pressure; } if (t0 == t1) |