1 |
C idamax.f |
2 |
C is freely available from netlib. It is not subject to any GNU License |
3 |
C set by the authors of the ASCEND math programming system. |
4 |
C $Date: 1996/04/30 18:14:08 $ $Revision: 1.1.1.1 $ |
5 |
C |
6 |
integer function idamax(n,dx,incx) |
7 |
c |
8 |
c finds the index of element having max. absolute value. |
9 |
c jack dongarra, linpack, 3/11/78. |
10 |
c modified to correct problem with negative increment, 8/21/90. |
11 |
c |
12 |
double precision dx(*),dmax |
13 |
integer i,incx,ix,n |
14 |
c |
15 |
idamax = 0 |
16 |
if( n .lt. 1 ) return |
17 |
idamax = 1 |
18 |
if(n.eq.1)return |
19 |
if(incx.eq.1)go to 20 |
20 |
c |
21 |
c code for increment not equal to 1 |
22 |
c |
23 |
ix = 1 |
24 |
if(incx.lt.0)ix = (-n+1)*incx + 1 |
25 |
dmax = dabs(dx(ix)) |
26 |
ix = ix + incx |
27 |
do 10 i = 2,n |
28 |
if(dabs(dx(ix)).le.dmax) go to 5 |
29 |
idamax = i |
30 |
dmax = dabs(dx(ix)) |
31 |
5 ix = ix + incx |
32 |
10 continue |
33 |
return |
34 |
c |
35 |
c code for increment equal to 1 |
36 |
c |
37 |
20 dmax = dabs(dx(1)) |
38 |
do 30 i = 2,n |
39 |
if(dabs(dx(i)).le.dmax) go to 30 |
40 |
idamax = i |
41 |
dmax = dabs(dx(i)) |
42 |
30 continue |
43 |
return |
44 |
end |