static void show_total_dive_stats(void) { double value; int decimals, seconds; const char *unit; char buffer[60]; stats_t *stats_ptr; if (!stats_w.framelabel) return; stats_ptr = &stats_selection; get_selected_dives_text(buffer, sizeof(buffer)); set_label(stats_w.framelabel, _("Statistics %s"), buffer); set_label(stats_w.selection_size, "%d", stats_ptr->selection_size); if (stats_ptr->selection_size == 0) { clear_stats_widgets(); return; } if (stats_ptr->min_temp) { value = get_temp_units(stats_ptr->min_temp, &unit); set_label(stats_w.min_temp, "%.1f %s", value, unit); } if (stats_ptr->combined_temp && stats_ptr->combined_count) set_label(stats_w.avg_temp, "%.1f %s", stats_ptr->combined_temp / stats_ptr->combined_count, unit); if (stats_ptr->max_temp) { value = get_temp_units(stats_ptr->max_temp, &unit); set_label(stats_w.max_temp, "%.1f %s", value, unit); } set_label(stats_w.total_time, get_time_string(stats_ptr->total_time.seconds, 0)); seconds = stats_ptr->total_time.seconds; if (stats_ptr->selection_size) seconds /= stats_ptr->selection_size; set_label(stats_w.avg_time, get_time_string(seconds, 0)); set_label(stats_w.longest_time, get_time_string(stats_ptr->longest_time.seconds, 0)); set_label(stats_w.shortest_time, get_time_string(stats_ptr->shortest_time.seconds, 0)); value = get_depth_units(stats_ptr->max_depth.mm, &decimals, &unit); set_label(stats_w.max_overall_depth, "%.*f %s", decimals, value, unit); value = get_depth_units(stats_ptr->min_depth.mm, &decimals, &unit); set_label(stats_w.min_overall_depth, "%.*f %s", decimals, value, unit); value = get_depth_units(stats_ptr->avg_depth.mm, &decimals, &unit); set_label(stats_w.avg_overall_depth, "%.*f %s", decimals, value, unit); value = get_volume_units(stats_ptr->max_sac.mliter, &decimals, &unit); set_label(stats_w.max_sac, _("%.*f %s/min"), decimals, value, unit); value = get_volume_units(stats_ptr->min_sac.mliter, &decimals, &unit); set_label(stats_w.min_sac, _("%.*f %s/min"), decimals, value, unit); value = get_volume_units(stats_ptr->avg_sac.mliter, &decimals, &unit); set_label(stats_w.avg_sac, _("%.*f %s/min"), decimals, value, unit); }
QString DiveItem::displaySac() const { QString str; struct dive *dive = get_dive_by_uniq_id(diveId); if (dive->sac) { const char *unit; int decimal; double value = get_volume_units(dive->sac, &decimal, &unit); return QString::number(value, 'f', decimal); } return QString(""); }
QString get_volume_string(volume_t volume, bool showunit, int mbar) { const char *unit; int decimals; double value = get_volume_units(volume.mliter, &decimals, &unit); if (mbar) { // we are showing a tank size // fix the weird imperial way of denominating size and provide // reasonable number of decimals if (prefs.units.volume == units::CUFT) value *= bar_to_atm(mbar / 1000.0); decimals = (value > 20.0) ? 0 : (value > 2.0) ? 1 : 2; } return QString("%1%2").arg(value, 0, 'f', decimals).arg(showunit ? unit : ""); }
static void add_cell(GtkTreeStore *store, GtkTreeIter *parent, unsigned int val, int cell, gboolean depth_not_volume) { double value; int decimals; const char *unit; char value_str[40]; if (depth_not_volume) { value = get_depth_units(val, &decimals, &unit); snprintf(value_str, sizeof(value_str), "%.*f %s", decimals, value, unit); } else { value = get_volume_units(val, &decimals, &unit); snprintf(value_str, sizeof(value_str), "%.*f %s/min", decimals, value, unit); } add_cell_to_tree(store, value_str, cell, parent); }
QString get_cylinder_used_gas_string(cylinder_t *cyl, bool showunit) { int decimals; const char *unit; double gas_usage; /* Get the cylinder gas use in mbar */ gas_usage = start_pressure(cyl) - end_pressure(cyl); /* Can we turn it into a volume? */ if (cyl->type.size.mliter) { gas_usage = bar_to_atm(gas_usage / 1000); gas_usage *= cyl->type.size.mliter; gas_usage = get_volume_units(gas_usage, &decimals, &unit); } else { gas_usage = get_pressure_units(gas_usage, &unit); decimals = 0; } // translate("gettextFromC","%.*f %s" return QString("%1 %2").arg(gas_usage, 0, 'f', decimals).arg(showunit ? unit : ""); }
static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer) { char buffer[20000], temp[1000]; int len, lastdepth = 0, lasttime = 0; struct divedatapoint *dp = diveplan->dp; bool gaschange = !plan_verbatim; struct divedatapoint *nextdp = NULL; disclaimer = translate("gettextFromC", "DISCLAIMER / WARNING: THIS IS A NEW IMPLEMENTATION OF THE BUHLMANN " "ALGORITHM AND A DIVE PLANNER IMPLEMENTION BASED ON THAT WHICH HAS " "RECEIVED ONLY A LIMITED AMOUNT OF TESTING. WE STRONGLY RECOMMEND NOT TO " "PLAN DIVES SIMPLY BASED ON THE RESULTS GIVEN HERE."); if (!dp) return; len = show_disclaimer ? snprintf(buffer, sizeof(buffer), "<div><b>%s<b></div><br>", disclaimer) : 0; snprintf(temp, sizeof(temp), translate("gettextFromC", "based on GFlow = %d and GFhigh = %d"), diveplan->gflow, diveplan->gfhigh); len += snprintf(buffer + len, sizeof(buffer) - len, "<div><b>%s</b><br>%s</div><br>", translate("gettextFromC", "Subsurface dive plan"), temp); if (!plan_verbatim) { len += snprintf(buffer + len, sizeof(buffer) - len, "<div><table><thead><tr><th>%s</th>", translate("gettextFromC", "depth")); if (plan_display_runtime) len += snprintf(buffer + len, sizeof(buffer) - len, "<th style='padding-left: 10px;'>%s</th>", translate("gettextFromC", "runtime")); if (plan_display_duration) len += snprintf(buffer + len, sizeof(buffer) - len, "<th style='padding-left: 10px;'>%s</th>", translate("gettextFromC", "duration")); len += snprintf(buffer + len, sizeof(buffer) - len, "<th style='padding-left: 10px; float: left;'>%s</th></tr></thead><tbody style='float: left;'>", translate("gettextFromC", "gas")); } do { struct gasmix gasmix, newgasmix = {}; const char *depth_unit; double depthvalue; int decimals; if (dp->time == 0) continue; gasmix = dp->gasmix; depthvalue = get_depth_units(dp->depth, &decimals, &depth_unit); /* analyze the dive points ahead */ nextdp = dp->next; while (nextdp && nextdp->time == 0) nextdp = nextdp->next; if (nextdp) newgasmix = nextdp->gasmix; /* do we want to skip this leg as it is devoid of anything useful? */ if (!dp->entered && gasmix_distance(&gasmix, &newgasmix) == 0 && nextdp && dp->depth != lastdepth && nextdp->depth != dp->depth) continue; if (dp->time - lasttime < 10 && !(gaschange && dp->next && dp->depth != dp->next->depth)) continue; len = strlen(buffer); if (nextdp && gasmix_distance(&gasmix, &newgasmix)) gaschange = true; if (plan_verbatim) { if (dp->depth != lastdepth) { if (plan_display_transitions || dp->entered || !dp->next || (gaschange && dp->next && dp->depth != nextdp->depth)) { snprintf(temp, sizeof(temp), translate("gettextFromC", "Transition to %.*f %s in %d:%02d min - runtime %d:%02u on %s"), decimals, depthvalue, depth_unit, FRACTION(dp->time - lasttime, 60), FRACTION(dp->time, 60), gasname(&gasmix)); len += snprintf(buffer + len, sizeof(buffer) - len, "%s<br>", temp); lasttime = dp->time; } } else { if (dp->depth != nextdp->depth) { snprintf(temp, sizeof(temp), translate("gettextFromC", "Stay at %.*f %s for %d:%02d min - runtime %d:%02u on %s"), decimals, depthvalue, depth_unit, FRACTION(dp->time - lasttime, 60), FRACTION(dp->time, 60), gasname(&gasmix)); len += snprintf(buffer + len, sizeof(buffer) - len, "%s<br>", temp); lasttime = dp->time; } } } else { if ((dp->depth == lastdepth && dp->depth != nextdp->depth) || plan_display_transitions || dp->entered || !dp->next || (gaschange && dp->next && dp->depth != nextdp->depth)) { snprintf(temp, sizeof(temp), translate("gettextFromC", "%3.0f%s"), depthvalue, depth_unit); len += snprintf(buffer + len, sizeof(buffer) - len, "<tr><td style='padding-left: 10px; float: right;'>%s</td>", temp); if (plan_display_runtime) { snprintf(temp, sizeof(temp), translate("gettextFromC", "%3dmin"), (dp->time + 30) / 60); len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; float: right;'>%s</td>", temp); } if (plan_display_duration) { snprintf(temp, sizeof(temp), translate("gettextFromC", "%3dmin"), (dp->time - lasttime + 30) / 60); len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; float: right;'>%s</td>", temp); } if (gaschange) { len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s</b></td>", gasname(&newgasmix)); gaschange = false; } else { len += snprintf(buffer + len, sizeof(buffer) - len, "<td> </td>"); } len += snprintf(buffer + len, sizeof(buffer) - len, "</tr>"); lasttime = dp->time; } } if (gaschange) { // gas switch at this waypoint if (plan_verbatim) { snprintf(temp, sizeof(temp), translate("gettextFromC", "Switch gas to %s"), gasname(&newgasmix)); len += snprintf(buffer + len, sizeof(buffer) - len, "%s<br>", temp); gaschange = false; } gasmix = newgasmix; } lastdepth = dp->depth; } while ((dp = nextdp) != NULL); len += snprintf(buffer + len, sizeof(buffer) - len, "</tbody></table></div>"); dive->cns = 0; dive->maxcns = 0; update_cylinder_related_info(dive); snprintf(temp, sizeof(temp), "%s", translate("gettextFromC", "CNS")); len += snprintf(buffer + len, sizeof(buffer) - len, "<div><br>%s: %i%%", temp, dive->cns); snprintf(temp, sizeof(temp), "%s", translate("gettextFromC", "OTU")); len += snprintf(buffer + len, sizeof(buffer) - len, "<br>%s: %i</div>", temp, dive->otu); snprintf(temp, sizeof(temp), "%s", translate("gettextFromC", "Gas consumption:")); len += snprintf(buffer + len, sizeof(buffer) - len, "<div><br>%s<br>", temp); for (int gasidx = 0; gasidx < MAX_CYLINDERS; gasidx++) { double volume, pressure, deco_volume, deco_pressure; const char *unit, *pressure_unit; char warning[1000] = ""; cylinder_t *cyl = &dive->cylinder[gasidx]; if (cylinder_none(cyl)) break; volume = get_volume_units(cyl->gas_used.mliter, NULL, &unit); deco_volume = get_volume_units(cyl->deco_gas_used.mliter, NULL, &unit); if (cyl->type.size.mliter) { deco_pressure = get_pressure_units(1000.0 * cyl->deco_gas_used.mliter / cyl->type.size.mliter, &pressure_unit); pressure = get_pressure_units(1000.0 * cyl->gas_used.mliter / cyl->type.size.mliter, &pressure_unit); /* Warn if the plan uses more gas than is available in a cylinder * This only works if we have working pressure for the cylinder * 10bar is a made up number - but it seemed silly to pretend you could breathe cylinder down to 0 */ if (cyl->end.mbar < 10000) snprintf(warning, sizeof(warning), " — <span style='color: red;'>%s </span> %s", translate("gettextFromC", "Warning:"), translate("gettextFromC", "this is more gas than available in the specified cylinder!")); else if ((float) cyl->end.mbar * cyl->type.size.mliter / 1000.0 < (float) cyl->deco_gas_used.mliter) snprintf(warning, sizeof(warning), " — <span style='color: red;'>%s </span> %s", translate("gettextFromC", "Warning:"), translate("gettextFromC", "not enough reserve for gas sharing on ascent!")); snprintf(temp, sizeof(temp), translate("gettextFromC", "%.0f%s/%.0f%s of %s (%.0f%s/%.0f%s in planned ascent)"), volume, unit, pressure, pressure_unit, gasname(&cyl->gasmix), deco_volume, unit, deco_pressure, pressure_unit); } else { snprintf(temp, sizeof(temp), translate("gettextFromC", "%.0f%s (%.0f%s during planned ascent) of %s"), volume, unit, deco_volume, unit, gasname(&cyl->gasmix)); } len += snprintf(buffer + len, sizeof(buffer) - len, "%s%s<br>", temp, warning); } dp = diveplan->dp; while (dp) { if (dp->time != 0) { int pO2 = depth_to_atm(dp->depth, dive) * get_o2(&dp->gasmix); if (pO2 > (dp->entered ? prefs.bottompo2 : prefs.decopo2)) { const char *depth_unit; int decimals; double depth_value = get_depth_units(dp->depth, &decimals, &depth_unit); len = strlen(buffer); snprintf(temp, sizeof(temp), translate("gettextFromC", "high pO₂ value %.2f at %d:%02u with gas %s at depth %.*f %s"), pO2 / 1000.0, FRACTION(dp->time, 60), gasname(&dp->gasmix), decimals, depth_value, depth_unit); len += snprintf(buffer + len, sizeof(buffer) - len, "<span style='color: red;'>%s </span> %s<br>", translate("gettextFromC", "Warning:"), temp); } } dp = dp->next; } snprintf(buffer + len, sizeof(buffer) - len, "</div>"); dive->notes = strdup(buffer); }
void show_dive_stats(struct dive *dive) { char buf[80]; double value; int decimals; const char *unit; int idx, offset, gas_used; struct dive *prev_dive; struct tm *tm; process_all_dives(dive, &prev_dive); tm = gmtime(&dive->when); snprintf(buf, sizeof(buf), "%s, %s %d, %d %2d:%02d", weekday(tm->tm_wday), monthname(tm->tm_mon), tm->tm_mday, tm->tm_year + 1900, tm->tm_hour, tm->tm_min); set_label(info_stat_w.date, buf); set_label(info_stat_w.dive_time, "%d min", (dive->duration.seconds + 30) / 60); if (prev_dive) set_label(info_stat_w.surf_intv, get_time_string(dive->when - (prev_dive->when + prev_dive->duration.seconds), 4)); else set_label(info_stat_w.surf_intv, "unknown"); value = get_depth_units(dive->maxdepth.mm, &decimals, &unit); set_label(info_stat_w.max_depth, "%.*f %s", decimals, value, unit); value = get_depth_units(dive->meandepth.mm, &decimals, &unit); set_label(info_stat_w.avg_depth, "%.*f %s", decimals, value, unit); if (dive->watertemp.mkelvin) { value = get_temp_units(dive->watertemp.mkelvin, &unit); set_label(info_stat_w.water_temp, "%.1f %s", value, unit); } else set_label(info_stat_w.water_temp, ""); value = get_volume_units(dive->sac, &decimals, &unit); if (value > 0) { set_label(info_stat_w.sac, "%.*f %s/min", decimals, value, unit); } else set_label(info_stat_w.sac, ""); set_label(info_stat_w.otu, "%d", dive->otu); offset = 0; gas_used = 0; buf[0] = '\0'; /* for the O2/He readings just create a list of them */ for (idx = 0; idx < MAX_CYLINDERS; idx++) { cylinder_t *cyl = &dive->cylinder[idx]; unsigned int start, end; start = cyl->start.mbar ? : cyl->sample_start.mbar; end = cyl->end.mbar ? : cyl->sample_end.mbar; /* we assume that every valid cylinder has either a working pressure * or a size; but for good measure let's also accept cylinders with * a starting or ending pressure*/ if (cyl->type.workingpressure.mbar || cyl->type.size.mliter || start || end) { /* 0% O2 strangely means air, so 21% - I don't like that at all */ int o2 = cyl->gasmix.o2.permille ? : 209; if (offset > 0) { snprintf(buf+offset, 80-offset, ", "); offset += 2; } snprintf(buf+offset, 80-offset, "%d/%d", (o2 + 5) / 10, (cyl->gasmix.he.permille + 5) / 10); offset = strlen(buf); } /* and if we have size, start and end pressure, we can * calculate the total gas used */ if (cyl->type.size.mliter && start && end) gas_used += cyl->type.size.mliter / 1000.0 * (start - end); }
static void plot_string(struct plot_info *pi, struct plot_data *entry, struct membuffer *b, bool has_ndl) { int pressurevalue, mod, ead, end, eadd; const char *depth_unit, *pressure_unit, *temp_unit, *vertical_speed_unit; double depthvalue, tempvalue, speedvalue, sacvalue; int decimals; const char *unit; depthvalue = get_depth_units(entry->depth, NULL, &depth_unit); put_format(b, translate("gettextFromC", "@: %d:%02d\nD: %.1f%s\n"), FRACTION(entry->sec, 60), depthvalue, depth_unit); if (GET_PRESSURE(entry)) { pressurevalue = get_pressure_units(GET_PRESSURE(entry), &pressure_unit); put_format(b, translate("gettextFromC", "P: %d%s\n"), pressurevalue, pressure_unit); } if (entry->temperature) { tempvalue = get_temp_units(entry->temperature, &temp_unit); put_format(b, translate("gettextFromC", "T: %.1f%s\n"), tempvalue, temp_unit); } speedvalue = get_vertical_speed_units(abs(entry->speed), NULL, &vertical_speed_unit); /* Ascending speeds are positive, descending are negative */ if (entry->speed > 0) speedvalue *= -1; put_format(b, translate("gettextFromC", "V: %.1f%s\n"), speedvalue, vertical_speed_unit); sacvalue = get_volume_units(entry->sac, &decimals, &unit); if (entry->sac && prefs.show_sac) put_format(b, translate("gettextFromC", "SAC: %.*f%s/min\n"), decimals, sacvalue, unit); if (entry->cns) put_format(b, translate("gettextFromC", "CNS: %u%%\n"), entry->cns); if (prefs.pp_graphs.po2) put_format(b, translate("gettextFromC", "pO%s: %.2fbar\n"), UTF8_SUBSCRIPT_2, entry->pressures.o2); if (prefs.pp_graphs.pn2) put_format(b, translate("gettextFromC", "pN%s: %.2fbar\n"), UTF8_SUBSCRIPT_2, entry->pressures.n2); if (prefs.pp_graphs.phe) put_format(b, translate("gettextFromC", "pHe: %.2fbar\n"), entry->pressures.he); if (prefs.mod) { mod = (int)get_depth_units(entry->mod, NULL, &depth_unit); put_format(b, translate("gettextFromC", "MOD: %d%s\n"), mod, depth_unit); } eadd = (int)get_depth_units(entry->eadd, NULL, &depth_unit); if (prefs.ead) { switch (pi->dive_type) { case NITROX: ead = (int)get_depth_units(entry->ead, NULL, &depth_unit); put_format(b, translate("gettextFromC", "EAD: %d%s\nEADD: %d%s\n"), ead, depth_unit, eadd, depth_unit); break; case TRIMIX: end = (int)get_depth_units(entry->end, NULL, &depth_unit); put_format(b, translate("gettextFromC", "END: %d%s\nEADD: %d%s\n"), end, depth_unit, eadd, depth_unit); break; case AIR: case FREEDIVING: /* nothing */ break; } } if (entry->stopdepth) { depthvalue = get_depth_units(entry->stopdepth, NULL, &depth_unit); if (entry->ndl) { /* this is a safety stop as we still have ndl */ if (entry->stoptime) put_format(b, translate("gettextFromC", "Safetystop: %umin @ %.0f%s\n"), DIV_UP(entry->stoptime, 60), depthvalue, depth_unit); else put_format(b, translate("gettextFromC", "Safetystop: unkn time @ %.0f%s\n"), depthvalue, depth_unit); } else { /* actual deco stop */ if (entry->stoptime) put_format(b, translate("gettextFromC", "Deco: %umin @ %.0f%s\n"), DIV_UP(entry->stoptime, 60), depthvalue, depth_unit); else put_format(b, translate("gettextFromC", "Deco: unkn time @ %.0f%s\n"), depthvalue, depth_unit); } } else if (entry->in_deco) { put_string(b, translate("gettextFromC", "In deco\n")); } else if (has_ndl) { put_format(b, translate("gettextFromC", "NDL: %umin\n"), DIV_UP(entry->ndl, 60)); } if (entry->tts) put_format(b, translate("gettextFromC", "TTS: %umin\n"), DIV_UP(entry->tts, 60)); if (entry->stopdepth_calc && entry->stoptime_calc) { depthvalue = get_depth_units(entry->stopdepth_calc, NULL, &depth_unit); put_format(b, translate("gettextFromC", "Deco: %umin @ %.0f%s (calc)\n"), DIV_UP(entry->stoptime_calc, 60), depthvalue, depth_unit); } else if (entry->in_deco_calc) { /* This means that we have no NDL left, * and we have no deco stop, * so if we just accend to the surface slowly * (ascent_mm_per_step / ascent_s_per_step) * everything will be ok. */ put_string(b, translate("gettextFromC", "In deco (calc)\n")); } else if (prefs.calcndltts && entry->ndl_calc != 0) { if(entry->ndl_calc < MAX_PROFILE_DECO) put_format(b, translate("gettextFromC", "NDL: %umin (calc)\n"), DIV_UP(entry->ndl_calc, 60)); else put_format(b, "%s", translate("gettextFromC", "NDL: >2h (calc)\n")); } if (entry->tts_calc) { if (entry->tts_calc < MAX_PROFILE_DECO) put_format(b, translate("gettextFromC", "TTS: %umin (calc)\n"), DIV_UP(entry->tts_calc, 60)); else put_format(b, "%s", translate("gettextFromC", "TTS: >2h (calc)\n")); } if (entry->rbt) put_format(b, translate("gettextFromC", "RBT: %umin\n"), DIV_UP(entry->rbt, 60)); if (entry->ceiling) { depthvalue = get_depth_units(entry->ceiling, NULL, &depth_unit); put_format(b, translate("gettextFromC", "Calculated ceiling %.0f%s\n"), depthvalue, depth_unit); if (prefs.calcalltissues) { int k; for (k = 0; k < 16; k++) { if (entry->ceilings[k]) { depthvalue = get_depth_units(entry->ceilings[k], NULL, &depth_unit); put_format(b, translate("gettextFromC", "Tissue %.0fmin: %.1f%s\n"), buehlmann_N2_t_halflife[k], depthvalue, depth_unit); } } } } if (entry->heartbeat && prefs.hrgraph) put_format(b, translate("gettextFromC", "heartbeat: %d\n"), entry->heartbeat); if (entry->bearing) put_format(b, translate("gettextFromC", "bearing: %d\n"), entry->bearing); if (entry->running_sum) { depthvalue = get_depth_units(entry->running_sum / entry->sec, NULL, &depth_unit); put_format(b, translate("gettextFromC", "mean depth to here %.1f%s\n"), depthvalue, depth_unit); } strip_mb(b); }
static void show_single_dive_stats(struct dive *dive) { char buf[80]; double value; int decimals; const char *unit; int idx, offset, gas_used; struct dive *prev_dive; struct tm tm; process_all_dives(dive, &prev_dive); utc_mkdate(dive->when, &tm); snprintf(buf, sizeof(buf), /*++GETTEXT 80 chars: weekday, monthname, day, year, hour, min */ _("%1$s, %2$s %3$d, %4$d %5$2d:%6$02d"), weekday(tm.tm_wday), monthname(tm.tm_mon), tm.tm_mday, tm.tm_year + 1900, tm.tm_hour, tm.tm_min); set_label(single_w.date, buf); set_label(single_w.dive_time, _("%d min"), (dive->duration.seconds + 30) / 60); if (prev_dive) set_label(single_w.surf_intv, get_time_string(dive->when - (prev_dive->when + prev_dive->duration.seconds), 4)); else set_label(single_w.surf_intv, _("unknown")); value = get_depth_units(dive->maxdepth.mm, &decimals, &unit); set_label(single_w.max_depth, "%.*f %s", decimals, value, unit); value = get_depth_units(dive->meandepth.mm, &decimals, &unit); set_label(single_w.avg_depth, "%.*f %s", decimals, value, unit); if (dive->watertemp.mkelvin) { value = get_temp_units(dive->watertemp.mkelvin, &unit); set_label(single_w.water_temp, "%.1f %s", value, unit); } else set_label(single_w.water_temp, ""); value = get_volume_units(dive->sac, &decimals, &unit); if (value > 0) { set_label(single_w.sac, _("%.*f %s/min"), decimals, value, unit); } else set_label(single_w.sac, ""); set_label(single_w.otu, "%d", dive->otu); offset = 0; gas_used = 0; buf[0] = '\0'; /* for the O2/He readings just create a list of them */ for (idx = 0; idx < MAX_CYLINDERS; idx++) { cylinder_t *cyl = &dive->cylinder[idx]; unsigned int start, end; start = cyl->start.mbar ? : cyl->sample_start.mbar; end = cyl->end.mbar ? : cyl->sample_end.mbar; if (!cylinder_none(cyl)) { /* 0% O2 strangely means air, so 21% - I don't like that at all */ int o2 = cyl->gasmix.o2.permille ? : AIR_PERMILLE; if (offset > 0) { snprintf(buf+offset, 80-offset, ", "); offset += 2; } snprintf(buf+offset, 80-offset, "%d/%d", (o2 + 5) / 10, (cyl->gasmix.he.permille + 5) / 10); offset = strlen(buf); } /* and if we have size, start and end pressure, we can * calculate the total gas used */ if (cyl->type.size.mliter && start && end) gas_used += cyl->type.size.mliter / 1000.0 * (start - end); }
QVariant DiveItem::data(int column, int role) const { QVariant retVal; struct dive *dive = get_dive_by_uniq_id(diveId); if (!dive) return QVariant(); switch (role) { case Qt::TextAlignmentRole: retVal = dive_table_alignment(column); break; case DiveTripModel::SORT_ROLE: Q_ASSERT(dive != NULL); switch (column) { case NR: retVal = (qulonglong)dive->when; break; case DATE: retVal = (qulonglong)dive->when; break; case RATING: retVal = dive->rating; break; case DEPTH: retVal = dive->maxdepth.mm; break; case DURATION: retVal = dive->duration.seconds; break; case TEMPERATURE: retVal = dive->watertemp.mkelvin; break; case TOTALWEIGHT: retVal = total_weight(dive); break; case SUIT: retVal = QString(dive->suit); break; case CYLINDER: retVal = QString(dive->cylinder[0].type.description); break; case GAS: retVal = nitrox_sort_value(dive); break; case SAC: retVal = dive->sac; break; case OTU: retVal = dive->otu; break; case MAXCNS: retVal = dive->maxcns; break; case LOCATION: retVal = QString(get_dive_location(dive)); break; } break; case Qt::DisplayRole: Q_ASSERT(dive != NULL); switch (column) { case NR: retVal = dive->number; break; case DATE: retVal = displayDate(); break; case DEPTH: retVal = displayDepth(); break; case DURATION: retVal = displayDuration(); break; case TEMPERATURE: retVal = displayTemperature(); break; case TOTALWEIGHT: retVal = displayWeight(); break; case SUIT: retVal = QString(dive->suit); break; case CYLINDER: retVal = QString(dive->cylinder[0].type.description); break; case SAC: retVal = displaySac(); break; case OTU: retVal = dive->otu; break; case MAXCNS: retVal = dive->maxcns; break; case LOCATION: retVal = QString(get_dive_location(dive)); break; case GAS: const char *gas_string = get_dive_gas_string(dive); retVal = QString(gas_string); free((void*)gas_string); break; } break; case Qt::DecorationRole: if (column == LOCATION) if (dive_has_gps_location(dive)) { IconMetrics im = defaultIconMetrics(); retVal = QIcon(":satellite").pixmap(im.sz_small, im.sz_small); } break; case Qt::ToolTipRole: switch (column) { case NR: retVal = tr("#"); break; case DATE: retVal = tr("Date"); break; case RATING: retVal = tr("Rating"); break; case DEPTH: retVal = tr("Depth(%1)").arg((get_units()->length == units::METERS) ? tr("m") : tr("ft")); break; case DURATION: retVal = tr("Duration"); break; case TEMPERATURE: retVal = tr("Temp(%1%2)").arg(UTF8_DEGREE).arg((get_units()->temperature == units::CELSIUS) ? "C" : "F"); break; case TOTALWEIGHT: retVal = tr("Weight(%1)").arg((get_units()->weight == units::KG) ? tr("kg") : tr("lbs")); break; case SUIT: retVal = tr("Suit"); break; case CYLINDER: retVal = tr("Cyl"); break; case GAS: retVal = tr("Gas"); break; case SAC: const char *unit; get_volume_units(0, NULL, &unit); retVal = tr("SAC(%1)").arg(QString(unit).append(tr("/min"))); break; case OTU: retVal = tr("OTU"); break; case MAXCNS: retVal = tr("Max CNS"); break; case LOCATION: retVal = tr("Location"); break; } break; } if (role == DiveTripModel::STAR_ROLE) { Q_ASSERT(dive != NULL); retVal = dive->rating; } if (role == DiveTripModel::DIVE_ROLE) { retVal = QVariant::fromValue<void *>(dive); } if (role == DiveTripModel::DIVE_IDX) { Q_ASSERT(dive != NULL); retVal = get_divenr(dive); } return retVal; }
QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation, int role) const { QVariant ret; if (orientation == Qt::Vertical) return ret; switch (role) { case Qt::TextAlignmentRole: ret = dive_table_alignment(section); break; case Qt::FontRole: ret = defaultModelFont(); break; case Qt::DisplayRole: switch (section) { case NR: ret = tr("#"); break; case DATE: ret = tr("Date"); break; case RATING: ret = tr("Rating"); break; case DEPTH: ret = tr("Depth"); break; case DURATION: ret = tr("Duration"); break; case TEMPERATURE: ret = tr("Temp"); break; case TOTALWEIGHT: ret = tr("Weight"); break; case SUIT: ret = tr("Suit"); break; case CYLINDER: ret = tr("Cyl"); break; case GAS: ret = tr("Gas"); break; case SAC: ret = tr("SAC"); break; case OTU: ret = tr("OTU"); break; case MAXCNS: ret = tr("Max CNS"); break; case LOCATION: ret = tr("Location"); break; } break; case Qt::ToolTipRole: switch (section) { case NR: ret = tr("#"); break; case DATE: ret = tr("Date"); break; case RATING: ret = tr("Rating"); break; case DEPTH: ret = tr("Depth(%1)").arg((get_units()->length == units::METERS) ? tr("m") : tr("ft")); break; case DURATION: ret = tr("Duration"); break; case TEMPERATURE: ret = tr("Temp(%1%2)").arg(UTF8_DEGREE).arg((get_units()->temperature == units::CELSIUS) ? "C" : "F"); break; case TOTALWEIGHT: ret = tr("Weight(%1)").arg((get_units()->weight == units::KG) ? tr("kg") : tr("lbs")); break; case SUIT: ret = tr("Suit"); break; case CYLINDER: ret = tr("Cyl"); break; case GAS: ret = tr("Gas"); break; case SAC: const char *unit; get_volume_units(0, NULL, &unit); ret = tr("SAC(%1)").arg(QString(unit).append(tr("/min"))); break; case OTU: ret = tr("OTU"); break; case MAXCNS: ret = tr("Max CNS"); break; case LOCATION: ret = tr("Location"); break; } break; } return ret; }
/* we try to show the data from the currently selected divecomputer * right now for some values (e.g., surface pressure) we could fall back * to dive data, but for consistency we don't. */ static void show_single_dive_stats(struct dive *dive) { char buf[256]; double value; int decimals; const char *unit; int idx, offset, gas_used, mbar; struct dive *prev_dive; struct tm tm; struct divecomputer *dc; process_all_dives(dive, &prev_dive); if (!dive) return; dc = select_dc(&dive->dc); utc_mkdate(dive->when, &tm); snprintf(buf, sizeof(buf), /*++GETTEXT 80 chars: weekday, monthname, day, year, hour, min */ _("%1$s, %2$s %3$d, %4$d %5$2d:%6$02d"), weekday(tm.tm_wday), monthname(tm.tm_mon), tm.tm_mday, tm.tm_year + 1900, tm.tm_hour, tm.tm_min); set_label(single_w.date, buf); set_label(single_w.dive_time, _("%d min"), (dive->duration.seconds + 30) / 60); if (prev_dive) set_label(single_w.surf_intv, get_time_string(dive->when - (prev_dive->when + prev_dive->duration.seconds), 4)); else set_label(single_w.surf_intv, _("unknown")); value = get_depth_units(dc->maxdepth.mm, &decimals, &unit); set_label(single_w.max_depth, "%.*f %s", decimals, value, unit); value = get_depth_units(dc->meandepth.mm, &decimals, &unit); set_label(single_w.avg_depth, "%.*f %s", decimals, value, unit); set_label(single_w.viz, star_strings[dive->visibility]); if (dc->watertemp.mkelvin) { value = get_temp_units(dc->watertemp.mkelvin, &unit); set_label(single_w.water_temp, "%.1f %s", value, unit); } else { set_label(single_w.water_temp, ""); } if (dc->airtemp.mkelvin) { value = get_temp_units(dc->airtemp.mkelvin, &unit); set_label(single_w.air_temp, "%.1f %s", value, unit); } else { if (dive->airtemp.mkelvin) { value = get_temp_units(dive->airtemp.mkelvin, &unit); set_label(single_w.air_temp, "%.1f %s", value, unit); } else { set_label(single_w.air_temp, ""); } } mbar = dc->surface_pressure.mbar; /* it would be easy to get dive data here: * if (!mbar) * mbar = get_surface_pressure_in_mbar(dive, FALSE); */ if (mbar) { set_label(single_w.air_press, "%d mbar", mbar); } else { set_label(single_w.air_press, ""); } value = get_volume_units(dive->sac, &decimals, &unit); if (value > 0) set_label(single_w.sac, _("%.*f %s/min"), decimals, value, unit); else set_label(single_w.sac, ""); set_label(single_w.otu, "%d", dive->otu); offset = 0; gas_used = 0; buf[0] = '\0'; /* for the O2/He readings just create a list of them */ for (idx = 0; idx < MAX_CYLINDERS; idx++) { cylinder_t *cyl = &dive->cylinder[idx]; pressure_t start, end; start = cyl->start.mbar ? cyl->start : cyl->sample_start; end = cyl->end.mbar ?cyl->sample_end : cyl->sample_end; if (!cylinder_none(cyl)) { /* 0% O2 strangely means air, so 21% - I don't like that at all */ int o2 = get_o2(&cyl->gasmix); int he = get_he(&cyl->gasmix); if (offset > 0) { snprintf(buf+offset, 80-offset, ", "); offset += 2; } snprintf(buf+offset, 80-offset, "%d/%d", (o2 + 5) / 10, (he + 5) / 10); offset = strlen(buf); } /* and if we have size, start and end pressure, we can * calculate the total gas used */ if (start.mbar && end.mbar) gas_used += gas_volume(cyl, start) - gas_volume(cyl, end); } set_label(single_w.o2he, buf); if (gas_used) { value = get_volume_units(gas_used, &decimals, &unit); set_label(single_w.gas_used, "%.*f %s", decimals, value, unit); } else { set_label(single_w.gas_used, ""); } }
QString get_volume_unit() { const char *unit; (void) get_volume_units(0, NULL, &unit); return QString(unit); }
static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error) { const unsigned int sz_buffer = 2000000; const unsigned int sz_temp = 100000; char *buffer = (char *)malloc(sz_buffer); char *temp = (char *)malloc(sz_temp); char buf[1000], *deco; int len, lastdepth = 0, lasttime = 0, lastsetpoint = -1, newdepth = 0, lastprintdepth = 0, lastprintsetpoint = -1; struct gasmix lastprintgasmix = { -1, -1 }; struct divedatapoint *dp = diveplan->dp; bool gaschange_after = !plan_verbatim; bool gaschange_before; bool lastentered; struct divedatapoint *nextdp = NULL; plan_verbatim = prefs.verbatim_plan; plan_display_runtime = prefs.display_runtime; plan_display_duration = prefs.display_duration; plan_display_transitions = prefs.display_transitions; if (prefs.deco_mode == VPMB) { deco = "VPM-B"; } else { deco = "BUHLMANN"; } snprintf(buf, sizeof(buf), translate("gettextFromC", "DISCLAIMER / WARNING: THIS IS A NEW IMPLEMENTATION OF THE %s " "ALGORITHM AND A DIVE PLANNER IMPLEMENTATION BASED ON THAT WHICH HAS " "RECEIVED ONLY A LIMITED AMOUNT OF TESTING. WE STRONGLY RECOMMEND NOT TO " "PLAN DIVES SIMPLY BASED ON THE RESULTS GIVEN HERE."), deco); disclaimer = buf; if (!dp) { free((void *)buffer); free((void *)temp); return; } if (error) { snprintf(temp, sz_temp, "%s", translate("gettextFromC", "Decompression calculation aborted due to excessive time")); snprintf(buffer, sz_buffer, "<span style='color: red;'>%s </span> %s<br>", translate("gettextFromC", "Warning:"), temp); dive->notes = strdup(buffer); free((void *)buffer); free((void *)temp); return; } len = show_disclaimer ? snprintf(buffer, sz_buffer, "<div><b>%s<b></div><br>", disclaimer) : 0; if (prefs.deco_mode == BUEHLMANN){ snprintf(temp, sz_temp, translate("gettextFromC", "based on Buhlmann ZHL-16B with GFlow = %d and GFhigh = %d"), diveplan->gflow, diveplan->gfhigh); } else if (prefs.deco_mode == VPMB){ snprintf(temp, sz_temp, "%s", translate("gettextFromC", "based on VPM-B")); } else if (prefs.deco_mode == RECREATIONAL){ snprintf(temp, sz_temp, translate("gettextFromC", "recreational mode based on Buhlmann ZHL-16B with GFlow = %d and GFhigh = %d"), diveplan->gflow, diveplan->gfhigh); } len += snprintf(buffer + len, sz_buffer - len, "<div><b>%s</b><br>%s</div><br>", translate("gettextFromC", "Subsurface dive plan"), temp); if (!plan_verbatim) { len += snprintf(buffer + len, sz_buffer - len, "<div><table><thead><tr><th>%s</th>", translate("gettextFromC", "depth")); if (plan_display_duration) len += snprintf(buffer + len, sz_buffer - len, "<th style='padding-left: 10px;'>%s</th>", translate("gettextFromC", "duration")); if (plan_display_runtime) len += snprintf(buffer + len, sz_buffer - len, "<th style='padding-left: 10px;'>%s</th>", translate("gettextFromC", "runtime")); len += snprintf(buffer + len, sz_buffer - len, "<th style='padding-left: 10px; float: left;'>%s</th></tr></thead><tbody style='float: left;'>", translate("gettextFromC", "gas")); } do { struct gasmix gasmix, newgasmix = {}; const char *depth_unit; double depthvalue; int decimals; bool isascent = (dp->depth < lastdepth); nextdp = dp->next; if (dp->time == 0) continue; gasmix = dp->gasmix; depthvalue = get_depth_units(dp->depth, &decimals, &depth_unit); /* analyze the dive points ahead */ while (nextdp && nextdp->time == 0) nextdp = nextdp->next; if (nextdp) newgasmix = nextdp->gasmix; gaschange_after = (nextdp && (gasmix_distance(&gasmix, &newgasmix) || dp->setpoint != nextdp->setpoint)); gaschange_before = (gasmix_distance(&lastprintgasmix, &gasmix) || lastprintsetpoint != dp->setpoint); /* do we want to skip this leg as it is devoid of anything useful? */ if (!dp->entered && nextdp && dp->depth != lastdepth && nextdp->depth != dp->depth && !gaschange_before && !gaschange_after) continue; if (dp->time - lasttime < 10 && !(gaschange_after && dp->next && dp->depth != dp->next->depth)) continue; len = strlen(buffer); if (plan_verbatim) { /* When displaying a verbatim plan, we output a waypoint for every gas change. * Therefore, we do not need to test for difficult cases that mean we need to * print a segment just so we don't miss a gas change. This makes the logic * to determine whether or not to print a segment much simpler than with the * non-verbatim plan. */ if (dp->depth != lastprintdepth) { if (plan_display_transitions || dp->entered || !dp->next || (gaschange_after && dp->next && dp->depth != nextdp->depth)) { if (dp->setpoint) snprintf(temp, sz_temp, translate("gettextFromC", "Transition to %.*f %s in %d:%02d min - runtime %d:%02u on %s (SP = %.1fbar)"), decimals, depthvalue, depth_unit, FRACTION(dp->time - lasttime, 60), FRACTION(dp->time, 60), gasname(&gasmix), (double) dp->setpoint / 1000.0); else snprintf(temp, sz_temp, translate("gettextFromC", "Transition to %.*f %s in %d:%02d min - runtime %d:%02u on %s"), decimals, depthvalue, depth_unit, FRACTION(dp->time - lasttime, 60), FRACTION(dp->time, 60), gasname(&gasmix)); len += snprintf(buffer + len, sz_buffer - len, "%s<br>", temp); } newdepth = dp->depth; lasttime = dp->time; } else { if ((nextdp && dp->depth != nextdp->depth) || gaschange_after) { if (dp->setpoint) snprintf(temp, sz_temp, translate("gettextFromC", "Stay at %.*f %s for %d:%02d min - runtime %d:%02u on %s (SP = %.1fbar)"), decimals, depthvalue, depth_unit, FRACTION(dp->time - lasttime, 60), FRACTION(dp->time, 60), gasname(&gasmix), (double) dp->setpoint / 1000.0); else snprintf(temp, sz_temp, translate("gettextFromC", "Stay at %.*f %s for %d:%02d min - runtime %d:%02u on %s"), decimals, depthvalue, depth_unit, FRACTION(dp->time - lasttime, 60), FRACTION(dp->time, 60), gasname(&gasmix)); len += snprintf(buffer + len, sz_buffer - len, "%s<br>", temp); newdepth = dp->depth; lasttime = dp->time; } } } else { /* When not displaying the verbatim dive plan, we typically ignore ascents between deco stops, * unless the display transitions option has been selected. We output a segment if any of the * following conditions are met. * 1) Display transitions is selected * 2) The segment was manually entered * 3) It is the last segment of the dive * 4) The segment is not an ascent, there was a gas change at the start of the segment and the next segment * is a change in depth (typical deco stop) * 5) There is a gas change at the end of the segment and the last segment was entered (first calculated * segment if it ends in a gas change) * 6) There is a gaschange after but no ascent. This should only occur when backgas breaks option is selected * 7) It is an ascent ending with a gas change, but is not followed by a stop. As case 5 already matches * the first calculated ascent if it ends with a gas change, this should only occur if a travel gas is * used for a calculated ascent, there is a subsequent gas change before the first deco stop, and zero * time has been allowed for a gas switch. */ if (plan_display_transitions || dp->entered || !dp->next || (nextdp && dp->depth != nextdp->depth) || (!isascent && gaschange_before && nextdp && dp->depth != nextdp->depth) || (gaschange_after && lastentered) || (gaschange_after && !isascent) || (isascent && gaschange_after && nextdp && dp->depth != nextdp->depth )) { snprintf(temp, sz_temp, translate("gettextFromC", "%3.0f%s"), depthvalue, depth_unit); len += snprintf(buffer + len, sz_buffer - len, "<tr><td style='padding-left: 10px; float: right;'>%s</td>", temp); if (plan_display_duration) { snprintf(temp, sz_temp, translate("gettextFromC", "%3dmin"), (dp->time - lasttime + 30) / 60); len += snprintf(buffer + len, sz_buffer - len, "<td style='padding-left: 10px; float: right;'>%s</td>", temp); } if (plan_display_runtime) { snprintf(temp, sz_temp, translate("gettextFromC", "%3dmin"), (dp->time + 30) / 60); len += snprintf(buffer + len, sz_buffer - len, "<td style='padding-left: 10px; float: right;'>%s</td>", temp); } /* Normally a gas change is displayed on the stopping segment, so only display a gas change at the end of * an ascent segment if it is not followed by a stop */ if (isascent && gaschange_after && dp->next && nextdp && dp->depth != nextdp->depth) { if (dp->setpoint) { snprintf(temp, sz_temp, translate("gettextFromC", "(SP = %.1fbar)"), (double) nextdp->setpoint / 1000.0); len += snprintf(buffer + len, sz_buffer - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s %s</b></td>", gasname(&newgasmix), temp); } else { len += snprintf(buffer + len, sz_buffer - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s</b></td>", gasname(&newgasmix)); } lastprintsetpoint = nextdp->setpoint; lastprintgasmix = newgasmix; gaschange_after = false; } else if (gaschange_before) { // If a new gas has been used for this segment, now is the time to show it if (dp->setpoint) { snprintf(temp, sz_temp, translate("gettextFromC", "(SP = %.1fbar)"), (double) dp->setpoint / 1000.0); len += snprintf(buffer + len, sz_buffer - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s %s</b></td>", gasname(&gasmix), temp); } else { len += snprintf(buffer + len, sz_buffer - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s</b></td>", gasname(&gasmix)); } // Set variables so subsequent iterations can test against the last gas printed lastprintsetpoint = dp->setpoint; lastprintgasmix = gasmix; gaschange_after = false; } else { len += snprintf(buffer + len, sz_buffer - len, "<td> </td>"); } len += snprintf(buffer + len, sz_buffer - len, "</tr>"); newdepth = dp->depth; lasttime = dp->time; } } if (gaschange_after) { // gas switch at this waypoint if (plan_verbatim) { if (lastsetpoint >= 0) { if (nextdp && nextdp->setpoint) snprintf(temp, sz_temp, translate("gettextFromC", "Switch gas to %s (SP = %.1fbar)"), gasname(&newgasmix), (double) nextdp->setpoint / 1000.0); else snprintf(temp, sz_temp, translate("gettextFromC", "Switch gas to %s"), gasname(&newgasmix)); len += snprintf(buffer + len, sz_buffer - len, "%s<br>", temp); } gaschange_after = false; gasmix = newgasmix; } } lastprintdepth = newdepth; lastdepth = dp->depth; lastsetpoint = dp->setpoint; lastentered = dp->entered; } while ((dp = nextdp) != NULL); len += snprintf(buffer + len, sz_buffer - len, "</tbody></table></div>"); dive->cns = 0; dive->maxcns = 0; update_cylinder_related_info(dive); snprintf(temp, sz_temp, "%s", translate("gettextFromC", "CNS")); len += snprintf(buffer + len, sz_buffer - len, "<div><br>%s: %i%%", temp, dive->cns); snprintf(temp, sz_temp, "%s", translate("gettextFromC", "OTU")); len += snprintf(buffer + len, sz_buffer - len, "<br>%s: %i</div>", temp, dive->otu); if (dive->dc.divemode == CCR) snprintf(temp, sz_temp, "%s", translate("gettextFromC", "Gas consumption (CCR legs excluded):")); else snprintf(temp, sz_temp, "%s", translate("gettextFromC", "Gas consumption:")); len += snprintf(buffer + len, sz_buffer - len, "<div><br>%s<br>", temp); for (int gasidx = 0; gasidx < MAX_CYLINDERS; gasidx++) { double volume, pressure, deco_volume, deco_pressure; const char *unit, *pressure_unit; char warning[1000] = ""; cylinder_t *cyl = &dive->cylinder[gasidx]; if (cylinder_none(cyl)) break; volume = get_volume_units(cyl->gas_used.mliter, NULL, &unit); deco_volume = get_volume_units(cyl->deco_gas_used.mliter, NULL, &unit); if (cyl->type.size.mliter) { deco_pressure = get_pressure_units(1000.0 * cyl->deco_gas_used.mliter / cyl->type.size.mliter, &pressure_unit); pressure = get_pressure_units(1000.0 * cyl->gas_used.mliter / cyl->type.size.mliter, &pressure_unit); /* Warn if the plan uses more gas than is available in a cylinder * This only works if we have working pressure for the cylinder * 10bar is a made up number - but it seemed silly to pretend you could breathe cylinder down to 0 */ if (cyl->end.mbar < 10000) snprintf(warning, sizeof(warning), " — <span style='color: red;'>%s </span> %s", translate("gettextFromC", "Warning:"), translate("gettextFromC", "this is more gas than available in the specified cylinder!")); else if ((float) cyl->end.mbar * cyl->type.size.mliter / 1000.0 < (float) cyl->deco_gas_used.mliter) snprintf(warning, sizeof(warning), " — <span style='color: red;'>%s </span> %s", translate("gettextFromC", "Warning:"), translate("gettextFromC", "not enough reserve for gas sharing on ascent!")); snprintf(temp, sz_temp, translate("gettextFromC", "%.0f%s/%.0f%s of %s (%.0f%s/%.0f%s in planned ascent)"), volume, unit, pressure, pressure_unit, gasname(&cyl->gasmix), deco_volume, unit, deco_pressure, pressure_unit); } else { snprintf(temp, sz_temp, translate("gettextFromC", "%.0f%s (%.0f%s during planned ascent) of %s"), volume, unit, deco_volume, unit, gasname(&cyl->gasmix)); } len += snprintf(buffer + len, sz_buffer - len, "%s%s<br>", temp, warning); } dp = diveplan->dp; if (dive->dc.divemode != CCR) { while (dp) { if (dp->time != 0) { struct gas_pressures pressures; fill_pressures(&pressures, depth_to_atm(dp->depth, dive), &dp->gasmix, 0.0, dive->dc.divemode); if (pressures.o2 > (dp->entered ? prefs.bottompo2 : prefs.decopo2) / 1000.0) { const char *depth_unit; int decimals; double depth_value = get_depth_units(dp->depth, &decimals, &depth_unit); len = strlen(buffer); snprintf(temp, sz_temp, translate("gettextFromC", "high pO₂ value %.2f at %d:%02u with gas %s at depth %.*f %s"), pressures.o2, FRACTION(dp->time, 60), gasname(&dp->gasmix), decimals, depth_value, depth_unit); len += snprintf(buffer + len, sz_buffer - len, "<span style='color: red;'>%s </span> %s<br>", translate("gettextFromC", "Warning:"), temp); } else if (pressures.o2 < 0.16) { const char *depth_unit; int decimals; double depth_value = get_depth_units(dp->depth, &decimals, &depth_unit); len = strlen(buffer); snprintf(temp, sz_temp, translate("gettextFromC", "low pO₂ value %.2f at %d:%02u with gas %s at depth %.*f %s"), pressures.o2, FRACTION(dp->time, 60), gasname(&dp->gasmix), decimals, depth_value, depth_unit); len += snprintf(buffer + len, sz_buffer - len, "<span style='color: red;'>%s </span> %s<br>", translate("gettextFromC", "Warning:"), temp); } } dp = dp->next; } } snprintf(buffer + len, sz_buffer - len, "</div>"); dive->notes = strdup(buffer); free((void *)buffer); free((void *)temp); }