pure function is_sorted_integer_int32 (V, ascending) result(res)
integer (int32), intent(in) :: V(:)
logical, intent(in), optional :: ascending
logical :: ascending_
logical :: res
integer :: i
if(present(ascending)) then
ascending_ = ascending
else
ascending_ = .true.
endif
res = .true.
if (ascending_) then
do i = 1, size(V) - 1
if (V(i) > V(i + 1)) then
res = .false.
return
end if
end do
else
do i = 1, size(V) - 1
if (V(i) < V(i + 1)) then
res = .false.
return
end if
end do
end if
end function is_sorted_integer_int32