CCR patch: Oxygen partial pressures

This patch does three things:
1) A new function fill_o2_values() is added to profile.c. This
   fills all oxygen sesnsor and setpoint values that have been
   zeroed before in order to save space in the dive log. This
   recreates the full set of sensor values obtained from the
   original CCR xml log file.
2) Function fill_o2_values() is activated in function create_
   plot_info_new() in profile.c
3) The calling parameters to function fill_pressures() in dive.c
   are changed. The last parameter is now a pointer to a structure
   of divecomputer. This will be needed in the last patch of the
   present series of three patches.

[Dirk Hohndel: minor whitespace cleanup]

Signed-off-by: willem ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
willem ferguson 2014-10-12 14:46:20 +02:00 committed by Dirk Hohndel
parent 3b30009d7a
commit 49c9ad199f
4 changed files with 49 additions and 5 deletions

2
deco.c
View file

@ -190,7 +190,7 @@ double add_segment(double pressure, const struct gasmix *gasmix, int period_in_s
int fo2 = get_o2(gasmix), fhe = get_he(gasmix);
struct gas_pressures pressures;
fill_pressures(&pressures, pressure, gasmix, (double) ccpo2 / 1000.0, dive->dc.dctype);
fill_pressures(&pressures, pressure, gasmix, (double) ccpo2 / 1000.0, &(dive->dc));
if (buehlmann_config.gf_low_at_maxdepth && pressure > gf_low_pressure_this_dive)
gf_low_pressure_this_dive = pressure;

2
dive.c
View file

@ -1521,7 +1521,7 @@ int gasmix_distance(const struct gasmix *a, const struct gasmix *b)
}
/* Compute partial gas pressures in bar from gasmix and ambient pressures, possibly for OC or CCR, to be extended to PSCT */
extern void fill_pressures(struct gas_pressures *pressures, const double amb_pressure, const struct gasmix *mix, double po2, const enum dive_comp_type type)
extern void fill_pressures(struct gas_pressures *pressures, const double amb_pressure, const struct gasmix *mix, double po2, const struct divecomputer *dc)
{
if (po2) {
/* we have an O₂ partial pressure in the sample - so this

5
dive.h
View file

@ -137,7 +137,6 @@ struct gas_pressures {
double o2, n2, he;
};
extern void fill_pressures(struct gas_pressures *pressures, const double amb_pressure, const struct gasmix *mix, double po2, const enum dive_comp_type type);
extern void sanitize_gasmix(struct gasmix *mix);
extern int gasmix_distance(const struct gasmix *a, const struct gasmix *b);
extern struct gasmix *get_gasmix_from_event(struct event *ev);
@ -260,6 +259,10 @@ struct divecomputer {
struct divecomputer *next;
};
extern void fill_pressures(struct gas_pressures *pressures, const double amb_pressure, const struct gasmix *mix, double po2, const struct divecomputer *dc);
#define MAX_CYLINDERS (8)
#define MAX_WEIGHTSYSTEMS (6)
#define W_IDX_PRIMARY 0

View file

@ -834,7 +834,7 @@ static void calculate_gas_information_new(struct dive *dive, struct plot_info *p
fo2 = get_o2(&dive->cylinder[cylinderindex].gasmix);
fhe = get_he(&dive->cylinder[cylinderindex].gasmix);
fill_pressures(&entry->pressures, amb_pressure, &dive->cylinder[cylinderindex].gasmix, entry->pressures.o2, dive->dc.dctype);
fill_pressures(&entry->pressures, amb_pressure, &dive->cylinder[cylinderindex].gasmix, entry->pressures.o2, &(dive->dc));
/* Calculate MOD, EAD, END and EADD based on partial pressures calculated before
* so there is no difference in calculating between OC and CC
@ -860,6 +860,47 @@ static void calculate_gas_information_new(struct dive *dive, struct plot_info *p
}
}
void fill_o2_values(struct divecomputer *dc, struct plot_info *pi)
/* For CCR:
* In the samples from each dive computer, any duplicate values for the
* oxygen sensors were removed (i.e. set to 0) in order to conserve
* storage space (see function fuxup_dive_dc). But for drawing the prodile
* a complete series of valid o2 pressure values is required. This function
* takes the oxygen sensor data and setpoint values from the structures
* of plotinfo and re-inserts the duplicate values set to 0 so
* that the oxygen sensor data are complete and ready for plotting.
* The original sequence of oxygen values are recreated without attempting
* any interpolations for values set to zero, recreating the raw data from
* the CCR dive log. This function called by: create_plot_info_new() */
{
int i, j;
double last_setpoint;
double last_sensor[3];
for (i = 0; i < pi->nr; i++) {
struct plot_data *entry = pi->entry + i;
// For 1st iteration, initialise the last_ values
if (i == 0) {
last_setpoint = pi->entry->o2setpoint;
for (j = 0; j < dc->no_o2sensors; j++)
last_sensor[j] = pi->entry->o2sensor[j];
} else {
// Now re-insert the missing oxygen pressure values
if (entry->o2setpoint)
last_setpoint = entry->o2setpoint;
else
entry->o2setpoint = last_setpoint;
for (j = 0; j < dc->no_o2sensors; j++)
if (entry->o2sensor[j])
last_sensor[j] = entry->o2sensor[j];
else
entry->o2sensor[j] = last_sensor[j];
}
}
}
#ifdef DEBUG_GAS
/* A CCR debug function that writes the cylinder pressure and the oxygen values to the file debug_print_profiledata.dat:
* Called in create_plot_info_new()
@ -915,7 +956,7 @@ void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plo
if (dc->dctype == CCR) { /* For CCR dives.. */
printf("CCR DIVE: %s (%d O2 sensors)\n", dc->model, dc->no_o2sensors);
populate_pressure_information(dive, dc, pi, DILUENT); /* .. calculate missing diluent gas pressure entries */
// fill_o2_values(dc, pi); /* .. and insert the O2 sensor data having 0 values. */
fill_o2_values(dc, pi); /* .. and insert the O2 sensor data having 0 values. */
}
calculate_sac(dive, pi); /* Calculate sac */
calculate_deco_information(dive, dc, pi, false);