      FUNCTION RELERR(A,X,B,LDA,N,WORK)
************************************************************************
*                                                                      *
* Purpose: Calculates the relative error in the infinity-norm          *
*          in "Ax", if Ax = b.                                         *
*          (Relative error in the infinity-norm can be translated      *
*           into a statement about the number of correct significant   *
*           digits in x.)                                              *
*                                                                      *
*           Def.:                                                      *
*                  epsrel= Norminf(Ax - b)/Nnorminf(b) <> 10^(-p)      *
*                                                                      *
*                  then the largest component of x has approximately   *
*                  p correct significant digits.                       *
*                                                                      *
*                  Norminf: infinity norm                              *
*                                                                      *
* Input:   Complex*16 matrix:                     A(1:LDA,1:N)         *
*          Complex*16 vector:                     X(1:N)               *
*          Complex*16 vector:                     B(1:N)               *
*          Integer:                               LDA,N                *
*          Complex*16 vector:                     WORK(1:LDA)          *
*                                                                      *
* Output:  none                                                        *
*                                                                      *
* Date: 12:12:1996              Author: Marco Kunze                    *
*                                       Marco.Kunze@univ-rennes1.fr    *
************************************************************************

      IMPLICIT   NONE
      INTEGER    LDA, N
      REAL*8     VALUE, RELERR, ABSERR, NVECIN
      COMPLEX*16 A(1:LDA,1:N), X(1:N), B(1:N),WORK(1:LDA)

      EXTERNAL ABSERR, NVECIN

C----------------------- Executable Statements -------------------------

      VALUE = 0.D0

      VALUE = ABSERR(A,X,B,LDA,N,WORK) / NVECIN(B,N)

      RELERR = VALUE

      END

      FUNCTION ABSERR(A,X,B,LDA,N,WORK)
************************************************************************
*                                                                      *
* Purpose: Calculates the absolute error in the infinity-norm          *
*          in "Ax", if Ax = b.                                         *
*          (Relative error in the infinity-norm can be translated      *
*           into a statement about the number of correct significant   *
*           digits in x.)                                              *
*                                                                      *
*           Def.:  epsrel= Norminf(Ax - b)                             *
*                                                                      *
*                  Norminf: infinity norm                              *
*                                                                      *
* Input:   Complex*16 matrix:                     A(1:LDA,1:N)         *
*          Complex*16 vector:                     X(1:N)               *
*          Complex*16 vector:                     B(1:N)               *
*          Integer:                               LDA,N                *
*          Complex*16 vector:                     WORK(1:LDA)          *
*                                                                      *
* Output:  none                                                        *
*                                                                      *
* Date: 12:12:1996              Author: Marco Kunze                    *
*                                       Marco.Kunze@univ-rennes1.fr    *
************************************************************************

      IMPLICIT   NONE
      INTEGER    LDA, N
      REAL*8     VALUE, NVECIN, ABSERR
      COMPLEX*16 A(1:LDA,1:N), X(1:N), B(1:N), WORK(1:LDA)

      EXTERNAL   NVECIN

C----------------------- Executable Statements -------------------------

      VALUE = 0.D0

      CALL ZMTVEP(A,X,WORK,LDA,N)
      CALL ZVEVED(WORK,B,N)

      VALUE = NVECIN(WORK,N)

      ABSERR = VALUE

      END

      FUNCTION NVECIN(VEC,DIM)
************************************************************************
*                                                                      *
* Purpose: Calculates the infinity norm of a complex*16 vector vec.    *
*                                                                      *
* Input:   Complex*16 vector:                  VEC(DIM)                *
*          Dimension of vec:                   DIM                     *
*                                                                      *
* Output:  none                                                        *
*                                                                      *
* Date: 12:12:1996              Author: Marco Kunze                    *
*                                       Marco.Kunze@univ-rennes1.fr    *
************************************************************************

      IMPLICIT   NONE
      INTEGER    DIM, I
      REAL*8     NVECIN, VALUE
      COMPLEX*16 VEC(DIM)

C----------------------- Executable Statements -------------------------

      VALUE = 0.D0

      DO 10 I =1, DIM

         VALUE = MAX( VALUE, ABS(VEC(I)))

10    CONTINUE

      NVECIN = VALUE

      END

      SUBROUTINE ZMTVEP(A,X,B,LDA,N)
************************************************************************
*                                                                      *
* Purpose: Matrix-Vector Multiplication Ax = b.                        *
*                                                                      *
* Input:   Complex*16 matrix:                     A(1:LDA,1:N)         *
*          Complex*16 vector:                     X(1:N)               *
*          Integer:                               LDA,N                *
*                                                                      *
* Output:  Complex*16 vector:                     B(1:N)               *
*                                                                      *
* Date: 12:12:1996              Author: Marco Kunze                    *
*                                       Marco.Kunze@univ-rennes1.fr    *
************************************************************************

      IMPLICIT   NONE
      INTEGER    K, L, LDA, N
      COMPLEX*16 A(1:LDA,1:N), X(1:N), B(1:N)
      COMPLEX*16 SUM
C----------------------- Executable Statements -------------------------

      DO 10 K=1,N
      SUM=(0.D0,0.D0)
         DO 20 L=1,N
           SUM=SUM+A(K,L)*X(L)
20       CONTINUE
      B(K) = SUM
10    CONTINUE

      END

      SUBROUTINE ZVEVED(X,Y,N)
************************************************************************
*                                                                      *
* Purpose: Vector-Vector subtraction.                                  *
*                                                                      *
* Input:   Complex*16 vector:                  X(N), Y(N)              *
*          Integer:                            N                       *
*                                                                      *
* Output:  Complex*16 vector:                  X(N) = X(N) - Y(N)      *
*                                                                      *
* Date: 12:12:1996              Author: Marco Kunze                    *
*                                       Marco.Kunze@univ-rennes1.fr    *
************************************************************************

      IMPLICIT   NONE
      INTEGER    I, N
      COMPLEX*16 X(1:N), Y(1:N)

C----------------------- Executable Statements -------------------------

      DO 10 I=1,N
          X(I) = X(I) - Y(I)
10    CONTINUE

      END


