dyn_mpas_procedures Module

This module provides standardized procedures (i.e., functions and subroutines) that serve as reusable building blocks for larger and more complex functionalities elsewhere. Specifically, procedures in this module are intended to be used by the MPAS subdriver and therefore are compiled into the MPAS library ahead of CAM-SIMA.

Computational procedures implement formulas that are universal in atmospheric sciences. They should be designated as elemental where possible to aid compiler optimizations, such as vectorization. Utility procedures implement simple and well-defined operations that can be easily tested.


Used by


Interfaces

public interface almost_divisible

  • private pure elemental function almost_divisible_real32(a, b) result(almost_divisible)

    Test if a is divisible by b, where a and b are both reals. (KCW, 2024-05-25)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real32), intent(in) :: a
    real(kind=real32), intent(in) :: b

    Return Value logical

  • private pure elemental function almost_divisible_real64(a, b) result(almost_divisible)

    Test if a is divisible by b, where a and b are both reals. (KCW, 2024-05-25)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in) :: a
    real(kind=real64), intent(in) :: b

    Return Value logical

public interface almost_equal

  • private pure elemental function almost_equal_real32(a, b, absolute_tolerance, relative_tolerance) result(almost_equal)

    Test a and b for approximate equality, where a and b are both reals. (KCW, 2024-05-25)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real32), intent(in) :: a
    real(kind=real32), intent(in) :: b
    real(kind=real32), intent(in), optional :: absolute_tolerance
    real(kind=real32), intent(in), optional :: relative_tolerance

    Return Value logical

  • private pure elemental function almost_equal_real64(a, b, absolute_tolerance, relative_tolerance) result(almost_equal)

    Test a and b for approximate equality, where a and b are both reals. (KCW, 2024-05-25)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in) :: a
    real(kind=real64), intent(in) :: b
    real(kind=real64), intent(in), optional :: absolute_tolerance
    real(kind=real64), intent(in), optional :: relative_tolerance

    Return Value logical

public interface clamp

  • private pure elemental function clamp_int32(x, xmin, xmax) result(clamp)

    Clamp/Limit the value of x to the range of [xmin, xmax], where x, xmin, and xmax are all integers. No check is performed to ensure xmin < xmax. (KCW, 2025-07-16)

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int32), intent(in) :: x
    integer(kind=int32), intent(in) :: xmin
    integer(kind=int32), intent(in) :: xmax

    Return Value integer(kind=int32)

  • private pure elemental function clamp_int64(x, xmin, xmax) result(clamp)

    Clamp/Limit the value of x to the range of [xmin, xmax], where x, xmin, and xmax are all integers. No check is performed to ensure xmin < xmax. (KCW, 2025-07-16)

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int64), intent(in) :: x
    integer(kind=int64), intent(in) :: xmin
    integer(kind=int64), intent(in) :: xmax

    Return Value integer(kind=int64)

  • private pure elemental function clamp_real32(x, xmin, xmax) result(clamp)

    Clamp/Limit the value of x to the range of [xmin, xmax], where x, xmin, and xmax are all reals. No check is performed to ensure xmin < xmax. (KCW, 2025-07-16)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real32), intent(in) :: x
    real(kind=real32), intent(in) :: xmin
    real(kind=real32), intent(in) :: xmax

    Return Value real(kind=real32)

  • private pure elemental function clamp_real64(x, xmin, xmax) result(clamp)

    Clamp/Limit the value of x to the range of [xmin, xmax], where x, xmin, and xmax are all reals. No check is performed to ensure xmin < xmax. (KCW, 2025-07-16)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in) :: x
    real(kind=real64), intent(in) :: xmin
    real(kind=real64), intent(in) :: xmax

    Return Value real(kind=real64)

public interface dzu_of_dzw

  • private pure function dzu_of_dzw_real32(dzw) result(dzu)

    Compute the difference in between u-wind levels dzu from the difference in between w-wind levels dzw, where is the vertical coordinate, u-wind and w-wind levels are synonymous with layer midpoints and interfaces in MPAS, respectively. (KCW, 2025-10-20)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real32), intent(in) :: dzw(:)

    Return Value real(kind=real32), (size(dzw)-1)

  • private pure function dzu_of_dzw_real64(dzw) result(dzu)

    Compute the difference in between u-wind levels dzu from the difference in between w-wind levels dzw, where is the vertical coordinate, u-wind and w-wind levels are synonymous with layer midpoints and interfaces in MPAS, respectively. (KCW, 2025-10-20)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in) :: dzw(:)

    Return Value real(kind=real64), (size(dzw)-1)

public interface dzw_of_rdzw

  • private pure elemental function dzw_of_rdzw_real32(rdzw) result(dzw)

    Compute the difference in between w-wind levels dzw from the reciprocal difference in between w-wind levels rdzw, where is the vertical coordinate, and w-wind levels are synonymous with layer interfaces in MPAS. (KCW, 2025-10-20)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real32), intent(in) :: rdzw

    Return Value real(kind=real32)

  • private pure elemental function dzw_of_rdzw_real64(rdzw) result(dzw)

    Compute the difference in between w-wind levels dzw from the reciprocal difference in between w-wind levels rdzw, where is the vertical coordinate, and w-wind levels are synonymous with layer interfaces in MPAS. (KCW, 2025-10-20)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in) :: rdzw

    Return Value real(kind=real64)

public interface tokenize

  • private pure subroutine tokenize_into_first_last(string, set, first, last)

    Parse a string into tokens. This subroutine implements the tokenize intrinsic procedure as defined in the Fortran 2023 language standard (Section 16.9.210).

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: string
    character(len=*), intent(in) :: set
    integer, intent(out), allocatable :: first(:)
    integer, intent(out), allocatable :: last(:)
  • private pure subroutine tokenize_into_tokens_separator(string, set, tokens, separator)

    Parse a string into tokens. This subroutine implements the tokenize intrinsic procedure as defined in the Fortran 2023 language standard (Section 16.9.210).

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: string
    character(len=*), intent(in) :: set
    character(len=:), intent(out), allocatable :: tokens(:)
    character(len=:), intent(out), optional, allocatable :: separator(:)

public interface zu_of_dzw

  • private pure function zu_of_dzw_real32(dzw) result(zu)

    Compute the coordinates at u-wind levels zu from the difference in between w-wind levels dzw, where is the vertical coordinate, u-wind and w-wind levels are synonymous with layer midpoints and interfaces in MPAS, respectively. (KCW, 2025-10-20)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real32), intent(in) :: dzw(:)

    Return Value real(kind=real32), (size(dzw))

  • private pure function zu_of_dzw_real64(dzw) result(zu)

    Compute the coordinates at u-wind levels zu from the difference in between w-wind levels dzw, where is the vertical coordinate, u-wind and w-wind levels are synonymous with layer midpoints and interfaces in MPAS, respectively. (KCW, 2025-10-20)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in) :: dzw(:)

    Return Value real(kind=real64), (size(dzw))

public interface zw_of_dzw

  • private pure function zw_of_dzw_real32(dzw) result(zw)

    Compute the coordinates at w-wind levels zw from the difference in between w-wind levels dzw, where is the vertical coordinate, and w-wind levels are synonymous with layer interfaces in MPAS. (KCW, 2025-10-20)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real32), intent(in) :: dzw(:)

    Return Value real(kind=real32), (size(dzw)+1)

  • private pure function zw_of_dzw_real64(dzw) result(zw)

    Compute the coordinates at w-wind levels zw from the difference in between w-wind levels dzw, where is the vertical coordinate, and w-wind levels are synonymous with layer interfaces in MPAS. (KCW, 2025-10-20)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in) :: dzw(:)

    Return Value real(kind=real64), (size(dzw)+1)


Functions

private pure elemental function almost_divisible_real32(a, b) result(almost_divisible)

Test if a is divisible by b, where a and b are both reals. (KCW, 2024-05-25)

Arguments

Type IntentOptional Attributes Name
real(kind=real32), intent(in) :: a
real(kind=real32), intent(in) :: b

Return Value logical

private pure elemental function almost_divisible_real64(a, b) result(almost_divisible)

Test if a is divisible by b, where a and b are both reals. (KCW, 2024-05-25)

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in) :: a
real(kind=real64), intent(in) :: b

Return Value logical

private pure elemental function almost_equal_real32(a, b, absolute_tolerance, relative_tolerance) result(almost_equal)

Test a and b for approximate equality, where a and b are both reals. (KCW, 2024-05-25)

Arguments

Type IntentOptional Attributes Name
real(kind=real32), intent(in) :: a
real(kind=real32), intent(in) :: b
real(kind=real32), intent(in), optional :: absolute_tolerance
real(kind=real32), intent(in), optional :: relative_tolerance

Return Value logical

private pure elemental function almost_equal_real64(a, b, absolute_tolerance, relative_tolerance) result(almost_equal)

Test a and b for approximate equality, where a and b are both reals. (KCW, 2024-05-25)

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in) :: a
real(kind=real64), intent(in) :: b
real(kind=real64), intent(in), optional :: absolute_tolerance
real(kind=real64), intent(in), optional :: relative_tolerance

Return Value logical

private pure elemental function clamp_int32(x, xmin, xmax) result(clamp)

Clamp/Limit the value of x to the range of [xmin, xmax], where x, xmin, and xmax are all integers. No check is performed to ensure xmin < xmax. (KCW, 2025-07-16)

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: x
integer(kind=int32), intent(in) :: xmin
integer(kind=int32), intent(in) :: xmax

Return Value integer(kind=int32)

private pure elemental function clamp_int64(x, xmin, xmax) result(clamp)

Clamp/Limit the value of x to the range of [xmin, xmax], where x, xmin, and xmax are all integers. No check is performed to ensure xmin < xmax. (KCW, 2025-07-16)

Arguments

Type IntentOptional Attributes Name
integer(kind=int64), intent(in) :: x
integer(kind=int64), intent(in) :: xmin
integer(kind=int64), intent(in) :: xmax

Return Value integer(kind=int64)

private pure elemental function clamp_real32(x, xmin, xmax) result(clamp)

Clamp/Limit the value of x to the range of [xmin, xmax], where x, xmin, and xmax are all reals. No check is performed to ensure xmin < xmax. (KCW, 2025-07-16)

Arguments

Type IntentOptional Attributes Name
real(kind=real32), intent(in) :: x
real(kind=real32), intent(in) :: xmin
real(kind=real32), intent(in) :: xmax

Return Value real(kind=real32)

private pure elemental function clamp_real64(x, xmin, xmax) result(clamp)

Clamp/Limit the value of x to the range of [xmin, xmax], where x, xmin, and xmax are all reals. No check is performed to ensure xmin < xmax. (KCW, 2025-07-16)

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in) :: x
real(kind=real64), intent(in) :: xmin
real(kind=real64), intent(in) :: xmax

Return Value real(kind=real64)

private pure function dzu_of_dzw_real32(dzw) result(dzu)

Compute the difference in between u-wind levels dzu from the difference in between w-wind levels dzw, where is the vertical coordinate, u-wind and w-wind levels are synonymous with layer midpoints and interfaces in MPAS, respectively. (KCW, 2025-10-20)

Arguments

Type IntentOptional Attributes Name
real(kind=real32), intent(in) :: dzw(:)

Return Value real(kind=real32), (size(dzw)-1)

private pure function dzu_of_dzw_real64(dzw) result(dzu)

Compute the difference in between u-wind levels dzu from the difference in between w-wind levels dzw, where is the vertical coordinate, u-wind and w-wind levels are synonymous with layer midpoints and interfaces in MPAS, respectively. (KCW, 2025-10-20)

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in) :: dzw(:)

Return Value real(kind=real64), (size(dzw)-1)

private pure elemental function dzw_of_rdzw_real32(rdzw) result(dzw)

Compute the difference in between w-wind levels dzw from the reciprocal difference in between w-wind levels rdzw, where is the vertical coordinate, and w-wind levels are synonymous with layer interfaces in MPAS. (KCW, 2025-10-20)

Arguments

Type IntentOptional Attributes Name
real(kind=real32), intent(in) :: rdzw

Return Value real(kind=real32)

private pure elemental function dzw_of_rdzw_real64(rdzw) result(dzw)

Compute the difference in between w-wind levels dzw from the reciprocal difference in between w-wind levels rdzw, where is the vertical coordinate, and w-wind levels are synonymous with layer interfaces in MPAS. (KCW, 2025-10-20)

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in) :: rdzw

Return Value real(kind=real64)

public pure function index_unique(array)

Return the index of unique elements in array, which can be any intrinsic data types, as an integer array. Please note that array must only have one dimension, and the unique elements are returned by their first occurrences in array. If array contains zero element or is of unsupported data types, an empty integer array is produced. For example, index_unique([1, 2, 3, 1, 2, 3, 4, 5]) returns [1, 2, 3, 7, 8]. (KCW, 2024-03-22)

Arguments

Type IntentOptional Attributes Name
class(*), intent(in) :: array(:)

Return Value integer, allocatable, (:)

public pure function stringify(value, separator)

Convert one or more values of any intrinsic data types to a character string for pretty printing. If value contains more than one element, the elements will be stringified, delimited by separator, then concatenated. If value contains exactly one element, the element will be stringified without using separator. If value contains zero element or is of unsupported data types, an empty character string is produced. If separator is not supplied, it defaults to ", " (i.e., a comma and a space). (KCW, 2024-02-04)

Arguments

Type IntentOptional Attributes Name
class(*), intent(in) :: value(:)
character(len=*), intent(in), optional :: separator

Return Value character(len=:), allocatable

private pure function zu_of_dzw_real32(dzw) result(zu)

Compute the coordinates at u-wind levels zu from the difference in between w-wind levels dzw, where is the vertical coordinate, u-wind and w-wind levels are synonymous with layer midpoints and interfaces in MPAS, respectively. (KCW, 2025-10-20)

Arguments

Type IntentOptional Attributes Name
real(kind=real32), intent(in) :: dzw(:)

Return Value real(kind=real32), (size(dzw))

private pure function zu_of_dzw_real64(dzw) result(zu)

Compute the coordinates at u-wind levels zu from the difference in between w-wind levels dzw, where is the vertical coordinate, u-wind and w-wind levels are synonymous with layer midpoints and interfaces in MPAS, respectively. (KCW, 2025-10-20)

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in) :: dzw(:)

Return Value real(kind=real64), (size(dzw))

private pure function zw_of_dzw_real32(dzw) result(zw)

Compute the coordinates at w-wind levels zw from the difference in between w-wind levels dzw, where is the vertical coordinate, and w-wind levels are synonymous with layer interfaces in MPAS. (KCW, 2025-10-20)

Arguments

Type IntentOptional Attributes Name
real(kind=real32), intent(in) :: dzw(:)

Return Value real(kind=real32), (size(dzw)+1)

private pure function zw_of_dzw_real64(dzw) result(zw)

Compute the coordinates at w-wind levels zw from the difference in between w-wind levels dzw, where is the vertical coordinate, and w-wind levels are synonymous with layer interfaces in MPAS. (KCW, 2025-10-20)

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in) :: dzw(:)

Return Value real(kind=real64), (size(dzw)+1)


Subroutines

public pure subroutine split(string, set, pos, back)

Parse a string into tokens, one at a time. This subroutine implements the split intrinsic procedure as defined in the Fortran 2023 language standard (Section 16.9.196).

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: string
character(len=*), intent(in) :: set
integer, intent(inout) :: pos
logical, intent(in), optional :: back

private pure subroutine tokenize_into_first_last(string, set, first, last)

Parse a string into tokens. This subroutine implements the tokenize intrinsic procedure as defined in the Fortran 2023 language standard (Section 16.9.210).

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: string
character(len=*), intent(in) :: set
integer, intent(out), allocatable :: first(:)
integer, intent(out), allocatable :: last(:)

private pure subroutine tokenize_into_tokens_separator(string, set, tokens, separator)

Parse a string into tokens. This subroutine implements the tokenize intrinsic procedure as defined in the Fortran 2023 language standard (Section 16.9.210).

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: string
character(len=*), intent(in) :: set
character(len=:), intent(out), allocatable :: tokens(:)
character(len=:), intent(out), optional, allocatable :: separator(:)