From 33c34bfe13b312fcb41390b95d88c7756c97c6c1 Mon Sep 17 00:00:00 2001 From: Tim Segers Date: Fri, 30 Sep 2022 12:23:30 +0200 Subject: Add GF99 function --- deco.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'deco.c') diff --git a/deco.c b/deco.c index 66182d9..42d3776 100644 --- a/deco.c +++ b/deco.c @@ -241,6 +241,33 @@ double ceiling(const decostate_t *ds, double gf) return round_ceiling(ds, c); } +double gf99(const decostate_t *ds, double depth) +{ + double gf = 0; + + for (int i = 0; i < 16; i++) { + /* n2 a and b values */ + double an = ZHL16N[i].a[ALGO_VER]; + double bn = ZHL16N[i].b; + + /* he a and b values */ + double ah = ZHL16He[i].a; + double bh = ZHL16He[i].b; + + /* scale n2 and he values for a and b proportional to their pressure */ + double pn2 = ds->pn2[i]; + double phe = ds->phe[i]; + + double a = ((an * pn2) + (ah * phe)) / (pn2 + phe); + double b = ((bn * pn2) + (bh * phe)) / (pn2 + phe); + + /* update gf99 */ + gf = max(gf, (pn2 + phe - depth) / (a + depth / b - depth)); + } + + return gf * 100; +} + void init_tissues(decostate_t *ds) { const double pn2 = 0.79 * (SURFACE_PRESSURE - P_WV); -- cgit v1.2.3-70-g09d2