pure function is_sorted_real_dp (V, ascending) result(res)
real (dp), 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_real_dp