return depth.mm * 0.00328084 + 0.5;
}
+static double mkelvin_to_C(int mkelvin)
+{
+ return (mkelvin - 273150) / 1000.0;
+}
+
+static double mkelvin_to_F(int mkelvin)
+{
+ return mkelvin * 9 / 5000.0 - 459.670;
+}
+
static inline int to_C(temperature_t temp)
{
if (!temp.mkelvin)
return 0;
- return (temp.mkelvin - 273150 + 499) / 1000;
+ return mkelvin_to_C(temp.mkelvin) + 0.5;
}
static inline int to_F(temperature_t temp)
{
if (!temp.mkelvin)
return 0;
- return temp.mkelvin * 9 / 5000.0 - 459.670 + 0.5;
+ return mkelvin_to_F(temp.mkelvin) + 0.5;
}
static inline int to_K(temperature_t temp)
repaint_dive();
}
+static void get_temp(struct dive *dive, int *val, char **str)
+{
+ int value = dive->watertemp.mkelvin;
+ char buffer[80];
+
+ *val = value;
+ *str = "";
+ if (value) {
+ double deg;
+ switch (output_units.temperature) {
+ case CELSIUS:
+ deg = mkelvin_to_C(value);
+ break;
+ case FAHRENHEIT:
+ deg = mkelvin_to_F(value);
+ break;
+ default:
+ return;
+ }
+ snprintf(buffer, sizeof(buffer), "%.1f", deg);
+ *str = strdup(buffer);
+ }
+}
+
+static void get_nitrox(struct dive *dive, int *val, char **str)
+{
+ int value = dive->cylinder[0].gasmix.o2.permille;
+ char buffer[80];
+
+ *val = value;
+ *str = "";
+ if (value) {
+ snprintf(buffer, sizeof(buffer), "%.1f", value/10.0);
+ *str = strdup(buffer);
+ }
+}
+
+static void get_sac(struct dive *dive, int *val, char **str)
+{
+ *val = 0;
+ *str = "";
+}
+
static gboolean set_one_dive(GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
char buffer[256], *datestr, *depth, *duration;
struct tm *tm;
int integer, frac;
+ int temp, nitrox, sac;
+ char *tempstr, *nitroxstr, *sacstr;
/* Get the dive number */
gtk_tree_model_get_value(model, iter, DIVE_INDEX, &value);
duration = malloc(len + 1);
memcpy(duration, buffer, len+1);
+ get_temp(dive, &temp, &tempstr);
+ get_nitrox(dive, &nitrox, &nitroxstr);
+ get_sac(dive, &sac, &sacstr);
+
/*
* We only set the fields that changed: the strings.
* The core data itself is unaffected by units
DIVE_DATESTR, datestr,
DIVE_DEPTHSTR, depth,
DIVE_DURATIONSTR, duration,
+ DIVE_TEMPSTR, tempstr,
+ DIVE_TEMP, temp,
+ DIVE_NITROXSTR, nitroxstr,
+ DIVE_NITROX, nitrox,
+ DIVE_SACSTR, sacstr,
+ DIVE_NITROX, sac,
-1);
return FALSE;
DIVE_DEPTH, dive->maxdepth,
DIVE_DURATIONSTR, "duration",
DIVE_DURATION, dive->duration.seconds,
+ DIVE_TEMPSTR, "temp",
+ DIVE_TEMP, dive->watertemp.mkelvin,
+ DIVE_NITROXSTR, "21.0",
+ DIVE_NITROX, dive->cylinder[0].gasmix.o2,
+ DIVE_SACSTR, "sac",
+ DIVE_SAC, 0,
-1);
}