get_pair_value Function

public 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.

Arguments

Type IntentOptional Attributes 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(len=*), intent(in) :: name

The name to be searched in the pair_arr.

Return Value character(len=:), allocatable

Stores the value of the corresponding pair_type object whose name
attribute is equal to the given name.


Contents

Source Code


Source Code

    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