Calculate correct nitrogen and helium gas pressures for CCR after
import from CSV (Version 2)

Currently the gas pressures stored in structures of pressure are
calculated using the gasmix composition of the currently selected
cylinder. But with CCR dives the default cylinder is the oxygen
cylinder (here, index 0). However, the gas pressures need to
be calculated using gasmix data from cylinder 1 (the diluent
cylinder). This patch allows setting the appropriate cylinder
for calculating the values in the structures of pressure. It
also allows for correctly calculating gas pressures for any
open circuit cylinders (e.g. bailout) that a CCR diver may
use. This is performed as follows:

1) Add two integer variables to the structure definition of dive:
   oxygen_cylinder_index
   diluent_cylinder_index

2) Specifically for imports of Poseidon dives, define these two variables
   within the structure of dive as:
   oxygen_cylinder_index=0
   diluent_cylinder_index=1

3) Where gas partial pressures are calculated, use the integer
   dive->diluent_cylinder_pressure to find the diluent gasmix.

This creates a reasonably flexible, non-hard-coded solution.

Signed-off-by: willem ferguson <[email protected]>

>From 1b7f11c4586539a3151e3cad6fb4906203df245c Mon Sep 17 00:00:00 2001
From: willem ferguson <[email protected]>
Date: Mon, 3 Nov 2014 16:42:32 +0200
Subject: [PATCH] Calculate correct nitrogen and helium gas pressures for CCR
 after import from CSV (Version 2)

Currently the gas pressures stored in structures of pressure are
calculated using the gasmix composition of the currently selected
cylinder. But with CCR dives the default cylinder is the oxygen
cylinder (cylinder index 0). However, the gas pressures need to
be calculated using gasmix data from cylinder 1 (the diluent
cylinder). This patch allows setting the appropriate cylinder
for calculating the values in the structures of pressure. It
also allows for correctly calculating gas pressures for any
open circuit cylinders (e.g. bailout) that a CCR diver may
use. This is performed as follows:

1) Add two integer variables to the structure definition of dive:
   oxygen_cylinder_index
   diluent_cylinder_index

2) For imports of Poseidon dives, define these two variables
   within the structure of dive as:
   oxygen_xylinder_index=0
   diluent_cylinder_index=1

3) Where gas partial pressures are calculated, use the integer
   diluent_cylinder_pressure to find the diluent gasmix.

Signed-off-by: willem ferguson <[email protected]>
---
 dive.h    | 2 ++
 file.c    | 2 ++
 profile.c | 5 ++++-
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/dive.h b/dive.h
index 6809d83..e600e28 100644
--- a/dive.h
+++ b/dive.h
@@ -319,6 +319,8 @@ struct dive {
 	struct divecomputer dc;
 	int id; // unique ID for this dive
 	struct picture *picture_list;
+	int oxygen_cylinder_index; // for CCR dives
+	int diluent_cylinder_index; // for CCR dives
 };
 
 /* when selectively copying dive information, which parts should be copied? */
diff --git a/file.c b/file.c
index bab7909..272ebea 100644
--- a/file.c
+++ b/file.c
@@ -473,6 +473,8 @@ int parse_txt_file(const char *filename, const char *csv)
 		dive->dc.deviceid = atoi(parse_mkvi_value(memtxt.buffer, "Rig Serial number"));
 		dive->dc.dctype = CCR;
 		dive->dc.no_o2sensors = 2;
+		dive->oxygen_cylinder_index = 0;
+		dive->diluent_cylinder_index = 1;
 
 		dive->cylinder[cur_cylinder_index].type.size.mliter = 3000;
 		dive->cylinder[cur_cylinder_index].type.workingpressure.mbar = 200000;
diff --git a/profile.c b/profile.c
index 4be3a5b..e97ea4c 100644
--- a/profile.c
+++ b/profile.c
@@ -901,7 +901,10 @@ static void calculate_gas_information_new(struct dive *dive, struct plot_info *p
 		fo2 = get_o2(&dive->cylinder[cylinderindex].gasmix);
 		fhe = get_he(&dive->cylinder[cylinderindex].gasmix);
 
-		fill_pressures(&entry->pressures, amb_pressure, &dive->cylinder[cylinderindex].gasmix, entry->pressures.o2);
+		if ((dive->dc.dctype == CCR) && (cylinderindex <= dive->diluent_cylinder_index))
+			fill_pressures(&entry->pressures, amb_pressure, &dive->cylinder[dive->diluent_cylinder_index].gasmix, entry->pressures.o2);
+		else
+			fill_pressures(&entry->pressures, amb_pressure, &dive->cylinder[cylinderindex].gasmix, entry->pressures.o2);
 
 		/* Calculate MOD, EAD, END and EADD based on partial pressures calculated before
 		 * so there is no difference in calculating between OC and CC
-- 
1.9.1

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

Reply via email to