X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=profile.c;h=f0ae0c9311c5eba3c3bc24130c01d8b02c36eb59;hb=2b0f30c3d4773d4e78daf7e2ce76f5c3f3a2d0b3;hp=e5d8aa9b9065d5cc335e9a74413da3bd2eae1aae;hpb=c52b95d502fb79e52d5927b7c59addef984d23e2;p=ext%2Fsubsurface.git diff --git a/profile.c b/profile.c index e5d8aa9..f0ae0c9 100644 --- a/profile.c +++ b/profile.c @@ -21,8 +21,7 @@ struct plot_info { int nr; int maxtime; int meandepth, maxdepth; - int minpressure, maxpressure; - int endpressure; /* start pressure better be max pressure */ + int maxpressure; int mintemp, maxtemp; struct plot_data { unsigned int same_cylinder:1; @@ -102,9 +101,9 @@ static void dump_pi (struct plot_info *pi) int i; printf("pi:{nr:%d maxtime:%d meandepth:%d maxdepth:%d \n" - " minpressure:%d maxpressure:%d endpressure:%d mintemp:%d maxtemp:%d\n", + " maxpressure:%d mintemp:%d maxtemp:%d\n", pi->nr, pi->maxtime, pi->meandepth, pi->maxdepth, - pi->minpressure, pi->maxpressure, pi->endpressure, pi->mintemp, pi->maxtemp); + pi->maxpressure, pi->mintemp, pi->maxtemp); for (i = 0; i < pi->nr; i++) printf(" entry[%d]:{same_cylinder:%d cylinderindex:%d sec:%d pressure:{%d,%d}\n" " temperature:%d depth:%d smoothed:%d}\n", @@ -513,7 +512,7 @@ static void plot_single_temp_text(struct graphics_context *gc, int sec, int mkel { double deg; const char *unit; - static const text_render_options_t tro = {12, 0.2, 0.2, 1.0, LEFT, TOP}; + static const text_render_options_t tro = {12, 0.6, 0.6, 1.0, LEFT, TOP}; deg = get_temp_units(mkelvin, &unit); @@ -523,7 +522,7 @@ static void plot_single_temp_text(struct graphics_context *gc, int sec, int mkel static void plot_temperature_text(struct graphics_context *gc, struct plot_info *pi) { int i; - int last = 0, sec = 0; + int last = -300, sec = 0; int last_temperature = 0, last_printed_temp = 0; if (!setup_temperature_limits(gc, pi)) @@ -537,14 +536,23 @@ static void plot_temperature_text(struct graphics_context *gc, struct plot_info continue; last_temperature = mkelvin; sec = entry->sec; - if (sec < last + 300) + /* don't print a temperature + * if it's been less than 5min and less than a 2K change OR + * if it's been less than 2min OR if the change from the + * last print is less than .4K (and therefore less than 1F */ + if (((sec < last + 300) && (abs(mkelvin - last_printed_temp) < 2000)) || + (sec < last + 120) || + (abs(mkelvin - last_printed_temp) < 400)) continue; last = sec; plot_single_temp_text(gc,sec,mkelvin); last_printed_temp = mkelvin; } - /* it would be nice to print the end temperature, if it's different */ - if (abs(last_temperature - last_printed_temp) > 500) + /* it would be nice to print the end temperature, if it's + * different or if the last temperature print has been more + * than a quarter of the dive back */ + if ((abs(last_temperature - last_printed_temp) > 500) || + ((double)last / (double)sec < 0.75)) plot_single_temp_text(gc, sec, last_temperature); } @@ -648,6 +656,8 @@ static void plot_pressure_value(struct graphics_context *gc, int mbar, int sec, plot_text(gc, &tro, sec, mbar, "%d %s", pressure, unit); } +#define GET_PRESSURE(_entry) (SENSOR_PRESSURE(_entry) ? : INTERPOLATED_PRESSURE(_entry)) + static void plot_cylinder_pressure_text(struct graphics_context *gc, struct plot_info *pi) { int i; @@ -660,14 +670,21 @@ static void plot_cylinder_pressure_text(struct graphics_context *gc, struct plot if (!get_cylinder_pressure_range(gc, pi)) return; - /* only loop over the actual events from the dive computer */ - for (i = 2; i < pi->nr; i++) { + /* only loop over the actual events from the dive computer + * plus the second synthetic event at the start (to make sure + * we get "time=0" right) + * sadly with a recent change that first entry may no longer + * have any pressure reading - in that case just grab the + * pressure from the second entry */ + if (GET_PRESSURE(pi->entry + 1) == 0 && GET_PRESSURE(pi->entry + 2) !=0) + INTERPOLATED_PRESSURE(pi->entry + 1) = GET_PRESSURE(pi->entry + 2); + for (i = 1; i < pi->nr; i++) { entry = pi->entry + i; if (!entry->same_cylinder) { cyl = entry->cylinderindex; if (!seen_cyl[cyl]) { - mbar = SENSOR_PRESSURE(entry) ? : INTERPOLATED_PRESSURE(entry); + mbar = GET_PRESSURE(entry); plot_pressure_value(gc, mbar, entry->sec, LEFT, BOTTOM); seen_cyl[cyl] = TRUE; } @@ -675,14 +692,14 @@ static void plot_cylinder_pressure_text(struct graphics_context *gc, struct plot /* remember the last pressure and time of * the previous cylinder */ cyl = (entry - 1)->cylinderindex; - last_pressure[cyl] = - SENSOR_PRESSURE(entry - 1) ? : INTERPOLATED_PRESSURE(entry - 1); + last_pressure[cyl] = GET_PRESSURE(entry - 1); last_time[cyl] = (entry - 1)->sec; } } } cyl = entry->cylinderindex; - last_pressure[cyl] = SENSOR_PRESSURE(entry) ? : INTERPOLATED_PRESSURE(entry); + if (GET_PRESSURE(entry)) + last_pressure[cyl] = GET_PRESSURE(entry); last_time[cyl] = entry->sec; for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) { @@ -769,12 +786,10 @@ static struct plot_info *analyze_plot_info(struct plot_info *pi) /* Do pressure min/max based on the non-surface data */ for (i = 0; i < nr; i++) { struct plot_data *entry = pi->entry+i; - int pressure = SENSOR_PRESSURE(entry) ? : INTERPOLATED_PRESSURE(entry); + int pressure = GET_PRESSURE(entry); int temperature = entry->temperature; if (pressure) { - if (!pi->minpressure || pressure < pi->minpressure) - pi->minpressure = pressure; if (pressure > pi->maxpressure) pi->maxpressure = pressure; } @@ -889,8 +904,9 @@ static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi, cur_pr[cyl] = track_pr[cyl]->start; } - /* The first two are "fillers" */ - for (i = 2; i < pi->nr; i++) { + /* The first two are "fillers", but in case we don't have a sample + * at time 0 we need to process the second of them here */ + for (i = 1; i < pi->nr; i++) { entry = pi->entry + i; if (SENSOR_PRESSURE(entry)) { cur_pr[entry->cylinderindex] = SENSOR_PRESSURE(entry); @@ -919,6 +935,7 @@ static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi, if (!nlist) { /* just continue without calculating * interpolated values */ + INTERPOLATED_PRESSURE(entry) = cur_pr[entry->cylinderindex]; list = NULL; continue; } @@ -929,7 +946,8 @@ static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi, INTERPOLATED_PRESSURE(entry) = cur_pr[entry->cylinderindex] + cur_pt * magic; cur_pr[entry->cylinderindex] = INTERPOLATED_PRESSURE(entry); - } + } else + INTERPOLATED_PRESSURE(entry) = cur_pr[entry->cylinderindex]; } } } @@ -1094,7 +1112,7 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str entry->temperature = sample->temperature.mkelvin; if (depth || lastdepth) - lastindex = i+pi_idx; + lastindex = i + pi_idx; lastdepth = depth; if (depth > pi->maxdepth) @@ -1109,14 +1127,14 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str entry = pi->entry + i + pi_idx; ev = get_next_gaschange(ev->next); } - nr_samples += pi_idx - 2; + nr = nr_samples + pi_idx - 2; check_gas_change_events(dive, pi); for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) /* initialize the start pressures */ track_pr[cyl] = pr_track_alloc(dive->cylinder[cyl].start.mbar, -1); current = track_pr[pi->entry[2].cylinderindex]; - for (i = 0; i < nr_samples; i++) { - entry = pi->entry + i + 2; + for (i = 0; i < nr + 1; i++) { + entry = pi->entry + i + 1; entry->same_cylinder = entry->cylinderindex == cylinderindex; cylinderindex = entry->cylinderindex; @@ -1154,17 +1172,34 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str pr_track->end = pr; } } - /* Fill in the last two entries with empty values but valid times */ - i = nr_samples + 2; + /* Fill in the last two entries with empty values but valid times + * without creating a false cylinder change event */ + i = nr + 2; pi->entry[i].sec = sec + 20; + 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+1].sec = sec + 40; - /* the number of actual entries - we may have allocated more if there - * were gas change events, but this is how many were filled */ + pi->entry[i+1].same_cylinder = 1; + pi->entry[i+1].cylinderindex = pi->entry[i-1].cylinderindex; + INTERPOLATED_PRESSURE(pi->entry + i + 1) = GET_PRESSURE(pi->entry + i - 1); + /* the number of actual entries - some computers have lots of + * depth 0 samples at the end of a dive, we want to make sure + * we have exactly one of them at the end */ pi->nr = lastindex+1; + while (pi->nr <= i+2 && pi->entry[pi->nr-1].depth > 0) + pi->nr++; pi->maxtime = pi->entry[lastindex].sec; - pi->endpressure = pi->minpressure = dive->cylinder[0].end.mbar; - pi->maxpressure = dive->cylinder[0].start.mbar; + /* Analyze_plot_info() will do the sample max pressures, + * this handles the manual pressures + */ + pi->maxpressure = 0; + for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) { + unsigned int mbar = dive->cylinder[cyl].start.mbar; + if (mbar > pi->maxpressure) + pi->maxpressure = mbar; + } pi->meandepth = dive->meandepth.mm;