summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2014-11-09 14:36:27 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-11-16 20:50:16 +0000
commit84dc8b8962ae8a4a75ca1ec81acd09989f757c98 (patch)
treed6c265f31d8901f481cdf96d5fdfdde5b6e8f8e9
parent5034f760727ae66d401093420f4c443eaad33d9a (diff)
downloadsubsurface-84dc8b8962ae8a4a75ca1ec81acd09989f757c98.tar.gz
Some gas handling improvements
Add a time linear gas interpolation strategy. Some minor changes. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.c4
-rw-r--r--dive.h2
-rw-r--r--file.c4
-rw-r--r--gaspressures.c52
-rw-r--r--gaspressures.h1
5 files changed, 38 insertions, 25 deletions
diff --git a/dive.c b/dive.c
index 0c0e64972..f9914d479 100644
--- a/dive.c
+++ b/dive.c
@@ -1062,8 +1062,8 @@ unsigned int dc_airtemp(struct divecomputer *dc)
static void fixup_cylinder_use(struct dive *dive) // for CCR dives, store the indices
{ // of the oxygen and diluent cylinders
- dive->oxygen_cylinder_index = get_cylinder_use(dive, oxygen);
- dive->diluent_cylinder_index = get_cylinder_use(dive, diluent);
+ dive->oxygen_cylinder_index = get_cylinder_use(dive, OXYGEN);
+ dive->diluent_cylinder_index = get_cylinder_use(dive, DILUENT);
}
static void fixup_airtemp(struct dive *dive)
diff --git a/dive.h b/dive.h
index 8d5a93ae9..e6b72f9bc 100644
--- a/dive.h
+++ b/dive.h
@@ -48,7 +48,7 @@ extern "C" {
#endif
enum dive_comp_type {OC, CCR, PSCR}; // Flags (Open-circuit and Closed-circuit-rebreather) for setting dive computer type
-enum cylinderuse {oxygen, diluent, bailout}; // The different uses for cylinders in CCR dives
+enum cylinderuse {OC_GAS, DILUENT, OXYGEN}; // The different uses for cylinders
struct gasmix {
fraction_t o2;
diff --git a/file.c b/file.c
index e8fc2b5cd..a71f9d0f3 100644
--- a/file.c
+++ b/file.c
@@ -507,14 +507,14 @@ int parse_txt_file(const char *filename, const char *csv)
dive->dc.dctype = CCR;
dive->dc.no_o2sensors = 2;
- dive->cylinder[cur_cylinder_index].cylinder_use = oxygen;
+ dive->cylinder[cur_cylinder_index].cylinder_use = OXYGEN;
dive->cylinder[cur_cylinder_index].type.size.mliter = 3000;
dive->cylinder[cur_cylinder_index].type.workingpressure.mbar = 200000;
dive->cylinder[cur_cylinder_index].type.description = strdup("3l Mk6");
dive->cylinder[cur_cylinder_index].gasmix.o2.permille = 1000;
cur_cylinder_index++;
- dive->cylinder[cur_cylinder_index].cylinder_use = diluent;
+ dive->cylinder[cur_cylinder_index].cylinder_use = DILUENT;
dive->cylinder[cur_cylinder_index].type.size.mliter = 3000;
dive->cylinder[cur_cylinder_index].type.workingpressure.mbar = 200000;
dive->cylinder[cur_cylinder_index].type.description = strdup("3l Mk6");
diff --git a/gaspressures.c b/gaspressures.c
index 3155a90ad..fbb52a130 100644
--- a/gaspressures.c
+++ b/gaspressures.c
@@ -97,7 +97,7 @@ static void dump_pr_track(pr_track_t **track_pr)
* segments according to how big of a time_pressure area
* they have.
*/
-static void fill_missing_segment_pressures(pr_track_t *list)
+static void fill_missing_segment_pressures(pr_track_t *list, enum interpolation_strategy strategy)
{
while (list) {
int start = list->start, end;
@@ -128,17 +128,29 @@ static void fill_missing_segment_pressures(pr_track_t *list)
*/
list->start = start;
tmp->end = end;
- for (;;) {
- int pressure;
- pt += list->pressure_time;
- pressure = start;
- if (pt_sum)
- pressure -= (start - end) * (double)pt / pt_sum;
- list->end = pressure;
- if (list == tmp)
- break;
- list = list->next;
- list->start = pressure;
+ switch (strategy) {
+ case SAC:
+ for (;;) {
+ int pressure;
+ pt += list->pressure_time;
+ pressure = start;
+ if (pt_sum)
+ pressure -= (start - end) * (double)pt / pt_sum;
+ list->end = pressure;
+ if (list == tmp)
+ break;
+ list = list->next;
+ list->start = pressure;
+ }
+ break;
+ case TIME:
+ if (list->t_end && (tmp->t_start - tmp->t_end))
+ list->end = start - (start - end) * (list->t_end - tmp->t_end) / (tmp->t_start - tmp->t_end);
+ else
+ list->end = start;
+ break;
+ case CONSTANT:
+ list->end = start;
}
/* Ok, we've done that set of segments */
@@ -155,12 +167,11 @@ void dump_pr_interpolate(int i, pr_interpolate_t interpolate_pr)
#endif
-static struct pr_interpolate_struct get_pr_interpolate_data(pr_track_t *segment, struct plot_info *pi, int cur, int diluent_flag)
+static struct pr_interpolate_struct get_pr_interpolate_data(pr_track_t *segment, struct plot_info *pi, int cur, int pressure)
{ // cur = index to pi->entry corresponding to t_end of segment; diluent_flag=1 indicates diluent cylinder
struct pr_interpolate_struct interpolate;
int i;
struct plot_data *entry;
- int pressure;
interpolate.start = segment->start;
interpolate.end = segment->end;
@@ -169,10 +180,6 @@ static struct pr_interpolate_struct get_pr_interpolate_data(pr_track_t *segment,
for (i = 0; i < pi->nr; i++) {
entry = pi->entry + i;
- if (diluent_flag)
- pressure = DILUENT_PRESSURE(entry);
- else
- pressure = SENSOR_PRESSURE(entry);
if (entry->sec < segment->t_start)
continue;
@@ -219,12 +226,17 @@ static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi,
int cur_pr[MAX_CYLINDERS]; // cur_pr[MAX_CYLINDERS] is the CCR diluent cylinder
for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) {
+ enum interpolation_strategy strategy;
if (!track_pr[cyl]) {
/* no segment where this cylinder is used */
cur_pr[cyl] = -1;
continue;
}
- fill_missing_segment_pressures(track_pr[cyl]); // Interpolate the missing tank pressure values ..
+ if (dive->cylinder[cyl].cylinder_use == OC_GAS)
+ strategy = SAC;
+ else
+ strategy = TIME;
+ fill_missing_segment_pressures(track_pr[cyl], strategy); // Interpolate the missing tank pressure values ..
cur_pr[cyl] = track_pr[cyl]->start; // in the pr_track_t lists of structures
} // and keep the starting pressure for each cylinder.
@@ -279,7 +291,7 @@ static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi,
continue; // and skip to next point.
}
// If there is a valid segment but no tank pressure ..
- interpolate = get_pr_interpolate_data(segment, pi, i, diluent_flag); // Set up an interpolation structure
+ interpolate = get_pr_interpolate_data(segment, pi, i, pressure); // Set up an interpolation structure
/* if this segment has pressure_time, then calculate a new interpolated pressure */
if (interpolate.pressure_time) {
diff --git a/gaspressures.h b/gaspressures.h
index 71fee341e..420c117a2 100644
--- a/gaspressures.h
+++ b/gaspressures.h
@@ -27,6 +27,7 @@ struct pr_interpolate_struct {
int acc_pressure_time;
};
+enum interpolation_strategy {SAC, TIME, CONSTANT};
#ifdef __cplusplus
}