MODULE CInterfaceNrm2
CONTAINS
!
! C interface routines for the hybrid versions of nrm2
!
    FUNCTION  c_snrm2(n, incx, x) RESULT(norm) &
              BIND(c, name='c_snrm2') 
    USE, INTRINSIC :: iso_c_binding, ONLY: c_int, c_float
    USE nrm2HybridMod, ONLY: snrm2
    INTEGER (c_int), INTENT(IN), VALUE :: n, incx
    REAL (c_float), INTENT(IN) :: x(*)
    REAL (c_float) :: norm

    norm = snrm2(n, x, incx)

    END FUNCTION c_snrm2

    FUNCTION  c_dnrm2(n, incx, x) RESULT(norm) &
              BIND(c, name='c_dnrm2') 
    USE, INTRINSIC :: iso_c_binding, ONLY: c_int, c_double
    USE nrm2HybridMod, ONLY: dnrm2
    INTEGER (c_int), INTENT(IN), VALUE :: n, incx
    REAL (c_double), INTENT(IN) :: x(*)
    REAL (c_double) :: norm

    norm = dnrm2(n, x, incx)

    END FUNCTION c_dnrm2

    FUNCTION  c_scnrm2(n, incx, x) RESULT(norm) &
              BIND(c, name='c_scnrm2') 
    USE, INTRINSIC :: iso_c_binding,  &
         ONLY: c_int, c_float, c_float_complex
    USE nrm2HybridMod, ONLY: scnrm2
    INTEGER (c_int), INTENT(IN), VALUE :: n, incx
    COMPLEX (c_float_complex), INTENT(IN) :: x(*)
    REAL (c_float) :: norm

    norm = scnrm2(n, x, incx)

    END FUNCTION c_scnrm2

    FUNCTION  c_dznrm2(n, incx, x) RESULT(norm) &
              BIND(c, name='c_dznrm2') 
    USE, INTRINSIC :: iso_c_binding,  &
         ONLY: c_int, c_double, c_double_complex
    USE nrm2HybridMod, ONLY: dznrm2
    INTEGER (c_int), INTENT(IN), VALUE :: n, incx
    COMPLEX (c_double_complex), INTENT(IN) :: x(*)
    REAL (c_double) :: norm

    norm = dznrm2(n, x, incx)

    END FUNCTION c_dznrm2
!
! and the routines implementing Kahan's algorithm
!
    FUNCTION  c_snrm2Kahan(n, incx, x) RESULT(norm) &
              BIND(c, name='c_snrm2Kahan') 
    USE, INTRINSIC :: iso_c_binding, ONLY: c_int, c_float
    USE nrm2HybridMod, ONLY: snrm2Kahan
    INTEGER (c_int), INTENT(IN), VALUE :: n, incx
    REAL (c_float), INTENT(IN) :: x(*)
    REAL (c_float) :: norm

    norm = snrm2Kahan(n, x, incx)

    END FUNCTION c_snrm2Kahan

    FUNCTION  c_dnrm2Kahan(n, incx, x) RESULT(norm) &
              BIND(c, name='c_dnrm2Kahan') 
    USE, INTRINSIC :: iso_c_binding, ONLY: c_int, c_double
    USE nrm2HybridMod, ONLY: dnrm2Kahan
    INTEGER (c_int), INTENT(IN), VALUE :: n, incx
    REAL (c_double), INTENT(IN) :: x(*)
    REAL (c_double) :: norm

    norm = dnrm2Kahan(n, x, incx)

    END FUNCTION c_dnrm2Kahan

    FUNCTION  c_scnrm2Kahan(n, incx, x) RESULT(norm) &
              BIND(c, name='c_scnrm2Kahan') 
    USE, INTRINSIC :: iso_c_binding,  &
         ONLY: c_int, c_float, c_float_complex
    USE nrm2HybridMod, ONLY: scnrm2Kahan
    INTEGER (c_int), INTENT(IN), VALUE :: n, incx
    COMPLEX (c_float_complex), INTENT(IN) :: x(*)
    REAL (c_float) :: norm

    norm = scnrm2Kahan(n, x, incx)

    END FUNCTION c_scnrm2Kahan

    FUNCTION  c_dznrm2Kahan(n, incx, x) RESULT(norm) &
              BIND(c, name='c_dznrm2Kahan') 
    USE, INTRINSIC :: iso_c_binding,  &
         ONLY: c_int, c_double, c_double_complex
    USE nrm2HybridMod, ONLY: dznrm2Kahan
    INTEGER (c_int), INTENT(IN), VALUE :: n, incx
    COMPLEX (c_double_complex), INTENT(IN) :: x(*)
    REAL (c_double) :: norm

    norm = dznrm2Kahan(n, x, incx)

    END FUNCTION c_dznrm2Kahan

END MODULE CInterfaceNrm2
