[PATCH] centralised definition for surface pressure

Dirk Hohndel dirk at hohndel.org
Mon Jan 14 09:52:15 PST 2013


Jan Schubert <Jan.Schubert at doubleSlash.de> writes:

> This patch centralizes the definition for surface pressure by
> eliminating 11 (!) occurrences of definitions for surface pressure, feel
> free to find more :-).
> It also removes a few occurrences of definitions for oxygen in air.

I'm not surprised. Good idea to rationalize and centralize that.

> diff --git a/deco.c b/deco.c
> index 1a2d13a..111f27d 100644
> --- a/deco.c
> +++ b/deco.c
> @@ -134,7 +134,7 @@ static double tissue_tolerance_calc(const struct dive *dive)
>  double add_segment(double pressure, struct gasmix *gasmix, int period_in_seconds, double ccpo2, const struct dive *dive)
>  {
>  	int ci;
> -	int fo2 = gasmix->o2.permille ? gasmix->o2.permille : 209;
> +	int fo2 = gasmix->o2.permille ? gasmix->o2.permille : AIR_PERMILLE;
>  	double ppn2 = (pressure - WV_PRESSURE) * (1000 - fo2 - gasmix->he.permille) / 1000.0;
>  	double pphe = (pressure - WV_PRESSURE) * gasmix->he.permille / 1000.0;
>  
> diff --git a/dive.c b/dive.c
> index 4fc6f75..59d0eb2 100644
> --- a/dive.c
> +++ b/dive.c
> @@ -269,8 +269,8 @@ static void sanitize_gasmix(struct gasmix *mix)
>  	if (!he) {
>  		if (!o2)
>  			return;
> -		/* 20.9% or 21% O2 is just air */
> -		if (o2 >= 209 && o2 <= 210) {
> +		/* 20.8% to 21% O2 is just air */
> +		if (o2 >= (AIR_PERMILLE - 1) && o2 <= (AIR_PERMILLE + 1)) {
>  			mix->o2.permille = 0;
>  			return;
>  		}
> diff --git a/dive.h b/dive.h
> index c53e194..e182525 100644
> --- a/dive.h
> +++ b/dive.h
> @@ -11,11 +11,13 @@
>  #include <libxml/tree.h>
>  #include <openssl/sha.h>
>  
> -#define O2_IN_AIR 0.20942
> -#define N2_IN_AIR 0.78084 // has been set to 0.7902 before to ignore other components of air
> -#define O2_DENSITY 1.429  // Gramm/Liter
> -#define N2_DENSITY 1.251
> -#define HE_DENSITY 0.1786
> +#define O2_IN_AIR        0.20942
> +#define N2_IN_AIR        0.78084 // 0.7902 before
> +#define O2_DENSITY       1.429   // Gramm/Liter
> +#define N2_DENSITY       1.251
> +#define HE_DENSITY       0.1786
> +#define SURFACE_PRESSURE 1.01325 // mbar
> +#define AIR_PERMILLE     O2_IN_AIR * 1000

Now this is interesting. I'm not sure this will bite us anywhere in the
code, but if you think about it, the old definition of 209 was an int,
but 0.20942 * 1000 is actually a float. So this could change calculations.
So while I like the intent of making this simpler, I think I'd feel
better if AIR_PERMILLE was defined to be 209 in stead of 0.20942 * 1000

The same now happens with SURFACE_PRESSURE. Multiplying the 1.01325 with
1000 also creates a float, not an int.

I glanced through the code - it seems harmless. It just makes me
nervous.

> @@ -909,7 +909,8 @@ void input_plan()
>  {
>  	GtkWidget *planner, *content, *vbox, *hbox, *outervbox, *add_row, *deltat, *label, *surfpres;
>  	char starttimebuf[64] = "+60:00";
> -	char pressurebuf[64] = "1013";
> +	char pressurebuf[64];
> +	sprintf(pressurebuf, "%d", (int)(SURFACE_PRESSURE * 1000));

don't like this one...


/D


More information about the subsurface mailing list