sort_real_ascending Subroutine

public subroutine sort_real_ascending(values)

Sort finite real values ascending in place (heapsort; equal values may change order).

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(inout) :: values(:)

Called by

proc~~sort_real_ascending~~CalledByGraph proc~sort_real_ascending sort_real_ascending proc~build_periodic_zero_mode_height_plan build_periodic_zero_mode_height_plan proc~build_periodic_zero_mode_height_plan->proc~sort_real_ascending proc~core_build_plan_impl core_build_plan_impl proc~core_build_plan_impl->proc~sort_real_ascending proc~core_complete_plan_impl core_complete_plan_impl proc~core_build_plan_impl->proc~core_complete_plan_impl proc~core_prepare_panel_sources_impl core_prepare_panel_sources_impl proc~core_prepare_panel_sources_impl->proc~sort_real_ascending proc~beach_zero_mode_build beach_zero_mode_build proc~beach_zero_mode_build->proc~build_periodic_zero_mode_height_plan proc~build_periodic_zero_mode_plan build_periodic_zero_mode_plan proc~build_periodic_zero_mode_plan->proc~build_periodic_zero_mode_height_plan proc~core_build_panel_plan_impl core_build_panel_plan_impl proc~core_build_panel_plan_impl->proc~core_prepare_panel_sources_impl proc~core_build_panel_plan_impl->proc~core_complete_plan_impl proc~core_complete_plan_impl->proc~build_periodic_zero_mode_height_plan none~init~6 electrostatic_snapshot_type%init none~init~6->proc~build_periodic_zero_mode_plan proc~prepare_periodic_cache_and_stop prepare_periodic_cache_and_stop proc~prepare_periodic_cache_and_stop->none~init~6 program~main main program~main->proc~prepare_periodic_cache_and_stop

Source Code

  subroutine sort_real_ascending(values)
    real(dp), intent(inout) :: values(:)
    real(dp) :: key
    integer :: start, last

    last = size(values)
    do start = last/2, 1, -1
      call sift_down(start, last)
    end do
    do last = size(values), 2, -1
      key = values(last)
      values(last) = values(1)
      values(1) = key
      call sift_down(1, last - 1)
    end do
  contains
    subroutine sift_down(first, limit)
      integer, intent(in) :: first, limit
      integer :: root, child
      real(dp) :: key

      root = first
      key = values(root)
      do while (root <= limit/2)
        child = 2*root
        if (child < limit) then
          if (values(child) < values(child + 1)) child = child + 1
        end if
        if (key >= values(child)) exit
        values(root) = values(child)
        root = child
      end do
      values(root) = key
    end subroutine sift_down
  end subroutine sort_real_ascending