summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-09-21 12:12:54 -0700
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-09-21 12:12:54 -0700
commit515a9171523f7d8aa85f2caab262ba7d6320c33c (patch)
treed1f49227a67701bacbba0679839fcba0d7b8f9d0 /dive.c
parent184eecf7c0dbcbdecba097411828afaac30773aa (diff)
downloadsubsurface-515a9171523f7d8aa85f2caab262ba7d6320c33c.tar.gz
Add helper function for doing depth unit calculations
.. and use it for printing too. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/dive.c b/dive.c
index 1b906ee43..41bbabd69 100644
--- a/dive.c
+++ b/dive.c
@@ -5,6 +5,31 @@
#include "dive.h"
+double get_depth_units(unsigned int mm, int *frac, const char **units)
+{
+ int decimals;
+ double d;
+ const char *unit;
+
+ switch (output_units.length) {
+ case METERS:
+ d = mm / 1000.0;
+ unit = "m";
+ decimals = d < 20;
+ break;
+ case FEET:
+ d = mm_to_feet(mm);
+ unit = "ft";
+ decimals = 0;
+ break;
+ }
+ if (frac)
+ *frac = decimals;
+ if (units)
+ *units = unit;
+ return d;
+}
+
struct dive *alloc_dive(void)
{
const int initial_samples = 5;