kusano 7d535a
/*! @file izmax1.c
kusano 7d535a
 * \brief Finds the index of the element whose real part has maximum absolute value
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
#include <math.h></math.h>
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
    IZMAX1 finds the index of the element whose real part has maximum   
kusano 7d535a
    absolute value.   
kusano 7d535a
kusano 7d535a
    Based on IZAMAX from 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 >= 1.   
kusano 7d535a
kusano 7d535a
   ===================================================================== 
kusano 7d535a
kusano 7d535a
*/  
kusano 7d535a
kusano 7d535a
int
kusano 7d535a
izmax1_(int *n, doublecomplex *cx, int *incx)
kusano 7d535a
{
kusano 7d535a
kusano 7d535a
kusano 7d535a
    /* System generated locals */
kusano 7d535a
    int ret_val, i__1, i__2;
kusano 7d535a
    double d__1;
kusano 7d535a
    
kusano 7d535a
    /* Local variables */
kusano 7d535a
    double smax;
kusano 7d535a
    int i, ix;
kusano 7d535a
kusano 7d535a
#define CX(I) cx[(I)-1]
kusano 7d535a
kusano 7d535a
    ret_val = 0;
kusano 7d535a
    if (*n < 1) {
kusano 7d535a
	return ret_val;
kusano 7d535a
    }
kusano 7d535a
    ret_val = 1;
kusano 7d535a
    if (*n == 1) {
kusano 7d535a
	return ret_val;
kusano 7d535a
    }
kusano 7d535a
    if (*incx == 1) {
kusano 7d535a
	goto L30;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
/*     CODE FOR INCREMENT NOT EQUAL TO 1 */
kusano 7d535a
kusano 7d535a
    ix = 1;
kusano 7d535a
    smax = (d__1 = CX(1).r, fabs(d__1));
kusano 7d535a
    ix += *incx;
kusano 7d535a
    i__1 = *n;
kusano 7d535a
    for (i = 2; i <= *n; ++i) {
kusano 7d535a
	i__2 = ix;
kusano 7d535a
	if ((d__1 = CX(ix).r, fabs(d__1)) <= smax) {
kusano 7d535a
	    goto L10;
kusano 7d535a
	}
kusano 7d535a
	ret_val = i;
kusano 7d535a
	i__2 = ix;
kusano 7d535a
	smax = (d__1 = CX(ix).r, fabs(d__1));
kusano 7d535a
L10:
kusano 7d535a
	ix += *incx;
kusano 7d535a
/* L20: */
kusano 7d535a
    }
kusano 7d535a
    return ret_val;
kusano 7d535a
kusano 7d535a
/*     CODE FOR INCREMENT EQUAL TO 1 */
kusano 7d535a
kusano 7d535a
L30:
kusano 7d535a
    smax = (d__1 = CX(1).r, fabs(d__1));
kusano 7d535a
    i__1 = *n;
kusano 7d535a
    for (i = 2; i <= *n; ++i) {
kusano 7d535a
	i__2 = i;
kusano 7d535a
	if ((d__1 = CX(i).r, fabs(d__1)) <= smax) {
kusano 7d535a
	    goto L40;
kusano 7d535a
	}
kusano 7d535a
	ret_val = i;
kusano 7d535a
	i__2 = i;
kusano 7d535a
	smax = (d__1 = CX(i).r, fabs(d__1));
kusano 7d535a
L40:
kusano 7d535a
	;
kusano 7d535a
    }
kusano 7d535a
    return ret_val;
kusano 7d535a
kusano 7d535a
/*     End of IZMAX1 */
kusano 7d535a
kusano 7d535a
} /* izmax1_ */
kusano 7d535a