MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
idamax.f
1  INTEGER FUNCTION idamax(N,DX,INCX)
2 * .. Scalar Arguments ..
3  INTEGER incx,n
4 * ..
5 * .. Array Arguments ..
6  DOUBLE PRECISION dx(*)
7 * ..
8 *
9 * Purpose
10 * =======
11 *
12 * IDAMAX finds the index of element having max. absolute value.
13 *
14 * Further Details
15 * ===============
16 *
17 * jack dongarra, linpack, 3/11/78.
18 * modified 3/93 to return if incx .le. 0.
19 * modified 12/3/93, array(1) declarations changed to array(*)
20 *
21 * =====================================================================
22 *
23 * .. Local Scalars ..
24  DOUBLE PRECISION dmax
25  INTEGER i,ix
26 * ..
27 * .. Intrinsic Functions ..
28  INTRINSIC dabs
29 * ..
30  idamax = 0
31  IF (n.LT.1 .OR. incx.LE.0) RETURN
32  idamax = 1
33  IF (n.EQ.1) RETURN
34  IF (incx.EQ.1) THEN
35 *
36 * code for increment equal to 1
37 *
38  dmax = dabs(dx(1))
39  DO i = 2,n
40  IF (dabs(dx(i)).GT.dmax) THEN
41  idamax = i
42  dmax = dabs(dx(i))
43  END IF
44  END DO
45  ELSE
46 *
47 * code for increment not equal to 1
48 *
49  ix = 1
50  dmax = dabs(dx(1))
51  ix = ix + incx
52  DO i = 2,n
53  IF (dabs(dx(ix)).GT.dmax) THEN
54  idamax = i
55  dmax = dabs(dx(ix))
56  END IF
57  ix = ix + incx
58  END DO
59  END IF
60  RETURN
61  END