diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2012-11-11 10:00:45 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2012-11-11 10:00:45 +0100 |
commit | 4c3dfee446eda061f862e1fdcce93b54a066feff (patch) | |
tree | a6a3087c1172f8a4856f453223c433e7aa525b1b | |
parent | 776f92edcf9e1fb563f8cae5bc49c54a85ff2faf (diff) | |
parent | e167108c76c4a74ab50561fd59b2158704767a75 (diff) | |
download | subsurface-4c3dfee446eda061f862e1fdcce93b54a066feff.tar.gz |
Merge branch 'pressure'
Make depth to absolute pressure conversions consistent.
-rw-r--r-- | dive.h | 14 | ||||
-rw-r--r-- | divelist.c | 6 | ||||
-rw-r--r-- | profile.c | 30 |
3 files changed, 33 insertions, 17 deletions
@@ -282,6 +282,20 @@ struct dive { struct sample sample[]; }; +/* 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) +{ + double specific_weight = 1.03 * 0.981; + int surface_pressure = 1013; + if (dive->salinity) + specific_weight = dive->salinity / 10000.0 * 0.981; + if (dive->surface_pressure.mbar) + surface_pressure = dive->surface_pressure.mbar; + return depth / 10.0 * specific_weight + surface_pressure + 0.5; +} + /* this is a global spot for a temporary dive structure that we use to * be able to edit a dive without unintended side effects */ extern struct dive edit_dive; diff --git a/divelist.c b/divelist.c index 056a4f64a..6aa26c2bd 100644 --- a/divelist.c +++ b/divelist.c @@ -711,7 +711,7 @@ static int calculate_otu(struct dive *dive) int o2 = dive->cylinder[sample->cylinderindex].gasmix.o2.permille; if (!o2) o2 = AIR_PERMILLE; - po2 = o2 / 1000.0 * (sample->depth.mm + 10000) / 10000.0; + po2 = o2 / 1000.0 * depth_to_mbar(sample->depth.mm, dive) / 1000.0; if (po2 >= 0.5) otu += pow(po2 - 0.5, 0.83) * t / 30.0; } @@ -771,8 +771,8 @@ static int calculate_sac(struct dive *dive) } } } - /* Mean pressure in atm: 1 atm per 10m */ - pressure = 1 + (dive->meandepth.mm / 10000.0); + /* Mean pressure in bar (SAC calculations are in bar*l/min) */ + pressure = depth_to_mbar(dive->meandepth.mm, dive) / 1000.0; sac = airuse / pressure * 60 / duration; /* milliliters per minute.. */ @@ -1179,8 +1179,7 @@ static void set_sac_color(struct graphics_context *gc, int sac, int avg_sac) ((GET_PRESSURE((_entry1)) - GET_PRESSURE((_entry2))) * \ (_dive)->cylinder[(_entry1)->cylinderindex].type.size.mliter / \ (((_entry2)->sec - (_entry1)->sec) / 60.0) / \ - (1 + ((_entry1)->depth + (_entry2)->depth) / 20000.0) / \ - 1000.0) + depth_to_mbar(((_entry1)->depth + (_entry2)->depth) / 2.0, (_dive))) #define SAC_WINDOW 45 /* sliding window in seconds for current SAC calculation */ @@ -1671,6 +1670,7 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str gboolean missing_pr = FALSE; struct plot_data *entry = NULL; struct event *ev, *ceil_ev; + double amb_pressure; /* we want to potentially add synthetic plot_info elements for the gas changes */ nr = nr_samples + 4 + 2 * count_gas_change_events(dive); @@ -1780,7 +1780,6 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str current = track_pr[pi->entry[2].cylinderindex]; for (i = 0; i < nr + 1; i++) { int fo2, fhe; - double pressure; entry = pi->entry + i + 1; @@ -1804,19 +1803,19 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str list_add(track_pr[cylinderindex], current); } } - pressure = (entry->depth + 10000) / 10000.0 * 1.01325; + amb_pressure = depth_to_mbar(entry->depth, dive) / 1000.0; fo2 = dive->cylinder[cylinderindex].gasmix.o2.permille; fhe = dive->cylinder[cylinderindex].gasmix.he.permille; if (!fo2) fo2 = AIR_PERMILLE; - entry->po2 = fo2 / 1000.0 * pressure; - entry->phe = fhe / 1000.0 * pressure; - entry->pn2 = (1000 - fo2 - fhe) / 1000.0 * pressure; + entry->po2 = fo2 / 1000.0 * amb_pressure; + entry->phe = fhe / 1000.0 * amb_pressure; + entry->pn2 = (1000 - fo2 - fhe) / 1000.0 * amb_pressure; /* finally, do the discrete integration to get the SAC rate equivalent */ current->pressure_time += (entry->sec - (entry-1)->sec) * - (1 + (entry->depth + (entry-1)->depth) / 20000.0); + depth_to_mbar((entry->depth + (entry-1)->depth) / 2, dive) / 1000.0; missing_pr |= !SENSOR_PRESSURE(entry); } @@ -1837,8 +1836,9 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str pi->entry[i].same_cylinder = 1; pi->entry[i].cylinderindex = pi->entry[i-1].cylinderindex; INTERPOLATED_PRESSURE(pi->entry + i) = GET_PRESSURE(pi->entry + i - 1); - pi->entry[i].po2 = pi->entry[i-1].po2 / (pi->entry[i].depth + 10000.0) * 10000.0; - pi->entry[i].phe = pi->entry[i-1].phe / (pi->entry[i].depth + 10000.0) * 10000.0; + amb_pressure = depth_to_mbar(pi->entry[i - 1].depth, dive) / 1000.0; + pi->entry[i].po2 = pi->entry[i-1].po2 / amb_pressure; + pi->entry[i].phe = pi->entry[i-1].phe / amb_pressure; pi->entry[i].pn2 = 1.01325 - pi->entry[i].po2 - pi->entry[i].phe; pi->entry[i+1].sec = sec + 40; pi->entry[i+1].same_cylinder = 1; @@ -1848,15 +1848,17 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str pi->entry[i+1].phe = pi->entry[i].phe; pi->entry[i+1].pn2 = pi->entry[i].pn2; /* make sure the first two pi entries have a sane po2 / phe / pn2 */ + amb_pressure = depth_to_mbar(pi->entry[2].depth, dive) / 1000.0; if (pi->entry[1].po2 < 0.01) - pi->entry[1].po2 = pi->entry[2].po2 / (pi->entry[2].depth + 10000.0) * 10000.0; + pi->entry[1].po2 = pi->entry[2].po2 / amb_pressure; if (pi->entry[1].phe < 0.01) - pi->entry[1].phe = pi->entry[2].phe / (pi->entry[2].depth + 10000.0) * 10000.0; + pi->entry[1].phe = pi->entry[2].phe / amb_pressure; pi->entry[1].pn2 = 1.01325 - pi->entry[1].po2 - pi->entry[1].phe; + amb_pressure = depth_to_mbar(pi->entry[1].depth, dive) / 1000.0; if (pi->entry[0].po2 < 0.01) - pi->entry[0].po2 = pi->entry[1].po2 / (pi->entry[1].depth + 10000.0) * 10000.0; + pi->entry[0].po2 = pi->entry[1].po2 / amb_pressure; if (pi->entry[0].phe < 0.01) - pi->entry[0].phe = pi->entry[1].phe / (pi->entry[1].depth + 10000.0) * 10000.0; + pi->entry[0].phe = pi->entry[1].phe / amb_pressure; pi->entry[0].pn2 = 1.01325 - pi->entry[0].po2 - pi->entry[0].phe; /* the number of actual entries - some computers have lots of |