deco code rewrite

Dirk Hohndel dirk at hohndel.org
Wed Dec 5 14:54:21 PST 2012


Jan Schubert <Jan.Schubert at GMX.li> writes:

> On 12/05/12 23:40, Jan Schubert wrote:
>> On 12/05/12 23:28, Dirk Hohndel wrote:
>>> Dirk Hohndel <dirk at hohndel.org> writes:
>>>>> - also pO2, pN2 and pHe are wrong
>>>> that could be related to a similar libdivecomputer issue - assuming
>>>> there's something wrong with the gas mixes reported (or how we parse
>>>> them). 
>>> Oh, for that dive, could you check what is shown in the Equipment tab
>>> for Cylinders?
>> See screenshot attached, seems to be valid from my point of view.
>
> Sry, forgot to add: The pO2, pN2 and pHe seems to be calculated from the
> 91/0 bailout/deco gas while the dive list shows correct 8/70 has been used.

Err, no. Because of space constraints in the divelist we have a somewhat
creative algorithm of what we show there. I guess one could say that we
try to show the "manliest gas" :-)

/*
 * Get "maximal" dive gas for a dive.
 * Rules:
 *  - Trimix trumps nitrox (highest He wins, O2 breaks ties)
 *  - Nitrox trumps air (even if hypoxic)
 * These are the same rules as the inter-dive sorting rules.
 */
static void get_dive_gas(struct dive *dive, int *o2_p, int *he_p, int *o2low_p)
{
	int i;
	int maxo2 = -1, maxhe = -1, mino2 = 1000;

	for (i = 0; i < MAX_CYLINDERS; i++) {
		cylinder_t *cyl = dive->cylinder + i;
		struct gasmix *mix = &cyl->gasmix;
		int o2 = mix->o2.permille;
		int he = mix->he.permille;

		if (cylinder_none(cyl))
			continue;
		if (!o2)
			o2 = AIR_PERMILLE;
		if (o2 < mino2)
			mino2 = o2;
		if (he > maxhe)
			goto newmax;
		if (he < maxhe)
			continue;
		if (o2 <= maxo2)
			continue;
newmax:
		maxhe = he;
		maxo2 = o2;
	}
	/* All air? Show/sort as "air"/zero */
	if (!maxhe && maxo2 == AIR_PERMILLE && mino2 == maxo2)
		maxo2 = mino2 = 0;
	*o2_p = maxo2;
	*he_p = maxhe;
	*o2low_p = mino2;
}

and then later

static void nitrox_data_func(GtkTreeViewColumn *col,
			     GtkCellRenderer *renderer,
			     GtkTreeModel *model,
			     GtkTreeIter *iter,
			     gpointer data)
{
	int idx, o2, he, o2low;
	char buffer[80];
	struct dive *dive;

	gtk_tree_model_get(model, iter, DIVE_INDEX, &idx, -1);
	if (idx < 0) {
		*buffer = '\0';
		goto exit;
	}
	dive = get_dive(idx);
	get_dive_gas(dive, &o2, &he, &o2low);
	o2 = (o2 + 5) / 10;
	he = (he + 5) / 10;
	o2low = (o2low + 5) / 10;

	if (he)
		snprintf(buffer, sizeof(buffer), "%d/%d", o2, he);
	else if (o2)
		if (o2 == o2low)
			snprintf(buffer, sizeof(buffer), "%d", o2);
		else
			snprintf(buffer, sizeof(buffer), "%d" UTF8_ELLIPSIS "%d", o2low, o2);
	else
		strcpy(buffer, _("air"));
exit:
	g_object_set(renderer, "text", buffer, NULL);
}

So we show the trimix gas with the highest He that is in the gas
list. Otherwise we show the range of O2 values in the different
non-trimix mixes. So if you dive air as bottom gas and 70% O2 for deco
you get 21...70. But if any of your tanks contain He, then then one with
the highest He is the one that we display in the divelist.


But what this all means is that Subsurface doesn't catch on which tank
you were diving with...

/D


More information about the subsurface mailing list