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

Go to the source code of this file.

Functions/Subroutines

subroutine isortiiddc (ix1, ix2, dy1, dy2, cy, n, kflag)
 

Function/Subroutine Documentation

◆ isortiiddc()

subroutine isortiiddc ( integer, dimension(2,*)  ix1,
integer, dimension(2,*)  ix2,
real*8, dimension(2,*)  dy1,
real*8, dimension(2,*)  dy2,
character*20, dimension(*)  cy,
integer  n,
integer  kflag 
)
6 !
7 ! modified to make the same interchanges in an integer (ix2), two
8 ! double (dy1 and dy2) and a char*20 aray (cy)
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 IX1 and optionally makes the same interchanges in
25 C array IY. The array IX1 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 IX1 - 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 IX1 to be sorted
32 C KFLAG - control parameter
33 C = 2 means sort IX1 in increasing order and carry IY along.
34 C = 1 means sort IX1 in increasing order (ignoring IY)
35 C = -1 means sort IX1 in decreasing order (ignoring IY)
36 C = -2 means sort IX1 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 IX1,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 C .. Scalar Arguments ..
64  implicit none
65 c
66  integer kflag, n,iside,istat
67 C .. Array Arguments ..
68  integer ix1(2,*),ix2(2,*)
69  real*8 dy1(2,*),dy2(2,*)
70  character*20 cy(*)
71 C .. Local Scalars ..
72  real r
73  integer i, ij, j, k, kk, l, m, nn, t, tt,tx21,tx12,tx22,
74  & ttx21,ttx12,ttx22
75  real*8 tty11,tty12,ty11,ty12,tty21,tty22,ty21,ty22
76  character*20 uuy,uy
77 C .. Local Arrays ..
78  integer il(31), iu(31)
79 C .. External Subroutines ..
80 ! EXTERNAL XERMSG
81 C .. Intrinsic Functions ..
82  intrinsic abs, int
83 C***FIRST EXECUTABLE STATEMENT ISORT
84 !
85  do i=1,n
86  read(cy(i)(2:2),'(i1)',iostat=istat) iside
87  if(istat.gt.0) iside=0
88  ix1(1,i)=10*ix1(1,i)+iside
89  enddo
90 !
91  nn = n
92  if (nn .lt. 1) then
93 ! CALL XERMSG ('SLATEC', 'ISORT',
94 ! + 'The number of values to be sorted is not positive.', 1, 1)
95  return
96  endif
97 C
98  kk = abs(kflag)
99  if (kk.ne.1 .and. kk.ne.2) then
100 ! CALL XERMSG ('SLATEC', 'ISORT',
101 ! + 'The sort control parameter, K, is not 2, 1, -1, or -2.', 2,
102 ! + 1)
103  return
104  endif
105 C
106 C Alter array IX1 to get decreasing order if needed
107 C
108  if (kflag .le. -1) then
109  do 10 i=1,nn
110  ix1(1,i) = -ix1(1,i)
111  10 continue
112  endif
113 C
114  if (kk .eq. 2) go to 100
115 C
116 C Sort IX1 only
117 C
118  m = 1
119  i = 1
120  j = nn
121  r = 0.375e0
122 C
123  20 if (i .eq. j) go to 60
124  if (r .le. 0.5898437e0) then
125  r = r+3.90625e-2
126  else
127  r = r-0.21875e0
128  endif
129 C
130  30 k = i
131 C
132 C Select a central element of the array and save it in location T
133 C
134  ij = i + int((j-i)*r)
135  t = ix1(1,ij)
136 C
137 C If first element of array is greater than T, interchange with T
138 C
139  if (ix1(1,i) .gt. t) then
140  ix1(1,ij) = ix1(1,i)
141  ix1(1,i) = t
142  t = ix1(1,ij)
143  endif
144  l = j
145 C
146 C If last element of array is less than than T, interchange with T
147 C
148  if (ix1(1,j) .lt. t) then
149  ix1(1,ij) = ix1(1,j)
150  ix1(1,j) = t
151  t = ix1(1,ij)
152 C
153 C If first element of array is greater than T, interchange with T
154 C
155  if (ix1(1,i) .gt. t) then
156  ix1(1,ij) = ix1(1,i)
157  ix1(1,i) = t
158  t = ix1(1,ij)
159  endif
160  endif
161 C
162 C Find an element in the second half of the array which is smaller
163 C than T
164 C
165  40 l = l-1
166  if (ix1(1,l) .gt. t) go to 40
167 C
168 C Find an element in the first half of the array which is greater
169 C than T
170 C
171  50 k = k+1
172  if (ix1(1,k) .lt. t) go to 50
173 C
174 C Interchange these elements
175 C
176  if (k .le. l) then
177  tt = ix1(1,l)
178  ix1(1,l) = ix1(1,k)
179  ix1(1,k) = tt
180  go to 40
181  endif
182 C
183 C Save upper and lower subscripts of the array yet to be sorted
184 C
185  if (l-i .gt. j-k) then
186  il(m) = i
187  iu(m) = l
188  i = k
189  m = m+1
190  else
191  il(m) = k
192  iu(m) = j
193  j = l
194  m = m+1
195  endif
196  go to 70
197 C
198 C Begin again on another portion of the unsorted array
199 C
200  60 m = m-1
201  if (m .eq. 0) go to 190
202  i = il(m)
203  j = iu(m)
204 C
205  70 if (j-i .ge. 1) go to 30
206  if (i .eq. 1) go to 20
207  i = i-1
208 C
209  80 i = i+1
210  if (i .eq. j) go to 60
211  t = ix1(1,i+1)
212  if (ix1(1,i) .le. t) go to 80
213  k = i
214 C
215  90 ix1(1,k+1) = ix1(1,k)
216  k = k-1
217  if (t .lt. ix1(1,k)) go to 90
218  ix1(1,k+1) = t
219  go to 80
220 C
221 C Sort IX1 and carry IY along
222 C
223  100 m = 1
224  i = 1
225  j = nn
226  r = 0.375e0
227 C
228  110 if (i .eq. j) go to 150
229  if (r .le. 0.5898437e0) then
230  r = r+3.90625e-2
231  else
232  r = r-0.21875e0
233  endif
234 C
235  120 k = i
236 C
237 C Select a central element of the array and save it in location T
238 C
239  ij = i + int((j-i)*r)
240  t = ix1(1,ij)
241  ty11 = dy1(1,ij)
242  ty21 = dy1(2,ij)
243  ty12 = dy2(1,ij)
244  ty22 = dy2(2,ij)
245  tx21 = ix1(2,ij)
246  tx12=ix2(1,ij)
247  tx22=ix2(2,ij)
248  uy = cy(ij)
249 C
250 C If first element of array is greater than T, interchange with T
251 C
252  if (ix1(1,i) .gt. t) then
253  ix1(1,ij) = ix1(1,i)
254  ix1(1,i) = t
255  t = ix1(1,ij)
256  dy1(1,ij) = dy1(1,i)
257  dy1(2,ij) = dy1(2,i)
258  dy2(1,ij) = dy2(1,i)
259  dy2(2,ij) = dy2(2,i)
260  ix1(2,ij) = ix1(2,i)
261  ix2(1,ij)=ix2(1,i)
262  ix2(2,ij)=ix2(2,i)
263  cy(ij) = cy(i)
264  dy1(1,i) = ty11
265  dy1(2,i) = ty21
266  dy2(1,i) = ty12
267  dy2(2,i) = ty22
268  ix1(2,i) = tx21
269  ix2(1,i)=tx12
270  ix2(2,i)=tx22
271  cy(i) = uy
272  ty11 = dy1(1,ij)
273  ty21 = dy1(2,ij)
274  ty12 = dy2(1,ij)
275  ty22 = dy2(2,ij)
276  tx21 = ix1(2,ij)
277  tx12=ix2(1,ij)
278  tx22=ix2(2,ij)
279  uy = cy(ij)
280  endif
281  l = j
282 C
283 C If last element of array is less than T, interchange with T
284 C
285  if (ix1(1,j) .lt. t) then
286  ix1(1,ij) = ix1(1,j)
287  ix1(1,j) = t
288  t = ix1(1,ij)
289  dy1(1,ij) = dy1(1,j)
290  dy1(2,ij) = dy1(2,j)
291  dy2(1,ij) = dy2(1,j)
292  dy2(2,ij) = dy2(2,j)
293  ix1(2,ij) = ix1(2,j)
294  ix2(1,ij)=ix2(1,j)
295  ix2(2,ij)=ix2(2,j)
296  cy(ij) = cy(j)
297  dy1(1,j) = ty11
298  dy1(2,j) = ty21
299  dy2(1,j) = ty12
300  dy2(2,j) = ty22
301  ix1(2,j) = tx21
302  ix2(1,j)=tx12
303  ix2(2,j)=tx22
304  cy(j) = uy
305  ty11 = dy1(1,ij)
306  ty21 = dy1(2,ij)
307  ty12 = dy2(1,ij)
308  ty22 = dy2(2,ij)
309  tx21 = ix1(2,ij)
310  tx12=ix2(1,ij)
311  tx22=ix2(2,ij)
312  uy = cy(ij)
313 C
314 C If first element of array is greater than T, interchange with T
315 C
316  if (ix1(1,i) .gt. t) then
317  ix1(1,ij) = ix1(1,i)
318  ix1(1,i) = t
319  t = ix1(1,ij)
320  dy1(1,ij) = dy1(1,i)
321  dy1(2,ij) = dy1(2,i)
322  dy2(1,ij) = dy2(1,i)
323  dy2(2,ij) = dy2(2,i)
324  ix1(2,ij) = ix1(2,i)
325  ix2(1,ij)=ix2(1,i)
326  ix2(2,ij)=ix2(2,i)
327  cy(ij) = cy(i)
328  dy1(1,i) = ty11
329  dy1(2,i) = ty21
330  dy2(1,i) = ty12
331  dy2(2,i) = ty22
332  ix1(2,i) = tx21
333  ix2(1,i)=tx12
334  ix2(2,i)=tx22
335  cy(i) = uy
336  ty11 = dy1(1,ij)
337  ty21 = dy1(2,ij)
338  ty12 = dy2(1,ij)
339  ty22 = dy2(2,ij)
340  tx21 = ix1(2,ij)
341  tx12=ix2(1,ij)
342  tx22=ix2(2,ij)
343  uy = cy(ij)
344  endif
345  endif
346 C
347 C Find an element in the second half of the array which is smaller
348 C than T
349 C
350  130 l = l-1
351  if (ix1(1,l) .gt. t) go to 130
352 C
353 C Find an element in the first half of the array which is greater
354 C than T
355 C
356  140 k = k+1
357  if (ix1(1,k) .lt. t) go to 140
358 C
359 C Interchange these elements
360 C
361  if (k .le. l) then
362  tt = ix1(1,l)
363  ix1(1,l) = ix1(1,k)
364  ix1(1,k) = tt
365  tty11 = dy1(1,l)
366  tty21 = dy1(2,l)
367  tty12 = dy2(1,l)
368  tty22 = dy2(2,l)
369  ttx21 = ix1(2,l)
370  ttx12=ix2(1,l)
371  ttx22=ix2(2,l)
372  uuy = cy(l)
373  dy1(1,l) = dy1(1,k)
374  dy1(2,l) = dy1(2,k)
375  dy2(1,l) = dy2(1,k)
376  dy2(2,l) = dy2(2,k)
377  ix1(2,l) = ix1(2,k)
378  ix2(1,l)=ix2(1,k)
379  ix2(2,l)=ix2(2,k)
380  cy(l) = cy(k)
381  dy1(1,k) = tty11
382  dy1(2,k) = tty21
383  dy2(1,k) = tty12
384  dy2(2,k) = tty22
385  ix1(2,k) = ttx21
386  ix2(1,k)=ttx12
387  ix2(2,k)=ttx22
388  cy(k) = uuy
389  go to 130
390  endif
391 C
392 C Save upper and lower subscripts of the array yet to be sorted
393 C
394  if (l-i .gt. j-k) then
395  il(m) = i
396  iu(m) = l
397  i = k
398  m = m+1
399  else
400  il(m) = k
401  iu(m) = j
402  j = l
403  m = m+1
404  endif
405  go to 160
406 C
407 C Begin again on another portion of the unsorted array
408 C
409  150 m = m-1
410  if (m .eq. 0) go to 190
411  i = il(m)
412  j = iu(m)
413 C
414  160 if (j-i .ge. 1) go to 120
415  if (i .eq. 1) go to 110
416  i = i-1
417 C
418  170 i = i+1
419  if (i .eq. j) go to 150
420  t = ix1(1,i+1)
421  ty11 = dy1(1,i+1)
422  ty21 = dy1(2,i+1)
423  ty12 = dy2(1,i+1)
424  ty22 = dy2(2,i+1)
425  tx21 = ix1(2,i+1)
426  tx12=ix2(1,i+1)
427  tx22=ix2(2,i+1)
428  uy = cy(i+1)
429  if (ix1(1,i) .le. t) go to 170
430  k = i
431 C
432  180 ix1(1,k+1) = ix1(1,k)
433  dy1(1,k+1) = dy1(1,k)
434  dy1(2,k+1) = dy1(2,k)
435  dy2(1,k+1) = dy2(1,k)
436  dy2(2,k+1) = dy2(2,k)
437  ix1(2,k+1) = ix1(2,k)
438  ix2(1,k+1)=ix2(1,k)
439  ix2(2,k+1)=ix2(2,k)
440  cy(k+1) = cy(k)
441  k = k-1
442  if (t .lt. ix1(1,k)) go to 180
443  ix1(1,k+1) = t
444  dy1(1,k+1) = ty11
445  dy1(2,k+1) = ty21
446  dy2(1,k+1) = ty12
447  dy2(2,k+1) = ty22
448  ix1(2,k+1) = tx21
449  ix2(1,k+1)=tx12
450  ix2(2,k+1)=tx22
451  cy(k+1) = uy
452  go to 170
453 C
454 C Clean up
455 C
456  190 if (kflag .le. -1) then
457  do 200 i=1,nn
458  ix1(1,i) = -ix1(1,i)
459  200 continue
460  endif
461 !
462  do i=1,nn
463  read(cy(i)(2:2),'(i1)',iostat=istat) iside
464  if(istat.gt.0) iside=0
465  ix1(1,i)=(ix1(1,i)-iside)/10
466  enddo
467 !
468  return
Hosted by OpenAircraft.com, (Michigan UAV, LLC)