OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
myqsort_int.F
Go to the documentation of this file.
1Copyright> OpenRadioss
2Copyright> Copyright (C) 1986-2025 Altair Engineering Inc.
3Copyright>
4Copyright> This program is free software: you can redistribute it and/or modify
5Copyright> it under the terms of the GNU Affero General Public License as published by
6Copyright> the Free Software Foundation, either version 3 of the License, or
7Copyright> (at your option) any later version.
8Copyright>
9Copyright> This program is distributed in the hope that it will be useful,
10Copyright> but WITHOUT ANY WARRANTY; without even the implied warranty of
11Copyright> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12Copyright> GNU Affero General Public License for more details.
13Copyright>
14Copyright> You should have received a copy of the GNU Affero General Public License
15Copyright> along with this program. If not, see <https://www.gnu.org/licenses/>.
16Copyright>
17Copyright>
18Copyright> Commercial Alternative: Altair Radioss Software
19Copyright>
20Copyright> As an alternative to this open-source version, Altair also offers Altair Radioss
21Copyright> software under a commercial license. Contact Altair to discuss further if the
22Copyright> commercial version may interest you: https://www.altair.com/radioss/.
23!||====================================================================
24!|| myqsort_int ../common_source/tools/sort/myqsort_int.F
25!||--- called by ------------------------------------------------------
26!|| find_surface_inter ../engine/source/interfaces/interf/find_surface_inter.F
27!|| get_segment_orientation ../engine/source/interfaces/interf/get_segment_orientation.F90
28!|| init_nodal_state ../engine/source/interfaces/interf/init_nodal_state.F
29!|| nloc_dmg_init ../starter/source/materials/fail/nloc_dmg_init.F
30!|| select_s2s ../starter/source/interfaces/inter3d1/select_s2s.F90
31!|| spmd_cell_size_exchange ../engine/source/mpi/interfaces/spmd_cell_size_exchange.F
32!|| update_neighbour_segment ../engine/source/interfaces/interf/update_neighbour_segment.F90
33!||====================================================================
34 SUBROUTINE myqsort_int(N, A, PERM, ERROR)
35C-----------------------------------------------
36c q u i c k s o r t
37C Sedgewick algorithm from "Implementing Quicksort Programs" ; int version
38C A: data
39C N: len
40C PERM: permutations
41C-----------------------------------------------
42C I m p l i c i t T y p e s
43C-----------------------------------------------
44#include "implicit_f.inc"
45C-----------------------------------------------
46C-----------------------------------------------
47C D u m m y A r g u m e n t s
48C-----------------------------------------------
49 INTEGER N,ERROR,PERM(N)
50 INTEGER :: A(N)
51C-----------------------------------------------
52C L o c a l V a r i a b l e s
53C-----------------------------------------------
54 INTEGER :: STACKLEN
55 INTEGER :: TRESHOLD
56 INTEGER :: DONE
57C the max STACKLEN <= 1 + 2 x log2 (N+1)/(TRESHOLD + 2)
58 parameter( stacklen = 128 ,
59 . treshold = 9 )
60C
61 INTEGER :: I
62 INTEGER :: IPLUS1
63 INTEGER :: J
64 INTEGER :: JMINUS1
65 INTEGER :: K
66 INTEGER :: LEFT
67 INTEGER :: LLEN
68 INTEGER :: RIGHT
69 INTEGER :: RLEN
70 INTEGER :: TOP
71 INTEGER :: STACK(STACKLEN)
72C REAL ou REAL*8
74 . rk, rv
75C
76 error = 0
77C
78 IF (n < 1) THEN
79 error = -1
80 RETURN
81 ENDIF
82
83 IF (n == 1) THEN
84 perm(1)=1
85 RETURN
86 ENDIF
87
88 DO i = 1, n
89 perm(i) = i
90 ENDDO
91C
92 top = 1
93 left = 1
94 right = n
95 IF (n <= treshold) THEN
96 done = 1
97 ELSE
98 done = 0
99 ENDIF
100
101c QUICKSORT
102c
103 DO WHILE (done /= 1)
104 rk = a((left+right)/2)
105 a((left+right)/2) = a(left)
106 a(left) = rk
107C
108 k = perm((left+right)/2)
109 perm((left+right)/2) = perm(left)
110 perm(left) = k
111
112 IF( a(left+1) > a(right) ) THEN
113 rk = a(left+1)
114 a(left+1) = a(right)
115 a(right) = rk
116 k = perm(left+1)
117 perm(left+1) = perm(right)
118 perm(right) = k
119 ENDIF
120 IF( a(left) > a(right) ) THEN
121 rk = a(left)
122 a(left) = a(right)
123 a(right) = rk
124 k = perm(left)
125 perm(left) = perm(right)
126 perm(right) = k
127 ENDIF
128 IF( a(left+1) > a(left) ) THEN
129 rk = a(left+1)
130 a(left+1) = a(left)
131 a(left) = rk
132 k = perm(left+1)
133 perm(left+1) = perm(left)
134 perm(left) = k
135 ENDIF
136
137 rv = a(left)
138 i = left+1
139 j = right
140
141 DO WHILE(j >= i)
142 i = i + 1
143 DO WHILE(a(i) < rv)
144 i = i +1
145 ENDDO
146 j = j - 1
147 DO WHILE(a(j) > rv)
148 j = j - 1
149 ENDDO
150 IF (j >= i) THEN
151 rk = a(i)
152 a(i) = a(j)
153 a(j) = rk
154 k = perm(i)
155 perm(i) = perm(j)
156 perm(j) = k
157 ENDIF
158 ENDDO
159C
160 rk = a(left)
161 a(left) = a(j)
162 a(j) = rk
163C
164 k = perm(left)
165 perm(left) = perm(j)
166 perm(j) = k
167C
168 llen = j-left
169 rlen = right - i + 1
170
171 IF(max(llen, rlen) <= treshold ) THEN
172 IF (top == 1) THEN
173 done = 1
174 ELSE
175 top = top - 2
176 left = stack(top)
177 right = stack(top+1)
178 ENDIF
179 ELSE IF(min(llen, rlen) <= treshold) THEN
180 IF( llen > rlen ) THEN
181 right = j - 1
182 ELSE
183 left = i
184 ENDIF
185 ELSE
186 IF( llen > rlen ) THEN
187 stack(top) = left
188 stack(top+1) = j-1
189 left = i
190 ELSE
191 stack(top) = i
192 stack(top+1) = right
193 right = j-1
194 ENDIF
195 top = top + 2
196 ENDIF
197 END DO
198c
199c INSERTION SORT
200c
201 i = n - 1
202 iplus1 = n
203 DO WHILE (i > 0)
204 IF( a(i) > a(iplus1) ) THEN
205 rk = a(i)
206 k = perm(i)
207 j = iplus1
208 jminus1 = i
209 DO WHILE(a(j) < rk)
210 a(jminus1) = a(j)
211 perm(jminus1) = perm(j)
212 jminus1 = j
213 j = j + 1
214 IF ( j > n ) EXIT
215 ENDDO
216 a(jminus1) = rk
217 perm(jminus1) = k
218 ENDIF
219C
220 iplus1 = i
221 i = i - 1
222 ENDDO
223c
224 RETURN
225c
226c -------------------
227c
228 end
#define my_real
Definition cppsort.cpp:32
#define min(a, b)
Definition macros.h:20
#define max(a, b)
Definition macros.h:21
subroutine myqsort_int(n, a, perm, error)
Definition myqsort_int.F:35