X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=divelist.c;h=bf853ec0e49fce534853c3b59e98abb0d9a314a1;hb=97a1dd68306de17aa73be092d2bcf174e8158f62;hp=acaf08d38a8e5ce29e26d95c932b7d9b43bd182d;hpb=b26ca781b87371e77b851298093b0a7136be64fa;p=ext%2Fsubsurface.git diff --git a/divelist.c b/divelist.c index acaf08d..bf853ec 100644 --- a/divelist.c +++ b/divelist.c @@ -223,7 +223,6 @@ static void sac_data_func(GtkTreeViewColumn *col, gpointer data) { int value; - const double liters_per_cuft = 28.317; const char *fmt; char buffer[16]; double sac; @@ -242,7 +241,7 @@ static void sac_data_func(GtkTreeViewColumn *col, break; case CUFT: fmt = "%4.2f"; - sac /= liters_per_cuft; + sac = ml_to_cuft(sac * 1000); break; } snprintf(buffer, sizeof(buffer), fmt, sac); @@ -300,6 +299,7 @@ static double calculate_airuse(struct dive *dive) int i; for (i = 0; i < MAX_CYLINDERS; i++) { + pressure_t start, end; cylinder_t *cyl = dive->cylinder + i; int size = cyl->type.size.mliter; double kilo_atm; @@ -307,7 +307,9 @@ static double calculate_airuse(struct dive *dive) if (!size) continue; - kilo_atm = (cyl->start.mbar - cyl->end.mbar) / 1013250.0; + start = cyl->start.mbar ? cyl->start : cyl->sample_start; + end = cyl->end.mbar ? cyl->end : cyl->sample_end; + kilo_atm = (to_ATM(start) - to_ATM(end)) / 1000.0; /* Liters of air at 1 atm == milliliters at 1k atm*/ airuse += kilo_atm * size; @@ -333,6 +335,14 @@ static int calculate_sac(struct dive *dive) return sac * 1000; } +void update_cylinder_related_info(struct dive *dive) +{ + if(dive != NULL) { + dive->sac = calculate_sac(dive); + dive->otu = calculate_otu(dive); + } +} + static void get_string(char **str, const char *s) { int len; @@ -450,8 +460,7 @@ static void fill_dive_list(void) for (i = 0; i < dive_table.nr; i++) { struct dive *dive = dive_table.dives[i]; - dive->otu = calculate_otu(dive); - dive->sac = calculate_sac(dive); + update_cylinder_related_info(dive); gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, DIVE_INDEX, i,