      SUBROUTINE lambda_ccsd_t_left(a_i0,d_f1,d_v2,d_y1,d_y2,k_f1_offset
     &,k_v2_offset,k_y1_offset,k_y2_offset,t_h4b,t_h5b,t_h6b,t_p1b,t_p2b
     &,t_p3b,toggle)
C     $Id$
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_yv + = 1 * P( 9 ) * y ( h4 p1 )_y * v ( h5 h6 p2 p3 )_v
C     i0 ( h4 h5 h6 p1 p2 p3 )_yf + = 1 * P( 9 ) * y ( h4 h5 p1 p2 )_y * f ( h6 p3 )_f
C     i0 ( h4 h5 h6 p1 p2 p3 )_yv + = -1 * P( 9 ) * Sum ( h7 ) * y ( h4 h7 p1 p2 )_y * v ( h5 h6 h7 p3 )_v
C     i0 ( h4 h5 h6 p1 p2 p3 )_yv + = -1 * P( 9 ) * Sum ( p7 ) * y ( h4 h5 p1 p7 )_y * v ( h6 p7 p2 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "util.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER t_h4b
      INTEGER t_h5b
      INTEGER t_h6b
      INTEGER t_p1b
      INTEGER t_p2b
      INTEGER t_p3b
      INTEGER toggle
      INTEGER d_y1
      INTEGER k_y1_offset
      INTEGER d_v2
      INTEGER k_v2_offset
      INTEGER d_y2
      INTEGER k_y2_offset
      INTEGER d_f1
      INTEGER k_f1_offset
      DOUBLE PRECISION a_i0(*)
      IF (toggle .eq. 1) CALL lambda_ccsd_t_left_1(d_y1,k_y1_offset,d_v2
     &,k_v2_offset,a_i0,t_h4b,t_h5b,t_h6b,t_p1b,t_p2b,t_p3b)
      IF (toggle .eq. 2) CALL lambda_ccsd_t_left_2(d_y2,k_y2_offset,d_f1
     &,k_f1_offset,a_i0,t_h4b,t_h5b,t_h6b,t_p1b,t_p2b,t_p3b)
      IF (toggle .eq. 2) CALL lambda_ccsd_t_left_3(d_y2,k_y2_offset,d_v2
     &,k_v2_offset,a_i0,t_h4b,t_h5b,t_h6b,t_p1b,t_p2b,t_p3b)
      IF (toggle .eq. 2) CALL lambda_ccsd_t_left_4(d_y2,k_y2_offset,d_v2
     &,k_v2_offset,a_i0,t_h4b,t_h5b,t_h6b,t_p1b,t_p2b,t_p3b)
      RETURN
      END
      SUBROUTINE lambda_ccsd_t_left_1(d_a,k_a_offset,d_b,k_b_offset,a_c,
     &t_h4b,t_h5b,t_h6b,t_p1b,t_p2b,t_p3b)
C     $Id$
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_yv + = 1 * P( 9 ) * y ( h4 p1 )_y * v ( h5 h6 p2 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER t_h4b
      INTEGER t_h5b
      INTEGER t_h6b
      INTEGER t_p1b
      INTEGER t_p2b
      INTEGER t_p3b
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b_1
      INTEGER p1b_1
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER p2b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      DOUBLE PRECISION a_c(*)
      LOGICAL skipped
      DO h4b = 1,noab
      DO h5b = 1,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = noab+1,noab+nvab
      DO p3b = p2b,noab+nvab
      skipped = .true.
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) skipped = .false.
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &3b)) skipped = .false.
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &1b)) skipped = .false.
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) skipped = .false.
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &3b)) skipped = .false.
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &1b)) skipped = .false.
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h4b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) skipped = .false.
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h4b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &3b)) skipped = .false.
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h4b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &1b)) skipped = .false.
      IF (.not.skipped) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,irrep_v)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('lambda_ccsd_t_left_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+p1b-1)) .eq. irrep_y) TH
     &EN
      CALL TCE_RESTRICTED_2(h4b,p1b,h4b_1,p1b_1)
      CALL TCE_RESTRICTED_4(h5b,h6b,p2b,p3b,h5b_2,h6b_2,p2b_2,p3b_2)
      dim_common = 1
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+p1b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb
     &(k_range+p2b-1) * int_mb(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('lambda_ccsd_t_left_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &lambda_ccsd_t_left_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p1b_1
     & - noab - 1 + nvab * (h4b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+p1b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('lambda_ccsd_t_left_1',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('lambda_ccsd_t_left_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &lambda_ccsd_t_left_1',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p2b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h5b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p3b-1)
     &,4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('lambda_ccsd_t_left_1',6,
     &MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('lambda_ccsd_t_left_
     &1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('lambda_ccsd_t_left_
     &1',8,MA_ERR)
      END IF
      END IF
      END IF
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h4b-1),6,4,3,5,2,1,1.0d0)
      END IF
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &3b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h4b-1),6,4,3,2,5,1,-1.0d0)
      END IF
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &1b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h4b-1),6,4,3,2,1,5,1.0d0)
      END IF
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h4b-1),4,6,3,5,2,1,-1.0d0)
      END IF
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &3b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h4b-1),4,6,3,2,5,1,1.0d0)
      END IF
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &1b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h4b-1),4,6,3,2,1,5,-1.0d0)
      END IF
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h4b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h4b-1),4,3,6,5,2,1,1.0d0)
      END IF
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h4b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &3b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h4b-1),4,3,6,2,5,1,-1.0d0)
      END IF
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h4b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &1b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h4b-1),4,3,6,2,1,5,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('lambda_ccsd_t_left_
     &1',9,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE lambda_ccsd_t_left_2(d_a,k_a_offset,d_b,k_b_offset,a_c,
     &t_h4b,t_h5b,t_h6b,t_p1b,t_p2b,t_p3b)
C     $Id$
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_yf + = 1 * P( 9 ) * y ( h4 h5 p1 p2 )_y * f ( h6 p3 )_f
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER t_h4b
      INTEGER t_h5b
      INTEGER t_h6b
      INTEGER t_p1b
      INTEGER t_p2b
      INTEGER t_p3b
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b_1
      INTEGER h5b_1
      INTEGER p1b_1
      INTEGER p2b_1
      INTEGER h6b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      DOUBLE PRECISION a_c(*)
      LOGICAL skipped
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = 1,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO p3b = noab+1,noab+nvab
      skipped = .true.
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) skipped = .false.
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &2b)) skipped = .false.
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &2b)) skipped = .false.
      IF ((t_h4b .eq. h6b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) skipped = .false.
      IF ((t_h4b .eq. h6b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &2b)) skipped = .false.
      IF ((t_h4b .eq. h6b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &2b)) skipped = .false.
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) skipped = .false.
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &2b)) skipped = .false.
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &2b)) skipped = .false.
      IF (.not.skipped) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,irrep_f)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('lambda_ccsd_t_left_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+p2b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+p2b-1)))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_4(h4b,h5b,p1b,p2b,h4b_1,h5b_1,p1b_1,p2b_1)
      CALL TCE_RESTRICTED_2(h6b,p3b,h6b_2,p3b_2)
      dim_common = 1
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+p1b-1) * int_mb(k_range+p2b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h6b-1) * int_mb(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('lambda_ccsd_t_left_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &lambda_ccsd_t_left_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p2b_1
     & - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab * (h5b_1 - 1 + noab 
     &* (h4b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p1b-1),int_mb(k_range+p2b-1)
     &,4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('lambda_ccsd_t_left_2',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('lambda_ccsd_t_left_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &lambda_ccsd_t_left_2',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (h6b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+p3b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('lambda_ccsd_t_left_2',6,
     &MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('lambda_ccsd_t_left_
     &2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('lambda_ccsd_t_left_
     &2',8,MA_ERR)
      END IF
      END IF
      END IF
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_
     &mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,2,4,3,1,1.0d0)
      END IF
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &2b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_
     &mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,2,1,4,3,1.0d0)
      END IF
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &2b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_
     &mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,2,4,1,3,-1.0d0)
      END IF
      IF ((t_h4b .eq. h6b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_
     &mb(k_range+h5b-1),int_mb(k_range+h4b-1),2,6,5,4,3,1,1.0d0)
      END IF
      IF ((t_h4b .eq. h6b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &2b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_
     &mb(k_range+h5b-1),int_mb(k_range+h4b-1),2,6,5,1,4,3,1.0d0)
      END IF
      IF ((t_h4b .eq. h6b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &2b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_
     &mb(k_range+h5b-1),int_mb(k_range+h4b-1),2,6,5,4,1,3,-1.0d0)
      END IF
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_
     &mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,2,5,4,3,1,-1.0d0)
      END IF
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &2b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_
     &mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,2,5,1,4,3,-1.0d0)
      END IF
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &2b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_
     &mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,2,5,4,1,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('lambda_ccsd_t_left_
     &2',9,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE lambda_ccsd_t_left_3(d_a,k_a_offset,d_b,k_b_offset,a_c,
     &t_h4b,t_h5b,t_h6b,t_p1b,t_p2b,t_p3b)
C     $Id$
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_yv + = -1 * P( 9 ) * Sum ( h7 ) * y ( h4 h7 p1 p2 )_y * v ( h5 h6 h7 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER t_h4b
      INTEGER t_h5b
      INTEGER t_h6b
      INTEGER t_p1b
      INTEGER t_p2b
      INTEGER t_p3b
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h7b
      INTEGER h4b_1
      INTEGER h7b_1
      INTEGER p1b_1
      INTEGER p2b_1
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER p3b_2
      INTEGER h7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      DOUBLE PRECISION a_c(*)
      LOGICAL skipped
      DO h4b = 1,noab
      DO h5b = 1,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO p3b = noab+1,noab+nvab
      skipped = .true.
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) skipped = .false.
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &2b)) skipped = .false.
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &2b)) skipped = .false.
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) skipped = .false.
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &2b)) skipped = .false.
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &2b)) skipped = .false.
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h4b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) skipped = .false.
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h4b)
     & .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &2b)) skipped = .false.
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h4b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &2b)) skipped = .false.
      IF (.not.skipped) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,irrep_v)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('lambda_ccsd_t_left_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h7b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+p2b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+p2b-1)))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_4(h4b,h7b,p1b,p2b,h4b_1,h7b_1,p1b_1,p2b_1)
      CALL TCE_RESTRICTED_4(h5b,h6b,p3b,h7b,h5b_2,h6b_2,p3b_2,h7b_2)
      dim_common = int_mb(k_range+h7b-1)
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+p1b-1) * int_mb
     &(k_range+p2b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb
     &(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('lambda_ccsd_t_left_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &lambda_ccsd_t_left_3',2,MA_ERR)
      IF ((h7b .lt. h4b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p2b_1
     & - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab * (h4b_1 - 1 + noab 
     &* (h7b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h7b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p1b-1),int_mb(k_range+p2b-1)
     &,4,3,2,1,-1.0d0)
      END IF
      IF ((h4b .le. h7b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p2b_1
     & - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab * (h7b_1 - 1 + noab 
     &* (h4b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+p1b-1),int_mb(k_range+p2b-1)
     &,4,3,1,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('lambda_ccsd_t_left_3',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('lambda_ccsd_t_left_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &lambda_ccsd_t_left_3',5,MA_ERR)
      IF ((h7b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (h7b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h5b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('lambda_ccsd_t_left_3',6,
     &MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('lambda_ccsd_t_left_
     &3',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('lambda_ccsd_t_left_
     &3',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h4b-1),6,3,2,5,4,1,-1.0d0)
      END IF
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &2b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h4b-1),6,3,2,1,5,4,-1.0d0)
      END IF
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &2b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h4b-1),6,3,2,5,1,4,1.0d0)
      END IF
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h4b-1),3,6,2,5,4,1,1.0d0)
      END IF
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &2b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h4b-1),3,6,2,1,5,4,1.0d0)
      END IF
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &2b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h4b-1),3,6,2,5,1,4,-1.0d0)
      END IF
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h4b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h4b-1),3,2,6,5,4,1,-1.0d0)
      END IF
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h4b)
     & .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &2b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h4b-1),3,2,6,1,5,4,-1.0d0)
      END IF
      IF ((t_h4b .eq. h5b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h4b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &2b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h4b-1),3,2,6,5,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('lambda_ccsd_t_left_
     &3',9,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE lambda_ccsd_t_left_4(d_a,k_a_offset,d_b,k_b_offset,a_c,
     &t_h4b,t_h5b,t_h6b,t_p1b,t_p2b,t_p3b)
C     $Id$
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_yv + = -1 * P( 9 ) * Sum ( p7 ) * y ( h4 h5 p1 p7 )_y * v ( h6 p7 p2 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER t_h4b
      INTEGER t_h5b
      INTEGER t_h6b
      INTEGER t_p1b
      INTEGER t_p2b
      INTEGER t_p3b
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER h4b_1
      INTEGER h5b_1
      INTEGER p1b_1
      INTEGER p7b_1
      INTEGER h6b_2
      INTEGER p7b_2
      INTEGER p2b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      DOUBLE PRECISION a_c(*)
      LOGICAL skipped
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = 1,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = noab+1,noab+nvab
      DO p3b = p2b,noab+nvab
      skipped = .true.
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) skipped = .false.
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &3b)) skipped = .false.
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &1b)) skipped = .false.
      IF ((t_h4b .eq. h6b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) skipped = .false.
      IF ((t_h4b .eq. h6b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &3b)) skipped = .false.
      IF ((t_h4b .eq. h6b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &1b)) skipped = .false.
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) skipped = .false.
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &3b)) skipped = .false.
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &1b)) skipped = .false.
      IF (.not.skipped) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,irrep_v)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('lambda_ccsd_t_left_4',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+p7b-1)))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_4(h4b,h5b,p1b,p7b,h4b_1,h5b_1,p1b_1,p7b_1)
      CALL TCE_RESTRICTED_4(h6b,p7b,p2b,p3b,h6b_2,p7b_2,p2b_2,p3b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+p1b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h6b-1) * int_mb(k_range+p2b-1) * int_mb
     &(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('lambda_ccsd_t_left_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &lambda_ccsd_t_left_4',2,MA_ERR)
      IF ((p7b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p1b_1
     & - noab - 1 + nvab * (p7b_1 - noab - 1 + nvab * (h5b_1 - 1 + noab 
     &* (h4b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p7b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p1b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p7b_1
     & - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab * (h5b_1 - 1 + noab 
     &* (h4b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p1b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('lambda_ccsd_t_left_4',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('lambda_ccsd_t_left_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &lambda_ccsd_t_left_4',5,MA_ERR)
      IF ((h6b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p2b_2 - 1 + (noab+nvab) * (p7b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+p2b-1),int_mb(k_range+p3b-1)
     &,4,3,1,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('lambda_ccsd_t_left_4',6,
     &MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('lambda_ccsd_t_left_
     &4',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('lambda_ccsd_t_left_
     &4',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1),int_
     &mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,3,4,2,1,-1.0d0)
      END IF
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &3b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1),int_
     &mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,3,2,4,1,1.0d0)
      END IF
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h5b) .and. (t_h6b .eq. h6b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &1b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1),int_
     &mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,3,2,1,4,-1.0d0)
      END IF
      IF ((t_h4b .eq. h6b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1),int_
     &mb(k_range+h5b-1),int_mb(k_range+h4b-1),3,6,5,4,2,1,-1.0d0)
      END IF
      IF ((t_h4b .eq. h6b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &3b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1),int_
     &mb(k_range+h5b-1),int_mb(k_range+h4b-1),3,6,5,2,4,1,1.0d0)
      END IF
      IF ((t_h4b .eq. h6b) .and. (t_h5b .eq. h4b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &1b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1),int_
     &mb(k_range+h5b-1),int_mb(k_range+h4b-1),3,6,5,2,1,4,-1.0d0)
      END IF
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p2b) .and. (t_p3b .eq. p
     &3b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1),int_
     &mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,3,5,4,2,1,1.0d0)
      END IF
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p1b) .and. (t_p3b .eq. p
     &3b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1),int_
     &mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,3,5,2,4,1,-1.0d0)
      END IF
      IF ((t_h4b .eq. h4b) .and. (t_h5b .eq. h6b) .and. (t_h6b .eq. h5b)
     & .and. (t_p1b .eq. p2b) .and. (t_p2b .eq. p3b) .and. (t_p3b .eq. p
     &1b)) THEN
      CALL TCE_SORTACC_6(dbl_mb(k_c_sort),a_c,int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1),int_
     &mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,3,5,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('lambda_ccsd_t_left_
     &4',9,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
