stdlib_icamax Function

public pure function stdlib_icamax(n, cx, incx)

ICAMAX finds the index of the first element having maximum |Re(.)| + |Im(.)|

Arguments

Type IntentOptional Attributes Name
integer(kind=ilp), intent(in) :: n
complex(kind=sp), intent(in) :: cx(*)
integer(kind=ilp), intent(in) :: incx

Return Value integer(kind=ilp)


Source Code

     pure integer(ilp) function stdlib_icamax(n,cx,incx)
     !! ICAMAX finds the index of the first element having maximum |Re(.)| + |Im(.)|
        ! -- reference blas level1 routine --
        ! -- reference blas is a software package provided by univ. of tennessee,    --
        ! -- univ. of california berkeley, univ. of colorado denver and nag ltd..--
           ! Scalar Arguments 
           integer(ilp), intent(in) :: incx, n
           ! Array Arguments 
           complex(sp), intent(in) :: cx(*)
        ! =====================================================================
           ! Local Scalars 
           real(sp) :: smax
           integer(ilp) :: i, ix
           stdlib_icamax = 0
           if (n<1 .or. incx<=0) return
           stdlib_icamax = 1
           if (n==1) return
           if (incx==1) then
              ! code for increment equal to 1
              smax = stdlib_scabs1(cx(1))
              do i = 2,n
                 if (stdlib_scabs1(cx(i))>smax) then
                    stdlib_icamax = i
                    smax = stdlib_scabs1(cx(i))
                 end if
              end do
           else
              ! code for increment not equal to 1
              ix = 1
              smax = stdlib_scabs1(cx(1))
              ix = ix + incx
              do i = 2,n
                 if (stdlib_scabs1(cx(ix))>smax) then
                    stdlib_icamax = i
                    smax = stdlib_scabs1(cx(ix))
                 end if
                 ix = ix + incx
              end do
           end if
           return
     end function stdlib_icamax