Hi,

On 26.02.2016, at 13:45, Robert Helling <[email protected]> wrote:

My question is: what is the semantic of the salinity in libdivecomputer, is it “just the mass of salt per liter of water” (in which case we would need to change the translation in subsurface) or is it like in subsurface the density of water (i.e. mass of water plus salt per liter)? In the latter case, there needs to be a conversion when reading out this oceanic computer.


here is a patch that fixes this problem: If an (imported) salinity is non-zero but way to small, we treat it as an actual salinity, i.e. amount of salt per liter and add the density of water to it.

From 490b57589ca70f038bf84b3bf700fcf471d114e2 Mon Sep 17 00:00:00 2001
From: "Robert C. Helling" <[email protected]>
Date: Fri, 26 Feb 2016 15:16:36 +0100
Subject: [PATCH] If salinity is not density, add density of fresh water
To: [email protected]

There was a reported case of an import of a dive that gave a salinity of
35g/l. This is an actual salinity (an amount of salt in the water) but
for subsurface the salinity is actually the density of the water. So for
too small values of the salinity add the density of fresh water.

Signed-off-by: Robert C. Helling <[email protected]>
---
 subsurface-core/dive.c | 2 ++
 subsurface-core/dive.h | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/subsurface-core/dive.c b/subsurface-core/dive.c
index fafb1db..4256871 100644
--- a/subsurface-core/dive.c
+++ b/subsurface-core/dive.c
@@ -1142,6 +1142,8 @@ static void fixup_water_salinity(struct dive *dive)
 
        for_each_dc (dive, dc) {
                if (dc->salinity) {
+                       if (dc->salinity < 500)
+                               dc->salinity += FRESHWATER_SALINITY;
                        sum += dc->salinity;
                        nr++;
                }
diff --git a/subsurface-core/dive.h b/subsurface-core/dive.h
index 3ad2108..dd0f1e1 100644
--- a/subsurface-core/dive.h
+++ b/subsurface-core/dive.h
@@ -409,6 +409,8 @@ static inline int calculate_depth_to_mbar(int depth, 
pressure_t surface_pressure
                mbar = SURFACE_PRESSURE;
        if (!salinity)
                salinity = SEAWATER_SALINITY;
+       if (salinity < 500)
+               salinity += FRESHWATER_SALINITY;
        specific_weight = salinity / 10000.0 * 0.981;
        mbar += rint(depth / 10.0 * specific_weight);
        return mbar;
-- 
2.5.4 (Apple Git-61)


Best
Robert

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to