mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Even more places with pressure and volume conversions
Amazing at how many spots we are re-implementing the wheel. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
5698057951
commit
485b02937d
5 changed files with 16 additions and 16 deletions
12
dive.h
12
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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
2
uemis.c
2
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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue