One of the powerful convenience features provided by the LabRAD Manager is on-the-fly unit conversion. When registering an available setting, a server module can specify accepted units for incoming requests. The Manager will then seemlessly convert all (complex) values sent to this setting to match the requested units, or return an error if the given units can't be converted to the requested ones.
For a formal description, refer to the EBNF LabRAD Grammar.
The LabRAD Manager parses composite unit strings into their base components and respective fractional exponents. For example m/s^2 will get parsed into m with exponent 1 and s with exponent -2. This is done for the source unit string and the target unit string.
To find the conversion factor the Manager divides the source units by the target units. For this, the exponents of all base components in the target units are subtracted from the exponents in the source units. All base components that end up with exponent 0 are then dropped. Now, for the first time, the Manager tries to identify the base components and converts them to SI units. Therefore, you can specify units that the Manager does not know as long as they drop out during the division process above. The SI conversion factors then get raised to their corresponding exponents and multiplied together to yield the final conversion factor. The resulting quantity has to be unit-less for the conversion to succeed.
Unit | Source Exponent | Target Exponent |
TShirts | 1 | 1 |
min | -1 | 0 |
hr | 0 | -1 |
Unit | Src - Tgt | New Exponent | Action |
TShirts | 1 - 1 | 0 | drop |
min | (-1) - 0 | -1 | keep |
hr | 0 - (-1) | 1 | keep |
Exponent of | ||||||||||
Unit | Factor | m | kg | s | A | K | mol | cd | rad | sr |
min | 60 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
hr | 3600 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
New Exponent of | |||||||||||
Unit | Exponent | New Factor | m | kg | s | A | K | mol | cd | rad | sr |
min | -1 | 1/60 | 0 | 0 | -1 | 0 | 0 | 0 | 0 | 0 | 0 |
hr | 1 | 3600 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
Product | 60 | ||||||||||
Sum | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Since all exponents of the SI base units came out to be 0, the conversion succeeded and the conversion factor is 60, for example 5TShirts/min convert to 5 * 60 = 300TShirts/hr.
Notice that the conversion succeeded even though TShirts is not a unit that the Manager recognizes!
The Manager knows the following units:
Exponent of | |||||||||||
Unit | Factor | m | kg | s | A | K | mol | cd | rad | sr | Prefixable |
m | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
g | 0.001 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
s | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
A | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | yes |
K | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | yes |
mol | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | yes |
cd | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | yes |
rad | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | yes |
sr | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | yes |
Bq | 1 | 0 | 0 | -1 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
Ci | 3.7e10 | 0 | 0 | -1 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
acre | 4046.9 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | no |
a | 100 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
F | 1 | -2 | -1 | 4 | 2 | 0 | 0 | 0 | 0 | 0 | yes |
C | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | yes |
S | 1 | -2 | -1 | 3 | 2 | 0 | 0 | 0 | 0 | 0 | yes |
V | 1 | 2 | 1 | -3 | -1 | 0 | 0 | 0 | 0 | 0 | yes |
Ohm | 1 | 2 | 1 | -3 | -2 | 0 | 0 | 0 | 0 | 0 | yes |
Btu | 1055.1 | 2 | 1 | -2 | 0 | 0 | 0 | 0 | 0 | 0 | no |
cal | 4.1868 | 2 | 1 | -2 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
eV | 1.6022e-19 | 2 | 1 | -2 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
erg | 1e-7 | 2 | 1 | -2 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
J | 1 | 2 | 1 | -2 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
dyn | 0.00001 | 1 | 1 | -2 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
N | 1 | 1 | 1 | -2 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
ozf | 0.27801 | 1 | 1 | -2 | 0 | 0 | 0 | 0 | 0 | 0 | no |
lbf | 4.4482 | 1 | 1 | -2 | 0 | 0 | 0 | 0 | 0 | 0 | no |
Hz | 1 | 0 | 0 | -1 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
ft | 0.3048 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | no |
in | 0.0254 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | no |
mi | 1609.3 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | no |
nit | 1 | -2 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | yes |
nits | 1 | -2 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | yes |
sb | 10000 | -2 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | yes |
fc | 10.764 | -2 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | no |
lx | 1 | -2 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | yes |
phot | 10000 | -2 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | yes |
lm | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | yes |
Mx | 1e-8 | 2 | 1 | -2 | -1 | 0 | 0 | 0 | 0 | 0 | yes |
Wb | 1 | 2 | 1 | -2 | -1 | 0 | 0 | 0 | 0 | 0 | yes |
G | 0.0001 | 0 | 1 | -2 | -1 | 0 | 0 | 0 | 0 | 0 | yes |
T | 1 | 0 | 1 | -2 | -1 | 0 | 0 | 0 | 0 | 0 | yes |
H | 1 | 2 | 1 | -2 | -2 | 0 | 0 | 0 | 0 | 0 | yes |
u | 1.6605e-27 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
lb | 0.45359 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | no |
slug | 14.594 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | no |
º | 0.017453 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | no |
deg | 0.017453 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | no |
' | 0.00029089 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | no |
" | 4.8481e-6 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | no |
hp | 745.7 | 2 | 1 | -3 | 0 | 0 | 0 | 0 | 0 | 0 | no |
W | 1 | 2 | 1 | -3 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
atm | 1.0133e5 | -1 | 1 | -2 | 0 | 0 | 0 | 0 | 0 | 0 | no |
bar | 1e5 | -1 | 1 | -2 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
Pa | 1 | -1 | 1 | -2 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
torr | 133.32 | -1 | 1 | -2 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
mmHg | 133.32 | -1 | 1 | -2 | 0 | 0 | 0 | 0 | 0 | 0 | no |
ºC | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | no |
degC | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | no |
ºF | 5/9 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | no |
degF | 5/9 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | no |
d | 86400 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | no |
h | 3600 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | no |
min | 60 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | no |
y | 3.1557e7 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
gal | 0.0037854 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | no |
l | 0.001 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | yes |
pint | 0.00047318 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | no |
qt | 0.00094635 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | no |
Remark:
If degF, ºF, degC, or ºC are part of composite units, like in m/degF, they simply contribute to the scaling factor of the conversion. If they, after the initial division process, end up alone, like in degF to degC, the unit conversion will also include the correct offset.
The Manager supports the following non-linear units: dBW, dBm. If these units don't drop out during the initial division process, the conversion only succeeds if these units are not part of a composite unit string.
For example you CAN convert 15dBm to W, but you can NOT convert 15dBm/s to W/s.
The Manager supports SI unit prefixing like km, MPa, etc. The prefixes get included when the SI conversion factor is calculated. The following prefixes are supported for all prefixable (see above) units:
Prefix | Factor |
Y | 1e24 |
Z | 1e21 |
E | 1e18 |
P | 1e15 |
T | 1e12 |
G | 1e9 |
M | 1e6 |
k | 1000 |
h | 100 |
da | 10 |
d | 0.1 |
c | 0.01 |
m | 0.001 |
µ | 1e-6 |
u | 1e-6 |
n | 1e-9 |
p | 1e-12 |
f | 1e-15 |
a | 1e-18 |
z | 1e-21 |
y | 1e-24 |
Please post a bug report on this project's bug tracker if you find an error in the unit tables above or the way the Manager converts them.
You can test-run the unit conversion using the LabRAD Explorer as described in the LabRAD Quick Start Tutorial.
~ Markus Ansmann, Jan 25th, 2008