summaryrefslogtreecommitdiffstats
path: root/deco.c
AgeCommit message (Collapse)Author
2013-02-03Fixing SP handling in planner, adding eventGravatar Jan Schubert
This moves some double/floating handling for po2 to plain integer. There are still non int values around (also for phe and po2) in the plot area. Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-30Massive cleanupGravatar Dirk Hohndel
Mostly coding style and whitespace changes plus making lots of functions static that have no need to be extern. This also helped find a bit of code that is actually no longer used. This should have absolutely no functional impact - all changes should be purely cosmetic. But it removes a bunch of lines of code and makes the rest easier to read. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-25Removed unused structure definition in deco.cGravatar Dirk Hohndel
Leftover from the initial implementation. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-23Move more dive computer filled data to the divecomputer structureGravatar Linus Torvalds
This moves the fields 'duration', 'surfacetime', 'maxdepth', 'meandepth', 'airtemp', 'watertemp', 'salinity' and 'surface_pressure' to the per-divecomputer data structure. They are filled in by the dive computer, and normally not edited. NOTE! All actual *use* of this data was then changed from dive->field to dive->dc.field programmatically with a shell-script and sed, and the result then edited for details. So while the XML save and restore code has been updated, all the displaying etc will currently always just show the first dive computer entry. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-14Centralising and redefining values as integersGravatar Jan Schubert
This patch centralizes the definition for surface pressure, oxygen in air, (re)defines all such values as plain integers and adapts calculations. It eliminates 11 (!) occurrences of definitions for surface pressure and also a few for oxygen in air. It also rewrites the calculation for EAD, END and EADD using the new definitons, harmonizing it for OC and CC and fixes a bug for EADD OC calculation. And finally it removes the unneeded variable entry_ead in gtk-gui.c. Jan Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-13Add support for MOD, EAD, AND and EADD in the mouse over displayGravatar Dirk Hohndel
- MOD: Maximum Operation Depth based on a configurable limit - EAD: Equivalent Air Depth considering N2 and (!) O2 narcotic - END: Equivalent Nitrogen (Narcotic) Depth considering just N2 narcotic (ignoring O2) - EADD: Equivalent Air Density Depth Please note that some people and even diving organisations have opposite definitions for EAD and END. Considering A stands for Air, lets choose the above. And considering N for Nitrogen it also fits in this scheme. This patch moves N2_IN_AIR from deco.c to dive.h as this is already used in several places and might be useful for future use also. It also respecifies N2_IN_AIR to a more correct value of 78,084%, the former one also included all other gases than oxygen appearing in air. If someone needs to use the former value it would be more correct to use 1-O2_IN_AIR instead. Signed-off-by: Jan Schubert / Jan.Schubert@GMX.li Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-10Adjust GFlow to apply at deepest ceiling instead of at max depthGravatar Robert C. Helling
This moves the point where GF_low applies up which implies that at all shallower depth (i.e. during deco) a lower GF results which makes the deco longer compared to the previous implementation. Of course, "GF_low" applies at first deco stop is a bit tricky since the depth of the first deco stop again depends on GF_low, i.e. there is another equation to solve. You can do this by inverting the equation for the ambient pressure and use GF_low as the gradient factor. This yields amb = (b * M_value_corrected - GF_low * a * b) / ((1-b) * GF_low + b) Signed-off-by: Robert C. Helling helling@atdotde.de Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Undo unintentional change to deco.cGravatar Dirk Hohndel
In commit d163a68ac69e "Clean up the rewritten deco.c" I apparently made one more change than I intended - I changed the last deco stop back to 3m instead of allowing the smooth mode to go all the way back to 0 without any discrete steps. This fixes that mistake. Reported-by: Robert C. Helling <helling@lmu.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Minor cleanupsGravatar Dirk Hohndel
Coding style in deco.c. Unneccessary if clause in profile.c (the loop starts with i = 1) Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Clean up the rewritten deco.cGravatar Dirk Hohndel
In commit a7902f279a57 "Rewrite of the deco code" Robert kept the old code that he replaced around; I removed all that as it's in the git history if we ever need to look at it again but doesn't really help us in the file as it is. I also removed constants, variables and config parameters that aren't used in the new implementation and did some coding style / formatting changes to make deco.c more consistent with the rest of Subsurface. I also updated the comments at the top of the file to reflect reality. I did one change that actually affects the code. In the explanation of his changes Robert said that gf_low_pressure_this_dive is initialized to the exquivalent of 20m, yet his code added the surface pressure twice. I decided to change the default config value from 3 (bar) to 2 so that this indeed reflects (about) 20m (as in the code below surface_pressure is added to this value). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Rewrite of the deco codeGravatar Robert C. Helling
o) Instead of using gradient factors as means of comparison, I now use pressure (as in: maximal ambient pressure). o) tissue_tolerance_calc() now computes the maximal ambient pressure now respecting gradient factors. For this, it needs to know about the surface pressure (as refernce for GF_high), thus gets *dive as an argument. It is called from add_segment() which this also needs *dive as an additional argument. o) This implies deco_allowed_depth is now mainly a ambient-pressure to depth conversion with decorations to avoid negative depth (i.e. no deco obliation), implementation of quantization (!smooth => multiples of 3m) and explicit setting of last deco depth (e.g. 6m for O2 deco). o) gf_low_pressure_this_dive (slight change of name), the max depth in pressure units is updated in add_segment. I set the minimal value in buehlmann_config to the equivalent of 20m as otherwise good values of GF_low add a lot of deco to shallow dives which do not need deep stops in the first place. o) The bogus loop is gone as well as actual_gradient_limit() and gradient_factor_calculation() and large parts of deco_allowed_depth() although I did not delete the code but put it in comments. o) The meat is in the formula in lines 147-154 of deco.c. Here is the rationale: Without gradient factors, the M-value (i.e the maximal tissue pressure) at a given depth is given by ambient_pressure / buehlmann_b + a. According to "Clearing Up The Confusion About "Deep Stops" by Erik C. Baker (as found via google) the effect of the gradient factors is no replace this by a reduced affine relation (i.e. another line) such that at the surface the difference between M-value and ambient pressure is reduced by a factor GF_high and at the maximal depth by a factor GF_low. That is, we are looking for parameters alpha and beta such that alpha surface + beta = surface + gf_high * (surface/b + a - surface) and alpha max_p + beta = max_p + gf_low * (max_p/b + a - max_p) This can be solved for alpha and beta and then inverted to obtain the max ambient pressure given tissue loadings. The result is the above mentioned formula. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07Add bailout code to prevent infinite loop in deco calculationGravatar Dirk Hohndel
This appears to happen if we have impossible dive sequences in the dive_list (i.e., merging XML files from two different divers with overlapping trips). We need to fix the underlying cause for this issue (i.e., only pick the 'right' dives to calculate the residual tissue saturation), but at least this code prevents the hang in an infinite loop. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06Add the ability to cache our deco stateGravatar Dirk Hohndel
We kept reduing all the deco calculations, including the previous dives (if any) for each segment we add to the dive plan. This simply remembers the last stage and then just adds to that. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-05Fix bug in smooth ceiling modeGravatar Dirk Hohndel
The ceiling calculations for the gradient factors still had a 3m increment hardcoded. This is now also conditional on the smooth parameter. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-04Correctly handle air in the deco codeGravatar Dirk Hohndel
We mark air with o2.permille = 0. But it's actually 20.9% O2. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-04Fix deco calculations to correctly use GF values and add CC supportGravatar Dirk Hohndel
The old implementation was broken in several ways. For one thing the GF values are percentages, so they should normally be 0 < GF < 1 (well, some crazy people like to go above that). With this most of the Bühlmann config constants were wrong. Furthermore, after we adjust the pressure tolerance based on the gradient factors, we need to convert this back into a depth (instead of passing back the unmodified depth - oops). Finally, this commit adds closed circuit support to the deco calculations. Major progress and much more useful at this stage. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03Make GF values configurableGravatar Dirk Hohndel
There are a couple of issues with this commit: GtkEntry should emit the 'changed' signal when it is modified (so that changes in the preferences get applied right away) - but that doesn't appear to be working consistently. Also, this doesn't appear to affect the deco of any dives that I try it with. So my guess is something is wrong with the underlying deco algorithm. That's diappointing. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03Consider previous dives when calculating decoGravatar Dirk Hohndel
This also initializes the N2 tissue saturations to correct numbers (setting them to zero was clearly silly). With this commit we walk back in the dive_table until we find a surface intervall that's longer than 48h. Or a dive that comes after the last one we looked at; that would indicate that this is a divelist that contains dives from multiple divers or dives that for other reasons are not ordered. In a sane environment one would assume that the dives that need to be taken into account when doing deco calculations are organized as one trip in the XML file and so this logic should work. One major downside of the current implementation is that we recalculate everything whenever the plot_info is recreated - which happens quite frequently, for example when resizing the window or even when we go into loup mode. While this isn't all that compute intensive, this is an utter waste and we should at least cache the saturation inherited from previous dives (and clear that number when the selected dive changes). We don't want to cache all of it as the recreation of the plot_info may be triggered by the user changing equipment (and most importantly, gasmix) information. In that case the deco data for this dive does indeed have to be recreated. But without changing the current dive the saturation after the last surface intervall should stay the same. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03Use gradient factors in deco calculationGravatar Dirk Hohndel
Usually dive computers show the ceiling in terms of the next deco stop - and those are in 3m increments. This commit also adds the ability to chose either the typical 3m increments or the smooth ceiling that the Bühlmann algorithm actually calculates. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03First stab at deco calculationsGravatar Dirk Hohndel
This seems to give us roughly the right data but needs a lot more testing. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>