Octopus
sort.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!! Copyright (C) 2021 S. Ohlmann
3!!
4!! This program is free software; you can redistribute it and/or modify
5!! it under the terms of the GNU General Public License as published by
6!! the Free Software Foundation; either version 2, or (at your option)
7!! any later version.
8!!
9!! This program is distributed in the hope that it will be useful,
10!! but WITHOUT ANY WARRANTY; without even the implied warranty of
11!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12!! GNU General Public License for more details.
13!!
14!! You should have received a copy of the GNU General Public License
15!! along with this program; if not, write to the Free Software
16!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17!! 02110-1301, USA.
18!!
19
20#include "global.h"
21
24module sort_oct_m
25 use debug_oct_m
26 use global_oct_m
27
28 implicit none
29
30 private
31 public :: &
32 sort
33
34 ! ------------------------------------------------------------------------------
56 interface sort
57 module procedure dsort, isort, lsort
58 module procedure dshellsort1, zshellsort1, ishellsort1
59 module procedure dshellsort2, zshellsort2, ishellsort2
60 end interface sort
61
63 interface
64 subroutine dsort1(size, array)
65 use, intrinsic :: iso_fortran_env
66 implicit none
67 integer, intent(in) :: size
68 real(real64), intent(inout) :: array(*)
69 end subroutine dsort1
70
71 subroutine dsort2(size, array, indices)
72 use, intrinsic :: iso_fortran_env
73 implicit none
74 integer, intent(in) :: size
75 real(real64), intent(inout) :: array(*)
76 integer, intent(out) :: indices(*)
77 end subroutine dsort2
78
79 subroutine isort1(size, array)
80 implicit none
81 integer, intent(in) :: size
82 integer, intent(inout) :: array(*)
83 end subroutine isort1
84
85 subroutine isort2(size, array, indices)
86 implicit none
87 integer, intent(in) :: size
88 integer, intent(inout) :: array(*)
89 integer, intent(out) :: indices(*)
90 end subroutine isort2
91
92 subroutine lsort1(size, array)
93 use, intrinsic :: iso_fortran_env
94 implicit none
95 integer, intent(in) :: size
96 integer(int64), intent(inout) :: array(*)
97 end subroutine lsort1
98
99 subroutine lsort2(size, array, indices)
100 use, intrinsic :: iso_fortran_env
101 implicit none
102 integer, intent(in) :: size
103 integer(int64), intent(inout) :: array(*)
104 integer, intent(out) :: indices(*)
105 end subroutine lsort2
106 end interface
107
108contains
109
110 ! ---------------------------------------------------------
111 subroutine dsort(a, ind)
112 real(real64), intent(inout) :: a(:)
113 integer, optional, intent(out) :: ind(:)
114
115 push_sub(dsort)
116
117 if (size(a) > 0) then
118
119 if (.not. present(ind)) then
120 call dsort1(size(a), a)
121 else
122 call dsort2(size(a), a, ind)
123 end if
124
125 end if
126
127 pop_sub(dsort)
128 end subroutine dsort
129
130
131 ! ---------------------------------------------------------
133 subroutine isort(a, ind)
134 integer, intent(inout) :: a(:)
135 integer, optional, intent(out) :: ind(:)
136
137 push_sub(isort)
138
139 if (size(a) > 0) then
140
141 if (.not. present(ind)) then
142 call isort1(size(a), a)
143 else
144 call isort2(size(a), a, ind)
145 end if
146
147 end if
148
149 pop_sub(isort)
150 end subroutine isort
151
152 ! ---------------------------------------------------------
154 subroutine lsort(a, ind)
155 integer(int64), intent(inout) :: a(:)
156 integer, optional, intent(out) :: ind(:)
158 push_sub(lsort)
159
160 if (size(a) > 0) then
161
162 if (.not. present(ind)) then
163 call lsort1(size(a), a)
164 else
165 call lsort2(size(a), a, ind)
166 end if
167
168 end if
169
170 pop_sub(lsort)
171 end subroutine lsort
173
174#include "undef.F90"
175#include "complex.F90"
176#include "sort_inc.F90"
177
178#include "undef.F90"
179#include "real.F90"
180#include "sort_inc.F90"
181
182#include "undef.F90"
183#include "integer.F90"
184#include "sort_inc.F90"
186end module sort_oct_m
187
188!! Local Variables:
189!! mode: f90
190!! coding: utf-8
191!! End:
from sort_low.cc
Definition: sort.F90:157
This is the common interface to a sorting routine. It performs the shell algorithm,...
Definition: sort.F90:149
This module is intended to contain "only mathematical" functions and procedures.
Definition: sort.F90:117
subroutine ishellsort2(a, x)
Definition: sort.F90:714
subroutine dsort(a, ind)
Definition: sort.F90:205
subroutine dshellsort1(a, x)
Definition: sort.F90:502
subroutine zshellsort2(a, x)
Definition: sort.F90:382
subroutine isort(a, ind)
Shell sort for integer arrays.
Definition: sort.F90:227
subroutine ishellsort1(a, x)
Definition: sort.F90:668
subroutine dshellsort2(a, x)
Definition: sort.F90:548
subroutine lsort(a, ind)
Shell sort for integer(int64) arrays.
Definition: sort.F90:248
subroutine zshellsort1(a, x)
Definition: sort.F90:336