    MODULE nrm2_other
      CHARACTER (LEN=*), PARAMETER :: descript = &
        'original Algorithm 539 code rewritten to be more readable with compensated summation'
        
    CONTAINS

      FUNCTION snrm2(n, x, incx) RESULT(res)
      USE set_precision, lp=>skind
!*     .. Scalar Arguments ..
        INTEGER, INTENT(IN) :: incx, n
!*     .. Array Arguments ..
        REAL (lp), INTENT(IN) :: x(*)
        REAL(lp):: res
!*     ..
!*
!*  SNRM2 returns the Euclidean norm of a vector via the function
!*  name, so that
!*
!*     SNRM2 := sqrt( x'*x )
!*
      include 'newOrigRealCsum.inc'
      END FUNCTION snrm2

      FUNCTION dnrm2(n, x, incx) RESULT(res)
      USE set_precision, lp=>dkind
!*     .. Scalar Arguments ..
        INTEGER, INTENT(IN) :: incx, n
!*     .. Array Arguments ..
        REAL (lp), INTENT(IN) :: x(*)
        REAL(lp):: res
!*     ..
!*
!*  Purpose
!*  =======
!*
!*  DNRM2 returns the Euclidean norm of a vector via the function
!*  name, so that
!*
!*     DNRM2 := sqrt( x'*x )
      include 'newOrigRealCsum.inc'
      END FUNCTION dnrm2

      FUNCTION scnrm2(n, x, incx) RESULT(res)
      USE set_precision, lp=>skind
!*     .. Scalar Arguments ..
        INTEGER, INTENT(IN) :: incx, n
!*     .. Array Arguments ..
        COMPLEX (lp), INTENT(IN) :: x(*)
        REAL(lp):: res
!*     ..
!*
!*  SCNRM2 returns the Euclidean norm of a vector via the function
!*  name, so that
!*
!*     SCNRM2 := sqrt( conjg( x' )*x )
!*
      include 'newOrigComplexCsum.inc'
      END FUNCTION scnrm2

      FUNCTION dznrm2(n, x, incx) RESULT(res)
      USE set_precision, lp=>dkind
!*     .. Scalar Arguments ..
        INTEGER incx, n
!*     .. Array Arguments ..
        COMPLEX (lp) ::x(*)
        REAL(lp) :: res
!*     ..
!*
!*  DZNRM2 returns the Euclidean norm of a vector via the function
!*  name, so that
!*
!*     DZNRM2 := sqrt( conjg( x' )*x )
      include 'newOrigComplexCsum.inc'
      END FUNCTION dznrm2

    END MODULE nrm2_other
