The function retrieves the
value
associated with a specifiedname
from the passed array ofpair_type
objects (i.e., pair_arr). The search for thename
is case-insensitive. If thename
is not found, the function returns an unallocated string. In the case of duplicatename
entries in thepair_arr
, the function returns thevalue
of the first occurrence of thename
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(pair_type), | intent(in) | :: | pair_arr(:) |
The array in which we want to find a |
||
character(len=*), | intent(in) | :: | name |
The |
Stores the value
of the corresponding pair_type
object whose name
attribute is equal to the given name
.
pure function get_pair_value(pair_arr, name) result(val)
!!> The function retrieves the `value` associated with a specified
!!> `name` from the passed array of `pair_type` objects (i.e., pair_arr).
!!> The search for the `name` is **case-insensitive**. If the `name` is
!!> not found, the function returns an **unallocated string**. In the case
!!> of duplicate `name` entries in the `pair_arr`, the function returns the
!!> `value` of the **first occurrence** of the `name`.
type(pair_type), intent(in) :: pair_arr(:)
!! The array in which we want to find a `pair_type` instance with its
!! `name` attribute equal to the given `name`.
character(*), intent(in) :: name
!! The `name` to be searched in the `pair_arr`.
character(:), allocatable :: val
!! Stores the `value` of the corresponding `pair_type` object whose `name`
!! attribute is equal to the given `name`.
integer :: n
do n = 1, size(pair_arr)
if (to_lower(name) == to_lower(pair_arr(n)%name)) then
val = pair_arr(n)%value
return
end if
end do
end function get_pair_value