[PATCH] Don't calculate SAC-rates for negative pressure changes

Linus Torvalds torvalds at linux-foundation.org
Sat Apr 26 11:05:44 PDT 2014


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Sat, 26 Apr 2014 10:55:17 -0700
Subject: [PATCH] Don't calculate SAC-rates for negative pressure changes

They happen - maybe the cylinder actually warmed up, or maybe the user
entered just a ending pressure without a starting pressure.  Regardless,
just ignore cylinder pressure changes that go up.

Also ignore cylinders with a zero ending pressure: that's really a
*missing* pressure rather than an actual zero pressure.  As Dirk says,
the scuba regulators don't even work without a healthy positive pressure
differential, so even when you breathe down a tank to "empty", it won't
be at zero pressure (this is true even with gauge pressure, where zero
means "atmospheric pressure").

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---

The whole "local sac rate" calculation in the profile might get confused 
if there are actually rising cylinder pressures in the samples, but this 
won't make the situation any worse than it is right now. That local sac 
rate calculation is kind of iffy anyway.

 divelist.c   | 2 ++
 profile.c    | 2 +-
 statistics.c | 2 +-
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/divelist.c b/divelist.c
index 17f24ef7e539..f0a66b45646b 100644
--- a/divelist.c
+++ b/divelist.c
@@ -311,6 +311,8 @@ static double calculate_airuse(struct dive *dive)
 
 		start = cyl->start.mbar ? cyl->start : cyl->sample_start;
 		end = cyl->end.mbar ? cyl->end : cyl->sample_end;
+		if (!end.mbar || start.mbar <= end.mbar)
+			continue;
 
 		airuse += gas_volume(cyl, start) - gas_volume(cyl, end);
 	}
diff --git a/profile.c b/profile.c
index 4d5e05aa4524..f5d287bfd5c2 100644
--- a/profile.c
+++ b/profile.c
@@ -157,7 +157,7 @@ static int get_local_sac(struct plot_data *entry1, struct plot_data *entry2, str
 		return 0;
 	a.mbar = GET_PRESSURE(entry1);
 	b.mbar = GET_PRESSURE(entry2);
-	if (!a.mbar || !b.mbar)
+	if (!b.mbar || a.mbar <= b.mbar)
 		return 0;
 
 	/* Mean pressure in ATM */
diff --git a/statistics.c b/statistics.c
index 1610a1a8ace0..ad5a95d06c3d 100644
--- a/statistics.c
+++ b/statistics.c
@@ -329,7 +329,7 @@ void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS])
 
 		start = cyl->start.mbar ? cyl->start : cyl->sample_start;
 		end = cyl->end.mbar ? cyl->end : cyl->sample_end;
-		if (start.mbar && end.mbar)
+		if (end.mbar && start.mbar > end.mbar)
 			gases[idx].mliter = gas_volume(cyl, start) - gas_volume(cyl, end);
 	}
 }
-- 
2.0.0.rc1



More information about the subsurface mailing list