find_cut_row Function

private pure function find_cut_row(ai, af, a, val) result(res)


Type IntentOptional Attributes Name
integer, intent(in) :: ai
integer, intent(in) :: af
integer, intent(in), DIMENSION(3, 1:af) :: a
integer, intent(in) :: val

Return Value integer

Source Code

   PURE FUNCTION find_cut_row(ai, af, a, val) RESULT(res)
      INTEGER, INTENT(IN)                                :: ai, af
      INTEGER, DIMENSION(3, 1:af), INTENT(IN)            :: a
      INTEGER, INTENT(IN)                                :: val
      INTEGER                                            :: res

      INTEGER                                            :: i, ihigh, ilow

! do a log(N) search along the ordered index

      ilow = ai
      IF (a(1, ilow) > val) THEN
         res = ilow
      END IF

      ihigh = af
      IF (a(1, ihigh) <= val) THEN
         res = ihigh + 1
      END IF

         IF (ihigh - ilow == 1) EXIT
         i = (ilow + ihigh)/2
         IF (a(1, i) > val) THEN
            ihigh = i
            ilow = i
         END IF
      END DO
      res = ihigh

      ! the linear search version
      ! DO i=ai,af
      !    IF (a(i)%r>val) EXIT
   END FUNCTION find_cut_row