Next: , Previous: , Up: Implementation Defined Aspects   [Contents][Index]


3.10 Aspect Dimension_System

The Dimension_System aspect is used to define a system of dimensions that will be used in subsequent subtype declarations with Dimension aspects that reference this system. The syntax is:

with Dimension_System => (DIMENSION {, DIMENSION});

DIMENSION ::= ([Unit_Name   =>] IDENTIFIER,
               [Unit_Symbol =>] SYMBOL,
               [Dim_Symbol  =>] SYMBOL)

SYMBOL ::= CHARACTER_LITERAL | STRING_LITERAL

This aspect is applied to a type, which must be a numeric derived type (typically a floating-point type), that will represent values within the dimension system. Each DIMENSION corresponds to one particular dimension. A maximum of 7 dimensions may be specified. Unit_Name is the name of the dimension (for example Meter). Unit_Symbol is the shorthand used for quantities of this dimension (for example m for Meter). Dim_Symbol gives the identification within the dimension system (typically this is a single letter, e.g. L standing for length for unit name Meter). The Unit_Symbol is used in formatted output of dimensioned quantities. The Dim_Symbol is used in error messages when numeric operations have inconsistent dimensions.

GNAT provides the standard definition of the International MKS system in the run-time package System.Dim.Mks. You can easily define similar packages for cgs units or British units, and define conversion factors between values in different systems. The MKS system is characterized by the following aspect:

type Mks_Type is new Long_Long_Float with
  Dimension_System => (
    (Unit_Name => Meter,    Unit_Symbol => 'm',   Dim_Symbol => 'L'),
    (Unit_Name => Kilogram, Unit_Symbol => "kg",  Dim_Symbol => 'M'),
    (Unit_Name => Second,   Unit_Symbol => 's',   Dim_Symbol => 'T'),
    (Unit_Name => Ampere,   Unit_Symbol => 'A',   Dim_Symbol => 'I'),
    (Unit_Name => Kelvin,   Unit_Symbol => 'K',   Dim_Symbol => '@'),
    (Unit_Name => Mole,     Unit_Symbol => "mol", Dim_Symbol => 'N'),
    (Unit_Name => Candela,  Unit_Symbol => "cd",  Dim_Symbol => 'J'));

Note that in the above type definition, we use the at symbol (@) to represent a theta character (avoiding the use of extended Latin-1 characters in this context).

See section ’Performing Dimensionality Analysis in GNAT’ in the GNAT Users Guide for detailed examples of use of the dimension system.


Next: , Previous: , Up: Implementation Defined Aspects   [Contents][Index]