idamax finds the index of the first element having maximum absolute value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=ip) | :: | n | ||||
real(kind=wp) | :: | dx(*) | ||||
integer(kind=ip) | :: | incx |
integer function idamax(n,dx,incx) !! idamax finds the index of the first element having maximum absolute value. integer(ip) :: incx,n real(wp) :: dx(*) real(wp) :: dmax integer(ip) :: i,ix idamax = 0 if (n<1 .or. incx<=0) return idamax = 1 if (n==1) return if (incx==1) then ! code for increment equal to 1 dmax = abs(dx(1)) do i = 2,n if (abs(dx(i))>dmax) then idamax = i dmax = abs(dx(i)) end if end do else ! code for increment not equal to 1 ix = 1 dmax = abs(dx(1)) ix = ix + incx do i = 2,n if (abs(dx(ix))>dmax) then idamax = i dmax = abs(dx(ix)) end if ix = ix + incx end do end if end function idamax