kusano 7d535a
/*! @file icmax1.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_scomplex.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
    ICMAX1 finds the index of the element whose real part has maximum   
kusano 7d535a
    absolute value.   
kusano 7d535a
kusano 7d535a
    Based on ICAMAX 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 CLACON.   
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 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
int icmax1_(int *n, complex *cx, int *incx)
kusano 7d535a
{
kusano 7d535a
/*
kusano 7d535a
       NEXT LINE IS THE ONLY MODIFICATION.   
kusano 7d535a
kusano 7d535a
    
kusano 7d535a
   Parameter adjustments   
kusano 7d535a
       Function Body */
kusano 7d535a
    /* System generated locals */
kusano 7d535a
    int ret_val, i__1, i__2;
kusano 7d535a
    float r__1;
kusano 7d535a
    /* Local variables */
kusano 7d535a
    static float smax;
kusano 7d535a
    static int i, ix;
kusano 7d535a
kusano 7d535a
kusano 7d535a
#define CX(I) cx[(I)-1]
kusano 7d535a
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 = (r__1 = CX(1).r, fabs(r__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 ((r__1 = CX(ix).r, fabs(r__1)) <= smax) {
kusano 7d535a
	    goto L10;
kusano 7d535a
	}
kusano 7d535a
	ret_val = i;
kusano 7d535a
	i__2 = ix;
kusano 7d535a
	smax = (r__1 = CX(ix).r, fabs(r__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 = (r__1 = CX(1).r, fabs(r__1));
kusano 7d535a
    i__1 = *n;
kusano 7d535a
    for (i = 2; i <= *n; ++i) {
kusano 7d535a
	i__2 = i;
kusano 7d535a
	if ((r__1 = CX(i).r, fabs(r__1)) <= smax) {
kusano 7d535a
	    goto L40;
kusano 7d535a
	}
kusano 7d535a
	ret_val = i;
kusano 7d535a
	i__2 = i;
kusano 7d535a
	smax = (r__1 = CX(i).r, fabs(r__1));
kusano 7d535a
L40:
kusano 7d535a
	;
kusano 7d535a
    }
kusano 7d535a
    return ret_val;
kusano 7d535a
kusano 7d535a
/*     End of ICMAX1 */
kusano 7d535a
kusano 7d535a
} /* icmax1_ */
kusano 7d535a