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

Go to the source code of this file.

Functions/Subroutines

subroutine isortii (ix, iy, n, kflag)
 

Function/Subroutine Documentation

◆ isortii()

subroutine isortii ( integer, dimension(*), intent(inout)  ix,
integer, dimension(*), intent(inout)  iy,
integer, intent(in)  n,
integer, intent(in)  kflag 
)
6 C***BEGIN PROLOGUE ISORT
7 C***PURPOSE Sort an array and optionally make the same interchanges in
8 C an auxiliary array. The array may be sorted in increasing
9 C or decreasing order. A slightly modified QUICKSORT
10 C algorithm is used.
11 C***LIBRARY SLATEC
12 C***CATEGORY N6A2A
13 C***TYPE INTEGER (SSORT-S, DSORT-D, ISORT-I)
14 C***KEYWORDS SINGLETON QUICKSORT, SORT, SORTING
15 C***AUTHOR Jones, R. E., (SNLA)
16 C Kahaner, D. K., (NBS)
17 C Wisniewski, J. A., (SNLA)
18 C***DESCRIPTION
19 C
20 C ISORT sorts array IX and optionally makes the same interchanges in
21 C array IY. The array IX may be sorted in increasing order or
22 C decreasing order. A slightly modified quicksort algorithm is used.
23 C
24 C Description of Parameters
25 C IX - integer array of values to be sorted
26 C IY - integer array to be (optionally) carried along
27 C N - number of values in integer array IX to be sorted
28 C KFLAG - control parameter
29 C = 2 means sort IX in increasing order and carry IY along.
30 C = 1 means sort IX in increasing order (ignoring IY)
31 C = -1 means sort IX in decreasing order (ignoring IY)
32 C = -2 means sort IX in decreasing order and carry IY along.
33 C
34 C***REFERENCES R. C. Singleton, Algorithm 347, An efficient algorithm
35 C for sorting with minimal storage, Communications of
36 C the ACM, 12, 3 (1969), pp. 185-187.
37 C***ROUTINES CALLED XERMSG
38 C***REVISION HISTORY (YYMMDD)
39 C 761118 DATE WRITTEN
40 C 810801 Modified by David K. Kahaner.
41 C 890531 Changed all specific intrinsics to generic. (WRB)
42 C 890831 Modified array declarations. (WRB)
43 C 891009 Removed unreferenced statement labels. (WRB)
44 C 891009 REVISION DATE from Version 3.2
45 C 891214 Prologue converted to Version 4.0 format. (BAB)
46 C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
47 C 901012 Declared all variables; changed X,Y to IX,IY. (M. McClain)
48 C 920501 Reformatted the REFERENCES section. (DWL, WRB)
49 C 920519 Clarified error messages. (DWL)
50 C 920801 Declarations section rebuilt and code restructured to use
51 C IF-THEN-ELSE-ENDIF. (RWC, WRB)
52 ! 100411 changed the dimension of IL and IU from 21 to 31.
53 ! 150514 inserted intent statements
54 !
55 ! field IL and IU have the dimension 31. This is log2 of the largest
56 ! array size to be sorted. If arrays larger than 2**31 in length have
57 ! to be sorted, this dimension has to be modified accordingly
58 !
59 C***END PROLOGUE ISORT
60 !
61  implicit none
62 C .. Scalar Arguments ..
63  integer kflag, n
64 C .. Array Arguments ..
65  integer ix(*), iy(*)
66 C .. Local Scalars ..
67  real r
68  integer i, ij, j, k, kk, l, m, nn, t, tt, tty, ty
69 C .. Local Arrays ..
70  integer il(31), iu(31)
71 C .. External Subroutines ..
72 ! EXTERNAL XERMSG
73 C .. Intrinsic Functions ..
74  intrinsic abs, int
75 !
76  intent(in) n,kflag
77 !
78  intent(inout) ix,iy
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(i) = -ix(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(ij)
125 C
126 C If first element of array is greater than T, interchange with T
127 C
128  if (ix(i) .gt. t) then
129  ix(ij) = ix(i)
130  ix(i) = t
131  t = ix(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(j) .lt. t) then
138  ix(ij) = ix(j)
139  ix(j) = t
140  t = ix(ij)
141 C
142 C If first element of array is greater than T, interchange with T
143 C
144  if (ix(i) .gt. t) then
145  ix(ij) = ix(i)
146  ix(i) = t
147  t = ix(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(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(k) .lt. t) go to 50
162 C
163 C Interchange these elements
164 C
165  if (k .le. l) then
166  tt = ix(l)
167  ix(l) = ix(k)
168  ix(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(i+1)
201  if (ix(i) .le. t) go to 80
202  k = i
203 C
204  90 ix(k+1) = ix(k)
205  k = k-1
206  if (t .lt. ix(k)) go to 90
207  ix(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(ij)
230  ty = iy(ij)
231 C
232 C If first element of array is greater than T, interchange with T
233 C
234  if (ix(i) .gt. t) then
235  ix(ij) = ix(i)
236  ix(i) = t
237  t = ix(ij)
238  iy(ij) = iy(i)
239  iy(i) = ty
240  ty = iy(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(j) .lt. t) then
247  ix(ij) = ix(j)
248  ix(j) = t
249  t = ix(ij)
250  iy(ij) = iy(j)
251  iy(j) = ty
252  ty = iy(ij)
253 C
254 C If first element of array is greater than T, interchange with T
255 C
256  if (ix(i) .gt. t) then
257  ix(ij) = ix(i)
258  ix(i) = t
259  t = ix(ij)
260  iy(ij) = iy(i)
261  iy(i) = ty
262  ty = iy(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(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(k) .lt. t) go to 140
277 C
278 C Interchange these elements
279 C
280  if (k .le. l) then
281  tt = ix(l)
282  ix(l) = ix(k)
283  ix(k) = tt
284  tty = iy(l)
285  iy(l) = iy(k)
286  iy(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(i+1)
319  ty = iy(i+1)
320  if (ix(i) .le. t) go to 170
321  k = i
322 C
323  180 ix(k+1) = ix(k)
324  iy(k+1) = iy(k)
325  k = k-1
326  if (t .lt. ix(k)) go to 180
327  ix(k+1) = t
328  iy(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(i) = -ix(i)
336  200 continue
337  endif
338  return
Hosted by OpenAircraft.com, (Michigan UAV, LLC)