kusano 2b45e8
      SUBROUTINE DSYR2KF( UPLO, TRANS, N, K, ALPHA, A, LDA, B, LDB,
kusano 2b45e8
     $                   BETA, C, LDC )
kusano 2b45e8
*     .. Scalar Arguments ..
kusano 2b45e8
      CHARACTER*1        UPLO, TRANS
kusano 2b45e8
      INTEGER            N, K, LDA, LDB, LDC
kusano 2b45e8
      DOUBLE PRECISION   ALPHA, BETA
kusano 2b45e8
*     .. Array Arguments ..
kusano 2b45e8
      DOUBLE PRECISION   A( LDA, * ), B( LDB, * ), C( LDC, * )
kusano 2b45e8
*     ..
kusano 2b45e8
*
kusano 2b45e8
*  Purpose
kusano 2b45e8
*  =======
kusano 2b45e8
*
kusano 2b45e8
*  DSYR2K  performs one of the symmetric rank 2k operations
kusano 2b45e8
*
kusano 2b45e8
*     C := alpha*A*B' + alpha*B*A' + beta*C,
kusano 2b45e8
*
kusano 2b45e8
*  or
kusano 2b45e8
*
kusano 2b45e8
*     C := alpha*A'*B + alpha*B'*A + beta*C,
kusano 2b45e8
*
kusano 2b45e8
*  where  alpha and beta  are scalars, C is an  n by n  symmetric matrix
kusano 2b45e8
*  and  A and B  are  n by k  matrices  in the  first  case  and  k by n
kusano 2b45e8
*  matrices in the second case.
kusano 2b45e8
*
kusano 2b45e8
*  Parameters
kusano 2b45e8
*  ==========
kusano 2b45e8
*
kusano 2b45e8
*  UPLO   - CHARACTER*1.
kusano 2b45e8
*           On  entry,   UPLO  specifies  whether  the  upper  or  lower
kusano 2b45e8
*           triangular  part  of the  array  C  is to be  referenced  as
kusano 2b45e8
*           follows:
kusano 2b45e8
*
kusano 2b45e8
*              UPLO = 'U' or 'u'   Only the  upper triangular part of  C
kusano 2b45e8
*                                  is to be referenced.
kusano 2b45e8
*
kusano 2b45e8
*              UPLO = 'L' or 'l'   Only the  lower triangular part of  C
kusano 2b45e8
*                                  is to be referenced.
kusano 2b45e8
*
kusano 2b45e8
*           Unchanged on exit.
kusano 2b45e8
*
kusano 2b45e8
*  TRANS  - CHARACTER*1.
kusano 2b45e8
*           On entry,  TRANS  specifies the operation to be performed as
kusano 2b45e8
*           follows:
kusano 2b45e8
*
kusano 2b45e8
*              TRANS = 'N' or 'n'   C := alpha*A*B' + alpha*B*A' +
kusano 2b45e8
*                                        beta*C.
kusano 2b45e8
*
kusano 2b45e8
*              TRANS = 'T' or 't'   C := alpha*A'*B + alpha*B'*A +
kusano 2b45e8
*                                        beta*C.
kusano 2b45e8
*
kusano 2b45e8
*              TRANS = 'C' or 'c'   C := alpha*A'*B + alpha*B'*A +
kusano 2b45e8
*                                        beta*C.
kusano 2b45e8
*
kusano 2b45e8
*           Unchanged on exit.
kusano 2b45e8
*
kusano 2b45e8
*  N      - INTEGER.
kusano 2b45e8
*           On entry,  N specifies the order of the matrix C.  N must be
kusano 2b45e8
*           at least zero.
kusano 2b45e8
*           Unchanged on exit.
kusano 2b45e8
*
kusano 2b45e8
*  K      - INTEGER.
kusano 2b45e8
*           On entry with  TRANS = 'N' or 'n',  K  specifies  the number
kusano 2b45e8
*           of  columns  of the  matrices  A and B,  and on  entry  with
kusano 2b45e8
*           TRANS = 'T' or 't' or 'C' or 'c',  K  specifies  the  number
kusano 2b45e8
*           of rows of the matrices  A and B.  K must be at least  zero.
kusano 2b45e8
*           Unchanged on exit.
kusano 2b45e8
*
kusano 2b45e8
*  ALPHA  - DOUBLE PRECISION.
kusano 2b45e8
*           On entry, ALPHA specifies the scalar alpha.
kusano 2b45e8
*           Unchanged on exit.
kusano 2b45e8
*
kusano 2b45e8
*  A      - DOUBLE PRECISION array of DIMENSION ( LDA, ka ), where ka is
kusano 2b45e8
*           k  when  TRANS = 'N' or 'n',  and is  n  otherwise.
kusano 2b45e8
*           Before entry with  TRANS = 'N' or 'n',  the  leading  n by k
kusano 2b45e8
*           part of the array  A  must contain the matrix  A,  otherwise
kusano 2b45e8
*           the leading  k by n  part of the array  A  must contain  the
kusano 2b45e8
*           matrix A.
kusano 2b45e8
*           Unchanged on exit.
kusano 2b45e8
*
kusano 2b45e8
*  LDA    - INTEGER.
kusano 2b45e8
*           On entry, LDA specifies the first dimension of A as declared
kusano 2b45e8
*           in  the  calling  (sub)  program.   When  TRANS = 'N' or 'n'
kusano 2b45e8
*           then  LDA must be at least  max( 1, n ), otherwise  LDA must
kusano 2b45e8
*           be at least  max( 1, k ).
kusano 2b45e8
*           Unchanged on exit.
kusano 2b45e8
*
kusano 2b45e8
*  B      - DOUBLE PRECISION array of DIMENSION ( LDB, kb ), where kb is
kusano 2b45e8
*           k  when  TRANS = 'N' or 'n',  and is  n  otherwise.
kusano 2b45e8
*           Before entry with  TRANS = 'N' or 'n',  the  leading  n by k
kusano 2b45e8
*           part of the array  B  must contain the matrix  B,  otherwise
kusano 2b45e8
*           the leading  k by n  part of the array  B  must contain  the
kusano 2b45e8
*           matrix B.
kusano 2b45e8
*           Unchanged on exit.
kusano 2b45e8
*
kusano 2b45e8
*  LDB    - INTEGER.
kusano 2b45e8
*           On entry, LDB specifies the first dimension of B as declared
kusano 2b45e8
*           in  the  calling  (sub)  program.   When  TRANS = 'N' or 'n'
kusano 2b45e8
*           then  LDB must be at least  max( 1, n ), otherwise  LDB must
kusano 2b45e8
*           be at least  max( 1, k ).
kusano 2b45e8
*           Unchanged on exit.
kusano 2b45e8
*
kusano 2b45e8
*  BETA   - DOUBLE PRECISION.
kusano 2b45e8
*           On entry, BETA specifies the scalar beta.
kusano 2b45e8
*           Unchanged on exit.
kusano 2b45e8
*
kusano 2b45e8
*  C      - DOUBLE PRECISION array of DIMENSION ( LDC, n ).
kusano 2b45e8
*           Before entry  with  UPLO = 'U' or 'u',  the leading  n by n
kusano 2b45e8
*           upper triangular part of the array C must contain the upper
kusano 2b45e8
*           triangular part  of the  symmetric matrix  and the strictly
kusano 2b45e8
*           lower triangular part of C is not referenced.  On exit, the
kusano 2b45e8
*           upper triangular part of the array  C is overwritten by the
kusano 2b45e8
*           upper triangular part of the updated matrix.
kusano 2b45e8
*           Before entry  with  UPLO = 'L' or 'l',  the leading  n by n
kusano 2b45e8
*           lower triangular part of the array C must contain the lower
kusano 2b45e8
*           triangular part  of the  symmetric matrix  and the strictly
kusano 2b45e8
*           upper triangular part of C is not referenced.  On exit, the
kusano 2b45e8
*           lower triangular part of the array  C is overwritten by the
kusano 2b45e8
*           lower triangular part of the updated matrix.
kusano 2b45e8
*
kusano 2b45e8
*  LDC    - INTEGER.
kusano 2b45e8
*           On entry, LDC specifies the first dimension of C as declared
kusano 2b45e8
*           in  the  calling  (sub)  program.   LDC  must  be  at  least
kusano 2b45e8
*           max( 1, n ).
kusano 2b45e8
*           Unchanged on exit.
kusano 2b45e8
*
kusano 2b45e8
*
kusano 2b45e8
*  Level 3 Blas routine.
kusano 2b45e8
*
kusano 2b45e8
*
kusano 2b45e8
*  -- Written on 8-February-1989.
kusano 2b45e8
*     Jack Dongarra, Argonne National Laboratory.
kusano 2b45e8
*     Iain Duff, AERE Harwell.
kusano 2b45e8
*     Jeremy Du Croz, Numerical Algorithms Group Ltd.
kusano 2b45e8
*     Sven Hammarling, Numerical Algorithms Group Ltd.
kusano 2b45e8
*
kusano 2b45e8
*
kusano 2b45e8
*     .. External Functions ..
kusano 2b45e8
      LOGICAL            LSAME
kusano 2b45e8
      EXTERNAL           LSAME
kusano 2b45e8
*     .. External Subroutines ..
kusano 2b45e8
      EXTERNAL           XERBLA
kusano 2b45e8
*     .. Intrinsic Functions ..
kusano 2b45e8
      INTRINSIC          MAX
kusano 2b45e8
*     .. Local Scalars ..
kusano 2b45e8
      LOGICAL            UPPER
kusano 2b45e8
      INTEGER            I, INFO, J, L, NROWA
kusano 2b45e8
      DOUBLE PRECISION   TEMP1, TEMP2
kusano 2b45e8
*     .. Parameters ..
kusano 2b45e8
      DOUBLE PRECISION   ONE         , ZERO
kusano 2b45e8
      PARAMETER        ( ONE = 1.0D+0, ZERO = 0.0D+0 )
kusano 2b45e8
*     ..
kusano 2b45e8
*     .. Executable Statements ..
kusano 2b45e8
*
kusano 2b45e8
*     Test the input parameters.
kusano 2b45e8
*
kusano 2b45e8
      IF( LSAME( TRANS, 'N' ) )THEN
kusano 2b45e8
         NROWA = N
kusano 2b45e8
      ELSE
kusano 2b45e8
         NROWA = K
kusano 2b45e8
      END IF
kusano 2b45e8
      UPPER = LSAME( UPLO, 'U' )
kusano 2b45e8
*
kusano 2b45e8
      INFO = 0
kusano 2b45e8
      IF(      ( .NOT.UPPER               ).AND.
kusano 2b45e8
     $         ( .NOT.LSAME( UPLO , 'L' ) )      )THEN
kusano 2b45e8
         INFO = 1
kusano 2b45e8
      ELSE IF( ( .NOT.LSAME( TRANS, 'N' ) ).AND.
kusano 2b45e8
     $         ( .NOT.LSAME( TRANS, 'T' ) ).AND.
kusano 2b45e8
     $         ( .NOT.LSAME( TRANS, 'C' ) )      )THEN
kusano 2b45e8
         INFO = 2
kusano 2b45e8
      ELSE IF( N  .LT.0               )THEN
kusano 2b45e8
         INFO = 3
kusano 2b45e8
      ELSE IF( K  .LT.0               )THEN
kusano 2b45e8
         INFO = 4
kusano 2b45e8
      ELSE IF( LDA.LT.MAX( 1, NROWA ) )THEN
kusano 2b45e8
         INFO = 7
kusano 2b45e8
      ELSE IF( LDB.LT.MAX( 1, NROWA ) )THEN
kusano 2b45e8
         INFO = 9
kusano 2b45e8
      ELSE IF( LDC.LT.MAX( 1, N     ) )THEN
kusano 2b45e8
         INFO = 12
kusano 2b45e8
      END IF
kusano 2b45e8
      IF( INFO.NE.0 )THEN
kusano 2b45e8
         CALL XERBLA( 'DSYR2K', INFO )
kusano 2b45e8
         RETURN
kusano 2b45e8
      END IF
kusano 2b45e8
*
kusano 2b45e8
*     Quick return if possible.
kusano 2b45e8
*
kusano 2b45e8
      IF( ( N.EQ.0 ).OR.
kusano 2b45e8
     $    ( ( ( ALPHA.EQ.ZERO ).OR.( K.EQ.0 ) ).AND.( BETA.EQ.ONE ) ) )
kusano 2b45e8
     $   RETURN
kusano 2b45e8
*
kusano 2b45e8
*     And when  alpha.eq.zero.
kusano 2b45e8
*
kusano 2b45e8
      IF( ALPHA.EQ.ZERO )THEN
kusano 2b45e8
         IF( UPPER )THEN
kusano 2b45e8
            IF( BETA.EQ.ZERO )THEN
kusano 2b45e8
               DO 20, J = 1, N
kusano 2b45e8
                  DO 10, I = 1, J
kusano 2b45e8
                     C( I, J ) = ZERO
kusano 2b45e8
   10             CONTINUE
kusano 2b45e8
   20          CONTINUE
kusano 2b45e8
            ELSE
kusano 2b45e8
               DO 40, J = 1, N
kusano 2b45e8
                  DO 30, I = 1, J
kusano 2b45e8
                     C( I, J ) = BETA*C( I, J )
kusano 2b45e8
   30             CONTINUE
kusano 2b45e8
   40          CONTINUE
kusano 2b45e8
            END IF
kusano 2b45e8
         ELSE
kusano 2b45e8
            IF( BETA.EQ.ZERO )THEN
kusano 2b45e8
               DO 60, J = 1, N
kusano 2b45e8
                  DO 50, I = J, N
kusano 2b45e8
                     C( I, J ) = ZERO
kusano 2b45e8
   50             CONTINUE
kusano 2b45e8
   60          CONTINUE
kusano 2b45e8
            ELSE
kusano 2b45e8
               DO 80, J = 1, N
kusano 2b45e8
                  DO 70, I = J, N
kusano 2b45e8
                     C( I, J ) = BETA*C( I, J )
kusano 2b45e8
   70             CONTINUE
kusano 2b45e8
   80          CONTINUE
kusano 2b45e8
            END IF
kusano 2b45e8
         END IF
kusano 2b45e8
         RETURN
kusano 2b45e8
      END IF
kusano 2b45e8
*
kusano 2b45e8
*     Start the operations.
kusano 2b45e8
*
kusano 2b45e8
      IF( LSAME( TRANS, 'N' ) )THEN
kusano 2b45e8
*
kusano 2b45e8
*        Form  C := alpha*A*B' + alpha*B*A' + C.
kusano 2b45e8
*
kusano 2b45e8
         IF( UPPER )THEN
kusano 2b45e8
            DO 130, J = 1, N
kusano 2b45e8
               IF( BETA.EQ.ZERO )THEN
kusano 2b45e8
                  DO 90, I = 1, J
kusano 2b45e8
                     C( I, J ) = ZERO
kusano 2b45e8
   90             CONTINUE
kusano 2b45e8
               ELSE IF( BETA.NE.ONE )THEN
kusano 2b45e8
                  DO 100, I = 1, J
kusano 2b45e8
                     C( I, J ) = BETA*C( I, J )
kusano 2b45e8
  100             CONTINUE
kusano 2b45e8
               END IF
kusano 2b45e8
               DO 120, L = 1, K
kusano 2b45e8
                  IF( ( A( J, L ).NE.ZERO ).OR.
kusano 2b45e8
     $                ( B( J, L ).NE.ZERO )     )THEN
kusano 2b45e8
                     TEMP1 = ALPHA*B( J, L )
kusano 2b45e8
                     TEMP2 = ALPHA*A( J, L )
kusano 2b45e8
                     DO 110, I = 1, J
kusano 2b45e8
                        C( I, J ) = C( I, J ) +
kusano 2b45e8
     $                              A( I, L )*TEMP1 + B( I, L )*TEMP2
kusano 2b45e8
  110                CONTINUE
kusano 2b45e8
                  END IF
kusano 2b45e8
  120          CONTINUE
kusano 2b45e8
  130       CONTINUE
kusano 2b45e8
         ELSE
kusano 2b45e8
            DO 180, J = 1, N
kusano 2b45e8
               IF( BETA.EQ.ZERO )THEN
kusano 2b45e8
                  DO 140, I = J, N
kusano 2b45e8
                     C( I, J ) = ZERO
kusano 2b45e8
  140             CONTINUE
kusano 2b45e8
               ELSE IF( BETA.NE.ONE )THEN
kusano 2b45e8
                  DO 150, I = J, N
kusano 2b45e8
                     C( I, J ) = BETA*C( I, J )
kusano 2b45e8
  150             CONTINUE
kusano 2b45e8
               END IF
kusano 2b45e8
               DO 170, L = 1, K
kusano 2b45e8
                  IF( ( A( J, L ).NE.ZERO ).OR.
kusano 2b45e8
     $                ( B( J, L ).NE.ZERO )     )THEN
kusano 2b45e8
                     TEMP1 = ALPHA*B( J, L )
kusano 2b45e8
                     TEMP2 = ALPHA*A( J, L )
kusano 2b45e8
                     DO 160, I = J, N
kusano 2b45e8
                        C( I, J ) = C( I, J ) +
kusano 2b45e8
     $                              A( I, L )*TEMP1 + B( I, L )*TEMP2
kusano 2b45e8
  160                CONTINUE
kusano 2b45e8
                  END IF
kusano 2b45e8
  170          CONTINUE
kusano 2b45e8
  180       CONTINUE
kusano 2b45e8
         END IF
kusano 2b45e8
      ELSE
kusano 2b45e8
*
kusano 2b45e8
*        Form  C := alpha*A'*B + alpha*B'*A + C.
kusano 2b45e8
*
kusano 2b45e8
         IF( UPPER )THEN
kusano 2b45e8
            DO 210, J = 1, N
kusano 2b45e8
               DO 200, I = 1, J
kusano 2b45e8
                  TEMP1 = ZERO
kusano 2b45e8
                  TEMP2 = ZERO
kusano 2b45e8
                  DO 190, L = 1, K
kusano 2b45e8
                     TEMP1 = TEMP1 + A( L, I )*B( L, J )
kusano 2b45e8
                     TEMP2 = TEMP2 + B( L, I )*A( L, J )
kusano 2b45e8
  190             CONTINUE
kusano 2b45e8
                  IF( BETA.EQ.ZERO )THEN
kusano 2b45e8
                     C( I, J ) = ALPHA*TEMP1 + ALPHA*TEMP2
kusano 2b45e8
                  ELSE
kusano 2b45e8
                     C( I, J ) = BETA *C( I, J ) +
kusano 2b45e8
     $                           ALPHA*TEMP1 + ALPHA*TEMP2
kusano 2b45e8
                  END IF
kusano 2b45e8
  200          CONTINUE
kusano 2b45e8
  210       CONTINUE
kusano 2b45e8
         ELSE
kusano 2b45e8
            DO 240, J = 1, N
kusano 2b45e8
               DO 230, I = J, N
kusano 2b45e8
                  TEMP1 = ZERO
kusano 2b45e8
                  TEMP2 = ZERO
kusano 2b45e8
                  DO 220, L = 1, K
kusano 2b45e8
                     TEMP1 = TEMP1 + A( L, I )*B( L, J )
kusano 2b45e8
                     TEMP2 = TEMP2 + B( L, I )*A( L, J )
kusano 2b45e8
  220             CONTINUE
kusano 2b45e8
                  IF( BETA.EQ.ZERO )THEN
kusano 2b45e8
                     C( I, J ) = ALPHA*TEMP1 + ALPHA*TEMP2
kusano 2b45e8
                  ELSE
kusano 2b45e8
                     C( I, J ) = BETA *C( I, J ) +
kusano 2b45e8
     $                           ALPHA*TEMP1 + ALPHA*TEMP2
kusano 2b45e8
                  END IF
kusano 2b45e8
  230          CONTINUE
kusano 2b45e8
  240       CONTINUE
kusano 2b45e8
         END IF
kusano 2b45e8
      END IF
kusano 2b45e8
*
kusano 2b45e8
      RETURN
kusano 2b45e8
*
kusano 2b45e8
*     End of DSYR2K.
kusano 2b45e8
*
kusano 2b45e8
      END