Find the smallest index of that component of a vector having the maximum magnitude.
Find smallest index of maximum magnitude of double precision DX. IDAMAX = first I, I = 1 to N, to maximize ABS(DX(IX+(I-1)INCX)), where IX = 1 if INCX >= 0, else IX = 1+(1-N)INCX.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | n |
number of elements in input vector(s) |
||
real(kind=wp), | intent(in), | dimension(*) | :: | dx |
double precision vector with |
|
integer, | intent(in) | :: | incx |
storage spacing between elements of |
integer function idamax(n,dx,incx) implicit none integer,intent(in) :: n !! number of elements in input vector(s) real(wp),dimension(*),intent(in) :: dx !! double precision vector with `N` elements integer,intent(in) :: incx !! storage spacing between elements of `DX` real(wp) :: dmax, xmag integer :: i, ix idamax = 0 if ( n<=0 ) return idamax = 1 if ( n==1 ) return if ( incx==1 ) then ! code for increments equal to 1. dmax = abs(dx(1)) do i = 2 , n xmag = abs(dx(i)) if ( xmag>dmax ) then idamax = i dmax = xmag endif enddo else ! code for increments not equal to 1. ix = 1 if ( incx<0 ) ix = (-n+1)*incx + 1 dmax = abs(dx(ix)) ix = ix + incx do i = 2 , n xmag = abs(dx(ix)) if ( xmag>dmax ) then idamax = i dmax = xmag endif ix = ix + incx enddo end if end function idamax