Two patches:

1) CCR PATCH: PO2 calculations.

This patch takes the po2 calculations in calculate_gas_information()
and puts these in a separate function calc_po2(). This was suggested
by Robert Helling. Several variables are required to do this calcu-
lation, passed to the function as a pointer to a structure defined
in profile.h

Calculation of po2 in CCR dive logs, implemented in future patches,
will take place within calc_po2().

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

2) PATCH: Remove a debug #define

A #define that triggers debug output is removed from gaspressures.c.
This debug option pertains to output from CCR dive logs.

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


I hope the whitespace problem has now been sorted out.

Kind regards,
willemf

>From dae01b80ea87b0b0f0ca140393fc02d9b501ef1d Mon Sep 17 00:00:00 2001
From: willem ferguson <[email protected]>
Date: Sun, 14 Sep 2014 20:28:37 +0200
Subject: [PATCH] PATCH: Remove a debug #define

A #define that triggers debug output is removed from gaspressures.c

Signed-off-by: willem ferguson <[email protected]>
---
 gaspressures.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gaspressures.c b/gaspressures.c
index 3d29fc8..3155a90 100644
--- a/gaspressures.c
+++ b/gaspressures.c
@@ -21,7 +21,7 @@
 #include "display.h"
 #include "profile.h"
 #include "gaspressures.h"
-#define PRINT_PRESSURES_DEBUG 1
+
 static pr_track_t *pr_track_alloc(int start, int t_start)
 {
 	pr_track_t *pt = malloc(sizeof(pr_track_t));
-- 
1.9.1

>From 9d553beafcc43bcaa9fd7a6e7866a3f536aeea28 Mon Sep 17 00:00:00 2001
From: willem ferguson <[email protected]>
Date: Sun, 14 Sep 2014 20:15:38 +0200
Subject: [PATCH] CCR PATCH: PO2 calculations.

This patch takes the po2 calculations in calculate_gas_information()
and puts these in a separate function calc_po2(). This was suggested
by Robert Helling. Several variables are required to do this calcu-
lation, passed to the function as a pointer to a structure defined
in profile.h

Calculation of po2 in CCR dive logs, implemented in future patches,
will take place within  calc_po2().

Signed-off-by: willem ferguson <[email protected]>
---
 gaspressures.c |  2 +-
 profile.c      | 63 +++++++++++++++++++++++++++++++---------------------------
 profile.h      |  8 +++++++-
 3 files changed, 42 insertions(+), 31 deletions(-)

diff --git a/gaspressures.c b/gaspressures.c
index 3155a90..3d29fc8 100644
--- a/gaspressures.c
+++ b/gaspressures.c
@@ -21,7 +21,7 @@
 #include "display.h"
 #include "profile.h"
 #include "gaspressures.h"
-
+#define PRINT_PRESSURES_DEBUG 1
 static pr_track_t *pr_track_alloc(int start, int t_start)
 {
 	pr_track_t *pt = malloc(sizeof(pr_track_t));
diff --git a/profile.c b/profile.c
index 4700572..9694c86 100644
--- a/profile.c
+++ b/profile.c
@@ -804,37 +804,42 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru
 #endif
 }
 
+/* Calculate the oxygen partial pressure (po2) for a sample with no po2 value, or
+ * calculate a corrected po2.
+ * Parameters:	1) po2 value for the particular sample (this can be 0 if no po2 sensor is present).
+ *		2) pointer to a structure containg fo2, fhe and ambient pressure for that sample.
+ * Called by: calculate_gas_information_new().	*/
+static double calc_po2(double samplepo2, struct gas_record *gas_data)
+{
+	if (samplepo2) {
+		/* we have an O₂ partial pressure in the plot_data - so this
+		 * is likely a CCR dive... use that instead of the value
+		 * from the cylinder info */
+		if (samplepo2 >= gas_data->amb_pressure || gas_data->fo2 == 1000)
+			return(gas_data->amb_pressure);   // po2 cannot be > ambient_pressure
+	} else {
+		/* with no O₂ partial pressure in the plot_data,
+		 * calculate O₂ partial pressure using fo2 */
+		return(gas_data->amb_pressure * gas_data->fo2 / 1000.0);
+	}
+	return(samplepo2); // if 0 < samplepo2 < ambient_pressure, then return unmodified value
+}
+
 static void calculate_gas_information_new(struct dive *dive, struct plot_info *pi)
 {
 	int i;
-	double amb_pressure;
-
+	struct gas_record gas_storage;
+	struct gas_record *gas_data = &gas_storage; // A pointer is easier to pass to a function
 	for (i = 1; i < pi->nr; i++) {
-		int fo2, fhe;
 		struct plot_data *entry = pi->entry + i;
 		int cylinderindex = entry->cylinderindex;
 
-		amb_pressure = depth_to_mbar(entry->depth, dive) / 1000.0;
-		fo2 = get_o2(&dive->cylinder[cylinderindex].gasmix);
-		fhe = get_he(&dive->cylinder[cylinderindex].gasmix);
-
-		if (entry->po2) {
-			/* we have an O₂ partial pressure in the sample - so this
-			 * is likely a CC dive... use that instead of the value
-			 * from the cylinder info */
-			if (entry->po2 >= amb_pressure || fo2 == 1000) {
-				entry->po2 = amb_pressure;
-				entry->phe = 0;
-				entry->pn2 = 0;
-			} else {
-				entry->phe = (amb_pressure - entry->po2) * (double)fhe / (1000 - fo2);
-				entry->pn2 = amb_pressure - entry->po2 - entry->phe;
-			}
-		} else {
-			entry->po2 = fo2 / 1000.0 * amb_pressure;
-			entry->phe = fhe / 1000.0 * amb_pressure;
-			entry->pn2 = (1000 - fo2 - fhe) / 1000.0 * amb_pressure;
-		}
+		gas_data->amb_pressure = depth_to_mbar(entry->depth, dive) / 1000.0;
+		gas_data->fo2 = get_o2(&dive->cylinder[cylinderindex].gasmix);
+		gas_data->fhe = get_he(&dive->cylinder[cylinderindex].gasmix);
+		entry->po2 = calc_po2(entry->po2, gas_data);
+		entry->phe = (gas_data->amb_pressure - entry->po2) * (double)gas_data->fhe / (1000 - gas_data->fo2);
+		entry->pn2 = gas_data->amb_pressure - entry->po2 - entry->phe;
 
 		/* Calculate MOD, EAD, END and EADD based on partial pressures calculated before
 		 * so there is no difference in calculating between OC and CC
@@ -842,12 +847,12 @@ static void calculate_gas_information_new(struct dive *dive, struct plot_info *p
 		 * EAD just uses N₂ ("Air" for nitrox dives) */
 		pressure_t modpO2 = { .mbar = (int)(prefs.modpO2 * 1000) };
 		entry->mod = (double)gas_mod(&dive->cylinder[cylinderindex].gasmix, modpO2, 1).mm;
-		entry->end = (entry->depth + 10000) * (1000 - fhe) / 1000.0 - 10000;
-		entry->ead = (entry->depth + 10000) * (1000 - fo2 - fhe) / (double)N2_IN_AIR - 10000;
+		entry->end = (entry->depth + 10000) * (1000 - gas_data->fhe) / 1000.0 - 10000;
+		entry->ead = (entry->depth + 10000) * (1000 - gas_data->fo2 - gas_data->fhe) / (double)N2_IN_AIR - 10000;
 		entry->eadd = (entry->depth + 10000) *
-				      (entry->po2 / amb_pressure * O2_DENSITY +
-				       entry->pn2 / amb_pressure * N2_DENSITY +
-				       entry->phe / amb_pressure * HE_DENSITY) /
+				      (entry->po2 / gas_data->amb_pressure * O2_DENSITY +
+				       entry->pn2 / gas_data->amb_pressure * N2_DENSITY +
+				       entry->phe / gas_data->amb_pressure * HE_DENSITY) /
 				      (O2_IN_AIR * O2_DENSITY + N2_IN_AIR * N2_DENSITY) * 1000 - 10000;
 		if (entry->mod < 0)
 			entry->mod = 0;
diff --git a/profile.h b/profile.h
index 0a7abf5..5bcb20d 100644
--- a/profile.h
+++ b/profile.h
@@ -62,6 +62,12 @@ struct ev_select {
 	bool plot_ev;
 };
 
+struct gas_record {
+	double amb_pressure; // mbar
+	int fo2; // permille
+	int fhe; // permille
+};
+
 struct plot_info calculate_max_limits_new(struct dive *dive, struct divecomputer *dc);
 void compare_samples(struct plot_data *e1, struct plot_data *e2, char *buf, int bufsize, int sum);
 struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *dc, struct plot_info *pi);
@@ -81,7 +87,7 @@ void get_plot_details_new(struct plot_info *pi, int time, struct membuffer *);
 int get_maxtime(struct plot_info *pi);
 
 /* get the maximum depth to which we want to plot
- * take into account the additional verical space needed to plot
+ * take into account the additional vertical space needed to plot
  * partial pressure graphs */
 int get_maxdepth(struct plot_info *pi);
 
-- 
1.9.1

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

Reply via email to