uexpr is a Tcl package for calculating with units.
uexpr requires a fairly recent Tcl8.6
Some examples:
package require uexpr
uexpr 3ft + 8.56cm = m
returns 1.0 m (well actually 1.00...02 m)
Using package require uexpr=
loads the package and aliases uexpr to "=" so:
= 3in * 7in * 11in = in^3
returns 231.0 in^3
or
= 3in*7in*11in=gal
returns 1.0 gal
Acres in a square mile:
= 1mile^2=acre
returns 640.0 acre
Area of a circle with a given diameter:
set d 1in
= pi/4*d^2=in^2
returns 0.785398... in^2
pi is a built in constant, d is a Tcl variable
uexpr::unitNames returns a list of all units and constants currently available.
increase in temperature of water falling 1000 ft in an insulated pipe, given heat capacity of water and height it falls:
set Cpw "1 cal/gram degC"
set h 1000ft
= g*h/Cpw=degF
should return 1.285... degF. See notes on man page about absolute, biased and differential units (degF/degR degC/degK, absolute, gauge and differenial pressures).
uexpr requires a fairly recent version of Tcl8.6