Performa a binary search for the variable 'var_name'
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(CFG_t), | intent(in) | :: | cfg | |||
| character(len=*), | intent(in) | :: | var_name | |||
| integer, | intent(out) | :: | ix |
subroutine binary_search_variable(cfg, var_name, ix) type(CFG_t), intent(in) :: cfg character(len=*), intent(in) :: var_name integer, intent(out) :: ix integer :: i_min, i_max, i_mid i_min = 1 i_max = cfg%num_vars ix = - 1 do while (i_min < i_max) i_mid = i_min + (i_max - i_min) / 2 if ( llt(cfg%vars(i_mid)%var_name, var_name) ) then i_min = i_mid + 1 else i_max = i_mid end if end do ! If not found, binary_search_variable is not set here, and stays -1 if (i_max == i_min .and. cfg%vars(i_min)%var_name == var_name) then ix = i_min else ix = -1 end if end subroutine binary_search_variable