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.
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed
arrows point from an interface to procedures which implement that interface.
This could include the module procedures in a generic interface or the
implementation in a submodule of an interface in a parent module.
Source Code
integer function idamax(n,dx,incx)implicit noneinteger,intent(in)::n!! number of elements in input vector(s)real(wp),dimension(*),intent(in)::dx!! double precision vector with `N` elementsinteger,intent(in)::incx!! storage spacing between elements of `DX`real(wp)::dmax,xmaginteger::i,ixidamax=0if(n<=0)returnidamax=1if(n==1)return if(incx==1)then! code for increments equal to 1.dmax=abs(dx(1))do i=2,nxmag=abs(dx(i))if(xmag>dmax)thenidamax=idmax=xmagendif enddo else! code for increments not equal to 1.ix=1if(incx<0)ix=(-n+1)*incx+1dmax=abs(dx(ix))ix=ix+incxdo i=2,nxmag=abs(dx(ix))if(xmag>dmax)thenidamax=idmax=xmagendifix=ix+incxenddo end if end function idamax