From: Dirk Hohndel Date: Wed, 2 Nov 2011 04:12:21 +0000 (-0700) Subject: Even more places with pressure and volume conversions X-Git-Url: http://git.tdb.fi/?p=ext%2Fsubsurface.git;a=commitdiff_plain;h=485b02937d8ca1f9a9043c89e74a3d2f15d6426b Even more places with pressure and volume conversions Amazing at how many spots we are re-implementing the wheel. Signed-off-by: Dirk Hohndel --- diff --git a/dive.h b/dive.h index 783d640..b5a42d3 100644 --- a/dive.h +++ b/dive.h @@ -91,17 +91,12 @@ extern double get_depth_units(unsigned int mm, int *frac, const char **units); extern double get_volume_units(unsigned int mm, int *frac, const char **units); extern double get_temp_units(unsigned int mm, const char **units); -static inline double bar_to_atm(double bar) -{ - return bar / 1.01325; -} - static inline double ml_to_cuft(int ml) { return ml / 28316.8466; } -static inline double cuft_to_ml(double cuft) +static inline double cuft_to_l(double cuft) { return cuft * 28.3168466; } @@ -156,6 +151,11 @@ static inline int to_PSI(pressure_t pressure) return pressure.mbar * 0.0145037738 + 0.5; } +static inline double bar_to_atm(double bar) +{ + return bar / 1.01325; +} + static inline double to_ATM(pressure_t pressure) { return pressure.mbar / 1013.25; diff --git a/divelist.c b/divelist.c index acaf08d..2d04eb5 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); @@ -307,7 +306,7 @@ static double calculate_airuse(struct dive *dive) if (!size) continue; - kilo_atm = (cyl->start.mbar - cyl->end.mbar) / 1013250.0; + kilo_atm = (to_ATM(cyl->start) - to_ATM(cyl->end)) / 1000.0; /* Liters of air at 1 atm == milliliters at 1k atm*/ airuse += kilo_atm * size; diff --git a/equipment.c b/equipment.c index 64a05d5..c7a683b 100644 --- a/equipment.c +++ b/equipment.c @@ -360,7 +360,7 @@ static void fill_cylinder_info(struct cylinder_widget *cylinder, cylinder_t *cyl } if (pressure && output_units.volume == CUFT) { - volume = cuft_to_ml(volume); + volume = cuft_to_l(volume); volume /= bar_to_atm(pressure); } @@ -464,7 +464,7 @@ static void fill_tank_list(GtkListStore *store) /* Is it in cuft and psi? */ if (psi) { double bar = psi_to_bar(psi); - double airvolume = cuft_to_ml(size); + double airvolume = cuft_to_l(size) * 1000.0; double atm = bar_to_atm(bar); ml = airvolume / atm + 0.5; diff --git a/parse-xml.c b/parse-xml.c index c44b6f6..5eabc35 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -425,7 +425,7 @@ static void water_pressure(char *buffer, void *_depth) if (!val.fp) break; /* cbar to atm */ - atm = (val.fp / 100) / 1.01325; + atm = bar_to_atm(val.fp * 10); /* * atm to cm. Why not mm? The precision just isn't * there. @@ -1122,9 +1122,9 @@ static void match_standard_cylinder(cylinder_type_t *type) if (type->description) return; - cuft = type->size.mliter / 28317.0; + cuft = ml_to_cuft(type->size.mliter); cuft *= to_ATM(type->workingpressure); - psi = type->workingpressure.mbar / 68.95; + psi = to_PSI(type->workingpressure); switch (psi) { case 2300 ... 2500: /* 2400 psi: LP tank */ @@ -1177,7 +1177,8 @@ static void sanitize_cylinder_type(cylinder_type_t *type) return; if (input_units.volume == CUFT || import_source == SUUNTO) { - volume_of_air = type->size.mliter * 28.317; /* milli-cu ft to milliliter */ + /* confusing - we don't really start from ml but millicuft !*/ + volume_of_air = cuft_to_l(type->size.mliter); atm = to_ATM(type->workingpressure); /* working pressure in atm */ volume = volume_of_air / atm; /* milliliters at 1 atm: "true size" */ type->size.mliter = volume + 0.5; diff --git a/uemis.c b/uemis.c index f55407b..86b1860 100644 --- a/uemis.c +++ b/uemis.c @@ -86,7 +86,7 @@ static int pressure_to_depth(uint16_t value) { double atm, cm; - atm = (value / 100.0) / 1.01325; + atm = bar_to_atm(value / 100.0); cm = 100 * atm + 0.5; return( (cm > 0) ? 10 * (long)cm : 0); }