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.
Test if a is divisible by b, where a and b are both reals.
(KCW, 2024-05-25)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in) | :: | a | |||
| real(kind=real32), | intent(in) | :: | b |
Test if a is divisible by b, where a and b are both reals.
(KCW, 2024-05-25)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real64), | intent(in) | :: | a | |||
| real(kind=real64), | intent(in) | :: | b |
Test a and b for approximate equality, where a and b are both reals.
(KCW, 2024-05-25)
| Type | Intent | Optional | 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 |
Test a and b for approximate equality, where a and b are both reals.
(KCW, 2024-05-25)
| Type | Intent | Optional | 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 |
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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int32), | intent(in) | :: | x | |||
| integer(kind=int32), | intent(in) | :: | xmin | |||
| integer(kind=int32), | intent(in) | :: | xmax |
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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int64), | intent(in) | :: | x | |||
| integer(kind=int64), | intent(in) | :: | xmin | |||
| integer(kind=int64), | intent(in) | :: | xmax |
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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in) | :: | x | |||
| real(kind=real32), | intent(in) | :: | xmin | |||
| real(kind=real32), | intent(in) | :: | xmax |
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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real64), | intent(in) | :: | x | |||
| real(kind=real64), | intent(in) | :: | xmin | |||
| real(kind=real64), | intent(in) | :: | xmax |
Compute the differences in between u-wind levels dzu from the differences 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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in) | :: | dzw(:) |
Compute the differences in between u-wind levels dzu from the differences 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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real64), | intent(in) | :: | dzw(:) |
Compute the differences in between w-wind levels dzw from the reciprocal differences 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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in) | :: | rdzw |
Compute the differences in between w-wind levels dzw from the reciprocal differences 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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real64), | intent(in) | :: | rdzw |
Parse a string into tokens. Each character in set is a token delimiter.
first is allocated with the lower bound equal to one and the upper bound equal to the number of tokens in string.
Each element is assigned, in array element order, the starting position of each token in string, in the order found.
last is allocated with the lower bound equal to one and the upper bound equal to the number of tokens in string.
Each element is assigned, in array element order, the ending position of each token in string, in the order found.
This subroutine implements the tokenize intrinsic procedure as defined in the Fortran 2023 language standard
(Section 16.9.210). We implement it ourselves because the compiler support may take years to become widespread.
(KCW, 2025-10-29)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | string | |||
| character(len=*), | intent(in) | :: | set | |||
| integer, | intent(out), | allocatable | :: | first(:) | ||
| integer, | intent(out), | allocatable | :: | last(:) |
Parse a string into tokens. Each character in set is a token delimiter.
tokens is allocated with the lower bound equal to one and the upper bound equal to the number of tokens in string,
and with character length equal to the length of the longest token. It contains the tokens in string.
separator is allocated with the lower bound equal to one and the upper bound equal to one less than the number of
tokens in string, and with character length equal to one. It contains the token delimiters in string.
This subroutine implements the tokenize intrinsic procedure as defined in the Fortran 2023 language standard
(Section 16.9.210). We implement it ourselves because the compiler support may take years to become widespread.
(KCW, 2025-10-29)
| Type | Intent | Optional | 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(:) |
Compute the coordinates at u-wind levels zu from the differences 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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in) | :: | dzw(:) |
Compute the coordinates at u-wind levels zu from the differences 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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real64), | intent(in) | :: | dzw(:) |
Compute the coordinates at w-wind levels zw from the differences 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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in) | :: | dzw(:) |
Compute the coordinates at w-wind levels zw from the differences 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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real64), | intent(in) | :: | dzw(:) |
Test if a is divisible by b, where a and b are both reals.
(KCW, 2024-05-25)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in) | :: | a | |||
| real(kind=real32), | intent(in) | :: | b |
Test if a is divisible by b, where a and b are both reals.
(KCW, 2024-05-25)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real64), | intent(in) | :: | a | |||
| real(kind=real64), | intent(in) | :: | b |
Test a and b for approximate equality, where a and b are both reals.
(KCW, 2024-05-25)
| Type | Intent | Optional | 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 |
Test a and b for approximate equality, where a and b are both reals.
(KCW, 2024-05-25)
| Type | Intent | Optional | 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 |
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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int32), | intent(in) | :: | x | |||
| integer(kind=int32), | intent(in) | :: | xmin | |||
| integer(kind=int32), | intent(in) | :: | xmax |
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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int64), | intent(in) | :: | x | |||
| integer(kind=int64), | intent(in) | :: | xmin | |||
| integer(kind=int64), | intent(in) | :: | xmax |
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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in) | :: | x | |||
| real(kind=real32), | intent(in) | :: | xmin | |||
| real(kind=real32), | intent(in) | :: | xmax |
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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real64), | intent(in) | :: | x | |||
| real(kind=real64), | intent(in) | :: | xmin | |||
| real(kind=real64), | intent(in) | :: | xmax |
Compute the differences in between u-wind levels dzu from the differences 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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in) | :: | dzw(:) |
Compute the differences in between u-wind levels dzu from the differences 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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real64), | intent(in) | :: | dzw(:) |
Compute the differences in between w-wind levels dzw from the reciprocal differences 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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in) | :: | rdzw |
Compute the differences in between w-wind levels dzw from the reciprocal differences 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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real64), | intent(in) | :: | rdzw |
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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(*), | intent(in) | :: | array(:) |
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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(*), | intent(in) | :: | value(:) | |||
| character(len=*), | intent(in), | optional | :: | separator |
Compute the coordinates at u-wind levels zu from the differences 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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in) | :: | dzw(:) |
Compute the coordinates at u-wind levels zu from the differences 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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real64), | intent(in) | :: | dzw(:) |
Compute the coordinates at w-wind levels zw from the differences 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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in) | :: | dzw(:) |
Compute the coordinates at w-wind levels zw from the differences 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)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real64), | intent(in) | :: | dzw(:) |
Parse a string into tokens, one at a time. Each character in set is a token delimiter.
If back is absent or is present with the value .false., pos is assigned the position of the leftmost
token delimiter in string whose position is greater than pos, or if there is no such character, it
is assigned a value one greater than the length of string. This identifies a token with starting
position one greater than the value of pos on invocation, and ending position one less than the
value of pos on return.
If back is present with the value .true., pos is assigned the position of the rightmost token delimiter
in string whose position is less than pos, or if there is no such character, it is assigned the value
zero. This identifies a token with ending position one less than the value of pos on invocation, and
starting position one greater than the value of pos on return.
This subroutine implements the split intrinsic procedure as defined in the Fortran 2023 language standard
(Section 16.9.196). We implement it ourselves because the compiler support may take years to become widespread.
(KCW, 2025-10-29)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | string | |||
| character(len=*), | intent(in) | :: | set | |||
| integer, | intent(inout) | :: | pos | |||
| logical, | intent(in), | optional | :: | back |
Parse a string into tokens. Each character in set is a token delimiter.
first is allocated with the lower bound equal to one and the upper bound equal to the number of tokens in string.
Each element is assigned, in array element order, the starting position of each token in string, in the order found.
last is allocated with the lower bound equal to one and the upper bound equal to the number of tokens in string.
Each element is assigned, in array element order, the ending position of each token in string, in the order found.
This subroutine implements the tokenize intrinsic procedure as defined in the Fortran 2023 language standard
(Section 16.9.210). We implement it ourselves because the compiler support may take years to become widespread.
(KCW, 2025-10-29)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | string | |||
| character(len=*), | intent(in) | :: | set | |||
| integer, | intent(out), | allocatable | :: | first(:) | ||
| integer, | intent(out), | allocatable | :: | last(:) |
Parse a string into tokens. Each character in set is a token delimiter.
tokens is allocated with the lower bound equal to one and the upper bound equal to the number of tokens in string,
and with character length equal to the length of the longest token. It contains the tokens in string.
separator is allocated with the lower bound equal to one and the upper bound equal to one less than the number of
tokens in string, and with character length equal to one. It contains the token delimiters in string.
This subroutine implements the tokenize intrinsic procedure as defined in the Fortran 2023 language standard
(Section 16.9.210). We implement it ourselves because the compiler support may take years to become widespread.
(KCW, 2025-10-29)
| Type | Intent | Optional | 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(:) |