X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=divelist.c;h=d215fd23651c6e2737e0b671cfe97d5de22cd5e6;hb=dfacb5e124125e0e864509459d9ffef73495a3cd;hp=dc0e256a557c51b341fb9f22a7ef70e264868b87;hpb=7dca1cb78e7d8250bb4fd6843bd3260492554832;p=ext%2Fsubsurface.git diff --git a/divelist.c b/divelist.c index dc0e256..d215fd2 100644 --- a/divelist.c +++ b/divelist.c @@ -19,6 +19,7 @@ enum { DIVE_DEPTH, /* int: dive->maxdepth in mm */ DIVE_DURATIONSTR, /* "47" in minutes */ DIVE_DURATION, /* int: in seconds */ + DIVE_LOCATION, /* "47" in minutes */ DIVE_TEMPSTR, /* "78" in fahrenheit or whatever */ DIVE_TEMP, /* int: in mkelvin */ DIVE_NITROXSTR, /* "32.5" in percent */ @@ -106,7 +107,7 @@ static void get_depth(struct dive *dive, int *val, char **str) return; } len = snprintf(buffer, sizeof(buffer), - "%d", integer); + "%d", integer); if (frac >= 0) len += snprintf(buffer+len, sizeof(buffer)-len, ".%d", frac); @@ -123,6 +124,14 @@ static void get_duration(struct dive *dive, int *val, char **str) *str = strdup(buffer); } +static void get_location(struct dive *dive, char **str) +{ + char buffer[16]; + + snprintf(buffer, sizeof(buffer), "%s", dive->location); + *str = strdup(buffer); +} + static void get_temp(struct dive *dive, int *val, char **str) { int value = dive->watertemp.mkelvin; @@ -160,10 +169,67 @@ static void get_nitrox(struct dive *dive, int *val, char **str) } } +/* + * Return air usage (in liters). + */ +static double calculate_airuse(struct dive *dive) +{ + double airuse = 0; + int i; + + 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, @@ -175,6 +241,7 @@ static gboolean set_one_dive(GtkTreeModel *model, 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); @@ -185,6 +252,7 @@ static gboolean set_one_dive(GtkTreeModel *model, 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); @@ -197,12 +265,13 @@ static gboolean set_one_dive(GtkTreeModel *model, 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_NITROX, sac, + DIVE_SAC, sac, -1); return FALSE; @@ -246,6 +315,7 @@ static void fill_dive_list(struct DiveList *dive_list) DIVE_DEPTH, dive->maxdepth, DIVE_DURATIONSTR, "duration", DIVE_DURATION, dive->duration.seconds, + DIVE_LOCATION, "location", DIVE_TEMPSTR, "temp", DIVE_TEMP, dive->watertemp.mkelvin, DIVE_NITROXSTR, "21.0", @@ -275,8 +345,9 @@ struct DiveList dive_list_create(void) dive_list.model = gtk_list_store_new(DIVELIST_COLUMNS, G_TYPE_INT, /* index */ G_TYPE_STRING, G_TYPE_INT, /* Date */ - G_TYPE_STRING, G_TYPE_INT, /* Depth */ - G_TYPE_STRING, G_TYPE_INT, /* Duration */ + G_TYPE_STRING, G_TYPE_INT, /* Depth */ + G_TYPE_STRING, G_TYPE_INT, /* Duration */ + G_TYPE_STRING, /* Location */ G_TYPE_STRING, G_TYPE_INT, /* Temperature */ G_TYPE_STRING, G_TYPE_INT, /* Nitrox */ G_TYPE_STRING, G_TYPE_INT /* SAC */ @@ -316,6 +387,14 @@ struct DiveList dive_list_create(void) gtk_object_set(GTK_OBJECT(renderer), "alignment", PANGO_ALIGN_RIGHT, NULL); gtk_cell_renderer_set_alignment(GTK_CELL_RENDERER(renderer), 1.0, 0.5); + renderer = gtk_cell_renderer_text_new(); + dive_list.location = col = gtk_tree_view_column_new(); + gtk_tree_view_column_set_title(col, "Location"); + gtk_tree_view_column_set_sort_column_id(col, DIVE_LOCATION); + gtk_tree_view_column_pack_start(col, renderer, FALSE); + gtk_tree_view_column_add_attribute(col, renderer, "text", DIVE_LOCATION); + gtk_tree_view_append_column(GTK_TREE_VIEW(dive_list.tree_view), col); + renderer = gtk_cell_renderer_text_new(); dive_list.temperature = col = gtk_tree_view_column_new(); gtk_tree_view_column_set_title(col, "deg"); @@ -357,7 +436,7 @@ struct DiveList dive_list_create(void) dive_list.container_widget = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dive_list.container_widget), - GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_container_add(GTK_CONTAINER(dive_list.container_widget), dive_list.tree_view); return dive_list;