sourcery_units_m Module

Define SI and British units of measurement and associated arithmetic operators


Used by

  • module~~sourcery_units_m~~UsedByGraph module~sourcery_units_m sourcery_units_m module~sourcery_m sourcery_m module~sourcery_m->module~sourcery_units_m module~sourcery_units_s sourcery_units_s module~sourcery_units_s->module~sourcery_units_m module~sourcery_string_s sourcery_string_s module~sourcery_string_s->module~sourcery_m

Variables

Type Visibility Attributes Name Initial
character(len=*), public, parameter :: British_units_names(num_fundamental) = [character(len=len("sec"))::"R", "ft", "lbm", "sec"]
character(len=*), public, parameter :: SI_units_names(num_fundamental) = [character(len=len("sec"))::"K", "m", "kg", "sec"]
integer, public, parameter :: num_fundamental = 4
character(len=*), public, parameter :: units_system_names(num_systems) = [character(len=len("British"))::"SI", "British"]
integer, private, parameter :: num_systems = 2

Enumerations

enum, bind(c)

Enumerators

enumerator:: K = 1
enumerator:: m = 2
enumerator:: kg = 3
enumerator:: sec = 4
enumerator:: R = 1
enumerator:: ft = 2
enumerator:: lbm = 3
enumerator:: dimensionless = 0
enumerator:: SI = 1
enumerator:: British = 2

Description

Enumerate the fundamental units for dimensional units quantities (meters, kilograms, seconds, and degrees Kelvin)


Interfaces

interface

  • private impure elemental module function add(lhs, rhs) result(total)

    result is the units of the sum of two dimensional quantities; includes operand consistency check

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: lhs
    class(units), intent(in) :: rhs

    Return Value type(units)

interface

  • private pure module subroutine assign_units(lhs, rhs)

    copy units information

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(inout) :: lhs
    class(units), intent(in) :: rhs

interface

  • private elemental module function divide(numerator, denominator) result(ratio)

    result is the units of the ratio of two dimensional quantities; includes units-sysetm consistency check

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: numerator
    class(units), intent(in) :: denominator

    Return Value type(units)

interface

  • private impure elemental module function get_system(this) result(system_of_units)

    result is enumerated value designating units system

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: this

    Return Value integer

interface

  • private module function get_units(this) result(exponents)

    result holds the exponents of each unit in the argument (most useful when the actual argument is an expression)

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: this

    Return Value integer, (num_fundamental)

interface

  • private elemental module function has_density_units(this) result(density_units)

    Return true if units match kilograms (kg/m^3)

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: this

    Return Value logical

interface

  • private elemental module function has_energy_units(this) result(energy_units)

    Return true if units match joules (J)

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: this

    Return Value logical

interface

  • private elemental module function has_length_units(this) result(length_units)

    Return true if units match meters (m)

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: this

    Return Value logical

interface

  • private elemental module function has_mass_units(this) result(mass_units)

    Return true if units match kilograms (kg)

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: this

    Return Value logical

interface

  • private elemental module function has_power_units(this) result(power_units)

    Return true if units match Watts (W)

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: this

    Return Value logical

interface

  • private elemental module function has_specific_energy_units(this) result(specific_energy_units)

    Return true if units match Joules per kilogram (J/kg)

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: this

    Return Value logical

interface

  • private elemental module function has_stress_units(this) result(stress_units)

    Return true if units match Newtons per square meter (N/m^2)

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: this

    Return Value logical

interface

  • private elemental module function has_temperature_units(this) result(temperature_units)

    Return true if units match degrees Kelvin (K)

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: this

    Return Value logical

interface

  • private elemental module function has_time_units(this) result(time_units)

    Return true if units match seconds (s)

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: this

    Return Value logical

interface

  • private elemental module function has_velocity_units(this) result(velocity_units)

    Return true if units match meters/second^2 (m/s^2)

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: this

    Return Value logical

interface

  • private impure elemental module function integer_power(this, exponent_) result(this_raised)

    result has units of the opearand raised to the power "exponent_"

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: this
    integer, intent(in) :: exponent_

    Return Value type(units)

interface

  • private elemental module function is_dimensionless(this) result(nondimensional)

    Return true if all units exponents are zero; false otherwise.

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: this

    Return Value logical

interface

  • private elemental module function multiply(lhs, rhs) result(product_)

    result is the units of the product of two dimensional quantities; includes units-system consistency check

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: lhs
    class(units), intent(in) :: rhs

    Return Value type(units)

interface

  • private elemental module function negate(this) result(negative_this)

    result is the units of the negative of a dimensional quantities

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: this

    Return Value type(units)

interface

  • private impure elemental module function real_power(this, exponent_) result(this_raised)

    result is the units of the operand raised to the power "exponent_"; includes check that operand is dimensionless

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: this
    real, intent(in) :: exponent_

    Return Value type(units)

interface

  • private pure module subroutine set_units(this, exponents, system)

    define units

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(inout) :: this
    integer, intent(in) :: exponents(num_fundamental)
    integer, intent(in) :: system

interface

  • private impure elemental module function subtract(lhs, rhs) result(difference)

    result is the units of the difference of two dimensional quantities; includes operand consistency check

    Arguments

    Type IntentOptional Attributes Name
    class(units), intent(in) :: lhs
    class(units), intent(in) :: rhs

    Return Value type(units)


Derived Types

type, public ::  units

Morfeus universal base type for all units

Components

Type Visibility Attributes Name Initial
character(len=:), private, allocatable :: description
integer, private :: exponents_(num_fundamental) = dimensionless

Store the exponents for fundamental units

integer, private :: system = dimensionless

Default to SI units

Type-Bound Procedures

procedure, public :: add
procedure, public :: assign_units
generic, public :: assignment(=) => assign_units
procedure, public :: divide
procedure, public :: get_system
procedure, public :: get_units
procedure, public :: has_density_units
procedure, public :: has_energy_units
procedure, public :: has_length_units
procedure, public :: has_mass_units
procedure, public :: has_power_units
procedure, public :: has_specific_energy_units
procedure, public :: has_stress_units
procedure, public :: has_temperature_units
procedure, public :: has_time_units
procedure, public :: has_velocity_units
procedure, public :: integer_power
procedure, public :: is_dimensionless
procedure, public :: multiply
procedure, public :: negate
generic, public :: operator(*) => multiply
generic, public :: operator(**) => integer_power, real_power
generic, public :: operator(+) => add
generic, public :: operator(-) => subtract, negate
generic, public :: operator(/) => divide
procedure, public :: real_power
procedure, public :: set_units
procedure, public :: subtract