diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2011-09-22 13:45:53 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2011-09-22 16:26:38 -0700 |
commit | a93641b7222e767d6a3a1be598cd8099d8517059 (patch) | |
tree | fc6893f49513b99d221f2e0fc23f46a58c743dd7 /divelist.c | |
parent | 15463fdeb26ed1b5fdff62e4721a6dbbc507cefc (diff) | |
download | subsurface-a93641b7222e767d6a3a1be598cd8099d8517059.tar.gz |
Calculate OTUs for every dive
The calculation assumes that the cylinderindex in each sample tells us
which PO2 the dive was breathing at that time. This needs to be verified
with dives where there is an actual gas switch.
No idea where to display them, yet. Far fewer people will care about this
than care about SAC - does this still rate a spot in the dive_list?
I guess I could make it part of the dive_info - but it's not editable.
It doesn't seem to fit with the equipment page (even though this is the
one editable field that is related - nitrox %)
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r-- | divelist.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/divelist.c b/divelist.c index 51646c460..c2194bbec 100644 --- a/divelist.c +++ b/divelist.c @@ -14,6 +14,7 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#include <math.h> #include "divelist.h" #include "dive.h" @@ -222,6 +223,25 @@ static void sac_data_func(GtkTreeViewColumn *col, g_object_set(renderer, "text", buffer, NULL); } +/* calculate OTU for a dive */ +static double calculate_otu(struct dive *dive) +{ + int i; + double otu = 0.0; + + for (i = 1; i < dive->samples; i++) { + int t; + double po2; + struct sample *sample = dive->sample + i; + struct sample *psample = sample - 1; + t = sample->time.seconds - psample->time.seconds; + po2 = dive->cylinder[sample->cylinderindex].gasmix.o2.permille / 1000.0 * + (sample->depth.mm + 10000) / 10000.0; + if (po2 >= 0.5) + otu += pow(po2 - 0.5, 0.83) * t / 30.0; + } + return otu; +} /* * Return air usage (in liters). */ @@ -389,6 +409,7 @@ static void fill_dive_list(void) for (i = 0; i < dive_table.nr; i++) { struct dive *dive = dive_table.dives[i]; + dive->otu = calculate_otu(dive); gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, DIVE_INDEX, i, |