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

Go to the source code of this file.

Functions/Subroutines

subroutine isortiid (ix, iy, dy, n, kflag)
 

Function/Subroutine Documentation

◆ isortiid()

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