idamax Function

public function idamax(n, dx, incx)

Find the smallest index of that component of a vector having the maximum magnitude.

Description

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.

Authors

  • Lawson, C. L., (JPL)
  • Hanson, R. J., (SNLA)
  • Kincaid, D. R., (U. of Texas)
  • Krogh, F. T., (JPL)

Reference

  • C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T. Krogh, Basic linear algebra subprograms for Fortran usage, Algorithm No. 539, Transactions on Mathematical Software 5, 3 (September 1979), pp. 308-323.

History

  • 791001 DATE WRITTEN
  • 890531 Changed all specific intrinsics to generic. (WRB)
  • 890531 REVISION DATE from Version 3.2
  • 891214 Prologue converted to Version 4.0 format. (BAB)
  • 900821 Modified to correct problem with a negative increment. (WRB)
  • 920501 Reformatted the REFERENCES section. (WRB)
  • Jacob Williams, 2/21/2016, converted to modern Fortran.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: n

number of elements in input vector(s)

real(kind=wp), intent(in), dimension(*) :: dx

double precision vector with N elements

integer, intent(in) :: incx

storage spacing between elements of DX

Return Value integer


Called by

proc~~idamax~~CalledByGraph proc~idamax dvode_blas_module::idamax proc~dgbfa dvode_linpack_module::dgbfa proc~dgbfa->proc~idamax proc~dgefa dvode_linpack_module::dgefa proc~dgefa->proc~idamax proc~dvjac dvode_module::dvode_t%dvjac proc~dvjac->proc~dgbfa proc~dvjac->proc~dgefa proc~dvnlsd dvode_module::dvode_t%dvnlsd proc~dvnlsd->proc~dvjac proc~dvstep dvode_module::dvode_t%dvstep proc~dvstep->proc~dvnlsd proc~dvode dvode_module::dvode_t%dvode proc~dvode->proc~dvstep

Source Code

    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