euclidean norm of a vector.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer | :: | n | ||||
real(kind=wp) | :: | x(*) | ||||
integer | :: | incx |
real(wp) function dnrm2(n,x,incx) integer incx,n real(wp) x(*) real(wp) absxi,norm,scale,ssq integer ix if (n<1 .or. incx<1) then norm = zero else if (n==1) then norm = abs(x(1)) else scale = zero ssq = one ! the following loop is equivalent to this call to the lapack ! auxiliary routine: ! call dlassq( n, x, incx, scale, ssq ) do ix = 1,1 + (n-1)*incx,incx if (x(ix)/=zero) then absxi = abs(x(ix)) if (scale<absxi) then ssq = one + ssq* (scale/absxi)**2 scale = absxi else ssq = ssq + (absxi/scale)**2 end if end if end do norm = scale*sqrt(ssq) end if dnrm2 = norm end function dnrm2