summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2014-02-11 13:08:29 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-02-11 14:05:54 -0800
commite58f54cac1d050c090bfa5427991ae440bc78495 (patch)
treed4379185e39721d46d61ca6136001941b980ef1a
parent92bbed3304afeb8e7ef6593f48eae982d799b5f1 (diff)
downloadsubsurface-e58f54cac1d050c090bfa5427991ae440bc78495.tar.gz
Fix ATM-vs-bar confusion
SAC should be calculated in relationship to surface pressure, not "1 bar". I also realize that we have a few other cases where we do the same mistake: the partial pressure calculations do things like po2 = o2 / 1000.0 * depth_to_mbar(sample->depth.mm, dive); which is wrong as well - the partial pressure is also relative to standard atmospheric pressures. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.h10
-rw-r--r--divelist.c6
-rw-r--r--profile.c2
-rw-r--r--qt-ui/maintab.cpp4
4 files changed, 16 insertions, 6 deletions
diff --git a/dive.h b/dive.h
index 7d0aaaee6..658b199fe 100644
--- a/dive.h
+++ b/dive.h
@@ -223,6 +223,11 @@ static inline double bar_to_atm(double bar)
return bar / SURFACE_PRESSURE * 1000;
}
+static inline double mbar_to_atm(int mbar)
+{
+ return (double) mbar / SURFACE_PRESSURE;
+}
+
/* Volume in mliter of a cylinder at pressure 'p' */
extern int gas_volume(cylinder_t *cyl, pressure_t p);
extern int wet_volume(double cuft, pressure_t p);
@@ -450,6 +455,11 @@ static inline int depth_to_mbar(int depth, struct dive *dive)
return calculate_depth_to_mbar(depth, dive->surface_pressure, dive->salinity);
}
+static inline double depth_to_atm(int depth, struct dive *dive)
+{
+ return mbar_to_atm(depth_to_mbar(depth, dive));
+}
+
/* for the inverse calculation we use just the relative pressure
* (that's the one that some dive computers like the Uemis Zurich
* provide - for the other models that do this libdivecomputer has to
diff --git a/divelist.c b/divelist.c
index b16c9e513..a9a2b451c 100644
--- a/divelist.c
+++ b/divelist.c
@@ -221,7 +221,7 @@ static int calculate_otu(struct dive *dive)
po2 = sample->po2;
} else {
int o2 = active_o2(dive, dc, sample->time);
- po2 = o2 / 1000.0 * depth_to_mbar(sample->depth.mm, dive);
+ po2 = o2 * depth_to_atm(sample->depth.mm, dive);
}
if (po2 >= 500)
otu += pow((po2 - 500) / 1000.0, 0.83) * t / 30.0;
@@ -285,7 +285,7 @@ static int calculate_cns(struct dive *dive)
po2 = sample->po2;
} else {
int o2 = active_o2(dive, dc, sample->time);
- po2 = o2 / 1000.0 * depth_to_mbar(sample->depth.mm, dive);
+ po2 = o2 / depth_to_atm(sample->depth.mm, dive);
}
/* Find what table-row we should calculate % for */
for (j = 1; j < sizeof(cns_table)/(sizeof(int) * 3); j++)
@@ -338,7 +338,7 @@ static int calculate_sac(struct dive *dive)
return 0;
/* Mean pressure in ATM (SAC calculations are in atm*l/min) */
- pressure = (double) depth_to_mbar(meandepth, dive) / SURFACE_PRESSURE;
+ pressure = depth_to_atm(meandepth, dive);
sac = airuse / pressure * 60 / duration;
/* milliliters per minute.. */
diff --git a/profile.c b/profile.c
index 14b76f70e..07328580f 100644
--- a/profile.c
+++ b/profile.c
@@ -226,7 +226,7 @@ static int get_local_sac(struct plot_data *entry1, struct plot_data *entry2, str
/* Mean pressure in ATM */
depth = (entry1->depth + entry2->depth) / 2;
- atm = (double) depth_to_mbar(depth, dive) / SURFACE_PRESSURE;
+ atm = depth_to_atm(depth, dive);
cyl = dive->cylinder + index;
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index bdaddb827..85cf1b192 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -475,7 +475,7 @@ void MainTab::updateDiveInfo(int dive)
volume_t sac;
QString SACs;
if (mean[0] && duration[0]) {
- sac.mliter = gases[0].mliter * 1000.0 / (depth_to_mbar(mean[0], d) * duration[0] / 60.0);
+ sac.mliter = gases[0].mliter / (depth_to_atm(mean[0], d) * duration[0] / 60.0);
SACs = get_volume_string(sac, true).append(tr("/min"));
} else {
SACs = QString(tr("unknown"));
@@ -483,7 +483,7 @@ void MainTab::updateDiveInfo(int dive)
for(int i=1; i < MAX_CYLINDERS && gases[i].mliter != 0; i++) {
volumes.append("\n" + get_volume_string(gases[i], true));
if (duration[i]) {
- sac.mliter = gases[i].mliter * 1000.0 / (depth_to_mbar(mean[i], d) * duration[i] / 60);
+ sac.mliter = gases[i].mliter / (depth_to_atm(mean[i], d) * duration[i] / 60);
SACs.append("\n" + get_volume_string(sac, true).append(tr("/min")));
} else {
SACs.append("\n");