kusano 7d535a
/*! @file dzsum1.c
kusano 7d535a
 * \brief Takes sum of the absolute values of a complex vector and returns a double precision result
kusano 7d535a
 *
kusano 7d535a
 * 
kusano 7d535a
 *     -- LAPACK auxiliary 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
 *     October 31, 1992   
kusano 7d535a
 * 
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
#include "slu_dcomplex.h"
kusano 7d535a
#include "slu_Cnames.h"
kusano 7d535a
kusano 7d535a
/*! \brief
kusano 7d535a
kusano 7d535a
 
kusano 7d535a
    Purpose   
kusano 7d535a
    =======   
kusano 7d535a
kusano 7d535a
    DZSUM1 takes the sum of the absolute values of a complex   
kusano 7d535a
    vector and returns a double precision result.   
kusano 7d535a
kusano 7d535a
    Based on DZASUM from the Level 1 BLAS.   
kusano 7d535a
    The change is to use the 'genuine' absolute value.   
kusano 7d535a
kusano 7d535a
    Contributed by Nick Higham for use with ZLACON.   
kusano 7d535a
kusano 7d535a
    Arguments   
kusano 7d535a
    =========   
kusano 7d535a
kusano 7d535a
    N       (input) INT   
kusano 7d535a
            The number of elements in the vector CX.   
kusano 7d535a
kusano 7d535a
    CX      (input) COMPLEX*16 array, dimension (N)   
kusano 7d535a
            The vector whose elements will be summed.   
kusano 7d535a
kusano 7d535a
    INCX    (input) INT   
kusano 7d535a
            The spacing between successive values of CX.  INCX > 0.   
kusano 7d535a
kusano 7d535a
    ===================================================================== 
kusano 7d535a
kusano 7d535a
*/  
kusano 7d535a
double dzsum1_(int *n, doublecomplex *cx, int *incx)
kusano 7d535a
{
kusano 7d535a
kusano 7d535a
    /* Builtin functions */
kusano 7d535a
    double z_abs(doublecomplex *);
kusano 7d535a
    
kusano 7d535a
    /* Local variables */
kusano 7d535a
    int i, nincx;
kusano 7d535a
    double stemp;
kusano 7d535a
kusano 7d535a
kusano 7d535a
#define CX(I) cx[(I)-1]
kusano 7d535a
kusano 7d535a
    stemp = 0.;
kusano 7d535a
    if (*n <= 0) {
kusano 7d535a
	return stemp;
kusano 7d535a
    }
kusano 7d535a
    if (*incx == 1) {
kusano 7d535a
	goto L20;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    /*     CODE FOR INCREMENT NOT EQUAL TO 1 */
kusano 7d535a
kusano 7d535a
    nincx = *n * *incx;
kusano 7d535a
    for (i = 1; *incx < 0 ? i >= nincx : i <= nincx; i += *incx) {
kusano 7d535a
kusano 7d535a
	/*        NEXT LINE MODIFIED. */
kusano 7d535a
kusano 7d535a
	stemp += z_abs(&CX(i));
kusano 7d535a
/* L10: */
kusano 7d535a
    }
kusano 7d535a
    
kusano 7d535a
    return stemp;
kusano 7d535a
kusano 7d535a
    /*     CODE FOR INCREMENT EQUAL TO 1 */
kusano 7d535a
kusano 7d535a
L20:
kusano 7d535a
    for (i = 1; i <= *n; ++i) {
kusano 7d535a
kusano 7d535a
	/*        NEXT LINE MODIFIED. */
kusano 7d535a
kusano 7d535a
	stemp += z_abs(&CX(i));
kusano 7d535a
/* L30: */
kusano 7d535a
    }
kusano 7d535a
    
kusano 7d535a
    return stemp;
kusano 7d535a
kusano 7d535a
    /*     End of DZSUM1 */
kusano 7d535a
kusano 7d535a
} /* dzsum1_ */
kusano 7d535a