|
|
@ -30,6 +30,7 @@
|
|
|
|
!!$
|
|
|
|
!!$
|
|
|
|
subroutine isrx(n,x,indx,dir,flag)
|
|
|
|
subroutine isrx(n,x,indx,dir,flag)
|
|
|
|
use psb_serial_mod
|
|
|
|
use psb_serial_mod
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
!
|
|
|
|
!
|
|
|
|
! Quicksort with indices into original positions.
|
|
|
|
! Quicksort with indices into original positions.
|
|
|
|
! Adapted from a number of sources, including Don Knuth's TAOCP.
|
|
|
|
! Adapted from a number of sources, including Don Knuth's TAOCP.
|
|
|
@ -39,8 +40,9 @@ subroutine isrx(n,x,indx,dir,flag)
|
|
|
|
integer :: x(n), indx(n)
|
|
|
|
integer :: x(n), indx(n)
|
|
|
|
! ..
|
|
|
|
! ..
|
|
|
|
! .. Local Scalars ..
|
|
|
|
! .. Local Scalars ..
|
|
|
|
integer i, j, ii, xx, ilx, iux, istp, piv, lpiv
|
|
|
|
integer :: xx, piv, xk, xt
|
|
|
|
integer it1, it2, n1, n2
|
|
|
|
integer i, j, ii, ilx, iux, istp, lpiv
|
|
|
|
|
|
|
|
integer ixt, n1, n2
|
|
|
|
|
|
|
|
|
|
|
|
integer, parameter :: maxstack=64,nparms=3,ithrs=16
|
|
|
|
integer, parameter :: maxstack=64,nparms=3,ithrs=16
|
|
|
|
integer :: istack(nparms,maxstack)
|
|
|
|
integer :: istack(nparms,maxstack)
|
|
|
@ -88,40 +90,40 @@ subroutine isrx(n,x,indx,dir,flag)
|
|
|
|
lpiv = (i+j)/2
|
|
|
|
lpiv = (i+j)/2
|
|
|
|
piv = x(lpiv)
|
|
|
|
piv = x(lpiv)
|
|
|
|
if (piv < x(i)) then
|
|
|
|
if (piv < x(i)) then
|
|
|
|
it1 = x(i)
|
|
|
|
xt = x(i)
|
|
|
|
it2 = indx(i)
|
|
|
|
ixt = indx(i)
|
|
|
|
x(i) = x(lpiv)
|
|
|
|
x(i) = x(lpiv)
|
|
|
|
indx(i) = indx(lpiv)
|
|
|
|
indx(i) = indx(lpiv)
|
|
|
|
x(lpiv) = it1
|
|
|
|
x(lpiv) = xt
|
|
|
|
indx(lpiv) = it2
|
|
|
|
indx(lpiv) = ixt
|
|
|
|
piv = x(lpiv)
|
|
|
|
piv = x(lpiv)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
if (piv > x(j)) then
|
|
|
|
if (piv > x(j)) then
|
|
|
|
it1 = x(j)
|
|
|
|
xt = x(j)
|
|
|
|
it2 = indx(j)
|
|
|
|
ixt = indx(j)
|
|
|
|
x(j) = x(lpiv)
|
|
|
|
x(j) = x(lpiv)
|
|
|
|
indx(j) = indx(lpiv)
|
|
|
|
indx(j) = indx(lpiv)
|
|
|
|
x(lpiv) = it1
|
|
|
|
x(lpiv) = xt
|
|
|
|
indx(lpiv) = it2
|
|
|
|
indx(lpiv) = ixt
|
|
|
|
piv = x(lpiv)
|
|
|
|
piv = x(lpiv)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
if (piv < x(i)) then
|
|
|
|
if (piv < x(i)) then
|
|
|
|
it1 = x(i)
|
|
|
|
xt = x(i)
|
|
|
|
it2 = indx(i)
|
|
|
|
ixt = indx(i)
|
|
|
|
x(i) = x(lpiv)
|
|
|
|
x(i) = x(lpiv)
|
|
|
|
indx(i) = indx(lpiv)
|
|
|
|
indx(i) = indx(lpiv)
|
|
|
|
x(lpiv) = it1
|
|
|
|
x(lpiv) = xt
|
|
|
|
indx(lpiv) = it2
|
|
|
|
indx(lpiv) = ixt
|
|
|
|
piv = x(lpiv)
|
|
|
|
piv = x(lpiv)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
!
|
|
|
|
!
|
|
|
|
! now piv is correct; place it into first location
|
|
|
|
! now piv is correct; place it into first location
|
|
|
|
it1 = x(i)
|
|
|
|
xt = x(i)
|
|
|
|
it2 = indx(i)
|
|
|
|
ixt = indx(i)
|
|
|
|
x(i) = x(lpiv)
|
|
|
|
x(i) = x(lpiv)
|
|
|
|
indx(i) = indx(lpiv)
|
|
|
|
indx(i) = indx(lpiv)
|
|
|
|
x(lpiv) = it1
|
|
|
|
x(lpiv) = xt
|
|
|
|
indx(lpiv) = it2
|
|
|
|
indx(lpiv) = ixt
|
|
|
|
piv = x(lpiv)
|
|
|
|
piv = x(lpiv)
|
|
|
|
|
|
|
|
|
|
|
|
i = ilx - 1
|
|
|
|
i = ilx - 1
|
|
|
@ -136,22 +138,22 @@ subroutine isrx(n,x,indx,dir,flag)
|
|
|
|
!
|
|
|
|
!
|
|
|
|
! Ensure finite termination for next loop
|
|
|
|
! Ensure finite termination for next loop
|
|
|
|
!
|
|
|
|
!
|
|
|
|
it1 = xk
|
|
|
|
xt = xk
|
|
|
|
x(i) = piv
|
|
|
|
x(i) = piv
|
|
|
|
in_up2:do
|
|
|
|
in_up2:do
|
|
|
|
j = j - 1
|
|
|
|
j = j - 1
|
|
|
|
xk = x(j)
|
|
|
|
xk = x(j)
|
|
|
|
if (xk <= piv) exit in_up2
|
|
|
|
if (xk <= piv) exit in_up2
|
|
|
|
end do in_up2
|
|
|
|
end do in_up2
|
|
|
|
x(i) = it1
|
|
|
|
x(i) = xt
|
|
|
|
|
|
|
|
|
|
|
|
if (j > i) then
|
|
|
|
if (j > i) then
|
|
|
|
it1 = x(i)
|
|
|
|
xt = x(i)
|
|
|
|
it2 = indx(i)
|
|
|
|
ixt = indx(i)
|
|
|
|
x(i) = x(j)
|
|
|
|
x(i) = x(j)
|
|
|
|
indx(i) = indx(j)
|
|
|
|
indx(i) = indx(j)
|
|
|
|
x(j) = it1
|
|
|
|
x(j) = xt
|
|
|
|
indx(j) = it2
|
|
|
|
indx(j) = ixt
|
|
|
|
else
|
|
|
|
else
|
|
|
|
exit outer_up
|
|
|
|
exit outer_up
|
|
|
|
end if
|
|
|
|
end if
|
|
|
@ -229,40 +231,40 @@ subroutine isrx(n,x,indx,dir,flag)
|
|
|
|
lpiv = (i+j)/2
|
|
|
|
lpiv = (i+j)/2
|
|
|
|
piv = x(lpiv)
|
|
|
|
piv = x(lpiv)
|
|
|
|
if (piv > x(i)) then
|
|
|
|
if (piv > x(i)) then
|
|
|
|
it1 = x(i)
|
|
|
|
xt = x(i)
|
|
|
|
it2 = indx(i)
|
|
|
|
ixt = indx(i)
|
|
|
|
x(i) = x(lpiv)
|
|
|
|
x(i) = x(lpiv)
|
|
|
|
indx(i) = indx(lpiv)
|
|
|
|
indx(i) = indx(lpiv)
|
|
|
|
x(lpiv) = it1
|
|
|
|
x(lpiv) = xt
|
|
|
|
indx(lpiv) = it2
|
|
|
|
indx(lpiv) = ixt
|
|
|
|
piv = x(lpiv)
|
|
|
|
piv = x(lpiv)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
if (piv < x(j)) then
|
|
|
|
if (piv < x(j)) then
|
|
|
|
it1 = x(j)
|
|
|
|
xt = x(j)
|
|
|
|
it2 = indx(j)
|
|
|
|
ixt = indx(j)
|
|
|
|
x(j) = x(lpiv)
|
|
|
|
x(j) = x(lpiv)
|
|
|
|
indx(j) = indx(lpiv)
|
|
|
|
indx(j) = indx(lpiv)
|
|
|
|
x(lpiv) = it1
|
|
|
|
x(lpiv) = xt
|
|
|
|
indx(lpiv) = it2
|
|
|
|
indx(lpiv) = ixt
|
|
|
|
piv = x(lpiv)
|
|
|
|
piv = x(lpiv)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
if (piv > x(i)) then
|
|
|
|
if (piv > x(i)) then
|
|
|
|
it1 = x(i)
|
|
|
|
xt = x(i)
|
|
|
|
it2 = indx(i)
|
|
|
|
ixt = indx(i)
|
|
|
|
x(i) = x(lpiv)
|
|
|
|
x(i) = x(lpiv)
|
|
|
|
indx(i) = indx(lpiv)
|
|
|
|
indx(i) = indx(lpiv)
|
|
|
|
x(lpiv) = it1
|
|
|
|
x(lpiv) = xt
|
|
|
|
indx(lpiv) = it2
|
|
|
|
indx(lpiv) = ixt
|
|
|
|
piv = x(lpiv)
|
|
|
|
piv = x(lpiv)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
!
|
|
|
|
!
|
|
|
|
! now piv is correct; place it into first location
|
|
|
|
! now piv is correct; place it into first location
|
|
|
|
it1 = x(i)
|
|
|
|
xt = x(i)
|
|
|
|
it2 = indx(i)
|
|
|
|
ixt = indx(i)
|
|
|
|
x(i) = x(lpiv)
|
|
|
|
x(i) = x(lpiv)
|
|
|
|
indx(i) = indx(lpiv)
|
|
|
|
indx(i) = indx(lpiv)
|
|
|
|
x(lpiv) = it1
|
|
|
|
x(lpiv) = xt
|
|
|
|
indx(lpiv) = it2
|
|
|
|
indx(lpiv) = ixt
|
|
|
|
piv = x(lpiv)
|
|
|
|
piv = x(lpiv)
|
|
|
|
|
|
|
|
|
|
|
|
i = ilx - 1
|
|
|
|
i = ilx - 1
|
|
|
@ -277,22 +279,22 @@ subroutine isrx(n,x,indx,dir,flag)
|
|
|
|
!
|
|
|
|
!
|
|
|
|
! Ensure finite termination for next loop
|
|
|
|
! Ensure finite termination for next loop
|
|
|
|
!
|
|
|
|
!
|
|
|
|
it1 = xk
|
|
|
|
xt = xk
|
|
|
|
x(i) = piv
|
|
|
|
x(i) = piv
|
|
|
|
in_dw2:do
|
|
|
|
in_dw2:do
|
|
|
|
j = j - 1
|
|
|
|
j = j - 1
|
|
|
|
xk = x(j)
|
|
|
|
xk = x(j)
|
|
|
|
if (xk >= piv) exit in_dw2
|
|
|
|
if (xk >= piv) exit in_dw2
|
|
|
|
end do in_dw2
|
|
|
|
end do in_dw2
|
|
|
|
x(i) = it1
|
|
|
|
x(i) = xt
|
|
|
|
|
|
|
|
|
|
|
|
if (j > i) then
|
|
|
|
if (j > i) then
|
|
|
|
it1 = x(i)
|
|
|
|
xt = x(i)
|
|
|
|
it2 = indx(i)
|
|
|
|
ixt = indx(i)
|
|
|
|
x(i) = x(j)
|
|
|
|
x(i) = x(j)
|
|
|
|
indx(i) = indx(j)
|
|
|
|
indx(i) = indx(j)
|
|
|
|
x(j) = it1
|
|
|
|
x(j) = xt
|
|
|
|
indx(j) = it2
|
|
|
|
indx(j) = ixt
|
|
|
|
else
|
|
|
|
else
|
|
|
|
exit outer_dw
|
|
|
|
exit outer_dw
|
|
|
|
end if
|
|
|
|
end if
|
|
|
@ -353,6 +355,7 @@ subroutine isrx(n,x,indx,dir,flag)
|
|
|
|
contains
|
|
|
|
contains
|
|
|
|
|
|
|
|
|
|
|
|
subroutine iisrx_up(n,x,indx)
|
|
|
|
subroutine iisrx_up(n,x,indx)
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
integer :: n
|
|
|
|
integer :: n
|
|
|
|
integer :: x(n)
|
|
|
|
integer :: x(n)
|
|
|
|
integer :: indx(n)
|
|
|
|
integer :: indx(n)
|
|
|
@ -378,6 +381,7 @@ contains
|
|
|
|
end subroutine iisrx_up
|
|
|
|
end subroutine iisrx_up
|
|
|
|
|
|
|
|
|
|
|
|
subroutine iisrx_dw(n,x,indx)
|
|
|
|
subroutine iisrx_dw(n,x,indx)
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
integer :: n
|
|
|
|
integer :: n
|
|
|
|
integer :: x(n)
|
|
|
|
integer :: x(n)
|
|
|
|
integer :: indx(n)
|
|
|
|
integer :: indx(n)
|
|
|
|