Sort an array and optionally make the same interchanges in an auxiliary array. The array may be sorted in increasing or decreasing order.
Type | Intent | Optional | 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 |
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