+ 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;
+}
+
+static void get_string(char **str, const char *s)
+{
+ int len;
+ char *n;
+
+ if (!s)
+ s = "";
+ len = strlen(s);
+ if (len > 16)
+ len = 16;
+ n = malloc(len+1);
+ memcpy(n, s, len);
+ n[len] = 0;
+ *str = n;
+}
+
+static void get_location(struct dive *dive, char **str)
+{
+ get_string(str, dive->location);
+}
+
+static void get_cylinder(struct dive *dive, char **str)
+{
+ get_string(str, dive->cylinder[0].type.description);
+}
+
+static void fill_one_dive(struct dive *dive,
+ GtkTreeModel *model,
+ GtkTreeIter *iter)
+{
+ int sac;
+ char *location, *cylinder;
+
+ get_cylinder(dive, &cylinder);
+ get_location(dive, &location);
+ get_sac(dive, &sac);
+
+ /*
+ * 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_LOCATION, location,
+ DIVE_CYLINDER, cylinder,
+ DIVE_SAC, sac,
+ -1);