]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Even more places with pressure and volume conversions
authorDirk Hohndel <dirk@hohndel.org>
Wed, 2 Nov 2011 04:12:21 +0000 (21:12 -0700)
committerDirk Hohndel <dirk@hohndel.org>
Wed, 2 Nov 2011 04:34:06 +0000 (21:34 -0700)
Amazing at how many spots we are re-implementing the wheel.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
dive.h
divelist.c
equipment.c
parse-xml.c
uemis.c

diff --git a/dive.h b/dive.h
index 783d640a08c4d8e298ecb5e3f349f58837acf859..b5a42d3e2f84b3eb36c695be93b4ea861488a86a 100644 (file)
--- 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;
index acaf08d38a8e5ce29e26d95c932b7d9b43bd182d..2d04eb5b09e4469f13ad5029b6838294497a6d2a 100644 (file)
@@ -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;
index 64a05d5b024d3500ffbc6ff666cd3726d3ce99aa..c7a683b898a9a391547219bda9c1bba717f4e921 100644 (file)
@@ -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;
index c44b6f6ae359c707de417fa4a54de4548bbfbff1..5eabc353c17c47e4e68db5e0db2ded912f2b1437 100644 (file)
@@ -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 f55407b4bc254ab0ee9a641b2b6075d996ce983e..86b186043486a001b56154b4064e2bdcff4516f7 100644 (file)
--- 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);
 }