**********************************************************************
C
C     Copyright (C) 1992  Roland W. Freund and Noel M. Nachtigal
C     All rights reserved.
C
C     This code is part of a copyrighted package.  For details, see the
C     file `cpyrit.doc' in the top-level directory.
C
C     *****************************************************************
C     ANY USE OF  THIS CODE CONSTITUTES ACCEPTANCE OF  THE TERMS OF THE
C                             COPYRIGHT NOTICE
C     *****************************************************************
C
C**********************************************************************
C
      SUBROUTINE SAXPBY (N,SZ,SA,SX,SB,SY)
C
C     Purpose:
C     This subroutine computes SZ = SA * SX + SB * SY.  Several special
C     cases are handled separately:
C        SA =  0.0, SB =  0.0 => SZ = 0.0
C        SA =  0.0, SB =  1.0 => SZ = SY  (this is COPY)
C        SA =  0.0, SB = -1.0 => SZ = -SY
C        SA =  0.0, SB =   SB => SZ = SB * SY  (this is SCAL)
C        SA =  1.0, SB =  0.0 => SZ = SX  (this is COPY)
C        SA =  1.0, SB =  1.0 => SZ = SX + SY
C        SA =  1.0, SB = -1.0 => SZ = SX - SY
C        SA =  1.0, SB =   SB => SZ = SX + SB * SY (this is AXPY)
C        SA = -1.0, SB =  0.0 => SZ = -SX
C        SA = -1.0, SB =  1.0 => SZ = -SX + SY
C        SA = -1.0, SB = -1.0 => SZ = -SX - SY
C        SA = -1.0, SB =   SB => SZ = -SX + SB * SY
C        SA =   SA, SB =  0.0 => SZ = SA * SX  (this is SCAL)
C        SA =   SA, SB =  1.0 => SZ = SA * SX + SY  (this is AXPY)
C        SA =   SA, SB = -1.0 => SZ = SA * SX - SY
C        SA =   SA, SB =   SB => SZ = SA * SX + SB * SY
C     SZ may be the same as SX or SY.
C
C     Parameters:
C     N  = the dimension of the vectors (input).
C     SZ = the vector result (output).
C     SA = scalar multiplier for SX (input).
C     SX = one of the vectors (input).
C     SB = scalar multiplier for SY (input).
C     SY = the other vector (input).
C
C     Noel M. Nachtigal
C     March 23, 1993
C
C**********************************************************************
C
      INTEGER N
      REAL SA, SB, SX(N), SY(N), SZ(N)
C
C     Local variables.
C
      INTEGER I
C
      IF (N.LE.0) RETURN
C
      IF (SA.EQ.0.0E0) THEN
         IF (SB.EQ.0.0E0) THEN
C           SA = 0.0, SB = 0.0 => SZ = 0.0.
            DO 10 I = 1, N
               SZ(I) = 0.0E0
 10         CONTINUE
         ELSE IF (SB.EQ.1.0E0) THEN
C           SA = 0.0, SB = 1.0 => SZ = SY (this is COPY).
            DO 20 I = 1, N
               SZ(I) = SY(I)
 20         CONTINUE
         ELSE IF (SB.EQ.-1.0E0) THEN
C           SA = 0.0, SB = -1.0 => SZ = -SY.
            DO 30 I = 1, N
               SZ(I) = -SY(I)
 30         CONTINUE
         ELSE
C           SA = 0.0, SB = SB => SZ = SB * SY (this is SCAL).
            DO 40 I = 1, N
               SZ(I) = SB * SY(I)
 40         CONTINUE
         END IF
      ELSE IF (SA.EQ.1.0E0) THEN
         IF (SB.EQ.0.0E0) THEN
C           SA = 1.0, SB = 0.0 => SZ = SX (this is COPY).
            DO 50 I = 1, N
               SZ(I) = SX(I)
 50         CONTINUE
         ELSE IF (SB.EQ.1.0E0) THEN
C           SA = 1.0, SB = 1.0 => SZ = SX + SY.
            DO 60 I = 1, N
               SZ(I) = SX(I) + SY(I)
 60         CONTINUE
         ELSE IF (SB.EQ.-1.0E0) THEN
C           SA = 1.0, SB = -1.0 => SZ = SX - SY.
            DO 70 I = 1, N
               SZ(I) = SX(I) - SY(I)
 70         CONTINUE
         ELSE
C           SA = 1.0, SB = SB => SZ = SX + SB * SY (this is AXPY).
            DO 80 I = 1, N
               SZ(I) = SX(I) + SB * SY(I)
 80         CONTINUE
         END IF
      ELSE IF (SA.EQ.-1.0E0) THEN
         IF (SB.EQ.0.0E0) THEN
C           SA = -1.0, SB = 0.0 => SZ = -SX
            DO 90 I = 1, N
               SZ(I) = -SX(I)
 90         CONTINUE
         ELSE IF (SB.EQ.1.0E0) THEN
C           SA = -1.0, SB = 1.0 => SZ = -SX + SY
            DO 100 I = 1, N
               SZ(I) = -SX(I) + SY(I)
 100        CONTINUE
         ELSE IF (SB.EQ.-1.0E0) THEN
C           SA = -1.0, SB = -1.0 => SZ = -SX - SY.
            DO 110 I = 1, N
               SZ(I) = -SX(I) - SY(I)
 110        CONTINUE
         ELSE
C           SA = -1.0, SB = SB => SZ = -SX + SB * SY
            DO 120 I = 1, N
               SZ(I) = -SX(I) + SB * SY(I)
 120        CONTINUE
         END IF
      ELSE
         IF (SB.EQ.0.0E0) THEN
C           SA = SA, SB = 0.0 => SZ = SA * SX (this is SCAL).
            DO 130 I = 1, N
               SZ(I) = SA * SX(I)
 130        CONTINUE
         ELSE IF (SB.EQ.1.0E0) THEN
C           SA = SA, SB = 1.0 => SZ = SA * SX + SY (this is AXPY)
            DO 140 I = 1, N
               SZ(I) = SA * SX(I) + SY(I)
 140        CONTINUE
         ELSE IF (SB.EQ.-1.0E0) THEN
C           SA = SA, SB = -1.0 => SZ = SA * SX - SY.
            DO 150 I = 1, N
               SZ(I) = SA * SX(I) - SY(I)
 150        CONTINUE
         ELSE
C           SA = SA, SB = SB => SZ = SA * SX + SB * SY.
            DO 160 I = 1, N
               SZ(I) = SA * SX(I) + SB * SY(I)
 160        CONTINUE
         END IF
      END IF
C
      RETURN
      END
C
C**********************************************************************