CalculiX  2.13
A Free Software Three-Dimensional Structural Finite Element Program
isorti.f File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine isorti (ix, n, kflag)
 

Function/Subroutine Documentation

◆ isorti()

subroutine isorti ( integer, dimension(2,*)  ix,
integer  n,
integer  kflag 
)
6 !
7 ! modified: auxiliary array was dropped
8 !
9 C***BEGIN PROLOGUE ISORT
10 C***PURPOSE Sort an array and optionally make the same interchanges in
11 C an auxiliary array. The array may be sorted in increasing
12 C or decreasing order. A slightly modified QUICKSORT
13 C algorithm is used.
14 C***LIBRARY SLATEC
15 C***CATEGORY N6A2A
16 C***TYPE INTEGER (SSORT-S, DSORT-D, ISORT-I)
17 C***KEYWORDS SINGLETON QUICKSORT, SORT, SORTING
18 C***AUTHOR Jones, R. E., (SNLA)
19 C Kahaner, D. K., (NBS)
20 C Wisniewski, J. A., (SNLA)
21 C***DESCRIPTION
22 C
23 C ISORT sorts array IX and optionally makes the same interchanges in
24 C array IY. The array IX may be sorted in increasing order or
25 C decreasing order. A slightly modified quicksort algorithm is used.
26 C
27 C Description of Parameters
28 C IX(2,*) - integer array of values to be sorted
29 C IX(1,*) - integer array to be (optionally) carried along
30 C N - number of values in integer array IX to be sorted
31 C KFLAG - control parameter
32 C = 2 means sort IX(2,*) in increasing order and carry IX(1,*)
33 C along.
34 C = 1 means sort IX(2,*) in increasing order (ignoring IX(1,*))
35 C = -1 means sort IX(2,*) in decreasing order (ignoring IX(1,*))
36 C = -2 means sort IX(2,*) in decreasing order and carry IX(1,*)
37 C along.
38 C
39 C***REFERENCES R. C. Singleton, Algorithm 347, An efficient algorithm
40 C for sorting with minimal storage, Communications of
41 C the ACM, 12, 3 (1969), pp. 185-187.
42 C***ROUTINES CALLED XERMSG
43 C***REVISION HISTORY (YYMMDD)
44 C 761118 DATE WRITTEN
45 C 810801 Modified by David K. Kahaner.
46 C 890531 Changed all specific intrinsics to generic. (WRB)
47 C 890831 Modified array declarations. (WRB)
48 C 891009 Removed unreferenced statement labels. (WRB)
49 C 891009 REVISION DATE from Version 3.2
50 C 891214 Prologue converted to Version 4.0 format. (BAB)
51 C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
52 C 901012 Declared all variables; changed X,Y to IX,IY. (M. McClain)
53 C 920501 Reformatted the REFERENCES section. (DWL, WRB)
54 C 920519 Clarified error messages. (DWL)
55 C 920801 Declarations section rebuilt and code restructured to use
56 C IF-THEN-ELSE-ENDIF. (RWC, WRB)
57 ! 100411 changed the dimension of IL and IU from 21 to 31.
58 !
59 ! field IL and IU have the dimension 31. This is log2 of the largest
60 ! array size to be sorted. If arrays larger than 2**31 in length have
61 ! to be sorted, this dimension has to be modified accordingly
62 !
63 C***END PROLOGUE ISORT
64 !
65  implicit none
66 C .. Scalar Arguments ..
67  integer kflag, n
68 C .. Array Arguments ..
69  integer ix(2,*)
70 C .. Local Scalars ..
71  real r
72  integer i, ij, j, k, kk, l, m, nn, t, tt, tty, ty
73 C .. Local Arrays ..
74  integer il(31), iu(31)
75 C .. External Subroutines ..
76 ! EXTERNAL XERMSG
77 C .. Intrinsic Functions ..
78  intrinsic abs, int
79 C***FIRST EXECUTABLE STATEMENT ISORT
80  nn = n
81  if (nn .lt. 1) then
82 ! CALL XERMSG ('SLATEC', 'ISORT',
83 ! + 'The number of values to be sorted is not positive.', 1, 1)
84  return
85  endif
86 C
87  kk = abs(kflag)
88  if (kk.ne.1 .and. kk.ne.2) then
89 ! CALL XERMSG ('SLATEC', 'ISORT',
90 ! + 'The sort control parameter, K, is not 2, 1, -1, or -2.', 2,
91 ! + 1)
92  return
93  endif
94 C
95 C Alter array IX to get decreasing order if needed
96 C
97  if (kflag .le. -1) then
98  do 10 i=1,nn
99  ix(2,i) = -ix(2,i)
100  10 continue
101  endif
102 C
103  if (kk .eq. 2) go to 100
104 C
105 C Sort IX only
106 C
107  m = 1
108  i = 1
109  j = nn
110  r = 0.375e0
111 C
112  20 if (i .eq. j) go to 60
113  if (r .le. 0.5898437e0) then
114  r = r+3.90625e-2
115  else
116  r = r-0.21875e0
117  endif
118 C
119  30 k = i
120 C
121 C Select a central element of the array and save it in location T
122 C
123  ij = i + int((j-i)*r)
124  t = ix(2,ij)
125 C
126 C If first element of array is greater than T, interchange with T
127 C
128  if (ix(2,i) .gt. t) then
129  ix(2,ij) = ix(2,i)
130  ix(2,i) = t
131  t = ix(2,ij)
132  endif
133  l = j
134 C
135 C If last element of array is less than than T, interchange with T
136 C
137  if (ix(2,j) .lt. t) then
138  ix(2,ij) = ix(2,j)
139  ix(2,j) = t
140  t = ix(2,ij)
141 C
142 C If first element of array is greater than T, interchange with T
143 C
144  if (ix(2,i) .gt. t) then
145  ix(2,ij) = ix(2,i)
146  ix(2,i) = t
147  t = ix(2,ij)
148  endif
149  endif
150 C
151 C Find an element in the second half of the array which is smaller
152 C than T
153 C
154  40 l = l-1
155  if (ix(2,l) .gt. t) go to 40
156 C
157 C Find an element in the first half of the array which is greater
158 C than T
159 C
160  50 k = k+1
161  if (ix(2,k) .lt. t) go to 50
162 C
163 C Interchange these elements
164 C
165  if (k .le. l) then
166  tt = ix(2,l)
167  ix(2,l) = ix(2,k)
168  ix(2,k) = tt
169  go to 40
170  endif
171 C
172 C Save upper and lower subscripts of the array yet to be sorted
173 C
174  if (l-i .gt. j-k) then
175  il(m) = i
176  iu(m) = l
177  i = k
178  m = m+1
179  else
180  il(m) = k
181  iu(m) = j
182  j = l
183  m = m+1
184  endif
185  go to 70
186 C
187 C Begin again on another portion of the unsorted array
188 C
189  60 m = m-1
190  if (m .eq. 0) go to 190
191  i = il(m)
192  j = iu(m)
193 C
194  70 if (j-i .ge. 1) go to 30
195  if (i .eq. 1) go to 20
196  i = i-1
197 C
198  80 i = i+1
199  if (i .eq. j) go to 60
200  t = ix(2,i+1)
201  if (ix(2,i) .le. t) go to 80
202  k = i
203 C
204  90 ix(2,k+1) = ix(2,k)
205  k = k-1
206  if (t .lt. ix(2,k)) go to 90
207  ix(2,k+1) = t
208  go to 80
209 C
210 C Sort IX and carry IY along
211 C
212  100 m = 1
213  i = 1
214  j = nn
215  r = 0.375e0
216 C
217  110 if (i .eq. j) go to 150
218  if (r .le. 0.5898437e0) then
219  r = r+3.90625e-2
220  else
221  r = r-0.21875e0
222  endif
223 C
224  120 k = i
225 C
226 C Select a central element of the array and save it in location T
227 C
228  ij = i + int((j-i)*r)
229  t = ix(2,ij)
230  ty = ix(1,ij)
231 C
232 C If first element of array is greater than T, interchange with T
233 C
234  if (ix(2,i) .gt. t) then
235  ix(2,ij) = ix(2,i)
236  ix(2,i) = t
237  t = ix(2,ij)
238  ix(1,ij) = ix(1,i)
239  ix(1,i) = ty
240  ty = ix(1,ij)
241  endif
242  l = j
243 C
244 C If last element of array is less than T, interchange with T
245 C
246  if (ix(2,j) .lt. t) then
247  ix(2,ij) = ix(2,j)
248  ix(2,j) = t
249  t = ix(2,ij)
250  ix(1,ij) = ix(1,j)
251  ix(1,j) = ty
252  ty = ix(1,ij)
253 C
254 C If first element of array is greater than T, interchange with T
255 C
256  if (ix(2,i) .gt. t) then
257  ix(2,ij) = ix(2,i)
258  ix(2,i) = t
259  t = ix(2,ij)
260  ix(1,ij) = ix(1,i)
261  ix(1,i) = ty
262  ty = ix(1,ij)
263  endif
264  endif
265 C
266 C Find an element in the second half of the array which is smaller
267 C than T
268 C
269  130 l = l-1
270  if (ix(2,l) .gt. t) go to 130
271 C
272 C Find an element in the first half of the array which is greater
273 C than T
274 C
275  140 k = k+1
276  if (ix(2,k) .lt. t) go to 140
277 C
278 C Interchange these elements
279 C
280  if (k .le. l) then
281  tt = ix(2,l)
282  ix(2,l) = ix(2,k)
283  ix(2,k) = tt
284  tty = ix(1,l)
285  ix(1,l) = ix(1,k)
286  ix(1,k) = tty
287  go to 130
288  endif
289 C
290 C Save upper and lower subscripts of the array yet to be sorted
291 C
292  if (l-i .gt. j-k) then
293  il(m) = i
294  iu(m) = l
295  i = k
296  m = m+1
297  else
298  il(m) = k
299  iu(m) = j
300  j = l
301  m = m+1
302  endif
303  go to 160
304 C
305 C Begin again on another portion of the unsorted array
306 C
307  150 m = m-1
308  if (m .eq. 0) go to 190
309  i = il(m)
310  j = iu(m)
311 C
312  160 if (j-i .ge. 1) go to 120
313  if (i .eq. 1) go to 110
314  i = i-1
315 C
316  170 i = i+1
317  if (i .eq. j) go to 150
318  t = ix(2,i+1)
319  ty = ix(1,i+1)
320  if (ix(2,i) .le. t) go to 170
321  k = i
322 C
323  180 ix(2,k+1) = ix(2,k)
324  ix(1,k+1) = ix(1,k)
325  k = k-1
326  if (t .lt. ix(2,k)) go to 180
327  ix(2,k+1) = t
328  ix(1,k+1) = ty
329  go to 170
330 C
331 C Clean up
332 C
333  190 if (kflag .le. -1) then
334  do 200 i=1,nn
335  ix(2,i) = -ix(2,i)
336  200 continue
337  endif
338  return
Hosted by OpenAircraft.com, (Michigan UAV, LLC)