KTH framework for Nek5000 toolboxes; testing version  0.0.1
dlasrt.f
Go to the documentation of this file.
1  SUBROUTINE dlasrt( ID, N, D, INFO )
2 *
3 * -- LAPACK routine (version 3.0) --
4 * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
5 * Courant Institute, Argonne National Lab, and Rice University
6 * September 30, 1994
7 *
8 * .. Scalar Arguments ..
9  CHARACTER ID
10  INTEGER INFO, N
11 * ..
12 * .. Array Arguments ..
13  DOUBLE PRECISION D( * )
14 * ..
15 *
16 * Purpose
17 * =======
18 *
19 * Sort the numbers in D in increasing order (if ID = 'I') or
20 * in decreasing order (if ID = 'D' ).
21 *
22 * Use Quick Sort, reverting to Insertion sort on arrays of
23 * size <= 20. Dimension of STACK limits N to about 2**32.
24 *
25 * Arguments
26 * =========
27 *
28 * ID (input) CHARACTER*1
29 * = 'I': sort D in increasing order;
30 * = 'D': sort D in decreasing order.
31 *
32 * N (input) INTEGER
33 * The length of the array D.
34 *
35 * D (input/output) DOUBLE PRECISION array, dimension (N)
36 * On entry, the array to be sorted.
37 * On exit, D has been sorted into increasing order
38 * (D(1) <= ... <= D(N) ) or into decreasing order
39 * (D(1) >= ... >= D(N) ), depending on ID.
40 *
41 * INFO (output) INTEGER
42 * = 0: successful exit
43 * < 0: if INFO = -i, the i-th argument had an illegal value
44 *
45 * =====================================================================
46 *
47 * .. Parameters ..
48  INTEGER SELECT
49  parameter( SELECT = 20 )
50 * ..
51 * .. Local Scalars ..
52  INTEGER DIR, ENDD, I, J, START, STKPNT
53  DOUBLE PRECISION D1, D2, D3, DMNMX, TMP
54 * ..
55 * .. Local Arrays ..
56  INTEGER STACK( 2, 32 )
57 * ..
58 * .. External Functions ..
59  LOGICAL LSAME
60  EXTERNAL lsame
61 * ..
62 * .. External Subroutines ..
63  EXTERNAL xerbla
64 * ..
65 * .. Executable Statements ..
66 *
67 * Test the input paramters.
68 *
69  info = 0
70  dir = -1
71  IF( lsame( id, 'D' ) ) THEN
72  dir = 0
73  ELSE IF( lsame( id, 'I' ) ) THEN
74  dir = 1
75  END IF
76  IF( dir.EQ.-1 ) THEN
77  info = -1
78  ELSE IF( n.LT.0 ) THEN
79  info = -2
80  END IF
81  IF( info.NE.0 ) THEN
82  CALL xerbla( 'DLASRT', -info )
83  RETURN
84  END IF
85 *
86 * Quick return if possible
87 *
88  IF( n.LE.1 )
89  $ RETURN
90 *
91  stkpnt = 1
92  stack( 1, 1 ) = 1
93  stack( 2, 1 ) = n
94  10 CONTINUE
95  start = stack( 1, stkpnt )
96  endd = stack( 2, stkpnt )
97  stkpnt = stkpnt - 1
98  IF( endd-start.LE.SELECT .AND. endd-start.GT.0 ) THEN
99 *
100 * Do Insertion sort on D( START:ENDD )
101 *
102  IF( dir.EQ.0 ) THEN
103 *
104 * Sort into decreasing order
105 *
106  DO 30 i = start + 1, endd
107  DO 20 j = i, start + 1, -1
108  IF( d( j ).GT.d( j-1 ) ) THEN
109  dmnmx = d( j )
110  d( j ) = d( j-1 )
111  d( j-1 ) = dmnmx
112  ELSE
113  GO TO 30
114  END IF
115  20 CONTINUE
116  30 CONTINUE
117 *
118  ELSE
119 *
120 * Sort into increasing order
121 *
122  DO 50 i = start + 1, endd
123  DO 40 j = i, start + 1, -1
124  IF( d( j ).LT.d( j-1 ) ) THEN
125  dmnmx = d( j )
126  d( j ) = d( j-1 )
127  d( j-1 ) = dmnmx
128  ELSE
129  GO TO 50
130  END IF
131  40 CONTINUE
132  50 CONTINUE
133 *
134  END IF
135 *
136  ELSE IF( endd-start.GT.SELECT ) THEN
137 *
138 * Partition D( START:ENDD ) and stack parts, largest one first
139 *
140 * Choose partition entry as median of 3
141 *
142  d1 = d( start )
143  d2 = d( endd )
144  i = ( start+endd ) / 2
145  d3 = d( i )
146  IF( d1.LT.d2 ) THEN
147  IF( d3.LT.d1 ) THEN
148  dmnmx = d1
149  ELSE IF( d3.LT.d2 ) THEN
150  dmnmx = d3
151  ELSE
152  dmnmx = d2
153  END IF
154  ELSE
155  IF( d3.LT.d2 ) THEN
156  dmnmx = d2
157  ELSE IF( d3.LT.d1 ) THEN
158  dmnmx = d3
159  ELSE
160  dmnmx = d1
161  END IF
162  END IF
163 *
164  IF( dir.EQ.0 ) THEN
165 *
166 * Sort into decreasing order
167 *
168  i = start - 1
169  j = endd + 1
170  60 CONTINUE
171  70 CONTINUE
172  j = j - 1
173  IF( d( j ).LT.dmnmx )
174  $ GO TO 70
175  80 CONTINUE
176  i = i + 1
177  IF( d( i ).GT.dmnmx )
178  $ GO TO 80
179  IF( i.LT.j ) THEN
180  tmp = d( i )
181  d( i ) = d( j )
182  d( j ) = tmp
183  GO TO 60
184  END IF
185  IF( j-start.GT.endd-j-1 ) THEN
186  stkpnt = stkpnt + 1
187  stack( 1, stkpnt ) = start
188  stack( 2, stkpnt ) = j
189  stkpnt = stkpnt + 1
190  stack( 1, stkpnt ) = j + 1
191  stack( 2, stkpnt ) = endd
192  ELSE
193  stkpnt = stkpnt + 1
194  stack( 1, stkpnt ) = j + 1
195  stack( 2, stkpnt ) = endd
196  stkpnt = stkpnt + 1
197  stack( 1, stkpnt ) = start
198  stack( 2, stkpnt ) = j
199  END IF
200  ELSE
201 *
202 * Sort into increasing order
203 *
204  i = start - 1
205  j = endd + 1
206  90 CONTINUE
207  100 CONTINUE
208  j = j - 1
209  IF( d( j ).GT.dmnmx )
210  $ GO TO 100
211  110 CONTINUE
212  i = i + 1
213  IF( d( i ).LT.dmnmx )
214  $ GO TO 110
215  IF( i.LT.j ) THEN
216  tmp = d( i )
217  d( i ) = d( j )
218  d( j ) = tmp
219  GO TO 90
220  END IF
221  IF( j-start.GT.endd-j-1 ) THEN
222  stkpnt = stkpnt + 1
223  stack( 1, stkpnt ) = start
224  stack( 2, stkpnt ) = j
225  stkpnt = stkpnt + 1
226  stack( 1, stkpnt ) = j + 1
227  stack( 2, stkpnt ) = endd
228  ELSE
229  stkpnt = stkpnt + 1
230  stack( 1, stkpnt ) = j + 1
231  stack( 2, stkpnt ) = endd
232  stkpnt = stkpnt + 1
233  stack( 1, stkpnt ) = start
234  stack( 2, stkpnt ) = j
235  END IF
236  END IF
237  END IF
238  IF( stkpnt.GT.0 )
239  $ GO TO 10
240  RETURN
241 *
242 * End of DLASRT
243 *
244  END
subroutine dlasrt(ID, N, D, INFO)
Definition: dlasrt.f:2
subroutine xerbla(SRNAME, INFO)
Definition: xerbla.f:2