From JDiveLog to Subsurface

Linus Torvalds torvalds at linux-foundation.org
Sun Nov 6 12:51:41 EST 2011


On Sun, Nov 6, 2011 at 3:31 AM, Miika Turkia <miika.turkia at gmail.com> wrote:
>
> BTW what is the logic of cylinder sizes in there? (I currently mark sizes
> less than 20 to be liters and others I put no units and subsurface seems to
> translate them to liters)

I can explain the subsurface logic, but for other imports there is
absolutely no logic to cylinder sizes. In my experience, they are
always incorrect in the xml files (except for the simple case of
Europeans using SI units).

The subsurface logic is very simple, actually: cylinder sizes are
*always* in "wet size" liters internally (well, ml, but we parse
liters from xml files). So the cylinder size is the actual physical
size of the interior of the cylinder ("how many liters of water could
I fill this cylinder with").

HOWEVER.

In the imperial unit world, people don't use "physical size of the
cylinder", but "how much air - in cubic feet - can I cram into the
cylinder at pressure". So while subsurface always internally maintains
the size in liters wet size, subsurface can *import* data in imperial
units, and you can set it to *show* data in imperial units.

However, the imperial units by definition require a working pressure
for the cylinder: because for them the "size" isn't just a physical
size, it's literally how much air *at*pressure*. So now you need to
know the working pressure for the cylinder in order for the cylinder
"size" in cuft to make sense.

So at the import layer, if you say that your tank has a size of "80",
and a working pressure of "3000 psi", then subsurface will import it
as an AL80, which is actually a 11.1 liter tank. It will do the math
for you, and it wll also allow this format to be edited in the
cylinder editing widget, but it's a pain in the royal arse to work
with. It's also very error prone - you really do need to make sure you
have the right size and pressure.

And everybody gets this wrong. For example, on Dirk's dive computer,
you can set the tank size on the computer itself, but the firmware was
written by Europeans, so they clearly didn't understand the crazy
imperial system (I can't really blame them, but still). So on his
computer, when you set the tank size in cuft, it just always assumes a
working pressure of 200 bar. Which is insane, because while that is
*close* to 3000 psi, it's not really a round unit in the imperial
system.

More importantly, it means that the sizing works (well, "works":
there's an error of 3% or so) only for the standard aluminum tanks at
3000 psi (which is *close* to 200 bar). I realize that Europe uses 200
bar fairly commonly, but in the US (and the countries that have been
influenced by US diving, which is most of the Americas and Asia) the
common steel tank pressures are low-pressure (2400 psi + 10%, and the
sizes are pretty universally computed using the "+10%" size) or high
pressure (3442 psi or 3500 psi -around 240 bar).

In other words: it's a complete mess. Suunto Dive Manager seems to
default the size for tanks to 12 l, probably because that's a very
common size in Europe. That size is pretty much unheard of in the US,
although a common "HP100" (100 cuft at 3442 psi) has pretty much the
same internal wet size (but a 12-liter tank at the standard 200 bar is
only 84 cuft in imperial air size - see how the pressure changes the
numbers for what is physically the same size! Crazy!).

Anyway, what subsurface does at import time is that *if* you have
"input_units.volume" set to CUFT *and* you have a number for both a
"size" and a "pressure", then we assume that those numbers are in
cuft, and we do the right size conversion for imperial, and turn it
internally into liters.

But the native subsurface import never gas input_units.volume set to
CUFT, so if you translate some other XML into native subsurface XML,
then you need to always translate into liters in your xslt transform.

The transform is fairly simple, see the sanitize_cylinder_type()
function in parse-xml.c. You translate the cuft to liters, then you
divide by the pressure in atmospheres. Which is how a 80cuft tank at
3000 psi becomes:

   80 cuft in cuft = 2265 liter
   3000 psi = 204 atm
   2265 / 204 = 11.1 l

Isn't that lovely?

                         Linus


More information about the subsurface mailing list