posofval_real Function

public function posofval_real(me, val, nextifnotfound, lower, upper) result(pos)

the actual position of a given value in the dynamic array

most likely this is what you need in codes, using this data structure, it first does the binary search on the sorted values with sortposofval_real and then returns the looked up position in the original unsorted array, which corresponds to the position returned by the append routine.

Arguments

Type IntentOptional Attributes Name
type(dyn_realarray_type), intent(in) :: me
real(kind=rk), intent(in) :: val
logical, intent(in), optional :: nextifnotfound

flag to indicate, if the position of the next entry in the sorted list should be returned instead, if val is not found.

integer, intent(in), optional :: lower
integer, intent(in), optional :: upper

Return Value integer


Calls

proc~~posofval_real~~CallsGraph proc~posofval_real posofval_real interface~sortedposofval~5 sortedposofval proc~posofval_real->interface~sortedposofval~5 proc~sortposofval_label sortposofval_label interface~sortedposofval~5->proc~sortposofval_label

Called by

proc~~posofval_real~~CalledByGraph proc~posofval_real posofval_real interface~positionofval~4 positionofval interface~positionofval~4->proc~posofval_real

Contents

Source Code


Source Code

  function posofval_real(me, val, nextifnotfound, lower, upper) result(pos)
    !------------------------------------------------------------------------
    type(dyn_realarray_type), intent(in) :: me !< dynamic array
    real(kind=rk), intent(in) :: val !< value to search for
    !> flag to indicate, if the position of the next entry in the sorted
    !! list should be returned instead, if val is not found.
    logical, intent(in), optional :: nextifnotfound
    integer, intent(in), optional :: lower !< lower search limit
    integer, intent(in), optional :: upper !< upper search limit
    integer :: pos !< position in the array of the searche value, 0 if not found
    !------------------------------------------------------------------------
    integer :: sortpos
    integer :: lb, ub
    !------------------------------------------------------------------------

    lb = 1
    ub = me%nvals

    if( present( lower ) ) lb = lower
    if( present( upper ) ) ub = upper

    sortpos = sortedposofval(me, val, nextifnotfound, lb, ub)

    ! if result (sorted pos)
    if ((sortpos <= me%nvals) .and. (sortpos > 0)) then
      pos = me%sorted(sortpos)
    else
      pos = sortpos
    end if
  end function posofval_real