1 SUBROUTINE DLASRT( ID, N, D, INFO )
3 ! -- LAPACK routine (version 3.1) --
4 ! Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
7 ! .. Scalar Arguments ..
11 ! .. Array Arguments ..
12 DOUBLE PRECISION D( * )
18 ! Sort the numbers in D in increasing order (if ID = 'I') or
19 ! in decreasing order (if ID = 'D' ).
21 ! Use Quick Sort, reverting to Insertion sort on arrays of
22 ! size <= 20. Dimension of STACK limits N to about 2**32.
27 ! ID (input) CHARACTER*1
28 ! = 'I': sort D in increasing order;
29 ! = 'D': sort D in decreasing order.
32 ! The length of the array D.
34 ! D (input/output) DOUBLE PRECISION array, dimension (N)
35 ! On entry, the array to be sorted.
36 ! On exit, D has been sorted into increasing order
37 ! (D(1) <= ... <= D(N) ) or into decreasing order
38 ! (D(1) >= ... >= D(N) ), depending on ID.
40 ! INFO (output) INTEGER
41 ! = 0: successful exit
42 ! < 0: if INFO = -i, the i-th argument had an illegal value
44 ! =====================================================================
48 PARAMETER ( SELECT = 20 )
51 INTEGER DIR, ENDD, I, J, START, STKPNT
52 DOUBLE PRECISION D1, D2, D3, DMNMX, TMP
55 INTEGER STACK( 2, 32 )
57 ! .. External Functions ..
61 ! .. External Subroutines ..
64 ! .. Executable Statements ..
66 ! Test the input paramters.
70 IF( LSAME( ID, 'D' ) ) THEN
72 ELSE IF( LSAME( ID, 'I' ) ) THEN
77 ELSE IF( N.LT.0 ) THEN
81 CALL XERBLA( 'DLASRT', -INFO )
85 ! Quick return if possible
94 START = STACK( 1, STKPNT )
95 ENDD = STACK( 2, STKPNT )
97 IF( ENDD-START.LE.SELECT .AND. ENDD-START.GT.0 ) THEN
99 ! Do Insertion sort on D( START:ENDD )
103 ! Sort into decreasing order
105 DO 30 I = START + 1, ENDD
106 DO 20 J = I, START + 1, -1
107 IF( D( J ).GT.D( J-1 ) ) THEN
119 ! Sort into increasing order
121 DO 50 I = START + 1, ENDD
122 DO 40 J = I, START + 1, -1
123 IF( D( J ).LT.D( J-1 ) ) THEN
135 ELSE IF( ENDD-START.GT.SELECT ) THEN
137 ! Partition D( START:ENDD ) and stack parts, largest one first
139 ! Choose partition entry as median of 3
143 I = ( START+ENDD ) / 2
148 ELSE IF( D3.LT.D2 ) THEN
156 ELSE IF( D3.LT.D1 ) THEN
165 ! Sort into decreasing order
172 IF( D( J ).LT.DMNMX ) &
176 IF( D( I ).GT.DMNMX ) &
184 IF( J-START.GT.ENDD-J-1 ) THEN
186 STACK( 1, STKPNT ) = START
187 STACK( 2, STKPNT ) = J
189 STACK( 1, STKPNT ) = J + 1
190 STACK( 2, STKPNT ) = ENDD
193 STACK( 1, STKPNT ) = J + 1
194 STACK( 2, STKPNT ) = ENDD
196 STACK( 1, STKPNT ) = START
197 STACK( 2, STKPNT ) = J
201 ! Sort into increasing order
208 IF( D( J ).GT.DMNMX ) &
212 IF( D( I ).LT.DMNMX ) &
220 IF( J-START.GT.ENDD-J-1 ) THEN
222 STACK( 1, STKPNT ) = START
223 STACK( 2, STKPNT ) = J
225 STACK( 1, STKPNT ) = J + 1
226 STACK( 2, STKPNT ) = ENDD
229 STACK( 1, STKPNT ) = J + 1
230 STACK( 2, STKPNT ) = ENDD
232 STACK( 1, STKPNT ) = START
233 STACK( 2, STKPNT ) = J
243 END SUBROUTINE DLASRT