kusano 7d535a
/*  -- translated by f2c (version 19940927).
kusano 7d535a
   You must link the resulting object file with the libraries:
kusano 7d535a
	-lf2c -lm   (in that order)
kusano 7d535a
*/
kusano 7d535a
kusano 7d535a
#include "f2c.h"
kusano 7d535a
kusano 7d535a
doublereal slatm2_(integer *m, integer *n, integer *i, integer *j, integer *
kusano 7d535a
	kl, integer *ku, integer *idist, integer *iseed, real *d, integer *
kusano 7d535a
	igrade, real *dl, real *dr, integer *ipvtng, integer *iwork, real *
kusano 7d535a
	sparse)
kusano 7d535a
{
kusano 7d535a
    /* System generated locals */
kusano 7d535a
    real ret_val;
kusano 7d535a
kusano 7d535a
    /* Local variables */
kusano 7d535a
    static integer isub, jsub;
kusano 7d535a
    static real temp;
kusano 7d535a
    extern doublereal slaran_(integer *), slarnd_(integer *, integer *);
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*  -- LAPACK auxiliary test routine (version 2.0) --   
kusano 7d535a
       Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,   
kusano 7d535a
       Courant Institute, Argonne National Lab, and Rice University   
kusano 7d535a
       February 29, 1992   
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
    Purpose   
kusano 7d535a
    =======   
kusano 7d535a
kusano 7d535a
       SLATM2 returns the (I,J) entry of a random matrix of dimension   
kusano 7d535a
       (M, N) described by the other paramters. It is called by the   
kusano 7d535a
       SLATMR routine in order to build random test matrices. No error   
kusano 7d535a
       checking on parameters is done, because this routine is called in 
kusano 7d535a
  
kusano 7d535a
       a tight loop by SLATMR which has already checked the parameters.   
kusano 7d535a
kusano 7d535a
       Use of SLATM2 differs from SLATM3 in the order in which the random 
kusano 7d535a
  
kusano 7d535a
       number generator is called to fill in random matrix entries.   
kusano 7d535a
       With SLATM2, the generator is called to fill in the pivoted matrix 
kusano 7d535a
  
kusano 7d535a
       columnwise. With SLATM3, the generator is called to fill in the   
kusano 7d535a
       matrix columnwise, after which it is pivoted. Thus, SLATM3 can   
kusano 7d535a
       be used to construct random matrices which differ only in their   
kusano 7d535a
       order of rows and/or columns. SLATM2 is used to construct band   
kusano 7d535a
       matrices while avoiding calling the random number generator for   
kusano 7d535a
       entries outside the band (and therefore generating random numbers 
kusano 7d535a
  
kusano 7d535a
kusano 7d535a
       The matrix whose (I,J) entry is returned is constructed as   
kusano 7d535a
       follows (this routine only computes one entry):   
kusano 7d535a
kusano 7d535a
         If I is outside (1..M) or J is outside (1..N), return zero   
kusano 7d535a
            (this is convenient for generating matrices in band format). 
kusano 7d535a
  
kusano 7d535a
kusano 7d535a
         Generate a matrix A with random entries of distribution IDIST.   
kusano 7d535a
kusano 7d535a
         Set the diagonal to D.   
kusano 7d535a
kusano 7d535a
         Grade the matrix, if desired, from the left (by DL) and/or   
kusano 7d535a
            from the right (by DR or DL) as specified by IGRADE.   
kusano 7d535a
kusano 7d535a
         Permute, if desired, the rows and/or columns as specified by   
kusano 7d535a
            IPVTNG and IWORK.   
kusano 7d535a
kusano 7d535a
         Band the matrix to have lower bandwidth KL and upper   
kusano 7d535a
            bandwidth KU.   
kusano 7d535a
kusano 7d535a
         Set random entries to zero as specified by SPARSE.   
kusano 7d535a
kusano 7d535a
    Arguments   
kusano 7d535a
    =========   
kusano 7d535a
kusano 7d535a
    M      - INTEGER   
kusano 7d535a
             Number of rows of matrix. Not modified.   
kusano 7d535a
kusano 7d535a
    N      - INTEGER   
kusano 7d535a
             Number of columns of matrix. Not modified.   
kusano 7d535a
kusano 7d535a
    I      - INTEGER   
kusano 7d535a
             Row of entry to be returned. Not modified.   
kusano 7d535a
kusano 7d535a
    J      - INTEGER   
kusano 7d535a
             Column of entry to be returned. Not modified.   
kusano 7d535a
kusano 7d535a
    KL     - INTEGER   
kusano 7d535a
             Lower bandwidth. Not modified.   
kusano 7d535a
kusano 7d535a
    KU     - INTEGER   
kusano 7d535a
             Upper bandwidth. Not modified.   
kusano 7d535a
kusano 7d535a
    IDIST  - INTEGER   
kusano 7d535a
             On entry, IDIST specifies the type of distribution to be   
kusano 7d535a
             used to generate a random matrix .   
kusano 7d535a
             1 => UNIFORM( 0, 1 )   
kusano 7d535a
             2 => UNIFORM( -1, 1 )   
kusano 7d535a
             3 => NORMAL( 0, 1 )   
kusano 7d535a
             Not modified.   
kusano 7d535a
kusano 7d535a
    ISEED  - INTEGER array of dimension ( 4 )   
kusano 7d535a
             Seed for random number generator.   
kusano 7d535a
             Changed on exit.   
kusano 7d535a
kusano 7d535a
    D      - REAL array of dimension ( MIN( I , J ) )   
kusano 7d535a
             Diagonal entries of matrix. Not modified.   
kusano 7d535a
kusano 7d535a
    IGRADE - INTEGER   
kusano 7d535a
             Specifies grading of matrix as follows:   
kusano 7d535a
             0  => no grading   
kusano 7d535a
             1  => matrix premultiplied by diag( DL )   
kusano 7d535a
             2  => matrix postmultiplied by diag( DR )   
kusano 7d535a
             3  => matrix premultiplied by diag( DL ) and   
kusano 7d535a
                           postmultiplied by diag( DR )   
kusano 7d535a
             4  => matrix premultiplied by diag( DL ) and   
kusano 7d535a
                           postmultiplied by inv( diag( DL ) )   
kusano 7d535a
             5  => matrix premultiplied by diag( DL ) and   
kusano 7d535a
                           postmultiplied by diag( DL )   
kusano 7d535a
             Not modified.   
kusano 7d535a
kusano 7d535a
    DL     - REAL array ( I or J, as appropriate )   
kusano 7d535a
             Left scale factors for grading matrix.  Not modified.   
kusano 7d535a
kusano 7d535a
    DR     - REAL array ( I or J, as appropriate )   
kusano 7d535a
             Right scale factors for grading matrix.  Not modified.   
kusano 7d535a
kusano 7d535a
    IPVTNG - INTEGER   
kusano 7d535a
             On entry specifies pivoting permutations as follows:   
kusano 7d535a
             0 => none.   
kusano 7d535a
             1 => row pivoting.   
kusano 7d535a
             2 => column pivoting.   
kusano 7d535a
             3 => full pivoting, i.e., on both sides.   
kusano 7d535a
             Not modified.   
kusano 7d535a
kusano 7d535a
    IWORK  - INTEGER array ( I or J, as appropriate )   
kusano 7d535a
             This array specifies the permutation used. The   
kusano 7d535a
             row (or column) in position K was originally in   
kusano 7d535a
             position IWORK( K ).   
kusano 7d535a
             This differs from IWORK for SLATM3. Not modified.   
kusano 7d535a
kusano 7d535a
    SPARSE - REAL    between 0. and 1.   
kusano 7d535a
             On entry specifies the sparsity of the matrix   
kusano 7d535a
             if sparse matix is to be generated.   
kusano 7d535a
             SPARSE should lie between 0 and 1.   
kusano 7d535a
             A uniform ( 0, 1 ) random number x is generated and   
kusano 7d535a
             compared to SPARSE; if x is larger the matrix entry   
kusano 7d535a
             is unchanged and if x is smaller the entry is set   
kusano 7d535a
             to zero. Thus on the average a fraction SPARSE of the   
kusano 7d535a
             entries will be set to zero.   
kusano 7d535a
             Not modified.   
kusano 7d535a
kusano 7d535a
    ===================================================================== 
kusano 7d535a
  
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
   -----------------------------------------------------------------------
kusano 7d535a
   
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
       Check for I and J in range   
kusano 7d535a
kusano 7d535a
       Parameter adjustments */
kusano 7d535a
    --iwork;
kusano 7d535a
    --dr;
kusano 7d535a
    --dl;
kusano 7d535a
    --d;
kusano 7d535a
    --iseed;
kusano 7d535a
kusano 7d535a
    /* Function Body */
kusano 7d535a
    if (*i < 1 || *i > *m || *j < 1 || *j > *n) {
kusano 7d535a
	ret_val = 0.f;
kusano 7d535a
	return ret_val;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
/*     Check for banding */
kusano 7d535a
kusano 7d535a
    if (*j > *i + *ku || *j < *i - *kl) {
kusano 7d535a
	ret_val = 0.f;
kusano 7d535a
	return ret_val;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
/*     Check for sparsity */
kusano 7d535a
kusano 7d535a
    if (*sparse > 0.f) {
kusano 7d535a
	if (slaran_(&iseed[1]) < *sparse) {
kusano 7d535a
	    ret_val = 0.f;
kusano 7d535a
	    return ret_val;
kusano 7d535a
	}
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
/*     Compute subscripts depending on IPVTNG */
kusano 7d535a
kusano 7d535a
    if (*ipvtng == 0) {
kusano 7d535a
	isub = *i;
kusano 7d535a
	jsub = *j;
kusano 7d535a
    } else if (*ipvtng == 1) {
kusano 7d535a
	isub = iwork[*i];
kusano 7d535a
	jsub = *j;
kusano 7d535a
    } else if (*ipvtng == 2) {
kusano 7d535a
	isub = *i;
kusano 7d535a
	jsub = iwork[*j];
kusano 7d535a
    } else if (*ipvtng == 3) {
kusano 7d535a
	isub = iwork[*i];
kusano 7d535a
	jsub = iwork[*j];
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
/*     Compute entry and grade it according to IGRADE */
kusano 7d535a
kusano 7d535a
    if (isub == jsub) {
kusano 7d535a
	temp = d[isub];
kusano 7d535a
    } else {
kusano 7d535a
	temp = slarnd_(idist, &iseed[1]);
kusano 7d535a
    }
kusano 7d535a
    if (*igrade == 1) {
kusano 7d535a
	temp *= dl[isub];
kusano 7d535a
    } else if (*igrade == 2) {
kusano 7d535a
	temp *= dr[jsub];
kusano 7d535a
    } else if (*igrade == 3) {
kusano 7d535a
	temp = temp * dl[isub] * dr[jsub];
kusano 7d535a
    } else if (*igrade == 4 && isub != jsub) {
kusano 7d535a
	temp = temp * dl[isub] / dl[jsub];
kusano 7d535a
    } else if (*igrade == 5) {
kusano 7d535a
	temp = temp * dl[isub] * dl[jsub];
kusano 7d535a
    }
kusano 7d535a
    ret_val = temp;
kusano 7d535a
    return ret_val;
kusano 7d535a
kusano 7d535a
/*     End of SLATM2 */
kusano 7d535a
kusano 7d535a
} /* slatm2_ */
kusano 7d535a