1 /*! @file izmax1.c
2  * \brief Finds the index of the element whose real part has maximum absolute value
3  *
4  * <pre>
5  *     -- LAPACK auxiliary routine (version 2.0) --
6  *     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
7  *     Courant Institute, Argonne National Lab, and Rice University
8  *     October 31, 1992
9  * </pre>
10  */
11 #include <math.h>
12 #include "slu_dcomplex.h"
13 #include "slu_Cnames.h"
14 
15 /*! \brief
16 
17 <pre>
18     Purpose
19     =======
20 
21     IZMAX1 finds the index of the element whose real part has maximum
22     absolute value.
23 
24     Based on IZAMAX from Level 1 BLAS.
25     The change is to use the 'genuine' absolute value.
26 
27     Contributed by Nick Higham for use with ZLACON.
28 
29     Arguments
30     =========
31 
32     N       (input) INT
33             The number of elements in the vector CX.
34 
35     CX      (input) COMPLEX*16 array, dimension (N)
36             The vector whose elements will be summed.
37 
38     INCX    (input) INT
39             The spacing between successive values of CX.  INCX >= 1.
40 
41    =====================================================================
42 </pre>
43 */
44 
45 int
izmax1_(int * n,doublecomplex * cx,int * incx)46 izmax1_(int *n, doublecomplex *cx, int *incx)
47 {
48 
49 
50     /* System generated locals */
51     int ret_val, i__1, i__2;
52     double d__1;
53 
54     /* Local variables */
55     double smax;
56     int i, ix;
57 
58 #define CX(I) cx[(I)-1]
59 
60     ret_val = 0;
61     if (*n < 1) {
62 	return ret_val;
63     }
64     ret_val = 1;
65     if (*n == 1) {
66 	return ret_val;
67     }
68     if (*incx == 1) {
69 	goto L30;
70     }
71 
72 /*     CODE FOR INCREMENT NOT EQUAL TO 1 */
73 
74     ix = 1;
75     smax = (d__1 = CX(1).r, fabs(d__1));
76     ix += *incx;
77     i__1 = *n;
78     for (i = 2; i <= *n; ++i) {
79 	i__2 = ix;
80 	if ((d__1 = CX(ix).r, fabs(d__1)) <= smax) {
81 	    goto L10;
82 	}
83 	ret_val = i;
84 	i__2 = ix;
85 	smax = (d__1 = CX(ix).r, fabs(d__1));
86 L10:
87 	ix += *incx;
88 /* L20: */
89     }
90     return ret_val;
91 
92 /*     CODE FOR INCREMENT EQUAL TO 1 */
93 
94 L30:
95     smax = (d__1 = CX(1).r, fabs(d__1));
96     i__1 = *n;
97     for (i = 2; i <= *n; ++i) {
98 	i__2 = i;
99 	if ((d__1 = CX(i).r, fabs(d__1)) <= smax) {
100 	    goto L40;
101 	}
102 	ret_val = i;
103 	i__2 = i;
104 	smax = (d__1 = CX(i).r, fabs(d__1));
105 L40:
106 	;
107     }
108     return ret_val;
109 
110 /*     End of IZMAX1 */
111 
112 } /* izmax1_ */
113 
114