25 integer(I4B),
dimension(:),
intent(inout) :: indx
26 integer(I4B),
dimension(:),
intent(inout) :: v
27 logical,
intent(in),
optional :: reverse
30 integer(I4B),
parameter :: nn = 15
31 integer(I4B),
parameter :: nstack = 50
36 integer(I4B) :: jstack
38 integer(I4B) :: iright
39 integer(I4B),
dimension(nstack) :: istack
47 if (
present(reverse))
then
61 if (iright - ileft < nn)
then
62 do j = (ileft + 1), iright
65 do i = (j - 1), ileft, -1
73 if (jstack == 0)
return
74 iright = istack(jstack)
75 ileft = istack(jstack - 1)
78 k = (ileft + iright) / 2
79 call iswap(v(k), v(ileft + 1))
80 call iswap(indx(k), indx(ileft + 1))
81 if (v(ileft) > v(iright))
then
82 call iswap(v(ileft), v(iright))
83 call iswap(indx(ileft), indx(iright))
85 if (v(ileft + 1) > v(iright))
then
86 call iswap(v(ileft + 1), v(iright))
87 call iswap(indx(ileft + 1), indx(iright))
89 if (v(ileft) > v(ileft + 1))
then
90 call iswap(v(ileft), v(ileft + 1))
91 call iswap(indx(ileft), indx(ileft + 1))
113 call iswap(v(i), v(j))
114 call iswap(indx(i), indx(j))
117 indx(ileft + 1) = indx(j)
121 if (jstack > nstack)
then
122 write (
errmsg,
'(a,3(1x,a))') &
123 'JSTACK > NSTACK IN SortModule::qsort'
126 if ((iright - i + 1) >= (j - 1))
then
127 istack(jstack) = iright
128 istack(jstack - 1) = i
131 istack(jstack) = j - 1
132 istack(jstack - 1) = ileft
142 call iswap(v(i), v(j))
143 call iswap(indx(i), indx(j))
153 integer(I4B),
dimension(:),
intent(inout) :: indx
154 real(DP),
dimension(:),
intent(inout) :: v
155 logical,
intent(in),
optional :: reverse
158 integer(I4B),
parameter :: nn = 15
159 integer(I4B),
parameter :: nstack = 50
160 integer(I4B) :: nsize
164 integer(I4B) :: jstack
165 integer(I4B) :: ileft
166 integer(I4B) :: iright
167 integer(I4B),
dimension(nstack) :: istack
175 if (
present(reverse))
then
189 if (iright - ileft < nn)
then
190 do j = (ileft + 1), iright
193 do i = (j - 1), ileft, -1
196 indx(i + 1) = indx(i)
201 if (jstack == 0)
return
202 iright = istack(jstack)
203 ileft = istack(jstack - 1)
206 k = (ileft + iright) / 2
207 call rswap(v(k), v(ileft + 1))
208 call iswap(indx(k), indx(ileft + 1))
209 if (v(ileft) > v(iright))
then
210 call rswap(v(ileft), v(iright))
211 call iswap(indx(ileft), indx(iright))
213 if (v(ileft + 1) > v(iright))
then
214 call rswap(v(ileft + 1), v(iright))
215 call iswap(indx(ileft + 1), indx(iright))
217 if (v(ileft) > v(ileft + 1))
then
218 call rswap(v(ileft), v(ileft + 1))
219 call iswap(indx(ileft), indx(ileft + 1))
241 call rswap(v(i), v(j))
242 call iswap(indx(i), indx(j))
245 indx(ileft + 1) = indx(j)
249 if (jstack > nstack)
then
250 write (
errmsg,
'(a,3(1x,a))') &
251 'JSTACK > NSTACK IN SortModule::qsort'
254 if ((iright - i + 1) >= (j - 1))
then
255 istack(jstack) = iright
256 istack(jstack - 1) = i
259 istack(jstack) = j - 1
260 istack(jstack - 1) = ileft
270 call rswap(v(i), v(j))
271 call iswap(indx(i), indx(j))
279 integer(I4B),
dimension(:),
allocatable,
intent(in) :: a
280 integer(I4B),
dimension(:),
allocatable,
intent(inout) :: b
282 integer(I4B) :: count
284 integer(I4B),
dimension(:),
allocatable :: indxarr
285 integer(I4B),
dimension(:),
allocatable :: tarr
290 allocate (tarr(
size(a)))
291 allocate (indxarr(
size(a)))
300 call qsort(indxarr, tarr, reverse=.true.)
305 if (tarr(n) > tarr(n - 1)) count = count + 1
309 if (
allocated(b))
then
318 if (tarr(n) > b(count))
then
331 real(DP),
dimension(:),
allocatable,
intent(in) :: a
332 real(DP),
dimension(:),
allocatable,
intent(inout) :: b
334 integer(I4B) :: count
336 integer(I4B),
dimension(:),
allocatable :: indxarr
337 real(DP),
dimension(:),
allocatable :: tarr
342 allocate (tarr(
size(a)))
343 allocate (indxarr(
size(a)))
352 call qsort(indxarr, tarr, reverse=.true.)
357 if (tarr(n) > tarr(n - 1)) count = count + 1
361 if (
allocated(b))
then
370 if (tarr(n) > b(count))
then
385 integer(I4B),
dimension(:),
intent(inout) :: indx
386 real(dp),
dimension(:),
intent(inout) :: v
387 logical,
intent(in),
optional :: reverse
390 integer(I4B) :: nsizei
391 integer(I4B) :: nsizev
397 real(dp),
dimension(:),
allocatable :: vv
402 if (
present(reverse))
then
410 nsizei = min(nsizev,
size(indx))
411 allocate (vv(nsizei))
423 do i = nsizei + 1, nsizev
426 if (v(i) > vv(1))
then
435 if (k /= nsizei)
then
436 if (vv(k) > vv(k + 1))
then
440 if (vv(j) <= vv(k))
then
443 call rswap(vv(k), vv(j))
444 call iswap(indx(k), indx(j))
457 call iswap(indx(i), indx(j))
465 real(DP),
intent(inout) :: a
466 real(DP),
intent(inout) :: b
478 integer(I4B),
intent(inout) :: ia
479 integer(I4B),
intent(inout) :: ib
This module contains simulation constants.
integer(i4b), parameter linelength
maximum length of a standard line
This module defines variable data types.
This module contains simulation methods.
subroutine, public store_error(msg, terminate)
Store an error message.
This module contains simulation variables.
character(len=maxcharlen) errmsg
error message string
subroutine unique_values_int1d(a, b)
subroutine qsort_dbl1d(indx, v, reverse)
subroutine, public selectn(indx, v, reverse)
subroutine unique_values_dbl1d(a, b)
subroutine qsort_int1d(indx, v, reverse)