5. Conversions
An alias of a unit can be a conversion formula: a factor, an offset, or both. to converts a quantity into another unit through these formulas.
A factor
metre = uom64('m [length]')
kilometre = uom64('km = 1000 * m [length]')
q = 3.2_R8P * kilometre
converted = q%to(metre)
print '(A)', q%stringify(format='(F3.1)')//' = '//converted%stringify(format='(F6.1)')$ tutorial_5 factor
3.2 km = 3200.0 mkm = 1000 * m reads "one km is 1000 m". The conversion works both ways: to uses the formula of either unit.
Factors with a decimal point
The . separates the references of a compound unit, so a factor with a decimal point must be protected between < and >:
metre = uom64('m [length]')
mile = uom64('mi< = 1609.344 * m> [length]')
q = 26.2_R8P * mile
converted = q%to(metre)
print '(A)', q%stringify(format='(F4.1)')//' = '//converted%stringify(format='(F7.1)')$ tutorial_5 protected
26.2 mi = 42164.8 mAn offset
offset + factor * symbol is a linear formula with an offset, for the temperature scales:
kelvin = uom64('K [temperature]')
celsius = uom64('degC< = 273.15 + K> [temperature]')
q = 36.6_R8P * celsius
converted = q%to(kelvin)
print '(A)', q%stringify(format='(F4.1)')//' = '//converted%stringify(format='(F6.2)')$ tutorial_5 offset
36.6 degC = 309.75 KSeveral aliases
A unit can have several aliases: synonyms (hr) and formulas towards several units. The hour is a symbol and a formula at once:
second = uom64('s [time]')
hour = uom64('h = 3600 * s = hr [time]')
q = 1.5_R8P * hour
converted = q%to(second)
print '(A)', q%stringify(format='(F3.1)')//' = '//converted%stringify(format='(F6.1)')
call q%unset
q = converted%to(hour)
print '(A)', converted%stringify(format='(F6.1)')//' = '//q%stringify(format='(F3.1)')$ tutorial_5 aliases
1.5 h = 5400.0 s
5400.0 s = 1.5 hWhen neither unit has a formula towards the other, FURY looks for an alias they share: ft = 0.3048 * m and km = 1000 * m convert into each other through m (chapter 9 has an example).
Through the main alias
The pound-force is defined by a formula towards N, the main alias of the newton. FURY matches it, and converts a single symbol into a compound unit:
newton = uom64('kg [mass].m [length].s-2 [time-2] (N[force]) {newton}')
pound_force = uom64('lbf< = 4.4482216152605 * N> [force] {pound_force}')
q = 10._R8P * pound_force
converted = q%to(newton)
print '(A)', q%stringify(format='(F4.1)')//' = '//converted%stringify(format='(F6.3)', with_aliases=.true.)$ tutorial_5 main-alias
10.0 lbf = 44.482 kg.m.s-2 (N)The converted quantity has the unit passed to to: the newton, kg.m.s-2, with its main alias N.
No conversion, no number
A conversion between units that no formula relates stops the program, like a sum: to never returns the magnitude with a unit it does not have.
metre = uom64('m [length]')
second = uom64('s [time]')
q = 3._R8P * metre
converted = q%to(second)$ tutorial_5 impossible
error: cannot convert "m [length]" to "s [time]"
[exit status 1]FURY converts a unit symbol by symbol (or through the main alias): it does not expand an alias inside a product. An impulse in lbf.s is not converted into kg.m.s-1 directly; the cookbook shows how to convert its force first.
What you learned
Factors, protected factors, offsets, several aliases, conversions through a common alias and through the main alias; an impossible conversion stops the program. Reference: Conversions, Unit grammar.
Next: 6. The SI system.