Menu

Units

LabRAD Units

Overview

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.

Operation

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.

Example: TShirts/min to TShirts/hr

Parsing

UnitSource ExponentTarget Exponent
TShirts11
min-10
hr0-1

Division by subtraction of exponents

UnitSrc - TgtNew ExponentAction
TShirts1 - 10drop
min(-1) - 0-1keep
hr0 - (-1)1keep

Conversion to SI

Exponent of
UnitFactormkgsAKmolcdradsr
min60001000000
hr3600001000000

Exponentiation and multiplication

New Exponent of
UnitExponentNew FactormkgsAKmolcdradsr
min-11/6000-1000000
hr13600001000000
Product60
Sum000000000

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!

Linear units

The Manager knows the following units:

Exponent of
UnitFactormkgsAKmolcdradsrPrefixable
m1100000000yes
g0.001010000000yes
s1001000000yes
A1000100000yes
K1000010000yes
mol1000001000yes
cd1000000100yes
rad1000000010yes
sr1000000001yes
Bq100-1000000yes
Ci3.7e1000-1000000yes
acre4046.9200000000no
a100200000000yes
F1-2-14200000yes
C1001100000yes
S1-2-13200000yes
V121-3-100000yes
Ohm121-3-200000yes
Btu1055.121-2000000no
cal4.186821-2000000yes
eV1.6022e-1921-2000000yes
erg1e-721-2000000yes
J121-2000000yes
dyn0.0000111-2000000yes
N111-2000000yes
ozf0.2780111-2000000no
lbf4.448211-2000000no
Hz100-1000000yes
ft0.3048100000000no
in0.0254100000000no
mi1609.3100000000no
nit1-200000100yes
nits1-200000100yes
sb10000-200000100yes
fc10.764-200000101no
lx1-200000101yes
phot10000-200000101yes
lm1000000101yes
Mx1e-821-2-100000yes
Wb121-2-100000yes
G0.000101-2-100000yes
T101-2-100000yes
H121-2-200000yes
u1.6605e-27010000000yes
lb0.45359010000000no
slug14.594010000000no
º0.017453000000010no
deg0.017453000000010no
'0.00029089000000010no
"4.8481e-6000000010no
hp745.721-3000000no
W121-3000000yes
atm1.0133e5-11-2000000no
bar1e5-11-2000000yes
Pa1-11-2000000yes
torr133.32-11-2000000yes
mmHg133.32-11-2000000no
ºC1000010000no
degC1000010000no
ºF5/9000010000no
degF5/9000010000no
d86400001000000no
h3600001000000no
min60001000000no
y3.1557e7001000000yes
gal0.0037854300000000no
l0.001300000000yes
pint0.00047318300000000no
qt0.00094635300000000no

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.

Non-linear units

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.

SI prefixes

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:

PrefixFactor
Y1e24
Z1e21
E1e18
P1e15
T1e12
G1e9
M1e6
k1000
h100
da10
d0.1
c0.01
m0.001
µ1e-6
u1e-6
n1e-9
p1e-12
f1e-15
a1e-18
z1e-21
y1e-24

Note

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


Related

Wiki: DataTypes
Wiki: Grammar
Wiki: QuickStart

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.