      SUBROUTINE ccsdt2_q_left(a_i0,d_f1,d_i1_2,d_i1_3,d_i1_4,d_t1,d_v2,
     &d_y2,d_y3,k_f1_offset,k_i1_offset_2,k_i1_offset_3,k_i1_offset_4,k_
     &t1_offset,k_v2_offset,k_y2_offset,k_y3_offset,l_i1_offset_2,l_i1_o
     &ffset_3,l_i1_offset_4,t_h5b,t_h6b,t_h7b,t_h8b,t_p1b,t_p2b,t_p3b,t_
     &p4b,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 ( h5 h6 h7 h8 p1 p2 p3 p4 )_yv + = 1 * P( 36 ) * y ( h5 h6 p1 p2 )_y * v ( h7 h8 p3 p4 )_v
C     i0 ( h5 h6 h7 h8 p1 p2 p3 p4 )_yf + = 1 * P( 16 ) * y ( h5 h6 h7 p1 p2 p3 )_y * i1 ( h8 p4 )_f
C         i1 ( h5 p1 )_f + = 1 * f ( h5 p1 )_f
C         i1 ( h5 p1 )_vt + = 1 * Sum ( h10 p9 ) * t ( p9 h10 )_t * v ( h5 h10 p1 p9 )_v
C     i0 ( h5 h6 h7 h8 p1 p2 p3 p4 )_yv + = -1 * P( 24 ) * Sum ( h11 ) * y ( h5 h6 h11 p1 p2 p3 )_y * i1 ( h7 h8 h11 p4 )_v
C         i1 ( h5 h6 h11 p1 )_v + = 1 * v ( h5 h6 h11 p1 )_v
C         i1 ( h5 h6 h11 p1 )_vt + = -1 * Sum ( p9 ) * t ( p9 h11 )_t * v ( h5 h6 p1 p9 )_v
C     i0 ( h5 h6 h7 h8 p1 p2 p3 p4 )_yv + = -1 * P( 24 ) * Sum ( p9 ) * y ( h5 h6 h7 p1 p2 p9 )_y * i1 ( h8 p9 p3 p4 )_v
C         i1 ( h5 p9 p1 p2 )_v + = 1 * v ( h5 p9 p1 p2 )_v
C         i1 ( h5 p9 p1 p2 )_vt + = -1 * Sum ( h10 ) * t ( p9 h10 )_t * v ( h5 h10 p1 p2 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "util.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER t_h5b
      INTEGER t_h6b
      INTEGER t_h7b
      INTEGER t_h8b
      INTEGER t_p1b
      INTEGER t_p2b
      INTEGER t_p3b
      INTEGER t_p4b
      INTEGER toggle
      INTEGER d_y2
      INTEGER k_y2_offset
      INTEGER d_v2
      INTEGER k_v2_offset
      INTEGER d_y3
      INTEGER k_y3_offset
      INTEGER d_i1_2
      INTEGER k_i1_offset_2
      INTEGER l_i1_offset_2
      INTEGER d_i1_3
      INTEGER k_i1_offset_3
      INTEGER l_i1_offset_3
      INTEGER d_i1_4
      INTEGER k_i1_offset_4
      INTEGER l_i1_offset_4
      INTEGER d_f1
      INTEGER k_f1_offset
      INTEGER size_i1_2
      INTEGER d_t1
      INTEGER k_t1_offset
      INTEGER size_i1_3
      INTEGER size_i1_4
      DOUBLE PRECISION a_i0(*)
      CHARACTER*255 filename
      IF (toggle .eq. 3) THEN
      CALL DELETEFILE(d_i1_4)
      IF (.not.MA_POP_STACK(l_i1_offset_4)) CALL ERRQUIT('ccsdt2_q_left'
     &,-1,MA_ERR)
      END IF
      IF (toggle .eq. 3) THEN
      CALL DELETEFILE(d_i1_3)
      IF (.not.MA_POP_STACK(l_i1_offset_3)) CALL ERRQUIT('ccsdt2_q_left'
     &,-1,MA_ERR)
      END IF
      IF (toggle .eq. 3) THEN
      CALL DELETEFILE(d_i1_2)
      IF (.not.MA_POP_STACK(l_i1_offset_2)) CALL ERRQUIT('ccsdt2_q_left'
     &,-1,MA_ERR)
      END IF
      IF (toggle .eq. 2) CALL ccsdt2_q_left_1(d_y2,k_y2_offset,d_v2,k_v2
     &_offset,a_i0,t_h5b,t_h6b,t_h7b,t_h8b,t_p1b,t_p2b,t_p3b,t_p4b)
      IF (toggle .eq. 1) CALL OFFSET_ccsdt2_q_left_2_1(l_i1_offset_2,k_i
     &1_offset_2,size_i1_2)
      IF (toggle .eq. 1) CALL TCE_FILENAME('ccsdt2_q_left_2_1_i1',filena
     &me)
      IF (toggle .eq. 1) CALL CREATEFILE(filename,d_i1_2,size_i1_2)
      IF (toggle .eq. 1) CALL ccsdt2_q_left_2_1(d_f1,k_f1_offset,d_i1_2,
     &k_i1_offset_2)
      IF (toggle .eq. 1) CALL ccsdt2_q_left_2_2(d_t1,k_t1_offset,d_v2,k_
     &v2_offset,d_i1_2,k_i1_offset_2)
      IF (toggle .eq. 1) CALL RECONCILEFILE(d_i1_2,size_i1_2)
      IF (toggle .eq. 2) CALL ccsdt2_q_left_2(d_y3,k_y3_offset,d_i1_2,k_
     &i1_offset_2,a_i0,t_h5b,t_h6b,t_h7b,t_h8b,t_p1b,t_p2b,t_p3b,t_p4b)
      IF (toggle .eq. 1) CALL OFFSET_ccsdt2_q_left_3_1(l_i1_offset_3,k_i
     &1_offset_3,size_i1_3)
      IF (toggle .eq. 1) CALL TCE_FILENAME('ccsdt2_q_left_3_1_i1',filena
     &me)
      IF (toggle .eq. 1) CALL CREATEFILE(filename,d_i1_3,size_i1_3)
      IF (toggle .eq. 1) CALL ccsdt2_q_left_3_1(d_v2,k_v2_offset,d_i1_3,
     &k_i1_offset_3)
      IF (toggle .eq. 1) CALL ccsdt2_q_left_3_2(d_t1,k_t1_offset,d_v2,k_
     &v2_offset,d_i1_3,k_i1_offset_3)
      IF (toggle .eq. 1) CALL RECONCILEFILE(d_i1_3,size_i1_3)
      IF (toggle .eq. 2) CALL ccsdt2_q_left_3(d_y3,k_y3_offset,d_i1_3,k_
     &i1_offset_3,a_i0,t_h5b,t_h6b,t_h7b,t_h8b,t_p1b,t_p2b,t_p3b,t_p4b)
      IF (toggle .eq. 1) CALL OFFSET_ccsdt2_q_left_4_1(l_i1_offset_4,k_i
     &1_offset_4,size_i1_4)
      IF (toggle .eq. 1) CALL TCE_FILENAME('ccsdt2_q_left_4_1_i1',filena
     &me)
      IF (toggle .eq. 1) CALL CREATEFILE(filename,d_i1_4,size_i1_4)
      IF (toggle .eq. 1) CALL ccsdt2_q_left_4_1(d_v2,k_v2_offset,d_i1_4,
     &k_i1_offset_4)
      IF (toggle .eq. 1) CALL ccsdt2_q_left_4_2(d_t1,k_t1_offset,d_v2,k_
     &v2_offset,d_i1_4,k_i1_offset_4)
      IF (toggle .eq. 1) CALL RECONCILEFILE(d_i1_4,size_i1_4)
      IF (toggle .eq. 2) CALL ccsdt2_q_left_4(d_y3,k_y3_offset,d_i1_4,k_
     &i1_offset_4,a_i0,t_h5b,t_h6b,t_h7b,t_h8b,t_p1b,t_p2b,t_p3b,t_p4b)
      RETURN
      END
      SUBROUTINE ccsdt2_q_left_1(d_a,k_a_offset,d_b,k_b_offset,a_c,t_h5b
     &,t_h6b,t_h7b,t_h8b,t_p1b,t_p2b,t_p3b,t_p4b)
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 ( h5 h6 h7 h8 p1 p2 p3 p4 )_yv + = 1 * P( 36 ) * y ( h5 h6 p1 p2 )_y * v ( h7 h8 p3 p4 )_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_h5b
      INTEGER t_h6b
      INTEGER t_h7b
      INTEGER t_h8b
      INTEGER t_p1b
      INTEGER t_p2b
      INTEGER t_p3b
      INTEGER t_p4b
      INTEGER h5b
      INTEGER h6b
      INTEGER h7b
      INTEGER h8b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER p4b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h5b_1
      INTEGER h6b_1
      INTEGER p1b_1
      INTEGER p2b_1
      INTEGER h7b_2
      INTEGER h8b_2
      INTEGER p3b_2
      INTEGER p4b_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 h5b = 1,noab
      DO h6b = h5b,noab
      DO h7b = 1,noab
      DO h8b = h7b,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO p3b = noab+1,noab+nvab
      DO p4b = p3b,noab+nvab
      skipped = .true.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF (.not.skipped) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h7b-1)+int_mb(k_spin+h8b-1)+int_mb(k_spin+p1b-1)+i
     &nt_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-1)+int_mb(k_spin+p4b-1).ne.1
     &6)) THEN
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h7b-1)
     &+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-
     &1)+int_mb(k_spin+p3b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h7b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(k_sym+p1b-1),ieo
     &r(int_mb(k_sym+p2b-1),ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+p4b-1)
     &))))))) .eq. ieor(irrep_y,irrep_v)) THEN
      dimc = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb(k_ra
     &nge+h7b-1) * int_mb(k_range+h8b-1) * int_mb(k_range+p1b-1) * int_m
     &b(k_range+p2b-1) * int_mb(k_range+p3b-1) * int_mb(k_range+p4b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt2_q_left_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+p2b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+p2b-1)))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_4(h5b,h6b,p1b,p2b,h5b_1,h6b_1,p1b_1,p2b_1)
      CALL TCE_RESTRICTED_4(h7b,h8b,p3b,p4b,h7b_2,h8b_2,p3b_2,p4b_2)
      dim_common = 1
      dima_sort = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb
     &(k_range+p1b-1) * int_mb(k_range+p2b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h7b-1) * int_mb(k_range+h8b-1) * int_mb
     &(k_range+p3b-1) * int_mb(k_range+p4b-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('ccsdt2_q_left_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt2_q_left_1',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 * (h6b_1 - 1 + noab 
     &* (h5b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h6b-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('ccsdt2_q_left_1',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt2_q_left_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt2_q_left_1',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p4b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h7b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h7b-1)
     &,int_mb(k_range+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p4b-1)
     &,4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt2_q_left_1',6,MA_ER
     &R)
      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('ccsdt2_q_left_1',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt2_q_left_1',8,
     &MA_ERR)
      END IF
      END IF
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,4,3,6,5,2,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,4,3,2,6,5,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,4,3,2,6,1,5,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,4,3,6,2,5,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,4,3,6,2,1,5,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,4,3,2,1,6,5,1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),4,8,7,3,6,5,2,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),4,8,7,3,2,6,5,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),4,8,7,3,2,6,1,5,-1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),4,8,7,3,6,2,5,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),4,8,7,3,6,2,1,5,1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),4,8,7,3,2,1,6,5,1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),4,8,3,7,6,5,2,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),4,8,3,7,2,6,5,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),4,8,3,7,2,6,1,5,1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),4,8,3,7,6,2,5,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),4,8,3,7,6,2,1,5,-1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),4,8,3,7,2,1,6,5,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,4,7,3,6,5,2,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,4,7,3,2,6,5,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,4,7,3,2,6,1,5,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,4,7,3,6,2,5,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,4,7,3,6,2,1,5,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,4,7,3,2,1,6,5,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,4,3,7,6,5,2,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,4,3,7,2,6,5,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,4,3,7,2,6,1,5,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,4,3,7,6,2,5,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,4,3,7,6,2,1,5,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,4,3,7,2,1,6,5,1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),4,3,8,7,6,5,2,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),4,3,8,7,2,6,5,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),4,3,8,7,2,6,1,5,-1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),4,3,8,7,6,2,5,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),4,3,8,7,6,2,1,5,1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),4,3,8,7,2,1,6,5,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt2_q_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
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt2_q_left_2(d_a,k_a_offset,d_b,k_b_offset,a_c,t_h5b
     &,t_h6b,t_h7b,t_h8b,t_p1b,t_p2b,t_p3b,t_p4b)
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 ( h5 h6 h7 h8 p1 p2 p3 p4 )_yf + = 1 * P( 16 ) * y ( h5 h6 h7 p1 p2 p3 )_y * i1 ( h8 p4 )_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_h5b
      INTEGER t_h6b
      INTEGER t_h7b
      INTEGER t_h8b
      INTEGER t_p1b
      INTEGER t_p2b
      INTEGER t_p3b
      INTEGER t_p4b
      INTEGER h5b
      INTEGER h6b
      INTEGER h7b
      INTEGER h8b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER p4b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h5b_1
      INTEGER h6b_1
      INTEGER h7b_1
      INTEGER p1b_1
      INTEGER p2b_1
      INTEGER p3b_1
      INTEGER h8b_2
      INTEGER p4b_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 h5b = 1,noab
      DO h6b = h5b,noab
      DO h7b = h6b,noab
      DO h8b = 1,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO p3b = p2b,noab+nvab
      DO p4b = noab+1,noab+nvab
      skipped = .true.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF (.not.skipped) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h7b-1)+int_mb(k_spin+h8b-1)+int_mb(k_spin+p1b-1)+i
     &nt_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-1)+int_mb(k_spin+p4b-1).ne.1
     &6)) THEN
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h7b-1)
     &+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-
     &1)+int_mb(k_spin+p3b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h7b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(k_sym+p1b-1),ieo
     &r(int_mb(k_sym+p2b-1),ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+p4b-1)
     &))))))) .eq. ieor(irrep_y,irrep_f)) THEN
      dimc = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb(k_ra
     &nge+h7b-1) * int_mb(k_range+h8b-1) * int_mb(k_range+p1b-1) * int_m
     &b(k_range+p2b-1) * int_mb(k_range+p3b-1) * int_mb(k_range+p4b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt2_q_left_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h7b-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+h5b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h7b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_6(h5b,h6b,h7b,p1b,p2b,p3b,h5b_1,h6b_1,h7b_1,p1
     &b_1,p2b_1,p3b_1)
      CALL TCE_RESTRICTED_2(h8b,p4b,h8b_2,p4b_2)
      dim_common = 1
      dima_sort = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb
     &(k_range+h7b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * 
     &int_mb(k_range+p3b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h8b-1) * int_mb(k_range+p4b-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('ccsdt2_q_left_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt2_q_left_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p3b_1
     & - noab - 1 + nvab * (p2b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h7b_1 - 1 + noab * (h6b_1 - 1 + noab * (h5b_1 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h7b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p3b-1),6,5,4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt2_q_left_2',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt2_q_left_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt2_q_left_2',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p4b_2
     & - noab - 1 + nvab * (h8b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+p4b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt2_q_left_2',6,MA_ER
     &R)
      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('ccsdt2_q_left_2',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt2_q_left_2',8,
     &MA_ERR)
      END IF
      END IF
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,6,2,5,4,3,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,6,2,1,5,4,3,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,6,2,5,1,4,3,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,6,2,5,4,1,3,-1.0d0)
      END IF
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),2,8,7,6,5,4,3,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),2,8,7,6,1,5,4,3,1.0d0)
      END IF
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),2,8,7,6,5,1,4,3,-1.0d0)
      END IF
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),2,8,7,6,5,4,1,3,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,2,7,6,5,4,3,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,2,7,6,1,5,4,3,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,2,7,6,5,1,4,3,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,2,7,6,5,4,1,3,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,2,6,5,4,3,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,2,6,1,5,4,3,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,2,6,5,1,4,3,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,2,6,5,4,1,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt2_q_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
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt2_q_left_2_1(d_a,k_a_offset,d_c,k_c_offset)
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     i1 ( h5 p1 )_f + = 1 * f ( h5 p1 )_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_c
      INTEGER k_c_offset
      INTEGER nxtask
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h5b
      INTEGER p1b
      INTEGER dimc
      INTEGER h5b_1
      INTEGER p1b_1
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_c
      INTEGER k_c
      EXTERNAL nxtask
      nprocs = GA_NNODES()
      count = 0
      next = nxtask(nprocs,1)
      DO h5b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),int_mb(k_sym+p1b-1)) .eq. irrep_f) TH
     &EN
      dimc = int_mb(k_range+h5b-1) * int_mb(k_range+p1b-1)
      CALL TCE_RESTRICTED_2(h5b,p1b,h5b_1,p1b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h5b-1) * int_mb(k_range+p1b-1)
      dima = dim_common * dima_sort
      IF (dima .gt. 0) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt2_q_left_2_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt2_q_left_2_1',1,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p1b_1
     & - 1 + (noab+nvab) * (h5b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+p1b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt2_q_left_2_1',2,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt2_q_left_2_1',3,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (h5b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt2_q_left_2_1',4,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt2_q_left_2_1',
     &5,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = nxtask(nprocs,1)
      END IF
      count = count + 1
      END DO
      END DO
      next = nxtask(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt2_q_left_2_1(l_a_offset,k_a_offset,size)
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     i1 ( h5 p1 )_f
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h5b
      INTEGER p1b
      length = 0
      DO h5b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),int_mb(k_sym+p1b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt2_q_left_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h5b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),int_mb(k_sym+p1b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p1b - noab - 1 + nvab * (h5b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h5b-1) * int_mb(k_range+p1b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt2_q_left_2_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
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     i1 ( h5 p1 )_vt + = 1 * Sum ( h10 p9 ) * t ( p9 h10 )_t * v ( h5 h10 p1 p9 )_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 d_c
      INTEGER k_c_offset
      INTEGER nxtask
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h5b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p9b
      INTEGER h10b
      INTEGER p9b_1
      INTEGER h10b_1
      INTEGER h5b_2
      INTEGER h10b_2
      INTEGER p1b_2
      INTEGER p9b_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
      INTEGER l_c
      INTEGER k_c
      EXTERNAL nxtask
      nprocs = GA_NNODES()
      count = 0
      next = nxtask(nprocs,1)
      DO h5b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      dimc = int_mb(k_range+h5b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt2_q_left_2_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p9b = noab+1,noab+nvab
      DO h10b = 1,noab
      IF (int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),int_mb(k_sym+h10b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p9b,h10b,p9b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h5b,h10b,p1b,p9b,h5b_2,h10b_2,p1b_2,p9b_2)
      dim_common = int_mb(k_range+p9b-1) * int_mb(k_range+h10b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h5b-1) * int_mb(k_range+p1b-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('ccsdt2_q_left_2_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt2_q_left_2_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (p9b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt2_q_left_2_2',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt2_q_left_2_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt2_q_left_2_2',5,MA_ERR)
      IF ((h10b .lt. h5b) .and. (p9b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p9b_2 - 1 + (noab+nvab) * (h5b_2 - 1 + (noab
     &+nvab) * (h10b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h10b-1
     &),int_mb(k_range+h5b-1),int_mb(k_range+p9b-1),int_mb(k_range+p1b-1
     &),4,2,1,3,1.0d0)
      END IF
      IF ((h10b .lt. h5b) .and. (p1b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p9b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h5b_2 - 1 + (noab
     &+nvab) * (h10b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h10b-1
     &),int_mb(k_range+h5b-1),int_mb(k_range+p1b-1),int_mb(k_range+p9b-1
     &),3,2,1,4,-1.0d0)
      END IF
      IF ((h5b .le. h10b) .and. (p9b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p9b_2 - 1 + (noab+nvab) * (h10b_2 - 1 + (noa
     &b+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+h10b-1),int_mb(k_range+p9b-1),int_mb(k_range+p1b-1
     &),4,1,2,3,-1.0d0)
      END IF
      IF ((h5b .le. h10b) .and. (p1b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p9b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h10b_2 - 1 + (noa
     &b+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+h10b-1),int_mb(k_range+p1b-1),int_mb(k_range+p9b-1
     &),3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt2_q_left_2_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('ccsdt2_q_left_2_2',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt2_q_left_2_2',
     &8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt2_q_left_2_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (h5b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt2_q_left_2_2',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt2_q_left_2_2',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = nxtask(nprocs,1)
      END IF
      count = count + 1
      END DO
      END DO
      next = nxtask(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt2_q_left_3(d_a,k_a_offset,d_b,k_b_offset,a_c,t_h5b
     &,t_h6b,t_h7b,t_h8b,t_p1b,t_p2b,t_p3b,t_p4b)
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 ( h5 h6 h7 h8 p1 p2 p3 p4 )_yv + = -1 * P( 24 ) * Sum ( h11 ) * y ( h5 h6 h11 p1 p2 p3 )_y * i1 ( h7 h8 h11 p4 )_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_h5b
      INTEGER t_h6b
      INTEGER t_h7b
      INTEGER t_h8b
      INTEGER t_p1b
      INTEGER t_p2b
      INTEGER t_p3b
      INTEGER t_p4b
      INTEGER h5b
      INTEGER h6b
      INTEGER h7b
      INTEGER h8b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER p4b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h11b
      INTEGER h5b_1
      INTEGER h6b_1
      INTEGER h11b_1
      INTEGER p1b_1
      INTEGER p2b_1
      INTEGER p3b_1
      INTEGER h7b_2
      INTEGER h8b_2
      INTEGER p4b_2
      INTEGER h11b_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 h5b = 1,noab
      DO h6b = h5b,noab
      DO h7b = 1,noab
      DO h8b = h7b,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO p3b = p2b,noab+nvab
      DO p4b = noab+1,noab+nvab
      skipped = .true.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) skipped = .fals
     &e.
      IF (.not.skipped) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h7b-1)+int_mb(k_spin+h8b-1)+int_mb(k_spin+p1b-1)+i
     &nt_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-1)+int_mb(k_spin+p4b-1).ne.1
     &6)) THEN
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h7b-1)
     &+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-
     &1)+int_mb(k_spin+p3b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h7b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(k_sym+p1b-1),ieo
     &r(int_mb(k_sym+p2b-1),ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+p4b-1)
     &))))))) .eq. ieor(irrep_y,irrep_v)) THEN
      dimc = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb(k_ra
     &nge+h7b-1) * int_mb(k_range+h8b-1) * int_mb(k_range+p1b-1) * int_m
     &b(k_range+p2b-1) * int_mb(k_range+p3b-1) * int_mb(k_range+p4b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt2_q_left_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h11b = 1,noab
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h11b-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+h5b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h11b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),in
     &t_mb(k_sym+p3b-1)))))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_6(h5b,h6b,h11b,p1b,p2b,p3b,h5b_1,h6b_1,h11b_1,
     &p1b_1,p2b_1,p3b_1)
      CALL TCE_RESTRICTED_4(h7b,h8b,p4b,h11b,h7b_2,h8b_2,p4b_2,h11b_2)
      dim_common = int_mb(k_range+h11b-1)
      dima_sort = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb
     &(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_mb(k_range+p3b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h7b-1) * int_mb(k_range+h8b-1) * int_mb
     &(k_range+p4b-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('ccsdt2_q_left_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt2_q_left_3',2,MA_ERR)
      IF ((h11b .lt. h5b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p3b_1
     & - noab - 1 + nvab * (p2b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h6b_1 - 1 + noab * (h5b_1 - 1 + noab * (h11b_1 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h11b-1
     &),int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1
     &),int_mb(k_range+p2b-1),int_mb(k_range+p3b-1),6,5,4,3,2,1,1.0d0)
      END IF
      IF ((h5b .le. h11b) .and. (h11b .lt. h6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p3b_1
     & - noab - 1 + nvab * (p2b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h6b_1 - 1 + noab * (h11b_1 - 1 + noab * (h5b_1 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h11b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1
     &),int_mb(k_range+p2b-1),int_mb(k_range+p3b-1),6,5,4,3,1,2,-1.0d0)
      END IF
      IF ((h6b .le. h11b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p3b_1
     & - noab - 1 + nvab * (p2b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h11b_1 - 1 + noab * (h6b_1 - 1 + noab * (h5b_1 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h11b-1),int_mb(k_range+p1b-1
     &),int_mb(k_range+p2b-1),int_mb(k_range+p3b-1),6,5,4,2,1,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt2_q_left_3',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt2_q_left_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt2_q_left_3',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h11b_
     &2 - 1 + noab * (p4b_2 - noab - 1 + nvab * (h8b_2 - 1 + noab * (h7b
     &_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h7b-1)
     &,int_mb(k_range+h8b-1),int_mb(k_range+p4b-1),int_mb(k_range+h11b-1
     &),3,2,1,4,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt2_q_left_3',6,MA_ER
     &R)
      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('ccsdt2_q_left_3',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt2_q_left_3',8,
     &MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,3,2,6,5,4,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,3,2,1,6,5,4,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,3,2,6,1,5,4,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,3,2,6,5,1,4,1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),3,8,7,2,6,5,4,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),3,8,7,2,1,6,5,4,1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),3,8,7,2,6,1,5,4,-1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),3,8,7,2,6,5,1,4,1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),3,8,2,7,6,5,4,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),3,8,2,7,1,6,5,4,-1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),3,8,2,7,6,1,5,4,1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),3,8,2,7,6,5,1,4,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,3,7,2,6,5,4,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,3,7,2,1,6,5,4,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,3,7,2,6,1,5,4,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,3,7,2,6,5,1,4,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,3,2,7,6,5,4,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,3,2,7,1,6,5,4,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,3,2,7,6,1,5,4,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h7b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,3,2,7,6,5,1,4,1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),3,2,8,7,6,5,4,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p4b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),3,2,8,7,1,6,5,4,1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),3,2,8,7,6,1,5,4,-1.0d0)
      END IF
      IF ((t_h5b .eq. h7b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h5b)
     & .and. (t_h8b .eq. h6b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p3b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_
     &mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),3,2,8,7,6,5,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt2_q_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
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt2_q_left_3_1(d_a,k_a_offset,d_c,k_c_offset)
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     i1 ( h5 h6 h11 p1 )_v + = 1 * v ( h5 h6 h11 p1 )_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_c
      INTEGER k_c_offset
      INTEGER nxtask
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER h11b
      INTEGER dimc
      INTEGER h5b_1
      INTEGER h6b_1
      INTEGER p1b_1
      INTEGER h11b_1
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_c
      INTEGER k_c
      EXTERNAL nxtask
      nprocs = GA_NNODES()
      count = 0
      next = nxtask(nprocs,1)
      DO h5b = 1,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO h11b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+h11b-1)))) .eq. irrep_v) THEN
      dimc = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb(k_ra
     &nge+p1b-1) * int_mb(k_range+h11b-1)
      CALL TCE_RESTRICTED_4(h5b,h6b,p1b,h11b,h5b_1,h6b_1,p1b_1,h11b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb
     &(k_range+p1b-1) * int_mb(k_range+h11b-1)
      dima = dim_common * dima_sort
      IF (dima .gt. 0) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt2_q_left_3_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt2_q_left_3_1',1,MA_ERR)
      IF ((h11b .le. p1b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p1b_1
     & - 1 + (noab+nvab) * (h11b_1 - 1 + (noab+nvab) * (h6b_1 - 1 + (noa
     &b+nvab) * (h5b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h11b-1),int_mb(k_range+p1b-1
     &),3,4,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt2_q_left_3_1',2,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt2_q_left_3_1',3,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+h11b-1
     &),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1
     &),4,3,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (p1b - noab - 1 + nvab * (h6b - 1 + noab * (h5b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt2_q_left_3_1',4,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt2_q_left_3_1',
     &5,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = nxtask(nprocs,1)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = nxtask(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt2_q_left_3_1(l_a_offset,k_a_offset,size)
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     i1 ( h5 h6 h11 p1 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER h11b
      length = 0
      DO h5b = 1,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO h11b = 1,noab
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p1b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p1b-1).ne.8)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt2_q_left_3_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h5b = 1,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO h11b = 1,noab
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p1b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p1b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h11b - 1 + noab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_
     &mb(k_range+p1b-1) * int_mb(k_range+h11b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt2_q_left_3_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
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     i1 ( h5 h6 h11 p1 )_vt + = -1 * Sum ( p9 ) * t ( p9 h11 )_t * v ( h5 h6 p1 p9 )_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 d_c
      INTEGER k_c_offset
      INTEGER nxtask
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p9b
      INTEGER p9b_1
      INTEGER h11b_1
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER p1b_2
      INTEGER p9b_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
      INTEGER l_c
      INTEGER k_c
      EXTERNAL nxtask
      nprocs = GA_NNODES()
      count = 0
      next = nxtask(nprocs,1)
      DO h5b = 1,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO h11b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,irrep_t)) T
     &HEN
      dimc = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb(k_ra
     &nge+p1b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt2_q_left_3_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p9b = noab+1,noab+nvab
      IF (int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),int_mb(k_sym+h11b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p9b,h11b,p9b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h5b,h6b,p1b,p9b,h5b_2,h6b_2,p1b_2,p9b_2)
      dim_common = int_mb(k_range+p9b-1)
      dima_sort = int_mb(k_range+h11b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb
     &(k_range+p1b-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('ccsdt2_q_left_3_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt2_q_left_3_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (p9b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+h11b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt2_q_left_3_2',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt2_q_left_3_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt2_q_left_3_2',5,MA_ERR)
      IF ((p9b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p9b_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+p9b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p1b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p9b_2
     & - 1 + (noab+nvab) * (p1b_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+p1b-1),int_mb(k_range+p9b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt2_q_left_3_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('ccsdt2_q_left_3_2',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt2_q_left_3_2',
     &8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt2_q_left_3_2',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+h11b-1
     &),3,2,1,4,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (p1b - noab - 1 + nvab * (h6b - 1 + noab * (h5b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt2_q_left_3_2',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt2_q_left_3_2',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = nxtask(nprocs,1)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = nxtask(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt2_q_left_4(d_a,k_a_offset,d_b,k_b_offset,a_c,t_h5b
     &,t_h6b,t_h7b,t_h8b,t_p1b,t_p2b,t_p3b,t_p4b)
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 ( h5 h6 h7 h8 p1 p2 p3 p4 )_yv + = -1 * P( 24 ) * Sum ( p9 ) * y ( h5 h6 h7 p1 p2 p9 )_y * i1 ( h8 p9 p3 p4 )_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_h5b
      INTEGER t_h6b
      INTEGER t_h7b
      INTEGER t_h8b
      INTEGER t_p1b
      INTEGER t_p2b
      INTEGER t_p3b
      INTEGER t_p4b
      INTEGER h5b
      INTEGER h6b
      INTEGER h7b
      INTEGER h8b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER p4b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p9b
      INTEGER h5b_1
      INTEGER h6b_1
      INTEGER h7b_1
      INTEGER p1b_1
      INTEGER p2b_1
      INTEGER p9b_1
      INTEGER h8b_2
      INTEGER p9b_2
      INTEGER p3b_2
      INTEGER p4b_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 h5b = 1,noab
      DO h6b = h5b,noab
      DO h7b = h6b,noab
      DO h8b = 1,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO p3b = noab+1,noab+nvab
      DO p4b = p3b,noab+nvab
      skipped = .true.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) skipped = .fals
     &e.
      IF (.not.skipped) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h7b-1)+int_mb(k_spin+h8b-1)+int_mb(k_spin+p1b-1)+i
     &nt_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-1)+int_mb(k_spin+p4b-1).ne.1
     &6)) THEN
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h7b-1)
     &+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-
     &1)+int_mb(k_spin+p3b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h7b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(k_sym+p1b-1),ieo
     &r(int_mb(k_sym+p2b-1),ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+p4b-1)
     &))))))) .eq. ieor(irrep_y,irrep_v)) THEN
      dimc = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb(k_ra
     &nge+h7b-1) * int_mb(k_range+h8b-1) * int_mb(k_range+p1b-1) * int_m
     &b(k_range+p2b-1) * int_mb(k_range+p3b-1) * int_mb(k_range+p4b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt2_q_left_4',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p9b = noab+1,noab+nvab
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h7b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p9b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h7b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p9b-1)))))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_6(h5b,h6b,h7b,p1b,p2b,p9b,h5b_1,h6b_1,h7b_1,p1
     &b_1,p2b_1,p9b_1)
      CALL TCE_RESTRICTED_4(h8b,p9b,p3b,p4b,h8b_2,p9b_2,p3b_2,p4b_2)
      dim_common = int_mb(k_range+p9b-1)
      dima_sort = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb
     &(k_range+h7b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h8b-1) * int_mb(k_range+p3b-1) * int_mb
     &(k_range+p4b-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('ccsdt2_q_left_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt2_q_left_4',2,MA_ERR)
      IF ((p9b .lt. p1b)) 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 * (p9b_1 - noab - 1 
     &+ nvab * (h7b_1 - 1 + noab * (h6b_1 - 1 + noab * (h5b_1 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h7b-1),int_mb(k_range+p9b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+p2b-1),6,5,3,2,1,4,1.0d0)
      END IF
      IF ((p1b .le. p9b) .and. (p9b .lt. p2b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p2b_1
     & - noab - 1 + nvab * (p9b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h7b_1 - 1 + noab * (h6b_1 - 1 + noab * (h5b_1 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h7b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+p2b-1),6,4,3,2,1,5,-1.0d0)
      END IF
      IF ((p2b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p9b_1
     & - noab - 1 + nvab * (p2b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h7b_1 - 1 + noab * (h6b_1 - 1 + noab * (h5b_1 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h7b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p9b-1),5,4,3,2,1,6,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt2_q_left_4',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt2_q_left_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt2_q_left_4',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p4b_2
     & - noab - 1 + nvab * (p3b_2 - noab - 1 + nvab * (p9b_2 - noab - 1 
     &+ nvab * (h8b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+p3b-1),int_mb(k_range+p4b-1)
     &,4,3,1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt2_q_left_4',6,MA_ER
     &R)
      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('ccsdt2_q_left_4',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt2_q_left_4',8,
     &MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,6,3,5,4,2,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,6,3,2,5,4,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,6,3,2,5,1,4,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,6,3,5,2,4,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,6,3,5,2,1,4,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h7b)
     & .and. (t_h8b .eq. h8b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,6,3,2,1,5,4,-1.0d0)
      END IF
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),3,8,7,6,5,4,2,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),3,8,7,6,2,5,4,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),3,8,7,6,2,5,1,4,-1.0d0)
      END IF
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),3,8,7,6,5,2,4,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),3,8,7,6,5,2,1,4,1.0d0)
      END IF
      IF ((t_h5b .eq. h8b) .and. (t_h6b .eq. h5b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),3,8,7,6,2,1,5,4,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,3,7,6,5,4,2,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,3,7,6,2,5,4,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,3,7,6,2,5,1,4,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,3,7,6,5,2,4,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,3,7,6,5,2,1,4,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h8b) .and. (t_h7b .eq. h6b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,3,7,6,2,1,5,4,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &2b) .and. (t_p3b .eq. p3b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,3,6,5,4,2,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,3,6,2,5,4,1,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &1b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,3,6,2,5,1,4,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p2b) .and. (t_p4b .eq. p4b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,3,6,5,2,4,1,-1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p1b) .and. (t_p2b .eq. p
     &3b) .and. (t_p3b .eq. p4b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,3,6,5,2,1,4,1.0d0)
      END IF
      IF ((t_h5b .eq. h5b) .and. (t_h6b .eq. h6b) .and. (t_h7b .eq. h8b)
     & .and. (t_h8b .eq. h7b) .and. (t_p1b .eq. p3b) .and. (t_p2b .eq. p
     &4b) .and. (t_p3b .eq. p1b) .and. (t_p4b .eq. p2b)) THEN
      CALL TCE_SORTACC_8(dbl_mb(k_c_sort),a_c,int_mb(k_range+p4b-1),int_
     &mb(k_range+p3b-1),int_mb(k_range+h8b-1),int_mb(k_range+p2b-1),int_
     &mb(k_range+p1b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_
     &mb(k_range+h5b-1),8,7,3,6,2,1,5,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt2_q_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
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt2_q_left_4_1(d_a,k_a_offset,d_c,k_c_offset)
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     i1 ( h5 p9 p1 p2 )_v + = 1 * v ( h5 p9 p1 p2 )_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_c
      INTEGER k_c_offset
      INTEGER nxtask
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h5b
      INTEGER p9b
      INTEGER p1b
      INTEGER p2b
      INTEGER dimc
      INTEGER h5b_1
      INTEGER p9b_1
      INTEGER p1b_1
      INTEGER p2b_1
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_c
      INTEGER k_c
      EXTERNAL nxtask
      nprocs = GA_NNODES()
      count = 0
      next = nxtask(nprocs,1)
      DO h5b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1).ne.8)) THEN
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+p2b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+p2b-1)))) .eq. irrep_v) THEN
      dimc = int_mb(k_range+h5b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+p1b-1) * int_mb(k_range+p2b-1)
      CALL TCE_RESTRICTED_4(h5b,p9b,p1b,p2b,h5b_1,p9b_1,p1b_1,p2b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h5b-1) * int_mb(k_range+p9b-1) * int_mb
     &(k_range+p1b-1) * int_mb(k_range+p2b-1)
      dima = dim_common * dima_sort
      IF (dima .gt. 0) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt2_q_left_4_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt2_q_left_4_1',1,MA_ERR)
      IF ((h5b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p2b_1
     & - 1 + (noab+nvab) * (p1b_1 - 1 + (noab+nvab) * (p9b_1 - 1 + (noab
     &+nvab) * (h5b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+p1b-1),int_mb(k_range+p2b-1)
     &,4,3,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt2_q_left_4_1',2,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt2_q_left_4_1',3,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+p9b-1),int_mb(k_range+h5b-1)
     &,4,3,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p9b - noab - 1 + nvab
     & * (h5b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt2_q_left_4_1',4,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt2_q_left_4_1',
     &5,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = nxtask(nprocs,1)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = nxtask(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt2_q_left_4_1(l_a_offset,k_a_offset,size)
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     i1 ( h5 p9 p1 p2 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h5b
      INTEGER p9b
      INTEGER p1b
      INTEGER p2b
      length = 0
      DO h5b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+p2b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+p2b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1).ne.8)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt2_q_left_4_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h5b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+p2b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+p2b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p2b - noab - 1 + nvab * (p1b - noab - 1 
     &+ nvab * (p9b - noab - 1 + nvab * (h5b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h5b-1) * int_mb(k_range+p9b-1) * int_
     &mb(k_range+p1b-1) * int_mb(k_range+p2b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt2_q_left_4_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
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     i1 ( h5 p9 p1 p2 )_vt + = -1 * Sum ( h10 ) * t ( p9 h10 )_t * v ( h5 h10 p1 p2 )_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 d_c
      INTEGER k_c_offset
      INTEGER nxtask
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h5b
      INTEGER p9b
      INTEGER p1b
      INTEGER p2b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h10b
      INTEGER p9b_1
      INTEGER h10b_1
      INTEGER h5b_2
      INTEGER h10b_2
      INTEGER p1b_2
      INTEGER p2b_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
      INTEGER l_c
      INTEGER k_c
      EXTERNAL nxtask
      nprocs = GA_NNODES()
      count = 0
      next = nxtask(nprocs,1)
      DO h5b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1).ne.8)) THEN
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+p2b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+p2b-1)))) .eq. ieor(irrep_v,irrep_t)) TH
     &EN
      dimc = int_mb(k_range+h5b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+p1b-1) * int_mb(k_range+p2b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt2_q_left_4_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h10b = 1,noab
      IF (int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),int_mb(k_sym+h10b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p9b,h10b,p9b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h5b,h10b,p1b,p2b,h5b_2,h10b_2,p1b_2,p2b_2)
      dim_common = int_mb(k_range+h10b-1)
      dima_sort = int_mb(k_range+p9b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h5b-1) * int_mb(k_range+p1b-1) * int_mb
     &(k_range+p2b-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('ccsdt2_q_left_4_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt2_q_left_4_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (p9b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+h10b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt2_q_left_4_2',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt2_q_left_4_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt2_q_left_4_2',5,MA_ERR)
      IF ((h10b .lt. h5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h5b_2 - 1 + (noab
     &+nvab) * (h10b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h10b-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)
      END IF
      IF ((h5b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h10b_2 - 1 + (noa
     &b+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+h10b-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_b)) CALL ERRQUIT('ccsdt2_q_left_4_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('ccsdt2_q_left_4_2',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt2_q_left_4_2',
     &8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt2_q_left_4_2',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h5b-1),int_mb(k_range+p9b-1)
     &,3,4,2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p9b - noab - 1 + nvab
     & * (h5b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt2_q_left_4_2',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt2_q_left_4_2',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = nxtask(nprocs,1)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = nxtask(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
