Skip to content

6. The SI system ​

Defining every unit by hand is tedious and error prone: system_si64 is a catalogue of the International System of Units, ready to use. It is initialised once:

f90
call SI%initialize

Units by name or symbol ​

unit returns a unit of the system, queried by name, by symbol or by the main alias of a compound unit:

f90
metre  = SI%unit('metre')
newton = SI%unit('N')
print '(A)', metre%stringify(with_dimensions=.true., with_aliases=.true., with_name=.true.)
print '(A)', newton%stringify(with_dimensions=.true., with_aliases=.true., with_name=.true.)

A query matches the name of a unit (metre), its symbol (m), a synonym of its symbol (meter, sec) or its main alias (N), and also the units obtained prefixing the system units (km, kilometre):

f90
query = [character(16) :: 'm', 'meter', 'second', 'sec', 'km', 'kilometre']
do i=1, size(query)
  call metre%unset
  metre = SI%unit(trim(query(i)))
  print '(A)', query(i)//' -> '//metre%stringify(with_name=.true.)
enddo

Prefixes ​

The prefixed units are built on demand, with their conversion to the plain unit:

f90
kilometre = SI%unit('km')
minute    = SI%unit('min')
distance  = 42.195_R8P * kilometre
converted = distance%to(SI%unit('m'))
print '(A)', distance%stringify(format='(F6.3)')//' = '//converted%stringify(format='(F7.1)')

qunit returns a quantity of magnitude 1 in the queried unit: a number times it is a quantity. The binary prefixes are powers of 1024:

f90
kilobyte = 64 * SI%qunit('KiB')
call converted%unset
converted = kilobyte%to(SI%unit('byte'))
print '(A)', kilobyte%stringify(format='(F4.1)')//' = '//converted%stringify(format='(F7.1)')

Constants ​

const returns a physical constant, as a quantity with its unit and name:

f90
light = SI%const('speed_of_light')
g     = SI%const('gravity')
weight = 75._R8P * SI%unit('kg') * g
print '(A)', light%stringify(compact_reals=.true., with_name=.true.)
print '(A)', 'weight: '//weight%stringify(format='(F5.1)', with_dimensions=.true.)
$ tutorial_6
m = metre = meter [length] {metre}
kg.m.s-2 [mass.length.time-2] (N [force]) {newton}
m                -> m {metre}
meter            -> m {metre}
second           -> s {second}
sec              -> s {second}
km               -> km {kilometre}
kilometre        -> km {kilometre}
42.195 km = 42195.0 m
64.0 Kibyte = 65536.0 byte
speed_of_light: +299792458.0 m.s-1 {metre.second-1}
weight: 735.5 kg.m.s-2 [mass.length.time-2]

The weight of a 75 kg person is a mass times an acceleration: a force, kg.m.s-2. The Units systems page lists all the units, prefixes and constants of the SI system.

What you learned

initialize, unit by name, symbol, synonym or prefix, qunit, const. Reference: Units systems.

Next: 7. Precision.

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