diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-01-03 21:58:46 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-01-03 21:58:46 -0800 |
commit | f93f578eca3a5c8cfed42fa6ddecba63b851e9ae (patch) | |
tree | 64baf49864728e1c9c46d2920597e862832a3dae /divelist.c | |
parent | fc882f574febd5eb3387d33edc5f1f81ab93c0ea (diff) | |
parent | 9cd18c43aaaccaa8ba0fbdf8e5a23ad6c7bbeb73 (diff) | |
download | subsurface-f93f578eca3a5c8cfed42fa6ddecba63b851e9ae.tar.gz |
Merge branch 'deco2'
Bringing in the first attempts to do our own deco calculations
Diffstat (limited to 'divelist.c')
-rw-r--r-- | divelist.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/divelist.c b/divelist.c index e389d038f..f2e678181 100644 --- a/divelist.c +++ b/divelist.c @@ -818,6 +818,83 @@ static int calculate_sac(struct dive *dive, struct divecomputer *dc) return sac * 1000; } +/* for now we do this based on the first divecomputer */ +static void add_dive_to_deco(struct dive *dive) +{ + struct divecomputer *dc = &dive->dc; + int i; + + if (!dc) + return; + for (i = 1; i < dive->dc.samples; i++) { + struct sample *psample = dc->sample + i - 1; + struct sample *sample = dc->sample + i; + int t0 = psample->time.seconds; + int t1 = sample->time.seconds; + int j; + + for (j = t0; j < t1; j++) { + int depth = 0.5 + psample->depth.mm + (j - t0) * (sample->depth.mm - psample->depth.mm) / (t1 - t0); + (void) add_segment(depth_to_mbar(depth, dive) / 1000.0, &dive->cylinder[sample->sensor].gasmix, 1); + } + } +} + +static struct gasmix air = { .o2.permille = 209 }; + +/* take into account previous dives until there is a 48h gap between dives */ +void init_decompression(struct dive *dive) +{ + int i, divenr = -1; + timestamp_t when; + gboolean deco_init = FALSE; + + if (!dive) + return; + while (++divenr < dive_table.nr && get_dive(divenr) != dive) + ; + when = dive->when; + i = divenr; + while (--i) { + struct dive* pdive = get_dive(i); + if (!pdive || pdive->when > when || pdive->when + pdive->duration.seconds + 48 * 60 * 60 < when) + break; + when = pdive->when; + } + + while (++i < divenr) { + struct dive* pdive = get_dive(i); + double surface_pressure = pdive->surface_pressure.mbar ? pdive->surface_pressure.mbar / 1000.0 : 1.013; + unsigned int surface_time = get_dive(i+1)->when - pdive->when - pdive->duration.seconds; + + if (!deco_init) { + clear_deco(surface_pressure); + deco_init = TRUE; +#if DEBUG & 16 + dump_tissues(); +#endif + } + add_dive_to_deco(pdive); +#if DEBUG & 16 + printf("added dive #%d\n", pdive->number); + dump_tissues(); +#endif + add_segment(surface_pressure, &air, surface_time); +#if DEBUG & 16 + printf("after surface intervall of %d:%02u\n", FRACTION(surface_time,60)); + dump_tissues(); +#endif + } + if (!deco_init) { + double surface_pressure = dive->surface_pressure.mbar ? dive->surface_pressure.mbar / 1000.0 : 1.013; + clear_deco(surface_pressure); +#if DEBUG & 16 + printf("no previous dive\n"); + dump_tissues(); +#endif + } +} + void update_cylinder_related_info(struct dive *dive) { if (dive != NULL) { |