Skip to content

1. A first quantity ​

A FURY program uses one module, fury, and works with two types: a unit of measure (uom64) and a quantity (qreal64), a real number with its unit. The 64 is the real kind: 64 bits, double precision (chapter 7 has the others).

Units from a string ​

A unit is defined by a string: its symbol and, between square brackets, its dimensions.

f90
metre  = uom64('m [length]')
second = uom64('s [time]')

The dimensions are optional, but they make the unit algebra more informative (chapter 3) and are checked against the exponents of the symbols (chapter 4).

Quantities ​

A quantity is created by the constructor qreal64, or by multiplying a number by a unit:

f90
distance = qreal64(magnitude=100._R8P, unit=metre)  ! the constructor
time     = 9.58_R8P * second                         ! a number times a unit

R8P is the 64 bits real kind of PENF, exported by fury; 9.58_R8P is a double precision literal. Any integer or real kind times a unit gives a quantity.

Computing ​

The arithmetic operators work on quantities as on numbers, and the unit of the result is derived from the units of the operands:

f90
speed = distance / time
distance_again = speed * time

Printing ​

stringify returns the quantity as a string: the magnitude, then the unit. Its options choose the format of the magnitude and what to print of the unit; the magnitude itself is the component magnitude.

f90
print '(A)', speed%stringify()
print '(A)', speed%stringify(format='(F6.3)')
print '(A)', speed%stringify(compact_reals=.true., with_dimensions=.true.)
print '(A)', distance_again%stringify(format='(F6.2)')
print '(F6.3)', speed%magnitude
$ tutorial_1
+0.10438413361169102E+002 m.s-1
10.438 m.s-1
+10.438413361169102 m.s-1 [length.time-1]
100.00 m
10.438
  • Without options the magnitude is printed with all its digits, in exponential notation.
  • format is a Fortran edit descriptor for the magnitude.
  • compact_reals=.true. prints the shortest representation of the magnitude.
  • with_dimensions=.true. appends the dimensions, derived like the symbols: length.time-1.
  • speed * time is a length again: m.s-1 times s is m.

What you learned

Units from strings, quantities by constructor or by number * unit, arithmetic with derived units, stringify. Reference: Quantities, Units.

Next: 2. Defining units.

Released under GPL v3, BSD 2-Clause, BSD 3-Clause or MIT, at your choice.