Skip to content

Quantities ​

qreal64 (and qreal32, qreal128) is a physical quantity: a real magnitude, its unit and an optional name. The components are public:

ComponentType
magnitudereal(R8P) (R4P, R16P)
unitclass(uom64), allocatable
namecharacter(len=:), allocatable

Creating a quantity ​

f90
a = qreal64(magnitude=2._R8P, unit=metre, name='width')  ! the constructor, optionally named
b = 2._R8P * metre                                       ! a number times a unit
c = 2 * SI%qunit('metre')                                ! a number times a unit quantity of a system

qreal64(magnitude, unit, name), all optional; number * unit for any integer or real kind; system%qunit(name) a quantity of magnitude 1 in a unit of a system.

Operators ​

OperationOperandsResult
q + r, q - rquantities with equal unitsthe sum, in that unit; different units are an error
+q, -qa quantitythe quantity, its opposite
q * r, q / rquantitiesthe product, the quotient, with the unit algebra
q * x, x * q, q / xa quantity and a number of any integer or real kindthe scaled quantity
q ** n, q ** xa quantity and an integer or a realthe power; for 1/q write q ** (-1)
q == r, q /= rquantitiesequality of magnitudes and units
q = rquantitiesassignment: a quantity without unit takes the one of r; one with a unit accepts only an equal unit, otherwise it is an error

Quantities of different kinds mix: see Precision.

Methods ​

MethodPurpose
stringify(format, with_dimensions, with_aliases, with_name, compact_reals)the quantity as a string: format is an edit descriptor for the magnitude, the flags choose the parts of the unit, with_name prefixes the name
to(unit)the quantity converted into unit; an impossible conversion is an error
has_same_unit(other)true if the units are equal
is_unit_defined()true if the quantity has a unit
has_name()true if the quantity has a name
set(magnitude, unit, name)sets the parts
unset()frees the quantity: it can be assigned any unit again
allocate_unit()allocates the unit component
f90
print '(A)', g%stringify()
print '(A)', g%stringify(format='(F7.5)')
print '(A)', g%stringify(compact_reals=.true.)
print '(A)', g%stringify(compact_reals=.true., with_dimensions=.true.)
print '(A)', g%stringify(compact_reals=.true., with_aliases=.true.)
print '(A)', g%stringify(compact_reals=.true., with_name=.true.)
$ cookbook_print
+0.98066499999999994E+001 m.s-2
9.80665 m.s-2
+9.80665 m.s-2
+9.80665 m.s-2 [length.time-2]
+9.80665 m = metre.s-2 (acc)
gravity: +9.80665 m.s-2 {metre/second2}

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