      SUBROUTINE ccsd_lambda1_mod(d_f1,d_i0,d_t1,d_t2,d_v2,d_y1,d_y2,k_f
     &1_offset,k_i0_offset,k_t1_offset,k_t2_offset,k_v2_offset,k_y1_offs
     &et,k_y2_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     i0 ( h2 p1 )_f + = 1 * f ( h2 p1 )_f
C     i0 ( h2 p1 )_yf + = -1 * Sum ( h7 ) * y ( h7 p1 )_y * i1 ( h2 h7 )_f
C         i1 ( h2 h7 )_f + = 1 * f ( h2 h7 )_f
C         i1 ( h2 h7 )_ft + = 1 * Sum ( p3 ) * t ( p3 h7 )_t * i2 ( h2 p3 )_f
C             i2 ( h2 p3 )_f + = 1 * f ( h2 p3 )_f
C             i2 ( h2 p3 )_vt + = 1 * Sum ( h6 p5 ) * t ( p5 h6 )_t * v ( h2 h6 p3 p5 )_v
C         i1 ( h2 h7 )_vt + = 1 * Sum ( h4 p3 ) * t ( p3 h4 )_t * v ( h2 h4 h7 p3 )_v
C         i1 ( h2 h7 )_vt + = -1/2 * Sum ( h6 p3 p4 ) * t ( p3 p4 h6 h7 )_t * v ( h2 h6 p3 p4 )_v
C     i0 ( h2 p1 )_yf + = 1 * Sum ( p7 ) * y ( h2 p7 )_y * i1 ( p7 p1 )_f
C         i1 ( p7 p1 )_f + = 1 * f ( p7 p1 )_f
C         i1 ( p7 p1 )_vt + = -1 * Sum ( h4 p3 ) * t ( p3 h4 )_t * v ( h4 p7 p1 p3 )_v
C         i1 ( p7 p1 )_vtt + = -1 * Sum ( h4 ) * t ( p7 h4 )_t * i2 ( h4 p1 )_vt
C             i2 ( h4 p1 )_vt + = 1 * Sum ( h6 p5 ) * t ( p5 h6 )_t * v ( h4 h6 p1 p5 )_v
C     i0 ( h2 p1 )_yv + = -1 * Sum ( h4 p3 ) * y ( h4 p3 )_y * v ( h2 p3 h4 p1 )_v
C     i0 ( h2 p1 )_yv + = -1/2 * Sum ( h12 h11 p9 ) * y ( h11 h12 p1 p9 )_y * i1 ( h2 p9 h11 h12 )_v
C         i1 ( h2 p9 h11 h12 )_v + = 1 * v ( h2 p9 h11 h12 )_v
C         i1 ( h2 p9 h11 h12 )_vt + = -1 * Sum ( h7 ) * t ( p9 h7 )_t * i2 ( h2 h7 h11 h12 )_v
C             i2 ( h2 h7 h11 h12 )_v + = 1 * v ( h2 h7 h11 h12 )_v
C             i2 ( h2 h7 h11 h12 )_vt + = -2 * Sum ( p3 ) * t ( p3 h11 )_t * i3 ( h2 h7 h12 p3 )_v
C                 i3 ( h2 h7 h12 p3 )_v + = 1 * v ( h2 h7 h12 p3 )_v
C                 i3 ( h2 h7 h12 p3 )_vt + = -1/2 * Sum ( p5 ) * t ( p5 h12 )_t * v ( h2 h7 p3 p5 )_v
C             i2 ( h2 h7 h11 h12 )_vt + = 1/2 * Sum ( p3 p4 ) * t ( p3 p4 h11 h12 )_t * v ( h2 h7 p3 p4 )_v
C         i1 ( h2 p9 h11 h12 )_vt + = -2 * Sum ( p3 ) * t ( p3 h11 )_t * i2 ( h2 p9 h12 p3 )_v
C             i2 ( h2 p9 h12 p3 )_v + = 1 * v ( h2 p9 h12 p3 )_v
C             i2 ( h2 p9 h12 p3 )_vt + = -1/2 * Sum ( p5 ) * t ( p5 h12 )_t * v ( h2 p9 p3 p5 )_v
C         i1 ( h2 p9 h11 h12 )_ft + = 1 * Sum ( p5 ) * t ( p5 p9 h11 h12 )_t * i2 ( h2 p5 )_f
C             i2 ( h2 p5 )_f + = 1 * f ( h2 p5 )_f
C             i2 ( h2 p5 )_vt + = 1 * Sum ( h8 p7 ) * t ( p7 h8 )_t * v ( h2 h8 p5 p7 )_v
C         i1 ( h2 p9 h11 h12 )_vt + = -2 * Sum ( h6 p4 ) * t ( p4 p9 h6 h11 )_t * i2 ( h2 h6 h12 p4 )_v
C             i2 ( h2 h6 h12 p4 )_v + = 1 * v ( h2 h6 h12 p4 )_v
C             i2 ( h2 h6 h12 p4 )_vt + = -1 * Sum ( p7 ) * t ( p7 h12 )_t * v ( h2 h6 p4 p7 )_v
C         i1 ( h2 p9 h11 h12 )_vt + = 1/2 * Sum ( p3 p4 ) * t ( p3 p4 h11 h12 )_t * v ( h2 p9 p3 p4 )_v
C     i0 ( h2 p1 )_yv + = 1/2 * Sum ( h7 p5 p8 ) * y ( h2 h7 p5 p8 )_y * i1 ( p5 p8 h7 p1 )_v
C         i1 ( p5 p8 h7 p1 )_v + = -1 * v ( p5 p8 h7 p1 )_v
C         i1 ( p5 p8 h7 p1 )_vt + = 1 * Sum ( p3 ) * t ( p3 h7 )_t * v ( p5 p8 p1 p3 )_v
C     i0 ( h2 p1 )_vt + = 1 * Sum ( h10 p9 ) * i1 ( p9 h10 )_t * v ( h2 h10 p1 p9 )_v
C         i1 ( p9 h10 )_t + = 1 * t ( p9 h10 )_t
C         i1 ( p9 h10 )_yt + = 1 * Sum ( h5 p3 ) * t ( p3 p9 h5 h10 )_t * y ( h5 p3 )_y
C         i1 ( p9 h10 )_ytt + = -1 * Sum ( h6 ) * t ( p9 h6 )_t * i2 ( h6 h10 )_yt
C             i2 ( h6 h10 )_yt + = 1 * Sum ( p5 ) * t ( p5 h10 )_t * y ( h6 p5 )_y
C             i2 ( h6 h10 )_yt + = 1/2 * Sum ( h5 p4 p3 ) * t ( p3 p4 h5 h10 )_t * y ( h5 h6 p3 p4 )_y
C         i1 ( p9 h10 )_ytt + = -1/2 * Sum ( h5 h6 p3 ) * t ( p3 p9 h5 h6 )_t * i2 ( h5 h6 h10 p3 )_yt
C             i2 ( h5 h6 h10 p3 )_yt + = 1 * Sum ( p7 ) * t ( p7 h10 )_t * y ( h5 h6 p3 p7 )_y
C     i0 ( h2 p1 )_ytf + = -1 * Sum ( h3 ) * i1 ( h2 h3 )_yt * f ( h3 p1 )_f
C         i1 ( h2 h3 )_yt + = 1 * Sum ( p4 ) * t ( p4 h3 )_t * y ( h2 p4 )_y
C         i1 ( h2 h3 )_yt + = 1/2 * Sum ( h6 p5 p4 ) * t ( p4 p5 h3 h6 )_t * y ( h2 h6 p4 p5 )_y
C     i0 ( h2 p1 )_ytv + = 1 * Sum ( h6 h8 ) * i1 ( h6 h8 )_yt * v ( h2 h8 h6 p1 )_v
C         i1 ( h6 h8 )_yt + = 1 * Sum ( p3 ) * t ( p3 h8 )_t * y ( h6 p3 )_y
C         i1 ( h6 h8 )_yt + = 1/2 * Sum ( h5 p4 p3 ) * t ( p3 p4 h5 h8 )_t * y ( h5 h6 p3 p4 )_y
C     i0 ( h2 p1 )_ytv + = 1 * Sum ( p7 p8 ) * i1 ( p7 p8 )_yt * v ( h2 p8 p1 p7 )_v
C         i1 ( p7 p8 )_yt + = 1 * Sum ( h4 ) * t ( p7 h4 )_t * y ( h4 p8 )_y
C         i1 ( p7 p8 )_yt + = 1/2 * Sum ( h6 h5 p3 ) * t ( p3 p7 h5 h6 )_t * y ( h5 h6 p3 p8 )_y
C     i0 ( h2 p1 )_ytv + = 1 * Sum ( h6 h4 p5 ) * i1 ( h2 h6 h4 p5 )_yt * v ( h4 p5 h6 p1 )_v
C         i1 ( h2 h6 h4 p5 )_yt + = 1 * Sum ( p3 ) * t ( p3 h4 )_t * y ( h2 h6 p3 p5 )_y
C     i0 ( h2 p1 )_ytv + = 1/2 * Sum ( p9 h12 h6 ) * i1 ( h2 p9 h6 h12 )_yt * v ( h6 h12 p1 p9 )_v
C         i1 ( h2 p9 h6 h12 )_yt + = -1 * Sum ( p3 ) * t ( p3 p9 h6 h12 )_t * y ( h2 p3 )_y
C         i1 ( h2 p9 h6 h12 )_ytt + = -1/2 * Sum ( h10 ) * t ( p9 h10 )_t * i2 ( h2 h10 h6 h12 )_yt
C             i2 ( h2 h10 h6 h12 )_yt + = -1 * Sum ( p4 p3 ) * t ( p3 p4 h6 h12 )_t * y ( h2 h10 p3 p4 )_y
C             i2 ( h2 h10 h6 h12 )_ytt + = 2 * Sum ( p5 ) * t ( p5 h12 )_t * i3 ( h2 h10 h6 p5 )_yt
C                 i3 ( h2 h10 h6 p5 )_yt + = 1 * Sum ( p7 ) * t ( p7 h6 )_t * y ( h2 h10 p5 p7 )_y
C         i1 ( h2 p9 h6 h12 )_ytt + = 2 * Sum ( h5 p3 ) * t ( p3 p9 h5 h12 )_t * i2 ( h2 h5 h6 p3 )_yt
C             i2 ( h2 h5 h6 p3 )_yt + = 1 * Sum ( p7 ) * t ( p7 h6 )_t * y ( h2 h5 p3 p7 )_y
C         i1 ( h2 p9 h6 h12 )_ytt + = -1 * t ( p9 h6 )_t * i2 ( h2 h12 )_yt
C             i2 ( h2 h12 )_yt + = 1 * Sum ( h5 p4 p3 ) * t ( p3 p4 h5 h12 )_t * y ( h2 h5 p3 p4 )_y
C     i0 ( h2 p1 )_ytv + = 1/4 * Sum ( h7 h8 h6 ) * i1 ( h2 h7 h6 h8 )_yt * v ( h6 h8 h7 p1 )_v
C         i1 ( h2 h7 h6 h8 )_yt + = -1 * Sum ( p4 p3 ) * t ( p3 p4 h6 h8 )_t * y ( h2 h7 p3 p4 )_y
C         i1 ( h2 h7 h6 h8 )_ytt + = 2 * Sum ( p3 ) * t ( p3 h8 )_t * i2 ( h2 h7 h6 p3 )_yt
C             i2 ( h2 h7 h6 p3 )_yt + = 1 * Sum ( p5 ) * t ( p5 h6 )_t * y ( h2 h7 p3 p5 )_y
C     i0 ( h2 p1 )_ytv + = 1 * Sum ( p8 h6 p7 ) * i1 ( h2 p8 h6 p7 )_yt * v ( h6 p7 p1 p8 )_v
C         i1 ( h2 p8 h6 p7 )_yt + = 1 * Sum ( h5 p3 ) * t ( p3 p8 h5 h6 )_t * y ( h2 h5 p3 p7 )_y
C         i1 ( h2 p8 h6 p7 )_ytt + = -1 * Sum ( h4 ) * t ( p8 h4 )_t * i2 ( h2 h4 h6 p7 )_yt
C             i2 ( h2 h4 h6 p7 )_yt + = 1 * Sum ( p5 ) * t ( p5 h6 )_t * y ( h2 h4 p5 p7 )_y
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "util.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_i0
      INTEGER k_i0_offset
      INTEGER d_f1
      INTEGER k_f1_offset
      INTEGER d_y1
      INTEGER k_y1_offset
      INTEGER d_i1
      INTEGER k_i1_offset
      INTEGER d_v2
      INTEGER k_v2_offset
      INTEGER d_y2
      INTEGER k_y2_offset
      INTEGER l_i1_offset
      INTEGER size_i1
      INTEGER d_t1
      INTEGER k_t1_offset
      INTEGER d_i2
      INTEGER k_i2_offset
      INTEGER d_t2
      INTEGER k_t2_offset
      INTEGER l_i2_offset
      INTEGER size_i2
      INTEGER d_i3
      INTEGER k_i3_offset
      INTEGER l_i3_offset
      INTEGER size_i3
      CHARACTER*255 filename
      CALL ccsd_lambda1_mod_1(d_f1,k_f1_offset,d_i0,k_i0_offset)
      CALL OFFSET_ccsd_lambda1_mod_2_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_lambda1_mod_2_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_lambda1_mod_2_1(d_f1,k_f1_offset,d_i1,k_i1_offset)
      CALL OFFSET_ccsd_lambda1_mod_2_2_1(l_i2_offset,k_i2_offset,size_i2
     &)
      CALL TCE_FILENAME('ccsd_lambda1_mod_2_2_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_lambda1_mod_2_2_1(d_f1,k_f1_offset,d_i2,k_i2_offset)
      CALL ccsd_lambda1_mod_2_2_2(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i2
     &,k_i2_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_lambda1_mod_2_2(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k
     &_i1_offset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL ccsd_lambda1_mod_2_3(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i1,k
     &_i1_offset)
      CALL ccsd_lambda1_mod_2_4(d_t2,k_t2_offset,d_v2,k_v2_offset,d_i1,k
     &_i1_offset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_lambda1_mod_2(d_y1,k_y1_offset,d_i1,k_i1_offset,d_i0,k_i
     &0_offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL OFFSET_ccsd_lambda1_mod_3_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_lambda1_mod_3_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_lambda1_mod_3_1(d_f1,k_f1_offset,d_i1,k_i1_offset)
      CALL ccsd_lambda1_mod_3_2(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i1,k
     &_i1_offset)
      CALL OFFSET_ccsd_lambda1_mod_3_3_1(l_i2_offset,k_i2_offset,size_i2
     &)
      CALL TCE_FILENAME('ccsd_lambda1_mod_3_3_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_lambda1_mod_3_3_1(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i2
     &,k_i2_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_lambda1_mod_3_3(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k
     &_i1_offset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_lambda1_mod_3(d_y1,k_y1_offset,d_i1,k_i1_offset,d_i0,k_i
     &0_offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL ccsd_lambda1_mod_4(d_y1,k_y1_offset,d_v2,k_v2_offset,d_i0,k_i
     &0_offset)
      CALL OFFSET_ccsd_lambda1_mod_5_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_lambda1_mod_5_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_lambda1_mod_5_1(d_v2,k_v2_offset,d_i1,k_i1_offset)
      CALL OFFSET_ccsd_lambda1_mod_5_2_1(l_i2_offset,k_i2_offset,size_i2
     &)
      CALL TCE_FILENAME('ccsd_lambda1_mod_5_2_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_lambda1_mod_5_2_1(d_v2,k_v2_offset,d_i2,k_i2_offset)
      CALL OFFSET_ccsd_lambda1_mod_5_2_2_1(l_i3_offset,k_i3_offset,size_
     &i3)
      CALL TCE_FILENAME('ccsd_lambda1_mod_5_2_2_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL ccsd_lambda1_mod_5_2_2_1(d_v2,k_v2_offset,d_i3,k_i3_offset)
      CALL ccsd_lambda1_mod_5_2_2_2(d_t1,k_t1_offset,d_v2,k_v2_offset,d_
     &i3,k_i3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL ccsd_lambda1_mod_5_2_2(d_t1,k_t1_offset,d_i3,k_i3_offset,d_i2
     &,k_i2_offset)
      CALL DELETEFILE(d_i3)
      IF (.not.MA_POP_STACK(l_i3_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL ccsd_lambda1_mod_5_2_3(d_t2,k_t2_offset,d_v2,k_v2_offset,d_i2
     &,k_i2_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_lambda1_mod_5_2(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k
     &_i1_offset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL OFFSET_ccsd_lambda1_mod_5_3_1(l_i2_offset,k_i2_offset,size_i2
     &)
      CALL TCE_FILENAME('ccsd_lambda1_mod_5_3_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_lambda1_mod_5_3_1(d_v2,k_v2_offset,d_i2,k_i2_offset)
      CALL ccsd_lambda1_mod_5_3_2(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i2
     &,k_i2_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_lambda1_mod_5_3(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k
     &_i1_offset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL OFFSET_ccsd_lambda1_mod_5_4_1(l_i2_offset,k_i2_offset,size_i2
     &)
      CALL TCE_FILENAME('ccsd_lambda1_mod_5_4_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_lambda1_mod_5_4_1(d_f1,k_f1_offset,d_i2,k_i2_offset)
      CALL ccsd_lambda1_mod_5_4_2(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i2
     &,k_i2_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_lambda1_mod_5_4(d_t2,k_t2_offset,d_i2,k_i2_offset,d_i1,k
     &_i1_offset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL OFFSET_ccsd_lambda1_mod_5_5_1(l_i2_offset,k_i2_offset,size_i2
     &)
      CALL TCE_FILENAME('ccsd_lambda1_mod_5_5_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_lambda1_mod_5_5_1(d_v2,k_v2_offset,d_i2,k_i2_offset)
      CALL ccsd_lambda1_mod_5_5_2(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i2
     &,k_i2_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_lambda1_mod_5_5(d_t2,k_t2_offset,d_i2,k_i2_offset,d_i1,k
     &_i1_offset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL ccsd_lambda1_mod_5_6(d_t2,k_t2_offset,d_v2,k_v2_offset,d_i1,k
     &_i1_offset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_lambda1_mod_5(d_y2,k_y2_offset,d_i1,k_i1_offset,d_i0,k_i
     &0_offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL OFFSET_ccsd_lambda1_mod_6_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_lambda1_mod_6_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_lambda1_mod_6_1(d_v2,k_v2_offset,d_i1,k_i1_offset)
      CALL ccsd_lambda1_mod_6_2(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i1,k
     &_i1_offset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_lambda1_mod_6(d_y2,k_y2_offset,d_i1,k_i1_offset,d_i0,k_i
     &0_offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL OFFSET_ccsd_lambda1_mod_7_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_lambda1_mod_7_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_lambda1_mod_7_1(d_t1,k_t1_offset,d_i1,k_i1_offset)
      CALL ccsd_lambda1_mod_7_2(d_t2,k_t2_offset,d_y1,k_y1_offset,d_i1,k
     &_i1_offset)
      CALL OFFSET_ccsd_lambda1_mod_7_3_1(l_i2_offset,k_i2_offset,size_i2
     &)
      CALL TCE_FILENAME('ccsd_lambda1_mod_7_3_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_lambda1_mod_7_3_1(d_t1,k_t1_offset,d_y1,k_y1_offset,d_i2
     &,k_i2_offset)
      CALL ccsd_lambda1_mod_7_3_2(d_t2,k_t2_offset,d_y2,k_y2_offset,d_i2
     &,k_i2_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_lambda1_mod_7_3(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k
     &_i1_offset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL OFFSET_ccsd_lambda1_mod_7_4_1(l_i2_offset,k_i2_offset,size_i2
     &)
      CALL TCE_FILENAME('ccsd_lambda1_mod_7_4_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_lambda1_mod_7_4_1(d_t1,k_t1_offset,d_y2,k_y2_offset,d_i2
     &,k_i2_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_lambda1_mod_7_4(d_t2,k_t2_offset,d_i2,k_i2_offset,d_i1,k
     &_i1_offset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_lambda1_mod_7(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_i
     &0_offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL OFFSET_ccsd_lambda1_mod_8_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_lambda1_mod_8_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_lambda1_mod_8_1(d_t1,k_t1_offset,d_y1,k_y1_offset,d_i1,k
     &_i1_offset)
      CALL ccsd_lambda1_mod_8_2(d_t2,k_t2_offset,d_y2,k_y2_offset,d_i1,k
     &_i1_offset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_lambda1_mod_8(d_i1,k_i1_offset,d_f1,k_f1_offset,d_i0,k_i
     &0_offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL OFFSET_ccsd_lambda1_mod_9_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_lambda1_mod_9_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_lambda1_mod_9_1(d_t1,k_t1_offset,d_y1,k_y1_offset,d_i1,k
     &_i1_offset)
      CALL ccsd_lambda1_mod_9_2(d_t2,k_t2_offset,d_y2,k_y2_offset,d_i1,k
     &_i1_offset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_lambda1_mod_9(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_i
     &0_offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL OFFSET_ccsd_lambda1_mod_10_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_lambda1_mod_10_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_lambda1_mod_10_1(d_t1,k_t1_offset,d_y1,k_y1_offset,d_i1,
     &k_i1_offset)
      CALL ccsd_lambda1_mod_10_2(d_t2,k_t2_offset,d_y2,k_y2_offset,d_i1,
     &k_i1_offset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_lambda1_mod_10(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_
     &i0_offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL OFFSET_ccsd_lambda1_mod_11_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_lambda1_mod_11_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_lambda1_mod_11_1(d_t1,k_t1_offset,d_y2,k_y2_offset,d_i1,
     &k_i1_offset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_lambda1_mod_11(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_
     &i0_offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL OFFSET_ccsd_lambda1_mod_12_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_lambda1_mod_12_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_lambda1_mod_12_1(d_t2,k_t2_offset,d_y1,k_y1_offset,d_i1,
     &k_i1_offset)
      CALL OFFSET_ccsd_lambda1_mod_12_2_1(l_i2_offset,k_i2_offset,size_i
     &2)
      CALL TCE_FILENAME('ccsd_lambda1_mod_12_2_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_lambda1_mod_12_2_1(d_t2,k_t2_offset,d_y2,k_y2_offset,d_i
     &2,k_i2_offset)
      CALL OFFSET_ccsd_lambda1_mod_12_2_2_1(l_i3_offset,k_i3_offset,size
     &_i3)
      CALL TCE_FILENAME('ccsd_lambda1_mod_12_2_2_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL ccsd_lambda1_mod_12_2_2_1(d_t1,k_t1_offset,d_y2,k_y2_offset,d
     &_i3,k_i3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL ccsd_lambda1_mod_12_2_2(d_t1,k_t1_offset,d_i3,k_i3_offset,d_i
     &2,k_i2_offset)
      CALL DELETEFILE(d_i3)
      IF (.not.MA_POP_STACK(l_i3_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_lambda1_mod_12_2(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,
     &k_i1_offset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL OFFSET_ccsd_lambda1_mod_12_3_1(l_i2_offset,k_i2_offset,size_i
     &2)
      CALL TCE_FILENAME('ccsd_lambda1_mod_12_3_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_lambda1_mod_12_3_1(d_t1,k_t1_offset,d_y2,k_y2_offset,d_i
     &2,k_i2_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_lambda1_mod_12_3(d_t2,k_t2_offset,d_i2,k_i2_offset,d_i1,
     &k_i1_offset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL OFFSET_ccsd_lambda1_mod_12_4_1(l_i2_offset,k_i2_offset,size_i
     &2)
      CALL TCE_FILENAME('ccsd_lambda1_mod_12_4_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_lambda1_mod_12_4_1(d_t2,k_t2_offset,d_y2,k_y2_offset,d_i
     &2,k_i2_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_lambda1_mod_12_4(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,
     &k_i1_offset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_lambda1_mod_12(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_
     &i0_offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL OFFSET_ccsd_lambda1_mod_13_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_lambda1_mod_13_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_lambda1_mod_13_1(d_t2,k_t2_offset,d_y2,k_y2_offset,d_i1,
     &k_i1_offset)
      CALL OFFSET_ccsd_lambda1_mod_13_2_1(l_i2_offset,k_i2_offset,size_i
     &2)
      CALL TCE_FILENAME('ccsd_lambda1_mod_13_2_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_lambda1_mod_13_2_1(d_t1,k_t1_offset,d_y2,k_y2_offset,d_i
     &2,k_i2_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_lambda1_mod_13_2(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,
     &k_i1_offset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_lambda1_mod_13(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_
     &i0_offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL OFFSET_ccsd_lambda1_mod_14_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_lambda1_mod_14_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_lambda1_mod_14_1(d_t2,k_t2_offset,d_y2,k_y2_offset,d_i1,
     &k_i1_offset)
      CALL OFFSET_ccsd_lambda1_mod_14_2_1(l_i2_offset,k_i2_offset,size_i
     &2)
      CALL TCE_FILENAME('ccsd_lambda1_mod_14_2_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_lambda1_mod_14_2_1(d_t1,k_t1_offset,d_y2,k_y2_offset,d_i
     &2,k_i2_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_lambda1_mod_14_2(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,
     &k_i1_offset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_lambda1_mod_14(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_
     &i0_offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_lambda1_mod
     &',-1,MA_ERR)
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_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     i0 ( h2 p1 )_f + = 1 * f ( h2 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 h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER h2b_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 h2b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p1b-1)) .eq. irrep_f) TH
     &EN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p1b-1)
      CALL TCE_RESTRICTED_2(h2b,p1b,h2b_1,p1b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h2b-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('ccsd_lambda1_mod_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_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) * (h2b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p1b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_1',2,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_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+h2b-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 * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_1',4,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_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 ccsd_lambda1_mod_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     i0 ( h2 p1 )_yf + = -1 * Sum ( h7 ) * y ( h7 p1 )_y * i1 ( h2 h7 )_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 d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h7b
      INTEGER h7b_1
      INTEGER p1b_1
      INTEGER h2b_2
      INTEGER h7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &y,irrep_f)) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h7b = 1,noab
      IF (int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h7b-1),int_mb(k_sym+p1b-1)) .eq. irrep_y) TH
     &EN
      CALL TCE_RESTRICTED_2(h7b,p1b,h7b_1,p1b_1)
      CALL TCE_RESTRICTED_2(h2b,h7b,h2b_2,h7b_2)
      dim_common = int_mb(k_range+h7b-1)
      dima_sort = int_mb(k_range+p1b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-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('ccsd_lambda1_mod_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p1b_1
     & - noab - 1 + nvab * (h7b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h7b-1)
     &,int_mb(k_range+p1b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_2',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_2',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h7b_2
     & - 1 + noab * (h2b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_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('ccsd_lambda1_mod_2'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_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('
     &ccsd_lambda1_mod_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p1b-1),1,2,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_2',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_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 ccsd_lambda1_mod_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 ( h2 h7 )_f + = 1 * f ( h2 h7 )_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 h2b
      INTEGER h7b
      INTEGER dimc
      INTEGER h2b_1
      INTEGER h7b_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 h2b = 1,noab
      DO h7b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h7b-1)) .eq. irrep_f) TH
     &EN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1)
      CALL TCE_RESTRICTED_2(h2b,h7b,h2b_1,h7b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-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('ccsd_lambda1_mod_2_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_2_1',1,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_1
     & - 1 + (noab+nvab) * (h2b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_2_1',2,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_2_1',3,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+h7b-1)
     &,int_mb(k_range+h2b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h7b -
     & 1 + noab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_2_1',4,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_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_ccsd_lambda1_mod_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 ( h2 h7 )_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 h2b
      INTEGER h7b
      length = 0
      DO h2b = 1,noab
      DO h7b = 1,noab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h7b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-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('ccsd_lambda1_mod_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h7b = 1,noab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h7b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h7b - 1 + noab * (h2b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_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 ( h2 h7 )_ft + = 1 * Sum ( p3 ) * t ( p3 h7 )_t * i2 ( h2 p3 )_f
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h7b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h7b_1
      INTEGER h2b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO h7b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h7b-1)) .eq. ieor(irrep_
     &f,irrep_t)) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_2_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h7b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p3b,h7b,p3b_1,h7b_1)
      CALL TCE_RESTRICTED_2(h2b,p3b,h2b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h7b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-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('ccsd_lambda1_mod_2_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_2_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_1
     & - 1 + noab * (p3b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h7b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_2_2',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_2_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_2_2',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h2b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p3b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_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('ccsd_lambda1_mod_2_
     &2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_2_
     &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('
     &ccsd_lambda1_mod_2_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),1,2,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h7b -
     & 1 + noab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_2_2',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_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 ccsd_lambda1_mod_2_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     i2 ( h2 p3 )_f + = 1 * f ( h2 p3 )_f
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p3b
      INTEGER dimc
      INTEGER h2b_1
      INTEGER p3b_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 h2b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p3b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p3b-1)) .eq. irrep_f) TH
     &EN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p3b-1)
      CALL TCE_RESTRICTED_2(h2b,p3b,h2b_1,p3b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h2b-1) * int_mb(k_range+p3b-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('ccsd_lambda1_mod_2_2_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_2_2_1',1,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p3b_1
     & - 1 + (noab+nvab) * (h2b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p3b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_2_2_1',
     &2,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_2_2_1',3,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h2b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_2_2_1',
     &4,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_2_
     &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_ccsd_lambda1_mod_2_2_1(l_a_offset,k_a_offset,siz
     &e)
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     i2 ( h2 p3 )_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 h2b
      INTEGER p3b
      length = 0
      DO h2b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p3b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p3b-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('ccsd_lambda1_mod_2_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p3b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p3b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p3b - noab - 1 + nvab * (h2b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+p3b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_2_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     i2 ( h2 p3 )_vt + = 1 * Sum ( h6 p5 ) * t ( p5 h6 )_t * v ( h2 h6 p3 p5 )_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 h2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER h6b
      INTEGER p5b_1
      INTEGER h6b_1
      INTEGER h2b_2
      INTEGER h6b_2
      INTEGER p3b_2
      INTEGER p5b_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 h2b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p3b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p3b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_2_2_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      DO h6b = 1,noab
      IF (int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h6b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p5b,h6b,p5b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h2b,h6b,p3b,p5b,h2b_2,h6b_2,p3b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1) * int_mb(k_range+h6b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_2_2_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_2_2_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (p5b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p5b-1)
     &,int_mb(k_range+h6b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_2_2_2',
     &3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_2_2_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_2_2_2',5,MA_ERR)
      IF ((h6b .lt. h2b) .and. (p5b .lt. p3b)) THEN
      if(.not.intorb) then 
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p3b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p3b_2,p5b_2,h2b_2,h6b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p5b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h6b .lt. h2b) .and. (p3b .le. p5b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p5b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p5b_2,p3b_2,h2b_2,h6b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p3b-1),int_mb(k_range+p5b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF ((h2b .le. h6b) .and. (p5b .lt. p3b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p3b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p3b_2,p5b_2,h6b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p5b-1),int_mb(k_range+p3b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h2b .le. h6b) .and. (p3b .le. p5b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p5b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p5b_2,p3b_2,h6b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p3b-1),int_mb(k_range+p5b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_2_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('ccsd_lambda1_mod_2_
     &2_2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_2_
     &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('
     &ccsd_lambda1_mod_2_2_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h2b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_2_2_2',
     &10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_2_
     &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 ccsd_lambda1_mod_2_3(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 ( h2 h7 )_vt + = 1 * Sum ( h4 p3 ) * t ( p3 h4 )_t * v ( h2 h4 h7 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h7b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER h4b
      INTEGER p3b_1
      INTEGER h4b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER h7b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO h7b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h7b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_2_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      DO h4b = 1,noab
      IF (int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+h4b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h4b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p3b,h4b,p3b_1,h4b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,h7b,p3b,h2b_2,h4b_2,h7b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1) * int_mb(k_range+h4b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-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('ccsd_lambda1_mod_2_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_2_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_1
     & - 1 + noab * (p3b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h4b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_2_3',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_2_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_2_3',5,MA_ERR)
      IF ((h4b .lt. h2b) .and. (h7b .le. p3b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (h7b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p3b_2
     & - 1 + (noab+nvab) * (h7b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p3b_2,h7b_2,h2b_2,h4b_2)
      end if 
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF ((h2b .le. h4b) .and. (h7b .le. p3b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (h7b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p3b_2
     & - 1 + (noab+nvab) * (h7b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p3b_2,h7b_2,h4b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_2_3',6,
     &MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_2_
     &3',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_2_
     &3',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('
     &ccsd_lambda1_mod_2_3',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h7b-1)
     &,int_mb(k_range+h2b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h7b -
     & 1 + noab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_2_3',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_2_
     &3',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 ccsd_lambda1_mod_2_4(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 ( h2 h7 )_vt + = -1/2 * Sum ( h6 p3 p4 ) * t ( p3 p4 h6 h7 )_t * v ( h2 h6 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 d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h7b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p4b
      INTEGER h6b
      INTEGER p3b_1
      INTEGER p4b_1
      INTEGER h7b_1
      INTEGER h6b_1
      INTEGER h2b_2
      INTEGER h6b_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
      INTEGER nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO h7b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h7b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_2_4',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      DO p4b = p3b,noab+nvab
      DO h6b = 1,noab
      IF (int_mb(k_spin+p3b-1)+int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+h
     &7b-1)+int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),ieor(int_mb(k_sym+p4b-1),ieor(int_mb(
     &k_sym+h7b-1),int_mb(k_sym+h6b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p3b,p4b,h7b,h6b,p3b_1,p4b_1,h7b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h2b,h6b,p3b,p4b,h2b_2,h6b_2,p3b_2,p4b_2)
      dim_common = int_mb(k_range+p3b-1) * int_mb(k_range+p4b-1) * int_m
     &b(k_range+h6b-1)
      dima_sort = int_mb(k_range+h7b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-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('ccsd_lambda1_mod_2_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_2_4',2,MA_ERR)
      IF ((h6b .le. h7b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_1
     & - 1 + noab * (h6b_1 - 1 + noab * (p4b_1 - noab - 1 + nvab * (p3b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p4b-1),int_mb(k_range+h6b-1),int_mb(k_range+h7b-1)
     &,4,3,2,1,1.0d0)
      END IF
      IF ((h7b .lt. h6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h7b_1 - 1 + noab * (p4b_1 - noab - 1 + nvab * (p3b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p4b-1),int_mb(k_range+h7b-1),int_mb(k_range+h6b-1)
     &,3,4,2,1,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_2_4',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_2_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_2_4',5,MA_ERR)
      IF ((h6b .lt. h2b)) THEN
      if(.not.intorb) then
      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) * (h2b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p4b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p4b_2,p3b_2,h2b_2,h6b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p3b-1),int_mb(k_range+p4b-1)
     &,2,1,4,3,-1.0d0)
      END IF
      IF ((h2b .le. h6b)) THEN
      if(.not.intorb) then
      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) * (h6b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p4b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p4b_2,p3b_2,h6b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p3b-1),int_mb(k_range+p4b-1)
     &,1,2,4,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_2_4',6,
     &MA_ERR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p3b .eq. p4b) THEN
      nsuperp(isuperp) = nsuperp(isuperp) + 1
      ELSE
      isuperp = isuperp + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsuperp(1))/FACTORIAL(nsuperp(2)),dbl_mb(k_a_sort),dim_common,dbl_
     &mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_2_
     &4',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_2_
     &4',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_2_4',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),1,2,-1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h7b -
     & 1 + noab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_2_4',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_2_
     &4',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 ccsd_lambda1_mod_3(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     i0 ( h2 p1 )_yf + = 1 * Sum ( p7 ) * y ( h2 p7 )_y * i1 ( p7 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_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER h2b_1
      INTEGER p7b_1
      INTEGER p7b_2
      INTEGER p1b_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 h2b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &y,irrep_f)) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p7b-1)) .eq. irrep_y) TH
     &EN
      CALL TCE_RESTRICTED_2(h2b,p7b,h2b_1,p7b_1)
      CALL TCE_RESTRICTED_2(p7b,p1b,p7b_2,p1b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h2b-1)
      dima = dim_common * dima_sort
      dimb_sort = 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('ccsd_lambda1_mod_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p7b_1
     & - noab - 1 + nvab * (h2b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p7b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_3',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_3',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p1b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_3',6,MA
     &_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_3'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_3'
     &,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('
     &ccsd_lambda1_mod_3',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+h2b-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 * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_3',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_3'
     &,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 ccsd_lambda1_mod_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 ( p7 p1 )_f + = 1 * f ( p7 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 p7b
      INTEGER p1b
      INTEGER dimc
      INTEGER p7b_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 p7b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p7b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+p1b-1)) .eq. irrep_f) TH
     &EN
      dimc = int_mb(k_range+p7b-1) * int_mb(k_range+p1b-1)
      CALL TCE_RESTRICTED_2(p7b,p1b,p7b_1,p1b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+p7b-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('ccsd_lambda1_mod_3_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_3_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) * (p7b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p1b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_3_1',2,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_3_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+p7b-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 * (p7b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_3_1',4,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_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
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_lambda1_mod_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 ( p7 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 p7b
      INTEGER p1b
      length = 0
      DO p7b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+p1b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+p7b-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('ccsd_lambda1_mod_3_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO p7b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+p1b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+p7b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p1b - noab - 1 + nvab * (p7b - noab - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+p7b-1) * int_mb(k_range+p1b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_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 ( p7 p1 )_vt + = -1 * Sum ( h4 p3 ) * t ( p3 h4 )_t * v ( h4 p7 p1 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p7b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER h4b
      INTEGER p3b_1
      INTEGER h4b_1
      INTEGER p7b_2
      INTEGER h4b_2
      INTEGER p1b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO p7b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p7b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      dimc = int_mb(k_range+p7b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_3_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      DO h4b = 1,noab
      IF (int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+h4b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h4b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p3b,h4b,p3b_1,h4b_1)
      CALL TCE_RESTRICTED_4(p7b,h4b,p1b,p3b,p7b_2,h4b_2,p1b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1) * int_mb(k_range+h4b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p7b-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('ccsd_lambda1_mod_3_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_3_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_1
     & - 1 + noab * (p3b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h4b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_3_2',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_3_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_3_2',5,MA_ERR)
      IF ((h4b .le. p7b) .and. (p3b .lt. p1b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (p7b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (p7b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p1b_2,p3b_2,p7b_2,h4b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+p3b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h4b .le. p7b) .and. (p1b .le. p3b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (p7b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p3b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (p7b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p3b_2,p1b_2,p7b_2,h4b_2)
      end if 
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+p1b-1),int_mb(k_range+p3b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_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('ccsd_lambda1_mod_3_
     &2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_3_
     &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('
     &ccsd_lambda1_mod_3_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+p7b-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 * (p7b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_3_2',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_3_
     &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 ccsd_lambda1_mod_3_3(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 ( p7 p1 )_vtt + = -1 * Sum ( h4 ) * t ( p7 h4 )_t * i2 ( h4 p1 )_vt
      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 p7b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER p7b_1
      INTEGER h4b_1
      INTEGER h4b_2
      INTEGER p1b_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 p7b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p7b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,ieor(irrep_t,irrep_t))) THEN
      dimc = int_mb(k_range+p7b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_3_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h4b = 1,noab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h4b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h4b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p7b,h4b,p7b_1,h4b_1)
      CALL TCE_RESTRICTED_2(h4b,p1b,h4b_2,p1b_2)
      dim_common = int_mb(k_range+h4b-1)
      dima_sort = int_mb(k_range+p7b-1)
      dima = dim_common * dima_sort
      dimb_sort = 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('ccsd_lambda1_mod_3_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_3_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_1
     & - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h4b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_3_3',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_3_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_3_3',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (h4b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+p1b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_3_3',6,
     &MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_3_
     &3',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_3_
     &3',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('
     &ccsd_lambda1_mod_3_3',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+p7b-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 * (p7b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_3_3',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_3_
     &3',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 ccsd_lambda1_mod_3_3_1(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     i2 ( h4 p1 )_vt + = 1 * Sum ( h6 p5 ) * t ( p5 h6 )_t * v ( h4 h6 p1 p5 )_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 h4b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER h6b
      INTEGER p5b_1
      INTEGER h6b_1
      INTEGER h4b_2
      INTEGER h6b_2
      INTEGER p1b_2
      INTEGER p5b_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 h4b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_3_3_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      DO h6b = 1,noab
      IF (int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h6b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p5b,h6b,p5b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h4b,h6b,p1b,p5b,h4b_2,h6b_2,p1b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1) * int_mb(k_range+h6b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-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('ccsd_lambda1_mod_3_3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_3_3_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (p5b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p5b-1)
     &,int_mb(k_range+h6b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_3_3_1',
     &3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_3_3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_3_3_1',5,MA_ERR)
      IF ((h6b .lt. h4b) .and. (p5b .lt. p1b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p1b_2,p5b_2,h4b_2,h6b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p5b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h6b .lt. h4b) .and. (p1b .le. p5b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p5b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p5b_2,p1b_2,h4b_2,h6b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p1b-1),int_mb(k_range+p5b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF ((h4b .le. h6b) .and. (p5b .lt. p1b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p1b_2,p5b_2,h6b_2,h4b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p5b-1),int_mb(k_range+p1b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h4b .le. h6b) .and. (p1b .le. p5b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p5b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p5b_2,p1b_2,h6b_2,h4b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p1b-1),int_mb(k_range+p5b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_3_3_1',
     &6,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_3_
     &3_1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_3_
     &3_1',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('
     &ccsd_lambda1_mod_3_3_1',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+h4b-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 * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_3_3_1',
     &10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_3_
     &3_1',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 OFFSET_ccsd_lambda1_mod_3_3_1(l_a_offset,k_a_offset,siz
     &e)
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     i2 ( h4 p1 )_vt
      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 h4b
      INTEGER p1b
      length = 0
      DO h4b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-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('ccsd_lambda1_mod_3_3_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p1b - noab - 1 + nvab * (h4b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+p1b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_4(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     i0 ( h2 p1 )_yv + = -1 * Sum ( h4 p3 ) * y ( h4 p3 )_y * v ( h2 p3 h4 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_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER p3b
      INTEGER h4b_1
      INTEGER p3b_1
      INTEGER h2b_2
      INTEGER p3b_2
      INTEGER p1b_2
      INTEGER h4b_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 h2b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &y,irrep_v)) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_4',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h4b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+p3b-1)) .eq. irrep_y) TH
     &EN
      CALL TCE_RESTRICTED_2(h4b,p3b,h4b_1,p3b_1)
      CALL TCE_RESTRICTED_4(h2b,p3b,p1b,h4b,h2b_2,p3b_2,p1b_2,h4b_2)
      dim_common = int_mb(k_range+h4b-1) * int_mb(k_range+p3b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-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('ccsd_lambda1_mod_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_4',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p3b_1
     & - noab - 1 + nvab * (h4b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+p3b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_4',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_4',5,MA_ERR)
      IF ((h2b .le. p3b) .and. (h4b .le. p1b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (h4b_2 - 1 + (noab+nvab) * (p3b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (h4b_2 - 1 + (noab+nvab) * (p3b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p1b_2,h4b_2,p3b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p3b-1),int_mb(k_range+h4b-1),int_mb(k_range+p1b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_4',6,MA
     &_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_4'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_4'
     &,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('
     &ccsd_lambda1_mod_4',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+h2b-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 * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_4',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_4'
     &,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 ccsd_lambda1_mod_5(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     i0 ( h2 p1 )_yv + = -1/2 * Sum ( h12 h11 p9 ) * y ( h11 h12 p1 p9 )_y * i1 ( h2 p9 h11 h12 )_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 h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h11b
      INTEGER h12b
      INTEGER p9b
      INTEGER h11b_1
      INTEGER h12b_1
      INTEGER p1b_1
      INTEGER p9b_1
      INTEGER h2b_2
      INTEGER p9b_2
      INTEGER h11b_2
      INTEGER h12b_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 nsuperh(2)
      INTEGER isuperh
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &y,irrep_v)) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h11b = 1,noab
      DO h12b = h11b,noab
      DO p9b = noab+1,noab+nvab
      IF (int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-1) .eq. int_mb(k_spin
     &+p1b-1)+int_mb(k_spin+p9b-1)) THEN
      IF (ieor(int_mb(k_sym+h11b-1),ieor(int_mb(k_sym+h12b-1),ieor(int_m
     &b(k_sym+p1b-1),int_mb(k_sym+p9b-1)))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_4(h11b,h12b,p1b,p9b,h11b_1,h12b_1,p1b_1,p9b_1)
      CALL TCE_RESTRICTED_4(h2b,p9b,h11b,h12b,h2b_2,p9b_2,h11b_2,h12b_2)
      dim_common = int_mb(k_range+h11b-1) * int_mb(k_range+h12b-1) * int
     &_mb(k_range+p9b-1)
      dima_sort = int_mb(k_range+p1b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-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('ccsd_lambda1_mod_5',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5',2,MA_ERR)
      IF ((p9b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p1b_1
     & - noab - 1 + nvab * (p9b_1 - noab - 1 + nvab * (h12b_1 - 1 + noab
     & * (h11b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h11b-1
     &),int_mb(k_range+h12b-1),int_mb(k_range+p9b-1),int_mb(k_range+p1b-
     &1),4,3,2,1,-1.0d0)
      END IF
      IF ((p1b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p9b_1
     & - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab * (h12b_1 - 1 + noab
     & * (h11b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h11b-1
     &),int_mb(k_range+h12b-1),int_mb(k_range+p1b-1),int_mb(k_range+p9b-
     &1),3,4,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_5',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h12b_
     &2 - 1 + noab * (h11b_2 - 1 + noab * (p9b_2 - noab - 1 + nvab * (h2
     &b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h11b-1),int_mb(k_range+h12b-
     &1),1,2,4,3,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_5',6,MA
     &_ERR)
      nsuperh(1) = 1
      nsuperh(2) = 1
      isuperh = 1
      IF (h11b .eq. h12b) THEN
      nsuperh(isuperh) = nsuperh(isuperh) + 1
      ELSE
      isuperh = isuperh + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsuperh(1))/FACTORIAL(nsuperh(2)),dbl_mb(k_a_sort),dim_common,dbl_
     &mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5'
     &,8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p1b-1),1,2,-1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_5',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5'
     &,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 ccsd_lambda1_mod_5_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 ( h2 p9 h11 h12 )_v + = 1 * v ( h2 p9 h11 h12 )_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 h2b
      INTEGER p9b
      INTEGER h11b
      INTEGER h12b
      INTEGER dimc
      INTEGER h2b_1
      INTEGER p9b_1
      INTEGER h11b_1
      INTEGER h12b_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 h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h11b = 1,noab
      DO h12b = h11b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_v) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+h12b-1)
      CALL TCE_RESTRICTED_4(h2b,p9b,h11b,h12b,h2b_1,p9b_1,h11b_1,h12b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb
     &(k_range+h11b-1) * int_mb(k_range+h12b-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('ccsd_lambda1_mod_5_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_1',1,MA_ERR)
      IF ((h2b .le. p9b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + (noab+nvab) * (h11b_1 - 1 + (noab+nvab) * (p9b_1 - 1 + (no
     &ab+nvab) * (h2b_1 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),
     &(h12b_
     &1 - 1 + (noab+nvab) * (h11b_1 - 1 + (noab+nvab) * (p9b_1 - 1 + (no
     &ab+nvab) * (h2b_1 - 1)))),h12b_1,h11b_1,p9b_1,h2b_1)
      end if
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h11b-1),int_mb(k_range+h12b-
     &1),4,3,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_5_1',2,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_1',3,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+h11b-1),int_mb(k_range+p9b-1),int_mb(k_range+h2b-
     &1),4,3,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h11b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_5_1',4,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &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_ccsd_lambda1_mod_5_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 ( h2 p9 h11 h12 )_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 h2b
      INTEGER p9b
      INTEGER h11b
      INTEGER h12b
      length = 0
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h11b = 1,noab
      DO h12b = h11b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-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('ccsd_lambda1_mod_5_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h11b = 1,noab
      DO h12b = h11b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h12b - 1 + noab * (h11b - 1 + noab * (p9
     &b - noab - 1 + nvab * (h2b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_
     &mb(k_range+h11b-1) * int_mb(k_range+h12b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_5_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 ( h2 p9 h11 h12 )_vt + = -1 * Sum ( h7 ) * t ( p9 h7 )_t * i2 ( h2 h7 h11 h12 )_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 h2b
      INTEGER p9b
      INTEGER h11b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h7b
      INTEGER p9b_1
      INTEGER h7b_1
      INTEGER h2b_2
      INTEGER h7b_2
      INTEGER h11b_2
      INTEGER h12b_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 h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h11b = 1,noab
      DO h12b = h11b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_v,irrep_t)) 
     &THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h7b = 1,noab
      IF (int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),int_mb(k_sym+h7b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p9b,h7b,p9b_1,h7b_1)
      CALL TCE_RESTRICTED_4(h2b,h7b,h11b,h12b,h2b_2,h7b_2,h11b_2,h12b_2)
      dim_common = int_mb(k_range+h7b-1)
      dima_sort = int_mb(k_range+p9b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h11b-1) * int_m
     &b(k_range+h12b-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('ccsd_lambda1_mod_5_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_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+h7b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_5_2',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_2',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h12b_
     &2 - 1 + noab * (h11b_2 - 1 + noab * (h7b_2 - 1 + noab * (h2b_2 - 1
     &)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+h11b-1),int_mb(k_range+h12b-
     &1),4,3,1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_5_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('ccsd_lambda1_mod_5_
     &2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &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('
     &ccsd_lambda1_mod_5_2',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+h11b-1),int_mb(k_range+h2b-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),(h12b 
     &- 1 + noab * (h11b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_5_2',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &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 ccsd_lambda1_mod_5_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     i2 ( h2 h7 h11 h12 )_v + = 1 * v ( h2 h7 h11 h12 )_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 h2b
      INTEGER h7b
      INTEGER h11b
      INTEGER h12b
      INTEGER dimc
      INTEGER h2b_1
      INTEGER h7b_1
      INTEGER h11b_1
      INTEGER h12b_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 h2b = 1,noab
      DO h7b = 1,noab
      DO h11b = 1,noab
      DO h12b = h11b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_v) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+h12b-1)
      CALL TCE_RESTRICTED_4(h2b,h7b,h11b,h12b,h2b_1,h7b_1,h11b_1,h12b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_mb
     &(k_range+h11b-1) * int_mb(k_range+h12b-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('ccsd_lambda1_mod_5_2_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_2_1',1,MA_ERR)
      IF ((h7b .lt. h2b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + (noab+nvab) * (h11b_1 - 1 + (noab+nvab) * (h2b_1 - 1 + (no
     &ab+nvab) * (h7b_1 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),
     &(h12b_
     &1 - 1 + (noab+nvab) * (h11b_1 - 1 + (noab+nvab) * (h2b_1 - 1 + (no
     &ab+nvab) * (h7b_1 - 1)))),h12b_1,h11b_1,h2b_1,h7b_1)
      end if
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h7b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h11b-1),int_mb(k_range+h12b-
     &1),4,3,1,2,-1.0d0)
      END IF
      IF ((h2b .le. h7b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + (noab+nvab) * (h11b_1 - 1 + (noab+nvab) * (h7b_1 - 1 + (no
     &ab+nvab) * (h2b_1 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),
     &(h12b_
     &1 - 1 + (noab+nvab) * (h11b_1 - 1 + (noab+nvab) * (h7b_1 - 1 + (no
     &ab+nvab) * (h2b_1 - 1)))),h12b_1,h11b_1,h7b_1,h2b_1)
      end if
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+h11b-1),int_mb(k_range+h12b-
     &1),4,3,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_5_2_1',
     &2,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_2_1',3,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+h11b-1),int_mb(k_range+h7b-1),int_mb(k_range+h2b-
     &1),4,3,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h11b - 1 + noab * (h7b - 1 + noab * (h2b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_5_2_1',
     &4,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &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
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_lambda1_mod_5_2_1(l_a_offset,k_a_offset,siz
     &e)
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     i2 ( h2 h7 h11 h12 )_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 h2b
      INTEGER h7b
      INTEGER h11b
      INTEGER h12b
      length = 0
      DO h2b = 1,noab
      DO h7b = 1,noab
      DO h11b = 1,noab
      DO h12b = h11b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-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('ccsd_lambda1_mod_5_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h7b = 1,noab
      DO h11b = 1,noab
      DO h12b = h11b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h12b - 1 + noab * (h11b - 1 + noab * (h7
     &b - 1 + noab * (h2b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_
     &mb(k_range+h11b-1) * int_mb(k_range+h12b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_5_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     i2 ( h2 h7 h11 h12 )_vt + = -2 * Sum ( p3 ) * t ( p3 h11 )_t * i3 ( h2 h7 h12 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h7b
      INTEGER h11b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h11b_1
      INTEGER h2b_2
      INTEGER h7b_2
      INTEGER h12b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO h7b = 1,noab
      DO h11b = 1,noab
      DO h12b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_v,irrep_t)) 
     &THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_2_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h11b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p3b,h11b,p3b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h2b,h7b,h12b,p3b,h2b_2,h7b_2,h12b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h11b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_mb
     &(k_range+h12b-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('ccsd_lambda1_mod_5_2_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_2_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (p3b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h11b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_5_2_2',
     &3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_2_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_2_2',5,MA_ERR)
      IF ((h12b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h12b_2 - 1 + noab * (h7b_2 - 1 + noab * (h2b
     &_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+h12b-1),int_mb(k_range+p3b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_5_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('ccsd_lambda1_mod_5_
     &2_2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &2_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('
     &ccsd_lambda1_mod_5_2_2',9,MA_ERR)
      IF ((h11b .le. h12b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+h7b-1),int_mb(k_range+h2b-1),int_mb(k_range+h11b-
     &1),3,2,4,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h11b - 1 + noab * (h7b - 1 + noab * (h2b - 1)))))
      END IF
      IF ((h12b .le. h11b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+h7b-1),int_mb(k_range+h2b-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 * (h12b - 1 + noab * (h7b - 1 + noab * (h2b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_5_2_2',
     &10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &2_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 ccsd_lambda1_mod_5_2_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     i3 ( h2 h7 h12 p3 )_v + = 1 * v ( h2 h7 h12 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h7b
      INTEGER h12b
      INTEGER p3b
      INTEGER dimc
      INTEGER h2b_1
      INTEGER h7b_1
      INTEGER h12b_1
      INTEGER p3b_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 h2b = 1,noab
      DO h7b = 1,noab
      DO h12b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p3b-1)))) .eq. irrep_v) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_mb(k_ra
     &nge+h12b-1) * int_mb(k_range+p3b-1)
      CALL TCE_RESTRICTED_4(h2b,h7b,h12b,p3b,h2b_1,h7b_1,h12b_1,p3b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_mb
     &(k_range+h12b-1) * int_mb(k_range+p3b-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('ccsd_lambda1_mod_5_2_2_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_2_2_1',1,MA_ERR)
      IF ((h7b .lt. h2b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p3b_1
     & - 1 + (noab+nvab) * (h12b_1 - 1 + (noab+nvab) * (h2b_1 - 1 + (noa
     &b+nvab) * (h7b_1 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),
     &(p3b_1
     & - 1 + (noab+nvab) * (h12b_1 - 1 + (noab+nvab) * (h2b_1 - 1 + (noa
     &b+nvab) * (h7b_1 - 1)))),p3b_1,h12b_1,h2b_1,h7b_1)
      end if
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h7b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h12b-1),int_mb(k_range+p3b-1
     &),4,3,1,2,-1.0d0)
      END IF
      IF ((h2b .le. h7b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p3b_1
     & - 1 + (noab+nvab) * (h12b_1 - 1 + (noab+nvab) * (h7b_1 - 1 + (noa
     &b+nvab) * (h2b_1 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),
     &(p3b_1
     & - 1 + (noab+nvab) * (h12b_1 - 1 + (noab+nvab) * (h7b_1 - 1 + (noa
     &b+nvab) * (h2b_1 - 1)))),p3b_1,h12b_1,h7b_1,h2b_1)
      end if
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+h12b-1),int_mb(k_range+p3b-1
     &),4,3,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_5_2_2_1
     &',2,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_2_2_1',3,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h12b-1),int_mb(k_range+h7b-1),int_mb(k_range+h2b-1
     &),4,3,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (h12b - 1 + noab * (h7b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_5_2_2_1
     &',4,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &2_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
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_lambda1_mod_5_2_2_1(l_a_offset,k_a_offset,s
     &ize)
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     i3 ( h2 h7 h12 p3 )_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 h2b
      INTEGER h7b
      INTEGER h12b
      INTEGER p3b
      length = 0
      DO h2b = 1,noab
      DO h7b = 1,noab
      DO h12b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p3b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p3b-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('ccsd_lambda1_mod_5_2_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h7b = 1,noab
      DO h12b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p3b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p3b - noab - 1 + nvab * (h12b - 1 + noab
     & * (h7b - 1 + noab * (h2b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_
     &mb(k_range+h12b-1) * int_mb(k_range+p3b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_5_2_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     i3 ( h2 h7 h12 p3 )_vt + = -1/2 * Sum ( p5 ) * t ( p5 h12 )_t * v ( h2 h7 p3 p5 )_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 h2b
      INTEGER h7b
      INTEGER h12b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h12b_1
      INTEGER h2b_2
      INTEGER h7b_2
      INTEGER p3b_2
      INTEGER p5b_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 h2b = 1,noab
      DO h7b = 1,noab
      DO h12b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_v,irrep_t)) T
     &HEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_mb(k_ra
     &nge+h12b-1) * int_mb(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_2_2_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h12b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p5b,h12b,p5b_1,h12b_1)
      CALL TCE_RESTRICTED_4(h2b,h7b,p3b,p5b,h2b_2,h7b_2,p3b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1)
      dima_sort = int_mb(k_range+h12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_mb
     &(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_2_2_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_2_2_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (p5b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p5b-1)
     &,int_mb(k_range+h12b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_5_2_2_2
     &',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_2_2_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_2_2_2',5,MA_ERR)
      IF ((h7b .lt. h2b) .and. (p5b .lt. p3b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h7b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p3b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h7b_2 - 1)))),p3b_2,p5b_2,h2b_2,h7b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h7b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p5b-1),int_mb(k_range+p3b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h7b .lt. h2b) .and. (p3b .le. p5b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h7b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p5b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h7b_2 - 1)))),p5b_2,p3b_2,h2b_2,h7b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h7b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p3b-1),int_mb(k_range+p5b-1)
     &,3,1,2,4,-1.0d0)
      END IF
      IF ((h2b .le. h7b) .and. (p5b .lt. p3b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h7b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p3b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h7b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p3b_2,p5b_2,h7b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+p5b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h2b .le. h7b) .and. (p3b .le. p5b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h7b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p5b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h7b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p5b_2,p3b_2,h7b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_mb(k_range+p5b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_5_2_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('ccsd_lambda1_mod_5_
     &2_2_2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &2_2_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('
     &ccsd_lambda1_mod_5_2_2_2',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+h2b-1),int_mb(k_range+h12b-1
     &),3,2,4,1,-1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (h12b - 1 + noab * (h7b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_5_2_2_2
     &',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &2_2_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 ccsd_lambda1_mod_5_2_3(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     i2 ( h2 h7 h11 h12 )_vt + = 1/2 * Sum ( p3 p4 ) * t ( p3 p4 h11 h12 )_t * v ( h2 h7 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 d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h7b
      INTEGER h11b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p4b
      INTEGER p3b_1
      INTEGER p4b_1
      INTEGER h11b_1
      INTEGER h12b_1
      INTEGER h2b_2
      INTEGER h7b_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
      INTEGER nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO h7b = 1,noab
      DO h11b = 1,noab
      DO h12b = h11b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_v,irrep_t)) 
     &THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_2_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      DO p4b = p3b,noab+nvab
      IF (int_mb(k_spin+p3b-1)+int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),ieor(int_mb(k_sym+p4b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p3b,p4b,h11b,h12b,p3b_1,p4b_1,h11b_1,h12b_1)
      CALL TCE_RESTRICTED_4(h2b,h7b,p3b,p4b,h2b_2,h7b_2,p3b_2,p4b_2)
      dim_common = int_mb(k_range+p3b-1) * int_mb(k_range+p4b-1)
      dima_sort = int_mb(k_range+h11b-1) * int_mb(k_range+h12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-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('ccsd_lambda1_mod_5_2_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_2_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (h11b_1 - 1 + noab * (p4b_1 - noab - 1 + nvab * (p3
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p4b-1),int_mb(k_range+h11b-1),int_mb(k_range+h12b-
     &1),4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_5_2_3',
     &3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_2_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_2_3',5,MA_ERR)
      IF ((h7b .lt. h2b)) THEN
      if(.not.intorb) then
      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) * (h2b_2 - 1 + (noab
     &+nvab) * (h7b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p4b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h7b_2 - 1)))),p4b_2,p3b_2,h2b_2,h7b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h7b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p3b-1),int_mb(k_range+p4b-1)
     &,1,2,4,3,-1.0d0)
      END IF
      IF ((h2b .le. h7b)) THEN
      if(.not.intorb) then 
      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) * (h7b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p4b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h7b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p4b_2,p3b_2,h7b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_mb(k_range+p4b-1)
     &,2,1,4,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_5_2_3',
     &6,MA_ERR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p3b .eq. p4b) THEN
      nsuperp(isuperp) = nsuperp(isuperp) + 1
      ELSE
      isuperp = isuperp + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsuperp(1))/FACTORIAL(nsuperp(2)),dbl_mb(k_a_sort),dim_common,dbl_
     &mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &2_3',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &2_3',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('
     &ccsd_lambda1_mod_5_2_3',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h7b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h12b-1),int_mb(k_range+h11b-
     &1),2,1,4,3,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h11b - 1 + noab * (h7b - 1 + noab * (h2b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_5_2_3',
     &10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &2_3',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 ccsd_lambda1_mod_5_3(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 ( h2 p9 h11 h12 )_vt + = -2 * Sum ( p3 ) * t ( p3 h11 )_t * i2 ( h2 p9 h12 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p9b
      INTEGER h11b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h11b_1
      INTEGER h2b_2
      INTEGER p9b_2
      INTEGER h12b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h11b = 1,noab
      DO h12b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_v,irrep_t)) 
     &THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h11b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p3b,h11b,p3b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h2b,p9b,h12b,p3b,h2b_2,p9b_2,h12b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h11b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb
     &(k_range+h12b-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('ccsd_lambda1_mod_5_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (p3b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h11b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_5_3',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_3',5,MA_ERR)
      IF ((h12b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h12b_2 - 1 + noab * (p9b_2 - noab - 1 + nvab
     & * (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h12b-1),int_mb(k_range+p3b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_5_3',6,
     &MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &3',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &3',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('
     &ccsd_lambda1_mod_5_3',9,MA_ERR)
      IF ((h11b .le. h12b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+p9b-1),int_mb(k_range+h2b-1),int_mb(k_range+h11b-
     &1),3,2,4,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h11b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      END IF
      IF ((h12b .le. h11b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+p9b-1),int_mb(k_range+h2b-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 * (h12b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_5_3',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &3',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 ccsd_lambda1_mod_5_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     i2 ( h2 p9 h12 p3 )_v + = 1 * v ( h2 p9 h12 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p9b
      INTEGER h12b
      INTEGER p3b
      INTEGER dimc
      INTEGER h2b_1
      INTEGER p9b_1
      INTEGER h12b_1
      INTEGER p3b_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 h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h12b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p3b-1)))) .eq. irrep_v) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h12b-1) * int_mb(k_range+p3b-1)
      CALL TCE_RESTRICTED_4(h2b,p9b,h12b,p3b,h2b_1,p9b_1,h12b_1,p3b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb
     &(k_range+h12b-1) * int_mb(k_range+p3b-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('ccsd_lambda1_mod_5_3_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_3_1',1,MA_ERR)
      IF ((h2b .le. p9b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p3b_1
     & - 1 + (noab+nvab) * (h12b_1 - 1 + (noab+nvab) * (p9b_1 - 1 + (noa
     &b+nvab) * (h2b_1 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),
     &(p3b_1
     & - 1 + (noab+nvab) * (h12b_1 - 1 + (noab+nvab) * (p9b_1 - 1 + (noa
     &b+nvab) * (h2b_1 - 1)))),p3b_1,h12b_1,p9b_1,h2b_1)
      end if
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h12b-1),int_mb(k_range+p3b-1
     &),4,3,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_5_3_1',
     &2,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_3_1',3,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h12b-1),int_mb(k_range+p9b-1),int_mb(k_range+h2b-1
     &),4,3,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (h12b - 1 + noab * (p9b - noab - 1 + nvab * (h2
     &b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_5_3_1',
     &4,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &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_ccsd_lambda1_mod_5_3_1(l_a_offset,k_a_offset,siz
     &e)
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     i2 ( h2 p9 h12 p3 )_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 h2b
      INTEGER p9b
      INTEGER h12b
      INTEGER p3b
      length = 0
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h12b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p3b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p3b-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('ccsd_lambda1_mod_5_3_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h12b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p3b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p3b - noab - 1 + nvab * (h12b - 1 + noab
     & * (p9b - noab - 1 + nvab * (h2b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_
     &mb(k_range+h12b-1) * int_mb(k_range+p3b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_5_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     i2 ( h2 p9 h12 p3 )_vt + = -1/2 * Sum ( p5 ) * t ( p5 h12 )_t * v ( h2 p9 p3 p5 )_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 h2b
      INTEGER p9b
      INTEGER h12b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h12b_1
      INTEGER h2b_2
      INTEGER p9b_2
      INTEGER p3b_2
      INTEGER p5b_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 h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h12b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_v,irrep_t)) T
     &HEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h12b-1) * int_mb(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_3_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h12b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p5b,h12b,p5b_1,h12b_1)
      CALL TCE_RESTRICTED_4(h2b,p9b,p3b,p5b,h2b_2,p9b_2,p3b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1)
      dima_sort = int_mb(k_range+h12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb
     &(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_3_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_3_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (p5b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p5b-1)
     &,int_mb(k_range+h12b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_5_3_2',
     &3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_3_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_3_2',5,MA_ERR)
      IF ((h2b .le. p9b) .and. (p5b .lt. p3b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p3b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p3b_2,p5b_2,p9b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+p5b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h2b .le. p9b) .and. (p3b .le. p5b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p5b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p5b_2,p3b_2,p9b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+p3b-1),int_mb(k_range+p5b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_5_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('ccsd_lambda1_mod_5_
     &3_2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &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('
     &ccsd_lambda1_mod_5_3_2',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h2b-1),int_mb(k_range+h12b-1
     &),3,2,4,1,-1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (h12b - 1 + noab * (p9b - noab - 1 + nvab * (h2
     &b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_5_3_2',
     &10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &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 ccsd_lambda1_mod_5_4(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 ( h2 p9 h11 h12 )_ft + = 1 * Sum ( p5 ) * t ( p5 p9 h11 h12 )_t * i2 ( h2 p5 )_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 d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p9b
      INTEGER h11b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p9b_1
      INTEGER p5b_1
      INTEGER h11b_1
      INTEGER h12b_1
      INTEGER h2b_2
      INTEGER p5b_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 h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h11b = 1,noab
      DO h12b = h11b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_f,irrep_t)) 
     &THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_4',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p5b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p9b,p5b,h11b,h12b,p9b_1,p5b_1,h11b_1,h12b_1)
      CALL TCE_RESTRICTED_2(h2b,p5b,h2b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1)
      dima_sort = int_mb(k_range+p9b-1) * int_mb(k_range+h11b-1) * int_m
     &b(k_range+h12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-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('ccsd_lambda1_mod_5_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_4',2,MA_ERR)
      IF ((p5b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (h11b_1 - 1 + noab * (p9b_1 - noab - 1 + nvab * (p5
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p5b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h11b-1),int_mb(k_range+h12b-
     &1),4,3,2,1,1.0d0)
      END IF
      IF ((p9b .lt. p5b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (h11b_1 - 1 + noab * (p5b_1 - noab - 1 + nvab * (p9
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+p5b-1),int_mb(k_range+h11b-1),int_mb(k_range+h12b-
     &1),4,3,1,2,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_5_4',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_4',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (h2b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p5b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_5_4',6,
     &MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &4',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &4',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('
     &ccsd_lambda1_mod_5_4',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h12b-1),int_mb(k_range+h11b-1),int_mb(k_range+p9b-
     &1),1,4,3,2,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h11b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_5_4',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &4',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 ccsd_lambda1_mod_5_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     i2 ( h2 p5 )_f + = 1 * f ( h2 p5 )_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 h2b
      INTEGER p5b
      INTEGER dimc
      INTEGER h2b_1
      INTEGER p5b_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 h2b = 1,noab
      DO p5b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p5b-1)) .eq. irrep_f) TH
     &EN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p5b-1)
      CALL TCE_RESTRICTED_2(h2b,p5b,h2b_1,p5b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h2b-1) * int_mb(k_range+p5b-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('ccsd_lambda1_mod_5_4_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_4_1',1,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p5b_1
     & - 1 + (noab+nvab) * (h2b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p5b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_5_4_1',
     &2,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_4_1',3,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+p5b-1)
     &,int_mb(k_range+h2b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p5b -
     & noab - 1 + nvab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_5_4_1',
     &4,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &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
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_lambda1_mod_5_4_1(l_a_offset,k_a_offset,siz
     &e)
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     i2 ( h2 p5 )_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 h2b
      INTEGER p5b
      length = 0
      DO h2b = 1,noab
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p5b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-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('ccsd_lambda1_mod_5_4_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p5b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p5b - noab - 1 + nvab * (h2b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+p5b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_5_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     i2 ( h2 p5 )_vt + = 1 * Sum ( h8 p7 ) * t ( p7 h8 )_t * v ( h2 h8 p5 p7 )_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 h2b
      INTEGER p5b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER h8b
      INTEGER p7b_1
      INTEGER h8b_1
      INTEGER h2b_2
      INTEGER h8b_2
      INTEGER p5b_2
      INTEGER p7b_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 h2b = 1,noab
      DO p5b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p5b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p5b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_4_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      DO h8b = 1,noab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h8b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p7b,h8b,p7b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,p5b,p7b,h2b_2,h8b_2,p5b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1) * int_mb(k_range+h8b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+p5b-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('ccsd_lambda1_mod_5_4_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_4_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_5_4_2',
     &3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_4_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_4_2',5,MA_ERR)
      IF ((h8b .lt. h2b) .and. (p7b .lt. p5b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p5b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p5b_2,p7b_2,h2b_2,h8b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p7b-1),int_mb(k_range+p5b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h8b .lt. h2b) .and. (p5b .le. p7b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p7b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p7b_2,p5b_2,h2b_2,h8b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p5b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF ((h2b .le. h8b) .and. (p7b .lt. p5b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p5b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p5b_2,p7b_2,h8b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h8b-1),int_mb(k_range+p7b-1),int_mb(k_range+p5b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h2b .le. h8b) .and. (p5b .le. p7b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p7b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p7b_2,p5b_2,h8b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h8b-1),int_mb(k_range+p5b-1),int_mb(k_range+p7b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_5_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('ccsd_lambda1_mod_5_
     &4_2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &4_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('
     &ccsd_lambda1_mod_5_4_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p5b-1)
     &,int_mb(k_range+h2b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p5b -
     & noab - 1 + nvab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_5_4_2',
     &10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &4_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 ccsd_lambda1_mod_5_5(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 ( h2 p9 h11 h12 )_vt + = -2 * Sum ( h6 p4 ) * t ( p4 p9 h6 h11 )_t * i2 ( h2 h6 h12 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 d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p9b
      INTEGER h11b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p4b
      INTEGER h6b
      INTEGER p9b_1
      INTEGER p4b_1
      INTEGER h11b_1
      INTEGER h6b_1
      INTEGER h2b_2
      INTEGER h6b_2
      INTEGER h12b_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
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h11b = 1,noab
      DO h12b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_v,irrep_t)) 
     &THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_5',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p4b = noab+1,noab+nvab
      DO h6b = 1,noab
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p4b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h6b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p9b,p4b,h11b,h6b,p9b_1,p4b_1,h11b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h2b,h6b,h12b,p4b,h2b_2,h6b_2,h12b_2,p4b_2)
      dim_common = int_mb(k_range+p4b-1) * int_mb(k_range+h6b-1)
      dima_sort = int_mb(k_range+p9b-1) * int_mb(k_range+h11b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h12b-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('ccsd_lambda1_mod_5_5',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_5',2,MA_ERR)
      IF ((p4b .le. p9b) .and. (h6b .le. h11b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (h6b_1 - 1 + noab * (p9b_1 - noab - 1 + nvab * (p4b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p4b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h6b-1),int_mb(k_range+h11b-1
     &),4,2,3,1,1.0d0)
      END IF
      IF ((p4b .le. p9b) .and. (h11b .lt. h6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h11b_1 - 1 + noab * (p9b_1 - noab - 1 + nvab * (p4b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p4b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h11b-1),int_mb(k_range+h6b-1
     &),3,2,4,1,-1.0d0)
      END IF
      IF ((p9b .lt. p4b) .and. (h6b .le. h11b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (h6b_1 - 1 + noab * (p4b_1 - noab - 1 + nvab * (p9b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+p4b-1),int_mb(k_range+h6b-1),int_mb(k_range+h11b-1
     &),4,1,3,2,-1.0d0)
      END IF
      IF ((p9b .lt. p4b) .and. (h11b .lt. h6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h11b_1 - 1 + noab * (p4b_1 - noab - 1 + nvab * (p9b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+p4b-1),int_mb(k_range+h11b-1),int_mb(k_range+h6b-1
     &),3,1,4,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_5_5',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_5',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_5',5,MA_ERR)
      IF ((h12b .le. p4b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p4b_2
     & - noab - 1 + nvab * (h12b_2 - 1 + noab * (h6b_2 - 1 + noab * (h2b
     &_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h12b-1),int_mb(k_range+p4b-1
     &),3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_5_5',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('ccsd_lambda1_mod_5_
     &5',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &5',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('
     &ccsd_lambda1_mod_5_5',9,MA_ERR)
      IF ((h11b .le. h12b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+h2b-1),int_mb(k_range+h11b-1),int_mb(k_range+p9b-
     &1),2,4,3,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h11b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      END IF
      IF ((h12b .le. h11b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+h2b-1),int_mb(k_range+h11b-1),int_mb(k_range+p9b-
     &1),2,4,1,3,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h12b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_5_5',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &5',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 ccsd_lambda1_mod_5_5_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     i2 ( h2 h6 h12 p4 )_v + = 1 * v ( h2 h6 h12 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_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h6b
      INTEGER h12b
      INTEGER p4b
      INTEGER dimc
      INTEGER h2b_1
      INTEGER h6b_1
      INTEGER h12b_1
      INTEGER p4b_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 h2b = 1,noab
      DO h6b = 1,noab
      DO h12b = 1,noab
      DO p4b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p4b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p4b-1)))) .eq. irrep_v) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h6b-1) * int_mb(k_ra
     &nge+h12b-1) * int_mb(k_range+p4b-1)
      CALL TCE_RESTRICTED_4(h2b,h6b,h12b,p4b,h2b_1,h6b_1,h12b_1,p4b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h6b-1) * int_mb
     &(k_range+h12b-1) * int_mb(k_range+p4b-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('ccsd_lambda1_mod_5_5_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_5_1',1,MA_ERR)
      IF ((h6b .lt. h2b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p4b_1
     & - 1 + (noab+nvab) * (h12b_1 - 1 + (noab+nvab) * (h2b_1 - 1 + (noa
     &b+nvab) * (h6b_1 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),
     &(p4b_1
     & - 1 + (noab+nvab) * (h12b_1 - 1 + (noab+nvab) * (h2b_1 - 1 + (noa
     &b+nvab) * (h6b_1 - 1)))),p4b_1,h12b_1,h2b_1,h6b_1)
      end if
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h12b-1),int_mb(k_range+p4b-1
     &),4,3,1,2,-1.0d0)
      END IF
      IF ((h2b .le. h6b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p4b_1
     & - 1 + (noab+nvab) * (h12b_1 - 1 + (noab+nvab) * (h6b_1 - 1 + (noa
     &b+nvab) * (h2b_1 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),
     &(p4b_1
     & - 1 + (noab+nvab) * (h12b_1 - 1 + (noab+nvab) * (h6b_1 - 1 + (noa
     &b+nvab) * (h2b_1 - 1)))),p4b_1,h12b_1,h6b_1,h2b_1)
      end if
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h12b-1),int_mb(k_range+p4b-1
     &),4,3,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_5_5_1',
     &2,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_5_1',3,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+p4b-1)
     &,int_mb(k_range+h12b-1),int_mb(k_range+h6b-1),int_mb(k_range+h2b-1
     &),4,3,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p4b -
     & noab - 1 + nvab * (h12b - 1 + noab * (h6b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_5_5_1',
     &4,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &5_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_ccsd_lambda1_mod_5_5_1(l_a_offset,k_a_offset,siz
     &e)
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     i2 ( h2 h6 h12 p4 )_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 h2b
      INTEGER h6b
      INTEGER h12b
      INTEGER p4b
      length = 0
      DO h2b = 1,noab
      DO h6b = 1,noab
      DO h12b = 1,noab
      DO p4b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p4b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p4b-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('ccsd_lambda1_mod_5_5_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h6b = 1,noab
      DO h12b = 1,noab
      DO p4b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p4b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p4b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p4b - noab - 1 + nvab * (h12b - 1 + noab
     & * (h6b - 1 + noab * (h2b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+h6b-1) * int_
     &mb(k_range+h12b-1) * int_mb(k_range+p4b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_5_5_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     i2 ( h2 h6 h12 p4 )_vt + = -1 * Sum ( p7 ) * t ( p7 h12 )_t * v ( h2 h6 p4 p7 )_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 h2b
      INTEGER h6b
      INTEGER h12b
      INTEGER p4b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h12b_1
      INTEGER h2b_2
      INTEGER h6b_2
      INTEGER p4b_2
      INTEGER p7b_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 h2b = 1,noab
      DO h6b = 1,noab
      DO h12b = 1,noab
      DO p4b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p4b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p4b-1)))) .eq. ieor(irrep_v,irrep_t)) T
     &HEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h6b-1) * int_mb(k_ra
     &nge+h12b-1) * int_mb(k_range+p4b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_5_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h12b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p7b,h12b,p7b_1,h12b_1)
      CALL TCE_RESTRICTED_4(h2b,h6b,p4b,p7b,h2b_2,h6b_2,p4b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h6b-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('ccsd_lambda1_mod_5_5_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_5_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h12b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_5_5_2',
     &3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_5_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_5_2',5,MA_ERR)
      IF ((h6b .lt. h2b) .and. (p7b .lt. p4b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p4b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p4b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p7b-1),int_mb(k_range+p4b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h6b .lt. h2b) .and. (p4b .le. p7b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - 1 + (noab+nvab) * (p4b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p7b_2
     & - 1 + (noab+nvab) * (p4b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p7b_2,p4b_2,h2b_2,h6b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p4b-1),int_mb(k_range+p7b-1)
     &,3,1,2,4,-1.0d0)
      END IF
      IF ((h2b .le. h6b) .and. (p7b .lt. p4b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p4b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p4b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p4b_2,p7b_2,h6b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p7b-1),int_mb(k_range+p4b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h2b .le. h6b) .and. (p4b .le. p7b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - 1 + (noab+nvab) * (p4b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p7b_2
     & - 1 + (noab+nvab) * (p4b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p7b_2,p4b_2,h6b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p4b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_5_5_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('ccsd_lambda1_mod_5_
     &5_2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &5_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('
     &ccsd_lambda1_mod_5_5_2',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p4b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h2b-1),int_mb(k_range+h12b-1
     &),3,2,4,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p4b -
     & noab - 1 + nvab * (h12b - 1 + noab * (h6b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_5_5_2',
     &10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &5_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 ccsd_lambda1_mod_5_6(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 ( h2 p9 h11 h12 )_vt + = 1/2 * Sum ( p3 p4 ) * t ( p3 p4 h11 h12 )_t * v ( h2 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 d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p9b
      INTEGER h11b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p4b
      INTEGER p3b_1
      INTEGER p4b_1
      INTEGER h11b_1
      INTEGER h12b_1
      INTEGER h2b_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
      INTEGER nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h11b = 1,noab
      DO h12b = h11b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_v,irrep_t)) 
     &THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_6',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      DO p4b = p3b,noab+nvab
      IF (int_mb(k_spin+p3b-1)+int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),ieor(int_mb(k_sym+p4b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p3b,p4b,h11b,h12b,p3b_1,p4b_1,h11b_1,h12b_1)
      CALL TCE_RESTRICTED_4(h2b,p9b,p3b,p4b,h2b_2,p9b_2,p3b_2,p4b_2)
      dim_common = int_mb(k_range+p3b-1) * int_mb(k_range+p4b-1)
      dima_sort = int_mb(k_range+h11b-1) * int_mb(k_range+h12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-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('ccsd_lambda1_mod_5_6',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_6',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (h11b_1 - 1 + noab * (p4b_1 - noab - 1 + nvab * (p3
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p4b-1),int_mb(k_range+h11b-1),int_mb(k_range+h12b-
     &1),4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_5_6',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_5_6',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_5_6',5,MA_ERR)
      IF ((h2b .le. p9b)) THEN
      if(.not.intorb) then
      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) * (p9b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p4b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p4b_2,p3b_2,p9b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+p3b-1),int_mb(k_range+p4b-1)
     &,2,1,4,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_5_6',6,
     &MA_ERR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p3b .eq. p4b) THEN
      nsuperp(isuperp) = nsuperp(isuperp) + 1
      ELSE
      isuperp = isuperp + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsuperp(1))/FACTORIAL(nsuperp(2)),dbl_mb(k_a_sort),dim_common,dbl_
     &mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &6',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &6',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('
     &ccsd_lambda1_mod_5_6',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p9b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h12b-1),int_mb(k_range+h11b-
     &1),2,1,4,3,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h11b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_5_6',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_5_
     &6',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 ccsd_lambda1_mod_6(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     i0 ( h2 p1 )_yv + = 1/2 * Sum ( h7 p5 p8 ) * y ( h2 h7 p5 p8 )_y * i1 ( p5 p8 h7 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_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h7b
      INTEGER p5b
      INTEGER p8b
      INTEGER h2b_1
      INTEGER h7b_1
      INTEGER p5b_1
      INTEGER p8b_1
      INTEGER p5b_2
      INTEGER p8b_2
      INTEGER p1b_2
      INTEGER h7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER nsubp(2)
      INTEGER isubp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &y,irrep_v)) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_6',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h7b = 1,noab
      DO p5b = noab+1,noab+nvab
      DO p8b = p5b,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+p
     &5b-1)+int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+p5b-1),int_mb(k_sym+p8b-1)))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_4(h2b,h7b,p5b,p8b,h2b_1,h7b_1,p5b_1,p8b_1)
      CALL TCE_RESTRICTED_4(p5b,p8b,p1b,h7b,p5b_2,p8b_2,p1b_2,h7b_2)
      dim_common = int_mb(k_range+h7b-1) * int_mb(k_range+p5b-1) * int_m
     &b(k_range+p8b-1)
      dima_sort = int_mb(k_range+h2b-1)
      dima = dim_common * dima_sort
      dimb_sort = 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('ccsd_lambda1_mod_6',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_6',2,MA_ERR)
      IF ((h7b .lt. h2b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p8b_1
     & - noab - 1 + nvab * (p5b_1 - noab - 1 + nvab * (h2b_1 - 1 + noab 
     &* (h7b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h7b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p5b-1),int_mb(k_range+p8b-1)
     &,2,4,3,1,-1.0d0)
      END IF
      IF ((h2b .le. h7b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p8b_1
     & - noab - 1 + nvab * (p5b_1 - noab - 1 + nvab * (h7b_1 - 1 + noab 
     &* (h2b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+p5b-1),int_mb(k_range+p8b-1)
     &,1,4,3,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_6',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_6',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_6',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h7b_2
     & - 1 + noab * (p1b_2 - noab - 1 + nvab * (p8b_2 - noab - 1 + nvab 
     &* (p5b_2 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+p5b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+p1b-1),int_mb(k_range+h7b-1)
     &,3,2,1,4,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_6',6,MA
     &_ERR)
      nsubp(1) = 1
      nsubp(2) = 1
      isubp = 1
      IF (p5b .eq. p8b) THEN
      nsubp(isubp) = nsubp(isubp) + 1
      ELSE
      isubp = isubp + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsubp(1))/FACTORIAL(nsubp(2)),dbl_mb(k_a_sort),dim_common,dbl_mb(k
     &_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_6'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_6'
     &,8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_6',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+h2b-1),2,1,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_6',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_6'
     &,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 ccsd_lambda1_mod_6_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 ( p5 p8 h7 p1 )_v + = -1 * v ( p5 p8 h7 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 p5b
      INTEGER p8b
      INTEGER p1b
      INTEGER h7b
      INTEGER dimc
      INTEGER p5b_1
      INTEGER p8b_1
      INTEGER p1b_1
      INTEGER h7b_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 p5b = noab+1,noab+nvab
      DO p8b = p5b,noab+nvab
      DO p1b = noab+1,noab+nvab
      DO h7b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p5b-1)+int_mb(k_spin+p8b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+h7b-1).ne.8)) THEN
      IF (int_mb(k_spin+p5b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+h7b-1)))) .eq. irrep_v) THEN
      dimc = int_mb(k_range+p5b-1) * int_mb(k_range+p8b-1) * int_mb(k_ra
     &nge+p1b-1) * int_mb(k_range+h7b-1)
      CALL TCE_RESTRICTED_4(p5b,p8b,p1b,h7b,p5b_1,p8b_1,p1b_1,h7b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+p5b-1) * int_mb(k_range+p8b-1) * int_mb
     &(k_range+p1b-1) * int_mb(k_range+h7b-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('ccsd_lambda1_mod_6_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_6_1',1,MA_ERR)
      IF ((h7b .le. p1b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p1b_1
     & - 1 + (noab+nvab) * (h7b_1 - 1 + (noab+nvab) * (p8b_1 - 1 + (noab
     &+nvab) * (p5b_1 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),
     &(p1b_1
     & - 1 + (noab+nvab) * (h7b_1 - 1 + (noab+nvab) * (p8b_1 - 1 + (noab
     &+nvab) * (p5b_1 - 1)))),p1b_1,h7b_1,p8b_1,p5b_1)
      end if
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p5b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p1b-1)
     &,3,4,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_6_1',2,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_6_1',3,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+h7b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+p8b-1),int_mb(k_range+p5b-1)
     &,4,3,2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h7b -
     & 1 + noab * (p1b - noab - 1 + nvab * (p8b - noab - 1 + nvab * (p5b
     & - noab - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_6_1',4,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_6_
     &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_ccsd_lambda1_mod_6_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 ( p5 p8 h7 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 p5b
      INTEGER p8b
      INTEGER p1b
      INTEGER h7b
      length = 0
      DO p5b = noab+1,noab+nvab
      DO p8b = p5b,noab+nvab
      DO p1b = noab+1,noab+nvab
      DO h7b = 1,noab
      IF (int_mb(k_spin+p5b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h
     &7b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+h7b-1),int_mb(k_sym+p1b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p5b-1)+int_mb(k_spin+p8b-1
     &)+int_mb(k_spin+h7b-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('ccsd_lambda1_mod_6_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO p5b = noab+1,noab+nvab
      DO p8b = p5b,noab+nvab
      DO p1b = noab+1,noab+nvab
      DO h7b = 1,noab
      IF (int_mb(k_spin+p5b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h
     &7b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+h7b-1),int_mb(k_sym+p1b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p5b-1)+int_mb(k_spin+p8b-1
     &)+int_mb(k_spin+h7b-1)+int_mb(k_spin+p1b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h7b - 1 + noab * (p1b - noab - 1 + nvab 
     &* (p8b - noab - 1 + nvab * (p5b - noab - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+p5b-1) * int_mb(k_range+p8b-1) * int_
     &mb(k_range+p1b-1) * int_mb(k_range+h7b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_6_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 ( p5 p8 h7 p1 )_vt + = 1 * Sum ( p3 ) * t ( p3 h7 )_t * v ( p5 p8 p1 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p5b
      INTEGER p8b
      INTEGER p1b
      INTEGER h7b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h7b_1
      INTEGER p5b_2
      INTEGER p8b_2
      INTEGER p1b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO p5b = noab+1,noab+nvab
      DO p8b = p5b,noab+nvab
      DO p1b = noab+1,noab+nvab
      DO h7b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p5b-1)+int_mb(k_spin+p8b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+h7b-1).ne.8)) THEN
      IF (int_mb(k_spin+p5b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+h7b-1)))) .eq. ieor(irrep_v,irrep_t)) TH
     &EN
      dimc = int_mb(k_range+p5b-1) * int_mb(k_range+p8b-1) * int_mb(k_ra
     &nge+p1b-1) * int_mb(k_range+h7b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_6_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h7b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p3b,h7b,p3b_1,h7b_1)
      CALL TCE_RESTRICTED_4(p5b,p8b,p1b,p3b,p5b_2,p8b_2,p1b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h7b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p5b-1) * int_mb(k_range+p8b-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('ccsd_lambda1_mod_6_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_6_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_1
     & - 1 + noab * (p3b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h7b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_6_2',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_6_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_6_2',5,MA_ERR)
      IF ((p3b .lt. p1b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (p8b_2 - 1 + (noab
     &+nvab) * (p5b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (p8b_2 - 1 + (noab
     &+nvab) * (p5b_2 - 1)))),p1b_2,p3b_2,p8b_2,p5b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+p5b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p1b .le. p3b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (p8b_2 - 1 + (noab
     &+nvab) * (p5b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p3b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (p8b_2 - 1 + (noab
     &+nvab) * (p5b_2 - 1)))),p3b_2,p1b_2,p8b_2,p5b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+p5b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+p1b-1),int_mb(k_range+p3b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_6_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('ccsd_lambda1_mod_6_
     &2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_6_
     &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('
     &ccsd_lambda1_mod_6_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+p8b-1),int_mb(k_range+p5b-1),int_mb(k_range+h7b-1)
     &,3,2,1,4,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h7b -
     & 1 + noab * (p1b - noab - 1 + nvab * (p8b - noab - 1 + nvab * (p5b
     & - noab - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_6_2',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_6_
     &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 ccsd_lambda1_mod_7(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     i0 ( h2 p1 )_vt + = 1 * Sum ( h10 p9 ) * i1 ( p9 h10 )_t * v ( h2 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 h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p9b
      INTEGER h10b
      INTEGER p9b_1
      INTEGER h10b_1
      INTEGER h2b_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 h2b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_7',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(h2b,h10b,p1b,p9b,h2b_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+h2b-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('ccsd_lambda1_mod_7',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_7',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('ccsd_lambda1_mod_7',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_7',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_7',5,MA_ERR)
      IF ((h10b .lt. h2b) .and. (p9b .lt. p1b)) THEN
      if(.not.intorb) 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) * (h2b_2 - 1 + (noab
     &+nvab) * (h10b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (p9b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h10b_2 - 1)))),p1b_2,p9b_2,h2b_2,h10b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h10b-1
     &),int_mb(k_range+h2b-1),int_mb(k_range+p9b-1),int_mb(k_range+p1b-1
     &),4,2,1,3,1.0d0)
      END IF
      IF ((h10b .lt. h2b) .and. (p1b .le. p9b)) THEN
      if(.not.intorb) 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) * (h2b_2 - 1 + (noab
     &+nvab) * (h10b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p9b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h10b_2 - 1)))),p9b_2,p1b_2,h2b_2,h10b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h10b-1
     &),int_mb(k_range+h2b-1),int_mb(k_range+p1b-1),int_mb(k_range+p9b-1
     &),3,2,1,4,-1.0d0)
      END IF
      IF ((h2b .le. h10b) .and. (p9b .lt. p1b)) THEN
      if(.not.intorb) 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) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(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) * (h2b_2 - 1)))),p1b_2,p9b_2,h10b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-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 ((h2b .le. h10b) .and. (p1b .le. p9b)) THEN
      if(.not.intorb) 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) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(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) * (h2b_2 - 1)))),p9b_2,p1b_2,h10b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-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('ccsd_lambda1_mod_7',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('ccsd_lambda1_mod_7'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7'
     &,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('
     &ccsd_lambda1_mod_7',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+h2b-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 * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_7',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7'
     &,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 ccsd_lambda1_mod_7_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 ( p9 h10 )_t + = 1 * t ( p9 h10 )_t
      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 p9b
      INTEGER h10b
      INTEGER dimc
      INTEGER p9b_1
      INTEGER h10b_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 p9b = noab+1,noab+nvab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p9b-1)+int_mb(k_spin+h10b-
     &1).ne.4)) THEN
      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
      dimc = int_mb(k_range+p9b-1) * int_mb(k_range+h10b-1)
      CALL TCE_RESTRICTED_2(p9b,h10b,p9b_1,h10b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+p9b-1) * int_mb(k_range+h10b-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('ccsd_lambda1_mod_7_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_7_1',1,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('ccsd_lambda1_mod_7_1',2,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_7_1',3,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+h10b-1
     &),int_mb(k_range+p9b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (p9b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_7_1',4,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7_
     &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_ccsd_lambda1_mod_7_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 ( p9 h10 )_t
      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 p9b
      INTEGER h10b
      length = 0
      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
      IF ((.not.restricted).or.(int_mb(k_spin+p9b-1)+int_mb(k_spin+h10b-
     &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('ccsd_lambda1_mod_7_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      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
      IF ((.not.restricted).or.(int_mb(k_spin+p9b-1)+int_mb(k_spin+h10b-
     &1).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h10b - 1 + noab * (p9b - noab - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+p9b-1) * int_mb(k_range+h10b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_7_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 ( p9 h10 )_yt + = 1 * Sum ( h5 p3 ) * t ( p3 p9 h5 h10 )_t * y ( h5 p3 )_y
      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 p9b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER h5b
      INTEGER p9b_1
      INTEGER p3b_1
      INTEGER h10b_1
      INTEGER h5b_1
      INTEGER h5b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO p9b = noab+1,noab+nvab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p9b-1)+int_mb(k_spin+h10b-
     &1).ne.4)) THEN
      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. ieor(irrep
     &_y,irrep_t)) THEN
      dimc = int_mb(k_range+p9b-1) * int_mb(k_range+h10b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_7_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      DO h5b = 1,noab
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h5b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p3b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h5b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p9b,p3b,h10b,h5b,p9b_1,p3b_1,h10b_1,h5b_1)
      CALL TCE_RESTRICTED_2(h5b,p3b,h5b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1) * int_mb(k_range+h5b-1)
      dima_sort = int_mb(k_range+p9b-1) * int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = 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('ccsd_lambda1_mod_7_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_7_2',2,MA_ERR)
      IF ((p3b .le. p9b) .and. (h5b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h5b_1 - 1 + noab * (p9b_1 - noab - 1 + nvab * (p3b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h5b-1),int_mb(k_range+h10b-1
     &),4,2,3,1,1.0d0)
      END IF
      IF ((p3b .le. p9b) .and. (h10b .lt. h5b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_1
     & - 1 + noab * (h10b_1 - 1 + noab * (p9b_1 - noab - 1 + nvab * (p3b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h10b-1),int_mb(k_range+h5b-1
     &),3,2,4,1,-1.0d0)
      END IF
      IF ((p9b .lt. p3b) .and. (h5b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h5b_1 - 1 + noab * (p3b_1 - noab - 1 + nvab * (p9b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+p3b-1),int_mb(k_range+h5b-1),int_mb(k_range+h10b-1
     &),4,1,3,2,-1.0d0)
      END IF
      IF ((p9b .lt. p3b) .and. (h10b .lt. h5b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_1
     & - 1 + noab * (h10b_1 - 1 + noab * (p3b_1 - noab - 1 + nvab * (p9b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+p3b-1),int_mb(k_range+h10b-1),int_mb(k_range+h5b-1
     &),3,1,4,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_7_2',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_7_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_7_2',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h5b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+p3b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_7_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('ccsd_lambda1_mod_7_
     &2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7_
     &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('
     &ccsd_lambda1_mod_7_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h10b-1
     &),int_mb(k_range+p9b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (p9b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_7_2',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7_
     &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 ccsd_lambda1_mod_7_3(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 ( p9 h10 )_ytt + = -1 * Sum ( h6 ) * t ( p9 h6 )_t * i2 ( h6 h10 )_yt
      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 p9b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h6b
      INTEGER p9b_1
      INTEGER h6b_1
      INTEGER h6b_2
      INTEGER h10b_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 p9b = noab+1,noab+nvab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p9b-1)+int_mb(k_spin+h10b-
     &1).ne.4)) THEN
      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. ieor(irrep
     &_y,ieor(irrep_t,irrep_t))) THEN
      dimc = int_mb(k_range+p9b-1) * int_mb(k_range+h10b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_7_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h6b = 1,noab
      IF (int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),int_mb(k_sym+h6b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p9b,h6b,p9b_1,h6b_1)
      CALL TCE_RESTRICTED_2(h6b,h10b,h6b_2,h10b_2)
      dim_common = int_mb(k_range+h6b-1)
      dima_sort = int_mb(k_range+p9b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h10b-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('ccsd_lambda1_mod_7_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_7_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_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+h6b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_7_3',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_7_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_7_3',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h10b_
     &2 - 1 + noab * (h6b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_7_3',6,
     &MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7_
     &3',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7_
     &3',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('
     &ccsd_lambda1_mod_7_3',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h10b-1
     &),int_mb(k_range+p9b-1),2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (p9b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_7_3',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7_
     &3',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 ccsd_lambda1_mod_7_3_1(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     i2 ( h6 h10 )_yt + = 1 * Sum ( p5 ) * t ( p5 h10 )_t * y ( h6 p5 )_y
      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 h6b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h10b_1
      INTEGER h6b_2
      INTEGER p5b_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 h6b = 1,noab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+h10b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+h10b-1)) .eq. ieor(irrep
     &_y,irrep_t)) THEN
      dimc = int_mb(k_range+h6b-1) * int_mb(k_range+h10b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_7_3_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h10b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p5b,h10b,p5b_1,h10b_1)
      CALL TCE_RESTRICTED_2(h6b,p5b,h6b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1)
      dima_sort = int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h6b-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('ccsd_lambda1_mod_7_3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_7_3_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (p5b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p5b-1)
     &,int_mb(k_range+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_7_3_1',
     &3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_7_3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_7_3_1',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (h6b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+p5b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_7_3_1',
     &6,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7_
     &3_1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7_
     &3_1',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('
     &ccsd_lambda1_mod_7_3_1',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h10b-1),1,2,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (h6b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_7_3_1',
     &10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7_
     &3_1',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 OFFSET_ccsd_lambda1_mod_7_3_1(l_a_offset,k_a_offset,siz
     &e)
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     i2 ( h6 h10 )_yt
      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 h6b
      INTEGER h10b
      length = 0
      DO h6b = 1,noab
      DO h10b = 1,noab
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+h10b-1)) .eq. ieor(irrep
     &_y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+h10b-
     &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('ccsd_lambda1_mod_7_3_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h6b = 1,noab
      DO h10b = 1,noab
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+h10b-1)) .eq. ieor(irrep
     &_y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+h10b-
     &1).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h10b - 1 + noab * (h6b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h6b-1) * int_mb(k_range+h10b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_7_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     i2 ( h6 h10 )_yt + = 1/2 * Sum ( h5 p4 p3 ) * t ( p3 p4 h5 h10 )_t * y ( h5 h6 p3 p4 )_y
      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 h6b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p4b
      INTEGER h5b
      INTEGER p3b_1
      INTEGER p4b_1
      INTEGER h10b_1
      INTEGER h5b_1
      INTEGER h6b_2
      INTEGER h5b_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
      INTEGER nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h6b = 1,noab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+h10b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+h10b-1)) .eq. ieor(irrep
     &_y,irrep_t)) THEN
      dimc = int_mb(k_range+h6b-1) * int_mb(k_range+h10b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_7_3_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      DO p4b = p3b,noab+nvab
      DO h5b = 1,noab
      IF (int_mb(k_spin+p3b-1)+int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h5b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),ieor(int_mb(k_sym+p4b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h5b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p3b,p4b,h10b,h5b,p3b_1,p4b_1,h10b_1,h5b_1)
      CALL TCE_RESTRICTED_4(h6b,h5b,p3b,p4b,h6b_2,h5b_2,p3b_2,p4b_2)
      dim_common = int_mb(k_range+p3b-1) * int_mb(k_range+p4b-1) * int_m
     &b(k_range+h5b-1)
      dima_sort = int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h6b-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('ccsd_lambda1_mod_7_3_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_7_3_2',2,MA_ERR)
      IF ((h5b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h5b_1 - 1 + noab * (p4b_1 - noab - 1 + nvab * (p3b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p4b-1),int_mb(k_range+h5b-1),int_mb(k_range+h10b-1
     &),4,3,2,1,1.0d0)
      END IF
      IF ((h10b .lt. h5b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_1
     & - 1 + noab * (h10b_1 - 1 + noab * (p4b_1 - noab - 1 + nvab * (p3b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p4b-1),int_mb(k_range+h10b-1),int_mb(k_range+h5b-1
     &),3,4,2,1,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_7_3_2',
     &3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_7_3_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_7_3_2',5,MA_ERR)
      IF ((h5b .le. h6b)) THEN
      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 * (h6b_2 - 1 + noab 
     &* (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+p3b-1),int_mb(k_range+p4b-1)
     &,2,1,4,3,1.0d0)
      END IF
      IF ((h6b .lt. h5b)) THEN
      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 * (h5b_2 - 1 + noab 
     &* (h6b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p3b-1),int_mb(k_range+p4b-1)
     &,1,2,4,3,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_7_3_2',
     &6,MA_ERR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p3b .eq. p4b) THEN
      nsuperp(isuperp) = nsuperp(isuperp) + 1
      ELSE
      isuperp = isuperp + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsuperp(1))/FACTORIAL(nsuperp(2)),dbl_mb(k_a_sort),dim_common,dbl_
     &mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7_
     &3_2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7_
     &3_2',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_7_3_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h10b-1),1,2,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (h6b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_7_3_2',
     &10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7_
     &3_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 ccsd_lambda1_mod_7_4(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 ( p9 h10 )_ytt + = -1/2 * Sum ( h5 h6 p3 ) * t ( p3 p9 h5 h6 )_t * i2 ( h5 h6 h10 p3 )_yt
      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 p9b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER h5b
      INTEGER h6b
      INTEGER p9b_1
      INTEGER p3b_1
      INTEGER h5b_1
      INTEGER h6b_1
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER h10b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER nsubh(2)
      INTEGER isubh
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO p9b = noab+1,noab+nvab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p9b-1)+int_mb(k_spin+h10b-
     &1).ne.4)) THEN
      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. ieor(irrep
     &_y,ieor(irrep_t,irrep_t))) THEN
      dimc = int_mb(k_range+p9b-1) * int_mb(k_range+h10b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_7_4',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      DO h5b = 1,noab
      DO h6b = h5b,noab
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+h
     &5b-1)+int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p3b-1),ieor(int_mb(
     &k_sym+h5b-1),int_mb(k_sym+h6b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p9b,p3b,h5b,h6b,p9b_1,p3b_1,h5b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h5b,h6b,h10b,p3b,h5b_2,h6b_2,h10b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1) * int_mb(k_range+h5b-1) * int_m
     &b(k_range+h6b-1)
      dima_sort = int_mb(k_range+p9b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h10b-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('ccsd_lambda1_mod_7_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_7_4',2,MA_ERR)
      IF ((p3b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h5b_1 - 1 + noab * (p9b_1 - noab - 1 + nvab * (p3b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h5b-1),int_mb(k_range+h6b-1)
     &,2,4,3,1,1.0d0)
      END IF
      IF ((p9b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h5b_1 - 1 + noab * (p3b_1 - noab - 1 + nvab * (p9b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+p3b-1),int_mb(k_range+h5b-1),int_mb(k_range+h6b-1)
     &,1,4,3,2,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_7_4',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_7_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_7_4',5,MA_ERR)
      IF ((h10b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h10b_2 - 1 + noab * (h6b_2 - 1 + noab * (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+h10b-1),int_mb(k_range+p3b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_7_4',6,
     &MA_ERR)
      nsubh(1) = 1
      nsubh(2) = 1
      isubh = 1
      IF (h5b .eq. h6b) THEN
      nsubh(isubh) = nsubh(isubh) + 1
      ELSE
      isubh = isubh + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsubh(1))/FACTORIAL(nsubh(2)),dbl_mb(k_a_sort),dim_common,dbl_mb(k
     &_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7_
     &4',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7_
     &4',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_7_4',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h10b-1
     &),int_mb(k_range+p9b-1),2,1,-1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (p9b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_7_4',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7_
     &4',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 ccsd_lambda1_mod_7_4_1(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     i2 ( h5 h6 h10 p3 )_yt + = 1 * Sum ( p7 ) * t ( p7 h10 )_t * y ( h5 h6 p3 p7 )_y
      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 h10b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h10b_1
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER p3b_2
      INTEGER p7b_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 h10b = 1,noab
      DO p3b = noab+1,noab+nvab
      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+h10b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h
     &10b-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+h10b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      dimc = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_7_4_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h10b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p7b,h10b,p7b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h5b,h6b,p3b,p7b,h5b_2,h6b_2,p3b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb
     &(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_7_4_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_7_4_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_7_4_1',
     &3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_7_4_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_7_4_1',5,MA_ERR)
      IF ((p7b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (h6b_2 - 1 + noab 
     &* (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+p7b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p3b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p3b_2 - noab - 1 + nvab * (h6b_2 - 1 + noab 
     &* (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+p3b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_7_4_1',
     &6,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7_
     &4_1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7_
     &4_1',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('
     &ccsd_lambda1_mod_7_4_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+h10b-1
     &),3,2,4,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (h10b - 1 + noab * (h6b - 1 + noab * (h5b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_7_4_1',
     &10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_7_
     &4_1',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 OFFSET_ccsd_lambda1_mod_7_4_1(l_a_offset,k_a_offset,siz
     &e)
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     i2 ( h5 h6 h10 p3 )_yt
      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 h10b
      INTEGER p3b
      length = 0
      DO h5b = 1,noab
      DO h6b = h5b,noab
      DO h10b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h
     &10b-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+h10b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+p3b-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('ccsd_lambda1_mod_7_4_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h5b = 1,noab
      DO h6b = h5b,noab
      DO h10b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h
     &10b-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+h10b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p3b - noab - 1 + nvab * (h10b - 1 + noab
     & * (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+h10b-1) * int_mb(k_range+p3b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_8(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     i0 ( h2 p1 )_ytf + = -1 * Sum ( h3 ) * i1 ( h2 h3 )_yt * f ( h3 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_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h3b
      INTEGER h2b_1
      INTEGER h3b_1
      INTEGER h3b_2
      INTEGER p1b_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 h2b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &y,ieor(irrep_t,irrep_f))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_8',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h3b = 1,noab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h3b-1)) .eq. ieor(irrep_
     &y,irrep_t)) THEN
      CALL TCE_RESTRICTED_2(h2b,h3b,h2b_1,h3b_1)
      CALL TCE_RESTRICTED_2(h3b,p1b,h3b_2,p1b_2)
      dim_common = int_mb(k_range+h3b-1)
      dima_sort = int_mb(k_range+h2b-1)
      dima = dim_common * dima_sort
      dimb_sort = 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('ccsd_lambda1_mod_8',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_8',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h3b_1
     & - 1 + noab * (h2b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h3b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_8',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_8',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_8',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (h3b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+p1b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_8',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('ccsd_lambda1_mod_8'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_8'
     &,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('
     &ccsd_lambda1_mod_8',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+h2b-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 * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_8',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_8'
     &,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 ccsd_lambda1_mod_8_1(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 ( h2 h3 )_yt + = 1 * Sum ( p4 ) * t ( p4 h3 )_t * y ( h2 p4 )_y
      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 h2b
      INTEGER h3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p4b
      INTEGER p4b_1
      INTEGER h3b_1
      INTEGER h2b_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
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO h3b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h3b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h3b-1)) .eq. ieor(irrep_
     &y,irrep_t)) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_8_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p4b = noab+1,noab+nvab
      IF (int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+p4b-1),int_mb(k_sym+h3b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p4b,h3b,p4b_1,h3b_1)
      CALL TCE_RESTRICTED_2(h2b,p4b,h2b_2,p4b_2)
      dim_common = int_mb(k_range+p4b-1)
      dima_sort = int_mb(k_range+h3b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-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('ccsd_lambda1_mod_8_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_8_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h3b_1
     & - 1 + noab * (p4b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p4b-1)
     &,int_mb(k_range+h3b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_8_1',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_8_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_8_1',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p4b_2
     & - noab - 1 + nvab * (h2b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p4b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_8_1',6,
     &MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_8_
     &1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_8_
     &1',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('
     &ccsd_lambda1_mod_8_1',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h3b-1),1,2,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h3b -
     & 1 + noab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_8_1',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_8_
     &1',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 OFFSET_ccsd_lambda1_mod_8_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 ( h2 h3 )_yt
      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 h2b
      INTEGER h3b
      length = 0
      DO h2b = 1,noab
      DO h3b = 1,noab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h3b-1)) .eq. ieor(irrep_
     &y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h3b-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('ccsd_lambda1_mod_8_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h3b = 1,noab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h3b-1)) .eq. ieor(irrep_
     &y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h3b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h3b - 1 + noab * (h2b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+h3b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_8_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 ( h2 h3 )_yt + = 1/2 * Sum ( h6 p5 p4 ) * t ( p4 p5 h3 h6 )_t * y ( h2 h6 p4 p5 )_y
      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 h2b
      INTEGER h3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p4b
      INTEGER p5b
      INTEGER h6b
      INTEGER p4b_1
      INTEGER p5b_1
      INTEGER h3b_1
      INTEGER h6b_1
      INTEGER h2b_2
      INTEGER h6b_2
      INTEGER p4b_2
      INTEGER p5b_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 nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO h3b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h3b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h3b-1)) .eq. ieor(irrep_
     &y,irrep_t)) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_8_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p4b = noab+1,noab+nvab
      DO p5b = p4b,noab+nvab
      DO h6b = 1,noab
      IF (int_mb(k_spin+p4b-1)+int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h
     &3b-1)+int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p4b-1),ieor(int_mb(k_sym+p5b-1),ieor(int_mb(
     &k_sym+h3b-1),int_mb(k_sym+h6b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p4b,p5b,h3b,h6b,p4b_1,p5b_1,h3b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h2b,h6b,p4b,p5b,h2b_2,h6b_2,p4b_2,p5b_2)
      dim_common = int_mb(k_range+p4b-1) * int_mb(k_range+p5b-1) * int_m
     &b(k_range+h6b-1)
      dima_sort = int_mb(k_range+h3b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-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('ccsd_lambda1_mod_8_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_8_2',2,MA_ERR)
      IF ((h6b .lt. h3b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h3b_1
     & - 1 + noab * (h6b_1 - 1 + noab * (p5b_1 - noab - 1 + nvab * (p4b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p4b-1)
     &,int_mb(k_range+p5b-1),int_mb(k_range+h6b-1),int_mb(k_range+h3b-1)
     &,4,3,2,1,-1.0d0)
      END IF
      IF ((h3b .le. h6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h3b_1 - 1 + noab * (p5b_1 - noab - 1 + nvab * (p4b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p4b-1)
     &,int_mb(k_range+p5b-1),int_mb(k_range+h3b-1),int_mb(k_range+h6b-1)
     &,3,4,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_8_2',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_8_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_8_2',5,MA_ERR)
      IF ((h6b .lt. h2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p4b_2 - noab - 1 + nvab * (h2b_2 - 1 + noab 
     &* (h6b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p4b-1),int_mb(k_range+p5b-1)
     &,2,1,4,3,-1.0d0)
      END IF
      IF ((h2b .le. h6b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p4b_2 - noab - 1 + nvab * (h6b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p4b-1),int_mb(k_range+p5b-1)
     &,1,2,4,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_8_2',6,
     &MA_ERR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p4b .eq. p5b) THEN
      nsuperp(isuperp) = nsuperp(isuperp) + 1
      ELSE
      isuperp = isuperp + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsuperp(1))/FACTORIAL(nsuperp(2)),dbl_mb(k_a_sort),dim_common,dbl_
     &mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_8_
     &2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_8_
     &2',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_8_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h3b-1),1,2,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h3b -
     & 1 + noab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_8_2',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_8_
     &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 ccsd_lambda1_mod_9(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     i0 ( h2 p1 )_ytv + = 1 * Sum ( h6 h8 ) * i1 ( h6 h8 )_yt * v ( h2 h8 h6 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_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h6b
      INTEGER h8b
      INTEGER h6b_1
      INTEGER h8b_1
      INTEGER h2b_2
      INTEGER h8b_2
      INTEGER p1b_2
      INTEGER h6b_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 h2b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &y,ieor(irrep_t,irrep_v))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_9',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h6b = 1,noab
      DO h8b = 1,noab
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+h8b-1)) .eq. ieor(irrep_
     &y,irrep_t)) THEN
      CALL TCE_RESTRICTED_2(h6b,h8b,h6b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,p1b,h6b,h2b_2,h8b_2,p1b_2,h6b_2)
      dim_common = int_mb(k_range+h6b-1) * int_mb(k_range+h8b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-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('ccsd_lambda1_mod_9',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_9',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (h6b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_9',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_9',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_9',5,MA_ERR)
      IF ((h8b .lt. h2b) .and. (h6b .le. p1b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (h6b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (h6b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p1b_2,h6b_2,h2b_2,h8b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h2b .le. h8b) .and. (h6b .le. p1b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (h6b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (h6b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p1b_2,h6b_2,h8b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h8b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_9',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('ccsd_lambda1_mod_9'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_9'
     &,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('
     &ccsd_lambda1_mod_9',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+h2b-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 * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_9',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_9'
     &,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 ccsd_lambda1_mod_9_1(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 ( h6 h8 )_yt + = 1 * Sum ( p3 ) * t ( p3 h8 )_t * y ( h6 p3 )_y
      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 h6b
      INTEGER h8b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h8b_1
      INTEGER h6b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h6b = 1,noab
      DO h8b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+h8b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+h8b-1)) .eq. ieor(irrep_
     &y,irrep_t)) THEN
      dimc = int_mb(k_range+h6b-1) * int_mb(k_range+h8b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_9_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h8b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p3b,h8b,p3b_1,h8b_1)
      CALL TCE_RESTRICTED_2(h6b,p3b,h6b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h8b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h6b-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('ccsd_lambda1_mod_9_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_9_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p3b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_9_1',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_9_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_9_1',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h6b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+p3b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_9_1',6,
     &MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_9_
     &1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_9_
     &1',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('
     &ccsd_lambda1_mod_9_1',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h8b-1),1,2,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h8b -
     & 1 + noab * (h6b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_9_1',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_9_
     &1',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 OFFSET_ccsd_lambda1_mod_9_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 ( h6 h8 )_yt
      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 h6b
      INTEGER h8b
      length = 0
      DO h6b = 1,noab
      DO h8b = 1,noab
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+h8b-1)) .eq. ieor(irrep_
     &y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+h8b-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('ccsd_lambda1_mod_9_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h6b = 1,noab
      DO h8b = 1,noab
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+h8b-1)) .eq. ieor(irrep_
     &y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+h8b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h8b - 1 + noab * (h6b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h6b-1) * int_mb(k_range+h8b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_9_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 ( h6 h8 )_yt + = 1/2 * Sum ( h5 p4 p3 ) * t ( p3 p4 h5 h8 )_t * y ( h5 h6 p3 p4 )_y
      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 h6b
      INTEGER h8b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p4b
      INTEGER h5b
      INTEGER p3b_1
      INTEGER p4b_1
      INTEGER h8b_1
      INTEGER h5b_1
      INTEGER h6b_2
      INTEGER h5b_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
      INTEGER nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h6b = 1,noab
      DO h8b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+h8b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+h8b-1)) .eq. ieor(irrep_
     &y,irrep_t)) THEN
      dimc = int_mb(k_range+h6b-1) * int_mb(k_range+h8b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_9_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      DO p4b = p3b,noab+nvab
      DO h5b = 1,noab
      IF (int_mb(k_spin+p3b-1)+int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+h
     &8b-1)+int_mb(k_spin+h5b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),ieor(int_mb(k_sym+p4b-1),ieor(int_mb(
     &k_sym+h8b-1),int_mb(k_sym+h5b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p3b,p4b,h8b,h5b,p3b_1,p4b_1,h8b_1,h5b_1)
      CALL TCE_RESTRICTED_4(h6b,h5b,p3b,p4b,h6b_2,h5b_2,p3b_2,p4b_2)
      dim_common = int_mb(k_range+p3b-1) * int_mb(k_range+p4b-1) * int_m
     &b(k_range+h5b-1)
      dima_sort = int_mb(k_range+h8b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h6b-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('ccsd_lambda1_mod_9_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_9_2',2,MA_ERR)
      IF ((h5b .le. h8b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (h5b_1 - 1 + noab * (p4b_1 - noab - 1 + nvab * (p3b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p4b-1),int_mb(k_range+h5b-1),int_mb(k_range+h8b-1)
     &,4,3,2,1,1.0d0)
      END IF
      IF ((h8b .lt. h5b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_1
     & - 1 + noab * (h8b_1 - 1 + noab * (p4b_1 - noab - 1 + nvab * (p3b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p4b-1),int_mb(k_range+h8b-1),int_mb(k_range+h5b-1)
     &,3,4,2,1,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_9_2',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_9_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_9_2',5,MA_ERR)
      IF ((h5b .le. h6b)) THEN
      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 * (h6b_2 - 1 + noab 
     &* (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+p3b-1),int_mb(k_range+p4b-1)
     &,2,1,4,3,1.0d0)
      END IF
      IF ((h6b .lt. h5b)) THEN
      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 * (h5b_2 - 1 + noab 
     &* (h6b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p3b-1),int_mb(k_range+p4b-1)
     &,1,2,4,3,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_9_2',6,
     &MA_ERR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p3b .eq. p4b) THEN
      nsuperp(isuperp) = nsuperp(isuperp) + 1
      ELSE
      isuperp = isuperp + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsuperp(1))/FACTORIAL(nsuperp(2)),dbl_mb(k_a_sort),dim_common,dbl_
     &mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_9_
     &2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_9_
     &2',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_9_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h8b-1),1,2,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h8b -
     & 1 + noab * (h6b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_9_2',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_9_
     &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 ccsd_lambda1_mod_10(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     i0 ( h2 p1 )_ytv + = 1 * Sum ( p7 p8 ) * i1 ( p7 p8 )_yt * v ( h2 p8 p1 p7 )_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 h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p8b
      INTEGER p7b_1
      INTEGER p8b_1
      INTEGER h2b_2
      INTEGER p8b_2
      INTEGER p1b_2
      INTEGER p7b_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 h2b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &y,ieor(irrep_t,irrep_v))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_10',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      DO p8b = noab+1,noab+nvab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+p8b-1)) .eq. ieor(irrep_
     &y,irrep_t)) THEN
      CALL TCE_RESTRICTED_2(p7b,p8b,p7b_1,p8b_1)
      CALL TCE_RESTRICTED_4(h2b,p8b,p1b,p7b,h2b_2,p8b_2,p1b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1) * int_mb(k_range+p8b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-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('ccsd_lambda1_mod_10',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_10',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p8b_1
     & - noab - 1 + nvab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_10',3,M
     &A_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_10',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_10',5,MA_ERR)
      IF ((h2b .le. p8b) .and. (p7b .lt. p1b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (p8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (p8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p1b_2,p7b_2,p8b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+p7b-1),int_mb(k_range+p1b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h2b .le. p8b) .and. (p1b .le. p7b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (p8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p7b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (p8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p7b_2,p1b_2,p8b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+p1b-1),int_mb(k_range+p7b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_10',6,M
     &A_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('ccsd_lambda1_mod_10
     &',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_10
     &',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('
     &ccsd_lambda1_mod_10',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+h2b-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 * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_10',10,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_10
     &',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 ccsd_lambda1_mod_10_1(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 ( p7 p8 )_yt + = 1 * Sum ( h4 ) * t ( p7 h4 )_t * y ( h4 p8 )_y
      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 p7b
      INTEGER p8b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER p7b_1
      INTEGER h4b_1
      INTEGER h4b_2
      INTEGER p8b_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 p7b = noab+1,noab+nvab
      DO p8b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p7b-1)+int_mb(k_spin+p8b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+p8b-1)) .eq. ieor(irrep_
     &y,irrep_t)) THEN
      dimc = int_mb(k_range+p7b-1) * int_mb(k_range+p8b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_10_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h4b = 1,noab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h4b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h4b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p7b,h4b,p7b_1,h4b_1)
      CALL TCE_RESTRICTED_2(h4b,p8b,h4b_2,p8b_2)
      dim_common = int_mb(k_range+h4b-1)
      dima_sort = int_mb(k_range+p7b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p8b-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('ccsd_lambda1_mod_10_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_10_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_1
     & - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h4b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_10_1',3
     &,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_10_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_10_1',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - noab - 1 + nvab * (h4b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+p8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_10_1',6
     &,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_10
     &_1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_10
     &_1',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('
     &ccsd_lambda1_mod_10_1',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p8b-1)
     &,int_mb(k_range+p7b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p8b -
     & noab - 1 + nvab * (p7b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_10_1',1
     &0,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_10
     &_1',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 OFFSET_ccsd_lambda1_mod_10_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 ( p7 p8 )_yt
      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 p7b
      INTEGER p8b
      length = 0
      DO p7b = noab+1,noab+nvab
      DO p8b = noab+1,noab+nvab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+p8b-1)) .eq. ieor(irrep_
     &y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p7b-1)+int_mb(k_spin+p8b-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('ccsd_lambda1_mod_10_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO p7b = noab+1,noab+nvab
      DO p8b = noab+1,noab+nvab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+p8b-1)) .eq. ieor(irrep_
     &y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p7b-1)+int_mb(k_spin+p8b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p8b - noab - 1 + nvab * (p7b - noab - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+p7b-1) * int_mb(k_range+p8b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_10_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 ( p7 p8 )_yt + = 1/2 * Sum ( h6 h5 p3 ) * t ( p3 p7 h5 h6 )_t * y ( h5 h6 p3 p8 )_y
      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 p7b
      INTEGER p8b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER h5b
      INTEGER h6b
      INTEGER p7b_1
      INTEGER p3b_1
      INTEGER h5b_1
      INTEGER h6b_1
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER p8b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER nsubh(2)
      INTEGER isubh
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO p7b = noab+1,noab+nvab
      DO p8b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p7b-1)+int_mb(k_spin+p8b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+p8b-1)) .eq. ieor(irrep_
     &y,irrep_t)) THEN
      dimc = int_mb(k_range+p7b-1) * int_mb(k_range+p8b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_10_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      DO h5b = 1,noab
      DO h6b = h5b,noab
      IF (int_mb(k_spin+p7b-1)+int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+h
     &5b-1)+int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),ieor(int_mb(k_sym+p3b-1),ieor(int_mb(
     &k_sym+h5b-1),int_mb(k_sym+h6b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p7b,p3b,h5b,h6b,p7b_1,p3b_1,h5b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h5b,h6b,p8b,p3b,h5b_2,h6b_2,p8b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1) * int_mb(k_range+h5b-1) * int_m
     &b(k_range+h6b-1)
      dima_sort = int_mb(k_range+p7b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p8b-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('ccsd_lambda1_mod_10_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_10_2',2,MA_ERR)
      IF ((p3b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h5b_1 - 1 + noab * (p7b_1 - noab - 1 + nvab * (p3b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+h5b-1),int_mb(k_range+h6b-1)
     &,2,4,3,1,1.0d0)
      END IF
      IF ((p7b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h5b_1 - 1 + noab * (p3b_1 - noab - 1 + nvab * (p7b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p3b-1),int_mb(k_range+h5b-1),int_mb(k_range+h6b-1)
     &,1,4,3,2,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_10_2',3
     &,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_10_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_10_2',5,MA_ERR)
      IF ((p3b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - noab - 1 + nvab * (p3b_2 - noab - 1 + nvab * (h6b_2 - 1 + noab 
     &* (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+p3b-1),int_mb(k_range+p8b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((p8b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (p8b_2 - noab - 1 + nvab * (h6b_2 - 1 + noab 
     &* (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+p8b-1),int_mb(k_range+p3b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_10_2',6
     &,MA_ERR)
      nsubh(1) = 1
      nsubh(2) = 1
      isubh = 1
      IF (h5b .eq. h6b) THEN
      nsubh(isubh) = nsubh(isubh) + 1
      ELSE
      isubh = isubh + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsubh(1))/FACTORIAL(nsubh(2)),dbl_mb(k_a_sort),dim_common,dbl_mb(k
     &_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_10
     &_2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_10
     &_2',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_10_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p8b-1)
     &,int_mb(k_range+p7b-1),2,1,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p8b -
     & noab - 1 + nvab * (p7b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_10_2',1
     &0,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_10
     &_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 ccsd_lambda1_mod_11(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     i0 ( h2 p1 )_ytv + = 1 * Sum ( h6 h4 p5 ) * i1 ( h2 h6 h4 p5 )_yt * v ( h4 p5 h6 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_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h6b
      INTEGER h4b
      INTEGER p5b
      INTEGER h2b_1
      INTEGER h6b_1
      INTEGER h4b_1
      INTEGER p5b_1
      INTEGER h4b_2
      INTEGER p5b_2
      INTEGER p1b_2
      INTEGER h6b_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 h2b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &y,ieor(irrep_t,irrep_v))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_11',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h6b = 1,noab
      DO h4b = 1,noab
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h
     &4b-1)+int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h4b-1),int_mb(k_sym+p5b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      CALL TCE_RESTRICTED_4(h2b,h6b,h4b,p5b,h2b_1,h6b_1,h4b_1,p5b_1)
      CALL TCE_RESTRICTED_4(h4b,p5b,p1b,h6b,h4b_2,p5b_2,p1b_2,h6b_2)
      dim_common = int_mb(k_range+h6b-1) * int_mb(k_range+h4b-1) * int_m
     &b(k_range+p5b-1)
      dima_sort = int_mb(k_range+h2b-1)
      dima = dim_common * dima_sort
      dimb_sort = 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('ccsd_lambda1_mod_11',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_11',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p5b_1
     & - noab - 1 + nvab * (h4b_1 - 1 + noab * (h6b_1 - 1 + noab * (h2b_
     &1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h4b-1),int_mb(k_range+p5b-1)
     &,1,4,3,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_11',3,M
     &A_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_11',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_11',5,MA_ERR)
      IF ((h6b .le. p1b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (h6b_2 - 1 + (noab+nvab) * (p5b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (h6b_2 - 1 + (noab+nvab) * (p5b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p1b_2,h6b_2,p5b_2,h4b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+p5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_11',6,M
     &A_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('ccsd_lambda1_mod_11
     &',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_11
     &',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_11',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+h2b-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 * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_11',10,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_11
     &',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 ccsd_lambda1_mod_11_1(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 ( h2 h6 h4 p5 )_yt + = 1 * Sum ( p3 ) * t ( p3 h4 )_t * y ( h2 h6 p3 p5 )_y
      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 h2b
      INTEGER h6b
      INTEGER h4b
      INTEGER p5b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h4b_1
      INTEGER h2b_2
      INTEGER h6b_2
      INTEGER p5b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO h6b = 1,noab
      DO h4b = 1,noab
      DO p5b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h4b-1)+int_mb(k_spin+p5b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h
     &4b-1)+int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h4b-1),int_mb(k_sym+p5b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h6b-1) * int_mb(k_ra
     &nge+h4b-1) * int_mb(k_range+p5b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_11_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+h4b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h4b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p3b,h4b,p3b_1,h4b_1)
      CALL TCE_RESTRICTED_4(h2b,h6b,p5b,p3b,h2b_2,h6b_2,p5b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h4b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h6b-1) * int_mb
     &(k_range+p5b-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('ccsd_lambda1_mod_11_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_11_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_1
     & - 1 + noab * (p3b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h4b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_11_1',3
     &,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_11_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_11_1',5,MA_ERR)
      IF ((h6b .lt. h2b) .and. (p3b .le. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p3b_2 - noab - 1 + nvab * (h2b_2 - 1 + noab 
     &* (h6b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p3b-1),int_mb(k_range+p5b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h6b .lt. h2b) .and. (p5b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (p5b_2 - noab - 1 + nvab * (h2b_2 - 1 + noab 
     &* (h6b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p5b-1),int_mb(k_range+p3b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF ((h2b .le. h6b) .and. (p3b .le. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p3b_2 - noab - 1 + nvab * (h6b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p3b-1),int_mb(k_range+p5b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h2b .le. h6b) .and. (p5b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (p5b_2 - noab - 1 + nvab * (h6b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p5b-1),int_mb(k_range+p3b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_11_1',6
     &,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_11
     &_1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_11
     &_1',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('
     &ccsd_lambda1_mod_11_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p5b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h2b-1),int_mb(k_range+h4b-1)
     &,3,2,4,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p5b -
     & noab - 1 + nvab * (h4b - 1 + noab * (h6b - 1 + noab * (h2b - 1)))
     &))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_11_1',1
     &0,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_11
     &_1',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 OFFSET_ccsd_lambda1_mod_11_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 ( h2 h6 h4 p5 )_yt
      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 h2b
      INTEGER h6b
      INTEGER h4b
      INTEGER p5b
      length = 0
      DO h2b = 1,noab
      DO h6b = 1,noab
      DO h4b = 1,noab
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h
     &4b-1)+int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h4b-1),int_mb(k_sym+p5b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h4b-1)+int_mb(k_spin+p5b-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('ccsd_lambda1_mod_11_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h6b = 1,noab
      DO h4b = 1,noab
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h
     &4b-1)+int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h4b-1),int_mb(k_sym+p5b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h4b-1)+int_mb(k_spin+p5b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p5b - noab - 1 + nvab * (h4b - 1 + noab 
     &* (h6b - 1 + noab * (h2b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+h6b-1) * int_
     &mb(k_range+h4b-1) * int_mb(k_range+p5b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_12(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     i0 ( h2 p1 )_ytv + = 1/2 * Sum ( p9 h12 h6 ) * i1 ( h2 p9 h6 h12 )_yt * v ( h6 h12 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 h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p9b
      INTEGER h6b
      INTEGER h12b
      INTEGER h2b_1
      INTEGER p9b_1
      INTEGER h6b_1
      INTEGER h12b_1
      INTEGER h6b_2
      INTEGER h12b_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 nsubh(2)
      INTEGER isubh
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &y,ieor(irrep_t,irrep_v))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p9b = noab+1,noab+nvab
      DO h6b = 1,noab
      DO h12b = h6b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      CALL TCE_RESTRICTED_4(h2b,p9b,h6b,h12b,h2b_1,p9b_1,h6b_1,h12b_1)
      CALL TCE_RESTRICTED_4(h6b,h12b,p1b,p9b,h6b_2,h12b_2,p1b_2,p9b_2)
      dim_common = int_mb(k_range+p9b-1) * int_mb(k_range+h6b-1) * int_m
     &b(k_range+h12b-1)
      dima_sort = int_mb(k_range+h2b-1)
      dima = dim_common * dima_sort
      dimb_sort = 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('ccsd_lambda1_mod_12',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (h6b_1 - 1 + noab * (p9b_1 - noab - 1 + nvab * (h2b
     &_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h6b-1),int_mb(k_range+h12b-1
     &),1,4,3,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_12',3,M
     &A_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12',5,MA_ERR)
      IF ((p9b .lt. p1b)) THEN
      if(.not.intorb) 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) * (h12b_2 - 1 + (noa
     &b+nvab) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (p9b_2 - 1 + (noab+nvab) * (h12b_2 - 1 + (noa
     &b+nvab) * (h6b_2 - 1)))),p1b_2,p9b_2,h12b_2,h6b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h12b-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
      if(.not.intorb) 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) * (h12b_2 - 1 + (noa
     &b+nvab) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p9b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h12b_2 - 1 + (noa
     &b+nvab) * (h6b_2 - 1)))),p9b_2,p1b_2,h12b_2,h6b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h12b-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('ccsd_lambda1_mod_12',6,M
     &A_ERR)
      nsubh(1) = 1
      nsubh(2) = 1
      isubh = 1
      IF (h6b .eq. h12b) THEN
      nsubh(isubh) = nsubh(isubh) + 1
      ELSE
      isubh = isubh + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsubh(1))/FACTORIAL(nsubh(2)),dbl_mb(k_a_sort),dim_common,dbl_mb(k
     &_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12',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+h2b-1),2,1,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_12',10,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &',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 ccsd_lambda1_mod_12_1(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 ( h2 p9 h6 h12 )_yt + = -1 * Sum ( p3 ) * t ( p3 p9 h6 h12 )_t * y ( h2 p3 )_y
      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 h2b
      INTEGER p9b
      INTEGER h6b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p9b_1
      INTEGER p3b_1
      INTEGER h6b_1
      INTEGER h12b_1
      INTEGER h2b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h6b = 1,noab
      DO h12b = h6b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p3b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p9b,p3b,h6b,h12b,p9b_1,p3b_1,h6b_1,h12b_1)
      CALL TCE_RESTRICTED_2(h2b,p3b,h2b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+p9b-1) * int_mb(k_range+h6b-1) * int_mb
     &(k_range+h12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-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('ccsd_lambda1_mod_12_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_1',2,MA_ERR)
      IF ((p3b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (h6b_1 - 1 + noab * (p9b_1 - noab - 1 + nvab * (p3b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h6b-1),int_mb(k_range+h12b-1
     &),4,3,2,1,1.0d0)
      END IF
      IF ((p9b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (h6b_1 - 1 + noab * (p3b_1 - noab - 1 + nvab * (p9b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+p3b-1),int_mb(k_range+h6b-1),int_mb(k_range+h12b-1
     &),4,3,1,2,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_12_1',3
     &,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_1',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h2b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p3b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_12_1',6
     &,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_1',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('
     &ccsd_lambda1_mod_12_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h12b-1),int_mb(k_range+h6b-1),int_mb(k_range+p9b-1
     &),1,4,3,2,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h6b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_12_1',1
     &0,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_1',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 OFFSET_ccsd_lambda1_mod_12_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 ( h2 p9 h6 h12 )_yt
      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 h2b
      INTEGER p9b
      INTEGER h6b
      INTEGER h12b
      length = 0
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h6b = 1,noab
      DO h12b = h6b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h12b-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('ccsd_lambda1_mod_12_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h6b = 1,noab
      DO h12b = h6b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h12b - 1 + noab * (h6b - 1 + noab * (p9b
     & - noab - 1 + nvab * (h2b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_
     &mb(k_range+h6b-1) * int_mb(k_range+h12b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_12_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 ( h2 p9 h6 h12 )_ytt + = -1/2 * Sum ( h10 ) * t ( p9 h10 )_t * i2 ( h2 h10 h6 h12 )_yt
      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 h2b
      INTEGER p9b
      INTEGER h6b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h10b
      INTEGER p9b_1
      INTEGER h10b_1
      INTEGER h2b_2
      INTEGER h10b_2
      INTEGER h6b_2
      INTEGER h12b_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 h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h6b = 1,noab
      DO h12b = h6b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,ieor(irrep_
     &t,irrep_t))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_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(h2b,h10b,h6b,h12b,h2b_2,h10b_2,h6b_2,h12b_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+h2b-1) * int_mb(k_range+h6b-1) * int_mb
     &(k_range+h12b-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('ccsd_lambda1_mod_12_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_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('ccsd_lambda1_mod_12_2',3
     &,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_2',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h12b_
     &2 - 1 + noab * (h6b_2 - 1 + noab * (h10b_2 - 1 + noab * (h2b_2 - 1
     &)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+h6b-1),int_mb(k_range+h12b-
     &1),4,3,1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_12_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('ccsd_lambda1_mod_12
     &_2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_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('
     &ccsd_lambda1_mod_12_2',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+h6b-1),int_mb(k_range+h2b-1),int_mb(k_range+p9b-1
     &),3,4,2,1,-1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h6b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_12_2',1
     &0,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_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 ccsd_lambda1_mod_12_2_1(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     i2 ( h2 h10 h6 h12 )_yt + = -1 * Sum ( p4 p3 ) * t ( p3 p4 h6 h12 )_t * y ( h2 h10 p3 p4 )_y
      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 h2b
      INTEGER h10b
      INTEGER h6b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p4b
      INTEGER p3b_1
      INTEGER p4b_1
      INTEGER h6b_1
      INTEGER h12b_1
      INTEGER h2b_2
      INTEGER h10b_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
      INTEGER nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO h10b = 1,noab
      DO h6b = 1,noab
      DO h12b = h6b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h10b-
     &1)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h10b-1) .eq. int_mb(k_spin+
     &h6b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h10b-1),ieor(int_mb
     &(k_sym+h6b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,irrep_t)) 
     &THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h10b-1) * int_mb(k_r
     &ange+h6b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_2_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      DO p4b = p3b,noab+nvab
      IF (int_mb(k_spin+p3b-1)+int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),ieor(int_mb(k_sym+p4b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p3b,p4b,h6b,h12b,p3b_1,p4b_1,h6b_1,h12b_1)
      CALL TCE_RESTRICTED_4(h2b,h10b,p3b,p4b,h2b_2,h10b_2,p3b_2,p4b_2)
      dim_common = int_mb(k_range+p3b-1) * int_mb(k_range+p4b-1)
      dima_sort = int_mb(k_range+h6b-1) * int_mb(k_range+h12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h10b-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('ccsd_lambda1_mod_12_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (h6b_1 - 1 + noab * (p4b_1 - noab - 1 + nvab * (p3b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p4b-1),int_mb(k_range+h6b-1),int_mb(k_range+h12b-1
     &),4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_12_2_1'
     &,3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_2_1',5,MA_ERR)
      IF ((h10b .lt. h2b)) THEN
      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 * (h2b_2 - 1 + noab 
     &* (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+h2b-1),int_mb(k_range+p3b-1),int_mb(k_range+p4b-1
     &),1,2,4,3,-1.0d0)
      END IF
      IF ((h2b .le. h10b)) THEN
      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 * (h10b_2 - 1 + noab
     & * (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+p3b-1),int_mb(k_range+p4b-1
     &),2,1,4,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_12_2_1'
     &,6,MA_ERR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p3b .eq. p4b) THEN
      nsuperp(isuperp) = nsuperp(isuperp) + 1
      ELSE
      isuperp = isuperp + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsuperp(1))/FACTORIAL(nsuperp(2)),dbl_mb(k_a_sort),dim_common,dbl_
     &mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_2_1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_2_1',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('
     &ccsd_lambda1_mod_12_2_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h10b-1
     &),int_mb(k_range+h2b-1),int_mb(k_range+h12b-1),int_mb(k_range+h6b-
     &1),2,1,4,3,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h6b - 1 + noab * (h10b - 1 + noab * (h2b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_12_2_1'
     &,10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_2_1',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 OFFSET_ccsd_lambda1_mod_12_2_1(l_a_offset,k_a_offset,si
     &ze)
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     i2 ( h2 h10 h6 h12 )_yt
      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 h2b
      INTEGER h10b
      INTEGER h6b
      INTEGER h12b
      length = 0
      DO h2b = 1,noab
      DO h10b = 1,noab
      DO h6b = 1,noab
      DO h12b = h6b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h10b-1) .eq. int_mb(k_spin+
     &h6b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h10b-1),ieor(int_mb
     &(k_sym+h6b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,irrep_t)) 
     &THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h10b-
     &1)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h12b-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('ccsd_lambda1_mod_12_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h10b = 1,noab
      DO h6b = 1,noab
      DO h12b = h6b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h10b-1) .eq. int_mb(k_spin+
     &h6b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h10b-1),ieor(int_mb
     &(k_sym+h6b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,irrep_t)) 
     &THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h10b-
     &1)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h12b - 1 + noab * (h6b - 1 + noab * (h10
     &b - 1 + noab * (h2b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+h10b-1) * int
     &_mb(k_range+h6b-1) * int_mb(k_range+h12b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_12_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     i2 ( h2 h10 h6 h12 )_ytt + = 2 * Sum ( p5 ) * t ( p5 h12 )_t * i3 ( h2 h10 h6 p5 )_yt
      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 h2b
      INTEGER h10b
      INTEGER h12b
      INTEGER h6b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h12b_1
      INTEGER h2b_2
      INTEGER h10b_2
      INTEGER h6b_2
      INTEGER p5b_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 h2b = 1,noab
      DO h10b = 1,noab
      DO h12b = 1,noab
      DO h6b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h10b-
     &1)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h10b-1) .eq. int_mb(k_spin+
     &h6b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h10b-1),ieor(int_mb
     &(k_sym+h6b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,ieor(irrep
     &_t,irrep_t))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h10b-1) * int_mb(k_r
     &ange+h6b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_2_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h12b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p5b,h12b,p5b_1,h12b_1)
      CALL TCE_RESTRICTED_4(h2b,h10b,h6b,p5b,h2b_2,h10b_2,h6b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1)
      dima_sort = int_mb(k_range+h12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h10b-1) * int_m
     &b(k_range+h6b-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('ccsd_lambda1_mod_12_2_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_2_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (p5b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p5b-1)
     &,int_mb(k_range+h12b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_12_2_2'
     &,3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_2_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_2_2',5,MA_ERR)
      IF ((h6b .le. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (h6b_2 - 1 + noab * (h10b_2 - 1 + noab * (h2b
     &_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+h6b-1),int_mb(k_range+p5b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_12_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('ccsd_lambda1_mod_12
     &_2_2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_2_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('
     &ccsd_lambda1_mod_12_2_2',9,MA_ERR)
      IF ((h6b .le. h12b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+h2b-1),int_mb(k_range+h12b-
     &1),3,2,1,4,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h6b - 1 + noab * (h10b - 1 + noab * (h2b - 1)))))
      END IF
      IF ((h12b .le. h6b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+h2b-1),int_mb(k_range+h12b-
     &1),3,2,4,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h6b -
     & 1 + noab * (h12b - 1 + noab * (h10b - 1 + noab * (h2b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_12_2_2'
     &,10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_2_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 ccsd_lambda1_mod_12_2_2_1(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     i3 ( h2 h10 h6 p5 )_yt + = 1 * Sum ( p7 ) * t ( p7 h6 )_t * y ( h2 h10 p5 p7 )_y
      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 h2b
      INTEGER h10b
      INTEGER h6b
      INTEGER p5b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h6b_1
      INTEGER h2b_2
      INTEGER h10b_2
      INTEGER p5b_2
      INTEGER p7b_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 h2b = 1,noab
      DO h10b = 1,noab
      DO h6b = 1,noab
      DO p5b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h10b-
     &1)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p5b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h10b-1) .eq. int_mb(k_spin+
     &h6b-1)+int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h10b-1),ieor(int_mb
     &(k_sym+h6b-1),int_mb(k_sym+p5b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h10b-1) * int_mb(k_r
     &ange+h6b-1) * int_mb(k_range+p5b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_2_2_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h6b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p7b,h6b,p7b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h2b,h10b,p5b,p7b,h2b_2,h10b_2,p5b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h6b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h10b-1) * int_m
     &b(k_range+p5b-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('ccsd_lambda1_mod_12_2_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_2_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h6b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_12_2_2_
     &1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_2_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_2_2_1',5,MA_ERR)
      IF ((h10b .lt. h2b) .and. (p7b .lt. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (h2b_2 - 1 + noab 
     &* (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+h2b-1),int_mb(k_range+p7b-1),int_mb(k_range+p5b-1
     &),4,1,2,3,1.0d0)
      END IF
      IF ((h10b .lt. h2b) .and. (p5b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p5b_2 - noab - 1 + nvab * (h2b_2 - 1 + noab 
     &* (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+h2b-1),int_mb(k_range+p5b-1),int_mb(k_range+p7b-1
     &),3,1,2,4,-1.0d0)
      END IF
      IF ((h2b .le. h10b) .and. (p7b .lt. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (h10b_2 - 1 + noab
     & * (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+p7b-1),int_mb(k_range+p5b-1
     &),4,2,1,3,-1.0d0)
      END IF
      IF ((h2b .le. h10b) .and. (p5b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p5b_2 - noab - 1 + nvab * (h10b_2 - 1 + noab
     & * (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+p5b-1),int_mb(k_range+p7b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_12_2_2_
     &1',6,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_2_2_1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_2_2_1',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('
     &ccsd_lambda1_mod_12_2_2_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p5b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+h2b-1),int_mb(k_range+h6b-1
     &),3,2,4,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p5b -
     & noab - 1 + nvab * (h6b - 1 + noab * (h10b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_12_2_2_
     &1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_2_2_1',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 OFFSET_ccsd_lambda1_mod_12_2_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     i3 ( h2 h10 h6 p5 )_yt
      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 h2b
      INTEGER h10b
      INTEGER h6b
      INTEGER p5b
      length = 0
      DO h2b = 1,noab
      DO h10b = 1,noab
      DO h6b = 1,noab
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h10b-1) .eq. int_mb(k_spin+
     &h6b-1)+int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h10b-1),ieor(int_mb
     &(k_sym+h6b-1),int_mb(k_sym+p5b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h10b-
     &1)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p5b-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('ccsd_lambda1_mod_12_2_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h10b = 1,noab
      DO h6b = 1,noab
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h10b-1) .eq. int_mb(k_spin+
     &h6b-1)+int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h10b-1),ieor(int_mb
     &(k_sym+h6b-1),int_mb(k_sym+p5b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h10b-
     &1)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p5b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p5b - noab - 1 + nvab * (h6b - 1 + noab 
     &* (h10b - 1 + noab * (h2b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+h10b-1) * int
     &_mb(k_range+h6b-1) * int_mb(k_range+p5b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_12_3(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 ( h2 p9 h6 h12 )_ytt + = 2 * Sum ( h5 p3 ) * t ( p3 p9 h5 h12 )_t * i2 ( h2 h5 h6 p3 )_yt
      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 h2b
      INTEGER p9b
      INTEGER h12b
      INTEGER h6b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER h5b
      INTEGER p9b_1
      INTEGER p3b_1
      INTEGER h12b_1
      INTEGER h5b_1
      INTEGER h2b_2
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h12b = 1,noab
      DO h6b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,ieor(irrep_
     &t,irrep_t))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      DO h5b = 1,noab
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+h5b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p3b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+h5b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p9b,p3b,h12b,h5b,p9b_1,p3b_1,h12b_1,h5b_1)
      CALL TCE_RESTRICTED_4(h2b,h5b,h6b,p3b,h2b_2,h5b_2,h6b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1) * int_mb(k_range+h5b-1)
      dima_sort = int_mb(k_range+p9b-1) * int_mb(k_range+h12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h6b-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('ccsd_lambda1_mod_12_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_3',2,MA_ERR)
      IF ((p3b .le. p9b) .and. (h5b .le. h12b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (h5b_1 - 1 + noab * (p9b_1 - noab - 1 + nvab * (p3b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h5b-1),int_mb(k_range+h12b-1
     &),4,2,3,1,1.0d0)
      END IF
      IF ((p3b .le. p9b) .and. (h12b .lt. h5b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_1
     & - 1 + noab * (h12b_1 - 1 + noab * (p9b_1 - noab - 1 + nvab * (p3b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h12b-1),int_mb(k_range+h5b-1
     &),3,2,4,1,-1.0d0)
      END IF
      IF ((p9b .lt. p3b) .and. (h5b .le. h12b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (h5b_1 - 1 + noab * (p3b_1 - noab - 1 + nvab * (p9b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+p3b-1),int_mb(k_range+h5b-1),int_mb(k_range+h12b-1
     &),4,1,3,2,-1.0d0)
      END IF
      IF ((p9b .lt. p3b) .and. (h12b .lt. h5b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_1
     & - 1 + noab * (h12b_1 - 1 + noab * (p3b_1 - noab - 1 + nvab * (p9b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+p3b-1),int_mb(k_range+h12b-1),int_mb(k_range+h5b-1
     &),3,1,4,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_12_3',3
     &,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_3',5,MA_ERR)
      IF ((h6b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h2b_
     &2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p3b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_12_3',6
     &,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_3',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_3',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('
     &ccsd_lambda1_mod_12_3',9,MA_ERR)
      IF ((h6b .le. h12b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h12b-1),int_mb(k_range+p9b-1
     &),2,4,1,3,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h6b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1))
     &)))
      END IF
      IF ((h12b .le. h6b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h12b-1),int_mb(k_range+p9b-1
     &),2,4,3,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h6b -
     & 1 + noab * (h12b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1))
     &)))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_12_3',1
     &0,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_3',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 ccsd_lambda1_mod_12_3_1(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     i2 ( h2 h5 h6 p3 )_yt + = 1 * Sum ( p7 ) * t ( p7 h6 )_t * y ( h2 h5 p3 p7 )_y
      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 h2b
      INTEGER h5b
      INTEGER h6b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h6b_1
      INTEGER h2b_2
      INTEGER h5b_2
      INTEGER p3b_2
      INTEGER p7b_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 h2b = 1,noab
      DO h5b = 1,noab
      DO h6b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_3_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h6b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p7b,h6b,p7b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h2b,h5b,p3b,p7b,h2b_2,h5b_2,p3b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h6b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_3_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h6b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_12_3_1'
     &,3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_3_1',5,MA_ERR)
      IF ((h5b .lt. h2b) .and. (p7b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (h2b_2 - 1 + noab 
     &* (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+h2b-1),int_mb(k_range+p7b-1),int_mb(k_range+p3b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h5b .lt. h2b) .and. (p3b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p3b_2 - noab - 1 + nvab * (h2b_2 - 1 + noab 
     &* (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+h2b-1),int_mb(k_range+p3b-1),int_mb(k_range+p7b-1)
     &,3,1,2,4,-1.0d0)
      END IF
      IF ((h2b .le. h5b) .and. (p7b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (h5b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p7b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h2b .le. h5b) .and. (p3b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p3b_2 - noab - 1 + nvab * (h5b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p3b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_12_3_1'
     &,6,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_3_1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_3_1',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('
     &ccsd_lambda1_mod_12_3_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h2b-1),int_mb(k_range+h6b-1)
     &,3,2,4,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (h6b - 1 + noab * (h5b - 1 + noab * (h2b - 1)))
     &))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_12_3_1'
     &,10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_3_1',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 OFFSET_ccsd_lambda1_mod_12_3_1(l_a_offset,k_a_offset,si
     &ze)
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     i2 ( h2 h5 h6 p3 )_yt
      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 h2b
      INTEGER h5b
      INTEGER h6b
      INTEGER p3b
      length = 0
      DO h2b = 1,noab
      DO h5b = 1,noab
      DO h6b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p3b-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('ccsd_lambda1_mod_12_3_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h5b = 1,noab
      DO h6b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p3b - noab - 1 + nvab * (h6b - 1 + noab 
     &* (h5b - 1 + noab * (h2b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+h5b-1) * int_
     &mb(k_range+h6b-1) * int_mb(k_range+p3b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_12_4(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 ( h2 p9 h6 h12 )_ytt + = -1 * t ( p9 h6 )_t * i2 ( h2 h12 )_yt
      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 h2b
      INTEGER p9b
      INTEGER h6b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p9b_1
      INTEGER h6b_1
      INTEGER h2b_2
      INTEGER h12b_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 h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h6b = 1,noab
      DO h12b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,ieor(irrep_
     &t,irrep_t))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_4',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      IF (int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),int_mb(k_sym+h6b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p9b,h6b,p9b_1,h6b_1)
      CALL TCE_RESTRICTED_2(h2b,h12b,h2b_2,h12b_2)
      dim_common = 1
      dima_sort = int_mb(k_range+p9b-1) * int_mb(k_range+h6b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h12b-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('ccsd_lambda1_mod_12_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_4',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_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+h6b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_12_4',3
     &,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_4',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h12b_
     &2 - 1 + noab * (h2b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h12b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_12_4',6
     &,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_4',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_4',8,MA_ERR)
      END IF
      END IF
      END IF
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_4',9,MA_ERR)
      IF ((h6b .le. h12b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+h2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p9b-1
     &),2,4,3,1,-1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h6b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1))
     &)))
      END IF
      IF ((h12b .le. h6b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+h2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p9b-1
     &),2,4,1,3,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h6b -
     & 1 + noab * (h12b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1))
     &)))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_12_4',1
     &0,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_4',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 ccsd_lambda1_mod_12_4_1(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     i2 ( h2 h12 )_yt + = 1 * Sum ( h5 p4 p3 ) * t ( p3 p4 h5 h12 )_t * y ( h2 h5 p3 p4 )_y
      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 h2b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p4b
      INTEGER h5b
      INTEGER p3b_1
      INTEGER p4b_1
      INTEGER h12b_1
      INTEGER h5b_1
      INTEGER h2b_2
      INTEGER h5b_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
      INTEGER nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO h12b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h12b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h12b-1)) .eq. ieor(irrep
     &_y,irrep_t)) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_4_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      DO p4b = p3b,noab+nvab
      DO h5b = 1,noab
      IF (int_mb(k_spin+p3b-1)+int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+h5b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),ieor(int_mb(k_sym+p4b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+h5b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p3b,p4b,h12b,h5b,p3b_1,p4b_1,h12b_1,h5b_1)
      CALL TCE_RESTRICTED_4(h2b,h5b,p3b,p4b,h2b_2,h5b_2,p3b_2,p4b_2)
      dim_common = int_mb(k_range+p3b-1) * int_mb(k_range+p4b-1) * int_m
     &b(k_range+h5b-1)
      dima_sort = int_mb(k_range+h12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-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('ccsd_lambda1_mod_12_4_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_4_1',2,MA_ERR)
      IF ((h5b .le. h12b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (h5b_1 - 1 + noab * (p4b_1 - noab - 1 + nvab * (p3b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p4b-1),int_mb(k_range+h5b-1),int_mb(k_range+h12b-1
     &),4,3,2,1,1.0d0)
      END IF
      IF ((h12b .lt. h5b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_1
     & - 1 + noab * (h12b_1 - 1 + noab * (p4b_1 - noab - 1 + nvab * (p3b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p4b-1),int_mb(k_range+h12b-1),int_mb(k_range+h5b-1
     &),3,4,2,1,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_12_4_1'
     &,3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_12_4_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_4_1',5,MA_ERR)
      IF ((h5b .lt. h2b)) THEN
      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 * (h2b_2 - 1 + noab 
     &* (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+h2b-1),int_mb(k_range+p3b-1),int_mb(k_range+p4b-1)
     &,2,1,4,3,-1.0d0)
      END IF
      IF ((h2b .le. h5b)) THEN
      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 * (h5b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p3b-1),int_mb(k_range+p4b-1)
     &,1,2,4,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_12_4_1'
     &,6,MA_ERR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p3b .eq. p4b) THEN
      nsuperp(isuperp) = nsuperp(isuperp) + 1
      ELSE
      isuperp = isuperp + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsuperp(1))/FACTORIAL(nsuperp(2)),dbl_mb(k_a_sort),dim_common,dbl_
     &mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_4_1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_4_1',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_12_4_1',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h12b-1),1,2,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_12_4_1'
     &,10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_12
     &_4_1',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 OFFSET_ccsd_lambda1_mod_12_4_1(l_a_offset,k_a_offset,si
     &ze)
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     i2 ( h2 h12 )_yt
      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 h2b
      INTEGER h12b
      length = 0
      DO h2b = 1,noab
      DO h12b = 1,noab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h12b-1)) .eq. ieor(irrep
     &_y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h12b-
     &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('ccsd_lambda1_mod_12_4_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h12b = 1,noab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h12b-1)) .eq. ieor(irrep
     &_y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h12b-
     &1).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h12b - 1 + noab * (h2b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+h12b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_13(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     i0 ( h2 p1 )_ytv + = 1/4 * Sum ( h7 h8 h6 ) * i1 ( h2 h7 h6 h8 )_yt * v ( h6 h8 h7 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_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h7b
      INTEGER h6b
      INTEGER h8b
      INTEGER h2b_1
      INTEGER h7b_1
      INTEGER h6b_1
      INTEGER h8b_1
      INTEGER h6b_2
      INTEGER h8b_2
      INTEGER p1b_2
      INTEGER h7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER nsubh(2)
      INTEGER isubh
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &y,ieor(irrep_t,irrep_v))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_13',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h7b = 1,noab
      DO h6b = 1,noab
      DO h8b = h6b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+h8b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      CALL TCE_RESTRICTED_4(h2b,h7b,h6b,h8b,h2b_1,h7b_1,h6b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h6b,h8b,p1b,h7b,h6b_2,h8b_2,p1b_2,h7b_2)
      dim_common = int_mb(k_range+h7b-1) * int_mb(k_range+h6b-1) * int_m
     &b(k_range+h8b-1)
      dima_sort = int_mb(k_range+h2b-1)
      dima = dim_common * dima_sort
      dimb_sort = 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('ccsd_lambda1_mod_13',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_13',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (h6b_1 - 1 + noab * (h7b_1 - 1 + noab * (h2b_1 - 1))
     &)))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_mb(k_range+h8b-1)
     &,1,4,3,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_13',3,M
     &A_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_13',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_13',5,MA_ERR)
      IF ((h7b .le. p1b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (h7b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (h7b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p1b_2,h7b_2,h8b_2,h6b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_13',6,M
     &A_ERR)
      nsubh(1) = 1
      nsubh(2) = 1
      isubh = 1
      IF (h6b .eq. h8b) THEN
      nsubh(isubh) = nsubh(isubh) + 1
      ELSE
      isubh = isubh + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsubh(1))/FACTORIAL(nsubh(2)),dbl_mb(k_a_sort),dim_common,dbl_mb(k
     &_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_13
     &',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_13
     &',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_13',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+h2b-1),2,1,1.0d0/4.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_13',10,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_13
     &',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 ccsd_lambda1_mod_13_1(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 ( h2 h7 h6 h8 )_yt + = -1 * Sum ( p4 p3 ) * t ( p3 p4 h6 h8 )_t * y ( h2 h7 p3 p4 )_y
      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 h2b
      INTEGER h7b
      INTEGER h6b
      INTEGER h8b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p4b
      INTEGER p3b_1
      INTEGER p4b_1
      INTEGER h6b_1
      INTEGER h8b_1
      INTEGER h2b_2
      INTEGER h7b_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
      INTEGER nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO h7b = 1,noab
      DO h6b = 1,noab
      DO h8b = h6b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h8b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+h8b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+h8b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_13_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      DO p4b = p3b,noab+nvab
      IF (int_mb(k_spin+p3b-1)+int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),ieor(int_mb(k_sym+p4b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+h8b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p3b,p4b,h6b,h8b,p3b_1,p4b_1,h6b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h2b,h7b,p3b,p4b,h2b_2,h7b_2,p3b_2,p4b_2)
      dim_common = int_mb(k_range+p3b-1) * int_mb(k_range+p4b-1)
      dima_sort = int_mb(k_range+h6b-1) * int_mb(k_range+h8b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-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('ccsd_lambda1_mod_13_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_13_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (h6b_1 - 1 + noab * (p4b_1 - noab - 1 + nvab * (p3b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p4b-1),int_mb(k_range+h6b-1),int_mb(k_range+h8b-1)
     &,4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_13_1',3
     &,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_13_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_13_1',5,MA_ERR)
      IF ((h7b .lt. h2b)) THEN
      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 * (h2b_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+h2b-1),int_mb(k_range+p3b-1),int_mb(k_range+p4b-1)
     &,1,2,4,3,-1.0d0)
      END IF
      IF ((h2b .le. h7b)) THEN
      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 * (h7b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_mb(k_range+p4b-1)
     &,2,1,4,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_13_1',6
     &,MA_ERR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p3b .eq. p4b) THEN
      nsuperp(isuperp) = nsuperp(isuperp) + 1
      ELSE
      isuperp = isuperp + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsuperp(1))/FACTORIAL(nsuperp(2)),dbl_mb(k_a_sort),dim_common,dbl_
     &mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_13
     &_1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_13
     &_1',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('
     &ccsd_lambda1_mod_13_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h7b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h8b-1),int_mb(k_range+h6b-1)
     &,2,1,4,3,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h8b -
     & 1 + noab * (h6b - 1 + noab * (h7b - 1 + noab * (h2b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_13_1',1
     &0,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_13
     &_1',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 OFFSET_ccsd_lambda1_mod_13_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 ( h2 h7 h6 h8 )_yt
      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 h2b
      INTEGER h7b
      INTEGER h6b
      INTEGER h8b
      length = 0
      DO h2b = 1,noab
      DO h7b = 1,noab
      DO h6b = 1,noab
      DO h8b = h6b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+h8b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h8b-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('ccsd_lambda1_mod_13_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h7b = 1,noab
      DO h6b = 1,noab
      DO h8b = h6b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+h8b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h8b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h8b - 1 + noab * (h6b - 1 + noab * (h7b 
     &- 1 + noab * (h2b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_
     &mb(k_range+h6b-1) * int_mb(k_range+h8b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_13_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 ( h2 h7 h6 h8 )_ytt + = 2 * Sum ( p3 ) * t ( p3 h8 )_t * i2 ( h2 h7 h6 p3 )_yt
      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 h2b
      INTEGER h7b
      INTEGER h8b
      INTEGER h6b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h8b_1
      INTEGER h2b_2
      INTEGER h7b_2
      INTEGER h6b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO h7b = 1,noab
      DO h8b = 1,noab
      DO h6b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h8b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+h8b-1)))) .eq. ieor(irrep_y,ieor(irrep_t
     &,irrep_t))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+h8b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_13_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h8b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p3b,h8b,p3b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h2b,h7b,h6b,p3b,h2b_2,h7b_2,h6b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h8b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_mb
     &(k_range+h6b-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('ccsd_lambda1_mod_13_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_13_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p3b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_13_2',3
     &,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_13_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_13_2',5,MA_ERR)
      IF ((h6b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h6b_2 - 1 + noab * (h7b_2 - 1 + noab * (h2b_
     &2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+h6b-1),int_mb(k_range+p3b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_13_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('ccsd_lambda1_mod_13
     &_2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_13
     &_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('
     &ccsd_lambda1_mod_13_2',9,MA_ERR)
      IF ((h6b .le. h8b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+h2b-1),int_mb(k_range+h8b-1)
     &,3,2,1,4,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h8b -
     & 1 + noab * (h6b - 1 + noab * (h7b - 1 + noab * (h2b - 1)))))
      END IF
      IF ((h8b .le. h6b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+h2b-1),int_mb(k_range+h8b-1)
     &,3,2,4,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h6b -
     & 1 + noab * (h8b - 1 + noab * (h7b - 1 + noab * (h2b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_13_2',1
     &0,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_13
     &_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 ccsd_lambda1_mod_13_2_1(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     i2 ( h2 h7 h6 p3 )_yt + = 1 * Sum ( p5 ) * t ( p5 h6 )_t * y ( h2 h7 p3 p5 )_y
      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 h2b
      INTEGER h7b
      INTEGER h6b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h6b_1
      INTEGER h2b_2
      INTEGER h7b_2
      INTEGER p3b_2
      INTEGER p5b_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 h2b = 1,noab
      DO h7b = 1,noab
      DO h6b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_13_2_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h6b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p5b,h6b,p5b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h2b,h7b,p3b,p5b,h2b_2,h7b_2,p3b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1)
      dima_sort = int_mb(k_range+h6b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_mb
     &(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_13_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_13_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (p5b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p5b-1)
     &,int_mb(k_range+h6b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_13_2_1'
     &,3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_13_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_13_2_1',5,MA_ERR)
      IF ((h7b .lt. h2b) .and. (p5b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (p5b_2 - noab - 1 + nvab * (h2b_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+h2b-1),int_mb(k_range+p5b-1),int_mb(k_range+p3b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h7b .lt. h2b) .and. (p3b .le. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p3b_2 - noab - 1 + nvab * (h2b_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+h2b-1),int_mb(k_range+p3b-1),int_mb(k_range+p5b-1)
     &,3,1,2,4,-1.0d0)
      END IF
      IF ((h2b .le. h7b) .and. (p5b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (p5b_2 - noab - 1 + nvab * (h7b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+p5b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h2b .le. h7b) .and. (p3b .le. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p3b_2 - noab - 1 + nvab * (h7b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_mb(k_range+p5b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_13_2_1'
     &,6,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_13
     &_2_1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_13
     &_2_1',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('
     &ccsd_lambda1_mod_13_2_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+h2b-1),int_mb(k_range+h6b-1)
     &,3,2,4,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (h6b - 1 + noab * (h7b - 1 + noab * (h2b - 1)))
     &))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_13_2_1'
     &,10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_13
     &_2_1',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 OFFSET_ccsd_lambda1_mod_13_2_1(l_a_offset,k_a_offset,si
     &ze)
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     i2 ( h2 h7 h6 p3 )_yt
      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 h2b
      INTEGER h7b
      INTEGER h6b
      INTEGER p3b
      length = 0
      DO h2b = 1,noab
      DO h7b = 1,noab
      DO h6b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p3b-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('ccsd_lambda1_mod_13_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h7b = 1,noab
      DO h6b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p3b - noab - 1 + nvab * (h6b - 1 + noab 
     &* (h7b - 1 + noab * (h2b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_
     &mb(k_range+h6b-1) * int_mb(k_range+p3b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_14(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     i0 ( h2 p1 )_ytv + = 1 * Sum ( p8 h6 p7 ) * i1 ( h2 p8 h6 p7 )_yt * v ( h6 p7 p1 p8 )_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 h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p8b
      INTEGER h6b
      INTEGER p7b
      INTEGER h2b_1
      INTEGER p8b_1
      INTEGER h6b_1
      INTEGER p7b_1
      INTEGER h6b_2
      INTEGER p7b_2
      INTEGER p1b_2
      INTEGER p8b_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 h2b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &y,ieor(irrep_t,irrep_v))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_14',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p8b = noab+1,noab+nvab
      DO h6b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+p7b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      CALL TCE_RESTRICTED_4(h2b,p8b,h6b,p7b,h2b_1,p8b_1,h6b_1,p7b_1)
      CALL TCE_RESTRICTED_4(h6b,p7b,p1b,p8b,h6b_2,p7b_2,p1b_2,p8b_2)
      dim_common = int_mb(k_range+p8b-1) * int_mb(k_range+h6b-1) * int_m
     &b(k_range+p7b-1)
      dima_sort = int_mb(k_range+h2b-1)
      dima = dim_common * dima_sort
      dimb_sort = 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('ccsd_lambda1_mod_14',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_14',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p7b_1
     & - noab - 1 + nvab * (h6b_1 - 1 + noab * (p8b_1 - noab - 1 + nvab 
     &* (h2b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+h6b-1),int_mb(k_range+p7b-1)
     &,1,4,3,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_14',3,M
     &A_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_14',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_14',5,MA_ERR)
      IF ((p8b .lt. p1b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p8b_2 - 1 + (noab+nvab) * (p7b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (p8b_2 - 1 + (noab+nvab) * (p7b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p1b_2,p8b_2,p7b_2,h6b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+p8b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p1b .le. p8b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (p7b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p8b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (p7b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p8b_2,p1b_2,p7b_2,h6b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+p1b-1),int_mb(k_range+p8b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_14',6,M
     &A_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('ccsd_lambda1_mod_14
     &',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_14
     &',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_lambda1_mod_14',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+h2b-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 * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_14',10,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_14
     &',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 ccsd_lambda1_mod_14_1(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 ( h2 p8 h6 p7 )_yt + = 1 * Sum ( h5 p3 ) * t ( p3 p8 h5 h6 )_t * y ( h2 h5 p3 p7 )_y
      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 h2b
      INTEGER p8b
      INTEGER h6b
      INTEGER p7b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER h5b
      INTEGER p8b_1
      INTEGER p3b_1
      INTEGER h6b_1
      INTEGER h5b_1
      INTEGER h2b_2
      INTEGER h5b_2
      INTEGER p7b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h2b = 1,noab
      DO p8b = noab+1,noab+nvab
      DO h6b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p8b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p7b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+p7b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p8b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p7b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_14_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      DO h5b = 1,noab
      IF (int_mb(k_spin+p8b-1)+int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+h5b-1)) THEN
      IF (ieor(int_mb(k_sym+p8b-1),ieor(int_mb(k_sym+p3b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+h5b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p8b,p3b,h6b,h5b,p8b_1,p3b_1,h6b_1,h5b_1)
      CALL TCE_RESTRICTED_4(h2b,h5b,p7b,p3b,h2b_2,h5b_2,p7b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1) * int_mb(k_range+h5b-1)
      dima_sort = int_mb(k_range+p8b-1) * int_mb(k_range+h6b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+p7b-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('ccsd_lambda1_mod_14_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_14_1',2,MA_ERR)
      IF ((p3b .le. p8b) .and. (h5b .le. h6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h5b_1 - 1 + noab * (p8b_1 - noab - 1 + nvab * (p3b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+h5b-1),int_mb(k_range+h6b-1)
     &,4,2,3,1,1.0d0)
      END IF
      IF ((p3b .le. p8b) .and. (h6b .lt. h5b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_1
     & - 1 + noab * (h6b_1 - 1 + noab * (p8b_1 - noab - 1 + nvab * (p3b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1)
     &,3,2,4,1,-1.0d0)
      END IF
      IF ((p8b .lt. p3b) .and. (h5b .le. h6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h5b_1 - 1 + noab * (p3b_1 - noab - 1 + nvab * (p8b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p8b-1)
     &,int_mb(k_range+p3b-1),int_mb(k_range+h5b-1),int_mb(k_range+h6b-1)
     &,4,1,3,2,-1.0d0)
      END IF
      IF ((p8b .lt. p3b) .and. (h6b .lt. h5b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_1
     & - 1 + noab * (h6b_1 - 1 + noab * (p3b_1 - noab - 1 + nvab * (p8b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p8b-1)
     &,int_mb(k_range+p3b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1)
     &,3,1,4,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_14_1',3
     &,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_14_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_14_1',5,MA_ERR)
      IF ((h5b .lt. h2b) .and. (p3b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p3b_2 - noab - 1 + nvab * (h2b_2 - 1 + noab 
     &* (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+h2b-1),int_mb(k_range+p3b-1),int_mb(k_range+p7b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h5b .lt. h2b) .and. (p7b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (h2b_2 - 1 + noab 
     &* (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+h2b-1),int_mb(k_range+p7b-1),int_mb(k_range+p3b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF ((h2b .le. h5b) .and. (p3b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p3b_2 - noab - 1 + nvab * (h5b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p3b-1),int_mb(k_range+p7b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h2b .le. h5b) .and. (p7b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (h5b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p7b-1),int_mb(k_range+p3b-1)
     &,3,1,2,4,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_14_1',6
     &,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_14
     &_1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_14
     &_1',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('
     &ccsd_lambda1_mod_14_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p8b-1)
     &,2,4,3,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p7b -
     & noab - 1 + nvab * (h6b - 1 + noab * (p8b - noab - 1 + nvab * (h2b
     & - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_14_1',1
     &0,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_14
     &_1',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 OFFSET_ccsd_lambda1_mod_14_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 ( h2 p8 h6 p7 )_yt
      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 h2b
      INTEGER p8b
      INTEGER h6b
      INTEGER p7b
      length = 0
      DO h2b = 1,noab
      DO p8b = noab+1,noab+nvab
      DO h6b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+p7b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p8b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p7b-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('ccsd_lambda1_mod_14_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO p8b = noab+1,noab+nvab
      DO h6b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+p7b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p8b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p7b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p7b - noab - 1 + nvab * (h6b - 1 + noab 
     &* (p8b - noab - 1 + nvab * (h2b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+p8b-1) * int_
     &mb(k_range+h6b-1) * int_mb(k_range+p7b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_lambda1_mod_14_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 ( h2 p8 h6 p7 )_ytt + = -1 * Sum ( h4 ) * t ( p8 h4 )_t * i2 ( h2 h4 h6 p7 )_yt
      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 h2b
      INTEGER p8b
      INTEGER h6b
      INTEGER p7b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER p8b_1
      INTEGER h4b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER h6b_2
      INTEGER p7b_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 h2b = 1,noab
      DO p8b = noab+1,noab+nvab
      DO h6b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p8b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p7b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+p7b-1)))) .eq. ieor(irrep_y,ieor(irrep_t
     &,irrep_t))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p8b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p7b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_14_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h4b = 1,noab
      IF (int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h4b-1)) THEN
      IF (ieor(int_mb(k_sym+p8b-1),int_mb(k_sym+h4b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p8b,h4b,p8b_1,h4b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,h6b,p7b,h2b_2,h4b_2,h6b_2,p7b_2)
      dim_common = int_mb(k_range+h4b-1)
      dima_sort = int_mb(k_range+p8b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h6b-1) * int_mb
     &(k_range+p7b-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('ccsd_lambda1_mod_14_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_14_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_1
     & - 1 + noab * (p8b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p8b-1)
     &,int_mb(k_range+h4b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_14_2',3
     &,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_14_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_14_2',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (h6b_2 - 1 + noab * (h4b_2 - 1 + noab * (h2b_
     &2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h6b-1),int_mb(k_range+p7b-1)
     &,4,3,1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_14_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('ccsd_lambda1_mod_14
     &_2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_14
     &_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('
     &ccsd_lambda1_mod_14_2',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h2b-1),int_mb(k_range+p8b-1)
     &,3,4,2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p7b -
     & noab - 1 + nvab * (h6b - 1 + noab * (p8b - noab - 1 + nvab * (h2b
     & - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_14_2',1
     &0,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_14
     &_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 ccsd_lambda1_mod_14_2_1(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     i2 ( h2 h4 h6 p7 )_yt + = 1 * Sum ( p5 ) * t ( p5 h6 )_t * y ( h2 h4 p5 p7 )_y
      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 h2b
      INTEGER h4b
      INTEGER h6b
      INTEGER p7b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h6b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER p7b_2
      INTEGER p5b_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 h2b = 1,noab
      DO h4b = 1,noab
      DO h6b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p7b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+p7b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h4b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p7b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_14_2_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h6b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p5b,h6b,p5b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,p7b,p5b,h2b_2,h4b_2,p7b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1)
      dima_sort = int_mb(k_range+h6b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h4b-1) * int_mb
     &(k_range+p7b-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('ccsd_lambda1_mod_14_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_lambda1_mod_14_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (p5b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p5b-1)
     &,int_mb(k_range+h6b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_lambda1_mod_14_2_1'
     &,3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_lambda1_mod_14_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_lambda1_mod_14_2_1',5,MA_ERR)
      IF ((h4b .lt. h2b) .and. (p5b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p5b_2 - noab - 1 + nvab * (h2b_2 - 1 + noab 
     &* (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p5b-1),int_mb(k_range+p7b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h4b .lt. h2b) .and. (p7b .lt. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (h2b_2 - 1 + noab 
     &* (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p7b-1),int_mb(k_range+p5b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF ((h2b .le. h4b) .and. (p5b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p5b_2 - noab - 1 + nvab * (h4b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p5b-1),int_mb(k_range+p7b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h2b .le. h4b) .and. (p7b .lt. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (h4b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p7b-1),int_mb(k_range+p5b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_lambda1_mod_14_2_1'
     &,6,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_lambda1_mod_14
     &_2_1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_lambda1_mod_14
     &_2_1',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('
     &ccsd_lambda1_mod_14_2_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h2b-1),int_mb(k_range+h6b-1)
     &,3,2,4,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p7b -
     & noab - 1 + nvab * (h6b - 1 + noab * (h4b - 1 + noab * (h2b - 1)))
     &))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_lambda1_mod_14_2_1'
     &,10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_lambda1_mod_14
     &_2_1',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 OFFSET_ccsd_lambda1_mod_14_2_1(l_a_offset,k_a_offset,si
     &ze)
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     i2 ( h2 h4 h6 p7 )_yt
      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 h2b
      INTEGER h4b
      INTEGER h6b
      INTEGER p7b
      length = 0
      DO h2b = 1,noab
      DO h4b = 1,noab
      DO h6b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+p7b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p7b-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('ccsd_lambda1_mod_14_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h4b = 1,noab
      DO h6b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+p7b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p7b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p7b - noab - 1 + nvab * (h6b - 1 + noab 
     &* (h4b - 1 + noab * (h2b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+h4b-1) * int_
     &mb(k_range+h6b-1) * int_mb(k_range+p7b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
