The units(1) program is available on many Unix systems (though rarely
installed by default). Most people think of it as a simple interactive
converter. It's actually much more powerful than that.
This is how people expect to use it, entering things at an
interactive prompt:
$ units
You have: mile
You want: km
* 1.609344
/ 0.62137119
That's useful but very dull. Functions are slightly more promising:
$ units
You have: tempF(98.4)
You want: tempC
36.888889
But it also works with pure command-line arguments, potentially of
some complexity - which of course allows it to be a handy command-line
calculator too. Atmospheric pressure in psi:
$ units atmosphere gravity*lb/inch^2
* 14.695949
/ 0.068045964
What time will my 3d print finish if I start it now?
$ units $(date +"%Hhour+%Mminute+%Ssecond")+8hour+19minute "hour;minute;second"
19 hour + 31 minute + 9 second
The blackbody temperature of a 100m-radius sphere radiating at 1MW
(yes, lots of physical constants are here too):
$ units "(1MW/stefanboltzmann/((100m^2)*4pi))^(1/4)" tempC
71.037224
If you're feeding the output into another programme (because this is
Unix and you can do that sort of thing), use --compact to strip off
the decoration:
$ units --compact "(1MW/stefanboltzmann/((100m^2)*4pi))^(1/4)" tempC
71.037224
Of course it's extensible. As someone who plays a fair bit of GURPS, I
find it useful to implement that game's logarithmic range scale, so I
add to my local .units file:
gurpsrange(x) units=[1;yard] range=[0,) \
10^((x+2)/6)*yard ; log(gurpsrange/yard)*6-2
and now I can easily calculate ranges for a space game:
$ units 5astronomicalunit gurpsrange
69.476555
$ units "gurpsrange(40)" mile
* 5681.8182
/ 0.000176
For any Torg players:
torgdistance(x) units=[1;metre] range=[0,) \
10^(x/5)*metre ; log(torgdistance/metre)*5
torgtime(x) units=[1;second] range=[0,) \
10^(x/5)*second ; log(torgtime/second)*5
torgweight(x) units=[1;kg] range=[0,) \
10^(x/5)*kg ; log(torgweight/kg)*5
torgspeed(x) units=[1;m/s] range=[0,) \
10^((x-5)/5)*m/s ; log(torgspeed*s/m)*5+5
Note that speed is not distance minus time as it should have been in a
cleanly-designed system, but based on metres per 10s combat round; thus
the fudge factor. What a pity.
Comments on this post are now closed. If you have particular grounds for adding a late comment, comment on a more recent post quoting the URL of this one.