ISMAX/IDMAX/IIMAX

 

Index of maximum element of vector

 

 

Use incx = 1 if the vector x is stored contiguously in

 

 

array x; that is, if xi is stored in x(i). Refer to “BLAS

 

 

Indexing Conventions” in the introduction to this

 

 

chapter.

Output

i

If n ≤ 0, then i = 0. Otherwise, i is the index of the

 

 

maximum element of x.

Fortran

 

INTEGER*4 FUNCTION ISMAX (N,X,INCX)

Equivalent

 

REAL*4 X(*),XMAX

 

 

ISMAX = 1

 

 

IF ( N .GT. 1 ) THEN

 

 

XMAX = X(1)

 

 

INCXA = ABS ( INCX )

 

 

IX = 1 + INCXA

 

 

DO 10 I = 2, N

 

 

IF ( X(IX) .GT. XMAX ) THEN

 

 

ISMAX = I

 

 

XMAX = X(IX)

 

 

END IF

 

 

IX = IX + INCXA

 

10

CONTINUE

 

 

ELSE IF ( N .LT. 1 ) THEN

 

 

ISMAX = 0

 

 

END IF

 

 

RETURN

 

 

END

Example Locate the largest element of a REAL*8 vector x, where x is a vector 10 elements long stored in a one-dimensional array X of dimension 20.

INTEGER*4

I,IDMAX,N,INCX

REAL*8

X(20)

N =

10

 

INCX = 1

 

I =

IDMAX

(N,X,INCX)

50HP MLIB User’s Guide