find_cut_col Function

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

Arguments

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_col(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(2, ilow) > val) THEN
         res = ilow
         RETURN
      END IF

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

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

      ! the linear search version
      ! DO i=ai,af
      !    IF (a(i)%c>val) EXIT
      !ENDDO
      !res=i
   END FUNCTION find_cut_col