3 /* Subroutine */ int dlasrt_(char *id, integer *n, doublereal *d__, integer *
6 /* System generated locals */
11 doublereal d1, d2, d3;
15 extern logical lsame_(char *, char *);
16 integer stack[64] /* was [2][32] */;
19 extern /* Subroutine */ int xerbla_(char *, integer *);
23 /* -- LAPACK routine (version 3.1) -- */
24 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
27 /* .. Scalar Arguments .. */
29 /* .. Array Arguments .. */
35 /* Sort the numbers in D in increasing order (if ID = 'I') or */
36 /* in decreasing order (if ID = 'D' ). */
38 /* Use Quick Sort, reverting to Insertion sort on arrays of */
39 /* size <= 20. Dimension of STACK limits N to about 2**32. */
44 /* ID (input) CHARACTER*1 */
45 /* = 'I': sort D in increasing order; */
46 /* = 'D': sort D in decreasing order. */
48 /* N (input) INTEGER */
49 /* The length of the array D. */
51 /* D (input/output) DOUBLE PRECISION array, dimension (N) */
52 /* On entry, the array to be sorted. */
53 /* On exit, D has been sorted into increasing order */
54 /* (D(1) <= ... <= D(N) ) or into decreasing order */
55 /* (D(1) >= ... >= D(N) ), depending on ID. */
57 /* INFO (output) INTEGER */
58 /* = 0: successful exit */
59 /* < 0: if INFO = -i, the i-th argument had an illegal value */
61 /* ===================================================================== */
63 /* .. Parameters .. */
65 /* .. Local Scalars .. */
67 /* .. Local Arrays .. */
69 /* .. External Functions .. */
71 /* .. External Subroutines .. */
73 /* .. Executable Statements .. */
75 /* Test the input paramters. */
77 /* Parameter adjustments */
83 if (lsame_(id, "D")) {
85 } else if (lsame_(id, "I")) {
95 xerbla_("DLASRT", &i__1);
99 /* Quick return if possible */
109 start = stack[(stkpnt << 1) - 2];
110 endd = stack[(stkpnt << 1) - 1];
112 if (endd - start <= 20 && endd - start > 0) {
114 /* Do Insertion sort on D( START:ENDD ) */
118 /* Sort into decreasing order */
121 for (i__ = start + 1; i__ <= i__1; ++i__) {
123 for (j = i__; j >= i__2; --j) {
124 if (d__[j] > d__[j - 1]) {
139 /* Sort into increasing order */
142 for (i__ = start + 1; i__ <= i__1; ++i__) {
144 for (j = i__; j >= i__2; --j) {
145 if (d__[j] < d__[j - 1]) {
160 } else if (endd - start > 20) {
162 /* Partition D( START:ENDD ) and stack parts, largest one first */
164 /* Choose partition entry as median of 3 */
168 i__ = (start + endd) / 2;
173 } else if (d3 < d2) {
181 } else if (d3 < d1) {
190 /* Sort into decreasing order */
197 if (d__[j] < dmnmx) {
202 if (d__[i__] > dmnmx) {
211 if (j - start > endd - j - 1) {
213 stack[(stkpnt << 1) - 2] = start;
214 stack[(stkpnt << 1) - 1] = j;
216 stack[(stkpnt << 1) - 2] = j + 1;
217 stack[(stkpnt << 1) - 1] = endd;
220 stack[(stkpnt << 1) - 2] = j + 1;
221 stack[(stkpnt << 1) - 1] = endd;
223 stack[(stkpnt << 1) - 2] = start;
224 stack[(stkpnt << 1) - 1] = j;
228 /* Sort into increasing order */
235 if (d__[j] > dmnmx) {
240 if (d__[i__] < dmnmx) {
249 if (j - start > endd - j - 1) {
251 stack[(stkpnt << 1) - 2] = start;
252 stack[(stkpnt << 1) - 1] = j;
254 stack[(stkpnt << 1) - 2] = j + 1;
255 stack[(stkpnt << 1) - 1] = endd;
258 stack[(stkpnt << 1) - 2] = j + 1;
259 stack[(stkpnt << 1) - 1] = endd;
261 stack[(stkpnt << 1) - 2] = start;
262 stack[(stkpnt << 1) - 1] = j;