dsort Subroutine

private subroutine dsort(n, Kflag, Dx, Dy)

Sort an array and optionally make the same interchanges in an auxiliary array. The array may be sorted in increasing or decreasing order.

History

  • 29-dec-2022 : Replaced original routines. Now just a wraper for sort_ascending recursive quicksort (JW)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: n

number of values in array DX to be sorted

integer, intent(in) :: Kflag

control parameter: * Kflag < 0 : sort DX in decreasing order and optionally carry DY along. * Kflag > 0 : sort DX in increasing order and optionally carry DY along.

real(kind=wp), intent(inout), dimension(*) :: Dx

array of values to be sorted (usually abscissas)

real(kind=wp), intent(inout), optional, dimension(*) :: Dy

array to be (optionally) carried along


Calls

proc~~dsort~~CallsGraph proc~dsort bspline_defc_module::dsort proc~sort_ascending bspline_defc_module::sort_ascending proc~dsort->proc~sort_ascending

Called by

proc~~dsort~~CalledByGraph proc~dsort bspline_defc_module::dsort proc~defcmn bspline_defc_module::defcmn proc~defcmn->proc~dsort proc~dfcmn bspline_defc_module::dfcmn proc~dfcmn->proc~dsort proc~defc bspline_defc_module::defc proc~defc->proc~defcmn proc~dfc bspline_defc_module::dfc proc~dfc->proc~dfcmn

Source Code

   subroutine dsort(n, Kflag, Dx, Dy)
      implicit none

      integer, intent(in) :: n !! number of values in array DX to be sorted
      integer, intent(in) :: Kflag !! control parameter:
                                   !!  * Kflag < 0 : sort DX in decreasing order and optionally carry DY along.
                                   !!  * Kflag > 0 : sort DX in increasing order and optionally carry DY along.
      real(wp), dimension(*), intent(inout) :: Dx !! array of values to be sorted   (usually abscissas)
      real(wp), dimension(*), intent(inout), optional :: Dy !! array to be (optionally) carried along

      if (n < 1) then
         write (*, *) 'The number of values to be sorted is not positive.'
         return
      end if

      if (abs(Kflag) == 0) then
         write (*, *) 'The sort control parameter, K, cannot be 0.'
         return
      end if

      ! Alter array DX to get decreasing order if needed
      if (Kflag < 0) Dx(1:n) = -Dx(1:n)
      call sort_ascending(n, Dx, Dy)
      if (Kflag < 0) Dx(1:n) = -Dx(1:n)

   end subroutine dsort