summaryrefslogtreecommitdiffstats
path: root/profile.c
diff options
context:
space:
mode:
authorGravatar Rodrigo Severo <rodrigo@fabricadeideias.com>2014-01-01 10:35:16 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-08 20:38:17 +0800
commiteec5dba1c23a6aef8c73ff744973cf8ad821eef2 (patch)
tree31a99523d5edf7c4ad6903594524b4dc5d352884 /profile.c
parent8f0c8be245b405251a6023591d915c702ea9d034 (diff)
downloadsubsurface-eec5dba1c23a6aef8c73ff744973cf8ad821eef2.tar.gz
Reinstating SURFACE_THRESHOLD test in pressure_time function
The small straight parts at the end of tank pressure lines are more of a aesthetic issue, not causing real harm so it is no reason to remove the SURFACE_THRESHOLD test from pressure_time function only because of this. Also improved interpolate data debuging, rearranged get_pr_interpolate_data and removed an unused variable from get_pr_interpolate_data. No real change here, just trying to make the code clearer. [Dirk Hohndel: clean up whitespace damage from this and the previous commit] Signed-off-by: Rodrigo Severo <rodrigo@fabricadeideias.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'profile.c')
-rw-r--r--profile.c46
1 files changed, 26 insertions, 20 deletions
diff --git a/profile.c b/profile.c
index 39ad2a1e1..0b90a288d 100644
--- a/profile.c
+++ b/profile.c
@@ -422,14 +422,14 @@ struct pr_interpolate_struct {
int start;
int end;
int pressure_time;
- int acc_pressure_time;
+ int acc_pressure_time;
};
#ifdef DEBUG_PR_INTERPOLATE
-static void dump_pr_interpolate(pr_interpolate_t interpolate_pr)
+static void dump_pr_interpolate(int i, pr_interpolate_t interpolate_pr)
{
- printf("INTERPOLATE: start %d - end %d - pt %d - acc_pt %d\n",
- interpolate_pr.start, interpolate_pr.end, interpolate_pr.pressure_time, interpolate_pr.acc_pressure_time);
+ printf("Interpolate for entry %d: start %d - end %d - pt %d - acc_pt %d\n", i,
+ interpolate_pr.start, interpolate_pr.end, interpolate_pr.pressure_time, interpolate_pr.acc_pressure_time);
}
#endif
@@ -489,7 +489,7 @@ static void fill_missing_segment_pressures(pr_track_t *list)
if (pt_sum)
pressure -= (start-end)*(double)pt/pt_sum;
list->end = pressure;
- if (list == tmp)
+ if (list == tmp)
break;
list = list->next;
list->start = pressure;
@@ -516,6 +516,9 @@ static inline int pressure_time(struct dive *dive, struct divecomputer *dc, stru
int time = b->sec - a->sec;
int depth = (a->depth + b->depth)/2;
+ if (depth <= SURFACE_THRESHOLD)
+ return 0;
+
return depth_to_mbar(depth, dive) * time;
}
@@ -523,13 +526,12 @@ static struct pr_interpolate_struct get_pr_interpolate_data(pr_track_t *segment,
{
struct pr_interpolate_struct interpolate;
int i;
- struct plot_data *entry, *cur_entry;
+ struct plot_data *entry;
interpolate.start = segment->start;
interpolate.end = segment->end;
interpolate.acc_pressure_time = 0;
interpolate.pressure_time = 0;
- cur_entry = pi->entry + cur;
for (i = 0; i < pi->nr; i++) {
entry = pi->entry + i;
@@ -544,7 +546,9 @@ static struct pr_interpolate_struct get_pr_interpolate_data(pr_track_t *segment,
interpolate.pressure_time = 0;
if (SENSOR_PRESSURE(entry))
interpolate.start = SENSOR_PRESSURE(entry);
- } else if (i < cur) {
+ continue;
+ }
+ if (i < cur) {
if (SENSOR_PRESSURE(entry)) {
interpolate.start = SENSOR_PRESSURE(entry);
interpolate.acc_pressure_time = 0;
@@ -553,15 +557,17 @@ static struct pr_interpolate_struct get_pr_interpolate_data(pr_track_t *segment,
interpolate.acc_pressure_time += entry->pressure_time;
interpolate.pressure_time += entry->pressure_time;
}
- } else if (i == cur) {
+ continue;
+ }
+ if (i == cur) {
interpolate.acc_pressure_time += entry->pressure_time;
interpolate.pressure_time += entry->pressure_time;
- } else {
- interpolate.pressure_time += entry->pressure_time;
- if (SENSOR_PRESSURE(entry)) {
- interpolate.end = SENSOR_PRESSURE(entry);
- break;
- }
+ continue;
+ }
+ interpolate.pressure_time += entry->pressure_time;
+ if (SENSOR_PRESSURE(entry)) {
+ interpolate.end = SENSOR_PRESSURE(entry);
+ break;
}
}
return interpolate;
@@ -589,7 +595,7 @@ static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi,
for (i = 1; i < pi->nr; i++) {
double magic;
pr_track_t *segment;
- pr_interpolate_t interpolate;
+ pr_interpolate_t interpolate;
entry = pi->entry + i;
cyl = entry->cylinderindex;
@@ -599,7 +605,7 @@ static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi,
continue;
}
- /* Find the right pressure segment for this entry.. */
+ /* Find the right pressure segment for this entry.. */
segment = track_pr[cyl];
while (segment && segment->t_end < entry->sec)
segment = segment->next;
@@ -610,9 +616,9 @@ static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi,
continue;
}
- interpolate = get_pr_interpolate_data(segment, pi, i);
+ interpolate = get_pr_interpolate_data(segment, pi, i);
#ifdef DEBUG_PR_INTERPOLATE
- dump_pr_interpolate(interpolate);
+ dump_pr_interpolate(i, interpolate);
#endif
/* Overall pressure change over total pressure-time for this segment*/
magic = (interpolate.end - interpolate.start) / (double) interpolate.pressure_time;
@@ -969,7 +975,7 @@ static void populate_pressure_information(struct dive *dive, struct divecomputer
/* discrete integration of pressure over time to get the SAC rate equivalent */
if (current) {
- entry->pressure_time = pressure_time(dive, dc, entry-1, entry);
+ entry->pressure_time = pressure_time(dive, dc, entry-1, entry);
current->pressure_time += entry->pressure_time;
current->t_end = entry->sec;
}