dlasrt.c
Go to the documentation of this file.
00001 /* dlasrt.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Subroutine */ int dlasrt_(char *id, integer *n, doublereal *d__, integer *
00017         info)
00018 {
00019     /* System generated locals */
00020     integer i__1, i__2;
00021 
00022     /* Local variables */
00023     integer i__, j;
00024     doublereal d1, d2, d3;
00025     integer dir;
00026     doublereal tmp;
00027     integer endd;
00028     extern logical lsame_(char *, char *);
00029     integer stack[64]   /* was [2][32] */;
00030     doublereal dmnmx;
00031     integer start;
00032     extern /* Subroutine */ int xerbla_(char *, integer *);
00033     integer stkpnt;
00034 
00035 
00036 /*  -- LAPACK routine (version 3.2) -- */
00037 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00038 /*     November 2006 */
00039 
00040 /*     .. Scalar Arguments .. */
00041 /*     .. */
00042 /*     .. Array Arguments .. */
00043 /*     .. */
00044 
00045 /*  Purpose */
00046 /*  ======= */
00047 
00048 /*  Sort the numbers in D in increasing order (if ID = 'I') or */
00049 /*  in decreasing order (if ID = 'D' ). */
00050 
00051 /*  Use Quick Sort, reverting to Insertion sort on arrays of */
00052 /*  size <= 20. Dimension of STACK limits N to about 2**32. */
00053 
00054 /*  Arguments */
00055 /*  ========= */
00056 
00057 /*  ID      (input) CHARACTER*1 */
00058 /*          = 'I': sort D in increasing order; */
00059 /*          = 'D': sort D in decreasing order. */
00060 
00061 /*  N       (input) INTEGER */
00062 /*          The length of the array D. */
00063 
00064 /*  D       (input/output) DOUBLE PRECISION array, dimension (N) */
00065 /*          On entry, the array to be sorted. */
00066 /*          On exit, D has been sorted into increasing order */
00067 /*          (D(1) <= ... <= D(N) ) or into decreasing order */
00068 /*          (D(1) >= ... >= D(N) ), depending on ID. */
00069 
00070 /*  INFO    (output) INTEGER */
00071 /*          = 0:  successful exit */
00072 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00073 
00074 /*  ===================================================================== */
00075 
00076 /*     .. Parameters .. */
00077 /*     .. */
00078 /*     .. Local Scalars .. */
00079 /*     .. */
00080 /*     .. Local Arrays .. */
00081 /*     .. */
00082 /*     .. External Functions .. */
00083 /*     .. */
00084 /*     .. External Subroutines .. */
00085 /*     .. */
00086 /*     .. Executable Statements .. */
00087 
00088 /*     Test the input paramters. */
00089 
00090     /* Parameter adjustments */
00091     --d__;
00092 
00093     /* Function Body */
00094     *info = 0;
00095     dir = -1;
00096     if (lsame_(id, "D")) {
00097         dir = 0;
00098     } else if (lsame_(id, "I")) {
00099         dir = 1;
00100     }
00101     if (dir == -1) {
00102         *info = -1;
00103     } else if (*n < 0) {
00104         *info = -2;
00105     }
00106     if (*info != 0) {
00107         i__1 = -(*info);
00108         xerbla_("DLASRT", &i__1);
00109         return 0;
00110     }
00111 
00112 /*     Quick return if possible */
00113 
00114     if (*n <= 1) {
00115         return 0;
00116     }
00117 
00118     stkpnt = 1;
00119     stack[0] = 1;
00120     stack[1] = *n;
00121 L10:
00122     start = stack[(stkpnt << 1) - 2];
00123     endd = stack[(stkpnt << 1) - 1];
00124     --stkpnt;
00125     if (endd - start <= 20 && endd - start > 0) {
00126 
00127 /*        Do Insertion sort on D( START:ENDD ) */
00128 
00129         if (dir == 0) {
00130 
00131 /*           Sort into decreasing order */
00132 
00133             i__1 = endd;
00134             for (i__ = start + 1; i__ <= i__1; ++i__) {
00135                 i__2 = start + 1;
00136                 for (j = i__; j >= i__2; --j) {
00137                     if (d__[j] > d__[j - 1]) {
00138                         dmnmx = d__[j];
00139                         d__[j] = d__[j - 1];
00140                         d__[j - 1] = dmnmx;
00141                     } else {
00142                         goto L30;
00143                     }
00144 /* L20: */
00145                 }
00146 L30:
00147                 ;
00148             }
00149 
00150         } else {
00151 
00152 /*           Sort into increasing order */
00153 
00154             i__1 = endd;
00155             for (i__ = start + 1; i__ <= i__1; ++i__) {
00156                 i__2 = start + 1;
00157                 for (j = i__; j >= i__2; --j) {
00158                     if (d__[j] < d__[j - 1]) {
00159                         dmnmx = d__[j];
00160                         d__[j] = d__[j - 1];
00161                         d__[j - 1] = dmnmx;
00162                     } else {
00163                         goto L50;
00164                     }
00165 /* L40: */
00166                 }
00167 L50:
00168                 ;
00169             }
00170 
00171         }
00172 
00173     } else if (endd - start > 20) {
00174 
00175 /*        Partition D( START:ENDD ) and stack parts, largest one first */
00176 
00177 /*        Choose partition entry as median of 3 */
00178 
00179         d1 = d__[start];
00180         d2 = d__[endd];
00181         i__ = (start + endd) / 2;
00182         d3 = d__[i__];
00183         if (d1 < d2) {
00184             if (d3 < d1) {
00185                 dmnmx = d1;
00186             } else if (d3 < d2) {
00187                 dmnmx = d3;
00188             } else {
00189                 dmnmx = d2;
00190             }
00191         } else {
00192             if (d3 < d2) {
00193                 dmnmx = d2;
00194             } else if (d3 < d1) {
00195                 dmnmx = d3;
00196             } else {
00197                 dmnmx = d1;
00198             }
00199         }
00200 
00201         if (dir == 0) {
00202 
00203 /*           Sort into decreasing order */
00204 
00205             i__ = start - 1;
00206             j = endd + 1;
00207 L60:
00208 L70:
00209             --j;
00210             if (d__[j] < dmnmx) {
00211                 goto L70;
00212             }
00213 L80:
00214             ++i__;
00215             if (d__[i__] > dmnmx) {
00216                 goto L80;
00217             }
00218             if (i__ < j) {
00219                 tmp = d__[i__];
00220                 d__[i__] = d__[j];
00221                 d__[j] = tmp;
00222                 goto L60;
00223             }
00224             if (j - start > endd - j - 1) {
00225                 ++stkpnt;
00226                 stack[(stkpnt << 1) - 2] = start;
00227                 stack[(stkpnt << 1) - 1] = j;
00228                 ++stkpnt;
00229                 stack[(stkpnt << 1) - 2] = j + 1;
00230                 stack[(stkpnt << 1) - 1] = endd;
00231             } else {
00232                 ++stkpnt;
00233                 stack[(stkpnt << 1) - 2] = j + 1;
00234                 stack[(stkpnt << 1) - 1] = endd;
00235                 ++stkpnt;
00236                 stack[(stkpnt << 1) - 2] = start;
00237                 stack[(stkpnt << 1) - 1] = j;
00238             }
00239         } else {
00240 
00241 /*           Sort into increasing order */
00242 
00243             i__ = start - 1;
00244             j = endd + 1;
00245 L90:
00246 L100:
00247             --j;
00248             if (d__[j] > dmnmx) {
00249                 goto L100;
00250             }
00251 L110:
00252             ++i__;
00253             if (d__[i__] < dmnmx) {
00254                 goto L110;
00255             }
00256             if (i__ < j) {
00257                 tmp = d__[i__];
00258                 d__[i__] = d__[j];
00259                 d__[j] = tmp;
00260                 goto L90;
00261             }
00262             if (j - start > endd - j - 1) {
00263                 ++stkpnt;
00264                 stack[(stkpnt << 1) - 2] = start;
00265                 stack[(stkpnt << 1) - 1] = j;
00266                 ++stkpnt;
00267                 stack[(stkpnt << 1) - 2] = j + 1;
00268                 stack[(stkpnt << 1) - 1] = endd;
00269             } else {
00270                 ++stkpnt;
00271                 stack[(stkpnt << 1) - 2] = j + 1;
00272                 stack[(stkpnt << 1) - 1] = endd;
00273                 ++stkpnt;
00274                 stack[(stkpnt << 1) - 2] = start;
00275                 stack[(stkpnt << 1) - 1] = j;
00276             }
00277         }
00278     }
00279     if (stkpnt > 0) {
00280         goto L10;
00281     }
00282     return 0;
00283 
00284 /*     End of DLASRT */
00285 
00286 } /* dlasrt_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:46