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_volume_units(unsigned int mm, int *frac, const char **units);
|
||||||
extern double get_temp_units(unsigned int mm, 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)
|
static inline double ml_to_cuft(int ml)
|
||||||
{
|
{
|
||||||
return ml / 28316.8466;
|
return ml / 28316.8466;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline double cuft_to_ml(double cuft)
|
static inline double cuft_to_l(double cuft)
|
||||||
{
|
{
|
||||||
return cuft * 28.3168466;
|
return cuft * 28.3168466;
|
||||||
}
|
}
|
||||||
|
@ -156,6 +151,11 @@ static inline int to_PSI(pressure_t pressure)
|
||||||
return pressure.mbar * 0.0145037738 + 0.5;
|
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)
|
static inline double to_ATM(pressure_t pressure)
|
||||||
{
|
{
|
||||||
return pressure.mbar / 1013.25;
|
return pressure.mbar / 1013.25;
|
||||||
|
|
|
@ -223,7 +223,6 @@ static void sac_data_func(GtkTreeViewColumn *col,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
const double liters_per_cuft = 28.317;
|
|
||||||
const char *fmt;
|
const char *fmt;
|
||||||
char buffer[16];
|
char buffer[16];
|
||||||
double sac;
|
double sac;
|
||||||
|
@ -242,7 +241,7 @@ static void sac_data_func(GtkTreeViewColumn *col,
|
||||||
break;
|
break;
|
||||||
case CUFT:
|
case CUFT:
|
||||||
fmt = "%4.2f";
|
fmt = "%4.2f";
|
||||||
sac /= liters_per_cuft;
|
sac = ml_to_cuft(sac * 1000);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
snprintf(buffer, sizeof(buffer), fmt, sac);
|
snprintf(buffer, sizeof(buffer), fmt, sac);
|
||||||
|
@ -307,7 +306,7 @@ static double calculate_airuse(struct dive *dive)
|
||||||
if (!size)
|
if (!size)
|
||||||
continue;
|
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*/
|
/* Liters of air at 1 atm == milliliters at 1k atm*/
|
||||||
airuse += kilo_atm * size;
|
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) {
|
if (pressure && output_units.volume == CUFT) {
|
||||||
volume = cuft_to_ml(volume);
|
volume = cuft_to_l(volume);
|
||||||
volume /= bar_to_atm(pressure);
|
volume /= bar_to_atm(pressure);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -464,7 +464,7 @@ static void fill_tank_list(GtkListStore *store)
|
||||||
/* Is it in cuft and psi? */
|
/* Is it in cuft and psi? */
|
||||||
if (psi) {
|
if (psi) {
|
||||||
double bar = psi_to_bar(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);
|
double atm = bar_to_atm(bar);
|
||||||
|
|
||||||
ml = airvolume / atm + 0.5;
|
ml = airvolume / atm + 0.5;
|
||||||
|
|
|
@ -425,7 +425,7 @@ static void water_pressure(char *buffer, void *_depth)
|
||||||
if (!val.fp)
|
if (!val.fp)
|
||||||
break;
|
break;
|
||||||
/* cbar to atm */
|
/* 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
|
* atm to cm. Why not mm? The precision just isn't
|
||||||
* there.
|
* there.
|
||||||
|
@ -1122,9 +1122,9 @@ static void match_standard_cylinder(cylinder_type_t *type)
|
||||||
if (type->description)
|
if (type->description)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cuft = type->size.mliter / 28317.0;
|
cuft = ml_to_cuft(type->size.mliter);
|
||||||
cuft *= to_ATM(type->workingpressure);
|
cuft *= to_ATM(type->workingpressure);
|
||||||
psi = type->workingpressure.mbar / 68.95;
|
psi = to_PSI(type->workingpressure);
|
||||||
|
|
||||||
switch (psi) {
|
switch (psi) {
|
||||||
case 2300 ... 2500: /* 2400 psi: LP tank */
|
case 2300 ... 2500: /* 2400 psi: LP tank */
|
||||||
|
@ -1177,7 +1177,8 @@ static void sanitize_cylinder_type(cylinder_type_t *type)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (input_units.volume == CUFT || import_source == SUUNTO) {
|
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 */
|
atm = to_ATM(type->workingpressure); /* working pressure in atm */
|
||||||
volume = volume_of_air / atm; /* milliliters at 1 atm: "true size" */
|
volume = volume_of_air / atm; /* milliliters at 1 atm: "true size" */
|
||||||
type->size.mliter = volume + 0.5;
|
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;
|
double atm, cm;
|
||||||
|
|
||||||
atm = (value / 100.0) / 1.01325;
|
atm = bar_to_atm(value / 100.0);
|
||||||
cm = 100 * atm + 0.5;
|
cm = 100 * atm + 0.5;
|
||||||
return( (cm > 0) ? 10 * (long)cm : 0);
|
return( (cm > 0) ? 10 * (long)cm : 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue