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