+static stats_t stats_selection;
+
+
+static void process_dive(struct dive *dp, stats_t *stats)
+{
+ int old_tt, sac_time = 0;
+ const char *unit;
+
+ old_tt = stats->total_time.seconds;
+ stats->total_time.seconds += dp->duration.seconds;
+ if (dp->duration.seconds > stats->longest_time.seconds)
+ stats->longest_time.seconds = dp->duration.seconds;
+ if (stats->shortest_time.seconds == 0 || dp->duration.seconds < stats->shortest_time.seconds)
+ stats->shortest_time.seconds = dp->duration.seconds;
+ if (dp->maxdepth.mm > stats->max_depth.mm)
+ stats->max_depth.mm = dp->maxdepth.mm;
+ if (stats->min_depth.mm == 0 || dp->maxdepth.mm < stats->min_depth.mm)
+ stats->min_depth.mm = dp->maxdepth.mm;
+ if (dp->watertemp.mkelvin) {
+ if (stats->min_temp == 0 || dp->watertemp.mkelvin < stats->min_temp)
+ stats->min_temp = dp->watertemp.mkelvin;
+ if (dp->watertemp.mkelvin > stats->max_temp)
+ stats->max_temp = dp->watertemp.mkelvin;
+ stats->combined_temp += get_temp_units(dp->watertemp.mkelvin, &unit);
+ stats->combined_count++;
+ }
+
+ /* Maybe we should drop zero-duration dives */
+ if (!dp->duration.seconds)
+ return;
+ stats->avg_depth.mm = (1.0 * old_tt * stats->avg_depth.mm +
+ dp->duration.seconds * dp->meandepth.mm) / stats->total_time.seconds;
+ if (dp->sac > 2800) { /* less than .1 cuft/min (2800ml/min) is bogus */
+ sac_time = stats->total_sac_time + dp->duration.seconds;
+ stats->avg_sac.mliter = (1.0 * stats->total_sac_time * stats->avg_sac.mliter +
+ dp->duration.seconds * dp->sac) / sac_time ;
+ if (dp->sac > stats->max_sac.mliter)
+ stats->max_sac.mliter = dp->sac;
+ if (stats->min_sac.mliter == 0 || dp->sac < stats->min_sac.mliter)
+ stats->min_sac.mliter = dp->sac;
+ stats->total_sac_time = sac_time;
+ }
+}