is_sorted_sp Function

private pure function is_sorted_sp(array, order) result(sorted)

Arguments

Type IntentOptional Attributes Name
real(kind=sp), intent(in) :: array(:)
integer(kind=default_int), intent(in), optional :: order

Return Value logical


Called by

proc~~is_sorted_sp~~CalledByGraph proc~is_sorted_sp is_sorted_sp interface~is_sorted is_sorted interface~is_sorted->proc~is_sorted_sp

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private :: i
integer(kind=default_int), private :: sort_order

Source Code

   pure function is_sorted_sp(array, order) result(sorted)
      real(sp), intent(in) :: array(:)
      integer(default_int), intent(in), optional :: order
      integer(default_int):: sort_order
      integer(default_int) :: i
      logical :: sorted

      sorted = .true.
      sort_order = ASCENDING

      if (present(order)) then
         sort_order = order
      end if

      select case (sort_order)
      case (DESCENDING)
         do i = 1, size(array) - 1
            if (array(i + 1) > array(i)) then
               sorted = .false.
               return
            end if
         end do
      case default  ! ASCENDING or any other value
         do i = 1, size(array) - 1
            if (array(i + 1) < array(i)) then
               sorted = .false.
               return
            end if
         end do
      end select

   end function is_sorted_sp