File: dlasrt.c

package info (click to toggle)
vxl 1.17.0.dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 153,280 kB
  • ctags: 105,123
  • sloc: cpp: 747,420; ansic: 209,130; fortran: 34,230; lisp: 14,915; sh: 6,187; python: 5,856; makefile: 340; perl: 294; xml: 160
file content (444 lines) | stat: -rw-r--r-- 13,123 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
/* lapack/double/dlasrt.f -- translated by f2c (version 20090411).
   You must link the resulting object file with libf2c:
        on Microsoft Windows system, link with libf2c.lib;
        on Linux or Unix systems, link with .../path/to/libf2c.a -lm
        or, if you install libf2c.a in a standard place, with -lf2c -lm
        -- in that order, at the end of the command line, as in
                cc *.o -lf2c -lm
        Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,

                http://www.netlib.org/f2c/libf2c.zip
*/

#ifdef __cplusplus
extern "C" {
#endif
#include "v3p_netlib.h"

/*<       SUBROUTINE DLASRT( ID, N, D, INFO ) >*/
/* Subroutine */ int dlasrt_(char *id, integer *n, doublereal *d__, integer *
        info, ftnlen id_len)
{
    /* System generated locals */
    integer i__1, i__2;

    /* Local variables */
    integer i__, j;
    doublereal d1, d2, d3;
    integer dir;
    doublereal tmp;
    integer endd;
    extern logical lsame_(const char *, const char *, ftnlen, ftnlen);
    integer stack[64]        /* was [2][32] */;
    doublereal dmnmx;
    integer start;
    extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
    integer stkpnt;


/*  -- LAPACK routine (version 3.2) -- */
/*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
/*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
/*     November 2006 */

/*     .. Scalar Arguments .. */
/*<       CHARACTER          ID >*/
/*<       INTEGER            INFO, N >*/
/*     .. */
/*     .. Array Arguments .. */
/*<       DOUBLE PRECISION   D( * ) >*/
/*     .. */

/*  Purpose */
/*  ======= */

/*  Sort the numbers in D in increasing order (if ID = 'I') or */
/*  in decreasing order (if ID = 'D' ). */

/*  Use Quick Sort, reverting to Insertion sort on arrays of */
/*  size <= 20. Dimension of STACK limits N to about 2**32. */

/*  Arguments */
/*  ========= */

/*  ID      (input) CHARACTER*1 */
/*          = 'I': sort D in increasing order; */
/*          = 'D': sort D in decreasing order. */

/*  N       (input) INTEGER */
/*          The length of the array D. */

/*  D       (input/output) DOUBLE PRECISION array, dimension (N) */
/*          On entry, the array to be sorted. */
/*          On exit, D has been sorted into increasing order */
/*          (D(1) <= ... <= D(N) ) or into decreasing order */
/*          (D(1) >= ... >= D(N) ), depending on ID. */

/*  INFO    (output) INTEGER */
/*          = 0:  successful exit */
/*          < 0:  if INFO = -i, the i-th argument had an illegal value */

/*  ===================================================================== */

/*     .. Parameters .. */
/*<       INTEGER            SELECT >*/
/*<       PARAMETER          ( SELECT = 20 ) >*/
/*     .. */
/*     .. Local Scalars .. */
/*<       INTEGER            DIR, ENDD, I, J, START, STKPNT >*/
/*<       DOUBLE PRECISION   D1, D2, D3, DMNMX, TMP >*/
/*     .. */
/*     .. Local Arrays .. */
/*<       INTEGER            STACK( 2, 32 ) >*/
/*     .. */
/*     .. External Functions .. */
/*<       LOGICAL            LSAME >*/
/*<       EXTERNAL           LSAME >*/
/*     .. */
/*     .. External Subroutines .. */
/*<       EXTERNAL           XERBLA >*/
/*     .. */
/*     .. Executable Statements .. */

/*     Test the input parameters. */

/*<       INFO = 0 >*/
    /* Parameter adjustments */
    --d__;

    /* Function Body */
    *info = 0;
/*<       DIR = -1 >*/
    dir = -1;
/*<       IF( LSAME( ID, 'D' ) ) THEN >*/
    if (lsame_(id, "D", (ftnlen)1, (ftnlen)1)) {
/*<          DIR = 0 >*/
        dir = 0;
/*<       ELSE IF( LSAME( ID, 'I' ) ) THEN >*/
    } else if (lsame_(id, "I", (ftnlen)1, (ftnlen)1)) {
/*<          DIR = 1 >*/
        dir = 1;
/*<       END IF >*/
    }
/*<       IF( DIR.EQ.-1 ) THEN >*/
    if (dir == -1) {
/*<          INFO = -1 >*/
        *info = -1;
/*<       ELSE IF( N.LT.0 ) THEN >*/
    } else if (*n < 0) {
/*<          INFO = -2 >*/
        *info = -2;
/*<       END IF >*/
    }
/*<       IF( INFO.NE.0 ) THEN >*/
    if (*info != 0) {
/*<          CALL XERBLA( 'DLASRT', -INFO ) >*/
        i__1 = -(*info);
        xerbla_("DLASRT", &i__1, (ftnlen)6);
/*<          RETURN >*/
        return 0;
/*<       END IF >*/
    }

/*     Quick return if possible */

/*<        >*/
    if (*n <= 1) {
        return 0;
    }

/*<       STKPNT = 1 >*/
    stkpnt = 1;
/*<       STACK( 1, 1 ) = 1 >*/
    stack[0] = 1;
/*<       STACK( 2, 1 ) = N >*/
    stack[1] = *n;
/*<    10 CONTINUE >*/
L10:
/*<       START = STACK( 1, STKPNT ) >*/
    start = stack[(stkpnt << 1) - 2];
/*<       ENDD = STACK( 2, STKPNT ) >*/
    endd = stack[(stkpnt << 1) - 1];
/*<       STKPNT = STKPNT - 1 >*/
    --stkpnt;
/*<       IF( ENDD-START.LE.SELECT .AND. ENDD-START.GT.0 ) THEN >*/
    if (endd - start <= 20 && endd - start > 0) {

/*        Do Insertion sort on D( START:ENDD ) */

/*<          IF( DIR.EQ.0 ) THEN >*/
        if (dir == 0) {

/*           Sort into decreasing order */

/*<             DO 30 I = START + 1, ENDD >*/
            i__1 = endd;
            for (i__ = start + 1; i__ <= i__1; ++i__) {
/*<                DO 20 J = I, START + 1, -1 >*/
                i__2 = start + 1;
                for (j = i__; j >= i__2; --j) {
/*<                   IF( D( J ).GT.D( J-1 ) ) THEN >*/
                    if (d__[j] > d__[j - 1]) {
/*<                      DMNMX = D( J ) >*/
                        dmnmx = d__[j];
/*<                      D( J ) = D( J-1 ) >*/
                        d__[j] = d__[j - 1];
/*<                      D( J-1 ) = DMNMX >*/
                        d__[j - 1] = dmnmx;
/*<                   ELSE >*/
                    } else {
/*<                      GO TO 30 >*/
                        goto L30;
/*<                   END IF >*/
                    }
/*<    20          CONTINUE >*/
/* L20: */
                }
/*<    30       CONTINUE >*/
L30:
                ;
            }

/*<          ELSE >*/
        } else {

/*           Sort into increasing order */

/*<             DO 50 I = START + 1, ENDD >*/
            i__1 = endd;
            for (i__ = start + 1; i__ <= i__1; ++i__) {
/*<                DO 40 J = I, START + 1, -1 >*/
                i__2 = start + 1;
                for (j = i__; j >= i__2; --j) {
/*<                   IF( D( J ).LT.D( J-1 ) ) THEN >*/
                    if (d__[j] < d__[j - 1]) {
/*<                      DMNMX = D( J ) >*/
                        dmnmx = d__[j];
/*<                      D( J ) = D( J-1 ) >*/
                        d__[j] = d__[j - 1];
/*<                      D( J-1 ) = DMNMX >*/
                        d__[j - 1] = dmnmx;
/*<                   ELSE >*/
                    } else {
/*<                      GO TO 50 >*/
                        goto L50;
/*<                   END IF >*/
                    }
/*<    40          CONTINUE >*/
/* L40: */
                }
/*<    50       CONTINUE >*/
L50:
                ;
            }

/*<          END IF >*/
        }

/*<       ELSE IF( ENDD-START.GT.SELECT ) THEN >*/
    } else if (endd - start > 20) {

/*        Partition D( START:ENDD ) and stack parts, largest one first */

/*        Choose partition entry as median of 3 */

/*<          D1 = D( START ) >*/
        d1 = d__[start];
/*<          D2 = D( ENDD ) >*/
        d2 = d__[endd];
/*<          I = ( START+ENDD ) / 2 >*/
        i__ = (start + endd) / 2;
/*<          D3 = D( I ) >*/
        d3 = d__[i__];
/*<          IF( D1.LT.D2 ) THEN >*/
        if (d1 < d2) {
/*<             IF( D3.LT.D1 ) THEN >*/
            if (d3 < d1) {
/*<                DMNMX = D1 >*/
                dmnmx = d1;
/*<             ELSE IF( D3.LT.D2 ) THEN >*/
            } else if (d3 < d2) {
/*<                DMNMX = D3 >*/
                dmnmx = d3;
/*<             ELSE >*/
            } else {
/*<                DMNMX = D2 >*/
                dmnmx = d2;
/*<             END IF >*/
            }
/*<          ELSE >*/
        } else {
/*<             IF( D3.LT.D2 ) THEN >*/
            if (d3 < d2) {
/*<                DMNMX = D2 >*/
                dmnmx = d2;
/*<             ELSE IF( D3.LT.D1 ) THEN >*/
            } else if (d3 < d1) {
/*<                DMNMX = D3 >*/
                dmnmx = d3;
/*<             ELSE >*/
            } else {
/*<                DMNMX = D1 >*/
                dmnmx = d1;
/*<             END IF >*/
            }
/*<          END IF >*/
        }

/*<          IF( DIR.EQ.0 ) THEN >*/
        if (dir == 0) {

/*           Sort into decreasing order */

/*<             I = START - 1 >*/
            i__ = start - 1;
/*<             J = ENDD + 1 >*/
            j = endd + 1;
/*<    60       CONTINUE >*/
L60:
/*<    70       CONTINUE >*/
L70:
/*<             J = J - 1 >*/
            --j;
/*<        >*/
            if (d__[j] < dmnmx) {
                goto L70;
            }
/*<    80       CONTINUE >*/
L80:
/*<             I = I + 1 >*/
            ++i__;
/*<        >*/
            if (d__[i__] > dmnmx) {
                goto L80;
            }
/*<             IF( I.LT.J ) THEN >*/
            if (i__ < j) {
/*<                TMP = D( I ) >*/
                tmp = d__[i__];
/*<                D( I ) = D( J ) >*/
                d__[i__] = d__[j];
/*<                D( J ) = TMP >*/
                d__[j] = tmp;
/*<                GO TO 60 >*/
                goto L60;
/*<             END IF >*/
            }
/*<             IF( J-START.GT.ENDD-J-1 ) THEN >*/
            if (j - start > endd - j - 1) {
/*<                STKPNT = STKPNT + 1 >*/
                ++stkpnt;
/*<                STACK( 1, STKPNT ) = START >*/
                stack[(stkpnt << 1) - 2] = start;
/*<                STACK( 2, STKPNT ) = J >*/
                stack[(stkpnt << 1) - 1] = j;
/*<                STKPNT = STKPNT + 1 >*/
                ++stkpnt;
/*<                STACK( 1, STKPNT ) = J + 1 >*/
                stack[(stkpnt << 1) - 2] = j + 1;
/*<                STACK( 2, STKPNT ) = ENDD >*/
                stack[(stkpnt << 1) - 1] = endd;
/*<             ELSE >*/
            } else {
/*<                STKPNT = STKPNT + 1 >*/
                ++stkpnt;
/*<                STACK( 1, STKPNT ) = J + 1 >*/
                stack[(stkpnt << 1) - 2] = j + 1;
/*<                STACK( 2, STKPNT ) = ENDD >*/
                stack[(stkpnt << 1) - 1] = endd;
/*<                STKPNT = STKPNT + 1 >*/
                ++stkpnt;
/*<                STACK( 1, STKPNT ) = START >*/
                stack[(stkpnt << 1) - 2] = start;
/*<                STACK( 2, STKPNT ) = J >*/
                stack[(stkpnt << 1) - 1] = j;
/*<             END IF >*/
            }
/*<          ELSE >*/
        } else {

/*           Sort into increasing order */

/*<             I = START - 1 >*/
            i__ = start - 1;
/*<             J = ENDD + 1 >*/
            j = endd + 1;
/*<    90       CONTINUE >*/
L90:
/*<   100       CONTINUE >*/
L100:
/*<             J = J - 1 >*/
            --j;
/*<        >*/
            if (d__[j] > dmnmx) {
                goto L100;
            }
/*<   110       CONTINUE >*/
L110:
/*<             I = I + 1 >*/
            ++i__;
/*<        >*/
            if (d__[i__] < dmnmx) {
                goto L110;
            }
/*<             IF( I.LT.J ) THEN >*/
            if (i__ < j) {
/*<                TMP = D( I ) >*/
                tmp = d__[i__];
/*<                D( I ) = D( J ) >*/
                d__[i__] = d__[j];
/*<                D( J ) = TMP >*/
                d__[j] = tmp;
/*<                GO TO 90 >*/
                goto L90;
/*<             END IF >*/
            }
/*<             IF( J-START.GT.ENDD-J-1 ) THEN >*/
            if (j - start > endd - j - 1) {
/*<                STKPNT = STKPNT + 1 >*/
                ++stkpnt;
/*<                STACK( 1, STKPNT ) = START >*/
                stack[(stkpnt << 1) - 2] = start;
/*<                STACK( 2, STKPNT ) = J >*/
                stack[(stkpnt << 1) - 1] = j;
/*<                STKPNT = STKPNT + 1 >*/
                ++stkpnt;
/*<                STACK( 1, STKPNT ) = J + 1 >*/
                stack[(stkpnt << 1) - 2] = j + 1;
/*<                STACK( 2, STKPNT ) = ENDD >*/
                stack[(stkpnt << 1) - 1] = endd;
/*<             ELSE >*/
            } else {
/*<                STKPNT = STKPNT + 1 >*/
                ++stkpnt;
/*<                STACK( 1, STKPNT ) = J + 1 >*/
                stack[(stkpnt << 1) - 2] = j + 1;
/*<                STACK( 2, STKPNT ) = ENDD >*/
                stack[(stkpnt << 1) - 1] = endd;
/*<                STKPNT = STKPNT + 1 >*/
                ++stkpnt;
/*<                STACK( 1, STKPNT ) = START >*/
                stack[(stkpnt << 1) - 2] = start;
/*<                STACK( 2, STKPNT ) = J >*/
                stack[(stkpnt << 1) - 1] = j;
/*<             END IF >*/
            }
/*<          END IF >*/
        }
/*<       END IF >*/
    }
/*<        >*/
    if (stkpnt > 0) {
        goto L10;
    }
/*<       RETURN >*/
    return 0;

/*     End of DLASRT */

/*<       END >*/
} /* dlasrt_ */

#ifdef __cplusplus
        }
#endif