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

Go to the source code of this file.

Functions/Subroutines

subroutine isortid (ix, dy, n, kflag)
 

Function/Subroutine Documentation

◆ isortid()

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