summaryrefslogtreecommitdiffstats
path: root/dive.h
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2013-02-09 11:15:18 +1100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-08 18:22:30 -0800
commit926fcef2a1e83b58c37c948a3f1a904aa0be0d0e (patch)
tree7f759284b78c77beecb2a11bae25649122f2690a /dive.h
parentb286ea638c8ce468cf9c1a1b5037867acb5d6fe4 (diff)
downloadsubsurface-926fcef2a1e83b58c37c948a3f1a904aa0be0d0e.tar.gz
Do more dive fixup for each dive computer
In commit b6c9301e5847 ("Move more dive computer filled data to the divecomputer structure") we moved the fields that get filled in by the dive computers to be per-divecomputer data structures. This patch re-creates some of those fields back in the "struct dive", but now the fields are initialized to be a reasonable average from the dive computer data. We already did some of this for the temperature min/max fields for the statistics, so this just continues that trend. The goal is to make it easy to look at "dive values" without having to iterate over dive computers every time you do. Just do it once in "fixup_dive()" instead. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.h')
-rw-r--r--dive.h46
1 files changed, 34 insertions, 12 deletions
diff --git a/dive.h b/dive.h
index ddb9327c6..87c30733d 100644
--- a/dive.h
+++ b/dive.h
@@ -20,6 +20,10 @@
#define SURFACE_PRESSURE_STRING "1013"
#define ZERO_C_IN_MKELVIN 273150 // mKelvin
+/* Salinity is expressed in weight in grams per 10l */
+#define SEAWATER_SALINITY 10300
+#define FRESHWATER_SALINITY 10000
+
/*
* Some silly typedefs to make our units very explicit.
@@ -314,9 +318,12 @@ struct dive {
weightsystem_t weightsystem[MAX_WEIGHTSYSTEMS];
char *suit;
int sac, otu, cns, maxcns;
+
+ /* Calculated based on dive computer data */
temperature_t mintemp, maxtemp;
+ pressure_t surface_pressure;
+ int salinity; // kg per 10000 l
- /* Eventually we'll do multiple dive computers */
struct divecomputer dc;
};
@@ -333,22 +340,34 @@ static inline void copy_gps_location(struct dive *from, struct dive *to)
}
}
-extern int get_surface_pressure_in_mbar(const struct dive *dive, gboolean non_null);
+static inline int get_surface_pressure_in_mbar(const struct dive *dive, gboolean non_null)
+{
+ int mbar = dive->surface_pressure.mbar;
+ if (!mbar && non_null)
+ mbar = SURFACE_PRESSURE;
+ return mbar;
+}
/* Pa = N/m^2 - so we determine the weight (in N) of the mass of 10m
* of water (and use standard salt water at 1.03kg per liter if we don't know salinity)
* and add that to the surface pressure (or to 1013 if that's unknown) */
-static inline int depth_to_mbar(int depth, struct dive *dive, struct divecomputer *dc)
+static inline int calculate_depth_to_mbar(int depth, pressure_t surface_pressure, int salinity)
{
- double specific_weight = 1.03 * 0.981;
- int surface_pressure;
- if (dc->salinity)
- specific_weight = dc->salinity / 10000.0 * 0.981;
- if (dc->surface_pressure.mbar)
- surface_pressure = dc->surface_pressure.mbar;
- else
- surface_pressure = get_surface_pressure_in_mbar(dive, TRUE);
- return depth / 10.0 * specific_weight + surface_pressure + 0.5;
+ double specific_weight;
+ int mbar = surface_pressure.mbar;
+
+ if (!mbar)
+ mbar = SURFACE_PRESSURE;
+ if (!salinity)
+ salinity = SEAWATER_SALINITY;
+ specific_weight = salinity / 10000.0 * 0.981;
+ mbar += depth / 10.0 * specific_weight + 0.5;
+ return mbar;
+}
+
+static inline int depth_to_mbar(int depth, struct dive *dive)
+{
+ return calculate_depth_to_mbar(depth, dive->surface_pressure, dive->salinity);
}
/* for the inverse calculation we use just the relative pressure
@@ -468,6 +487,9 @@ static inline struct dive *get_dive(int nr)
#define for_each_dive(_i,_x) \
for ((_i) = 0; ((_x) = get_dive(_i)) != NULL; (_i)++)
+#define for_each_dc(_dive,_dc) \
+ for (_dc = &_dive->dc; _dc; _dc = _dc->next)
+
#define for_each_gps_location(_i,_x) \
for ((_i) = 0; ((_x) = get_gps_location(_i, &gps_location_table)) != NULL; (_i)++)