X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=dive.c;h=54784cdbabfb01fbb5c5a8db539cdc481f20c613;hb=refs%2Fheads%2Fmaster;hp=f4bf497a7da0edeafb91b5a26b1de067f87d64b7;hpb=d2d4364afcc3fb310ea43573f0d455f90c9212ce;p=ext%2Fsubsurface.git diff --git a/dive.c b/dive.c index f4bf497..54784cd 100644 --- a/dive.c +++ b/dive.c @@ -472,11 +472,19 @@ struct dive *fixup_dive(struct dive *dive) cyl->sample_end.mbar = 0; } } - if (end < 0) - { + if (end < 0) { /* Assume an ascent/descent rate of 9 m/min */ - int asc_desc_time = dive->maxdepth.mm*60/9000; - dive->meandepth.mm = dive->maxdepth.mm*(dive->duration.seconds-asc_desc_time)/dive->duration.seconds; + int depth = dive->maxdepth.mm; + int asc_desc_time = depth*60/9000; + int duration = dive->duration.seconds; + + /* Some sanity checks against insane dives */ + if (duration < 2) + duration = 2; + if (asc_desc_time * 2 >= duration) + asc_desc_time = duration/2; + + dive->meandepth.mm = depth*(duration-asc_desc_time)/duration; return dive; }