summaryrefslogtreecommitdiffstats
path: root/dive.h
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-10 23:11:40 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-11 08:50:56 +0100
commite167108c76c4a74ab50561fd59b2158704767a75 (patch)
tree5a860e98e9420315b03ff1c2ff88d76e5cb0dc67 /dive.h
parentf53788e5e4066f0ef36041031de6bc2726274fc9 (diff)
downloadsubsurface-e167108c76c4a74ab50561fd59b2158704767a75.tar.gz
Add depth to mbar helper function
This ensures that we use consistent math to get the absolute pressure at a certain depth. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.h')
-rw-r--r--dive.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/dive.h b/dive.h
index 1e54e1273..dbb0d0bea 100644
--- a/dive.h
+++ b/dive.h
@@ -281,6 +281,20 @@ struct dive {
struct sample sample[];
};
+/* Pa = N/m^2 - so we determine the weight (in N) of the mass of 10m
+ * of water (and use standard salt water at 1.03kg per liter if we don't know salinity)
+ * and add that to the surface pressure (or to 1013 if that's unknown) */
+static inline int depth_to_mbar(int depth, struct dive *dive)
+{
+ double specific_weight = 1.03 * 0.981;
+ int surface_pressure = 1013;
+ if (dive->salinity)
+ specific_weight = dive->salinity / 10000.0 * 0.981;
+ if (dive->surface_pressure.mbar)
+ surface_pressure = dive->surface_pressure.mbar;
+ return depth / 10.0 * specific_weight + surface_pressure + 0.5;
+}
+
/* this is a global spot for a temporary dive structure that we use to
* be able to edit a dive without unintended side effects */
extern struct dive edit_dive;