65 subroutine dsort1(size, array)
66 use,
intrinsic :: iso_fortran_env
68 integer,
intent(in) :: size
69 real(real64),
intent(inout) :: array(*)
72 subroutine dsort2(size, array, indices)
73 use,
intrinsic :: iso_fortran_env
75 integer,
intent(in) :: size
76 real(real64),
intent(inout) :: array(*)
77 integer,
intent(out) :: indices(*)
80 subroutine isort1(size, array)
82 integer,
intent(in) :: size
83 integer,
intent(inout) :: array(*)
86 subroutine isort2(size, array, indices)
88 integer,
intent(in) :: size
89 integer,
intent(inout) :: array(*)
90 integer,
intent(out) :: indices(*)
93 subroutine lsort1(size, array)
94 use,
intrinsic :: iso_fortran_env
96 integer,
intent(in) :: size
97 integer(int64),
intent(inout) :: array(*)
100 subroutine lsort2(size, array, indices)
101 use,
intrinsic :: iso_fortran_env
103 integer,
intent(in) :: size
104 integer(int64),
intent(inout) :: array(*)
105 integer,
intent(out) :: indices(*)
112 subroutine dsort(a, ind)
113 real(real64),
intent(inout) :: a(:)
114 integer,
optional,
intent(out) :: ind(:)
118 if (
size(a) > 0)
then
120 if (.not.
present(ind))
then
123 call dsort2(
size(a), a, ind)
134 subroutine isort(a, ind)
135 integer,
intent(inout) :: a(:)
136 integer,
optional,
intent(out) :: ind(:)
140 if (
size(a) > 0)
then
142 if (.not.
present(ind))
then
145 call isort2(
size(a), a, ind)
155 subroutine lsort(a, ind)
156 integer(int64),
intent(inout) :: a(:)
157 integer,
optional,
intent(out) :: ind(:)
161 if (
size(a) > 0)
then
163 if (.not.
present(ind))
then
166 call lsort2(
size(a), a, ind)
176 pure logical function less_idx(i, j, off, kabs, ksgn)
result(less)
177 integer,
intent(in) :: i, j
178 integer,
intent(in) :: off(:, :)
179 real(int64),
intent(in) :: kabs(:)
180 integer,
intent(in) :: ksgn(:)
184 if (.not. abs(kabs(i) - kabs(j)) <= abs(kabs(j) * 1.0e-14_real64))
then
185 less = kabs(i) < kabs(j)
189 if (ksgn(i) /= ksgn(j))
then
190 less = ksgn(i) < ksgn(j)
196 if (off(d,i) /= off(d,j))
then
197 less = off(d,i) < off(d,j)
206 recursive subroutine mergesort_perm(perm, tmp, l, r, off, kabs, ksgn)
207 integer,
intent(inout) :: perm(:), tmp(:)
208 integer,
intent(in) :: l, r
209 integer,
intent(in) :: off(:, :)
210 real(real64),
intent(in) :: kabs(:)
211 integer,
intent(in) :: ksgn(:)
213 integer :: m, i, j, k
221 i = l; j = m+1; k = l
222 do while (i <= m .and. j <= r)
223 if (
less_idx(perm(i), perm(j), off, kabs, ksgn))
then
224 tmp(k) = perm(i); i = i+1
226 tmp(k) = perm(j); j = j+1
230 do while (i <= m); tmp(k) = perm(i); i=i+1; k=k+1;
end do
231 do while (j <= r); tmp(k) = perm(j); j=j+1; k=k+1;
end do
243 real(real64),
intent(in) :: v(:)
244 integer,
intent(in) :: off(:, :)
245 integer,
intent(out) :: perm(size(v))
246 logical,
intent(in),
optional :: negative_first
250 integer,
allocatable :: tmp(:)
251 real(real64),
allocatable :: kabs(:)
252 integer,
allocatable :: ksgn(:)
257 assert(
size(off, dim=2) == n)
261 allocate(tmp(n), kabs(n), ksgn(n))
268 ksgn(i) = merge(0, 1, v(i) < 0.0_real64)
270 ksgn(i) = merge(0, 1, v(i) >= 0.0_real64)
276 deallocate(tmp, kabs, ksgn)
281#include "complex.F90"
282#include "sort_inc.F90"
286#include "sort_inc.F90"
289#include "integer.F90"
290#include "sort_inc.F90"
This is the common interface to a sorting routine. It performs the shell algorithm,...
This module is intended to contain "only mathematical" functions and procedures.
subroutine ishellsort2(a, x)
subroutine dshellsort1(a, x)
subroutine zshellsort2(a, x)
subroutine isort(a, ind)
Shell sort for integer arrays.
subroutine ishellsort1(a, x)
subroutine dshellsort2(a, x)
recursive subroutine mergesort_perm(perm, tmp, l, r, off, kabs, ksgn)
Perform the permutations for the sorting.
pure logical function less_idx(i, j, off, kabs, ksgn)
Sorting criterium for the robust sorting below.
subroutine lsort(a, ind)
Shell sort for integer(int64) arrays.
subroutine, public robust_sort_by_abs(v, off, perm, negative_first)
Robbust sorting of floating point numbers by absolute values.
subroutine zshellsort1(a, x)