From 2064ce06cc02b6fc390fdf9bbe05fb60babc0d4b Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Tue, 23 Feb 2021 11:36:00 +0100 Subject: Fix pO2 for CCR at shallow depths Even when diving a CCR, the pO2 cannot exceed ambient pressure. This only makes a difference at shallow depths. Fix this in the calculation of OTUs and CNS. This affects some tests that now have slightly different CNS and OTU values. Suggested-by: Justin Ashworth Signed-off-by: Robert C. Helling --- core/divelist.c | 20 ++++++++++++-------- dives/TestDiveDM4.xml | 2 +- dives/TestDiveDM5.xml | 8 ++++---- dives/TestDiveDivelogsDE.xml | 2 +- dives/TestDiveSeabearHUDC.xml | 2 +- dives/TestDiveSeabearNewFormat.xml | 12 ++++++------ dives/mergedVyperOstc.xml | 8 ++++---- dives/test40-42.xml | 2 +- dives/test47+48.xml | 4 ++-- dives/test47.xml | 4 ++-- dives/test48+47.xml | 2 +- 11 files changed, 35 insertions(+), 31 deletions(-) diff --git a/core/divelist.c b/core/divelist.c index 526b4f0b7..a62245954 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -109,12 +109,14 @@ static int calculate_otu(const struct dive *dive) po2f = sample->o2sensor[0].mbar; // ... use data from the first o2 sensor } else { if (dc->divemode == CCR) { - po2i = psample->setpoint.mbar; // if CCR has no o2 sensors then use setpoint - po2f = sample->setpoint.mbar; + po2i = MIN((int) psample->setpoint.mbar, + depth_to_mbar(psample->depth.mm, dive)); // if CCR has no o2 sensors then use setpoint + po2f = MIN((int) sample->setpoint.mbar, + depth_to_mbar(sample->depth.mm, dive)); } else { // For OC and rebreather without o2 sensor/setpoint int o2 = active_o2(dive, dc, psample->time); // ... calculate po2 from depth and FiO2. - po2i = lrint(o2 * depth_to_atm(psample->depth.mm, dive)); // (initial) po2 at start of segment - po2f = lrint(o2 * depth_to_atm(sample->depth.mm, dive)); // (final) po2 at end of segment + po2i = lrint(o2 * depth_to_bar(psample->depth.mm, dive)); // (initial) po2 at start of segment + po2f = lrint(o2 * depth_to_bar(sample->depth.mm, dive)); // (final) po2 at end of segment } } if ((po2i > 500) || (po2f > 500)) { // If PO2 in segment is above 500 mbar then calculate otu @@ -164,14 +166,16 @@ static double calculate_cns_dive(const struct dive *dive) trueo2 = true; } if ((dc->divemode == CCR) && (!trueo2)) { - po2i = psample->setpoint.mbar; // if CCR has no o2 sensors then use setpoint - po2f = sample->setpoint.mbar; + po2i = MIN((int) psample->setpoint.mbar, + depth_to_mbar(psample->depth.mm, dive)); // if CCR has no o2 sensors then use setpoint + po2f = MIN((int) sample->setpoint.mbar, + depth_to_mbar(sample->depth.mm, dive)); trueo2 = true; } if (!trueo2) { int o2 = active_o2(dive, dc, psample->time); // For OC and rebreather without o2 sensor: - po2i = lrint(o2 * depth_to_atm(psample->depth.mm, dive)); // (initial) po2 at start of segment - po2f = lrint(o2 * depth_to_atm(sample->depth.mm, dive)); // (final) po2 at end of segment + po2i = lrint(o2 * depth_to_bar(psample->depth.mm, dive)); // (initial) po2 at start of segment + po2f = lrint(o2 * depth_to_bar(sample->depth.mm, dive)); // (final) po2 at end of segment } po2i = (po2i + po2f) / 2; // po2i now holds the mean po2 of initial and final po2 values of segment. /* Don't increase CNS when po2 below 500 matm */ diff --git a/dives/TestDiveDM4.xml b/dives/TestDiveDM4.xml index 053de2ea7..fd34100b2 100644 --- a/dives/TestDiveDM4.xml +++ b/dives/TestDiveDM4.xml @@ -5,7 +5,7 @@ - + Notes are here diff --git a/dives/TestDiveDM5.xml b/dives/TestDiveDM5.xml index c5eee2aaa..fdbcd6393 100644 --- a/dives/TestDiveDM5.xml +++ b/dives/TestDiveDM5.xml @@ -5,7 +5,7 @@ - + Notes are here @@ -194,7 +194,7 @@ - + Testing notes @@ -388,7 +388,7 @@ - + Dive notes @@ -597,7 +597,7 @@ - + Notes test diff --git a/dives/TestDiveDivelogsDE.xml b/dives/TestDiveDivelogsDE.xml index 960d53ef3..6817e1380 100644 --- a/dives/TestDiveDivelogsDE.xml +++ b/dives/TestDiveDivelogsDE.xml @@ -6,7 +6,7 @@ - + Linus Second deep dive Linus and I planned and executed - Alex just watching diff --git a/dives/TestDiveSeabearHUDC.xml b/dives/TestDiveSeabearHUDC.xml index f4c461697..c0ccce23e 100644 --- a/dives/TestDiveSeabearHUDC.xml +++ b/dives/TestDiveSeabearHUDC.xml @@ -4,7 +4,7 @@ - + diff --git a/dives/TestDiveSeabearNewFormat.xml b/dives/TestDiveSeabearNewFormat.xml index f5cea5026..36643540a 100644 --- a/dives/TestDiveSeabearNewFormat.xml +++ b/dives/TestDiveSeabearNewFormat.xml @@ -211,7 +211,7 @@ - + @@ -418,7 +418,7 @@ - + @@ -1351,7 +1351,7 @@ - + @@ -1973,7 +1973,7 @@ - + @@ -2180,7 +2180,7 @@ - + @@ -3113,7 +3113,7 @@ - + diff --git a/dives/mergedVyperOstc.xml b/dives/mergedVyperOstc.xml index a79bc0a3e..98f059c3a 100644 --- a/dives/mergedVyperOstc.xml +++ b/dives/mergedVyperOstc.xml @@ -6,7 +6,7 @@ - + @@ -103,7 +103,7 @@ - + @@ -194,7 +194,7 @@ - + @@ -420,7 +420,7 @@ - + diff --git a/dives/test40-42.xml b/dives/test40-42.xml index f591d8366..f7dc034e4 100644 --- a/dives/test40-42.xml +++ b/dives/test40-42.xml @@ -34,7 +34,7 @@ - + {\rtf1\ansi\ansicpg1252\deff0\deflang1035{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}} \viewkind4\uc1\pard\f0\fs17\par } diff --git a/dives/test47+48.xml b/dives/test47+48.xml index aa4c129c0..c88d1aeef 100644 --- a/dives/test47+48.xml +++ b/dives/test47+48.xml @@ -2,11 +2,11 @@ - + - + diff --git a/dives/test47.xml b/dives/test47.xml index 0b93f1142..1936d1c97 100644 --- a/dives/test47.xml +++ b/dives/test47.xml @@ -2,11 +2,11 @@ - + - + diff --git a/dives/test48+47.xml b/dives/test48+47.xml index 862d4765e..c88d1aeef 100644 --- a/dives/test48+47.xml +++ b/dives/test48+47.xml @@ -6,7 +6,7 @@ - + -- cgit v1.2.3-70-g09d2