예제 #1
0
/* Subroutine */ int sstein_(integer *n, real *d, real *e, integer *m, real *
	w, integer *iblock, integer *isplit, real *z, integer *ldz, real *
	work, integer *iwork, integer *ifail, integer *info)
{
/*  -- LAPACK routine (version 2.0) --   
       Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,   
       Courant Institute, Argonne National Lab, and Rice University   
       September 30, 1994   


    Purpose   
    =======   

    SSTEIN computes the eigenvectors of a real symmetric tridiagonal   
    matrix T corresponding to specified eigenvalues, using inverse   
    iteration.   

    The maximum number of iterations allowed for each eigenvector is   
    specified by an internal parameter MAXITS (currently set to 5).   

    Arguments   
    =========   

    N       (input) INTEGER   
            The order of the matrix.  N >= 0.   

    D       (input) REAL array, dimension (N)   
            The n diagonal elements of the tridiagonal matrix T.   

    E       (input) REAL array, dimension (N)   
            The (n-1) subdiagonal elements of the tridiagonal matrix   
            T, in elements 1 to N-1.  E(N) need not be set.   

    M       (input) INTEGER   
            The number of eigenvectors to be found.  0 <= M <= N.   

    W       (input) REAL array, dimension (N)   
            The first M elements of W contain the eigenvalues for   
            which eigenvectors are to be computed.  The eigenvalues   
            should be grouped by split-off block and ordered from   
            smallest to largest within the block.  ( The output array   
            W from SSTEBZ with ORDER = 'B' is expected here. )   

    IBLOCK  (input) INTEGER array, dimension (N)   
            The submatrix indices associated with the corresponding   
            eigenvalues in W; IBLOCK(i)=1 if eigenvalue W(i) belongs to   
            the first submatrix from the top, =2 if W(i) belongs to   
            the second submatrix, etc.  ( The output array IBLOCK   
            from SSTEBZ is expected here. )   

    ISPLIT  (input) INTEGER array, dimension (N)   
            The splitting points, at which T breaks up into submatrices. 
  
            The first submatrix consists of rows/columns 1 to   
            ISPLIT( 1 ), the second of rows/columns ISPLIT( 1 )+1   
            through ISPLIT( 2 ), etc.   
            ( The output array ISPLIT from SSTEBZ is expected here. )   

    Z       (output) REAL array, dimension (LDZ, M)   
            The computed eigenvectors.  The eigenvector associated   
            with the eigenvalue W(i) is stored in the i-th column of   
            Z.  Any vector which fails to converge is set to its current 
  
            iterate after MAXITS iterations.   

    LDZ     (input) INTEGER   
            The leading dimension of the array Z.  LDZ >= max(1,N).   

    WORK    (workspace) REAL array, dimension (5*N)   

    IWORK   (workspace) INTEGER array, dimension (N)   

    IFAIL   (output) INTEGER array, dimension (M)   
            On normal exit, all elements of IFAIL are zero.   
            If one or more eigenvectors fail to converge after   
            MAXITS iterations, then their indices are stored in   
            array IFAIL.   

    INFO    (output) INTEGER   
            = 0: successful exit.   
            < 0: if INFO = -i, the i-th argument had an illegal value   
            > 0: if INFO = i, then i eigenvectors failed to converge   
                 in MAXITS iterations.  Their indices are stored in   
                 array IFAIL.   

    Internal Parameters   
    ===================   

    MAXITS  INTEGER, default = 5   
            The maximum number of iterations performed.   

    EXTRA   INTEGER, default = 2   
            The number of iterations performed after norm growth   
            criterion is satisfied, should be at least 1.   

    ===================================================================== 
  


       Test the input parameters.   

    
   Parameter adjustments   
       Function Body */
    /* Table of constant values */
    static integer c__2 = 2;
    static integer c__1 = 1;
    static integer c_n1 = -1;
    
    /* System generated locals */
    integer z_dim1, z_offset, i__1, i__2, i__3;
    real r__1, r__2, r__3, r__4, r__5;
    /* Builtin functions */
    double sqrt(doublereal);
    /* Local variables */
    static integer jblk, nblk, jmax;
    extern doublereal sdot_(integer *, real *, integer *, real *, integer *), 
	    snrm2_(integer *, real *, integer *);
    static integer i, j, iseed[4], gpind, iinfo;
    extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
    static integer b1;
    extern doublereal sasum_(integer *, real *, integer *);
    static integer j1;
    extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 
	    integer *);
    static real ortol;
    extern /* Subroutine */ int saxpy_(integer *, real *, real *, integer *, 
	    real *, integer *);
    static integer indrv1, indrv2, indrv3, indrv4, indrv5, bn;
    static real xj;
    extern doublereal slamch_(char *);
    extern /* Subroutine */ int xerbla_(char *, integer *), slagtf_(
	    integer *, real *, real *, real *, real *, real *, real *, 
	    integer *, integer *);
    static integer nrmchk;
    extern integer isamax_(integer *, real *, integer *);
    extern /* Subroutine */ int slagts_(integer *, integer *, real *, real *, 
	    real *, real *, integer *, real *, real *, integer *);
    static integer blksiz;
    static real onenrm, pertol;
    extern /* Subroutine */ int slarnv_(integer *, integer *, integer *, real 
	    *);
    static real stpcrt, scl, eps, ctr, sep, nrm, tol;
    static integer its;
    static real xjm, eps1;



#define ISEED(I) iseed[(I)]
#define D(I) d[(I)-1]
#define E(I) e[(I)-1]
#define W(I) w[(I)-1]
#define IBLOCK(I) iblock[(I)-1]
#define ISPLIT(I) isplit[(I)-1]
#define WORK(I) work[(I)-1]
#define IWORK(I) iwork[(I)-1]
#define IFAIL(I) ifail[(I)-1]

#define Z(I,J) z[(I)-1 + ((J)-1)* ( *ldz)]

    *info = 0;
    i__1 = *m;
    for (i = 1; i <= *m; ++i) {
	IFAIL(i) = 0;
/* L10: */
    }

    if (*n < 0) {
	*info = -1;
    } else if (*m < 0 || *m > *n) {
	*info = -4;
    } else if (*ldz < max(1,*n)) {
	*info = -9;
    } else {
	i__1 = *m;
	for (j = 2; j <= *m; ++j) {
	    if (IBLOCK(j) < IBLOCK(j - 1)) {
		*info = -6;
		goto L30;
	    }
	    if (IBLOCK(j) == IBLOCK(j - 1) && W(j) < W(j - 1)) {
		*info = -5;
		goto L30;
	    }
/* L20: */
	}
L30:
	;
    }

    if (*info != 0) {
	i__1 = -(*info);
	xerbla_("SSTEIN", &i__1);
	return 0;
    }

/*     Quick return if possible */

    if (*n == 0 || *m == 0) {
	return 0;
    } else if (*n == 1) {
	Z(1,1) = 1.f;
	return 0;
    }

/*     Get machine constants. */

    eps = slamch_("Precision");

/*     Initialize seed for random number generator SLARNV. */

    for (i = 1; i <= 4; ++i) {
	ISEED(i - 1) = 1;
/* L40: */
    }

/*     Initialize pointers. */

    indrv1 = 0;
    indrv2 = indrv1 + *n;
    indrv3 = indrv2 + *n;
    indrv4 = indrv3 + *n;
    indrv5 = indrv4 + *n;

/*     Compute eigenvectors of matrix blocks. */

    j1 = 1;
    i__1 = IBLOCK(*m);
    for (nblk = 1; nblk <= IBLOCK(*m); ++nblk) {

/*        Find starting and ending indices of block nblk. */

	if (nblk == 1) {
	    b1 = 1;
	} else {
	    b1 = ISPLIT(nblk - 1) + 1;
	}
	bn = ISPLIT(nblk);
	blksiz = bn - b1 + 1;
	if (blksiz == 1) {
	    goto L60;
	}
	gpind = b1;

/*        Compute reorthogonalization criterion and stopping criterion
. */

	onenrm = (r__1 = D(b1), dabs(r__1)) + (r__2 = E(b1), dabs(r__2));
/* Computing MAX */
	r__3 = onenrm, r__4 = (r__1 = D(bn), dabs(r__1)) + (r__2 = E(bn - 1), 
		dabs(r__2));
	onenrm = dmax(r__3,r__4);
	i__2 = bn - 1;
	for (i = b1 + 1; i <= bn-1; ++i) {
/* Computing MAX */
	    r__4 = onenrm, r__5 = (r__1 = D(i), dabs(r__1)) + (r__2 = E(i - 1)
		    , dabs(r__2)) + (r__3 = E(i), dabs(r__3));
	    onenrm = dmax(r__4,r__5);
/* L50: */
	}
	ortol = onenrm * .001f;

	stpcrt = sqrt(.1f / blksiz);

/*        Loop through eigenvalues of block nblk. */

L60:
	jblk = 0;
	i__2 = *m;
	for (j = j1; j <= *m; ++j) {
	    if (IBLOCK(j) != nblk) {
		j1 = j;
		goto L160;
	    }
	    ++jblk;
	    xj = W(j);

/*           Skip all the work if the block size is one. */

	    if (blksiz == 1) {
		WORK(indrv1 + 1) = 1.f;
		goto L120;
	    }

/*           If eigenvalues j and j-1 are too close, add a relativ
ely   
             small perturbation. */

	    if (jblk > 1) {
		eps1 = (r__1 = eps * xj, dabs(r__1));
		pertol = eps1 * 10.f;
		sep = xj - xjm;
		if (sep < pertol) {
		    xj = xjm + pertol;
		}
	    }

	    its = 0;
	    nrmchk = 0;

/*           Get random starting vector. */

	    slarnv_(&c__2, iseed, &blksiz, &WORK(indrv1 + 1));

/*           Copy the matrix T so it won't be destroyed in factori
zation. */

	    scopy_(&blksiz, &D(b1), &c__1, &WORK(indrv4 + 1), &c__1);
	    i__3 = blksiz - 1;
	    scopy_(&i__3, &E(b1), &c__1, &WORK(indrv2 + 2), &c__1);
	    i__3 = blksiz - 1;
	    scopy_(&i__3, &E(b1), &c__1, &WORK(indrv3 + 1), &c__1);

/*           Compute LU factors with partial pivoting  ( PT = LU )
 */

	    tol = 0.f;
	    slagtf_(&blksiz, &WORK(indrv4 + 1), &xj, &WORK(indrv2 + 2), &WORK(
		    indrv3 + 1), &tol, &WORK(indrv5 + 1), &IWORK(1), &iinfo);

/*           Update iteration count. */

L70:
	    ++its;
	    if (its > 5) {
		goto L100;
	    }

/*           Normalize and scale the righthand side vector Pb.   

   Computing MAX */
	    r__2 = eps, r__3 = (r__1 = WORK(indrv4 + blksiz), dabs(r__1));
	    scl = blksiz * onenrm * dmax(r__2,r__3) / sasum_(&blksiz, &WORK(
		    indrv1 + 1), &c__1);
	    sscal_(&blksiz, &scl, &WORK(indrv1 + 1), &c__1);

/*           Solve the system LU = Pb. */

	    slagts_(&c_n1, &blksiz, &WORK(indrv4 + 1), &WORK(indrv2 + 2), &
		    WORK(indrv3 + 1), &WORK(indrv5 + 1), &IWORK(1), &WORK(
		    indrv1 + 1), &tol, &iinfo);

/*           Reorthogonalize by modified Gram-Schmidt if eigenvalu
es are   
             close enough. */

	    if (jblk == 1) {
		goto L90;
	    }
	    if ((r__1 = xj - xjm, dabs(r__1)) > ortol) {
		gpind = j;
	    }
	    if (gpind != j) {
		i__3 = j - 1;
		for (i = gpind; i <= j-1; ++i) {
		    ctr = -(doublereal)sdot_(&blksiz, &WORK(indrv1 + 1), &
			    c__1, &Z(b1,i), &c__1);
		    saxpy_(&blksiz, &ctr, &Z(b1,i), &c__1, &WORK(
			    indrv1 + 1), &c__1);
/* L80: */
		}
	    }

/*           Check the infinity norm of the iterate. */

L90:
	    jmax = isamax_(&blksiz, &WORK(indrv1 + 1), &c__1);
	    nrm = (r__1 = WORK(indrv1 + jmax), dabs(r__1));

/*           Continue for additional iterations after norm reaches
   
             stopping criterion. */

	    if (nrm < stpcrt) {
		goto L70;
	    }
	    ++nrmchk;
	    if (nrmchk < 3) {
		goto L70;
	    }

	    goto L110;

/*           If stopping criterion was not satisfied, update info 
and   
             store eigenvector number in array ifail. */

L100:
	    ++(*info);
	    IFAIL(*info) = j;

/*           Accept iterate as jth eigenvector. */

L110:
	    scl = 1.f / snrm2_(&blksiz, &WORK(indrv1 + 1), &c__1);
	    jmax = isamax_(&blksiz, &WORK(indrv1 + 1), &c__1);
	    if (WORK(indrv1 + jmax) < 0.f) {
		scl = -(doublereal)scl;
	    }
	    sscal_(&blksiz, &scl, &WORK(indrv1 + 1), &c__1);
L120:
	    i__3 = *n;
	    for (i = 1; i <= *n; ++i) {
		Z(i,j) = 0.f;
/* L130: */
	    }
	    i__3 = blksiz;
	    for (i = 1; i <= blksiz; ++i) {
		Z(b1+i-1,j) = WORK(indrv1 + i);
/* L140: */
	    }

/*           Save the shift to check eigenvalue spacing at next   
             iteration. */

	    xjm = xj;

/* L150: */
	}
L160:
	;
    }

    return 0;

/*     End of SSTEIN */

} /* sstein_ */
예제 #2
0
파일: dlarnv.c 프로젝트: AmEv7Fam/opentoonz
/* Subroutine */ int dlarnv_(integer *idist, integer *iseed, integer *n, 
	doublereal *x)
{
/*  -- LAPACK auxiliary routine (version 2.0) --   
       Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,   
       Courant Institute, Argonne National Lab, and Rice University   
       September 30, 1994   


    Purpose   
    =======   

    DLARNV returns a vector of n random real numbers from a uniform or   
    normal distribution.   

    Arguments   
    =========   

    IDIST   (input) INTEGER   
            Specifies the distribution of the random numbers:   
            = 1:  uniform (0,1)   
            = 2:  uniform (-1,1)   
            = 3:  normal (0,1)   

    ISEED   (input/output) INTEGER array, dimension (4)   
            On entry, the seed of the random number generator; the array 
  
            elements must be between 0 and 4095, and ISEED(4) must be   
            odd.   
            On exit, the seed is updated.   

    N       (input) INTEGER   
            The number of random numbers to be generated.   

    X       (output) DOUBLE PRECISION array, dimension (N)   
            The generated random numbers.   

    Further Details   
    ===============   

    This routine calls the auxiliary routine DLARUV to generate random   
    real numbers from a uniform (0,1) distribution, in batches of up to   
    128 using vectorisable code. The Box-Muller method is used to   
    transform numbers from a uniform to a normal distribution.   

    ===================================================================== 
  


    
   Parameter adjustments   
       Function Body */
    /* System generated locals */
    integer i__1, i__2, i__3;
    /* Builtin functions */
    double log(doublereal), sqrt(doublereal), cos(doublereal);
    /* Local variables */
    static integer i;
    static doublereal u[128];
    static integer il, iv;
    extern /* Subroutine */ int dlaruv_(integer *, integer *, doublereal *);
    static integer il2;


#define U(I) u[(I)]
#define X(I) x[(I)-1]
#define ISEED(I) iseed[(I)-1]


    i__1 = *n;
    for (iv = 1; iv <= *n; iv += 64) {
/* Computing MIN */
	i__2 = 64, i__3 = *n - iv + 1;
	il = min(i__2,i__3);
	if (*idist == 3) {
	    il2 = il << 1;
	} else {
	    il2 = il;
	}

/*        Call DLARUV to generate IL2 numbers from a uniform (0,1)   
          distribution (IL2 <= LV) */

	dlaruv_(&ISEED(1), &il2, u);

	if (*idist == 1) {

/*           Copy generated numbers */

	    i__2 = il;
	    for (i = 1; i <= il; ++i) {
		X(iv + i - 1) = U(i - 1);
/* L10: */
	    }
	} else if (*idist == 2) {

/*           Convert generated numbers to uniform (-1,1) distribut
ion */

	    i__2 = il;
	    for (i = 1; i <= il; ++i) {
		X(iv + i - 1) = U(i - 1) * 2. - 1.;
/* L20: */
	    }
	} else if (*idist == 3) {

/*           Convert generated numbers to normal (0,1) distributio
n */

	    i__2 = il;
	    for (i = 1; i <= il; ++i) {
		X(iv + i - 1) = sqrt(log(U((i << 1) - 2)) * -2.) * cos(U((i <<
			 1) - 1) * 6.2831853071795864769252867663);
/* L30: */
	    }
	}
/* L40: */
    }
    return 0;

/*     End of DLARNV */

} /* dlarnv_ */
예제 #3
0
/* Subroutine */ int dlaruv_(integer *iseed, integer *n, doublereal *x)
{
/*  -- LAPACK auxiliary routine (version 2.0) --
       Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
       Courant Institute, Argonne National Lab, and Rice University
       October 31, 1992


    Purpose
    =======

    DLARUV returns a vector of n random real numbers from a uniform (0,1)

    distribution (n <= 128).

    This is an auxiliary routine called by DLARNV and ZLARNV.

    Arguments
    =========

    ISEED   (input/output) INTEGER array, dimension (4)
            On entry, the seed of the random number generator; the array

            elements must be between 0 and 4095, and ISEED(4) must be
            odd.
            On exit, the seed is updated.

    N       (input) INTEGER
            The number of random numbers to be generated. N <= 128.

    X       (output) DOUBLE PRECISION array, dimension (N)
            The generated random numbers.

    Further Details
    ===============

    This routine uses a multiplicative congruential method with modulus
    2**48 and multiplier 33952834046453 (see G.S.Fishman,
    'Multiplicative congruential random number generators with modulus
    2**b: an exhaustive analysis for b = 32 and a partial analysis for
    b = 48', Math. Comp. 189, pp 331-344, 1990).

    48-bit integers are stored in 4 integer array elements with 12 bits
    per element. Hence the routine is portable across machines with
    integers of 32 bits or more.

    =====================================================================



   Parameter adjustments
       Function Body */
    /* Initialized data */
    static integer mm[512]      /* was [128][4] */ = { 494,2637,255,2008,1253,
            3344,4084,1739,3143,3468,688,1657,1238,3166,1292,3422,1270,2016,
            154,2862,697,1706,491,931,1444,444,3577,3944,2184,1661,3482,657,
            3023,3618,1267,1828,164,3798,3087,2400,2870,3876,1905,1593,1797,
            1234,3460,328,2861,1950,617,2070,3331,769,1558,2412,2800,189,287,
            2045,1227,2838,209,2770,3654,3993,192,2253,3491,2889,2857,2094,
            1818,688,1407,634,3231,815,3524,1914,516,164,303,2144,3480,119,
            3357,837,2826,2332,2089,3780,1700,3712,150,2000,3375,1621,3090,
            3765,1149,3146,33,3082,2741,359,3316,1749,185,2784,2202,2199,1364,
            1244,2020,3160,2785,2772,1217,1822,1245,2252,3904,2774,997,2573,
            1148,545,322,789,1440,752,2859,123,1848,643,2405,2638,2344,46,
            3814,913,3649,339,3808,822,2832,3078,3633,2970,637,2249,2081,4019,
            1478,242,481,2075,4058,622,3376,812,234,641,4005,1122,3135,2640,
            2302,40,1832,2247,2034,2637,1287,1691,496,1597,2394,2584,1843,336,
            1472,2407,433,2096,1761,2810,566,442,41,1238,1086,603,840,3168,
            1499,1084,3438,2408,1589,2391,288,26,512,1456,171,1677,2657,2270,
            2587,2961,1970,1817,676,1410,3723,2803,3185,184,663,499,3784,1631,
            1925,3912,1398,1349,1441,2224,2411,1907,3192,2786,382,37,759,2948,
            1862,3802,2423,2051,2295,1332,1832,2405,3638,3661,327,3660,716,
            1842,3987,1368,1848,2366,2508,3754,1766,3572,2893,307,1297,3966,
            758,2598,3406,2922,1038,2934,2091,2451,1580,1958,2055,1507,1078,
            3273,17,854,2916,3971,2889,3831,2621,1541,893,736,3992,787,2125,
            2364,2460,257,1574,3912,1216,3248,3401,2124,2762,149,2245,166,466,
            4018,1399,190,2879,153,2320,18,712,2159,2318,2091,3443,1510,449,
            1956,2201,3137,3399,1321,2271,3667,2703,629,2365,2431,1113,3922,
            2554,184,2099,3228,4012,1921,3452,3901,572,3309,3171,817,3039,
            1696,1256,3715,2077,3019,1497,1101,717,51,981,1978,1813,3881,76,
            3846,3694,1682,124,1660,3997,479,1141,886,3514,1301,3604,1888,
            1836,1990,2058,692,1194,20,3285,2046,2107,3508,3525,3801,2549,
            1145,2253,305,3301,1065,3133,2913,3285,1241,1197,3729,2501,1673,
            541,2753,949,2361,1165,4081,2725,3305,3069,3617,3733,409,2157,
            1361,3973,1865,2525,1409,3445,3577,77,3761,2149,1449,3005,225,85,
            3673,3117,3089,1349,2057,413,65,1845,697,3085,3441,1573,3689,2941,
            929,533,2841,4077,721,2821,2249,2397,2817,245,1913,1997,3121,997,
            1833,2877,1633,981,2009,941,2449,197,2441,285,1473,2741,3129,909,
            2801,421,4073,2813,2337,1429,1177,1901,81,1669,2633,2269,129,1141,
            249,3917,2481,3941,2217,2749,3041,1877,345,2861,1809,3141,2825,
            157,2881,3637,1465,2829,2161,3365,361,2685,3745,2325,3609,3821,
            3537,517,3017,2141,1537 };
    /* System generated locals */
    integer i__1;
    /* Local variables */
    static integer i, i1, i2, i3, i4, it1, it2, it3, it4;


#define MM(I) mm[(I)]
#define WAS(I) was[(I)]
#define ISEED(I) iseed[(I)-1]
#define X(I) x[(I)-1]



    i1 = ISEED(1);
    i2 = ISEED(2);
    i3 = ISEED(3);
    i4 = ISEED(4);

    i__1 = min(*n,128);
    for (i = 1; i <= min(*n,128); ++i) {

/*        Multiply the seed by i-th power of the multiplier modulo 2**
48 */

        it4 = i4 * MM(i + 383);
        it3 = it4 / 4096;
        it4 -= it3 << 12;
        it3 = it3 + i3 * MM(i + 383) + i4 * MM(i + 255);
        it2 = it3 / 4096;
        it3 -= it2 << 12;
        it2 = it2 + i2 * MM(i + 383) + i3 * MM(i + 255) + i4 * MM(i + 127);
        it1 = it2 / 4096;
        it2 -= it1 << 12;
        it1 = it1 + i1 * MM(i + 383) + i2 * MM(i + 255) + i3 * MM(i + 127) +
                i4 * MM(i - 1);
        it1 %= 4096;

/*        Convert 48-bit integer to a real number in the interval (0,1
) */

        X(i) = ((doublereal) it1 + ((doublereal) it2 + ((doublereal) it3 + (
                doublereal) it4 * 2.44140625e-4) * 2.44140625e-4) *
                2.44140625e-4) * 2.44140625e-4;
/* L10: */
    }

/*     Return final value of seed */

    ISEED(1) = it1;
    ISEED(2) = it2;
    ISEED(3) = it3;
    ISEED(4) = it4;
    return 0;

/*     End of DLARUV */

} /* dlaruv_ */
예제 #4
0
파일: clarnv.c 프로젝트: petsc/superlu
/* Subroutine */ int clarnv_slu(integer *idist, integer *iseed, integer *n, 
	complex *x)
{
/*  -- LAPACK auxiliary routine (version 2.0) --   
       Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,   
       Courant Institute, Argonne National Lab, and Rice University   
       September 30, 1994   


    Purpose   
    =======   

    CLARNV returns a vector of n random complex numbers from a uniform or 
  
    normal distribution.   

    Arguments   
    =========   

    IDIST   (input) INTEGER   
            Specifies the distribution of the random numbers:   
            = 1:  real and imaginary parts each uniform (0,1)   
            = 2:  real and imaginary parts each uniform (-1,1)   
            = 3:  real and imaginary parts each normal (0,1)   
            = 4:  uniformly distributed on the disc abs(z) < 1   
            = 5:  uniformly distributed on the circle abs(z) = 1   

    ISEED   (input/output) INTEGER array, dimension (4)   
            On entry, the seed of the random number generator; the array 
  
            elements must be between 0 and 4095, and ISEED(4) must be   
            odd.   
            On exit, the seed is updated.   

    N       (input) INTEGER   
            The number of random numbers to be generated.   

    X       (output) COMPLEX array, dimension (N)   
            The generated random numbers.   

    Further Details   
    ===============   

    This routine calls the auxiliary routine SLARUV to generate random   
    real numbers from a uniform (0,1) distribution, in batches of up to   
    128 using vectorisable code. The Box-Muller method is used to   
    transform numbers from a uniform to a normal distribution.   

    ===================================================================== 
  


    
   Parameter adjustments   
       Function Body */
    /* System generated locals */
    integer i__1, i__2, i__3, i__4, i__5;
    doublereal d__1, d__2;
    complex q__1, q__2, q__3;
    /* Builtin functions */
    double log(doublereal), sqrt(doublereal);
    void c_exp(complex *, complex *);
    /* Local variables */
    static integer i;
    static real u[128];
    static integer il, iv;
    extern /* Subroutine */ int slaruv_slu(integer *, integer *, real *);


#define X(I) x[(I)-1]
#define ISEED(I) iseed[(I)-1]


    i__1 = *n;
    for (iv = 1; iv <= *n; iv += 64) {
/* Computing MIN */
	i__2 = 64, i__3 = *n - iv + 1;
	il = min(i__2,i__3);

/*        Call SLARUV to generate 2*IL real numbers from a uniform (0,
1)   
          distribution (2*IL <= LV) */

	i__2 = il << 1;
	slaruv_slu(&ISEED(1), &i__2, u);

	if (*idist == 1) {

/*           Copy generated numbers */

	    i__2 = il;
	    for (i = 1; i <= il; ++i) {
		i__3 = iv + i - 1;
		i__4 = (i << 1) - 2;
		i__5 = (i << 1) - 1;
		q__1.r = u[(i<<1)-2], q__1.i = u[(i<<1)-1];
		X(iv+i-1).r = q__1.r, X(iv+i-1).i = q__1.i;
/* L10: */
	    }
	} else if (*idist == 2) {

/*           Convert generated numbers to uniform (-1,1) distribut
ion */

	    i__2 = il;
	    for (i = 1; i <= il; ++i) {
		i__3 = iv + i - 1;
		d__1 = u[(i << 1) - 2] * 2.f - 1.f;
		d__2 = u[(i << 1) - 1] * 2.f - 1.f;
		q__1.r = d__1, q__1.i = d__2;
		X(iv+i-1).r = q__1.r, X(iv+i-1).i = q__1.i;
/* L20: */
	    }
	} else if (*idist == 3) {

/*           Convert generated numbers to normal (0,1) distributio
n */

	    i__2 = il;
	    for (i = 1; i <= il; ++i) {
		i__3 = iv + i - 1;
		d__1 = sqrt(log(u[(i << 1) - 2]) * -2.f);
		d__2 = u[(i << 1) - 1] * 6.2831853071795864769252867663f;
		q__3.r = 0.f, q__3.i = d__2;
		c_exp(&q__2, &q__3);
		q__1.r = d__1 * q__2.r, q__1.i = d__1 * q__2.i;
		X(iv+i-1).r = q__1.r, X(iv+i-1).i = q__1.i;
/* L30: */
	    }
	} else if (*idist == 4) {

/*           Convert generated numbers to complex numbers uniforml
y   
             distributed on the unit disk */

	    i__2 = il;
	    for (i = 1; i <= il; ++i) {
		i__3 = iv + i - 1;
		d__1 = sqrt(u[(i << 1) - 2]);
		d__2 = u[(i << 1) - 1] * 6.2831853071795864769252867663f;
		q__3.r = 0.f, q__3.i = d__2;
		c_exp(&q__2, &q__3);
		q__1.r = d__1 * q__2.r, q__1.i = d__1 * q__2.i;
		X(iv+i-1).r = q__1.r, X(iv+i-1).i = q__1.i;
/* L40: */
	    }
	} else if (*idist == 5) {

/*           Convert generated numbers to complex numbers uniforml
y   
             distributed on the unit circle */

	    i__2 = il;
	    for (i = 1; i <= il; ++i) {
		i__3 = iv + i - 1;
		d__1 = u[(i << 1) - 1] * 6.2831853071795864769252867663f;
		q__2.r = 0.f, q__2.i = d__1;
		c_exp(&q__1, &q__2);
		X(iv+i-1).r = q__1.r, X(iv+i-1).i = q__1.i;
/* L50: */
	    }
	}
/* L60: */
    }
    return 0;

/*     End of CLARNV */

} /* clarnv_slu */