+
+ for (i = 0; i < MAX_CYLINDERS; i++) {
+ cylinder_t *cyl = dive->cylinder + i;
+ int size = cyl->type.size.mliter;
+ double kilo_atm;
+
+ if (!size)
+ continue;
+
+ kilo_atm = (cyl->start.mbar - cyl->end.mbar) / 1013250.0;
+
+ /* Liters of air at 1 atm == milliliters at 1k atm*/
+ airuse += kilo_atm * size;
+ }
+ return airuse;
+}
+
+static void get_sac(struct dive *dive, int *val, char **str)
+{
+ const double liters_per_cuft = 28.317;
+ double airuse, pressure, sac;
+ const char *fmt, *unit;
+ char buffer[20];
+
+ *val = 0;
+ *str = "";
+ airuse = calculate_airuse(dive);
+ if (!airuse)
+ return;
+ if (!dive->duration.seconds)
+ return;
+
+ /* Mean pressure in atm: 1 atm per 10m */
+ pressure = 1 + (dive->meandepth.mm / 10000.0);
+ sac = airuse / pressure * 60 / dive->duration.seconds;
+
+ /* milliliters per minute.. */
+ *val = sac * 1000;
+
+ switch (output_units.volume) {
+ case LITER:
+ unit = "l";
+ fmt = "%4.0f %s";
+ break;
+ case CUFT:
+ unit = "cuft";
+ fmt = "%4.2f %s";
+ airuse /= liters_per_cuft;
+ sac /= liters_per_cuft;
+ break;
+ }
+
+ snprintf(buffer, sizeof(buffer), fmt, sac, unit);
+ *str = strdup(buffer);
+}
+
+static gboolean set_one_dive(GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ GValue value = {0, };
+ struct dive *dive;
+ int date, depth, duration, temp, nitrox, sac;
+ char *datestr, *depthstr, *durationstr, *tempstr, *nitroxstr, *sacstr;
+ char *location;
+
+ /* Get the dive number */
+ gtk_tree_model_get_value(model, iter, DIVE_INDEX, &value);
+ dive = get_dive(g_value_get_int(&value));
+ if (!dive)
+ return TRUE;
+
+ get_date(dive, &date, &datestr);
+ get_depth(dive, &depth, &depthstr);
+ get_duration(dive, &duration, &durationstr);
+ get_location(dive, &location);
+ get_temp(dive, &temp, &tempstr);
+ get_nitrox(dive, &nitrox, &nitroxstr);
+ get_sac(dive, &sac, &sacstr);
+
+ /*
+ * We only set the fields that changed: the strings.
+ * The core data itself is unaffected by units
+ */
+ gtk_list_store_set(GTK_LIST_STORE(model), iter,
+ DIVE_DATESTR, datestr,
+ DIVE_DEPTHSTR, depthstr,
+ DIVE_DURATIONSTR, durationstr,
+ DIVE_LOCATION, location,
+ DIVE_TEMPSTR, tempstr,
+ DIVE_TEMP, temp,
+ DIVE_NITROXSTR, nitroxstr,
+ DIVE_NITROX, nitrox,
+ DIVE_SACSTR, sacstr,
+ DIVE_SAC, sac,
+ -1);
+
+ return FALSE;
+}
+
+void update_dive_list_units(struct DiveList *dive_list)
+{