      SUBROUTINE ccsd_y_tr1(d_f1,d_i0,d_t1,d_t2,d_v2,d_x1,d_x2,d_y1,d_y2
     &,k_f1_offset,k_i0_offset,k_t1_offset,k_t2_offset,k_v2_offset,k_x1_
     &offset,k_x2_offset,k_y1_offset,k_y2_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_xv + = 1 * Sum ( p9 h10 ) * i1 ( p9 h10 )_x * v ( h2 h10 p1 p9 )_v
C         i1 ( p9 h10 )_x + = 1 * x ( p9 h10 )_x
C         i1 ( p9 h10 )_yx + = 1 * Sum ( h6 p5 ) * x ( p5 p9 h6 h10 )_x * y ( h6 p5 )_y
C         i1 ( p9 h10 )_yxt + = -1 * Sum ( h4 ) * t ( p9 h4 )_t * i2 ( h4 h10 )_yx
C             i2 ( h4 h10 )_yx + = 1 * Sum ( p6 ) * x ( p6 h10 )_x * y ( h4 p6 )_y
C             i2 ( h4 h10 )_yx + = -1/2 * Sum ( h8 p6 p7 ) * x ( p6 p7 h8 h10 )_x * y ( h4 h8 p6 p7 )_y
C         i1 ( p9 h10 )_ytx + = -1 * Sum ( h7 ) * x ( p9 h7 )_x * i2 ( h7 h10 )_yt
C             i2 ( h7 h10 )_yt + = 1 * Sum ( p3 ) * t ( p3 h10 )_t * y ( h7 p3 )_y
C             i2 ( h7 h10 )_yt + = 1/2 * Sum ( h5 p3 p4 ) * t ( p3 p4 h5 h10 )_t * y ( h5 h7 p3 p4 )_y
C         i1 ( p9 h10 )_ytx + = -1/2 * Sum ( h7 h8 p6 ) * x ( p6 p9 h7 h8 )_x * i2 ( h7 h8 h10 p6 )_yt
C             i2 ( h7 h8 h10 p6 )_yt + = -1 * Sum ( p3 ) * t ( p3 h10 )_t * y ( h7 h8 p3 p6 )_y
C         i1 ( p9 h10 )_yxt + = 1/2 * Sum ( h5 h6 p3 ) * t ( p3 p9 h5 h6 )_t * i2 ( h5 h6 h10 p3 )_yx
C             i2 ( h5 h6 h10 p3 )_yx + = -1 * Sum ( p8 ) * x ( p8 h10 )_x * y ( h5 h6 p3 p8 )_y
C     i0 ( h2 p1 )_fxy + = -1 * Sum ( h7 ) * y ( h7 p1 )_y * i1 ( h2 h7 )_fx
C         i1 ( h2 h7 )_fx + = 1 * Sum ( p6 ) * x ( p6 h7 )_x * i2 ( h2 p6 )_f
C             i2 ( h2 p6 )_f + = 1 * f ( h2 p6 )_f
C             i2 ( h2 p6 )_vt + = -1 * Sum ( h4 p3 ) * t ( p3 h4 )_t * v ( h2 h4 p3 p6 )_v
C         i1 ( h2 h7 )_vx + = 1 * Sum ( h3 p5 ) * x ( p5 h3 )_x * v ( h2 h3 h7 p5 )_v
C         i1 ( h2 h7 )_vx + = -1/2 * Sum ( h3 p4 p5 ) * x ( p4 p5 h3 h7 )_x * v ( h2 h3 p4 p5 )_v
C         i1 ( h2 h7 )_vxt + = 1 * Sum ( p3 ) * t ( p3 h7 )_t * i2 ( h2 p3 )_vx
C             i2 ( h2 p3 )_vx + = 1 * Sum ( h5 p6 ) * x ( p6 h5 )_x * v ( h2 h5 p3 p6 )_v
C     i0 ( h2 p1 )_yxf + = -1 * Sum ( h3 ) * i1 ( h2 h3 )_yx * f ( h3 p1 )_f
C         i1 ( h2 h3 )_yx + = 1 * Sum ( p4 ) * x ( p4 h3 )_x * y ( h2 p4 )_y
C         i1 ( h2 h3 )_yx + = 1/2 * Sum ( h6 p4 p5 ) * x ( p4 p5 h3 h6 )_x * y ( h2 h6 p4 p5 )_y
C     i0 ( h2 p1 )_yxv + = 1 * Sum ( h4 h3 ) * i1 ( h4 h3 )_yx * v ( h2 h3 h4 p1 )_v
C         i1 ( h4 h3 )_yx + = 1 * Sum ( p5 ) * x ( p5 h3 )_x * y ( h4 p5 )_y
C         i1 ( h4 h3 )_yx + = 1/2 * Sum ( h7 p5 p6 ) * x ( p5 p6 h3 h7 )_x * y ( h4 h7 p5 p6 )_y
C     i0 ( h2 p1 )_yxv + = 1 * Sum ( p4 p3 ) * i1 ( p4 p3 )_yx * v ( h2 p3 p1 p4 )_v
C         i1 ( p4 p3 )_yx + = 1 * Sum ( h5 ) * x ( p4 h5 )_x * y ( h5 p3 )_y
C         i1 ( p4 p3 )_yx + = 1/2 * Sum ( h6 h7 p5 ) * x ( p4 p5 h6 h7 )_x * y ( h6 h7 p3 p5 )_y
C     i0 ( h2 p1 )_vxy + = 1 * Sum ( p8 ) * y ( h2 p8 )_y * i1 ( p8 p1 )_vx
C         i1 ( p8 p1 )_vx + = -1 * Sum ( h3 p5 ) * x ( p5 h3 )_x * v ( h3 p8 p1 p5 )_v
C         i1 ( p8 p1 )_vxt + = -1 * Sum ( h4 ) * t ( p8 h4 )_t * i2 ( h4 p1 )_vx
C             i2 ( h4 p1 )_vx + = 1 * Sum ( h5 p6 ) * x ( p6 h5 )_x * v ( h4 h5 p1 p6 )_v
C         i1 ( p8 p1 )_vtx + = 1 * Sum ( h5 ) * x ( p8 h5 )_x * i2 ( h5 p1 )_vt
C             i2 ( h5 p1 )_vt + = 1 * Sum ( h4 p3 ) * t ( p3 h4 )_t * v ( h4 h5 p1 p3 )_v
C     i0 ( h2 p1 )_fxy + = -1 * Sum ( p10 h9 ) * y ( h2 h9 p1 p10 )_y * i1 ( p10 h9 )_fx
C         i1 ( p10 h9 )_fx + = 1 * Sum ( h8 ) * x ( p10 h8 )_x * i2 ( h8 h9 )_f
C             i2 ( h8 h9 )_f + = 1 * f ( h8 h9 )_f
C             i2 ( h8 h9 )_ft + = 1 * Sum ( p7 ) * t ( p7 h9 )_t * i3 ( h8 p7 )_f
C                 i3 ( h8 p7 )_f + = 1 * f ( h8 p7 )_f
C                 i3 ( h8 p7 )_vt + = 1 * Sum ( h6 p5 ) * t ( p5 h6 )_t * v ( h6 h8 p5 p7 )_v
C             i2 ( h8 h9 )_vt + = -1 * Sum ( h4 p3 ) * t ( p3 h4 )_t * v ( h4 h8 h9 p3 )_v
C             i2 ( h8 h9 )_vt + = 1/2 * Sum ( h6 p3 p4 ) * t ( p3 p4 h6 h9 )_t * v ( h6 h8 p3 p4 )_v
C         i1 ( p10 h9 )_fx + = -1 * Sum ( p5 ) * x ( p5 h9 )_x * i2 ( p10 p5 )_f
C             i2 ( p10 p5 )_f + = 1 * f ( p10 p5 )_f
C             i2 ( p10 p5 )_vt + = 1 * Sum ( h4 p3 ) * t ( p3 h4 )_t * v ( h4 p10 p3 p5 )_v
C         i1 ( p10 h9 )_vx + = 1 * Sum ( h3 p6 ) * x ( p6 h3 )_x * v ( h3 p10 h9 p6 )_v
C         i1 ( p10 h9 )_fx + = -1 * Sum ( h6 p7 ) * x ( p7 p10 h6 h9 )_x * i2 ( h6 p7 )_f
C             i2 ( h6 p7 )_f + = 1 * f ( h6 p7 )_f
C             i2 ( h6 p7 )_vt + = 1 * Sum ( h4 p3 ) * t ( p3 h4 )_t * v ( h4 h6 p3 p7 )_v
C         i1 ( p10 h9 )_vx + = 1/2 * Sum ( h7 h5 p8 ) * x ( p8 p10 h5 h7 )_x * i2 ( h5 h7 h9 p8 )_v
C             i2 ( h5 h7 h9 p8 )_v + = -1 * v ( h5 h7 h9 p8 )_v
C             i2 ( h5 h7 h9 p8 )_vt + = -1 * Sum ( p3 ) * t ( p3 h9 )_t * v ( h5 h7 p3 p8 )_v
C         i1 ( p10 h9 )_vx + = -1/2 * Sum ( h3 p5 p6 ) * x ( p5 p6 h3 h9 )_x * v ( h3 p10 p5 p6 )_v
C         i1 ( p10 h9 )_fxt + = 1 * Sum ( h12 ) * t ( p10 h12 )_t * i2 ( h12 h9 )_fx
C             i2 ( h12 h9 )_fx + = 1 * Sum ( p3 ) * x ( p3 h9 )_x * i3 ( h12 p3 )_f
C                 i3 ( h12 p3 )_f + = 1 * f ( h12 p3 )_f
C                 i3 ( h12 p3 )_vt + = -1 * Sum ( h6 p5 ) * t ( p5 h6 )_t * v ( h6 h12 p3 p5 )_v
C             i2 ( h12 h9 )_vx + = -1 * Sum ( h5 p7 ) * x ( p7 h5 )_x * v ( h5 h12 h9 p7 )_v
C             i2 ( h12 h9 )_vx + = 1/2 * Sum ( h5 p6 p7 ) * x ( p6 p7 h5 h9 )_x * v ( h5 h12 p6 p7 )_v
C             i2 ( h12 h9 )_vxt + = 1 * Sum ( p3 ) * t ( p3 h9 )_t * i3 ( h12 p3 )_vx
C                 i3 ( h12 p3 )_vx + = -1 * Sum ( h7 p8 ) * x ( p8 h7 )_x * v ( h7 h12 p3 p8 )_v
C         i1 ( p10 h9 )_vxt + = -1 * Sum ( p3 ) * t ( p3 h9 )_t * i2 ( p10 p3 )_vx
C             i2 ( p10 p3 )_vx + = -1 * Sum ( h5 p7 ) * x ( p7 h5 )_x * v ( h5 p10 p3 p7 )_v
C         i1 ( p10 h9 )_vxt + = -1 * Sum ( h6 p4 ) * t ( p4 p10 h6 h9 )_t * i2 ( h6 p4 )_vx
C             i2 ( h6 p4 )_vx + = 1 * Sum ( h7 p8 ) * x ( p8 h7 )_x * v ( h6 h7 p4 p8 )_v
C         i1 ( p10 h9 )_vxt + = -1/2 * Sum ( h5 h6 p4 ) * t ( p4 p10 h5 h6 )_t * i2 ( h5 h6 h9 p4 )_vx
C             i2 ( h5 h6 h9 p4 )_vx + = -1 * Sum ( p7 ) * x ( p7 h9 )_x * v ( h5 h6 p4 p7 )_v
C     i0 ( h2 p1 )_yxv + = -1/2 * Sum ( h4 h5 h3 ) * i1 ( h4 h5 h3 p1 )_yx * v ( h2 h3 h4 h5 )_v
C         i1 ( h4 h5 h3 p1 )_yx + = -1 * Sum ( p6 ) * x ( p6 h3 )_x * y ( h4 h5 p1 p6 )_y
C     i0 ( h2 p1 )_vxy + = -1 * Sum ( p9 h10 h11 ) * y ( h10 h11 p1 p9 )_y * i1 ( h2 p9 h10 h11 )_vx
C         i1 ( h2 p9 h10 h11 )_vx + = 1 * Sum ( p5 ) * x ( p5 h11 )_x * v ( h2 p9 h10 p5 )_v
C         i1 ( h2 p9 h10 h11 )_fx + = 1/2 * Sum ( p6 ) * x ( p6 p9 h10 h11 )_x * i2 ( h2 p6 )_f
C         i1 ( h2 p9 h10 h11 )_vx + = 1 * Sum ( h6 p4 ) * x ( p4 p9 h6 h11 )_x * i2 ( h2 h6 h10 p4 )_v
C             i2 ( h2 h6 h10 p4 )_v + = 1 * v ( h2 h6 h10 p4 )_v
C             i2 ( h2 h6 h10 p4 )_vt + = 1 * Sum ( p3 ) * t ( p3 h10 )_t * v ( h2 h6 p3 p4 )_v
C         i1 ( h2 p9 h10 h11 )_vx + = 1/4 * Sum ( p4 p5 ) * x ( p4 p5 h10 h11 )_x * v ( h2 p9 p4 p5 )_v
C         i1 ( h2 p9 h10 h11 )_vtx + = -1 * Sum ( h8 ) * x ( p9 h8 )_x * i2 ( h2 h8 h10 h11 )_vt
C             i2 ( h2 h8 h10 h11 )_vt + = -1 * Sum ( p3 ) * t ( p3 h10 )_t * i3 ( h2 h8 h11 p3 )_v
C                 i3 ( h2 h8 h11 p3 )_v + = 1 * v ( h2 h8 h11 p3 )_v
C                 i3 ( h2 h8 h11 p3 )_vt + = -1/2 * Sum ( p5 ) * t ( p5 h11 )_t * v ( h2 h8 p3 p5 )_v
C             i2 ( h2 h8 h10 h11 )_vt + = 1/4 * Sum ( p3 p4 ) * t ( p3 p4 h10 h11 )_t * v ( h2 h8 p3 p4 )_v
C         i1 ( h2 p9 h10 h11 )_vxt + = 1 * Sum ( h8 ) * t ( p9 h8 )_t * i2 ( h2 h8 h10 h11 )_vx
C             i2 ( h2 h8 h10 h11 )_vx + = -1 * Sum ( p6 ) * x ( p6 h11 )_x * v ( h2 h8 h10 p6 )_v
C             i2 ( h2 h8 h10 h11 )_vx + = -1/4 * Sum ( p5 p6 ) * x ( p5 p6 h10 h11 )_x * v ( h2 h8 p5 p6 )_v
C             i2 ( h2 h8 h10 h11 )_vxt + = -1 * Sum ( p3 ) * t ( p3 h10 )_t * i3 ( h2 h8 h11 p3 )_vx
C                 i3 ( h2 h8 h11 p3 )_vx + = 1 * Sum ( p7 ) * x ( p7 h11 )_x * v ( h2 h8 p3 p7 )_v
C         i1 ( h2 p9 h10 h11 )_vxt + = -1 * Sum ( p3 ) * t ( p3 h10 )_t * i2 ( h2 p9 h11 p3 )_vx
C             i2 ( h2 p9 h11 p3 )_vx + = -1 * Sum ( p6 ) * x ( p6 h11 )_x * v ( h2 p9 p3 p6 )_v
C         i1 ( h2 p9 h10 h11 )_vxt + = 1/2 * Sum ( p4 ) * t ( p4 p9 h10 h11 )_t * i2 ( h2 p4 )_vx
C             i2 ( h2 p4 )_vx + = 1 * Sum ( h7 p8 ) * x ( p8 h7 )_x * v ( h2 h7 p4 p8 )_v
C         i1 ( h2 p9 h10 h11 )_vxt + = 1 * Sum ( h6 p4 ) * t ( p4 p9 h6 h10 )_t * i2 ( h2 h6 h11 p4 )_vx
C             i2 ( h2 h6 h11 p4 )_vx + = 1 * Sum ( p7 ) * x ( p7 h11 )_x * v ( h2 h6 p4 p7 )_v
C     i0 ( h2 p1 )_yxv + = -1 * Sum ( h5 h3 p4 ) * i1 ( h2 h5 h3 p4 )_yx * v ( h3 p4 h5 p1 )_v
C         i1 ( h2 h5 h3 p4 )_yx + = 1 * Sum ( p6 ) * x ( p6 h3 )_x * y ( h2 h5 p4 p6 )_y
C     i0 ( h2 p1 )_yxv + = -1/2 * Sum ( p5 p3 p4 ) * i1 ( h2 p5 p3 p4 )_yx * v ( p3 p4 p1 p5 )_v
C         i1 ( h2 p5 p3 p4 )_yx + = -1 * Sum ( h6 ) * x ( p5 h6 )_x * y ( h2 h6 p3 p4 )_y
C     i0 ( h2 p1 )_yxv + = 1/2 * Sum ( p11 h12 h10 ) * i1 ( h2 p11 h10 h12 )_yx * v ( h10 h12 p1 p11 )_v
C         i1 ( h2 p11 h10 h12 )_yx + = -1 * Sum ( p6 ) * x ( p6 p11 h10 h12 )_x * y ( h2 p6 )_y
C         i1 ( h2 p11 h10 h12 )_yxt + = 1/2 * Sum ( h4 ) * t ( p11 h4 )_t * i2 ( h2 h4 h10 h12 )_yx
C             i2 ( h2 h4 h10 h12 )_yx + = 1 * Sum ( p7 p8 ) * x ( p7 p8 h10 h12 )_x * y ( h2 h4 p7 p8 )_y
C             i2 ( h2 h4 h10 h12 )_yxt + = -4 * Sum ( p5 ) * t ( p5 h12 )_t * i3 ( h2 h4 h10 p5 )_yx
C                 i3 ( h2 h4 h10 p5 )_yx + = 1 * Sum ( p8 ) * x ( p8 h10 )_x * y ( h2 h4 p5 p8 )_y
C         i1 ( h2 p11 h10 h12 )_ytx + = 2 * Sum ( h8 p7 ) * x ( p7 p11 h8 h10 )_x * i2 ( h2 h8 h12 p7 )_yt
C             i2 ( h2 h8 h12 p7 )_yt + = 1 * Sum ( p3 ) * t ( p3 h12 )_t * y ( h2 h8 p3 p7 )_y
C         i1 ( h2 p11 h10 h12 )_yxt + = -1 * t ( p11 h12 )_t * i2 ( h2 h10 )_yx
C             i2 ( h2 h10 )_yx + = -1 * Sum ( h8 p6 p7 ) * x ( p6 p7 h8 h10 )_x * y ( h2 h8 p6 p7 )_y
C         i1 ( h2 p11 h10 h12 )_ytx + = 1 * x ( p11 h10 )_x * i2 ( h2 h12 )_yt
C             i2 ( h2 h12 )_yt + = -1 * Sum ( h5 p3 p4 ) * t ( p3 p4 h5 h12 )_t * y ( h2 h5 p3 p4 )_y
C         i1 ( h2 p11 h10 h12 )_yxt + = 2 * Sum ( h5 p3 ) * t ( p3 p11 h5 h12 )_t * i2 ( h2 h5 h10 p3 )_yx
C             i2 ( h2 h5 h10 p3 )_yx + = 1 * Sum ( p8 ) * x ( p8 h10 )_x * y ( h2 h5 p3 p8 )_y
C         i1 ( h2 p11 h10 h12 )_ytx + = 1/2 * Sum ( h8 ) * x ( p11 h8 )_x * i2 ( h2 h8 h10 h12 )_yt
C             i2 ( h2 h8 h10 h12 )_yt + = 1 * Sum ( p3 p4 ) * t ( p3 p4 h10 h12 )_t * y ( h2 h8 p3 p4 )_y
C             i2 ( h2 h8 h10 h12 )_ytt + = -2 * Sum ( p3 ) * t ( p3 h12 )_t * i3 ( h2 h8 h10 p3 )_yt
C                 i3 ( h2 h8 h10 p3 )_yt + = 1 * Sum ( p5 ) * t ( p5 h10 )_t * y ( h2 h8 p3 p5 )_y
C     i0 ( h2 p1 )_yxv + = 1/4 * Sum ( h4 h8 h9 ) * i1 ( h2 h4 h8 h9 )_yx * v ( h8 h9 h4 p1 )_v
C         i1 ( h2 h4 h8 h9 )_yx + = -1 * Sum ( p6 p7 ) * x ( p6 p7 h8 h9 )_x * y ( h2 h4 p6 p7 )_y
C         i1 ( h2 h4 h8 h9 )_yxt + = -4 * Sum ( p3 ) * t ( p3 h8 )_t * i2 ( h2 h4 h9 p3 )_yx
C             i2 ( h2 h4 h9 p3 )_yx + = 1 * Sum ( p7 ) * x ( p7 h9 )_x * y ( h2 h4 p3 p7 )_y
C     i0 ( h2 p1 )_yxv + = -1 * Sum ( p5 h11 p8 ) * i1 ( h2 p5 h11 p8 )_yx * v ( h11 p8 p1 p5 )_v
C         i1 ( h2 p5 h11 p8 )_yx + = 1 * Sum ( h7 p6 ) * x ( p5 p6 h7 h11 )_x * y ( h2 h7 p6 p8 )_y
C         i1 ( h2 p5 h11 p8 )_yxt + = -1 * Sum ( h4 ) * t ( p5 h4 )_t * i2 ( h2 h4 h11 p8 )_yx
C             i2 ( h2 h4 h11 p8 )_yx + = -1 * Sum ( p7 ) * x ( p7 h11 )_x * y ( h2 h4 p7 p8 )_y
C         i1 ( h2 p5 h11 p8 )_ytx + = 1 * Sum ( h7 ) * x ( p5 h7 )_x * i2 ( h2 h7 h11 p8 )_yt
C             i2 ( h2 h7 h11 p8 )_yt + = 1 * Sum ( p3 ) * t ( p3 h11 )_t * y ( h2 h7 p3 p8 )_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_i1
      INTEGER k_i1_offset
      INTEGER d_v2
      INTEGER k_v2_offset
      INTEGER d_y1
      INTEGER k_y1_offset
      INTEGER d_f1
      INTEGER k_f1_offset
      INTEGER d_y2
      INTEGER k_y2_offset
      INTEGER l_i1_offset
      INTEGER d_x1
      INTEGER k_x1_offset
      INTEGER size_i1
      INTEGER d_x2
      INTEGER k_x2_offset
      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 OFFSET_ccsd_y_tr1_1_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_y_tr1_1_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_y_tr1_1_1(d_x1,k_x1_offset,d_i1,k_i1_offset)
      CALL ccsd_y_tr1_1_2(d_x2,k_x2_offset,d_y1,k_y1_offset,d_i1,k_i1_of
     &fset)
      CALL OFFSET_ccsd_y_tr1_1_3_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_1_3_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_1_3_1(d_x1,k_x1_offset,d_y1,k_y1_offset,d_i2,k_i2_
     &offset)
      CALL ccsd_y_tr1_1_3_2(d_x2,k_x2_offset,d_y2,k_y2_offset,d_i2,k_i2_
     &offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_1_3(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_1_4_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_1_4_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_1_4_1(d_t1,k_t1_offset,d_y1,k_y1_offset,d_i2,k_i2_
     &offset)
      CALL ccsd_y_tr1_1_4_2(d_t2,k_t2_offset,d_y2,k_y2_offset,d_i2,k_i2_
     &offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_1_4(d_x1,k_x1_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_1_5_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_1_5_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_1_5_1(d_t1,k_t1_offset,d_y2,k_y2_offset,d_i2,k_i2_
     &offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_1_5(d_x2,k_x2_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_1_6_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_1_6_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_1_6_1(d_x1,k_x1_offset,d_y2,k_y2_offset,d_i2,k_i2_
     &offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_1_6(d_t2,k_t2_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_y_tr1_1(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_i0_offs
     &et)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_2_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_y_tr1_2_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL OFFSET_ccsd_y_tr1_2_1_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_2_1_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_2_1_1(d_f1,k_f1_offset,d_i2,k_i2_offset)
      CALL ccsd_y_tr1_2_1_2(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i2,k_i2_
     &offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_2_1(d_x1,k_x1_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL ccsd_y_tr1_2_2(d_x1,k_x1_offset,d_v2,k_v2_offset,d_i1,k_i1_of
     &fset)
      CALL ccsd_y_tr1_2_3(d_x2,k_x2_offset,d_v2,k_v2_offset,d_i1,k_i1_of
     &fset)
      CALL OFFSET_ccsd_y_tr1_2_4_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_2_4_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_2_4_1(d_x1,k_x1_offset,d_v2,k_v2_offset,d_i2,k_i2_
     &offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_2_4(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_y_tr1_2(d_y1,k_y1_offset,d_i1,k_i1_offset,d_i0,k_i0_offs
     &et)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_3_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_y_tr1_3_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_y_tr1_3_1(d_x1,k_x1_offset,d_y1,k_y1_offset,d_i1,k_i1_of
     &fset)
      CALL ccsd_y_tr1_3_2(d_x2,k_x2_offset,d_y2,k_y2_offset,d_i1,k_i1_of
     &fset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_y_tr1_3(d_i1,k_i1_offset,d_f1,k_f1_offset,d_i0,k_i0_offs
     &et)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_4_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_y_tr1_4_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_y_tr1_4_1(d_x1,k_x1_offset,d_y1,k_y1_offset,d_i1,k_i1_of
     &fset)
      CALL ccsd_y_tr1_4_2(d_x2,k_x2_offset,d_y2,k_y2_offset,d_i1,k_i1_of
     &fset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_y_tr1_4(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_i0_offs
     &et)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_5_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_y_tr1_5_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_y_tr1_5_1(d_x1,k_x1_offset,d_y1,k_y1_offset,d_i1,k_i1_of
     &fset)
      CALL ccsd_y_tr1_5_2(d_x2,k_x2_offset,d_y2,k_y2_offset,d_i1,k_i1_of
     &fset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_y_tr1_5(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_i0_offs
     &et)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_6_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_y_tr1_6_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_y_tr1_6_1(d_x1,k_x1_offset,d_v2,k_v2_offset,d_i1,k_i1_of
     &fset)
      CALL OFFSET_ccsd_y_tr1_6_2_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_6_2_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_6_2_1(d_x1,k_x1_offset,d_v2,k_v2_offset,d_i2,k_i2_
     &offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_6_2(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_6_3_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_6_3_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_6_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_y_tr1_6_3(d_x1,k_x1_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_y_tr1_6(d_y1,k_y1_offset,d_i1,k_i1_offset,d_i0,k_i0_offs
     &et)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_7_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_y_tr1_7_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL OFFSET_ccsd_y_tr1_7_1_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_7_1_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_7_1_1(d_f1,k_f1_offset,d_i2,k_i2_offset)
      CALL OFFSET_ccsd_y_tr1_7_1_2_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('ccsd_y_tr1_7_1_2_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL ccsd_y_tr1_7_1_2_1(d_f1,k_f1_offset,d_i3,k_i3_offset)
      CALL ccsd_y_tr1_7_1_2_2(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL ccsd_y_tr1_7_1_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_y_tr1',-1,M
     &A_ERR)
      CALL ccsd_y_tr1_7_1_3(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i2,k_i2_
     &offset)
      CALL ccsd_y_tr1_7_1_4(d_t2,k_t2_offset,d_v2,k_v2_offset,d_i2,k_i2_
     &offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_7_1(d_x1,k_x1_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_7_2_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_7_2_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_7_2_1(d_f1,k_f1_offset,d_i2,k_i2_offset)
      CALL ccsd_y_tr1_7_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_y_tr1_7_2(d_x1,k_x1_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL ccsd_y_tr1_7_3(d_x1,k_x1_offset,d_v2,k_v2_offset,d_i1,k_i1_of
     &fset)
      CALL OFFSET_ccsd_y_tr1_7_4_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_7_4_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_7_4_1(d_f1,k_f1_offset,d_i2,k_i2_offset)
      CALL ccsd_y_tr1_7_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_y_tr1_7_4(d_x2,k_x2_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_7_5_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_7_5_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_7_5_1(d_v2,k_v2_offset,d_i2,k_i2_offset)
      CALL ccsd_y_tr1_7_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_y_tr1_7_5(d_x2,k_x2_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL ccsd_y_tr1_7_6(d_x2,k_x2_offset,d_v2,k_v2_offset,d_i1,k_i1_of
     &fset)
      CALL OFFSET_ccsd_y_tr1_7_7_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_7_7_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_ccsd_y_tr1_7_7_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('ccsd_y_tr1_7_7_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL ccsd_y_tr1_7_7_1_1(d_f1,k_f1_offset,d_i3,k_i3_offset)
      CALL ccsd_y_tr1_7_7_1_2(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL ccsd_y_tr1_7_7_1(d_x1,k_x1_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_y_tr1',-1,M
     &A_ERR)
      CALL ccsd_y_tr1_7_7_2(d_x1,k_x1_offset,d_v2,k_v2_offset,d_i2,k_i2_
     &offset)
      CALL ccsd_y_tr1_7_7_3(d_x2,k_x2_offset,d_v2,k_v2_offset,d_i2,k_i2_
     &offset)
      CALL OFFSET_ccsd_y_tr1_7_7_4_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('ccsd_y_tr1_7_7_4_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL ccsd_y_tr1_7_7_4_1(d_x1,k_x1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL ccsd_y_tr1_7_7_4(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_y_tr1',-1,M
     &A_ERR)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_7_7(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_7_8_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_7_8_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_7_8_1(d_x1,k_x1_offset,d_v2,k_v2_offset,d_i2,k_i2_
     &offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_7_8(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_7_9_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_7_9_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_7_9_1(d_x1,k_x1_offset,d_v2,k_v2_offset,d_i2,k_i2_
     &offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_7_9(d_t2,k_t2_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_7_10_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_7_10_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_7_10_1(d_x1,k_x1_offset,d_v2,k_v2_offset,d_i2,k_i2
     &_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_7_10(d_t2,k_t2_offset,d_i2,k_i2_offset,d_i1,k_i1_o
     &ffset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_y_tr1_7(d_y2,k_y2_offset,d_i1,k_i1_offset,d_i0,k_i0_offs
     &et)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_8_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_y_tr1_8_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_y_tr1_8_1(d_x1,k_x1_offset,d_y2,k_y2_offset,d_i1,k_i1_of
     &fset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_y_tr1_8(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_i0_offs
     &et)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_9_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_y_tr1_9_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_y_tr1_9_1(d_x1,k_x1_offset,d_v2,k_v2_offset,d_i1,k_i1_of
     &fset)
      CALL OFFSET_ccsd_y_tr1_9_2_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_9_2_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_9_2_1(d_f1,k_f1_offset,d_i2,k_i2_offset)
      CALL ccsd_y_tr1_9_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_y_tr1_9_2(d_x2,k_x2_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_9_3_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_9_3_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_9_3_1(d_v2,k_v2_offset,d_i2,k_i2_offset)
      CALL ccsd_y_tr1_9_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_y_tr1_9_3(d_x2,k_x2_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL ccsd_y_tr1_9_4(d_x2,k_x2_offset,d_v2,k_v2_offset,d_i1,k_i1_of
     &fset)
      CALL OFFSET_ccsd_y_tr1_9_5_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_9_5_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_ccsd_y_tr1_9_5_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('ccsd_y_tr1_9_5_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL ccsd_y_tr1_9_5_1_1(d_v2,k_v2_offset,d_i3,k_i3_offset)
      CALL ccsd_y_tr1_9_5_1_2(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL ccsd_y_tr1_9_5_1(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_y_tr1',-1,M
     &A_ERR)
      CALL ccsd_y_tr1_9_5_2(d_t2,k_t2_offset,d_v2,k_v2_offset,d_i2,k_i2_
     &offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_9_5(d_x1,k_x1_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_9_6_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_9_6_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_9_6_1(d_x1,k_x1_offset,d_v2,k_v2_offset,d_i2,k_i2_
     &offset)
      CALL ccsd_y_tr1_9_6_2(d_x2,k_x2_offset,d_v2,k_v2_offset,d_i2,k_i2_
     &offset)
      CALL OFFSET_ccsd_y_tr1_9_6_3_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('ccsd_y_tr1_9_6_3_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL ccsd_y_tr1_9_6_3_1(d_x1,k_x1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL ccsd_y_tr1_9_6_3(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_y_tr1',-1,M
     &A_ERR)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_9_6(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_9_7_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_9_7_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_9_7_1(d_x1,k_x1_offset,d_v2,k_v2_offset,d_i2,k_i2_
     &offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_9_7(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_9_8_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_9_8_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_9_8_1(d_x1,k_x1_offset,d_v2,k_v2_offset,d_i2,k_i2_
     &offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_9_8(d_t2,k_t2_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_9_9_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_9_9_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_9_9_1(d_x1,k_x1_offset,d_v2,k_v2_offset,d_i2,k_i2_
     &offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_9_9(d_t2,k_t2_offset,d_i2,k_i2_offset,d_i1,k_i1_of
     &fset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_y_tr1_9(d_y2,k_y2_offset,d_i1,k_i1_offset,d_i0,k_i0_offs
     &et)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_10_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_y_tr1_10_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_y_tr1_10_1(d_x1,k_x1_offset,d_y2,k_y2_offset,d_i1,k_i1_o
     &ffset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_y_tr1_10(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_i0_off
     &set)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_11_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_y_tr1_11_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_y_tr1_11_1(d_x1,k_x1_offset,d_y2,k_y2_offset,d_i1,k_i1_o
     &ffset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_y_tr1_11(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_i0_off
     &set)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_12_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_y_tr1_12_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_y_tr1_12_1(d_x2,k_x2_offset,d_y1,k_y1_offset,d_i1,k_i1_o
     &ffset)
      CALL OFFSET_ccsd_y_tr1_12_2_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_12_2_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_12_2_1(d_x2,k_x2_offset,d_y2,k_y2_offset,d_i2,k_i2
     &_offset)
      CALL OFFSET_ccsd_y_tr1_12_2_2_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('ccsd_y_tr1_12_2_2_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL ccsd_y_tr1_12_2_2_1(d_x1,k_x1_offset,d_y2,k_y2_offset,d_i3,k_
     &i3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL ccsd_y_tr1_12_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_y_tr1',-1,M
     &A_ERR)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_12_2(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k_i1_o
     &ffset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_12_3_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_12_3_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_12_3_1(d_t1,k_t1_offset,d_y2,k_y2_offset,d_i2,k_i2
     &_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_12_3(d_x2,k_x2_offset,d_i2,k_i2_offset,d_i1,k_i1_o
     &ffset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_12_4_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_12_4_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_12_4_1(d_x2,k_x2_offset,d_y2,k_y2_offset,d_i2,k_i2
     &_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_12_4(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k_i1_o
     &ffset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_12_5_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_12_5_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_12_5_1(d_t2,k_t2_offset,d_y2,k_y2_offset,d_i2,k_i2
     &_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_12_5(d_x1,k_x1_offset,d_i2,k_i2_offset,d_i1,k_i1_o
     &ffset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_12_6_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_12_6_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_12_6_1(d_x1,k_x1_offset,d_y2,k_y2_offset,d_i2,k_i2
     &_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_12_6(d_t2,k_t2_offset,d_i2,k_i2_offset,d_i1,k_i1_o
     &ffset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_12_7_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_12_7_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_12_7_1(d_t2,k_t2_offset,d_y2,k_y2_offset,d_i2,k_i2
     &_offset)
      CALL OFFSET_ccsd_y_tr1_12_7_2_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('ccsd_y_tr1_12_7_2_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL ccsd_y_tr1_12_7_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_y_tr1_12_7_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_y_tr1',-1,M
     &A_ERR)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_12_7(d_x1,k_x1_offset,d_i2,k_i2_offset,d_i1,k_i1_o
     &ffset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_y_tr1_12(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_i0_off
     &set)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_13_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_y_tr1_13_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_y_tr1_13_1(d_x2,k_x2_offset,d_y2,k_y2_offset,d_i1,k_i1_o
     &ffset)
      CALL OFFSET_ccsd_y_tr1_13_2_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_13_2_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_13_2_1(d_x1,k_x1_offset,d_y2,k_y2_offset,d_i2,k_i2
     &_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_13_2(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k_i1_o
     &ffset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_y_tr1_13(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_i0_off
     &set)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_14_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsd_y_tr1_14_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsd_y_tr1_14_1(d_x2,k_x2_offset,d_y2,k_y2_offset,d_i1,k_i1_o
     &ffset)
      CALL OFFSET_ccsd_y_tr1_14_2_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_14_2_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_14_2_1(d_x1,k_x1_offset,d_y2,k_y2_offset,d_i2,k_i2
     &_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_14_2(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k_i1_o
     &ffset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL OFFSET_ccsd_y_tr1_14_3_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsd_y_tr1_14_3_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsd_y_tr1_14_3_1(d_t1,k_t1_offset,d_y2,k_y2_offset,d_i2,k_i2
     &_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsd_y_tr1_14_3(d_x1,k_x1_offset,d_i2,k_i2_offset,d_i1,k_i1_o
     &ffset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsd_y_tr1_14(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_i0_off
     &set)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsd_y_tr1',-1,M
     &A_ERR)
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_xv + = 1 * Sum ( p9 h10 ) * i1 ( p9 h10 )_x * 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 NXTVAL
      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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_
     &x,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_y_tr1_1',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_x) 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_y_tr1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_1',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_y_tr1_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_1',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_y_tr1_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_y_tr1_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_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+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_y_tr1_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_1',11,MA
     &_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_1_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_x + = 1 * x ( p9 h10 )_x
      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 NXTVAL
      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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x) 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_y_tr1_1_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_1_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_y_tr1_1_1',2,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_y_tr1_1_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_y_tr1_1_1',4,MA_ERR
     &)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_1_1',5,M
     &A_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_1_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_x
      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_x) 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_y_tr1_1_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_x) 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_y_tr1_1_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yx + = 1 * Sum ( h6 p5 ) * x ( p5 p9 h6 h10 )_x * 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p9b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER h6b
      INTEGER p9b_1
      INTEGER p5b_1
      INTEGER h10b_1
      INTEGER h6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x)) 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_y_tr1_1_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+p9b-1)+int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p5b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h6b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p9b,p5b,h10b,h6b,p9b_1,p5b_1,h10b_1,h6b_1)
      CALL TCE_RESTRICTED_2(h6b,p5b,h6b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1) * int_mb(k_range+h6b-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_y_tr1_1_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_1_2',2,MA_ERR)
      IF ((p5b .le. p9b) .and. (h6b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h6b_1 - 1 + noab * (p9b_1 - noab - 1 + nvab * (p5b
     &_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+h6b-1),int_mb(k_range+h10b-1
     &),4,2,3,1,1.0d0)
      END IF
      IF ((p5b .le. p9b) .and. (h10b .lt. h6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h10b_1 - 1 + noab * (p9b_1 - noab - 1 + nvab * (p5b
     &_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+h10b-1),int_mb(k_range+h6b-1
     &),3,2,4,1,-1.0d0)
      END IF
      IF ((p9b .lt. p5b) .and. (h6b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h6b_1 - 1 + noab * (p5b_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+p5b-1),int_mb(k_range+h6b-1),int_mb(k_range+h10b-1
     &),4,1,3,2,-1.0d0)
      END IF
      IF ((p9b .lt. p5b) .and. (h10b .lt. h6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h10b_1 - 1 + noab * (p5b_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+p5b-1),int_mb(k_range+h10b-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_y_tr1_1_2',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_1_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_1_2',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_y_tr1_1_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_y_tr1_1_2',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_1_2',8,M
     &A_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_y_tr1_1_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_y_tr1_1_2',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_1_2',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_1_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yxt + = -1 * Sum ( h4 ) * t ( p9 h4 )_t * i2 ( h4 h10 )_yx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p9b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER p9b_1
      INTEGER h4b_1
      INTEGER h4b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x,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_y_tr1_1_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h4b = 1,noab
      IF (int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h4b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),int_mb(k_sym+h4b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p9b,h4b,p9b_1,h4b_1)
      CALL TCE_RESTRICTED_2(h4b,h10b,h4b_2,h10b_2)
      dim_common = int_mb(k_range+h4b-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_y_tr1_1_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_1_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_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+h4b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_1_3',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_1_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_1_3',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h10b_
     &2 - 1 + noab * (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+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_1_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_y_tr1_1_3',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_1_3',8,M
     &A_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_y_tr1_1_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_y_tr1_1_3',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_1_3',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_1_3_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 )_yx + = 1 * Sum ( p6 ) * x ( p6 h10 )_x * y ( h4 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p6b
      INTEGER p6b_1
      INTEGER h10b_1
      INTEGER h4b_2
      INTEGER p6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h4b = 1,noab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h10b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h10b-1)) .eq. ieor(irrep
     &_y,irrep_x)) THEN
      dimc = int_mb(k_range+h4b-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_y_tr1_1_3_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p6b = noab+1,noab+nvab
      IF (int_mb(k_spin+p6b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p6b-1),int_mb(k_sym+h10b-1)) .eq. irrep_x) T
     &HEN
      CALL TCE_RESTRICTED_2(p6b,h10b,p6b_1,h10b_1)
      CALL TCE_RESTRICTED_2(h4b,p6b,h4b_2,p6b_2)
      dim_common = int_mb(k_range+p6b-1)
      dima_sort = int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-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_y_tr1_1_3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_1_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 * (p6b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_1_3_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_1_3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_1_3_1',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_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+p6b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_1_3_1',6,MA_E
     &RR)
      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_y_tr1_1_3_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_1_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_y_tr1_1_3_1',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h4b-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 * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_1_3_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_1_3_1',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_1_3_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 )_yx
      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 h10b
      length = 0
      DO h4b = 1,noab
      DO h10b = 1,noab
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h10b-1)) .eq. ieor(irrep
     &_y,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-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_y_tr1_1_3_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO h10b = 1,noab
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h10b-1)) .eq. ieor(irrep
     &_y,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h10b-
     &1).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h10b - 1 + noab * (h4b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+h10b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_1_3_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 )_yx + = -1/2 * Sum ( h8 p6 p7 ) * x ( p6 p7 h8 h10 )_x * y ( h4 h8 p6 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p6b
      INTEGER p7b
      INTEGER h8b
      INTEGER p6b_1
      INTEGER p7b_1
      INTEGER h10b_1
      INTEGER h8b_1
      INTEGER h4b_2
      INTEGER h8b_2
      INTEGER p6b_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 nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h4b = 1,noab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h10b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h10b-1)) .eq. ieor(irrep
     &_y,irrep_x)) THEN
      dimc = int_mb(k_range+h4b-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_y_tr1_1_3_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p6b = noab+1,noab+nvab
      DO p7b = p6b,noab+nvab
      DO h8b = 1,noab
      IF (int_mb(k_spin+p6b-1)+int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p6b-1),ieor(int_mb(k_sym+p7b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h8b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p6b,p7b,h10b,h8b,p6b_1,p7b_1,h10b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h4b,h8b,p6b,p7b,h4b_2,h8b_2,p6b_2,p7b_2)
      dim_common = int_mb(k_range+p6b-1) * int_mb(k_range+p7b-1) * int_m
     &b(k_range+h8b-1)
      dima_sort = int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-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_y_tr1_1_3_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_1_3_2',2,MA_ERR)
      IF ((h8b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h8b_1 - 1 + noab * (p7b_1 - noab - 1 + nvab * (p6b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+h8b-1),int_mb(k_range+h10b-1
     &),4,3,2,1,1.0d0)
      END IF
      IF ((h10b .lt. h8b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (h10b_1 - 1 + noab * (p7b_1 - noab - 1 + nvab * (p6b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+h10b-1),int_mb(k_range+h8b-1
     &),3,4,2,1,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_1_3_2',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_1_3_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_1_3_2',5,MA_ERR)
      IF ((h8b .lt. h4b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p6b_2 - noab - 1 + nvab * (h4b_2 - 1 + noab 
     &* (h8b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p6b-1),int_mb(k_range+p7b-1)
     &,2,1,4,3,-1.0d0)
      END IF
      IF ((h4b .le. h8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p6b_2 - noab - 1 + nvab * (h8b_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+h8b-1),int_mb(k_range+p6b-1),int_mb(k_range+p7b-1)
     &,1,2,4,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_1_3_2',6,MA_E
     &RR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p6b .eq. p7b) 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_y_tr1_1_3_2',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_1_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_y_tr1_1_3_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h4b-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 * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_1_3_2',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_1_3_2',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_1_4(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_ytx + = -1 * Sum ( h7 ) * x ( p9 h7 )_x * i2 ( h7 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p9b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h7b
      INTEGER p9b_1
      INTEGER h7b_1
      INTEGER h7b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x))) 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_y_tr1_1_4',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_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p9b,h7b,p9b_1,h7b_1)
      CALL TCE_RESTRICTED_2(h7b,h10b,h7b_2,h10b_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+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_y_tr1_1_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_1_4',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_y_tr1_1_4',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_1_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_1_4',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h10b_
     &2 - 1 + noab * (h7b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h7b-1)
     &,int_mb(k_range+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_1_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_y_tr1_1_4',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_1_4',8,M
     &A_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_y_tr1_1_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)
      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_y_tr1_1_4',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_1_4',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_1_4_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h7 h10 )_yt + = 1 * Sum ( p3 ) * t ( p3 h10 )_t * y ( h7 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h7b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h10b_1
      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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h7b = 1,noab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h7b-1)+int_mb(k_spin+h10b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+h7b-1),int_mb(k_sym+h10b-1)) .eq. ieor(irrep
     &_y,irrep_t)) THEN
      dimc = int_mb(k_range+h7b-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_y_tr1_1_4_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+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h10b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p3b,h10b,p3b_1,h10b_1)
      CALL TCE_RESTRICTED_2(h7b,p3b,h7b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = 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_y_tr1_1_4_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_1_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 * (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+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_1_4_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_1_4_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_1_4_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 * (h7b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h7b-1)
     &,int_mb(k_range+p3b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_1_4_1',6,MA_E
     &RR)
      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_y_tr1_1_4_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_1_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_y_tr1_1_4_1',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+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 * (h7b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_1_4_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_1_4_1',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_1_4_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h7 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 h7b
      INTEGER h10b
      length = 0
      DO h7b = 1,noab
      DO h10b = 1,noab
      IF (int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+h7b-1),int_mb(k_sym+h10b-1)) .eq. ieor(irrep
     &_y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h7b-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_y_tr1_1_4_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h7b = 1,noab
      DO h10b = 1,noab
      IF (int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+h7b-1),int_mb(k_sym+h10b-1)) .eq. ieor(irrep
     &_y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h7b-1)+int_mb(k_spin+h10b-
     &1).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h10b - 1 + noab * (h7b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h7b-1) * int_mb(k_range+h10b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_1_4_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h7 h10 )_yt + = 1/2 * Sum ( h5 p3 p4 ) * t ( p3 p4 h5 h10 )_t * y ( h5 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h7b
      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 h7b_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 NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h7b = 1,noab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h7b-1)+int_mb(k_spin+h10b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+h7b-1),int_mb(k_sym+h10b-1)) .eq. ieor(irrep
     &_y,irrep_t)) THEN
      dimc = int_mb(k_range+h7b-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_y_tr1_1_4_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(h7b,h5b,p3b,p4b,h7b_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+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_y_tr1_1_4_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_1_4_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_y_tr1_1_4_2',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_1_4_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_1_4_2',5,MA_ERR)
      IF ((h5b .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 
     &* (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+h7b-1),int_mb(k_range+p3b-1),int_mb(k_range+p4b-1)
     &,2,1,4,3,1.0d0)
      END IF
      IF ((h7b .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 
     &* (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+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_y_tr1_1_4_2',6,MA_E
     &RR)
      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_y_tr1_1_4_2',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_1_4_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_y_tr1_1_4_2',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+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 * (h7b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_1_4_2',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_1_4_2',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_1_5(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_ytx + = -1/2 * Sum ( h7 h8 p6 ) * x ( p6 p9 h7 h8 )_x * i2 ( h7 h8 h10 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p9b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p6b
      INTEGER h7b
      INTEGER h8b
      INTEGER p9b_1
      INTEGER p6b_1
      INTEGER h7b_1
      INTEGER h8b_1
      INTEGER h7b_2
      INTEGER h8b_2
      INTEGER h10b_2
      INTEGER p6b_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 NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x))) 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_y_tr1_1_5',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p6b = noab+1,noab+nvab
      DO h7b = 1,noab
      DO h8b = h7b,noab
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p6b-1) .eq. int_mb(k_spin+h
     &7b-1)+int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p6b-1),ieor(int_mb(
     &k_sym+h7b-1),int_mb(k_sym+h8b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p9b,p6b,h7b,h8b,p9b_1,p6b_1,h7b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h7b,h8b,h10b,p6b,h7b_2,h8b_2,h10b_2,p6b_2)
      dim_common = int_mb(k_range+p6b-1) * int_mb(k_range+h7b-1) * int_m
     &b(k_range+h8b-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_y_tr1_1_5',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_1_5',2,MA_ERR)
      IF ((p6b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (h7b_1 - 1 + noab * (p9b_1 - noab - 1 + nvab * (p6b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h7b-1),int_mb(k_range+h8b-1)
     &,2,4,3,1,1.0d0)
      END IF
      IF ((p9b .lt. p6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (h7b_1 - 1 + noab * (p6b_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+p6b-1),int_mb(k_range+h7b-1),int_mb(k_range+h8b-1)
     &,1,4,3,2,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_1_5',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_1_5',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_1_5',5,MA_ERR)
      IF ((h10b .le. p6b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - noab - 1 + nvab * (h10b_2 - 1 + noab * (h8b_2 - 1 + noab * (h7b
     &_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h7b-1)
     &,int_mb(k_range+h8b-1),int_mb(k_range+h10b-1),int_mb(k_range+p6b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_1_5',6,MA_ERR
     &)
      nsubh(1) = 1
      nsubh(2) = 1
      isubh = 1
      IF (h7b .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_y_tr1_1_5',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_1_5',8,M
     &A_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_y_tr1_1_5',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_y_tr1_1_5',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_1_5',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_1_5_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h7 h8 h10 p6 )_yt + = -1 * Sum ( p3 ) * t ( p3 h10 )_t * y ( h7 h8 p3 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h7b
      INTEGER h8b
      INTEGER h10b
      INTEGER p6b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h10b_1
      INTEGER h7b_2
      INTEGER h8b_2
      INTEGER p6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h7b = 1,noab
      DO h8b = h7b,noab
      DO h10b = 1,noab
      DO p6b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h7b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+p6b-1).ne.8)) THEN
      IF (int_mb(k_spin+h7b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+p6b-1)) THEN
      IF (ieor(int_mb(k_sym+h7b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+p6b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      dimc = int_mb(k_range+h7b-1) * int_mb(k_range+h8b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+p6b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_1_5_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+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h10b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p3b,h10b,p3b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h7b,h8b,p6b,p3b,h7b_2,h8b_2,p6b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h7b-1) * int_mb(k_range+h8b-1) * int_mb
     &(k_range+p6b-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_y_tr1_1_5_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_1_5_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &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+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_1_5_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_1_5_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_1_5_1',5,MA_ERR)
      IF ((p3b .le. p6b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - noab - 1 + nvab * (p3b_2 - noab - 1 + nvab * (h8b_2 - 1 + noab 
     &* (h7b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h7b-1)
     &,int_mb(k_range+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p6b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((p6b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (p6b_2 - noab - 1 + nvab * (h8b_2 - 1 + noab 
     &* (h7b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h7b-1)
     &,int_mb(k_range+h8b-1),int_mb(k_range+p6b-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_y_tr1_1_5_1',6,MA_E
     &RR)
      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_y_tr1_1_5_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_1_5_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_y_tr1_1_5_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p6b-1)
     &,int_mb(k_range+h8b-1),int_mb(k_range+h7b-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),(p6b -
     & noab - 1 + nvab * (h10b - 1 + noab * (h8b - 1 + noab * (h7b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_1_5_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_1_5_1',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_1_5_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h7 h8 h10 p6 )_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 h7b
      INTEGER h8b
      INTEGER h10b
      INTEGER p6b
      length = 0
      DO h7b = 1,noab
      DO h8b = h7b,noab
      DO h10b = 1,noab
      DO p6b = noab+1,noab+nvab
      IF (int_mb(k_spin+h7b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+p6b-1)) THEN
      IF (ieor(int_mb(k_sym+h7b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+p6b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h7b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+p6b-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_y_tr1_1_5_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h7b = 1,noab
      DO h8b = h7b,noab
      DO h10b = 1,noab
      DO p6b = noab+1,noab+nvab
      IF (int_mb(k_spin+h7b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+p6b-1)) THEN
      IF (ieor(int_mb(k_sym+h7b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+p6b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h7b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+p6b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p6b - noab - 1 + nvab * (h10b - 1 + noab
     & * (h8b - 1 + noab * (h7b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h7b-1) * int_mb(k_range+h8b-1) * int_
     &mb(k_range+h10b-1) * int_mb(k_range+p6b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_1_6(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yxt + = 1/2 * Sum ( h5 h6 p3 ) * t ( p3 p9 h5 h6 )_t * i2 ( h5 h6 h10 p3 )_yx
      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 NXTVAL
      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 NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x,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_y_tr1_1_6',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_y_tr1_1_6',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_1_6',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_y_tr1_1_6',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_1_6',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_1_6',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_y_tr1_1_6',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_y_tr1_1_6',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_1_6',8,M
     &A_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_y_tr1_1_6',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_y_tr1_1_6',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_1_6',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_1_6_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yx + = -1 * Sum ( p8 ) * x ( p8 h10 )_x * 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 NXTVAL
      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 p8b
      INTEGER p8b_1
      INTEGER h10b_1
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER p3b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x)) 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_y_tr1_1_6_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p8b = noab+1,noab+nvab
      IF (int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p8b-1),int_mb(k_sym+h10b-1)) .eq. irrep_x) T
     &HEN
      CALL TCE_RESTRICTED_2(p8b,h10b,p8b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h5b,h6b,p3b,p8b,h5b_2,h6b_2,p3b_2,p8b_2)
      dim_common = int_mb(k_range+p8b-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_y_tr1_1_6_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_1_6_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &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+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_1_6_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_1_6_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_1_6_1',5,MA_ERR)
      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)
     &,4,2,1,3,-1.0d0)
      END IF
      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)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_1_6_1',6,MA_E
     &RR)
      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_y_tr1_1_6_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_1_6_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_y_tr1_1_6_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_y_tr1_1_6_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_1_6_1',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_1_6_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yx
      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_x)) 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_y_tr1_1_6_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_x)) 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_y_tr1_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_fxy + = -1 * Sum ( h7 ) * y ( h7 p1 )_y * i1 ( h2 h7 )_fx
      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 NXTVAL
      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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_
     &f,ieor(irrep_x,irrep_y))) 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_y_tr1_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_y_tr1_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_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_y_tr1_2',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_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_y_tr1_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_y_tr1_2',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_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_y_tr1_2',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_2',11,MA
     &_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_fx + = 1 * Sum ( p6 ) * x ( p6 h7 )_x * i2 ( h2 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h7b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p6b
      INTEGER p6b_1
      INTEGER h7b_1
      INTEGER h2b_2
      INTEGER p6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x)) 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_y_tr1_2_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p6b = noab+1,noab+nvab
      IF (int_mb(k_spin+p6b-1) .eq. int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+p6b-1),int_mb(k_sym+h7b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p6b,h7b,p6b_1,h7b_1)
      CALL TCE_RESTRICTED_2(h2b,p6b,h2b_2,p6b_2)
      dim_common = int_mb(k_range+p6b-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_y_tr1_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_1
     & - 1 + noab * (p6b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+h7b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_2_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_2_1',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_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+p6b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_2_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_2_1',8,M
     &A_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_y_tr1_2_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+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_y_tr1_2_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_2_1',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_2_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_fx
      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. ieor(irrep_
     &f,irrep_x)) THEN
      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_y_tr1_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. ieor(irrep_
     &f,irrep_x)) THEN
      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_y_tr1_2_1_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p6 )_f + = 1 * f ( h2 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p6b
      INTEGER dimc
      INTEGER h2b_1
      INTEGER p6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p6b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p6b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p6b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p6b-1)) .eq. irrep_f) TH
     &EN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p6b-1)
      CALL TCE_RESTRICTED_2(h2b,p6b,h2b_1,p6b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h2b-1) * int_mb(k_range+p6b-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_y_tr1_2_1_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_2_1_1',1,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p6b_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+p6b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_2_1_1',2,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_y_tr1_2_1_1',3,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+p6b-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),(p6b -
     & noab - 1 + nvab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_2_1_1',4,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_2_1_1',5
     &,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_2_1_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p6 )_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 p6b
      length = 0
      DO h2b = 1,noab
      DO p6b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p6b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p6b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p6b-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_y_tr1_2_1_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO p6b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p6b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p6b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p6b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p6b - 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+p6b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_2_1_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p6 )_vt + = -1 * Sum ( h4 p3 ) * t ( p3 h4 )_t * v ( h2 h4 p3 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p6b
      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 p6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p6b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p6b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p6b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p6b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p6b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_2_1_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(h2b,h4b,p6b,p3b,h2b_2,h4b_2,p6b_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+p6b-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_y_tr1_2_1_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_2_1_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_y_tr1_2_1_2',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_2_1_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_2_1_2',5,MA_ERR)
      IF ((h4b .lt. h2b) .and. (p3b .le. p6b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - 1 + (noab+nvab) * (p3b_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),
     &(p6b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p6b_2,p3b_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+p3b-1),int_mb(k_range+p6b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h4b .lt. h2b) .and. (p6b .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) * (p6b_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) * (p6b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p3b_2,p6b_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+p6b-1),int_mb(k_range+p3b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF ((h2b .le. h4b) .and. (p3b .le. p6b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - 1 + (noab+nvab) * (p3b_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),
     &(p6b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p6b_2,p3b_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+p3b-1),int_mb(k_range+p6b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h2b .le. h4b) .and. (p6b .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) * (p6b_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) * (p6b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p3b_2,p6b_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+p6b-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_y_tr1_2_1_2',6,MA_E
     &RR)
      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_y_tr1_2_1_2',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_2_1_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_y_tr1_2_1_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p6b-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),(p6b -
     & noab - 1 + nvab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_2_1_2',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_2_1_2',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_2_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_vx + = 1 * Sum ( h3 p5 ) * x ( p5 h3 )_x * v ( h2 h3 h7 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h7b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER h3b
      INTEGER p5b_1
      INTEGER h3b_1
      INTEGER h2b_2
      INTEGER h3b_2
      INTEGER h7b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x)) 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_y_tr1_2_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      DO h3b = 1,noab
      IF (int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h3b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p5b,h3b,p5b_1,h3b_1)
      CALL TCE_RESTRICTED_4(h2b,h3b,h7b,p5b,h2b_2,h3b_2,h7b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1) * int_mb(k_range+h3b-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_y_tr1_2_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_2_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h3b_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+h3b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_2_2',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_2_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_2_2',5,MA_ERR)
      IF ((h3b .lt. h2b) .and. (h7b .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) * (h7b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h3b_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) * (h7b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h3b_2 - 1)))),p5b_2,h7b_2,h2b_2,h3b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h7b-1),int_mb(k_range+p5b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF ((h2b .le. h3b) .and. (h7b .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) * (h7b_2 - 1 + (noab+nvab) * (h3b_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) * (h7b_2 - 1 + (noab+nvab) * (h3b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p5b_2,h7b_2,h3b_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+h3b-1),int_mb(k_range+h7b-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_y_tr1_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_y_tr1_2_2',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_2_2',8,M
     &A_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_y_tr1_2_2',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_y_tr1_2_2',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_2_2',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_2_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_vx + = -1/2 * Sum ( h3 p4 p5 ) * x ( p4 p5 h3 h7 )_x * v ( h2 h3 p4 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h7b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p4b
      INTEGER p5b
      INTEGER h3b
      INTEGER p4b_1
      INTEGER p5b_1
      INTEGER h7b_1
      INTEGER h3b_1
      INTEGER h2b_2
      INTEGER h3b_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 NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x)) 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_y_tr1_2_3',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 h3b = 1,noab
      IF (int_mb(k_spin+p4b-1)+int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h
     &7b-1)+int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+p4b-1),ieor(int_mb(k_sym+p5b-1),ieor(int_mb(
     &k_sym+h7b-1),int_mb(k_sym+h3b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p4b,p5b,h7b,h3b,p4b_1,p5b_1,h7b_1,h3b_1)
      CALL TCE_RESTRICTED_4(h2b,h3b,p4b,p5b,h2b_2,h3b_2,p4b_2,p5b_2)
      dim_common = int_mb(k_range+p4b-1) * int_mb(k_range+p5b-1) * int_m
     &b(k_range+h3b-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_y_tr1_2_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_2_3',2,MA_ERR)
      IF ((h3b .le. h7b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_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+h7b-1)
     &,4,3,2,1,1.0d0)
      END IF
      IF ((h7b .lt. h3b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h3b_1
     & - 1 + noab * (h7b_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+h7b-1),int_mb(k_range+h3b-1)
     &,3,4,2,1,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_2_3',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_2_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_2_3',5,MA_ERR)
      IF ((h3b .lt. h2b)) 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) * (p4b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h3b_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) * (p4b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h3b_2 - 1)))),p5b_2,p4b_2,h2b_2,h3b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-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. h3b)) 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) * (p4b_2 - 1 + (noab+nvab) * (h3b_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) * (p4b_2 - 1 + (noab+nvab) * (h3b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p5b_2,p4b_2,h3b_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+h3b-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_y_tr1_2_3',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_y_tr1_2_3',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_2_3',8,M
     &A_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_y_tr1_2_3',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_y_tr1_2_3',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_2_3',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_2_4(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_vxt + = 1 * Sum ( p3 ) * t ( p3 h7 )_t * i2 ( h2 p3 )_vx
      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 NXTVAL
      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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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,ieor(irrep_x,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_y_tr1_2_4',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_y_tr1_2_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_2_4',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_y_tr1_2_4',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_2_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_2_4',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_y_tr1_2_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_y_tr1_2_4',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_2_4',8,M
     &A_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_y_tr1_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)
      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_y_tr1_2_4',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_2_4',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_2_4_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_vx + = 1 * Sum ( h5 p6 ) * x ( p6 h5 )_x * v ( h2 h5 p3 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p6b
      INTEGER h5b
      INTEGER p6b_1
      INTEGER h5b_1
      INTEGER h2b_2
      INTEGER h5b_2
      INTEGER p3b_2
      INTEGER p6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x)) 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_y_tr1_2_4_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p6b = noab+1,noab+nvab
      DO h5b = 1,noab
      IF (int_mb(k_spin+p6b-1) .eq. int_mb(k_spin+h5b-1)) THEN
      IF (ieor(int_mb(k_sym+p6b-1),int_mb(k_sym+h5b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p6b,h5b,p6b_1,h5b_1)
      CALL TCE_RESTRICTED_4(h2b,h5b,p3b,p6b,h2b_2,h5b_2,p3b_2,p6b_2)
      dim_common = int_mb(k_range+p6b-1) * int_mb(k_range+h5b-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_y_tr1_2_4_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_2_4_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_1
     & - 1 + noab * (p6b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+h5b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_2_4_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_2_4_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_2_4_1',5,MA_ERR)
      IF ((h5b .lt. h2b) .and. (p6b .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) * (p6b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h5b_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) * (p6b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h5b_2 - 1)))),p3b_2,p6b_2,h2b_2,h5b_2)
      end if
      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+p6b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h5b .lt. h2b) .and. (p3b .le. p6b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h5b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p6b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h5b_2 - 1)))),p6b_2,p3b_2,h2b_2,h5b_2)
      end if
      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+p6b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF ((h2b .le. h5b) .and. (p6b .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) * (p6b_2 - 1 + (noab+nvab) * (h5b_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) * (p6b_2 - 1 + (noab+nvab) * (h5b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p3b_2,p6b_2,h5b_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+h5b-1),int_mb(k_range+p6b-1),int_mb(k_range+p3b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h2b .le. h5b) .and. (p3b .le. p6b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h5b_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),
     &(p6b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h5b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p6b_2,p3b_2,h5b_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+h5b-1),int_mb(k_range+p3b-1),int_mb(k_range+p6b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_2_4_1',6,MA_E
     &RR)
      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_y_tr1_2_4_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_2_4_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_y_tr1_2_4_1',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_y_tr1_2_4_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_2_4_1',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_2_4_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_vx
      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. ieor(irrep_
     &v,irrep_x)) THEN
      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_y_tr1_2_4_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. ieor(irrep_
     &v,irrep_x)) THEN
      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_y_tr1_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yxf + = -1 * Sum ( h3 ) * i1 ( h2 h3 )_yx * 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 NXTVAL
      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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x,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_y_tr1_3',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_x)) 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_y_tr1_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_3',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_y_tr1_3',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_3',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_y_tr1_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_y_tr1_3',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_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_y_tr1_3',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_3',11,MA
     &_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_3_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yx + = 1 * Sum ( p4 ) * x ( p4 h3 )_x * 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 NXTVAL
      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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x)) 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_y_tr1_3_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_x) 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_y_tr1_3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_3_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_y_tr1_3_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_3_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_y_tr1_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_y_tr1_3_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_3_1',8,M
     &A_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_y_tr1_3_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_y_tr1_3_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_3_1',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_3_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yx
      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_x)) 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_y_tr1_3_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_x)) 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_y_tr1_3_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yx + = 1/2 * Sum ( h6 p4 p5 ) * x ( p4 p5 h3 h6 )_x * 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 NXTVAL
      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 NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x)) 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_y_tr1_3_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_x) 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_y_tr1_3_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_3_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_y_tr1_3_2',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_3_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_3_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_y_tr1_3_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_y_tr1_3_2',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_3_2',8,M
     &A_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_y_tr1_3_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_y_tr1_3_2',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_3_2',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_4(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yxv + = 1 * Sum ( h4 h3 ) * i1 ( h4 h3 )_yx * v ( h2 h3 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER h3b
      INTEGER h4b_1
      INTEGER h3b_1
      INTEGER h2b_2
      INTEGER h3b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x,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_y_tr1_4',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h4b = 1,noab
      DO h3b = 1,noab
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h3b-1)) .eq. ieor(irrep_
     &y,irrep_x)) THEN
      CALL TCE_RESTRICTED_2(h4b,h3b,h4b_1,h3b_1)
      CALL TCE_RESTRICTED_4(h2b,h3b,p1b,h4b,h2b_2,h3b_2,p1b_2,h4b_2)
      dim_common = int_mb(k_range+h4b-1) * int_mb(k_range+h3b-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_y_tr1_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_4',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h3b_1
     & - 1 + noab * (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+h3b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_4',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_4',5,MA_ERR)
      IF ((h3b .lt. h2b) .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) * (h2b_2 - 1 + (noab
     &+nvab) * (h3b_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) * (h2b_2 - 1 + (noab
     &+nvab) * (h3b_2 - 1)))),p1b_2,h4b_2,h2b_2,h3b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h4b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h2b .le. h3b) .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) * (h3b_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) * (h3b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p1b_2,h4b_2,h3b_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+h3b-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_y_tr1_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_y_tr1_4',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_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_y_tr1_4',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_4',11,MA
     &_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_4_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h4 h3 )_yx + = 1 * Sum ( p5 ) * x ( p5 h3 )_x * y ( h4 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h3b_1
      INTEGER h4b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h4b = 1,noab
      DO h3b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h3b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h3b-1)) .eq. ieor(irrep_
     &y,irrep_x)) THEN
      dimc = int_mb(k_range+h4b-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_y_tr1_4_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+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h3b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p5b,h3b,p5b_1,h3b_1)
      CALL TCE_RESTRICTED_2(h4b,p5b,h4b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1)
      dima_sort = int_mb(k_range+h3b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-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_y_tr1_4_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_4_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h3b_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+h3b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_4_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_4_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_4_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 * (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+p5b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_4_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_4_1',8,M
     &A_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_y_tr1_4_1',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h4b-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 * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_4_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_4_1',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_4_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h4 h3 )_yx
      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 h3b
      length = 0
      DO h4b = 1,noab
      DO h3b = 1,noab
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h3b-1)) .eq. ieor(irrep_
     &y,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-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_y_tr1_4_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO h3b = 1,noab
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h3b-1)) .eq. ieor(irrep_
     &y,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h3b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h3b - 1 + noab * (h4b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+h3b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_4_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h4 h3 )_yx + = 1/2 * Sum ( h7 p5 p6 ) * x ( p5 p6 h3 h7 )_x * y ( h4 h7 p5 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p6b
      INTEGER h7b
      INTEGER p5b_1
      INTEGER p6b_1
      INTEGER h3b_1
      INTEGER h7b_1
      INTEGER h4b_2
      INTEGER h7b_2
      INTEGER p5b_2
      INTEGER p6b_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 NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h4b = 1,noab
      DO h3b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h3b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h3b-1)) .eq. ieor(irrep_
     &y,irrep_x)) THEN
      dimc = int_mb(k_range+h4b-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_y_tr1_4_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      DO p6b = p5b,noab+nvab
      DO h7b = 1,noab
      IF (int_mb(k_spin+p5b-1)+int_mb(k_spin+p6b-1) .eq. int_mb(k_spin+h
     &3b-1)+int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),ieor(int_mb(k_sym+p6b-1),ieor(int_mb(
     &k_sym+h3b-1),int_mb(k_sym+h7b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p5b,p6b,h3b,h7b,p5b_1,p6b_1,h3b_1,h7b_1)
      CALL TCE_RESTRICTED_4(h4b,h7b,p5b,p6b,h4b_2,h7b_2,p5b_2,p6b_2)
      dim_common = int_mb(k_range+p5b-1) * int_mb(k_range+p6b-1) * int_m
     &b(k_range+h7b-1)
      dima_sort = int_mb(k_range+h3b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-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_y_tr1_4_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_4_2',2,MA_ERR)
      IF ((h7b .lt. h3b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h3b_1
     & - 1 + noab * (h7b_1 - 1 + noab * (p6b_1 - noab - 1 + nvab * (p5b_
     &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+p6b-1),int_mb(k_range+h7b-1),int_mb(k_range+h3b-1)
     &,4,3,2,1,-1.0d0)
      END IF
      IF ((h3b .le. h7b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_1
     & - 1 + noab * (h3b_1 - 1 + noab * (p6b_1 - noab - 1 + nvab * (p5b_
     &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+p6b-1),int_mb(k_range+h3b-1),int_mb(k_range+h7b-1)
     &,3,4,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_4_2',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_4_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_4_2',5,MA_ERR)
      IF ((h7b .lt. h4b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - noab - 1 + nvab * (p5b_2 - noab - 1 + nvab * (h4b_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+h4b-1),int_mb(k_range+p5b-1),int_mb(k_range+p6b-1)
     &,2,1,4,3,-1.0d0)
      END IF
      IF ((h4b .le. h7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - noab - 1 + nvab * (p5b_2 - noab - 1 + nvab * (h7b_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+h7b-1),int_mb(k_range+p5b-1),int_mb(k_range+p6b-1)
     &,1,2,4,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_4_2',6,MA_ERR
     &)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p5b .eq. p6b) 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_y_tr1_4_2',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_4_2',8,M
     &A_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_y_tr1_4_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h4b-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 * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_4_2',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_4_2',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_5(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yxv + = 1 * Sum ( p4 p3 ) * i1 ( p4 p3 )_yx * v ( h2 p3 p1 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p4b
      INTEGER p3b
      INTEGER p4b_1
      INTEGER p3b_1
      INTEGER h2b_2
      INTEGER p3b_2
      INTEGER p1b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x,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_y_tr1_5',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p4b = noab+1,noab+nvab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+p4b-1),int_mb(k_sym+p3b-1)) .eq. ieor(irrep_
     &y,irrep_x)) THEN
      CALL TCE_RESTRICTED_2(p4b,p3b,p4b_1,p3b_1)
      CALL TCE_RESTRICTED_4(h2b,p3b,p1b,p4b,h2b_2,p3b_2,p1b_2,p4b_2)
      dim_common = int_mb(k_range+p4b-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_y_tr1_5',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_5',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p3b_1
     & - noab - 1 + nvab * (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+p3b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_5',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_5',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_5',5,MA_ERR)
      IF ((h2b .le. p3b) .and. (p4b .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) * (p4b_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) * (p4b_2 - 1 + (noab+nvab) * (p3b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p1b_2,p4b_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+p4b-1),int_mb(k_range+p1b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h2b .le. p3b) .and. (p1b .le. 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) * (p1b_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),
     &(p4b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (p3b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p4b_2,p1b_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+p1b-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_y_tr1_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_y_tr1_5',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_5',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_y_tr1_5',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_5',11,MA
     &_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_5_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p4 p3 )_yx + = 1 * Sum ( h5 ) * x ( p4 h5 )_x * 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p4b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h5b
      INTEGER p4b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p4b = noab+1,noab+nvab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p4b-1)+int_mb(k_spin+p3b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+p4b-1),int_mb(k_sym+p3b-1)) .eq. ieor(irrep_
     &y,irrep_x)) THEN
      dimc = int_mb(k_range+p4b-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_y_tr1_5_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h5b = 1,noab
      IF (int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+h5b-1)) THEN
      IF (ieor(int_mb(k_sym+p4b-1),int_mb(k_sym+h5b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p4b,h5b,p4b_1,h5b_1)
      CALL TCE_RESTRICTED_2(h5b,p3b,h5b_2,p3b_2)
      dim_common = int_mb(k_range+h5b-1)
      dima_sort = int_mb(k_range+p4b-1)
      dima = dim_common * dima_sort
      dimb_sort = 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_y_tr1_5_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_5_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_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+h5b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_5_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_5_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_5_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 * (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),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_5_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_y_tr1_5_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_5_1',8,M
     &A_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_y_tr1_5_1',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+p4b-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 * (p4b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_5_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_5_1',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_5_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p4 p3 )_yx
      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 p4b
      INTEGER p3b
      length = 0
      DO p4b = noab+1,noab+nvab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+p4b-1),int_mb(k_sym+p3b-1)) .eq. ieor(irrep_
     &y,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p4b-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_y_tr1_5_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO p4b = noab+1,noab+nvab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+p4b-1),int_mb(k_sym+p3b-1)) .eq. ieor(irrep_
     &y,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p4b-1)+int_mb(k_spin+p3b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p3b - noab - 1 + nvab * (p4b - noab - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+p4b-1) * int_mb(k_range+p3b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_5_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p4 p3 )_yx + = 1/2 * Sum ( h6 h7 p5 ) * x ( p4 p5 h6 h7 )_x * y ( h6 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p4b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER h6b
      INTEGER h7b
      INTEGER p4b_1
      INTEGER p5b_1
      INTEGER h6b_1
      INTEGER h7b_1
      INTEGER h6b_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 nsubh(2)
      INTEGER isubh
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p4b = noab+1,noab+nvab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p4b-1)+int_mb(k_spin+p3b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+p4b-1),int_mb(k_sym+p3b-1)) .eq. ieor(irrep_
     &y,irrep_x)) THEN
      dimc = int_mb(k_range+p4b-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_y_tr1_5_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
      DO h7b = h6b,noab
      IF (int_mb(k_spin+p4b-1)+int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h
     &6b-1)+int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+p4b-1),ieor(int_mb(k_sym+p5b-1),ieor(int_mb(
     &k_sym+h6b-1),int_mb(k_sym+h7b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p4b,p5b,h6b,h7b,p4b_1,p5b_1,h6b_1,h7b_1)
      CALL TCE_RESTRICTED_4(h6b,h7b,p3b,p5b,h6b_2,h7b_2,p3b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1) * int_mb(k_range+h6b-1) * int_m
     &b(k_range+h7b-1)
      dima_sort = int_mb(k_range+p4b-1)
      dima = dim_common * dima_sort
      dimb_sort = 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_y_tr1_5_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_5_2',2,MA_ERR)
      IF ((p5b .lt. p4b)) 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 * (p5b_
     &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+p4b-1),int_mb(k_range+h6b-1),int_mb(k_range+h7b-1)
     &,2,4,3,1,-1.0d0)
      END IF
      IF ((p4b .le. p5b)) 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 * (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+h7b-1)
     &,1,4,3,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_5_2',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_5_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_5_2',5,MA_ERR)
      IF ((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 
     &* (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+h7b-1),int_mb(k_range+p5b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((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 
     &* (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+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_y_tr1_5_2',6,MA_ERR
     &)
      nsubh(1) = 1
      nsubh(2) = 1
      isubh = 1
      IF (h6b .eq. h7b) 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_y_tr1_5_2',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_5_2',8,M
     &A_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_y_tr1_5_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+p4b-1),2,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 * (p4b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_5_2',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_5_2',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_6(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_vxy + = 1 * Sum ( p8 ) * y ( h2 p8 )_y * i1 ( p8 p1 )_vx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p8b
      INTEGER h2b_1
      INTEGER p8b_1
      INTEGER p8b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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,ieor(irrep_x,irrep_y))) 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_y_tr1_6',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p8b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p8b-1)) .eq. irrep_y) TH
     &EN
      CALL TCE_RESTRICTED_2(h2b,p8b,h2b_1,p8b_1)
      CALL TCE_RESTRICTED_2(p8b,p1b,p8b_2,p1b_2)
      dim_common = int_mb(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_y_tr1_6',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_6',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p8b_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+p8b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_6',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_6',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_6',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (p8b_2 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+p8b-1)
     &,int_mb(k_range+p1b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_6',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_y_tr1_6',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_6',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_y_tr1_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)
      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_y_tr1_6',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_6',11,MA
     &_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_6_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p8 p1 )_vx + = -1 * Sum ( h3 p5 ) * x ( p5 h3 )_x * v ( h3 p8 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p8b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER h3b
      INTEGER p5b_1
      INTEGER h3b_1
      INTEGER p8b_2
      INTEGER h3b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p8b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p8b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+p8b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,irrep_x)) THEN
      dimc = int_mb(k_range+p8b-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_y_tr1_6_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      DO h3b = 1,noab
      IF (int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h3b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p5b,h3b,p5b_1,h3b_1)
      CALL TCE_RESTRICTED_4(p8b,h3b,p1b,p5b,p8b_2,h3b_2,p1b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1) * int_mb(k_range+h3b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = 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_y_tr1_6_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_6_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h3b_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+h3b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_6_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_6_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_6_1',5,MA_ERR)
      IF ((h3b .le. p8b) .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) * (p8b_2 - 1 + (noab
     &+nvab) * (h3b_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) * (p8b_2 - 1 + (noab
     &+nvab) * (h3b_2 - 1)))),p1b_2,p5b_2,p8b_2,h3b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+p5b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h3b .le. p8b) .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) * (p8b_2 - 1 + (noab
     &+nvab) * (h3b_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) * (p8b_2 - 1 + (noab
     &+nvab) * (h3b_2 - 1)))),p5b_2,p1b_2,p8b_2,h3b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+p1b-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_y_tr1_6_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_y_tr1_6_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_6_1',8,M
     &A_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_y_tr1_6_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+p8b-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 * (p8b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_6_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_6_1',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_6_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p8 p1 )_vx
      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 p8b
      INTEGER p1b
      length = 0
      DO p8b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+p8b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p8b-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_y_tr1_6_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO p8b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+p8b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p8b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p1b - noab - 1 + nvab * (p8b - noab - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+p8b-1) * int_mb(k_range+p1b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_6_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p8 p1 )_vxt + = -1 * Sum ( h4 ) * t ( p8 h4 )_t * i2 ( h4 p1 )_vx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p8b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER p8b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p8b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p8b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+p8b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,ieor(irrep_x,irrep_t))) THEN
      dimc = int_mb(k_range+p8b-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_y_tr1_6_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_2(h4b,p1b,h4b_2,p1b_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+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_y_tr1_6_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_6_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_y_tr1_6_2',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_6_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_6_2',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_y_tr1_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_y_tr1_6_2',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_6_2',8,M
     &A_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_y_tr1_6_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+p8b-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 * (p8b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_6_2',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_6_2',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_6_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_vx + = 1 * Sum ( h5 p6 ) * x ( p6 h5 )_x * v ( h4 h5 p1 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p6b
      INTEGER h5b
      INTEGER p6b_1
      INTEGER h5b_1
      INTEGER h4b_2
      INTEGER h5b_2
      INTEGER p1b_2
      INTEGER p6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x)) 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_y_tr1_6_2_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p6b = noab+1,noab+nvab
      DO h5b = 1,noab
      IF (int_mb(k_spin+p6b-1) .eq. int_mb(k_spin+h5b-1)) THEN
      IF (ieor(int_mb(k_sym+p6b-1),int_mb(k_sym+h5b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p6b,h5b,p6b_1,h5b_1)
      CALL TCE_RESTRICTED_4(h4b,h5b,p1b,p6b,h4b_2,h5b_2,p1b_2,p6b_2)
      dim_common = int_mb(k_range+p6b-1) * int_mb(k_range+h5b-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_y_tr1_6_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_6_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_1
     & - 1 + noab * (p6b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+h5b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_6_2_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_6_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_6_2_1',5,MA_ERR)
      IF ((h5b .lt. h4b) .and. (p6b .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) * (p6b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h5b_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) * (p6b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h5b_2 - 1)))),p1b_2,p6b_2,h4b_2,h5b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p6b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h5b .lt. h4b) .and. (p1b .le. p6b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h5b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p6b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h5b_2 - 1)))),p6b_2,p1b_2,h4b_2,h5b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p1b-1),int_mb(k_range+p6b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF ((h4b .le. h5b) .and. (p6b .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) * (p6b_2 - 1 + (noab+nvab) * (h5b_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) * (p6b_2 - 1 + (noab+nvab) * (h5b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p1b_2,p6b_2,h5b_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+h5b-1),int_mb(k_range+p6b-1),int_mb(k_range+p1b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h4b .le. h5b) .and. (p1b .le. p6b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h5b_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),
     &(p6b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h5b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p6b_2,p1b_2,h5b_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+h5b-1),int_mb(k_range+p1b-1),int_mb(k_range+p6b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_6_2_1',6,MA_E
     &RR)
      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_y_tr1_6_2_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_6_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_y_tr1_6_2_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_y_tr1_6_2_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_6_2_1',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_6_2_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_vx
      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_x)) 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_y_tr1_6_2_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_x)) 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_y_tr1_6_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p8 p1 )_vtx + = 1 * Sum ( h5 ) * x ( p8 h5 )_x * i2 ( h5 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p8b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h5b
      INTEGER p8b_1
      INTEGER h5b_1
      INTEGER h5b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p8b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p8b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+p8b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,ieor(irrep_t,irrep_x))) THEN
      dimc = int_mb(k_range+p8b-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_y_tr1_6_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h5b = 1,noab
      IF (int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h5b-1)) THEN
      IF (ieor(int_mb(k_sym+p8b-1),int_mb(k_sym+h5b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p8b,h5b,p8b_1,h5b_1)
      CALL TCE_RESTRICTED_2(h5b,p1b,h5b_2,p1b_2)
      dim_common = int_mb(k_range+h5b-1)
      dima_sort = int_mb(k_range+p8b-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_y_tr1_6_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_6_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_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+h5b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_6_3',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_6_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_6_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 * (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+p1b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_6_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_y_tr1_6_3',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_6_3',8,M
     &A_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_y_tr1_6_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+p8b-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 * (p8b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_6_3',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_6_3',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_6_3_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p1 )_vt + = 1 * Sum ( h4 p3 ) * t ( p3 h4 )_t * v ( h4 h5 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h5b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER h4b
      INTEGER p3b_1
      INTEGER h4b_1
      INTEGER h5b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h5b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      dimc = int_mb(k_range+h5b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_6_3_1',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(h5b,h4b,p1b,p3b,h5b_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+h5b-1) * int_mb(k_range+p1b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_6_3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_6_3_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_y_tr1_6_3_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_6_3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_6_3_1',5,MA_ERR)
      IF ((h4b .le. h5b) .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) * (h5b_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) * (h5b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p1b_2,p3b_2,h5b_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+h5b-1),int_mb(k_range+p3b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h4b .le. h5b) .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) * (h5b_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) * (h5b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p3b_2,p1b_2,h5b_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+h5b-1),int_mb(k_range+p1b-1),int_mb(k_range+p3b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF ((h5b .lt. h4b) .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) * (h4b_2 - 1 + (noab
     &+nvab) * (h5b_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) * (h4b_2 - 1 + (noab
     &+nvab) * (h5b_2 - 1)))),p1b_2,p3b_2,h4b_2,h5b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p3b-1),int_mb(k_range+p1b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h5b .lt. h4b) .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) * (h4b_2 - 1 + (noab
     &+nvab) * (h5b_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) * (h4b_2 - 1 + (noab
     &+nvab) * (h5b_2 - 1)))),p3b_2,p1b_2,h4b_2,h5b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p1b-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_y_tr1_6_3_1',6,MA_E
     &RR)
      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_y_tr1_6_3_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_6_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_y_tr1_6_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+h5b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (h5b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_6_3_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_6_3_1',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_6_3_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 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 h5b
      INTEGER p1b
      length = 0
      DO h5b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsd_y_tr1_6_3_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h5b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p1b - noab - 1 + nvab * (h5b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h5b-1) * int_mb(k_range+p1b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_fxy + = -1 * Sum ( p10 h9 ) * y ( h2 h9 p1 p10 )_y * i1 ( p10 h9 )_fx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h9b
      INTEGER p10b
      INTEGER h2b_1
      INTEGER h9b_1
      INTEGER p1b_1
      INTEGER p10b_1
      INTEGER p10b_2
      INTEGER h9b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_
     &f,ieor(irrep_x,irrep_y))) 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_y_tr1_7',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h9b = 1,noab
      DO p10b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h9b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+p10b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h9b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+p10b-1)))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_4(h2b,h9b,p1b,p10b,h2b_1,h9b_1,p1b_1,p10b_1)
      CALL TCE_RESTRICTED_2(p10b,h9b,p10b_2,h9b_2)
      dim_common = int_mb(k_range+h9b-1) * int_mb(k_range+p10b-1)
      dima_sort = int_mb(k_range+h2b-1) * int_mb(k_range+p1b-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_y_tr1_7',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7',2,MA_ERR)
      IF ((h9b .lt. h2b) .and. (p10b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p1b_1
     & - noab - 1 + nvab * (p10b_1 - noab - 1 + nvab * (h2b_1 - 1 + noab
     & * (h9b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p10b-1),int_mb(k_range+p1b-1
     &),4,2,3,1,1.0d0)
      END IF
      IF ((h9b .lt. h2b) .and. (p1b .le. p10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p10b_
     &1 - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab * (h2b_1 - 1 + noab
     & * (h9b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p1b-1),int_mb(k_range+p10b-1
     &),3,2,4,1,-1.0d0)
      END IF
      IF ((h2b .le. h9b) .and. (p10b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p1b_1
     & - noab - 1 + nvab * (p10b_1 - noab - 1 + nvab * (h9b_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+h9b-1),int_mb(k_range+p10b-1),int_mb(k_range+p1b-1
     &),4,1,3,2,-1.0d0)
      END IF
      IF ((h2b .le. h9b) .and. (p1b .le. p10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p10b_
     &1 - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab * (h9b_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+h9b-1),int_mb(k_range+p1b-1),int_mb(k_range+p10b-1
     &),3,1,4,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h9b_2
     & - 1 + noab * (p10b_2 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+p10b-1
     &),int_mb(k_range+h9b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_7',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_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_y_tr1_7',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7',11,MA
     &_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p10 h9 )_fx + = 1 * Sum ( h8 ) * x ( p10 h8 )_x * i2 ( h8 h9 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p10b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h8b
      INTEGER p10b_1
      INTEGER h8b_1
      INTEGER h8b_2
      INTEGER h9b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p10b = noab+1,noab+nvab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-1)+int_mb(k_spin+h9b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep
     &_f,irrep_x)) THEN
      dimc = int_mb(k_range+p10b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h8b = 1,noab
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+h8b-1)) .eq. irrep_x) T
     &HEN
      CALL TCE_RESTRICTED_2(p10b,h8b,p10b_1,h8b_1)
      CALL TCE_RESTRICTED_2(h8b,h9b,h8b_2,h9b_2)
      dim_common = int_mb(k_range+h8b-1)
      dima_sort = int_mb(k_range+p10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h9b-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_y_tr1_7_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p10b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p10b-1
     &),int_mb(k_range+h8b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_1',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h9b_2
     & - 1 + noab * (h8b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h9b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_7_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_y_tr1_7_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_1',8,M
     &A_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_y_tr1_7_1',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h9b-1)
     &,int_mb(k_range+p10b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (p10b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_1',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_7_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p10 h9 )_fx
      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 p10b
      INTEGER h9b
      length = 0
      DO p10b = noab+1,noab+nvab
      DO h9b = 1,noab
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep
     &_f,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-1)+int_mb(k_spin+h9b-
     &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_y_tr1_7_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO p10b = noab+1,noab+nvab
      DO h9b = 1,noab
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep
     &_f,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-1)+int_mb(k_spin+h9b-
     &1).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h9b - 1 + noab * (p10b - noab - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+p10b-1) * int_mb(k_range+h9b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_1_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h8 h9 )_f + = 1 * f ( h8 h9 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h8b
      INTEGER h9b
      INTEGER dimc
      INTEGER h8b_1
      INTEGER h9b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h8b = 1,noab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h8b-1)+int_mb(k_spin+h9b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),int_mb(k_sym+h9b-1)) .eq. irrep_f) TH
     &EN
      dimc = int_mb(k_range+h8b-1) * int_mb(k_range+h9b-1)
      CALL TCE_RESTRICTED_2(h8b,h9b,h8b_1,h9b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h8b-1) * int_mb(k_range+h9b-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_y_tr1_7_1_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_1_1',1,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_1
     & - 1 + (noab+nvab) * (h8b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h9b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_1_1',2,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_y_tr1_7_1_1',3,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (h8b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_1_1',4,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_1_1',5
     &,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_7_1_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h8 h9 )_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 h8b
      INTEGER h9b
      length = 0
      DO h8b = 1,noab
      DO h9b = 1,noab
      IF (int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),int_mb(k_sym+h9b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h8b-1)+int_mb(k_spin+h9b-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_y_tr1_7_1_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h8b = 1,noab
      DO h9b = 1,noab
      IF (int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),int_mb(k_sym+h9b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h8b-1)+int_mb(k_spin+h9b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h9b - 1 + noab * (h8b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h8b-1) * int_mb(k_range+h9b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_1_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h8 h9 )_ft + = 1 * Sum ( p7 ) * t ( p7 h9 )_t * i3 ( h8 p7 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h8b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h9b_1
      INTEGER h8b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h8b = 1,noab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h8b-1)+int_mb(k_spin+h9b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep_
     &f,irrep_t)) THEN
      dimc = int_mb(k_range+h8b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_1_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+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h9b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p7b,h9b,p7b_1,h9b_1)
      CALL TCE_RESTRICTED_2(h8b,p7b,h8b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h9b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h8b-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_y_tr1_7_1_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_1_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_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+h9b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_1_2',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_1_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_1_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 * (h8b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+p7b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_7_1_2',6,MA_E
     &RR)
      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_y_tr1_7_1_2',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_1_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_y_tr1_7_1_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h9b-1),1,2,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (h8b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_1_2',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_1_2',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_1_2_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h8 p7 )_f + = 1 * f ( h8 p7 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h8b
      INTEGER p7b
      INTEGER dimc
      INTEGER h8b_1
      INTEGER p7b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h8b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h8b-1)+int_mb(k_spin+p7b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),int_mb(k_sym+p7b-1)) .eq. irrep_f) TH
     &EN
      dimc = int_mb(k_range+h8b-1) * int_mb(k_range+p7b-1)
      CALL TCE_RESTRICTED_2(h8b,p7b,h8b_1,p7b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h8b-1) * int_mb(k_range+p7b-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_y_tr1_7_1_2_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_1_2_1',1,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p7b_1
     & - 1 + (noab+nvab) * (h8b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+p7b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_1_2_1',2,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_y_tr1_7_1_2_1',3,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p7b -
     & noab - 1 + nvab * (h8b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_1_2_1',4,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_1_2_1'
     &,5,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_7_1_2_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h8 p7 )_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 h8b
      INTEGER p7b
      length = 0
      DO h8b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),int_mb(k_sym+p7b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h8b-1)+int_mb(k_spin+p7b-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_y_tr1_7_1_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h8b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),int_mb(k_sym+p7b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h8b-1)+int_mb(k_spin+p7b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p7b - noab - 1 + nvab * (h8b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h8b-1) * int_mb(k_range+p7b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_1_2_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_
     &c_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h8 p7 )_vt + = 1 * Sum ( h6 p5 ) * t ( p5 h6 )_t * v ( h6 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h8b
      INTEGER p7b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER h6b
      INTEGER p5b_1
      INTEGER h6b_1
      INTEGER h8b_2
      INTEGER h6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h8b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h8b-1)+int_mb(k_spin+p7b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),int_mb(k_sym+p7b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      dimc = int_mb(k_range+h8b-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_y_tr1_7_1_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(h8b,h6b,p7b,p5b,h8b_2,h6b_2,p7b_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+h8b-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_y_tr1_7_1_2_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_1_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_y_tr1_7_1_2_2',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_1_2_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_1_2_2',5,MA_ERR)
      IF ((h6b .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) * (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) * (p5b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p7b_2,p5b_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+p5b-1),int_mb(k_range+p7b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h6b .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) * (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) * (p7b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p5b_2,p7b_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+p7b-1),int_mb(k_range+p5b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF ((h8b .lt. h6b) .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) * (h6b_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) * (h6b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p7b_2,p5b_2,h6b_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+h6b-1),int_mb(k_range+p5b-1),int_mb(k_range+p7b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h8b .lt. h6b) .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) * (h6b_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) * (h6b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p5b_2,p7b_2,h6b_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+h6b-1),int_mb(k_range+p7b-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_y_tr1_7_1_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_y_tr1_7_1_2_2'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_1_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_y_tr1_7_1_2_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p7b -
     & noab - 1 + nvab * (h8b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_1_2_2',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_1_2_2'
     &,11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_1_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h8 h9 )_vt + = -1 * Sum ( h4 p3 ) * t ( p3 h4 )_t * v ( h4 h8 h9 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h8b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER h4b
      INTEGER p3b_1
      INTEGER h4b_1
      INTEGER h8b_2
      INTEGER h4b_2
      INTEGER h9b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h8b = 1,noab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h8b-1)+int_mb(k_spin+h9b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      dimc = int_mb(k_range+h8b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_1_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(h8b,h4b,h9b,p3b,h8b_2,h4b_2,h9b_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+h8b-1) * int_mb(k_range+h9b-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_y_tr1_7_1_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_1_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_y_tr1_7_1_3',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_1_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_1_3',5,MA_ERR)
      IF ((h4b .le. h8b) .and. (h9b .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) * (h9b_2 - 1 + (noab+nvab) * (h8b_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) * (h9b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p3b_2,h9b_2,h8b_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+h8b-1),int_mb(k_range+h9b-1),int_mb(k_range+p3b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF ((h8b .lt. h4b) .and. (h9b .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) * (h9b_2 - 1 + (noab+nvab) * (h4b_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),
     &(p3b_2
     & - 1 + (noab+nvab) * (h9b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p3b_2,h9b_2,h4b_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+h4b-1),int_mb(k_range+h9b-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_y_tr1_7_1_3',6,MA_E
     &RR)
      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_y_tr1_7_1_3',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_1_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_y_tr1_7_1_3',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h8b-1),2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (h8b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_1_3',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_1_3',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_1_4(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h8 h9 )_vt + = 1/2 * Sum ( h6 p3 p4 ) * t ( p3 p4 h6 h9 )_t * v ( h6 h8 p3 p4 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h8b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p4b
      INTEGER h6b
      INTEGER p3b_1
      INTEGER p4b_1
      INTEGER h9b_1
      INTEGER h6b_1
      INTEGER h8b_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 NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h8b = 1,noab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h8b-1)+int_mb(k_spin+h9b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      dimc = int_mb(k_range+h8b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_1_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
     &9b-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+h9b-1),int_mb(k_sym+h6b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p3b,p4b,h9b,h6b,p3b_1,p4b_1,h9b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h8b,h6b,p3b,p4b,h8b_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+h9b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h8b-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_y_tr1_7_1_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_1_4',2,MA_ERR)
      IF ((h6b .le. h9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_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+h9b-1)
     &,4,3,2,1,1.0d0)
      END IF
      IF ((h9b .lt. h6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h9b_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+h9b-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_y_tr1_7_1_4',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_1_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_1_4',5,MA_ERR)
      IF ((h6b .le. h8b)) 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) * (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),
     &(p4b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p4b_2,p3b_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+p3b-1),int_mb(k_range+p4b-1)
     &,2,1,4,3,1.0d0)
      END IF
      IF ((h8b .lt. 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) * (h8b_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) * (h8b_2 - 1)))),p4b_2,p3b_2,h6b_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+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_y_tr1_7_1_4',6,MA_E
     &RR)
      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_y_tr1_7_1_4',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_1_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_y_tr1_7_1_4',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h9b-1),1,2,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (h8b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_1_4',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_1_4',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p10 h9 )_fx + = -1 * Sum ( p5 ) * x ( p5 h9 )_x * i2 ( p10 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p10b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h9b_1
      INTEGER p10b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p10b = noab+1,noab+nvab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-1)+int_mb(k_spin+h9b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep
     &_f,irrep_x)) THEN
      dimc = int_mb(k_range+p10b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_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+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h9b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p5b,h9b,p5b_1,h9b_1)
      CALL TCE_RESTRICTED_2(p10b,p5b,p10b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1)
      dima_sort = int_mb(k_range+h9b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p10b-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_y_tr1_7_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_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+h9b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_2',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_2',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p10b_2 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+p10b-1
     &),int_mb(k_range+p5b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_7_2',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_2',8,M
     &A_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_y_tr1_7_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p10b-1
     &),int_mb(k_range+h9b-1),1,2,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (p10b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_2',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_2',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_2_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p10 p5 )_f + = 1 * f ( p10 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p10b
      INTEGER p5b
      INTEGER dimc
      INTEGER p10b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p10b = noab+1,noab+nvab
      DO p5b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-1)+int_mb(k_spin+p5b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+p5b-1)) .eq. irrep_f) T
     &HEN
      dimc = int_mb(k_range+p10b-1) * int_mb(k_range+p5b-1)
      CALL TCE_RESTRICTED_2(p10b,p5b,p10b_1,p5b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+p10b-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_y_tr1_7_2_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_2_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) * (p10b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p10b-1
     &),int_mb(k_range+p5b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_2_1',2,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_y_tr1_7_2_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+p10b-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 * (p10b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_2_1',4,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_2_1',5
     &,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_7_2_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p10 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 p10b
      INTEGER p5b
      length = 0
      DO p10b = noab+1,noab+nvab
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+p5b-1)) .eq. irrep_f) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-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_y_tr1_7_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO p10b = noab+1,noab+nvab
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+p5b-1)) .eq. irrep_f) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-1)+int_mb(k_spin+p5b-
     &1).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p5b - noab - 1 + nvab * (p10b - noab - 1
     &)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+p10b-1) * int_mb(k_range+p5b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_2_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p10 p5 )_vt + = 1 * Sum ( h4 p3 ) * t ( p3 h4 )_t * v ( h4 p10 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p10b
      INTEGER p5b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER h4b
      INTEGER p3b_1
      INTEGER h4b_1
      INTEGER p10b_2
      INTEGER h4b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p10b = noab+1,noab+nvab
      DO p5b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-1)+int_mb(k_spin+p5b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+p5b-1)) .eq. ieor(irrep
     &_v,irrep_t)) THEN
      dimc = int_mb(k_range+p10b-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_y_tr1_7_2_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(p10b,h4b,p5b,p3b,p10b_2,h4b_2,p5b_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+p10b-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_y_tr1_7_2_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_2_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_y_tr1_7_2_2',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_2_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_2_2',5,MA_ERR)
      IF ((h4b .le. p10b) .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) * (p10b_2 - 1 + (noa
     &b+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) * (p3b_2 - 1 + (noab+nvab) * (p10b_2 - 1 + (noa
     &b+nvab) * (h4b_2 - 1)))),p5b_2,p3b_2,p10b_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+p10b-1),int_mb(k_range+p3b-1),int_mb(k_range+p5b-1
     &),4,2,1,3,1.0d0)
      END IF
      IF ((h4b .le. p10b) .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) * (p10b_2 - 1 + (noa
     &b+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) * (p5b_2 - 1 + (noab+nvab) * (p10b_2 - 1 + (noa
     &b+nvab) * (h4b_2 - 1)))),p3b_2,p5b_2,p10b_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+p10b-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_y_tr1_7_2_2',6,MA_E
     &RR)
      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_y_tr1_7_2_2',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_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_y_tr1_7_2_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+p10b-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 * (p10b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_2_2',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_2_2',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p10 h9 )_vx + = 1 * Sum ( h3 p6 ) * x ( p6 h3 )_x * v ( h3 p10 h9 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p10b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p6b
      INTEGER h3b
      INTEGER p6b_1
      INTEGER h3b_1
      INTEGER p10b_2
      INTEGER h3b_2
      INTEGER h9b_2
      INTEGER p6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p10b = noab+1,noab+nvab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-1)+int_mb(k_spin+h9b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep
     &_v,irrep_x)) THEN
      dimc = int_mb(k_range+p10b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p6b = noab+1,noab+nvab
      DO h3b = 1,noab
      IF (int_mb(k_spin+p6b-1) .eq. int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+p6b-1),int_mb(k_sym+h3b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p6b,h3b,p6b_1,h3b_1)
      CALL TCE_RESTRICTED_4(p10b,h3b,h9b,p6b,p10b_2,h3b_2,h9b_2,p6b_2)
      dim_common = int_mb(k_range+p6b-1) * int_mb(k_range+h3b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p10b-1) * int_mb(k_range+h9b-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_y_tr1_7_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h3b_1
     & - 1 + noab * (p6b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+h3b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_3',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_3',5,MA_ERR)
      IF ((h3b .le. p10b) .and. (h9b .le. p6b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - 1 + (noab+nvab) * (h9b_2 - 1 + (noab+nvab) * (p10b_2 - 1 + (noa
     &b+nvab) * (h3b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p6b_2
     & - 1 + (noab+nvab) * (h9b_2 - 1 + (noab+nvab) * (p10b_2 - 1 + (noa
     &b+nvab) * (h3b_2 - 1)))),p6b_2,h9b_2,p10b_2,h3b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+p10b-1),int_mb(k_range+h9b-1),int_mb(k_range+p6b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_7_3',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_3',8,M
     &A_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_y_tr1_7_3',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h9b-1)
     &,int_mb(k_range+p10b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (p10b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_3',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_3',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_4(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p10 h9 )_fx + = -1 * Sum ( h6 p7 ) * x ( p7 p10 h6 h9 )_x * i2 ( h6 p7 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p10b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER h6b
      INTEGER p10b_1
      INTEGER p7b_1
      INTEGER h9b_1
      INTEGER h6b_1
      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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p10b = noab+1,noab+nvab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-1)+int_mb(k_spin+h9b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep
     &_f,irrep_x)) THEN
      dimc = int_mb(k_range+p10b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_4',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      DO h6b = 1,noab
      IF (int_mb(k_spin+p10b-1)+int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+
     &h9b-1)+int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),ieor(int_mb(k_sym+p7b-1),ieor(int_mb
     &(k_sym+h9b-1),int_mb(k_sym+h6b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p10b,p7b,h9b,h6b,p10b_1,p7b_1,h9b_1,h6b_1)
      CALL TCE_RESTRICTED_2(h6b,p7b,h6b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1) * int_mb(k_range+h6b-1)
      dima_sort = int_mb(k_range+p10b-1) * int_mb(k_range+h9b-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_y_tr1_7_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_4',2,MA_ERR)
      IF ((p7b .le. p10b) .and. (h6b .le. h9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_1
     & - 1 + noab * (h6b_1 - 1 + noab * (p10b_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+p10b-1),int_mb(k_range+h6b-1),int_mb(k_range+h9b-1
     &),4,2,3,1,1.0d0)
      END IF
      IF ((p7b .le. p10b) .and. (h9b .lt. h6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h9b_1 - 1 + noab * (p10b_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+p10b-1),int_mb(k_range+h9b-1),int_mb(k_range+h6b-1
     &),3,2,4,1,-1.0d0)
      END IF
      IF ((p10b .lt. p7b) .and. (h6b .le. h9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_1
     & - 1 + noab * (h6b_1 - 1 + noab * (p7b_1 - noab - 1 + nvab * (p10b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p10b-1
     &),int_mb(k_range+p7b-1),int_mb(k_range+h6b-1),int_mb(k_range+h9b-1
     &),4,1,3,2,-1.0d0)
      END IF
      IF ((p10b .lt. p7b) .and. (h9b .lt. h6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h9b_1 - 1 + noab * (p7b_1 - noab - 1 + nvab * (p10b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p10b-1
     &),int_mb(k_range+p7b-1),int_mb(k_range+h9b-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_y_tr1_7_4',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_4',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)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+p7b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_7_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_y_tr1_7_4',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_4',8,M
     &A_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_y_tr1_7_4',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h9b-1)
     &,int_mb(k_range+p10b-1),2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (p10b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_4',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_4',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_4_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p7 )_f + = 1 * f ( h6 p7 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h6b
      INTEGER p7b
      INTEGER dimc
      INTEGER h6b_1
      INTEGER p7b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h6b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+p7b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+p7b-1)) .eq. irrep_f) TH
     &EN
      dimc = int_mb(k_range+h6b-1) * int_mb(k_range+p7b-1)
      CALL TCE_RESTRICTED_2(h6b,p7b,h6b_1,p7b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h6b-1) * int_mb(k_range+p7b-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_y_tr1_7_4_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_4_1',1,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p7b_1
     & - 1 + (noab+nvab) * (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+p7b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_4_1',2,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_y_tr1_7_4_1',3,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h6b-1),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)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_4_1',4,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_4_1',5
     &,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_7_4_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p7 )_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 h6b
      INTEGER p7b
      length = 0
      DO h6b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+p7b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+p7b-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_y_tr1_7_4_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h6b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+p7b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+p7b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p7b - noab - 1 + nvab * (h6b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h6b-1) * int_mb(k_range+p7b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_4_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p7 )_vt + = 1 * Sum ( h4 p3 ) * t ( p3 h4 )_t * v ( h4 h6 p3 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h6b
      INTEGER p7b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER h4b
      INTEGER p3b_1
      INTEGER h4b_1
      INTEGER h6b_2
      INTEGER h4b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h6b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+p7b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+p7b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      dimc = int_mb(k_range+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_y_tr1_7_4_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(h6b,h4b,p7b,p3b,h6b_2,h4b_2,p7b_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+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_y_tr1_7_4_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_4_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_y_tr1_7_4_2',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_4_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_4_2',5,MA_ERR)
      IF ((h4b .le. h6b) .and. (p3b .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) * (p3b_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),
     &(p7b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p7b_2,p3b_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+p3b-1),int_mb(k_range+p7b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h4b .le. h6b) .and. (p7b .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) * (p7b_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),
     &(p3b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p3b_2,p7b_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+p7b-1),int_mb(k_range+p3b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF ((h6b .lt. h4b) .and. (p3b .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) * (p3b_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),
     &(p7b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p7b_2,p3b_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+p3b-1),int_mb(k_range+p7b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h6b .lt. h4b) .and. (p7b .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) * (p7b_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),
     &(p3b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p3b_2,p7b_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+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_y_tr1_7_4_2',6,MA_E
     &RR)
      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_y_tr1_7_4_2',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_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_y_tr1_7_4_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h6b-1),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)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_4_2',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_4_2',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_5(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p10 h9 )_vx + = 1/2 * Sum ( h7 h5 p8 ) * x ( p8 p10 h5 h7 )_x * i2 ( h5 h7 h9 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p10b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p8b
      INTEGER h5b
      INTEGER h7b
      INTEGER p10b_1
      INTEGER p8b_1
      INTEGER h5b_1
      INTEGER h7b_1
      INTEGER h5b_2
      INTEGER h7b_2
      INTEGER h9b_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 nsubh(2)
      INTEGER isubh
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p10b = noab+1,noab+nvab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-1)+int_mb(k_spin+h9b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep
     &_v,irrep_x)) THEN
      dimc = int_mb(k_range+p10b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_5',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p8b = noab+1,noab+nvab
      DO h5b = 1,noab
      DO h7b = h5b,noab
      IF (int_mb(k_spin+p10b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+
     &h5b-1)+int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb
     &(k_sym+h5b-1),int_mb(k_sym+h7b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p10b,p8b,h5b,h7b,p10b_1,p8b_1,h5b_1,h7b_1)
      CALL TCE_RESTRICTED_4(h5b,h7b,h9b,p8b,h5b_2,h7b_2,h9b_2,p8b_2)
      dim_common = int_mb(k_range+p8b-1) * int_mb(k_range+h5b-1) * int_m
     &b(k_range+h7b-1)
      dima_sort = int_mb(k_range+p10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h9b-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_y_tr1_7_5',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_5',2,MA_ERR)
      IF ((p8b .le. p10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_1
     & - 1 + noab * (h5b_1 - 1 + noab * (p10b_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+p10b-1),int_mb(k_range+h5b-1),int_mb(k_range+h7b-1
     &),2,4,3,1,1.0d0)
      END IF
      IF ((p10b .lt. p8b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_1
     & - 1 + noab * (h5b_1 - 1 + noab * (p8b_1 - noab - 1 + nvab * (p10b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p10b-1
     &),int_mb(k_range+p8b-1),int_mb(k_range+h5b-1),int_mb(k_range+h7b-1
     &),1,4,3,2,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_5',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_5',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_5',5,MA_ERR)
      IF ((h9b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - noab - 1 + nvab * (h9b_2 - 1 + noab * (h7b_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+h7b-1),int_mb(k_range+h9b-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_y_tr1_7_5',6,MA_ERR
     &)
      nsubh(1) = 1
      nsubh(2) = 1
      isubh = 1
      IF (h5b .eq. h7b) 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_y_tr1_7_5',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_5',8,M
     &A_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_y_tr1_7_5',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h9b-1)
     &,int_mb(k_range+p10b-1),2,1,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (p10b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_5',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_5',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_5_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h7 h9 p8 )_v + = -1 * v ( h5 h7 h9 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_c
      INTEGER k_c_offset
      INTEGER NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h5b
      INTEGER h7b
      INTEGER h9b
      INTEGER p8b
      INTEGER dimc
      INTEGER h5b_1
      INTEGER h7b_1
      INTEGER h9b_1
      INTEGER p8b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h5b = 1,noab
      DO h7b = h5b,noab
      DO h9b = 1,noab
      DO p8b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h9b-1)+int_mb(k_spin+p8b-1).ne.8)) THEN
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &9b-1)+int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h9b-1),int_mb(k_sym+p8b-1)))) .eq. irrep_v) THEN
      dimc = int_mb(k_range+h5b-1) * int_mb(k_range+h7b-1) * int_mb(k_ra
     &nge+h9b-1) * int_mb(k_range+p8b-1)
      CALL TCE_RESTRICTED_4(h5b,h7b,h9b,p8b,h5b_1,h7b_1,h9b_1,p8b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h5b-1) * int_mb(k_range+h7b-1) * int_mb
     &(k_range+h9b-1) * int_mb(k_range+p8b-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_y_tr1_7_5_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_5_1',1,MA_ERR)
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p8b_1
     & - 1 + (noab+nvab) * (h9b_1 - 1 + (noab+nvab) * (h7b_1 - 1 + (noab
     &+nvab) * (h5b_1 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),
     &(p8b_1
     & - 1 + (noab+nvab) * (h9b_1 - 1 + (noab+nvab) * (h7b_1 - 1 + (noab
     &+nvab) * (h5b_1 - 1)))),p8b_1,h9b_1,h7b_1,h5b_1)
      end if
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+h9b-1),int_mb(k_range+p8b-1)
     &,4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_5_1',2,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_y_tr1_7_5_1',3,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+p8b-1)
     &,int_mb(k_range+h9b-1),int_mb(k_range+h7b-1),int_mb(k_range+h5b-1)
     &,4,3,2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p8b -
     & noab - 1 + nvab * (h9b - 1 + noab * (h7b - 1 + noab * (h5b - 1)))
     &))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_5_1',4,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_5_1',5
     &,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_7_5_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h7 h9 p8 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h5b
      INTEGER h7b
      INTEGER h9b
      INTEGER p8b
      length = 0
      DO h5b = 1,noab
      DO h7b = h5b,noab
      DO h9b = 1,noab
      DO p8b = noab+1,noab+nvab
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &9b-1)+int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h9b-1),int_mb(k_sym+p8b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h9b-1)+int_mb(k_spin+p8b-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_y_tr1_7_5_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h5b = 1,noab
      DO h7b = h5b,noab
      DO h9b = 1,noab
      DO p8b = noab+1,noab+nvab
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &9b-1)+int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h9b-1),int_mb(k_sym+p8b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h9b-1)+int_mb(k_spin+p8b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p8b - noab - 1 + nvab * (h9b - 1 + noab 
     &* (h7b - 1 + noab * (h5b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h5b-1) * int_mb(k_range+h7b-1) * int_
     &mb(k_range+h9b-1) * int_mb(k_range+p8b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_5_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h7 h9 p8 )_vt + = -1 * Sum ( p3 ) * t ( p3 h9 )_t * v ( h5 h7 p3 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h5b
      INTEGER h7b
      INTEGER h9b
      INTEGER p8b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h9b_1
      INTEGER h5b_2
      INTEGER h7b_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 l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h5b = 1,noab
      DO h7b = h5b,noab
      DO h9b = 1,noab
      DO p8b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h9b-1)+int_mb(k_spin+p8b-1).ne.8)) THEN
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &9b-1)+int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h9b-1),int_mb(k_sym+p8b-1)))) .eq. ieor(irrep_v,irrep_t)) TH
     &EN
      dimc = int_mb(k_range+h5b-1) * int_mb(k_range+h7b-1) * int_mb(k_ra
     &nge+h9b-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_y_tr1_7_5_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+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h9b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p3b,h9b,p3b_1,h9b_1)
      CALL TCE_RESTRICTED_4(h5b,h7b,p8b,p3b,h5b_2,h7b_2,p8b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h9b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h5b-1) * int_mb(k_range+h7b-1) * 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_y_tr1_7_5_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_5_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_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+h9b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_5_2',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_5_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_5_2',5,MA_ERR)
      IF ((p3b .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) * (p3b_2 - 1 + (noab+nvab) * (h7b_2 - 1 + (noab
     &+nvab) * (h5b_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) * (p3b_2 - 1 + (noab+nvab) * (h7b_2 - 1 + (noab
     &+nvab) * (h5b_2 - 1)))),p8b_2,p3b_2,h7b_2,h5b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h7b-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
      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) * (p8b_2 - 1 + (noab+nvab) * (h7b_2 - 1 + (noab
     &+nvab) * (h5b_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) * (p8b_2 - 1 + (noab+nvab) * (h7b_2 - 1 + (noab
     &+nvab) * (h5b_2 - 1)))),p3b_2,p8b_2,h7b_2,h5b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h7b-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_y_tr1_7_5_2',6,MA_E
     &RR)
      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_y_tr1_7_5_2',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_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_y_tr1_7_5_2',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p8b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+h5b-1),int_mb(k_range+h9b-1)
     &,3,2,4,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p8b -
     & noab - 1 + nvab * (h9b - 1 + noab * (h7b - 1 + noab * (h5b - 1)))
     &))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_5_2',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_5_2',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_6(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p10 h9 )_vx + = -1/2 * Sum ( h3 p5 p6 ) * x ( p5 p6 h3 h9 )_x * v ( h3 p10 p5 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p10b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p6b
      INTEGER h3b
      INTEGER p5b_1
      INTEGER p6b_1
      INTEGER h9b_1
      INTEGER h3b_1
      INTEGER p10b_2
      INTEGER h3b_2
      INTEGER p5b_2
      INTEGER p6b_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 NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p10b = noab+1,noab+nvab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-1)+int_mb(k_spin+h9b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep
     &_v,irrep_x)) THEN
      dimc = int_mb(k_range+p10b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_6',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      DO p6b = p5b,noab+nvab
      DO h3b = 1,noab
      IF (int_mb(k_spin+p5b-1)+int_mb(k_spin+p6b-1) .eq. int_mb(k_spin+h
     &9b-1)+int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),ieor(int_mb(k_sym+p6b-1),ieor(int_mb(
     &k_sym+h9b-1),int_mb(k_sym+h3b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p5b,p6b,h9b,h3b,p5b_1,p6b_1,h9b_1,h3b_1)
      CALL TCE_RESTRICTED_4(p10b,h3b,p5b,p6b,p10b_2,h3b_2,p5b_2,p6b_2)
      dim_common = int_mb(k_range+p5b-1) * int_mb(k_range+p6b-1) * int_m
     &b(k_range+h3b-1)
      dima_sort = int_mb(k_range+h9b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p10b-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_y_tr1_7_6',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_6',2,MA_ERR)
      IF ((h3b .le. h9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_1
     & - 1 + noab * (h3b_1 - 1 + noab * (p6b_1 - noab - 1 + nvab * (p5b_
     &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+p6b-1),int_mb(k_range+h3b-1),int_mb(k_range+h9b-1)
     &,4,3,2,1,1.0d0)
      END IF
      IF ((h9b .lt. h3b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h3b_1
     & - 1 + noab * (h9b_1 - 1 + noab * (p6b_1 - noab - 1 + nvab * (p5b_
     &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+p6b-1),int_mb(k_range+h9b-1),int_mb(k_range+h3b-1)
     &,3,4,2,1,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_6',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_6',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_6',5,MA_ERR)
      IF ((h3b .le. p10b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (p10b_2 - 1 + (noa
     &b+nvab) * (h3b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p6b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (p10b_2 - 1 + (noa
     &b+nvab) * (h3b_2 - 1)))),p6b_2,p5b_2,p10b_2,h3b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+p10b-1),int_mb(k_range+p5b-1),int_mb(k_range+p6b-1
     &),2,1,4,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_7_6',6,MA_ERR
     &)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p5b .eq. p6b) 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_y_tr1_7_6',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_6',8,M
     &A_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_y_tr1_7_6',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p10b-1
     &),int_mb(k_range+h9b-1),1,2,-1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (p10b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_6',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_6',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_7(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p10 h9 )_fxt + = 1 * Sum ( h12 ) * t ( p10 h12 )_t * i2 ( h12 h9 )_fx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p10b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h12b
      INTEGER p10b_1
      INTEGER h12b_1
      INTEGER h12b_2
      INTEGER h9b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p10b = noab+1,noab+nvab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-1)+int_mb(k_spin+h9b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep
     &_f,ieor(irrep_x,irrep_t))) THEN
      dimc = int_mb(k_range+p10b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_7',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h12b = 1,noab
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+h12b-1)) .eq. irrep_t) 
     &THEN
      CALL TCE_RESTRICTED_2(p10b,h12b,p10b_1,h12b_1)
      CALL TCE_RESTRICTED_2(h12b,h9b,h12b_2,h9b_2)
      dim_common = int_mb(k_range+h12b-1)
      dima_sort = int_mb(k_range+p10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h9b-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_y_tr1_7_7',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_7',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (p10b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p10b-1
     &),int_mb(k_range+h12b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_7',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_7',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_7',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h9b_2
     & - 1 + noab * (h12b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h12b-1
     &),int_mb(k_range+h9b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_7_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_y_tr1_7_7',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_7',8,M
     &A_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_y_tr1_7_7',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h9b-1)
     &,int_mb(k_range+p10b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (p10b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_7',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_7',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_7_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h12 h9 )_fx + = 1 * Sum ( p3 ) * x ( p3 h9 )_x * i3 ( h12 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h12b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h9b_1
      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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h12b = 1,noab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h12b-1)+int_mb(k_spin+h9b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h12b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h12b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep
     &_f,irrep_x)) THEN
      dimc = int_mb(k_range+h12b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_7_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+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h9b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p3b,h9b,p3b_1,h9b_1)
      CALL TCE_RESTRICTED_2(h12b,p3b,h12b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h9b-1)
      dima = dim_common * dima_sort
      dimb_sort = 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_y_tr1_7_7_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_7_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_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+h9b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_7_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_7_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_7_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 * (h12b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h12b-1
     &),int_mb(k_range+p3b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_7_7_1',6,MA_E
     &RR)
      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_y_tr1_7_7_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_7_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_y_tr1_7_7_1',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+h9b-1),1,2,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (h12b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_7_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_7_1',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_7_7_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h12 h9 )_fx
      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 h12b
      INTEGER h9b
      length = 0
      DO h12b = 1,noab
      DO h9b = 1,noab
      IF (int_mb(k_spin+h12b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h12b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep
     &_f,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h12b-1)+int_mb(k_spin+h9b-
     &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_y_tr1_7_7_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h12b = 1,noab
      DO h9b = 1,noab
      IF (int_mb(k_spin+h12b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h12b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep
     &_f,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h12b-1)+int_mb(k_spin+h9b-
     &1).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h9b - 1 + noab * (h12b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h12b-1) * int_mb(k_range+h9b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_7_1_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h12 p3 )_f + = 1 * f ( h12 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h12b
      INTEGER p3b
      INTEGER dimc
      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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h12b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h12b-1)+int_mb(k_spin+p3b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h12b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h12b-1),int_mb(k_sym+p3b-1)) .eq. irrep_f) T
     &HEN
      dimc = int_mb(k_range+h12b-1) * int_mb(k_range+p3b-1)
      CALL TCE_RESTRICTED_2(h12b,p3b,h12b_1,p3b_1)
      dim_common = 1
      dima_sort = 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_y_tr1_7_7_1_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_7_1_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) * (h12b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h12b-1
     &),int_mb(k_range+p3b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_7_1_1',2,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_y_tr1_7_7_1_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+h12b-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 * (h12b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_7_1_1',4,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_7_1_1'
     &,5,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_7_7_1_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h12 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 h12b
      INTEGER p3b
      length = 0
      DO h12b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h12b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h12b-1),int_mb(k_sym+p3b-1)) .eq. irrep_f) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h12b-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_y_tr1_7_7_1_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h12b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h12b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h12b-1),int_mb(k_sym+p3b-1)) .eq. irrep_f) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h12b-1)+int_mb(k_spin+p3b-
     &1).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p3b - noab - 1 + nvab * (h12b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h12b-1) * int_mb(k_range+p3b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_7_1_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_
     &c_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h12 p3 )_vt + = -1 * Sum ( h6 p5 ) * t ( p5 h6 )_t * v ( h6 h12 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h12b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER h6b
      INTEGER p5b_1
      INTEGER h6b_1
      INTEGER h12b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h12b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h12b-1)+int_mb(k_spin+p3b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h12b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h12b-1),int_mb(k_sym+p3b-1)) .eq. ieor(irrep
     &_v,irrep_t)) THEN
      dimc = int_mb(k_range+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_y_tr1_7_7_1_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(h12b,h6b,p3b,p5b,h12b_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+h12b-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_y_tr1_7_7_1_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_7_1_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_y_tr1_7_7_1_2',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_7_1_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_7_1_2',5,MA_ERR)
      IF ((h6b .le. h12b) .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) * (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),
     &(p3b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h12b_2 - 1 + (noa
     &b+nvab) * (h6b_2 - 1)))),p3b_2,p5b_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+p5b-1),int_mb(k_range+p3b-1
     &),4,2,1,3,-1.0d0)
      END IF
      IF ((h6b .le. h12b) .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) * (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),
     &(p5b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h12b_2 - 1 + (noa
     &b+nvab) * (h6b_2 - 1)))),p5b_2,p3b_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+p3b-1),int_mb(k_range+p5b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF ((h12b .lt. 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) * (h12b_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) * (h12b_2 - 1)))),p3b_2,p5b_2,h6b_2,h12b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h12b-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 ((h12b .lt. 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) * (h12b_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) * (h12b_2 - 1)))),p5b_2,p3b_2,h6b_2,h12b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h12b-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_y_tr1_7_7_1_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_y_tr1_7_7_1_2'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_7_1_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_y_tr1_7_7_1_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+h12b-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 * (h12b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_7_1_2',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_7_1_2'
     &,11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_7_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h12 h9 )_vx + = -1 * Sum ( h5 p7 ) * x ( p7 h5 )_x * v ( h5 h12 h9 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h12b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER h5b
      INTEGER p7b_1
      INTEGER h5b_1
      INTEGER h12b_2
      INTEGER h5b_2
      INTEGER h9b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h12b = 1,noab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h12b-1)+int_mb(k_spin+h9b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h12b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h12b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep
     &_v,irrep_x)) THEN
      dimc = int_mb(k_range+h12b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_7_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      DO h5b = 1,noab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h5b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h5b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p7b,h5b,p7b_1,h5b_1)
      CALL TCE_RESTRICTED_4(h12b,h5b,h9b,p7b,h12b_2,h5b_2,h9b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1) * int_mb(k_range+h5b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h12b-1) * int_mb(k_range+h9b-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_y_tr1_7_7_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_7_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_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+h5b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_7_2',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_7_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_7_2',5,MA_ERR)
      IF ((h5b .le. h12b) .and. (h9b .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) * (h9b_2 - 1 + (noab+nvab) * (h12b_2 - 1 + (noa
     &b+nvab) * (h5b_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) * (h9b_2 - 1 + (noab+nvab) * (h12b_2 - 1 + (noa
     &b+nvab) * (h5b_2 - 1)))),p7b_2,h9b_2,h12b_2,h5b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h12b-1),int_mb(k_range+h9b-1),int_mb(k_range+p7b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF ((h12b .lt. h5b) .and. (h9b .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) * (h9b_2 - 1 + (noab+nvab) * (h5b_2 - 1 + (noab
     &+nvab) * (h12b_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) * (h9b_2 - 1 + (noab+nvab) * (h5b_2 - 1 + (noab
     &+nvab) * (h12b_2 - 1)))),p7b_2,h9b_2,h5b_2,h12b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h12b-1
     &),int_mb(k_range+h5b-1),int_mb(k_range+h9b-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_y_tr1_7_7_2',6,MA_E
     &RR)
      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_y_tr1_7_7_2',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_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_y_tr1_7_7_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h12b-1),2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (h12b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_7_2',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_7_2',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_7_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h12 h9 )_vx + = 1/2 * Sum ( h5 p6 p7 ) * x ( p6 p7 h5 h9 )_x * v ( h5 h12 p6 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h12b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p6b
      INTEGER p7b
      INTEGER h5b
      INTEGER p6b_1
      INTEGER p7b_1
      INTEGER h9b_1
      INTEGER h5b_1
      INTEGER h12b_2
      INTEGER h5b_2
      INTEGER p6b_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 nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h12b = 1,noab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h12b-1)+int_mb(k_spin+h9b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h12b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h12b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep
     &_v,irrep_x)) THEN
      dimc = int_mb(k_range+h12b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_7_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p6b = noab+1,noab+nvab
      DO p7b = p6b,noab+nvab
      DO h5b = 1,noab
      IF (int_mb(k_spin+p6b-1)+int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h
     &9b-1)+int_mb(k_spin+h5b-1)) THEN
      IF (ieor(int_mb(k_sym+p6b-1),ieor(int_mb(k_sym+p7b-1),ieor(int_mb(
     &k_sym+h9b-1),int_mb(k_sym+h5b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p6b,p7b,h9b,h5b,p6b_1,p7b_1,h9b_1,h5b_1)
      CALL TCE_RESTRICTED_4(h12b,h5b,p6b,p7b,h12b_2,h5b_2,p6b_2,p7b_2)
      dim_common = int_mb(k_range+p6b-1) * int_mb(k_range+p7b-1) * int_m
     &b(k_range+h5b-1)
      dima_sort = int_mb(k_range+h9b-1)
      dima = dim_common * dima_sort
      dimb_sort = 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_y_tr1_7_7_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_7_3',2,MA_ERR)
      IF ((h5b .le. h9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_1
     & - 1 + noab * (h5b_1 - 1 + noab * (p7b_1 - noab - 1 + nvab * (p6b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+h5b-1),int_mb(k_range+h9b-1)
     &,4,3,2,1,1.0d0)
      END IF
      IF ((h9b .lt. h5b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_1
     & - 1 + noab * (h9b_1 - 1 + noab * (p7b_1 - noab - 1 + nvab * (p6b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+h9b-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_y_tr1_7_7_3',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_7_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_7_3',5,MA_ERR)
      IF ((h5b .le. h12b)) 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) * (p6b_2 - 1 + (noab+nvab) * (h12b_2 - 1 + (noa
     &b+nvab) * (h5b_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) * (p6b_2 - 1 + (noab+nvab) * (h12b_2 - 1 + (noa
     &b+nvab) * (h5b_2 - 1)))),p7b_2,p6b_2,h12b_2,h5b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h12b-1),int_mb(k_range+p6b-1),int_mb(k_range+p7b-1
     &),2,1,4,3,1.0d0)
      END IF
      IF ((h12b .lt. h5b)) 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) * (p6b_2 - 1 + (noab+nvab) * (h5b_2 - 1 + (noab
     &+nvab) * (h12b_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) * (p6b_2 - 1 + (noab+nvab) * (h5b_2 - 1 + (noab
     &+nvab) * (h12b_2 - 1)))),p7b_2,p6b_2,h5b_2,h12b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h12b-1
     &),int_mb(k_range+h5b-1),int_mb(k_range+p6b-1),int_mb(k_range+p7b-1
     &),1,2,4,3,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_7_7_3',6,MA_E
     &RR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p6b .eq. p7b) 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_y_tr1_7_7_3',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_7_3',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_y_tr1_7_7_3',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+h9b-1),1,2,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (h12b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_7_3',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_7_3',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_7_4(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h12 h9 )_vxt + = 1 * Sum ( p3 ) * t ( p3 h9 )_t * i3 ( h12 p3 )_vx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h12b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h9b_1
      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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h12b = 1,noab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h12b-1)+int_mb(k_spin+h9b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h12b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h12b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep
     &_v,ieor(irrep_x,irrep_t))) THEN
      dimc = int_mb(k_range+h12b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_7_4',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+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h9b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p3b,h9b,p3b_1,h9b_1)
      CALL TCE_RESTRICTED_2(h12b,p3b,h12b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h9b-1)
      dima = dim_common * dima_sort
      dimb_sort = 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_y_tr1_7_7_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_7_4',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_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+h9b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_7_4',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_7_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_7_4',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h12b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h12b-1
     &),int_mb(k_range+p3b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_7_7_4',6,MA_E
     &RR)
      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_y_tr1_7_7_4',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_7_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_y_tr1_7_7_4',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+h9b-1),1,2,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (h12b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_7_4',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_7_4',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_7_4_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_
     &c_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h12 p3 )_vx + = -1 * Sum ( h7 p8 ) * x ( p8 h7 )_x * v ( h7 h12 p3 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h12b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p8b
      INTEGER h7b
      INTEGER p8b_1
      INTEGER h7b_1
      INTEGER h12b_2
      INTEGER h7b_2
      INTEGER p3b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h12b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h12b-1)+int_mb(k_spin+p3b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h12b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h12b-1),int_mb(k_sym+p3b-1)) .eq. ieor(irrep
     &_v,irrep_x)) THEN
      dimc = int_mb(k_range+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_y_tr1_7_7_4_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p8b = noab+1,noab+nvab
      DO h7b = 1,noab
      IF (int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+p8b-1),int_mb(k_sym+h7b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p8b,h7b,p8b_1,h7b_1)
      CALL TCE_RESTRICTED_4(h12b,h7b,p3b,p8b,h12b_2,h7b_2,p3b_2,p8b_2)
      dim_common = int_mb(k_range+p8b-1) * int_mb(k_range+h7b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h12b-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_y_tr1_7_7_4_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_7_4_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_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+h7b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_7_4_1',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_7_4_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_7_4_1',5,MA_ERR)
      IF ((h7b .le. h12b) .and. (p8b .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) * (p8b_2 - 1 + (noab+nvab) * (h12b_2 - 1 + (noa
     &b+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) * (p8b_2 - 1 + (noab+nvab) * (h12b_2 - 1 + (noa
     &b+nvab) * (h7b_2 - 1)))),p3b_2,p8b_2,h12b_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+h12b-1),int_mb(k_range+p8b-1),int_mb(k_range+p3b-1
     &),4,2,1,3,-1.0d0)
      END IF
      IF ((h7b .le. h12b) .and. (p3b .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) * (p3b_2 - 1 + (noab+nvab) * (h12b_2 - 1 + (noa
     &b+nvab) * (h7b_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) * (p3b_2 - 1 + (noab+nvab) * (h12b_2 - 1 + (noa
     &b+nvab) * (h7b_2 - 1)))),p8b_2,p3b_2,h12b_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+h12b-1),int_mb(k_range+p3b-1),int_mb(k_range+p8b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF ((h12b .lt. h7b) .and. (p8b .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) * (p8b_2 - 1 + (noab+nvab) * (h7b_2 - 1 + (noab
     &+nvab) * (h12b_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) * (p8b_2 - 1 + (noab+nvab) * (h7b_2 - 1 + (noab
     &+nvab) * (h12b_2 - 1)))),p3b_2,p8b_2,h7b_2,h12b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h12b-1
     &),int_mb(k_range+h7b-1),int_mb(k_range+p8b-1),int_mb(k_range+p3b-1
     &),4,1,2,3,1.0d0)
      END IF
      IF ((h12b .lt. h7b) .and. (p3b .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) * (p3b_2 - 1 + (noab+nvab) * (h7b_2 - 1 + (noab
     &+nvab) * (h12b_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) * (p3b_2 - 1 + (noab+nvab) * (h7b_2 - 1 + (noab
     &+nvab) * (h12b_2 - 1)))),p8b_2,p3b_2,h7b_2,h12b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h12b-1
     &),int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_mb(k_range+p8b-1
     &),3,1,2,4,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_7_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_y_tr1_7_7_4_1'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_7_4_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_y_tr1_7_7_4_1',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+h12b-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 * (h12b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_7_4_1',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_7_4_1'
     &,11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_7_7_4_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h12 p3 )_vx
      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 h12b
      INTEGER p3b
      length = 0
      DO h12b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h12b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h12b-1),int_mb(k_sym+p3b-1)) .eq. ieor(irrep
     &_v,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h12b-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_y_tr1_7_7_4_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h12b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h12b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h12b-1),int_mb(k_sym+p3b-1)) .eq. ieor(irrep
     &_v,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h12b-1)+int_mb(k_spin+p3b-
     &1).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p3b - noab - 1 + nvab * (h12b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h12b-1) * int_mb(k_range+p3b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_8(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p10 h9 )_vxt + = -1 * Sum ( p3 ) * t ( p3 h9 )_t * i2 ( p10 p3 )_vx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p10b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h9b_1
      INTEGER p10b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p10b = noab+1,noab+nvab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-1)+int_mb(k_spin+h9b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep
     &_v,ieor(irrep_x,irrep_t))) THEN
      dimc = int_mb(k_range+p10b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_8',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+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h9b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p3b,h9b,p3b_1,h9b_1)
      CALL TCE_RESTRICTED_2(p10b,p3b,p10b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h9b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p10b-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_y_tr1_7_8',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_8',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_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+h9b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_8',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_8',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_8',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (p10b_2 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+p10b-1
     &),int_mb(k_range+p3b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_7_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_y_tr1_7_8',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_8',8,M
     &A_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_y_tr1_7_8',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p10b-1
     &),int_mb(k_range+h9b-1),1,2,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (p10b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_8',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_8',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_8_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p10 p3 )_vx + = -1 * Sum ( h5 p7 ) * x ( p7 h5 )_x * v ( h5 p10 p3 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p10b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER h5b
      INTEGER p7b_1
      INTEGER h5b_1
      INTEGER p10b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p10b = noab+1,noab+nvab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-1)+int_mb(k_spin+p3b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+p3b-1)) .eq. ieor(irrep
     &_v,irrep_x)) THEN
      dimc = int_mb(k_range+p10b-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_y_tr1_7_8_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      DO h5b = 1,noab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h5b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h5b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p7b,h5b,p7b_1,h5b_1)
      CALL TCE_RESTRICTED_4(p10b,h5b,p3b,p7b,p10b_2,h5b_2,p3b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1) * int_mb(k_range+h5b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p10b-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_y_tr1_7_8_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_8_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_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+h5b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_8_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_8_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_8_1',5,MA_ERR)
      IF ((h5b .le. p10b) .and. (p7b .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) * (p7b_2 - 1 + (noab+nvab) * (p10b_2 - 1 + (noa
     &b+nvab) * (h5b_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) * (p7b_2 - 1 + (noab+nvab) * (p10b_2 - 1 + (noa
     &b+nvab) * (h5b_2 - 1)))),p3b_2,p7b_2,p10b_2,h5b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+p10b-1),int_mb(k_range+p7b-1),int_mb(k_range+p3b-1
     &),4,2,1,3,-1.0d0)
      END IF
      IF ((h5b .le. p10b) .and. (p3b .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) * (p3b_2 - 1 + (noab+nvab) * (p10b_2 - 1 + (noa
     &b+nvab) * (h5b_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) * (p3b_2 - 1 + (noab+nvab) * (p10b_2 - 1 + (noa
     &b+nvab) * (h5b_2 - 1)))),p7b_2,p3b_2,p10b_2,h5b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+p10b-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_y_tr1_7_8_1',6,MA_E
     &RR)
      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_y_tr1_7_8_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_8_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_y_tr1_7_8_1',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+p10b-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 * (p10b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_8_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_8_1',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_7_8_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p10 p3 )_vx
      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 p10b
      INTEGER p3b
      length = 0
      DO p10b = noab+1,noab+nvab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+p3b-1)) .eq. ieor(irrep
     &_v,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-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_y_tr1_7_8_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO p10b = noab+1,noab+nvab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+p3b-1)) .eq. ieor(irrep
     &_v,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-1)+int_mb(k_spin+p3b-
     &1).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p3b - noab - 1 + nvab * (p10b - noab - 1
     &)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+p10b-1) * int_mb(k_range+p3b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_9(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p10 h9 )_vxt + = -1 * Sum ( h6 p4 ) * t ( p4 p10 h6 h9 )_t * i2 ( h6 p4 )_vx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p10b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p4b
      INTEGER h6b
      INTEGER p10b_1
      INTEGER p4b_1
      INTEGER h9b_1
      INTEGER h6b_1
      INTEGER h6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p10b = noab+1,noab+nvab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-1)+int_mb(k_spin+h9b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep
     &_v,ieor(irrep_x,irrep_t))) THEN
      dimc = int_mb(k_range+p10b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_9',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+p10b-1)+int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+
     &h9b-1)+int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),ieor(int_mb(k_sym+p4b-1),ieor(int_mb
     &(k_sym+h9b-1),int_mb(k_sym+h6b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p10b,p4b,h9b,h6b,p10b_1,p4b_1,h9b_1,h6b_1)
      CALL TCE_RESTRICTED_2(h6b,p4b,h6b_2,p4b_2)
      dim_common = int_mb(k_range+p4b-1) * int_mb(k_range+h6b-1)
      dima_sort = int_mb(k_range+p10b-1) * int_mb(k_range+h9b-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_y_tr1_7_9',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_9',2,MA_ERR)
      IF ((p4b .le. p10b) .and. (h6b .le. h9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_1
     & - 1 + noab * (h6b_1 - 1 + noab * (p10b_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+p10b-1),int_mb(k_range+h6b-1),int_mb(k_range+h9b-1
     &),4,2,3,1,1.0d0)
      END IF
      IF ((p4b .le. p10b) .and. (h9b .lt. h6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h9b_1 - 1 + noab * (p10b_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+p10b-1),int_mb(k_range+h9b-1),int_mb(k_range+h6b-1
     &),3,2,4,1,-1.0d0)
      END IF
      IF ((p10b .lt. p4b) .and. (h6b .le. h9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_1
     & - 1 + noab * (h6b_1 - 1 + noab * (p4b_1 - noab - 1 + nvab * (p10b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p10b-1
     &),int_mb(k_range+p4b-1),int_mb(k_range+h6b-1),int_mb(k_range+h9b-1
     &),4,1,3,2,-1.0d0)
      END IF
      IF ((p10b .lt. p4b) .and. (h9b .lt. h6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h9b_1 - 1 + noab * (p4b_1 - noab - 1 + nvab * (p10b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p10b-1
     &),int_mb(k_range+p4b-1),int_mb(k_range+h9b-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_y_tr1_7_9',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_9',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_9',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p4b_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+p4b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_7_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_y_tr1_7_9',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_9',8,M
     &A_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_y_tr1_7_9',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h9b-1)
     &,int_mb(k_range+p10b-1),2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (p10b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_9',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_9',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_9_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p4 )_vx + = 1 * Sum ( h7 p8 ) * x ( p8 h7 )_x * v ( h6 h7 p4 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h6b
      INTEGER p4b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p8b
      INTEGER h7b
      INTEGER p8b_1
      INTEGER h7b_1
      INTEGER h6b_2
      INTEGER h7b_2
      INTEGER p4b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h6b = 1,noab
      DO p4b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+p4b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+p4b-1)) .eq. ieor(irrep_
     &v,irrep_x)) THEN
      dimc = int_mb(k_range+h6b-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_y_tr1_7_9_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p8b = noab+1,noab+nvab
      DO h7b = 1,noab
      IF (int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+p8b-1),int_mb(k_sym+h7b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p8b,h7b,p8b_1,h7b_1)
      CALL TCE_RESTRICTED_4(h6b,h7b,p4b,p8b,h6b_2,h7b_2,p4b_2,p8b_2)
      dim_common = int_mb(k_range+p8b-1) * int_mb(k_range+h7b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = 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_y_tr1_7_9_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_9_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_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+h7b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_9_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_9_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_9_1',5,MA_ERR)
      IF ((h7b .lt. h6b) .and. (p8b .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) * (p8b_2 - 1 + (noab+nvab) * (h6b_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) * (p8b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h7b_2 - 1)))),p4b_2,p8b_2,h6b_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+h6b-1),int_mb(k_range+p8b-1),int_mb(k_range+p4b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h7b .lt. h6b) .and. (p4b .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) * (p4b_2 - 1 + (noab+nvab) * (h6b_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),
     &(p8b_2
     & - 1 + (noab+nvab) * (p4b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h7b_2 - 1)))),p8b_2,p4b_2,h6b_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+h6b-1),int_mb(k_range+p4b-1),int_mb(k_range+p8b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF ((h6b .le. h7b) .and. (p8b .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) * (p8b_2 - 1 + (noab+nvab) * (h7b_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) * (p8b_2 - 1 + (noab+nvab) * (h7b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p4b_2,p8b_2,h7b_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+h7b-1),int_mb(k_range+p8b-1),int_mb(k_range+p4b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h6b .le. h7b) .and. (p4b .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) * (p4b_2 - 1 + (noab+nvab) * (h7b_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) * (p4b_2 - 1 + (noab+nvab) * (h7b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p8b_2,p4b_2,h7b_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+h7b-1),int_mb(k_range+p4b-1),int_mb(k_range+p8b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_7_9_1',6,MA_E
     &RR)
      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_y_tr1_7_9_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_9_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_y_tr1_7_9_1',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p4b-1)
     &,int_mb(k_range+h6b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p4b -
     & noab - 1 + nvab * (h6b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_9_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_9_1',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_7_9_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p4 )_vx
      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 p4b
      length = 0
      DO h6b = 1,noab
      DO p4b = noab+1,noab+nvab
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+p4b-1)) .eq. ieor(irrep_
     &v,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+p4b-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_y_tr1_7_9_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h6b = 1,noab
      DO p4b = noab+1,noab+nvab
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+p4b-1)) .eq. ieor(irrep_
     &v,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+p4b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p4b - noab - 1 + nvab * (h6b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h6b-1) * int_mb(k_range+p4b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_10(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( p10 h9 )_vxt + = -1/2 * Sum ( h5 h6 p4 ) * t ( p4 p10 h5 h6 )_t * i2 ( h5 h6 h9 p4 )_vx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p10b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p10b_1
      INTEGER p4b_1
      INTEGER h5b_1
      INTEGER h6b_1
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER h9b_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 nsubh(2)
      INTEGER isubh
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p10b = noab+1,noab+nvab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p10b-1)+int_mb(k_spin+h9b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+p10b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),int_mb(k_sym+h9b-1)) .eq. ieor(irrep
     &_v,ieor(irrep_x,irrep_t))) THEN
      dimc = int_mb(k_range+p10b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_10',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p4b = noab+1,noab+nvab
      DO h5b = 1,noab
      DO h6b = h5b,noab
      IF (int_mb(k_spin+p10b-1)+int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+
     &h5b-1)+int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p10b-1),ieor(int_mb(k_sym+p4b-1),ieor(int_mb
     &(k_sym+h5b-1),int_mb(k_sym+h6b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p10b,p4b,h5b,h6b,p10b_1,p4b_1,h5b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h5b,h6b,h9b,p4b,h5b_2,h6b_2,h9b_2,p4b_2)
      dim_common = int_mb(k_range+p4b-1) * int_mb(k_range+h5b-1) * int_m
     &b(k_range+h6b-1)
      dima_sort = int_mb(k_range+p10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h9b-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_y_tr1_7_10',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_10',2,MA_ERR)
      IF ((p4b .le. p10b)) 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 * (p10b_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+p10b-1),int_mb(k_range+h5b-1),int_mb(k_range+h6b-1
     &),2,4,3,1,1.0d0)
      END IF
      IF ((p10b .lt. p4b)) 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 * (p4b_1 - noab - 1 + nvab * (p10b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p10b-1
     &),int_mb(k_range+p4b-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_y_tr1_7_10',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_10',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_10',5,MA_ERR)
      IF ((h9b .le. p4b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p4b_2
     & - noab - 1 + nvab * (h9b_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+h9b-1),int_mb(k_range+p4b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_7_10',6,MA_ER
     &R)
      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_y_tr1_7_10',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_10',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_y_tr1_7_10',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h9b-1)
     &,int_mb(k_range+p10b-1),2,1,-1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (p10b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_10',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_10',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_7_10_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h9 p4 )_vx + = -1 * Sum ( p7 ) * x ( p7 h9 )_x * v ( h5 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h5b
      INTEGER h6b
      INTEGER h9b
      INTEGER p4b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h9b_1
      INTEGER h5b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h5b = 1,noab
      DO h6b = h5b,noab
      DO h9b = 1,noab
      DO p4b = 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+h9b-1)+int_mb(k_spin+p4b-1).ne.8)) THEN
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h
     &9b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h9b-1),int_mb(k_sym+p4b-1)))) .eq. ieor(irrep_v,irrep_x)) TH
     &EN
      dimc = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb(k_ra
     &nge+h9b-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_y_tr1_7_10_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+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h9b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p7b,h9b,p7b_1,h9b_1)
      CALL TCE_RESTRICTED_4(h5b,h6b,p4b,p7b,h5b_2,h6b_2,p4b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h9b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h5b-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_y_tr1_7_10_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_7_10_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_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+h9b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_7_10_1',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_7_10_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_7_10_1',5,MA_ERR)
      IF ((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) * (h5b_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) * (h5b_2 - 1)))),p4b_2,p7b_2,h6b_2,h5b_2)
      end if
      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+p4b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((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) * (h5b_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) * (h5b_2 - 1)))),p7b_2,p4b_2,h6b_2,h5b_2)
      end if
      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+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_y_tr1_7_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_y_tr1_7_10_1',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_7_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_y_tr1_7_10_1',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+h5b-1),int_mb(k_range+h9b-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 * (h9b - 1 + noab * (h6b - 1 + noab * (h5b - 1)))
     &))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_7_10_1',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_7_10_1',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_7_10_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h9 p4 )_vx
      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 h9b
      INTEGER p4b
      length = 0
      DO h5b = 1,noab
      DO h6b = h5b,noab
      DO h9b = 1,noab
      DO p4b = noab+1,noab+nvab
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h
     &9b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h9b-1),int_mb(k_sym+p4b-1)))) .eq. ieor(irrep_v,irrep_x)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h9b-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_y_tr1_7_10_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h5b = 1,noab
      DO h6b = h5b,noab
      DO h9b = 1,noab
      DO p4b = noab+1,noab+nvab
      IF (int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h
     &9b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h5b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h9b-1),int_mb(k_sym+p4b-1)))) .eq. ieor(irrep_v,irrep_x)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h9b-1)+int_mb(k_spin+p4b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p4b - noab - 1 + nvab * (h9b - 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+h9b-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_y_tr1_8(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yxv + = -1/2 * Sum ( h4 h5 h3 ) * i1 ( h4 h5 h3 p1 )_yx * v ( h2 h3 h4 h5 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER h5b
      INTEGER h3b
      INTEGER h4b_1
      INTEGER h5b_1
      INTEGER p1b_1
      INTEGER h3b_1
      INTEGER h2b_2
      INTEGER h3b_2
      INTEGER h4b_2
      INTEGER h5b_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 NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x,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_y_tr1_8',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h3b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+h3b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      CALL TCE_RESTRICTED_4(h4b,h5b,p1b,h3b,h4b_1,h5b_1,p1b_1,h3b_1)
      CALL TCE_RESTRICTED_4(h2b,h3b,h4b,h5b,h2b_2,h3b_2,h4b_2,h5b_2)
      dim_common = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_m
     &b(k_range+h3b-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_y_tr1_8',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_8',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h3b_1
     & - 1 + noab * (p1b_1 - noab - 1 + nvab * (h5b_1 - 1 + noab * (h4b_
     &1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p1b-1),int_mb(k_range+h3b-1)
     &,3,4,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_8',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_8',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_8',5,MA_ERR)
      IF ((h3b .lt. h2b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h5b_2
     & - 1 + (noab+nvab) * (h4b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h3b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(h5b_2
     & - 1 + (noab+nvab) * (h4b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h3b_2 - 1)))),h5b_2,h4b_2,h2b_2,h3b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h4b-1),int_mb(k_range+h5b-1)
     &,2,1,4,3,-1.0d0)
      END IF
      IF ((h2b .le. h3b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h5b_2
     & - 1 + (noab+nvab) * (h4b_2 - 1 + (noab+nvab) * (h3b_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),
     &(h5b_2
     & - 1 + (noab+nvab) * (h4b_2 - 1 + (noab+nvab) * (h3b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),h5b_2,h4b_2,h3b_2,h2b_2)
      endif
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h3b-1),int_mb(k_range+h4b-1),int_mb(k_range+h5b-1)
     &,1,2,4,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_8',6,MA_ERR)
      nsuperh(1) = 1
      nsuperh(2) = 1
      isuperh = 1
      IF (h4b .eq. h5b) 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_y_tr1_8',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_8',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_y_tr1_8',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_y_tr1_8',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_8',11,MA
     &_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_8_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h4 h5 h3 p1 )_yx + = -1 * Sum ( p6 ) * x ( p6 h3 )_x * y ( h4 h5 p1 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER p1b
      INTEGER h3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p6b
      INTEGER p6b_1
      INTEGER h3b_1
      INTEGER h4b_2
      INTEGER h5b_2
      INTEGER p1b_2
      INTEGER p6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO p1b = noab+1,noab+nvab
      DO h3b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+h3b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+h3b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+p1b-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_y_tr1_8_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p6b = noab+1,noab+nvab
      IF (int_mb(k_spin+p6b-1) .eq. int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+p6b-1),int_mb(k_sym+h3b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p6b,h3b,p6b_1,h3b_1)
      CALL TCE_RESTRICTED_4(h4b,h5b,p1b,p6b,h4b_2,h5b_2,p1b_2,p6b_2)
      dim_common = int_mb(k_range+p6b-1)
      dima_sort = int_mb(k_range+h3b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+p1b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_8_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_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 * (p6b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+h3b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_8_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_8_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_8_1',5,MA_ERR)
      IF ((p6b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (p6b_2 - noab - 1 + nvab * (h5b_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+h5b-1),int_mb(k_range+p6b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p1b .le. p6b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (h5b_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+h5b-1),int_mb(k_range+p1b-1),int_mb(k_range+p6b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_8_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_8_1',8,M
     &A_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_y_tr1_8_1',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+h5b-1),int_mb(k_range+h4b-1),int_mb(k_range+h3b-1)
     &,3,2,1,4,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h3b -
     & 1 + noab * (p1b - noab - 1 + nvab * (h5b - 1 + noab * (h4b - 1)))
     &))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_8_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_8_1',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_8_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 ( h4 h5 h3 p1 )_yx
      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 h5b
      INTEGER p1b
      INTEGER h3b
      length = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO p1b = noab+1,noab+nvab
      DO h3b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &3b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h3b-1),int_mb(k_sym+p1b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h3b-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_y_tr1_8_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO p1b = noab+1,noab+nvab
      DO h3b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &3b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h3b-1),int_mb(k_sym+p1b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h3b-1)+int_mb(k_spin+p1b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h3b - 1 + noab * (p1b - noab - 1 + nvab 
     &* (h5b - 1 + noab * (h4b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_
     &mb(k_range+p1b-1) * int_mb(k_range+h3b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_vxy + = -1 * Sum ( p9 h10 h11 ) * y ( h10 h11 p1 p9 )_y * i1 ( h2 p9 h10 h11 )_vx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h10b
      INTEGER h11b
      INTEGER p9b
      INTEGER h10b_1
      INTEGER h11b_1
      INTEGER p1b_1
      INTEGER p9b_1
      INTEGER h2b_2
      INTEGER p9b_2
      INTEGER h10b_2
      INTEGER h11b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER nsuperh(2)
      INTEGER isuperh
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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,ieor(irrep_x,irrep_y))) 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_y_tr1_9',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h10b = 1,noab
      DO h11b = h10b,noab
      DO p9b = noab+1,noab+nvab
      IF (int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1) .eq. int_mb(k_spin
     &+p1b-1)+int_mb(k_spin+p9b-1)) THEN
      IF (ieor(int_mb(k_sym+h10b-1),ieor(int_mb(k_sym+h11b-1),ieor(int_m
     &b(k_sym+p1b-1),int_mb(k_sym+p9b-1)))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_4(h10b,h11b,p1b,p9b,h10b_1,h11b_1,p1b_1,p9b_1)
      CALL TCE_RESTRICTED_4(h2b,p9b,h10b,h11b,h2b_2,p9b_2,h10b_2,h11b_2)
      dim_common = int_mb(k_range+h10b-1) * int_mb(k_range+h11b-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_y_tr1_9',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9',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 * (h11b_1 - 1 + noab
     & * (h10b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h10b-1
     &),int_mb(k_range+h11b-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 * (h11b_1 - 1 + noab
     & * (h10b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h10b-1
     &),int_mb(k_range+h11b-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_y_tr1_9',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h11b_
     &2 - 1 + noab * (h10b_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+h10b-1),int_mb(k_range+h11b-
     &1),1,2,4,3,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_9',6,MA_ERR)
      nsuperh(1) = 1
      nsuperh(2) = 1
      isuperh = 1
      IF (h10b .eq. h11b) 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_y_tr1_9',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9',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_y_tr1_9',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_y_tr1_9',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9',11,MA
     &_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 h11 )_vx + = 1 * Sum ( p5 ) * x ( p5 h11 )_x * v ( h2 p9 h10 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p9b
      INTEGER h11b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h11b_1
      INTEGER h2b_2
      INTEGER p9b_2
      INTEGER h10b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h11b = 1,noab
      DO h10b = 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+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,irrep_x)) 
     &THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_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+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h11b-1)) .eq. irrep_x) T
     &HEN
      CALL TCE_RESTRICTED_2(p5b,h11b,p5b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h2b,p9b,h10b,p5b,h2b_2,p9b_2,h10b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-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+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_y_tr1_9_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &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+h11b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_1',5,MA_ERR)
      IF ((h2b .le. p9b) .and. (h10b .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) * (h10b_2 - 1 + (noab+nvab) * (p9b_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),
     &(p5b_2
     & - 1 + (noab+nvab) * (h10b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noa
     &b+nvab) * (h2b_2 - 1)))),p5b_2,h10b_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+h10b-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_y_tr1_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_y_tr1_9_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_1',8,M
     &A_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_y_tr1_9_1',9,MA_ERR)
      IF ((h10b .le. h11b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h10b-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/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      END IF
      IF ((h11b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h10b-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/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (h11b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_1',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_9_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 h11 )_vx
      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 h10b
      INTEGER h11b
      length = 0
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h11b = h10b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,irrep_x)) 
     &THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-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_y_tr1_9_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 h10b = 1,noab
      DO h11b = h10b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,irrep_x)) 
     &THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h11b - 1 + noab * (h10b - 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+h10b-1) * int_mb(k_range+h11b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 h11 )_fx + = 1/2 * Sum ( p6 ) * x ( p6 p9 h10 h11 )_x * i2 ( h2 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p9b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p6b
      INTEGER p9b_1
      INTEGER p6b_1
      INTEGER h10b_1
      INTEGER h11b_1
      INTEGER h2b_2
      INTEGER p6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h11b = h10b,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+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_f,irrep_x)) 
     &THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p6b = noab+1,noab+nvab
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p6b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p6b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p9b,p6b,h10b,h11b,p9b_1,p6b_1,h10b_1,h11b_1)
      CALL TCE_RESTRICTED_2(h2b,p6b,h2b_2,p6b_2)
      dim_common = int_mb(k_range+p6b-1)
      dima_sort = int_mb(k_range+p9b-1) * int_mb(k_range+h10b-1) * int_m
     &b(k_range+h11b-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_y_tr1_9_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_2',2,MA_ERR)
      IF ((p6b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (h10b_1 - 1 + noab * (p9b_1 - noab - 1 + nvab * (p6
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h10b-1),int_mb(k_range+h11b-
     &1),4,3,2,1,1.0d0)
      END IF
      IF ((p9b .lt. p6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (h10b_1 - 1 + noab * (p6b_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+p6b-1),int_mb(k_range+h10b-1),int_mb(k_range+h11b-
     &1),4,3,1,2,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_2',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_2',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_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+p6b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_9_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_y_tr1_9_2',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_2',8,M
     &A_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_y_tr1_9_2',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+h11b-1),int_mb(k_range+h10b-1),int_mb(k_range+p9b-
     &1),1,4,3,2,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_2',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_2',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_2_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p6 )_f + = 1 * f ( h2 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p6b
      INTEGER dimc
      INTEGER h2b_1
      INTEGER p6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p6b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p6b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p6b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p6b-1)) .eq. irrep_f) TH
     &EN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p6b-1)
      CALL TCE_RESTRICTED_2(h2b,p6b,h2b_1,p6b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h2b-1) * int_mb(k_range+p6b-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_y_tr1_9_2_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_2_1',1,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p6b_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+p6b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_2_1',2,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_y_tr1_9_2_1',3,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+p6b-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),(p6b -
     & noab - 1 + nvab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_2_1',4,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_2_1',5
     &,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_9_2_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p6 )_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 p6b
      length = 0
      DO h2b = 1,noab
      DO p6b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p6b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p6b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p6b-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_y_tr1_9_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO p6b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p6b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p6b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p6b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p6b - 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+p6b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_2_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p6 )_vt + = -1 * Sum ( h4 p3 ) * t ( p3 h4 )_t * v ( h2 h4 p3 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p6b
      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 p6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p6b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p6b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p6b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p6b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p6b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_2_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(h2b,h4b,p6b,p3b,h2b_2,h4b_2,p6b_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+p6b-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_y_tr1_9_2_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_2_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_y_tr1_9_2_2',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_2_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_2_2',5,MA_ERR)
      IF ((h4b .lt. h2b) .and. (p3b .le. p6b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - 1 + (noab+nvab) * (p3b_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),
     &(p6b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p6b_2,p3b_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+p3b-1),int_mb(k_range+p6b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h4b .lt. h2b) .and. (p6b .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) * (p6b_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) * (p6b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p3b_2,p6b_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+p6b-1),int_mb(k_range+p3b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF ((h2b .le. h4b) .and. (p3b .le. p6b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - 1 + (noab+nvab) * (p3b_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),
     &(p6b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p6b_2,p3b_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+p3b-1),int_mb(k_range+p6b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h2b .le. h4b) .and. (p6b .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) * (p6b_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) * (p6b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p3b_2,p6b_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+p6b-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_y_tr1_9_2_2',6,MA_E
     &RR)
      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_y_tr1_9_2_2',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_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_y_tr1_9_2_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p6b-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),(p6b -
     & noab - 1 + nvab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_2_2',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_2_2',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 h11 )_vx + = 1 * Sum ( h6 p4 ) * x ( p4 p9 h6 h11 )_x * i2 ( h2 h6 h10 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p9b
      INTEGER h11b
      INTEGER h10b
      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 h10b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h11b = 1,noab
      DO h10b = 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+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,irrep_x)) 
     &THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_3',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_x) THEN
      CALL TCE_RESTRICTED_4(p9b,p4b,h11b,h6b,p9b_1,p4b_1,h11b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h2b,h6b,h10b,p4b,h2b_2,h6b_2,h10b_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+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_y_tr1_9_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_3',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_y_tr1_9_3',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_3',5,MA_ERR)
      IF ((h10b .le. p4b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p4b_2
     & - noab - 1 + nvab * (h10b_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+h10b-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_y_tr1_9_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_y_tr1_9_3',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_3',8,M
     &A_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_y_tr1_9_3',9,MA_ERR)
      IF ((h10b .le. h11b)) THEN
      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+h11b-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),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      END IF
      IF ((h11b .le. h10b)) THEN
      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+h11b-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),(h10b 
     &- 1 + noab * (h11b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_3',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_3',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_3_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 p4 )_v + = 1 * v ( h2 h6 h10 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h6b
      INTEGER h10b
      INTEGER p4b
      INTEGER dimc
      INTEGER h2b_1
      INTEGER h6b_1
      INTEGER h10b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h6b = 1,noab
      DO h10b = 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+h10b-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
     &10b-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+h10b-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+h10b-1) * int_mb(k_range+p4b-1)
      CALL TCE_RESTRICTED_4(h2b,h6b,h10b,p4b,h2b_1,h6b_1,h10b_1,p4b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h6b-1) * int_mb
     &(k_range+h10b-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_y_tr1_9_3_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_3_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) * (h10b_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) * (h10b_1 - 1 + (noab+nvab) * (h2b_1 - 1 + (noa
     &b+nvab) * (h6b_1 - 1)))),p4b_1,h10b_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+h10b-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) * (h10b_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) * (h10b_1 - 1 + (noab+nvab) * (h6b_1 - 1 + (noa
     &b+nvab) * (h2b_1 - 1)))),p4b_1,h10b_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+h10b-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_y_tr1_9_3_1',2,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_y_tr1_9_3_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+h10b-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 * (h10b - 1 + noab * (h6b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_3_1',4,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_3_1',5
     &,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_9_3_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 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 h10b
      INTEGER p4b
      length = 0
      DO h2b = 1,noab
      DO h6b = 1,noab
      DO h10b = 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
     &10b-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+h10b-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+h10b-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_y_tr1_9_3_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h6b = 1,noab
      DO h10b = 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
     &10b-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+h10b-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+h10b-1)+int_mb(k_spin+p4b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p4b - noab - 1 + nvab * (h10b - 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+h10b-1) * int_mb(k_range+p4b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
c done till here
      SUBROUTINE ccsd_y_tr1_9_3_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 p4 )_vt + = 1 * Sum ( p3 ) * t ( p3 h10 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h6b
      INTEGER h10b
      INTEGER p4b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h10b_1
      INTEGER h2b_2
      INTEGER h6b_2
      INTEGER p4b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h6b = 1,noab
      DO h10b = 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+h10b-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
     &10b-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+h10b-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+h10b-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_y_tr1_9_3_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+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h10b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p3b,h10b,p3b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h2b,h6b,p4b,p3b,h2b_2,h6b_2,p4b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h10b-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_y_tr1_9_3_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_3_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &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+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_3_2',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_3_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_3_2',5,MA_ERR)
      IF ((h6b .lt. h2b) .and. (p3b .le. 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) * (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)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h6b .lt. h2b) .and. (p4b .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) * (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),
     &(p3b_2
     & - 1 + (noab+nvab) * (p4b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p3b_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+p3b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF ((h2b .le. h6b) .and. (p3b .le. 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) * (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)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h2b .le. h6b) .and. (p4b .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) * (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),
     &(p3b_2
     & - 1 + (noab+nvab) * (p4b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p3b_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+p3b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_9_3_2',6,MA_E
     &RR)
      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_y_tr1_9_3_2',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_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_y_tr1_9_3_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+h10b-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 * (h10b - 1 + noab * (h6b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_3_2',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_3_2',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_4(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 h11 )_vx + = 1/4 * Sum ( p4 p5 ) * x ( p4 p5 h10 h11 )_x * v ( h2 p9 p4 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p9b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p4b
      INTEGER p5b
      INTEGER p4b_1
      INTEGER p5b_1
      INTEGER h10b_1
      INTEGER h11b_1
      INTEGER h2b_2
      INTEGER p9b_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 NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h11b = h10b,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+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,irrep_x)) 
     &THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_4',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
      IF (int_mb(k_spin+p4b-1)+int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p4b-1),ieor(int_mb(k_sym+p5b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p4b,p5b,h10b,h11b,p4b_1,p5b_1,h10b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h2b,p9b,p4b,p5b,h2b_2,p9b_2,p4b_2,p5b_2)
      dim_common = int_mb(k_range+p4b-1) * int_mb(k_range+p5b-1)
      dima_sort = int_mb(k_range+h10b-1) * 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)
      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_y_tr1_9_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_4',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (h10b_1 - 1 + noab * (p5b_1 - noab - 1 + nvab * (p4
     &b_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+h10b-1),int_mb(k_range+h11b-
     &1),4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_4',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_4',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),(p5b_2
     & - 1 + (noab+nvab) * (p4b_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) * (p4b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p5b_2,p4b_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+p4b-1),int_mb(k_range+p5b-1)
     &,2,1,4,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_9_4',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_y_tr1_9_4',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_4',8,M
     &A_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_y_tr1_9_4',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+h11b-1),int_mb(k_range+h10b-
     &1),2,1,4,3,1.0d0/4.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_4',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_4',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_5(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 h11 )_vtx + = -1 * Sum ( h8 ) * x ( p9 h8 )_x * i2 ( h2 h8 h10 h11 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p9b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h8b
      INTEGER p9b_1
      INTEGER h8b_1
      INTEGER h2b_2
      INTEGER h8b_2
      INTEGER h10b_2
      INTEGER h11b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h11b = h10b,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+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irrep
     &_t,irrep_x))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_5',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h8b = 1,noab
      IF (int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),int_mb(k_sym+h8b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p9b,h8b,p9b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,h10b,h11b,h2b_2,h8b_2,h10b_2,h11b_2)
      dim_common = int_mb(k_range+h8b-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+h10b-1) * int_m
     &b(k_range+h11b-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_y_tr1_9_5',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_5',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_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+h8b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_5',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_5',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_5',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h11b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (h8b_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+h8b-1),int_mb(k_range+h10b-1),int_mb(k_range+h11b-
     &1),4,3,1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_9_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_y_tr1_9_5',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_5',8,M
     &A_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_y_tr1_9_5',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h11b-1
     &),int_mb(k_range+h10b-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),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_5',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_5',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_5_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 h10 h11 )_vt + = -1 * Sum ( p3 ) * t ( p3 h10 )_t * i3 ( h2 h8 h11 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h8b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h10b_1
      INTEGER h2b_2
      INTEGER h8b_2
      INTEGER h11b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h10b = 1,noab
      DO h11b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,irrep_t)) 
     &THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h8b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_5_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+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h10b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p3b,h10b,p3b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,h11b,p3b,h2b_2,h8b_2,h11b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h8b-1) * int_mb
     &(k_range+h11b-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_y_tr1_9_5_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_5_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &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+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_5_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_5_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_5_1',5,MA_ERR)
      IF ((h11b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h11b_2 - 1 + noab * (h8b_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+h8b-1),int_mb(k_range+h11b-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_y_tr1_9_5_1',6,MA_E
     &RR)
      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_y_tr1_9_5_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_5_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_y_tr1_9_5_1',9,MA_ERR)
      IF ((h10b .le. h11b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h11b-1
     &),int_mb(k_range+h8b-1),int_mb(k_range+h2b-1),int_mb(k_range+h10b-
     &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),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (h8b - 1 + noab * (h2b - 1)))))
      END IF
      IF ((h11b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h11b-1
     &),int_mb(k_range+h8b-1),int_mb(k_range+h2b-1),int_mb(k_range+h10b-
     &1),3,2,1,4,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (h11b - 1 + noab * (h8b - 1 + noab * (h2b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_5_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_5_1',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_9_5_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 h10 h11 )_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 h2b
      INTEGER h8b
      INTEGER h10b
      INTEGER h11b
      length = 0
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h10b = 1,noab
      DO h11b = h10b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,irrep_t)) 
     &THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-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_y_tr1_9_5_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h10b = 1,noab
      DO h11b = h10b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,irrep_t)) 
     &THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h11b - 1 + noab * (h10b - 1 + noab * (h8
     &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+h8b-1) * int_
     &mb(k_range+h10b-1) * int_mb(k_range+h11b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_5_1_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 h11 p3 )_v + = 1 * v ( h2 h8 h11 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h8b
      INTEGER h11b
      INTEGER p3b
      INTEGER dimc
      INTEGER h2b_1
      INTEGER h8b_1
      INTEGER h11b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h11b = 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+h8b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p3b-1)))) .eq. irrep_v) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h8b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+p3b-1)
      CALL TCE_RESTRICTED_4(h2b,h8b,h11b,p3b,h2b_1,h8b_1,h11b_1,p3b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h8b-1) * int_mb
     &(k_range+h11b-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_y_tr1_9_5_1_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_5_1_1',1,MA_ERR)
      IF ((h8b .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) * (h11b_1 - 1 + (noab+nvab) * (h2b_1 - 1 + (noa
     &b+nvab) * (h8b_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) * (h11b_1 - 1 + (noab+nvab) * (h2b_1 - 1 + (noa
     &b+nvab) * (h8b_1 - 1)))),p3b_1,h11b_1,h2b_1,h8b_1)
      end if
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h11b-1),int_mb(k_range+p3b-1
     &),4,3,1,2,-1.0d0)
      END IF
      IF ((h2b .le. h8b)) 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) * (h11b_1 - 1 + (noab+nvab) * (h8b_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) * (h11b_1 - 1 + (noab+nvab) * (h8b_1 - 1 + (noa
     &b+nvab) * (h2b_1 - 1)))),p3b_1,h11b_1,h8b_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+h8b-1),int_mb(k_range+h11b-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_y_tr1_9_5_1_1',2,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsd_y_tr1_9_5_1_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+h11b-1),int_mb(k_range+h8b-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 * (h11b - 1 + noab * (h8b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_5_1_1',4,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_5_1_1'
     &,5,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_9_5_1_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 h11 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 h8b
      INTEGER h11b
      INTEGER p3b
      length = 0
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h11b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h11b-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+h8b-1
     &)+int_mb(k_spin+h11b-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_y_tr1_9_5_1_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h11b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h11b-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+h8b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p3b - noab - 1 + nvab * (h11b - 1 + noab
     & * (h8b - 1 + noab * (h2b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+h8b-1) * int_
     &mb(k_range+h11b-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_y_tr1_9_5_1_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_
     &c_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 h11 p3 )_vt + = -1/2 * Sum ( p5 ) * t ( p5 h11 )_t * v ( h2 h8 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h8b
      INTEGER h11b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h11b_1
      INTEGER h2b_2
      INTEGER h8b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h11b = 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+h8b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h11b-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+h8b-1) * int_mb(k_ra
     &nge+h11b-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_y_tr1_9_5_1_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+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h11b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p5b,h11b,p5b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,p3b,p5b,h2b_2,h8b_2,p3b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-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+h8b-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_y_tr1_9_5_1_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_5_1_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &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+h11b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_5_1_2',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_5_1_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_5_1_2',5,MA_ERR)
      IF ((h8b .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) * (h8b_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) * (h8b_2 - 1)))),p3b_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+p3b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h8b .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) * (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) * (p3b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p5b_2,p3b_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+p3b-1),int_mb(k_range+p5b-1)
     &,3,1,2,4,-1.0d0)
      END IF
      IF ((h2b .le. h8b) .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) * (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),
     &(p3b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p3b_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+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h2b .le. h8b) .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) * (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) * (p3b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p5b_2,p3b_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+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_y_tr1_9_5_1_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_y_tr1_9_5_1_2'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_5_1_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_y_tr1_9_5_1_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+h8b-1),int_mb(k_range+h2b-1),int_mb(k_range+h11b-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 * (h11b - 1 + noab * (h8b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_5_1_2',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_5_1_2'
     &,11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_5_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 h10 h11 )_vt + = 1/4 * Sum ( p3 p4 ) * t ( p3 p4 h10 h11 )_t * v ( h2 h8 p3 p4 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h8b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p4b
      INTEGER p3b_1
      INTEGER p4b_1
      INTEGER h10b_1
      INTEGER h11b_1
      INTEGER h2b_2
      INTEGER h8b_2
      INTEGER p3b_2
      INTEGER p4b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h10b = 1,noab
      DO h11b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,irrep_t)) 
     &THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h8b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_5_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
      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+h11b-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+h11b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p3b,p4b,h10b,h11b,p3b_1,p4b_1,h10b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,p3b,p4b,h2b_2,h8b_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+h10b-1) * int_mb(k_range+h11b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h8b-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_y_tr1_9_5_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_5_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (h10b_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+h10b-1),int_mb(k_range+h11b-
     &1),4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_5_2',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_5_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_5_2',5,MA_ERR)
      IF ((h8b .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) * (h8b_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) * (h8b_2 - 1)))),p4b_2,p3b_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+p3b-1),int_mb(k_range+p4b-1)
     &,1,2,4,3,-1.0d0)
      END IF
      IF ((h2b .le. h8b)) 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) * (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),
     &(p4b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p4b_2,p3b_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+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_y_tr1_9_5_2',6,MA_E
     &RR)
      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_y_tr1_9_5_2',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_5_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_y_tr1_9_5_2',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h11b-1),int_mb(k_range+h10b-
     &1),2,1,4,3,1.0d0/4.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (h8b - 1 + noab * (h2b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_5_2',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_5_2',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_6(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 h11 )_vxt + = 1 * Sum ( h8 ) * t ( p9 h8 )_t * i2 ( h2 h8 h10 h11 )_vx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p9b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h8b
      INTEGER p9b_1
      INTEGER h8b_1
      INTEGER h2b_2
      INTEGER h8b_2
      INTEGER h10b_2
      INTEGER h11b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h11b = h10b,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+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irrep
     &_x,irrep_t))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_6',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h8b = 1,noab
      IF (int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),int_mb(k_sym+h8b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p9b,h8b,p9b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,h10b,h11b,h2b_2,h8b_2,h10b_2,h11b_2)
      dim_common = int_mb(k_range+h8b-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+h10b-1) * int_m
     &b(k_range+h11b-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_y_tr1_9_6',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_6',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_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+h8b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_6',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_6',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_6',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h11b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (h8b_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+h8b-1),int_mb(k_range+h10b-1),int_mb(k_range+h11b-
     &1),4,3,1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_9_6',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_y_tr1_9_6',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_6',8,M
     &A_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_y_tr1_9_6',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h11b-1
     &),int_mb(k_range+h10b-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),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_6',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_6',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_6_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 h10 h11 )_vx + = -1 * Sum ( p6 ) * x ( p6 h11 )_x * v ( h2 h8 h10 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h8b
      INTEGER h11b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p6b
      INTEGER p6b_1
      INTEGER h11b_1
      INTEGER h2b_2
      INTEGER h8b_2
      INTEGER h10b_2
      INTEGER p6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h11b = 1,noab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,irrep_x)) 
     &THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h8b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_6_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p6b = noab+1,noab+nvab
      IF (int_mb(k_spin+p6b-1) .eq. int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p6b-1),int_mb(k_sym+h11b-1)) .eq. irrep_x) T
     &HEN
      CALL TCE_RESTRICTED_2(p6b,h11b,p6b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,h10b,p6b,h2b_2,h8b_2,h10b_2,p6b_2)
      dim_common = int_mb(k_range+p6b-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+h8b-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_y_tr1_9_6_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_6_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (p6b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+h11b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_6_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_6_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_6_1',5,MA_ERR)
      IF ((h8b .lt. h2b) .and. (h10b .le. p6b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - 1 + (noab+nvab) * (h10b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noa
     &b+nvab) * (h8b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p6b_2
     & - 1 + (noab+nvab) * (h10b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noa
     &b+nvab) * (h8b_2 - 1)))),p6b_2,h10b_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+h10b-1),int_mb(k_range+p6b-1
     &),3,1,2,4,-1.0d0)
      END IF
      IF ((h2b .le. h8b) .and. (h10b .le. p6b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - 1 + (noab+nvab) * (h10b_2 - 1 + (noab+nvab) * (h8b_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),
     &(p6b_2
     & - 1 + (noab+nvab) * (h10b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noa
     &b+nvab) * (h2b_2 - 1)))),p6b_2,h10b_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+h10b-1),int_mb(k_range+p6b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_9_6_1',6,MA_E
     &RR)
      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_y_tr1_9_6_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_6_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_y_tr1_9_6_1',9,MA_ERR)
      IF ((h10b .le. h11b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h10b-1
     &),int_mb(k_range+h8b-1),int_mb(k_range+h2b-1),int_mb(k_range+h11b-
     &1),3,2,1,4,-1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (h8b - 1 + noab * (h2b - 1)))))
      END IF
      IF ((h11b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h10b-1
     &),int_mb(k_range+h8b-1),int_mb(k_range+h2b-1),int_mb(k_range+h11b-
     &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),(h10b 
     &- 1 + noab * (h11b - 1 + noab * (h8b - 1 + noab * (h2b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_6_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_6_1',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_9_6_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 h10 h11 )_vx
      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 h8b
      INTEGER h10b
      INTEGER h11b
      length = 0
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h10b = 1,noab
      DO h11b = h10b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,irrep_x)) 
     &THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-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_y_tr1_9_6_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h10b = 1,noab
      DO h11b = h10b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,irrep_x)) 
     &THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h11b - 1 + noab * (h10b - 1 + noab * (h8
     &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+h8b-1) * int_
     &mb(k_range+h10b-1) * int_mb(k_range+h11b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_6_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 h10 h11 )_vx + = -1/4 * Sum ( p5 p6 ) * x ( p5 p6 h10 h11 )_x * v ( h2 h8 p5 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h8b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p6b
      INTEGER p5b_1
      INTEGER p6b_1
      INTEGER h10b_1
      INTEGER h11b_1
      INTEGER h2b_2
      INTEGER h8b_2
      INTEGER p5b_2
      INTEGER p6b_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 NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h10b = 1,noab
      DO h11b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,irrep_x)) 
     &THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h8b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_6_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      DO p6b = p5b,noab+nvab
      IF (int_mb(k_spin+p5b-1)+int_mb(k_spin+p6b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),ieor(int_mb(k_sym+p6b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p5b,p6b,h10b,h11b,p5b_1,p6b_1,h10b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,p5b,p6b,h2b_2,h8b_2,p5b_2,p6b_2)
      dim_common = int_mb(k_range+p5b-1) * int_mb(k_range+p6b-1)
      dima_sort = int_mb(k_range+h10b-1) * int_mb(k_range+h11b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h8b-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_y_tr1_9_6_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_6_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (h10b_1 - 1 + noab * (p6b_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+p6b-1),int_mb(k_range+h10b-1),int_mb(k_range+h11b-
     &1),4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_6_2',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_6_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_6_2',5,MA_ERR)
      IF ((h8b .lt. h2b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_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),
     &(p6b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p6b_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+p6b-1)
     &,1,2,4,3,-1.0d0)
      END IF
      IF ((h2b .le. h8b)) THEN 
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_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),
     &(p6b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p6b_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+p6b-1)
     &,2,1,4,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_9_6_2',6,MA_E
     &RR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p5b .eq. p6b) 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_y_tr1_9_6_2',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_6_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_y_tr1_9_6_2',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h11b-1),int_mb(k_range+h10b-
     &1),2,1,4,3,-1.0d0/4.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (h8b - 1 + noab * (h2b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_6_2',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_6_2',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_6_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 h10 h11 )_vxt + = -1 * Sum ( p3 ) * t ( p3 h10 )_t * i3 ( h2 h8 h11 p3 )_vx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h8b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h10b_1
      INTEGER h2b_2
      INTEGER h8b_2
      INTEGER h11b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h10b = 1,noab
      DO h11b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irrep
     &_x,irrep_t))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h8b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_6_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+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h10b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p3b,h10b,p3b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,h11b,p3b,h2b_2,h8b_2,h11b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h8b-1) * int_mb
     &(k_range+h11b-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_y_tr1_9_6_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_6_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &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+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_6_3',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_6_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_6_3',5,MA_ERR)
      IF ((h11b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h11b_2 - 1 + noab * (h8b_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+h8b-1),int_mb(k_range+h11b-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_y_tr1_9_6_3',6,MA_E
     &RR)
      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_y_tr1_9_6_3',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_6_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_y_tr1_9_6_3',9,MA_ERR)
      IF ((h10b .le. h11b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h11b-1
     &),int_mb(k_range+h8b-1),int_mb(k_range+h2b-1),int_mb(k_range+h10b-
     &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),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (h8b - 1 + noab * (h2b - 1)))))
      END IF
      IF ((h11b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h11b-1
     &),int_mb(k_range+h8b-1),int_mb(k_range+h2b-1),int_mb(k_range+h10b-
     &1),3,2,1,4,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (h11b - 1 + noab * (h8b - 1 + noab * (h2b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_6_3',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_6_3',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_6_3_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_
     &c_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 h11 p3 )_vx + = 1 * Sum ( p7 ) * x ( p7 h11 )_x * v ( h2 h8 p3 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h8b
      INTEGER h11b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h11b_1
      INTEGER h2b_2
      INTEGER h8b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h11b = 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+h8b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_v,irrep_x)) T
     &HEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h8b-1) * int_mb(k_ra
     &nge+h11b-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_y_tr1_9_6_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+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h11b-1)) .eq. irrep_x) T
     &HEN
      CALL TCE_RESTRICTED_2(p7b,h11b,p7b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,p3b,p7b,h2b_2,h8b_2,p3b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-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+h8b-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_y_tr1_9_6_3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_6_3_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &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+h11b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_6_3_1',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_6_3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_6_3_1',5,MA_ERR)
      IF ((h8b .lt. h2b) .and. (p7b .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) * (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),
     &(p3b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p3b_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+p3b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h8b .lt. h2b) .and. (p3b .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) * (p3b_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) * (p3b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p7b_2,p3b_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+p3b-1),int_mb(k_range+p7b-1)
     &,3,1,2,4,-1.0d0)
      END IF
      IF ((h2b .le. h8b) .and. (p7b .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) * (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),
     &(p3b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p3b_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+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h2b .le. h8b) .and. (p3b .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) * (p3b_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) * (p3b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p7b_2,p3b_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+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_y_tr1_9_6_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_y_tr1_9_6_3_1'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_6_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_y_tr1_9_6_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+h8b-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),(p3b -
     & noab - 1 + nvab * (h11b - 1 + noab * (h8b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_6_3_1',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_6_3_1'
     &,11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_9_6_3_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 h11 p3 )_vx
      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 h8b
      INTEGER h11b
      INTEGER p3b
      length = 0
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h11b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_v,irrep_x)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h11b-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_y_tr1_9_6_3_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h11b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_v,irrep_x)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p3b - noab - 1 + nvab * (h11b - 1 + noab
     & * (h8b - 1 + noab * (h2b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+h8b-1) * int_
     &mb(k_range+h11b-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_y_tr1_9_7(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 h11 )_vxt + = -1 * Sum ( p3 ) * t ( p3 h10 )_t * i2 ( h2 p9 h11 p3 )_vx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p9b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h10b_1
      INTEGER h2b_2
      INTEGER p9b_2
      INTEGER h11b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h11b = 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+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irrep
     &_x,irrep_t))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_7',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+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h10b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p3b,h10b,p3b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h2b,p9b,h11b,p3b,h2b_2,p9b_2,h11b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb
     &(k_range+h11b-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_y_tr1_9_7',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_7',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &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+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_7',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_7',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_7',5,MA_ERR)
      IF ((h11b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h11b_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+h11b-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_y_tr1_9_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_y_tr1_9_7',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_7',8,M
     &A_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_y_tr1_9_7',9,MA_ERR)
      IF ((h10b .le. h11b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h11b-1
     &),int_mb(k_range+p9b-1),int_mb(k_range+h2b-1),int_mb(k_range+h10b-
     &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),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      END IF
      IF ((h11b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h11b-1
     &),int_mb(k_range+p9b-1),int_mb(k_range+h2b-1),int_mb(k_range+h10b-
     &1),3,2,1,4,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (h11b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_7',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_7',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_7_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h11 p3 )_vx + = -1 * Sum ( p6 ) * x ( p6 h11 )_x * v ( h2 p9 p3 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p9b
      INTEGER h11b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p6b
      INTEGER p6b_1
      INTEGER h11b_1
      INTEGER h2b_2
      INTEGER p9b_2
      INTEGER p3b_2
      INTEGER p6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h11b = 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+h11b-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
     &11b-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+h11b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_v,irrep_x)) T
     &HEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h11b-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_y_tr1_9_7_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p6b = noab+1,noab+nvab
      IF (int_mb(k_spin+p6b-1) .eq. int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p6b-1),int_mb(k_sym+h11b-1)) .eq. irrep_x) T
     &HEN
      CALL TCE_RESTRICTED_2(p6b,h11b,p6b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h2b,p9b,p3b,p6b,h2b_2,p9b_2,p3b_2,p6b_2)
      dim_common = int_mb(k_range+p6b-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+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_y_tr1_9_7_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_7_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (p6b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+h11b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_7_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_7_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_7_1',5,MA_ERR)
      IF ((h2b .le. p9b) .and. (p6b .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) * (p6b_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) * (p6b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p3b_2,p6b_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+p6b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h2b .le. p9b) .and. (p3b .le. p6b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_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),
     &(p6b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p6b_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+p6b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_9_7_1',6,MA_E
     &RR)
      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_y_tr1_9_7_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_7_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_y_tr1_9_7_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+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),(p3b -
     & noab - 1 + nvab * (h11b - 1 + noab * (p9b - noab - 1 + nvab * (h2
     &b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_7_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_7_1',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_9_7_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h11 p3 )_vx
      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 p3b
      length = 0
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h11b = 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
     &11b-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+h11b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_v,irrep_x)) T
     &HEN
      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+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_y_tr1_9_7_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 p3b = noab+1,noab+nvab
      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+p3b-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+p3b-1)))) .eq. ieor(irrep_v,irrep_x)) T
     &HEN
      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+p3b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p3b - noab - 1 + nvab * (h11b - 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+h11b-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_y_tr1_9_8(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 h11 )_vxt + = 1/2 * Sum ( p4 ) * t ( p4 p9 h10 h11 )_t * i2 ( h2 p4 )_vx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p9b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p4b
      INTEGER p9b_1
      INTEGER p4b_1
      INTEGER h10b_1
      INTEGER h11b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h11b = h10b,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+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irrep
     &_x,irrep_t))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_8',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+p9b-1)+int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p4b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p9b,p4b,h10b,h11b,p9b_1,p4b_1,h10b_1,h11b_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+p9b-1) * int_mb(k_range+h10b-1) * int_m
     &b(k_range+h11b-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_y_tr1_9_8',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_8',2,MA_ERR)
      IF ((p4b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (h10b_1 - 1 + noab * (p9b_1 - noab - 1 + nvab * (p4
     &b_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+h10b-1),int_mb(k_range+h11b-
     &1),4,3,2,1,1.0d0)
      END IF
      IF ((p9b .lt. p4b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (h10b_1 - 1 + noab * (p4b_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+p4b-1),int_mb(k_range+h10b-1),int_mb(k_range+h11b-
     &1),4,3,1,2,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_8',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_8',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_8',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_y_tr1_9_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_y_tr1_9_8',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_8',8,M
     &A_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_y_tr1_9_8',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+h11b-1),int_mb(k_range+h10b-1),int_mb(k_range+p9b-
     &1),1,4,3,2,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_8',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_8',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_8_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p4 )_vx + = 1 * Sum ( h7 p8 ) * x ( p8 h7 )_x * v ( h2 h7 p4 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p4b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p8b
      INTEGER h7b
      INTEGER p8b_1
      INTEGER h7b_1
      INTEGER h2b_2
      INTEGER h7b_2
      INTEGER p4b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 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+p4b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p4b-1)) .eq. ieor(irrep_
     &v,irrep_x)) THEN
      dimc = int_mb(k_range+h2b-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_y_tr1_9_8_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p8b = noab+1,noab+nvab
      DO h7b = 1,noab
      IF (int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+p8b-1),int_mb(k_sym+h7b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p8b,h7b,p8b_1,h7b_1)
      CALL TCE_RESTRICTED_4(h2b,h7b,p4b,p8b,h2b_2,h7b_2,p4b_2,p8b_2)
      dim_common = int_mb(k_range+p8b-1) * int_mb(k_range+h7b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-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_y_tr1_9_8_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_8_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_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+h7b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_8_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_8_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_8_1',5,MA_ERR)
      IF ((h7b .lt. h2b) .and. (p8b .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) * (p8b_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) * (p8b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h7b_2 - 1)))),p4b_2,p8b_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+p8b-1),int_mb(k_range+p4b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h7b .lt. h2b) .and. (p4b .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) * (p4b_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),
     &(p8b_2
     & - 1 + (noab+nvab) * (p4b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h7b_2 - 1)))),p8b_2,p4b_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+p4b-1),int_mb(k_range+p8b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF ((h2b .le. h7b) .and. (p8b .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) * (p8b_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) * (p8b_2 - 1 + (noab+nvab) * (h7b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p4b_2,p8b_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+p8b-1),int_mb(k_range+p4b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h2b .le. h7b) .and. (p4b .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) * (p4b_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),
     &(p8b_2
     & - 1 + (noab+nvab) * (p4b_2 - 1 + (noab+nvab) * (h7b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p8b_2,p4b_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+p4b-1),int_mb(k_range+p8b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_9_8_1',6,MA_E
     &RR)
      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_y_tr1_9_8_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_8_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_y_tr1_9_8_1',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p4b-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),(p4b -
     & noab - 1 + nvab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_8_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_8_1',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_9_8_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p4 )_vx
      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 p4b
      length = 0
      DO h2b = 1,noab
      DO p4b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p4b-1)) .eq. ieor(irrep_
     &v,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p4b-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_y_tr1_9_8_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO p4b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p4b-1)) .eq. ieor(irrep_
     &v,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p4b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p4b - 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+p4b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_9(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 h11 )_vxt + = 1 * Sum ( h6 p4 ) * t ( p4 p9 h6 h10 )_t * i2 ( h2 h6 h11 p4 )_vx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p9b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p4b
      INTEGER h6b
      INTEGER p9b_1
      INTEGER p4b_1
      INTEGER h10b_1
      INTEGER h6b_1
      INTEGER h2b_2
      INTEGER h6b_2
      INTEGER h11b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h11b = 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+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irrep
     &_x,irrep_t))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_9',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
     &10b-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+h10b-1),int_mb(k_sym+h6b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p9b,p4b,h10b,h6b,p9b_1,p4b_1,h10b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h2b,h6b,h11b,p4b,h2b_2,h6b_2,h11b_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+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h11b-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_y_tr1_9_9',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_9',2,MA_ERR)
      IF ((p4b .le. p9b) .and. (h6b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &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+h10b-1
     &),4,2,3,1,1.0d0)
      END IF
      IF ((p4b .le. p9b) .and. (h10b .lt. h6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h10b_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+h10b-1),int_mb(k_range+h6b-1
     &),3,2,4,1,-1.0d0)
      END IF
      IF ((p9b .lt. p4b) .and. (h6b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &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+h10b-1
     &),4,1,3,2,-1.0d0)
      END IF
      IF ((p9b .lt. p4b) .and. (h10b .lt. h6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (h10b_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+h10b-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_y_tr1_9_9',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_9',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_9',5,MA_ERR)
      IF ((h11b .le. p4b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p4b_2
     & - noab - 1 + nvab * (h11b_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+h11b-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_y_tr1_9_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_y_tr1_9_9',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_9',8,M
     &A_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_y_tr1_9_9',9,MA_ERR)
      IF ((h10b .le. h11b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h11b-1
     &),int_mb(k_range+h2b-1),int_mb(k_range+h10b-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),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      END IF
      IF ((h11b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h11b-1
     &),int_mb(k_range+h2b-1),int_mb(k_range+h10b-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),(h10b 
     &- 1 + noab * (h11b - 1 + noab * (p9b - noab - 1 + nvab * (h2b - 1)
     &))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_9',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_9',11,
     &MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_9_9_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h11 p4 )_vx + = 1 * Sum ( p7 ) * x ( p7 h11 )_x * 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h6b
      INTEGER h11b
      INTEGER p4b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h11b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h6b = 1,noab
      DO h11b = 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+h11b-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
     &11b-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+h11b-1),int_mb(k_sym+p4b-1)))) .eq. ieor(irrep_v,irrep_x)) T
     &HEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h6b-1) * int_mb(k_ra
     &nge+h11b-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_y_tr1_9_9_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+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h11b-1)) .eq. irrep_x) T
     &HEN
      CALL TCE_RESTRICTED_2(p7b,h11b,p7b_1,h11b_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+h11b-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_y_tr1_9_9_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_9_9_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &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+h11b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_9_9_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_9_9_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_9_9_1',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)))),p4b_2,p7b_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+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_y_tr1_9_9_1',6,MA_E
     &RR)
      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_y_tr1_9_9_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_9_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_y_tr1_9_9_1',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+h11b-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 * (h11b - 1 + noab * (h6b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_9_9_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_9_9_1',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_9_9_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h11 p4 )_vx
      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 h11b
      INTEGER p4b
      length = 0
      DO h2b = 1,noab
      DO h6b = 1,noab
      DO h11b = 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
     &11b-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+h11b-1),int_mb(k_sym+p4b-1)))) .eq. ieor(irrep_v,irrep_x)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h11b-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_y_tr1_9_9_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h6b = 1,noab
      DO h11b = 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
     &11b-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+h11b-1),int_mb(k_sym+p4b-1)))) .eq. ieor(irrep_v,irrep_x)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h6b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p4b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p4b - noab - 1 + nvab * (h11b - 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+h11b-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_y_tr1_10(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_off
     &set)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yxv + = -1 * Sum ( h5 h3 p4 ) * i1 ( h2 h5 h3 p4 )_yx * v ( h3 p4 h5 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h5b
      INTEGER h3b
      INTEGER p4b
      INTEGER h2b_1
      INTEGER h5b_1
      INTEGER h3b_1
      INTEGER p4b_1
      INTEGER h3b_2
      INTEGER p4b_2
      INTEGER p1b_2
      INTEGER h5b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x,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_y_tr1_10',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h5b = 1,noab
      DO h3b = 1,noab
      DO p4b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &3b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h3b-1),int_mb(k_sym+p4b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      CALL TCE_RESTRICTED_4(h2b,h5b,h3b,p4b,h2b_1,h5b_1,h3b_1,p4b_1)
      CALL TCE_RESTRICTED_4(h3b,p4b,p1b,h5b,h3b_2,p4b_2,p1b_2,h5b_2)
      dim_common = int_mb(k_range+h5b-1) * int_mb(k_range+h3b-1) * int_m
     &b(k_range+p4b-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_y_tr1_10',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_10',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p4b_1
     & - noab - 1 + nvab * (h3b_1 - 1 + noab * (h5b_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+h5b-1),int_mb(k_range+h3b-1),int_mb(k_range+p4b-1)
     &,1,4,3,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_10',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_10',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_10',5,MA_ERR)
      IF ((h5b .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) * (h5b_2 - 1 + (noab+nvab) * (p4b_2 - 1 + (noab
     &+nvab) * (h3b_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) * (h5b_2 - 1 + (noab+nvab) * (p4b_2 - 1 + (noab
     &+nvab) * (h3b_2 - 1)))),p1b_2,h5b_2,p4b_2,h3b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+p4b-1),int_mb(k_range+h5b-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_y_tr1_10',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_y_tr1_10',7,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_10',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_y_tr1_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_y_tr1_10',10,MA_ERR
     &)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_10',11,M
     &A_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_10_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h5 h3 p4 )_yx + = 1 * Sum ( p6 ) * x ( p6 h3 )_x * y ( h2 h5 p4 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h5b
      INTEGER h3b
      INTEGER p4b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p6b
      INTEGER p6b_1
      INTEGER h3b_1
      INTEGER h2b_2
      INTEGER h5b_2
      INTEGER p4b_2
      INTEGER p6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h5b = 1,noab
      DO h3b = 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+h5b-1
     &)+int_mb(k_spin+h3b-1)+int_mb(k_spin+p4b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &3b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h3b-1),int_mb(k_sym+p4b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h3b-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_y_tr1_10_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p6b = noab+1,noab+nvab
      IF (int_mb(k_spin+p6b-1) .eq. int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+p6b-1),int_mb(k_sym+h3b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p6b,h3b,p6b_1,h3b_1)
      CALL TCE_RESTRICTED_4(h2b,h5b,p4b,p6b,h2b_2,h5b_2,p4b_2,p6b_2)
      dim_common = int_mb(k_range+p6b-1)
      dima_sort = int_mb(k_range+h3b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h5b-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_y_tr1_10_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_10_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h3b_1
     & - 1 + noab * (p6b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+h3b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_10_1',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_10_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_10_1',5,MA_ERR)
      IF ((h5b .lt. h2b) .and. (p6b .lt. p4b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p4b_2
     & - noab - 1 + nvab * (p6b_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+p6b-1),int_mb(k_range+p4b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h5b .lt. h2b) .and. (p4b .le. p6b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - noab - 1 + nvab * (p4b_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+p4b-1),int_mb(k_range+p6b-1)
     &,3,1,2,4,-1.0d0)
      END IF
      IF ((h2b .le. h5b) .and. (p6b .lt. p4b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p4b_2
     & - noab - 1 + nvab * (p6b_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+p6b-1),int_mb(k_range+p4b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h2b .le. h5b) .and. (p4b .le. p6b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - noab - 1 + nvab * (p4b_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+p4b-1),int_mb(k_range+p6b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_10_1',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_y_tr1_10_1',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_10_1',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+h5b-1),int_mb(k_range+h2b-1),int_mb(k_range+h3b-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 * (h3b - 1 + noab * (h5b - 1 + noab * (h2b - 1)))
     &))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_10_1',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_10_1',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_10_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h5 h3 p4 )_yx
      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 h3b
      INTEGER p4b
      length = 0
      DO h2b = 1,noab
      DO h5b = 1,noab
      DO h3b = 1,noab
      DO p4b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &3b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h3b-1),int_mb(k_sym+p4b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h3b-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_y_tr1_10_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h5b = 1,noab
      DO h3b = 1,noab
      DO p4b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &3b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h3b-1),int_mb(k_sym+p4b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h3b-1)+int_mb(k_spin+p4b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p4b - noab - 1 + nvab * (h3b - 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+h3b-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_y_tr1_11(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_off
     &set)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yxv + = -1/2 * Sum ( p5 p3 p4 ) * i1 ( h2 p5 p3 p4 )_yx * v ( p3 p4 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p3b
      INTEGER p4b
      INTEGER h2b_1
      INTEGER p5b_1
      INTEGER p3b_1
      INTEGER p4b_1
      INTEGER p3b_2
      INTEGER p4b_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 nsubp(2)
      INTEGER isubp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x,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_y_tr1_11',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      DO p3b = noab+1,noab+nvab
      DO p4b = p3b,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+p
     &3b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p5b-1),ieor(int_mb(
     &k_sym+p3b-1),int_mb(k_sym+p4b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      CALL TCE_RESTRICTED_4(h2b,p5b,p3b,p4b,h2b_1,p5b_1,p3b_1,p4b_1)
      CALL TCE_RESTRICTED_4(p3b,p4b,p1b,p5b,p3b_2,p4b_2,p1b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1) * int_mb(k_range+p3b-1) * int_m
     &b(k_range+p4b-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_y_tr1_11',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_11',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p4b_1
     & - noab - 1 + nvab * (p3b_1 - noab - 1 + nvab * (p5b_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+p5b-1),int_mb(k_range+p3b-1),int_mb(k_range+p4b-1)
     &,1,4,3,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_11',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_11',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_11',5,MA_ERR)
      IF ((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) * (p4b_2 - 1 + (noab
     &+nvab) * (p3b_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) * (p4b_2 - 1 + (noab
     &+nvab) * (p3b_2 - 1)))),p1b_2,p5b_2,p4b_2,p3b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p4b-1),int_mb(k_range+p5b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((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) * (p4b_2 - 1 + (noab
     &+nvab) * (p3b_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) * (p4b_2 - 1 + (noab
     &+nvab) * (p3b_2 - 1)))),p5b_2,p1b_2,p4b_2,p3b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p4b-1),int_mb(k_range+p1b-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_y_tr1_11',6,MA_ERR)
      nsubp(1) = 1
      nsubp(2) = 1
      isubp = 1
      IF (p3b .eq. p4b) 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_y_tr1_11',7,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_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/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_y_tr1_11',10,MA_ERR
     &)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_11',11,M
     &A_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_11_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p5 p3 p4 )_yx + = -1 * Sum ( h6 ) * x ( p5 h6 )_x * y ( h2 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p5b
      INTEGER p3b
      INTEGER p4b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h6b
      INTEGER p5b_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 l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p5b = noab+1,noab+nvab
      DO p3b = noab+1,noab+nvab
      DO p4b = p3b,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1
     &)+int_mb(k_spin+p3b-1)+int_mb(k_spin+p4b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+p
     &3b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p5b-1),ieor(int_mb(
     &k_sym+p3b-1),int_mb(k_sym+p4b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p5b-1) * int_mb(k_ra
     &nge+p3b-1) * int_mb(k_range+p4b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_11_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      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_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p5b,h6b,p5b_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+h6b-1)
      dima_sort = int_mb(k_range+p5b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+p3b-1) * int_mb
     &(k_range+p4b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_11_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_11_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),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_11_1',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_11_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_11_1',5,MA_ERR)
      IF ((h6b .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 
     &* (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+p4b-1)
     &,4,3,2,1,-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),(p4b_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+p4b-1)
     &,4,3,1,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_11_1',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_y_tr1_11_1',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_11_1',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+p3b-1),int_mb(k_range+h2b-1),int_mb(k_range+p5b-1)
     &,3,4,2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p4b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p5b - noab - 1 + nvab
     & * (h2b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_11_1',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_11_1',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_11_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p5 p3 p4 )_yx
      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
      INTEGER p3b
      INTEGER p4b
      length = 0
      DO h2b = 1,noab
      DO p5b = noab+1,noab+nvab
      DO p3b = noab+1,noab+nvab
      DO p4b = p3b,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+p
     &3b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p5b-1),ieor(int_mb(
     &k_sym+p3b-1),int_mb(k_sym+p4b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1
     &)+int_mb(k_spin+p3b-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_y_tr1_11_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO p5b = noab+1,noab+nvab
      DO p3b = noab+1,noab+nvab
      DO p4b = p3b,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+p
     &3b-1)+int_mb(k_spin+p4b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p5b-1),ieor(int_mb(
     &k_sym+p3b-1),int_mb(k_sym+p4b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1
     &)+int_mb(k_spin+p3b-1)+int_mb(k_spin+p4b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p4b - noab - 1 + nvab * (p3b - noab - 1 
     &+ nvab * (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) * int_
     &mb(k_range+p3b-1) * int_mb(k_range+p4b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
c done till here
      SUBROUTINE ccsd_y_tr1_12(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_off
     &set)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yxv + = 1/2 * Sum ( p11 h12 h10 ) * i1 ( h2 p11 h10 h12 )_yx * v ( h10 h12 p1 p11 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p11b
      INTEGER h10b
      INTEGER h12b
      INTEGER h2b_1
      INTEGER p11b_1
      INTEGER h10b_1
      INTEGER h12b_1
      INTEGER h10b_2
      INTEGER h12b_2
      INTEGER p1b_2
      INTEGER p11b_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 NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x,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_y_tr1_12',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p11b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h12b = h10b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p11b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p11b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,irrep_x))
     & THEN
      CALL TCE_RESTRICTED_4(h2b,p11b,h10b,h12b,h2b_1,p11b_1,h10b_1,h12b_
     &1)
      CALL TCE_RESTRICTED_4(h10b,h12b,p1b,p11b,h10b_2,h12b_2,p1b_2,p11b_
     &2)
      dim_common = int_mb(k_range+p11b-1) * int_mb(k_range+h10b-1) * int
     &_mb(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_y_tr1_12',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_12',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (h10b_1 - 1 + noab * (p11b_1 - noab - 1 + nvab * (h
     &2b_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+p11b-1),int_mb(k_range+h10b-1),int_mb(k_range+h12b
     &-1),1,4,3,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_12',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_12',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_12',5,MA_ERR)
      IF ((p11b .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) * (p11b_2 - 1 + (noab+nvab) * (h12b_2 - 1 + (no
     &ab+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) * (p11b_2 - 1 + (noab+nvab) * (h12b_2 - 1 + (no
     &ab+nvab) * (h10b_2 - 1)))),p1b_2,p11b_2,h12b_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+h12b-1),int_mb(k_range+p11b-1),int_mb(k_range+p1b
     &-1),4,2,1,3,-1.0d0)
      END IF
      IF ((p1b .le. p11b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p11b_
     &2 - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h12b_2 - 1 + (no
     &ab+nvab) * (h10b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p11b_
     &2 - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h12b_2 - 1 + (no
     &ab+nvab) * (h10b_2 - 1)))),p11b_2,p1b_2,h12b_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+h12b-1),int_mb(k_range+p1b-1),int_mb(k_range+p11b
     &-1),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_12',6,MA_ERR)
      nsubh(1) = 1
      nsubh(2) = 1
      isubh = 1
      IF (h10b .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_y_tr1_12',7,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_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_y_tr1_12',10,MA_ERR
     &)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_12',11,M
     &A_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_12_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p11 h10 h12 )_yx + = -1 * Sum ( p6 ) * x ( p6 p11 h10 h12 )_x * y ( h2 p6 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p11b
      INTEGER h10b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p6b
      INTEGER p11b_1
      INTEGER p6b_1
      INTEGER h10b_1
      INTEGER h12b_1
      INTEGER h2b_2
      INTEGER p6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p11b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h12b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p11b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p11b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p11b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,irrep_x))
     & THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p11b-1) * int_mb(k_r
     &ange+h10b-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_y_tr1_12_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p6b = noab+1,noab+nvab
      IF (int_mb(k_spin+p11b-1)+int_mb(k_spin+p6b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),ieor(int_mb(k_sym+p6b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p11b,p6b,h10b,h12b,p11b_1,p6b_1,h10b_1,h12b_
     &1)
      CALL TCE_RESTRICTED_2(h2b,p6b,h2b_2,p6b_2)
      dim_common = int_mb(k_range+p6b-1)
      dima_sort = int_mb(k_range+p11b-1) * int_mb(k_range+h10b-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_y_tr1_12_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_12_1',2,MA_ERR)
      IF ((p6b .le. p11b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (h10b_1 - 1 + noab * (p11b_1 - noab - 1 + nvab * (p
     &6b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+p11b-1),int_mb(k_range+h10b-1),int_mb(k_range+h12b
     &-1),4,3,2,1,1.0d0)
      END IF
      IF ((p11b .lt. p6b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (h10b_1 - 1 + noab * (p6b_1 - noab - 1 + nvab * (p1
     &1b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p11b-1
     &),int_mb(k_range+p6b-1),int_mb(k_range+h10b-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_y_tr1_12_1',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_12_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_12_1',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_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+p6b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_12_1',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_y_tr1_12_1',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_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+h10b-1),int_mb(k_range+p11b
     &-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 * (h10b - 1 + noab * (p11b - noab - 1 + nvab * (h2b - 1
     &)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_12_1',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_12_1',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_12_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p11 h10 h12 )_yx
      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 p11b
      INTEGER h10b
      INTEGER h12b
      length = 0
      DO h2b = 1,noab
      DO p11b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h12b = h10b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p11b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p11b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,irrep_x))
     & THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p11b-
     &1)+int_mb(k_spin+h10b-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_y_tr1_12_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO p11b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h12b = h10b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p11b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p11b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,irrep_x))
     & THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p11b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h12b - 1 + noab * (h10b - 1 + noab * (p1
     &1b - 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+p11b-1) * int
     &_mb(k_range+h10b-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_y_tr1_12_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p11 h10 h12 )_yxt + = 1/2 * Sum ( h4 ) * t ( p11 h4 )_t * i2 ( h2 h4 h10 h12 )_yx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p11b
      INTEGER h10b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER p11b_1
      INTEGER h4b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER h10b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p11b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h12b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p11b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p11b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p11b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,ieor(irre
     &p_x,irrep_t))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p11b-1) * int_mb(k_r
     &ange+h10b-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_y_tr1_12_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h4b = 1,noab
      IF (int_mb(k_spin+p11b-1) .eq. int_mb(k_spin+h4b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),int_mb(k_sym+h4b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p11b,h4b,p11b_1,h4b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,h10b,h12b,h2b_2,h4b_2,h10b_2,h12b_2)
      dim_common = int_mb(k_range+h4b-1)
      dima_sort = int_mb(k_range+p11b-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+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_y_tr1_12_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_12_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_1
     & - 1 + noab * (p11b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p11b-1
     &),int_mb(k_range+h4b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_12_2',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_12_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_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 * (h10b_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+h10b-1),int_mb(k_range+h12b-
     &1),4,3,1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_12_2',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_y_tr1_12_2',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_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+h10b-1),int_mb(k_range+h2b-1),int_mb(k_range+p11b
     &-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 * (h10b - 1 + noab * (p11b - noab - 1 + nvab * (h2b - 1
     &)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_12_2',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_12_2',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_12_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 h12 )_yx + = 1 * Sum ( p7 p8 ) * x ( p7 p8 h10 h12 )_x * y ( h2 h4 p7 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h4b
      INTEGER h10b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p8b
      INTEGER p7b_1
      INTEGER p8b_1
      INTEGER h10b_1
      INTEGER h12b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER p7b_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 nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h4b = 1,noab
      DO h10b = 1,noab
      DO h12b = h10b,noab
      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+h10b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,irrep_x)) 
     &THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h4b-1) * int_mb(k_ra
     &nge+h10b-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_y_tr1_12_2_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      DO p8b = p7b,noab+nvab
      IF (int_mb(k_spin+p7b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p7b,p8b,h10b,h12b,p7b_1,p8b_1,h10b_1,h12b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,p7b,p8b,h2b_2,h4b_2,p7b_2,p8b_2)
      dim_common = int_mb(k_range+p7b-1) * int_mb(k_range+p8b-1)
      dima_sort = int_mb(k_range+h10b-1) * int_mb(k_range+h12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h4b-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_y_tr1_12_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_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 * (h10b_1 - 1 + noab * (p8b_1 - noab - 1 + nvab * (p7
     &b_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+p8b-1),int_mb(k_range+h10b-1),int_mb(k_range+h12b-
     &1),4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_12_2_1',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_12_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_12_2_1',5,MA_ERR)
      IF ((h4b .lt. h2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_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+p8b-1)
     &,1,2,4,3,-1.0d0)
      END IF
      IF ((h2b .le. h4b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_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+p8b-1)
     &,2,1,4,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_12_2_1',6,MA_
     &ERR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p7b .eq. p8b) 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_y_tr1_12_2_1',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_12_2_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h12b-1),int_mb(k_range+h10b-
     &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 * (h10b - 1 + noab * (h4b - 1 + noab * (h2b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_12_2_1',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_12_2_1',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_12_2_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 h12 )_yx
      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 h10b
      INTEGER h12b
      length = 0
      DO h2b = 1,noab
      DO h4b = 1,noab
      DO h10b = 1,noab
      DO h12b = h10b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,irrep_x)) 
     &THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1
     &)+int_mb(k_spin+h10b-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_y_tr1_12_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h4b = 1,noab
      DO h10b = 1,noab
      DO h12b = h10b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,irrep_x)) 
     &THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h12b - 1 + noab * (h10b - 1 + noab * (h4
     &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+h4b-1) * int_
     &mb(k_range+h10b-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_y_tr1_12_2_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 h12 )_yxt + = -4 * Sum ( p5 ) * t ( p5 h12 )_t * i3 ( h2 h4 h10 p5 )_yx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h4b
      INTEGER h12b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h12b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER h10b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h4b = 1,noab
      DO h12b = 1,noab
      DO h10b = 1,noab
      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+h10b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,ieor(irrep
     &_x,irrep_t))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h4b-1) * int_mb(k_ra
     &nge+h10b-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_y_tr1_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,h4b,h10b,p5b,h2b_2,h4b_2,h10b_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+h4b-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_y_tr1_12_2_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_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_y_tr1_12_2_2',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_12_2_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_12_2_2',5,MA_ERR)
      IF ((h10b .le. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (h10b_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+h10b-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_y_tr1_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_y_tr1_12_2_2',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_12_2_2',9,MA_ERR)
      IF ((h10b .le. h12b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h10b-1
     &),int_mb(k_range+h4b-1),int_mb(k_range+h2b-1),int_mb(k_range+h12b-
     &1),3,2,1,4,-2.0d0/1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h10b - 1 + noab * (h4b - 1 + noab * (h2b - 1)))))
      END IF
      IF ((h12b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h10b-1
     &),int_mb(k_range+h4b-1),int_mb(k_range+h2b-1),int_mb(k_range+h12b-
     &1),3,2,4,1,2.0d0/1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (h12b - 1 + noab * (h4b - 1 + noab * (h2b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_12_2_2',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_12_2_2',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_12_2_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k
     &_c_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h4 h10 p5 )_yx + = 1 * Sum ( p8 ) * x ( p8 h10 )_x * y ( h2 h4 p5 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h4b
      INTEGER h10b
      INTEGER p5b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p8b
      INTEGER p8b_1
      INTEGER h10b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER p5b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h4b = 1,noab
      DO h10b = 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+h4b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+p5b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+p5b-1)))) .eq. ieor(irrep_y,irrep_x)) T
     &HEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h4b-1) * int_mb(k_ra
     &nge+h10b-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_y_tr1_12_2_2_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p8b = noab+1,noab+nvab
      IF (int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p8b-1),int_mb(k_sym+h10b-1)) .eq. irrep_x) T
     &HEN
      CALL TCE_RESTRICTED_2(p8b,h10b,p8b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,p5b,p8b,h2b_2,h4b_2,p5b_2,p8b_2)
      dim_common = int_mb(k_range+p8b-1)
      dima_sort = int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h4b-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_y_tr1_12_2_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_12_2_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &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+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_12_2_2_1',3,M
     &A_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_12_2_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_12_2_2_1',5,MA_ERR)
      IF ((h4b .lt. h2b) .and. (p8b .lt. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p8b_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+p8b-1),int_mb(k_range+p5b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h4b .lt. h2b) .and. (p5b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_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+p8b-1)
     &,3,1,2,4,-1.0d0)
      END IF
      IF ((h2b .le. h4b) .and. (p8b .lt. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p8b_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+p8b-1),int_mb(k_range+p5b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h2b .le. h4b) .and. (p5b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_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+p8b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_12_2_2_1',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_y_tr1_12_2_2_1
     &',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_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+h4b-1),int_mb(k_range+h2b-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),(p5b -
     & noab - 1 + nvab * (h10b - 1 + noab * (h4b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_12_2_2_1',10,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_12_2_2_1
     &',11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_12_2_2_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h4 h10 p5 )_yx
      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 h10b
      INTEGER p5b
      length = 0
      DO h2b = 1,noab
      DO h4b = 1,noab
      DO h10b = 1,noab
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+p5b-1)))) .eq. ieor(irrep_y,irrep_x)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1
     &)+int_mb(k_spin+h10b-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_y_tr1_12_2_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h4b = 1,noab
      DO h10b = 1,noab
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+p5b-1)))) .eq. ieor(irrep_y,irrep_x)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+p5b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p5b - noab - 1 + nvab * (h10b - 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+h10b-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_y_tr1_12_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p11 h10 h12 )_ytx + = 2 * Sum ( h8 p7 ) * x ( p7 p11 h8 h10 )_x * i2 ( h2 h8 h12 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p11b
      INTEGER h10b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER h8b
      INTEGER p11b_1
      INTEGER p7b_1
      INTEGER h10b_1
      INTEGER h8b_1
      INTEGER h2b_2
      INTEGER h8b_2
      INTEGER h12b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p11b = noab+1,noab+nvab
      DO h10b = 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+p11b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p11b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p11b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,ieor(irre
     &p_t,irrep_x))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p11b-1) * int_mb(k_r
     &ange+h10b-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_y_tr1_12_3',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+p11b-1)+int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),ieor(int_mb(k_sym+p7b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h8b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p11b,p7b,h10b,h8b,p11b_1,p7b_1,h10b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,h12b,p7b,h2b_2,h8b_2,h12b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1) * int_mb(k_range+h8b-1)
      dima_sort = int_mb(k_range+p11b-1) * int_mb(k_range+h10b-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_y_tr1_12_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_12_3',2,MA_ERR)
      IF ((p7b .le. p11b) .and. (h8b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h8b_1 - 1 + noab * (p11b_1 - noab - 1 + nvab * (p7
     &b_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+p11b-1),int_mb(k_range+h8b-1),int_mb(k_range+h10b-
     &1),4,2,3,1,1.0d0)
      END IF
      IF ((p7b .le. p11b) .and. (h10b .lt. h8b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (h10b_1 - 1 + noab * (p11b_1 - noab - 1 + nvab * (p7
     &b_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+p11b-1),int_mb(k_range+h10b-1),int_mb(k_range+h8b-
     &1),3,2,4,1,-1.0d0)
      END IF
      IF ((p11b .lt. p7b) .and. (h8b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h8b_1 - 1 + noab * (p7b_1 - noab - 1 + nvab * (p11
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p11b-1
     &),int_mb(k_range+p7b-1),int_mb(k_range+h8b-1),int_mb(k_range+h10b-
     &1),4,1,3,2,-1.0d0)
      END IF
      IF ((p11b .lt. p7b) .and. (h10b .lt. h8b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (h10b_1 - 1 + noab * (p7b_1 - noab - 1 + nvab * (p11
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p11b-1
     &),int_mb(k_range+p7b-1),int_mb(k_range+h10b-1),int_mb(k_range+h8b-
     &1),3,1,4,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_12_3',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_12_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_12_3',5,MA_ERR)
      IF ((h12b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (h12b_2 - 1 + noab * (h8b_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+h8b-1),int_mb(k_range+h12b-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_y_tr1_12_3',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_y_tr1_12_3',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_12_3',9,MA_ERR)
      IF ((h10b .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+h10b-1),int_mb(k_range+p11b
     &-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 * (h10b - 1 + noab * (p11b - noab - 1 + nvab * (h2b - 1
     &)))))
      END IF
      IF ((h12b .le. h10b)) 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+h10b-1),int_mb(k_range+p11b
     &-1),2,4,1,3,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (h12b - 1 + noab * (p11b - noab - 1 + nvab * (h2b - 1
     &)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_12_3',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_12_3',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_12_3_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 h12 p7 )_yt + = 1 * Sum ( p3 ) * t ( p3 h12 )_t * y ( h2 h8 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h8b
      INTEGER h12b
      INTEGER p7b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h12b_1
      INTEGER h2b_2
      INTEGER h8b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h12b = 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+h8b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p7b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p7b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h8b-1) * int_mb(k_ra
     &nge+h12b-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_y_tr1_12_3_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+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h12b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p3b,h12b,p3b_1,h12b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,p7b,p3b,h2b_2,h8b_2,p7b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-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+h8b-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_y_tr1_12_3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_12_3_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &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+h12b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_12_3_1',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_12_3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_12_3_1',5,MA_ERR)
      IF ((h8b .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 
     &* (h8b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p3b-1),int_mb(k_range+p7b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h8b .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 
     &* (h8b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p7b-1),int_mb(k_range+p3b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF ((h2b .le. h8b) .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 * (h8b_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+h8b-1),int_mb(k_range+p3b-1),int_mb(k_range+p7b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h2b .le. h8b) .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 * (h8b_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+h8b-1),int_mb(k_range+p7b-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_y_tr1_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_y_tr1_12_3_1',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_12_3_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+h8b-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),(p7b -
     & noab - 1 + nvab * (h12b - 1 + noab * (h8b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_12_3_1',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_12_3_1',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_12_3_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 h12 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 h8b
      INTEGER h12b
      INTEGER p7b
      length = 0
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h12b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p7b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h12b-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_y_tr1_12_3_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h12b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p7b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p7b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p7b - noab - 1 + nvab * (h12b - 1 + noab
     & * (h8b - 1 + noab * (h2b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+h8b-1) * int_
     &mb(k_range+h12b-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_y_tr1_12_4(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p11 h10 h12 )_yxt + = -1 * t ( p11 h12 )_t * i2 ( h2 h10 )_yx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p11b
      INTEGER h12b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p11b_1
      INTEGER h12b_1
      INTEGER h2b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p11b = noab+1,noab+nvab
      DO h12b = 1,noab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p11b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p11b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p11b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,ieor(irre
     &p_x,irrep_t))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p11b-1) * int_mb(k_r
     &ange+h10b-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_y_tr1_12_4',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      IF (int_mb(k_spin+p11b-1) .eq. int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),int_mb(k_sym+h12b-1)) .eq. irrep_t) 
     &THEN
      CALL TCE_RESTRICTED_2(p11b,h12b,p11b_1,h12b_1)
      CALL TCE_RESTRICTED_2(h2b,h10b,h2b_2,h10b_2)
      dim_common = 1
      dima_sort = int_mb(k_range+p11b-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_y_tr1_12_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_12_4',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (p11b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p11b-1
     &),int_mb(k_range+h12b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_12_4',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_12_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_12_4',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h10b_
     &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+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_12_4',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_y_tr1_12_4',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_12_4',9,MA_ERR)
      IF ((h10b .le. h12b)) THEN
      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+p11b
     &-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),(h12b 
     &- 1 + noab * (h10b - 1 + noab * (p11b - noab - 1 + nvab * (h2b - 1
     &)))))
      END IF
      IF ((h12b .le. h10b)) THEN
      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+p11b
     &-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),(h10b 
     &- 1 + noab * (h12b - 1 + noab * (p11b - noab - 1 + nvab * (h2b - 1
     &)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_12_4',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_12_4',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_12_4_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yx + = -1 * Sum ( h8 p6 p7 ) * x ( p6 p7 h8 h10 )_x * y ( h2 h8 p6 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p6b
      INTEGER p7b
      INTEGER h8b
      INTEGER p6b_1
      INTEGER p7b_1
      INTEGER h10b_1
      INTEGER h8b_1
      INTEGER h2b_2
      INTEGER h8b_2
      INTEGER p6b_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 nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h10b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h10b-1)) .eq. ieor(irrep
     &_y,irrep_x)) THEN
      dimc = int_mb(k_range+h2b-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_y_tr1_12_4_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p6b = noab+1,noab+nvab
      DO p7b = p6b,noab+nvab
      DO h8b = 1,noab
      IF (int_mb(k_spin+p6b-1)+int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p6b-1),ieor(int_mb(k_sym+p7b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h8b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p6b,p7b,h10b,h8b,p6b_1,p7b_1,h10b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,p6b,p7b,h2b_2,h8b_2,p6b_2,p7b_2)
      dim_common = int_mb(k_range+p6b-1) * int_mb(k_range+p7b-1) * int_m
     &b(k_range+h8b-1)
      dima_sort = int_mb(k_range+h10b-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_y_tr1_12_4_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_12_4_1',2,MA_ERR)
      IF ((h8b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h8b_1 - 1 + noab * (p7b_1 - noab - 1 + nvab * (p6b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+h8b-1),int_mb(k_range+h10b-1
     &),4,3,2,1,1.0d0)
      END IF
      IF ((h10b .lt. h8b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (h10b_1 - 1 + noab * (p7b_1 - noab - 1 + nvab * (p6b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+h10b-1),int_mb(k_range+h8b-1
     &),3,4,2,1,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_12_4_1',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_12_4_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_12_4_1',5,MA_ERR)
      IF ((h8b .lt. h2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p6b_2 - noab - 1 + nvab * (h2b_2 - 1 + noab 
     &* (h8b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p6b-1),int_mb(k_range+p7b-1)
     &,2,1,4,3,-1.0d0)
      END IF
      IF ((h2b .le. h8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p6b_2 - noab - 1 + nvab * (h8b_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+h8b-1),int_mb(k_range+p6b-1),int_mb(k_range+p7b-1)
     &,1,2,4,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_12_4_1',6,MA_
     &ERR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p6b .eq. p7b) 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_y_tr1_12_4_1',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_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+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 * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_12_4_1',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_12_4_1',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_12_4_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yx
      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
      length = 0
      DO h2b = 1,noab
      DO h10b = 1,noab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h10b-1)) .eq. ieor(irrep
     &_y,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-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_y_tr1_12_4_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h10b = 1,noab
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h10b-1)) .eq. ieor(irrep
     &_y,irrep_x)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h10b-
     &1).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = 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)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_12_5(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p11 h10 h12 )_ytx + = 1 * x ( p11 h10 )_x * 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p11b
      INTEGER h10b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p11b_1
      INTEGER h10b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p11b = noab+1,noab+nvab
      DO h10b = 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+p11b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p11b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p11b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,ieor(irre
     &p_t,irrep_x))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p11b-1) * int_mb(k_r
     &ange+h10b-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_y_tr1_12_5',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      IF (int_mb(k_spin+p11b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),int_mb(k_sym+h10b-1)) .eq. irrep_x) 
     &THEN
      CALL TCE_RESTRICTED_2(p11b,h10b,p11b_1,h10b_1)
      CALL TCE_RESTRICTED_2(h2b,h12b,h2b_2,h12b_2)
      dim_common = 1
      dima_sort = int_mb(k_range+p11b-1) * int_mb(k_range+h10b-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_y_tr1_12_5',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_12_5',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (p11b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p11b-1
     &),int_mb(k_range+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_12_5',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_12_5',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_12_5',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_y_tr1_12_5',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_y_tr1_12_5',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_12_5',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_y_tr1_12_5',9,MA_ERR)
      IF ((h10b .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+h10b-1),int_mb(k_range+p11b
     &-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 * (h10b - 1 + noab * (p11b - noab - 1 + nvab * (h2b - 1
     &)))))
      END IF
      IF ((h12b .le. h10b)) 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+h10b-1),int_mb(k_range+p11b
     &-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),(h10b 
     &- 1 + noab * (h12b - 1 + noab * (p11b - noab - 1 + nvab * (h2b - 1
     &)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_12_5',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_12_5',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_12_5_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p3 p4 ) * 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 NXTVAL
      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 NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_y_tr1_12_5_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_y_tr1_12_5_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_12_5_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_y_tr1_12_5_1',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_12_5_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_12_5_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_y_tr1_12_5_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_y_tr1_12_5_1',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_12_5_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_y_tr1_12_5_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_y_tr1_12_5_1',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_12_5_1',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_12_5_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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_y_tr1_12_5_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_y_tr1_12_6(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p11 h10 h12 )_yxt + = 2 * Sum ( h5 p3 ) * t ( p3 p11 h5 h12 )_t * i2 ( h2 h5 h10 p3 )_yx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p11b
      INTEGER h12b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER h5b
      INTEGER p11b_1
      INTEGER p3b_1
      INTEGER h12b_1
      INTEGER h5b_1
      INTEGER h2b_2
      INTEGER h5b_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 l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p11b = noab+1,noab+nvab
      DO h12b = 1,noab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p11b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p11b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p11b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,ieor(irre
     &p_x,irrep_t))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p11b-1) * int_mb(k_r
     &ange+h10b-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_y_tr1_12_6',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+p11b-1)+int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+
     &h12b-1)+int_mb(k_spin+h5b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-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(p11b,p3b,h12b,h5b,p11b_1,p3b_1,h12b_1,h5b_1)
      CALL TCE_RESTRICTED_4(h2b,h5b,h10b,p3b,h2b_2,h5b_2,h10b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1) * int_mb(k_range+h5b-1)
      dima_sort = int_mb(k_range+p11b-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_y_tr1_12_6',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_12_6',2,MA_ERR)
      IF ((p3b .le. p11b) .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 * (p11b_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+p11b-1),int_mb(k_range+h5b-1),int_mb(k_range+h12b-
     &1),4,2,3,1,1.0d0)
      END IF
      IF ((p3b .le. p11b) .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 * (p11b_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+p11b-1),int_mb(k_range+h12b-1),int_mb(k_range+h5b-
     &1),3,2,4,1,-1.0d0)
      END IF
      IF ((p11b .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 * (p11
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p11b-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 ((p11b .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 * (p11
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p11b-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_y_tr1_12_6',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_12_6',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_12_6',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 * (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+h10b-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_y_tr1_12_6',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_y_tr1_12_6',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_12_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_y_tr1_12_6',9,MA_ERR)
      IF ((h10b .le. h12b)) THEN
      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+p11b
     &-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 * (h10b - 1 + noab * (p11b - noab - 1 + nvab * (h2b - 1
     &)))))
      END IF
      IF ((h12b .le. h10b)) THEN
      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+p11b
     &-1),2,4,3,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (h12b - 1 + noab * (p11b - noab - 1 + nvab * (h2b - 1
     &)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_12_6',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_12_6',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_12_6_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 p3 )_yx + = 1 * Sum ( p8 ) * x ( p8 h10 )_x * y ( h2 h5 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h5b
      INTEGER h10b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p8b
      INTEGER p8b_1
      INTEGER h10b_1
      INTEGER h2b_2
      INTEGER h5b_2
      INTEGER p3b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h5b = 1,noab
      DO h10b = 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+h10b-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
     &10b-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+h10b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_x)) T
     &HEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h5b-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_y_tr1_12_6_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p8b = noab+1,noab+nvab
      IF (int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p8b-1),int_mb(k_sym+h10b-1)) .eq. irrep_x) T
     &HEN
      CALL TCE_RESTRICTED_2(p8b,h10b,p8b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h2b,h5b,p3b,p8b,h2b_2,h5b_2,p3b_2,p8b_2)
      dim_common = int_mb(k_range+p8b-1)
      dima_sort = int_mb(k_range+h10b-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_y_tr1_12_6_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_12_6_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &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+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_12_6_1',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_12_6_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_12_6_1',5,MA_ERR)
      IF ((h5b .lt. h2b) .and. (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 * (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+p8b-1),int_mb(k_range+p3b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h5b .lt. h2b) .and. (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 * (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+p8b-1)
     &,3,1,2,4,-1.0d0)
      END IF
      IF ((h2b .le. h5b) .and. (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 * (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+p8b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h2b .le. h5b) .and. (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 * (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+p8b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_12_6_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_y_tr1_12_6_1',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_12_6_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_y_tr1_12_6_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+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 * (h5b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_12_6_1',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_12_6_1',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_12_6_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h10 p3 )_yx
      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 h10b
      INTEGER p3b
      length = 0
      DO h2b = 1,noab
      DO h5b = 1,noab
      DO h10b = 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
     &10b-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+h10b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_x)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h5b-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_y_tr1_12_6_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h5b = 1,noab
      DO h10b = 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
     &10b-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+h10b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_x)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h5b-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
     & * (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+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_y_tr1_12_7(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p11 h10 h12 )_ytx + = 1/2 * Sum ( h8 ) * x ( p11 h8 )_x * i2 ( h2 h8 h10 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p11b
      INTEGER h10b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h8b
      INTEGER p11b_1
      INTEGER h8b_1
      INTEGER h2b_2
      INTEGER h8b_2
      INTEGER h10b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p11b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h12b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p11b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p11b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p11b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_y,ieor(irre
     &p_t,irrep_x))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p11b-1) * int_mb(k_r
     &ange+h10b-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_y_tr1_12_7',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h8b = 1,noab
      IF (int_mb(k_spin+p11b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),int_mb(k_sym+h8b-1)) .eq. irrep_x) T
     &HEN
      CALL TCE_RESTRICTED_2(p11b,h8b,p11b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,h10b,h12b,h2b_2,h8b_2,h10b_2,h12b_2)
      dim_common = int_mb(k_range+h8b-1)
      dima_sort = int_mb(k_range+p11b-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+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_y_tr1_12_7',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_12_7',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p11b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p11b-1
     &),int_mb(k_range+h8b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_12_7',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_12_7',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_12_7',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h12b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (h8b_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+h8b-1),int_mb(k_range+h10b-1),int_mb(k_range+h12b-
     &1),4,3,1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_12_7',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_y_tr1_12_7',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_12_7',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_y_tr1_12_7',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+h10b-1),int_mb(k_range+h2b-1),int_mb(k_range+p11b
     &-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 * (h10b - 1 + noab * (p11b - noab - 1 + nvab * (h2b - 1
     &)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_12_7',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_12_7',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_12_7_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 h10 h12 )_yt + = 1 * Sum ( p3 p4 ) * t ( p3 p4 h10 h12 )_t * y ( h2 h8 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h8b
      INTEGER h10b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p4b
      INTEGER p3b_1
      INTEGER p4b_1
      INTEGER h10b_1
      INTEGER h12b_1
      INTEGER h2b_2
      INTEGER h8b_2
      INTEGER p3b_2
      INTEGER p4b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h10b = 1,noab
      DO h12b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h10b-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+h8b-1) * int_mb(k_ra
     &nge+h10b-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_y_tr1_12_7_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
     &10b-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+h10b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p3b,p4b,h10b,h12b,p3b_1,p4b_1,h10b_1,h12b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,p3b,p4b,h2b_2,h8b_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+h10b-1) * int_mb(k_range+h12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h8b-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_y_tr1_12_7_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_12_7_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (h10b_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+h10b-1),int_mb(k_range+h12b-
     &1),4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_12_7_1',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_12_7_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_12_7_1',5,MA_ERR)
      IF ((h8b .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 
     &* (h8b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+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. h8b)) 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 * (h8b_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+h8b-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_y_tr1_12_7_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_y_tr1_12_7_1',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_12_7_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_y_tr1_12_7_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h12b-1),int_mb(k_range+h10b-
     &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 * (h10b - 1 + noab * (h8b - 1 + noab * (h2b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_12_7_1',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_12_7_1',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_12_7_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 h10 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 h8b
      INTEGER h10b
      INTEGER h12b
      length = 0
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h10b = 1,noab
      DO h12b = h10b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h10b-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+h8b-1
     &)+int_mb(k_spin+h10b-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_y_tr1_12_7_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h10b = 1,noab
      DO h12b = h10b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h10b-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+h8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h12b - 1 + noab * (h10b - 1 + noab * (h8
     &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+h8b-1) * int_
     &mb(k_range+h10b-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_y_tr1_12_7_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 h10 h12 )_ytt + = -2 * Sum ( p3 ) * t ( p3 h12 )_t * i3 ( h2 h8 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h8b
      INTEGER h12b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h12b_1
      INTEGER h2b_2
      INTEGER h8b_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 l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h12b = 1,noab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h10b-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+h8b-1) * int_mb(k_ra
     &nge+h10b-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_y_tr1_12_7_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+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h12b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p3b,h12b,p3b_1,h12b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,h10b,p3b,h2b_2,h8b_2,h10b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-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+h8b-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_y_tr1_12_7_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_12_7_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &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+h12b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_12_7_2',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_12_7_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_12_7_2',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 * (h8b_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+h8b-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_y_tr1_12_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_y_tr1_12_7_2',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_12_7_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_y_tr1_12_7_2',9,MA_ERR)
      IF ((h10b .le. h12b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h10b-1
     &),int_mb(k_range+h8b-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 * (h10b - 1 + noab * (h8b - 1 + noab * (h2b - 1)))))
      END IF
      IF ((h12b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h10b-1
     &),int_mb(k_range+h8b-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),(h10b 
     &- 1 + noab * (h12b - 1 + noab * (h8b - 1 + noab * (h2b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_12_7_2',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_12_7_2',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_12_7_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k
     &_c_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 h10 p3 )_yt + = 1 * Sum ( p5 ) * t ( p5 h10 )_t * y ( h2 h8 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h8b
      INTEGER h10b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h10b_1
      INTEGER h2b_2
      INTEGER h8b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h10b = 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+h8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-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+h2b-1) * int_mb(k_range+h8b-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_y_tr1_12_7_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+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_4(h2b,h8b,p3b,p5b,h2b_2,h8b_2,p3b_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+h2b-1) * int_mb(k_range+h8b-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_y_tr1_12_7_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_12_7_2_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_y_tr1_12_7_2_1',3,M
     &A_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_12_7_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_12_7_2_1',5,MA_ERR)
      IF ((h8b .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 
     &* (h8b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p5b-1),int_mb(k_range+p3b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h8b .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 
     &* (h8b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+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. h8b) .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 * (h8b_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+h8b-1),int_mb(k_range+p5b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h2b .le. h8b) .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 * (h8b_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+h8b-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_y_tr1_12_7_2_1',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_y_tr1_12_7_2_1
     &',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_12_7_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_y_tr1_12_7_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+h8b-1),int_mb(k_range+h2b-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 * (h8b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_12_7_2_1',10,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_12_7_2_1
     &',11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_12_7_2_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h8 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 h2b
      INTEGER h8b
      INTEGER h10b
      INTEGER p3b
      length = 0
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h10b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-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+h2b-1)+int_mb(k_spin+h8b-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_y_tr1_12_7_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h8b = 1,noab
      DO h10b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h8b-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+h2b-1)+int_mb(k_spin+h8b-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
     & * (h8b - 1 + noab * (h2b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h2b-1) * int_mb(k_range+h8b-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_y_tr1_13(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_off
     &set)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yxv + = 1/4 * Sum ( h4 h8 h9 ) * i1 ( h2 h4 h8 h9 )_yx * v ( h8 h9 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER h8b
      INTEGER h9b
      INTEGER h2b_1
      INTEGER h4b_1
      INTEGER h8b_1
      INTEGER h9b_1
      INTEGER h8b_2
      INTEGER h9b_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 nsubh(2)
      INTEGER isubh
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x,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_y_tr1_13',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h4b = 1,noab
      DO h8b = 1,noab
      DO h9b = h8b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &8b-1)+int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h8b-1),int_mb(k_sym+h9b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      CALL TCE_RESTRICTED_4(h2b,h4b,h8b,h9b,h2b_1,h4b_1,h8b_1,h9b_1)
      CALL TCE_RESTRICTED_4(h8b,h9b,p1b,h4b,h8b_2,h9b_2,p1b_2,h4b_2)
      dim_common = int_mb(k_range+h4b-1) * int_mb(k_range+h8b-1) * int_m
     &b(k_range+h9b-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_y_tr1_13',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_13',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_1
     & - 1 + noab * (h8b_1 - 1 + noab * (h4b_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+h4b-1),int_mb(k_range+h8b-1),int_mb(k_range+h9b-1)
     &,1,4,3,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_13',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_13',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_13',5,MA_ERR)
      IF ((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) * (h9b_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) * (h4b_2 - 1 + (noab+nvab) * (h9b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p1b_2,h4b_2,h9b_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+h9b-1),int_mb(k_range+h4b-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_y_tr1_13',6,MA_ERR)
      nsubh(1) = 1
      nsubh(2) = 1
      isubh = 1
      IF (h8b .eq. h9b) 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_y_tr1_13',7,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_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_y_tr1_13',10,MA_ERR
     &)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_13',11,M
     &A_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_13_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h4 h8 h9 )_yx + = -1 * Sum ( p6 p7 ) * x ( p6 p7 h8 h9 )_x * y ( h2 h4 p6 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h4b
      INTEGER h8b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p6b
      INTEGER p7b
      INTEGER p6b_1
      INTEGER p7b_1
      INTEGER h8b_1
      INTEGER h9b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER p6b_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 nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTVAL
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h4b = 1,noab
      DO h8b = 1,noab
      DO h9b = h8b,noab
      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+h8b-1)+int_mb(k_spin+h9b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &8b-1)+int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h8b-1),int_mb(k_sym+h9b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h4b-1) * int_mb(k_ra
     &nge+h8b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_13_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p6b = noab+1,noab+nvab
      DO p7b = p6b,noab+nvab
      IF (int_mb(k_spin+p6b-1)+int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h
     &8b-1)+int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p6b-1),ieor(int_mb(k_sym+p7b-1),ieor(int_mb(
     &k_sym+h8b-1),int_mb(k_sym+h9b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p6b,p7b,h8b,h9b,p6b_1,p7b_1,h8b_1,h9b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,p6b,p7b,h2b_2,h4b_2,p6b_2,p7b_2)
      dim_common = int_mb(k_range+p6b-1) * int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h8b-1) * int_mb(k_range+h9b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h4b-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_y_tr1_13_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_13_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_1
     & - 1 + noab * (h8b_1 - 1 + noab * (p7b_1 - noab - 1 + nvab * (p6b_
     &1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+h8b-1),int_mb(k_range+h9b-1)
     &,4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_13_1',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_13_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_13_1',5,MA_ERR)
      IF ((h4b .lt. h2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p6b_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+p6b-1),int_mb(k_range+p7b-1)
     &,1,2,4,3,-1.0d0)
      END IF
      IF ((h2b .le. h4b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p6b_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+p6b-1),int_mb(k_range+p7b-1)
     &,2,1,4,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_13_1',6,MA_ER
     &R)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p6b .eq. p7b) 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_y_tr1_13_1',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_13_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h9b-1),int_mb(k_range+h8b-1)
     &,2,1,4,3,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (h8b - 1 + noab * (h4b - 1 + noab * (h2b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_13_1',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_13_1',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_13_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h4 h8 h9 )_yx
      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 h8b
      INTEGER h9b
      length = 0
      DO h2b = 1,noab
      DO h4b = 1,noab
      DO h8b = 1,noab
      DO h9b = h8b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &8b-1)+int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h8b-1),int_mb(k_sym+h9b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1
     &)+int_mb(k_spin+h8b-1)+int_mb(k_spin+h9b-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_y_tr1_13_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h4b = 1,noab
      DO h8b = 1,noab
      DO h9b = h8b,noab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &8b-1)+int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h8b-1),int_mb(k_sym+h9b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1
     &)+int_mb(k_spin+h8b-1)+int_mb(k_spin+h9b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h9b - 1 + noab * (h8b - 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+h8b-1) * int_mb(k_range+h9b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_13_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h4 h8 h9 )_yxt + = -4 * Sum ( p3 ) * t ( p3 h8 )_t * i2 ( h2 h4 h9 p3 )_yx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h4b
      INTEGER h8b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h8b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER h9b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h4b = 1,noab
      DO h8b = 1,noab
      DO h9b = 1,noab
      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+h8b-1)+int_mb(k_spin+h9b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &8b-1)+int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h8b-1),int_mb(k_sym+h9b-1)))) .eq. ieor(irrep_y,ieor(irrep_x
     &,irrep_t))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h4b-1) * int_mb(k_ra
     &nge+h8b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_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,h4b,h9b,p3b,h2b_2,h4b_2,h9b_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+h4b-1) * int_mb
     &(k_range+h9b-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_y_tr1_13_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_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_y_tr1_13_2',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_13_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_13_2',5,MA_ERR)
      IF ((h9b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h9b_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+h9b-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_y_tr1_13_2',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_y_tr1_13_2',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_13_2',9,MA_ERR)
      IF ((h8b .le. h9b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h2b-1),int_mb(k_range+h8b-1)
     &,3,2,4,1,-2.0d0/1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (h8b - 1 + noab * (h4b - 1 + noab * (h2b - 1)))))
      END IF
      IF ((h9b .le. h8b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h2b-1),int_mb(k_range+h8b-1)
     &,3,2,1,4,2.0d0/1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h8b -
     & 1 + noab * (h9b - 1 + noab * (h4b - 1 + noab * (h2b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_13_2',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_13_2',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_13_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h9 p3 )_yx + = 1 * Sum ( p7 ) * x ( p7 h9 )_x * y ( h2 h4 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h4b
      INTEGER h9b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h9b_1
      INTEGER h2b_2
      INTEGER h4b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h4b = 1,noab
      DO h9b = 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+h4b-1
     &)+int_mb(k_spin+h9b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &9b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h9b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h4b-1) * int_mb(k_ra
     &nge+h9b-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_y_tr1_13_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+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h9b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p7b,h9b,p7b_1,h9b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,p3b,p7b,h2b_2,h4b_2,p3b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h9b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h4b-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_y_tr1_13_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_13_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_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+h9b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_13_2_1',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_13_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_13_2_1',5,MA_ERR)
      IF ((h4b .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 
     &* (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+p3b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h4b .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 
     &* (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+p3b-1),int_mb(k_range+p7b-1)
     &,3,1,2,4,-1.0d0)
      END IF
      IF ((h2b .le. h4b) .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 * (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+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h2b .le. h4b) .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 * (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+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_y_tr1_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_y_tr1_13_2_1',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_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+h4b-1),int_mb(k_range+h2b-1),int_mb(k_range+h9b-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 * (h9b - 1 + noab * (h4b - 1 + noab * (h2b - 1)))
     &))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_13_2_1',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_13_2_1',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_13_2_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h9 p3 )_yx
      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 h9b
      INTEGER p3b
      length = 0
      DO h2b = 1,noab
      DO h4b = 1,noab
      DO h9b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &9b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h9b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1
     &)+int_mb(k_spin+h9b-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_y_tr1_13_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO h4b = 1,noab
      DO h9b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &9b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h9b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_x)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1
     &)+int_mb(k_spin+h9b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p3b - noab - 1 + nvab * (h9b - 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+h9b-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_y_tr1_14(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_off
     &set)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 )_yxv + = -1 * Sum ( p5 h11 p8 ) * i1 ( h2 p5 h11 p8 )_yx * v ( h11 p8 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER h11b
      INTEGER p8b
      INTEGER h2b_1
      INTEGER p5b_1
      INTEGER h11b_1
      INTEGER p8b_1
      INTEGER h11b_2
      INTEGER p8b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      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_x,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_y_tr1_14',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      DO h11b = 1,noab
      DO p8b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p5b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p8b-1)))) .eq. ieor(irrep_y,irrep_x)) T
     &HEN
      CALL TCE_RESTRICTED_4(h2b,p5b,h11b,p8b,h2b_1,p5b_1,h11b_1,p8b_1)
      CALL TCE_RESTRICTED_4(h11b,p8b,p1b,p5b,h11b_2,p8b_2,p1b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1) * int_mb(k_range+h11b-1) * int_
     &mb(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_y_tr1_14',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_14',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p8b_1
     & - noab - 1 + nvab * (h11b_1 - 1 + noab * (p5b_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+p5b-1),int_mb(k_range+h11b-1),int_mb(k_range+p8b-1
     &),1,4,3,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_14',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_14',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_14',5,MA_ERR)
      IF ((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) * (p8b_2 - 1 + (noab
     &+nvab) * (h11b_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) * (p8b_2 - 1 + (noab
     &+nvab) * (h11b_2 - 1)))),p1b_2,p5b_2,p8b_2,h11b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h11b-1
     &),int_mb(k_range+p8b-1),int_mb(k_range+p5b-1),int_mb(k_range+p1b-1
     &),4,2,1,3,-1.0d0)
      END IF
      IF ((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) * (p8b_2 - 1 + (noab
     &+nvab) * (h11b_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) * (p8b_2 - 1 + (noab
     &+nvab) * (h11b_2 - 1)))),p5b_2,p1b_2,p8b_2,h11b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h11b-1
     &),int_mb(k_range+p8b-1),int_mb(k_range+p1b-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_y_tr1_14',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_y_tr1_14',7,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_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_y_tr1_14',10,MA_ERR
     &)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_14',11,M
     &A_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_14_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p5 h11 p8 )_yx + = 1 * Sum ( h7 p6 ) * x ( p5 p6 h7 h11 )_x * y ( h2 h7 p6 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p5b
      INTEGER h11b
      INTEGER p8b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p6b
      INTEGER h7b
      INTEGER p5b_1
      INTEGER p6b_1
      INTEGER h11b_1
      INTEGER h7b_1
      INTEGER h2b_2
      INTEGER h7b_2
      INTEGER p8b_2
      INTEGER p6b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p5b = noab+1,noab+nvab
      DO h11b = 1,noab
      DO p8b = 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
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p8b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p5b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p8b-1)))) .eq. ieor(irrep_y,irrep_x)) T
     &HEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p5b-1) * int_mb(k_ra
     &nge+h11b-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_y_tr1_14_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p6b = noab+1,noab+nvab
      DO h7b = 1,noab
      IF (int_mb(k_spin+p5b-1)+int_mb(k_spin+p6b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),ieor(int_mb(k_sym+p6b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h7b-1)))) .eq. irrep_x) THEN
      CALL TCE_RESTRICTED_4(p5b,p6b,h11b,h7b,p5b_1,p6b_1,h11b_1,h7b_1)
      CALL TCE_RESTRICTED_4(h2b,h7b,p8b,p6b,h2b_2,h7b_2,p8b_2,p6b_2)
      dim_common = int_mb(k_range+p6b-1) * int_mb(k_range+h7b-1)
      dima_sort = int_mb(k_range+p5b-1) * int_mb(k_range+h11b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * 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_y_tr1_14_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_14_1',2,MA_ERR)
      IF ((p6b .lt. p5b) .and. (h7b .le. h11b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (h7b_1 - 1 + noab * (p5b_1 - noab - 1 + nvab * (p6b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+p5b-1),int_mb(k_range+h7b-1),int_mb(k_range+h11b-1
     &),4,2,3,1,-1.0d0)
      END IF
      IF ((p6b .lt. p5b) .and. (h11b .lt. h7b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_1
     & - 1 + noab * (h11b_1 - 1 + noab * (p5b_1 - noab - 1 + nvab * (p6b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p6b-1)
     &,int_mb(k_range+p5b-1),int_mb(k_range+h11b-1),int_mb(k_range+h7b-1
     &),3,2,4,1,1.0d0)
      END IF
      IF ((p5b .le. p6b) .and. (h7b .le. h11b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (h7b_1 - 1 + noab * (p6b_1 - noab - 1 + nvab * (p5b
     &_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+p6b-1),int_mb(k_range+h7b-1),int_mb(k_range+h11b-1
     &),4,1,3,2,1.0d0)
      END IF
      IF ((p5b .le. p6b) .and. (h11b .lt. h7b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_1
     & - 1 + noab * (h11b_1 - 1 + noab * (p6b_1 - noab - 1 + nvab * (p5b
     &_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+p6b-1),int_mb(k_range+h11b-1),int_mb(k_range+h7b-1
     &),3,1,4,2,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_14_1',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_14_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_14_1',5,MA_ERR)
      IF ((h7b .lt. h2b) .and. (p6b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - noab - 1 + nvab * (p6b_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+p6b-1),int_mb(k_range+p8b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h7b .lt. h2b) .and. (p8b .lt. p6b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - noab - 1 + nvab * (p8b_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+p8b-1),int_mb(k_range+p6b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF ((h2b .le. h7b) .and. (p6b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - noab - 1 + nvab * (p6b_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+p6b-1),int_mb(k_range+p8b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h2b .le. h7b) .and. (p8b .lt. p6b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p6b_2
     & - noab - 1 + nvab * (p8b_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+p8b-1),int_mb(k_range+p6b-1)
     &,3,1,2,4,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_14_1',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_y_tr1_14_1',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_14_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p8b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h11b-1),int_mb(k_range+p5b-1
     &),2,4,3,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p8b -
     & noab - 1 + nvab * (h11b - 1 + noab * (p5b - noab - 1 + nvab * (h2
     &b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_14_1',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_14_1',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_14_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p5 h11 p8 )_yx
      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
      INTEGER h11b
      INTEGER p8b
      length = 0
      DO h2b = 1,noab
      DO p5b = noab+1,noab+nvab
      DO h11b = 1,noab
      DO p8b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p5b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p8b-1)))) .eq. ieor(irrep_y,irrep_x)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p8b-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_y_tr1_14_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h2b = 1,noab
      DO p5b = noab+1,noab+nvab
      DO h11b = 1,noab
      DO p8b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p5b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p8b-1)))) .eq. ieor(irrep_y,irrep_x)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p8b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p8b - noab - 1 + nvab * (h11b - 1 + noab
     & * (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) * int_
     &mb(k_range+h11b-1) * int_mb(k_range+p8b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_14_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p5 h11 p8 )_yxt + = -1 * Sum ( h4 ) * t ( p5 h4 )_t * i2 ( h2 h4 h11 p8 )_yx
      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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p5b
      INTEGER h11b
      INTEGER p8b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER p5b_1
      INTEGER h4b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER h11b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p5b = noab+1,noab+nvab
      DO h11b = 1,noab
      DO p8b = 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
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p8b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p5b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p8b-1)))) .eq. ieor(irrep_y,ieor(irrep_
     &x,irrep_t))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p5b-1) * int_mb(k_ra
     &nge+h11b-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_y_tr1_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+p5b-1) .eq. int_mb(k_spin+h4b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h4b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p5b,h4b,p5b_1,h4b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,h11b,p8b,h2b_2,h4b_2,h11b_2,p8b_2)
      dim_common = int_mb(k_range+h4b-1)
      dima_sort = int_mb(k_range+p5b-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+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_y_tr1_14_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_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 * (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+h4b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_14_2',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_14_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_14_2',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - noab - 1 + nvab * (h11b_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+h11b-1),int_mb(k_range+p8b-1
     &),4,3,1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_14_2',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_y_tr1_14_2',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_14_2',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p8b-1)
     &,int_mb(k_range+h11b-1),int_mb(k_range+h2b-1),int_mb(k_range+p5b-1
     &),3,4,2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p8b -
     & noab - 1 + nvab * (h11b - 1 + noab * (p5b - noab - 1 + nvab * (h2
     &b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_14_2',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_14_2',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_14_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h11 p8 )_yx + = -1 * Sum ( p7 ) * x ( p7 h11 )_x * y ( h2 h4 p7 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h4b
      INTEGER h11b
      INTEGER p8b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h11b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER p8b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h4b = 1,noab
      DO h11b = 1,noab
      DO p8b = 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+h11b-1)+int_mb(k_spin+p8b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p8b-1)))) .eq. ieor(irrep_y,irrep_x)) T
     &HEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h4b-1) * int_mb(k_ra
     &nge+h11b-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_y_tr1_14_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+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h11b-1)) .eq. irrep_x) T
     &HEN
      CALL TCE_RESTRICTED_2(p7b,h11b,p7b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,p8b,p7b,h2b_2,h4b_2,p8b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-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+h4b-1) * 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_y_tr1_14_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_14_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &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+h11b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_14_2_1',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_14_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_14_2_1',5,MA_ERR)
      IF ((h4b .lt. h2b) .and. (p7b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_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+p8b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h4b .lt. h2b) .and. (p8b .lt. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p8b_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+p8b-1),int_mb(k_range+p7b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF ((h2b .le. h4b) .and. (p7b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_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+p8b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h2b .le. h4b) .and. (p8b .lt. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p8b_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+p8b-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_y_tr1_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_y_tr1_14_2_1',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_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_y_tr1_14_2_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p8b-1)
     &,int_mb(k_range+h4b-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),(p8b -
     & noab - 1 + nvab * (h11b - 1 + noab * (h4b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_14_2_1',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_14_2_1',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_14_2_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 h11 p8 )_yx
      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 h11b
      INTEGER p8b
      length = 0
      DO h2b = 1,noab
      DO h4b = 1,noab
      DO h11b = 1,noab
      DO p8b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p8b-1)))) .eq. ieor(irrep_y,irrep_x)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p8b-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_y_tr1_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 h11b = 1,noab
      DO p8b = noab+1,noab+nvab
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p8b-1)))) .eq. ieor(irrep_y,irrep_x)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h4b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p8b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p8b - noab - 1 + nvab * (h11b - 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+h11b-1) * int_mb(k_range+p8b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_14_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p5 h11 p8 )_ytx + = 1 * Sum ( h7 ) * x ( p5 h7 )_x * i2 ( h2 h7 h11 p8 )_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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p5b
      INTEGER h11b
      INTEGER p8b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h7b
      INTEGER p5b_1
      INTEGER h7b_1
      INTEGER h2b_2
      INTEGER h7b_2
      INTEGER h11b_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 NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO p5b = noab+1,noab+nvab
      DO h11b = 1,noab
      DO p8b = 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
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p8b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p8b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p5b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p8b-1)))) .eq. ieor(irrep_y,ieor(irrep_
     &t,irrep_x))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p5b-1) * int_mb(k_ra
     &nge+h11b-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_y_tr1_14_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h7b = 1,noab
      IF (int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h7b-1)) .eq. irrep_x) TH
     &EN
      CALL TCE_RESTRICTED_2(p5b,h7b,p5b_1,h7b_1)
      CALL TCE_RESTRICTED_4(h2b,h7b,h11b,p8b,h2b_2,h7b_2,h11b_2,p8b_2)
      dim_common = int_mb(k_range+h7b-1)
      dima_sort = int_mb(k_range+p5b-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+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_y_tr1_14_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_14_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_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+h7b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsd_y_tr1_14_3',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_14_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_14_3',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - noab - 1 + nvab * (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+p8b-1
     &),4,3,1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsd_y_tr1_14_3',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsd_y_tr1_14_3',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_14_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_y_tr1_14_3',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p8b-1)
     &,int_mb(k_range+h11b-1),int_mb(k_range+h2b-1),int_mb(k_range+p5b-1
     &),3,4,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p8b -
     & noab - 1 + nvab * (h11b - 1 + noab * (p5b - noab - 1 + nvab * (h2
     &b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_14_3',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_14_3',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsd_y_tr1_14_3_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 p8 )_yt + = 1 * Sum ( p3 ) * t ( p3 h11 )_t * y ( h2 h7 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 NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h7b
      INTEGER h11b
      INTEGER p8b
      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 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 l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h7b = 1,noab
      DO h11b = 1,noab
      DO p8b = 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+h11b-1)+int_mb(k_spin+p8b-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+p8b-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+p8b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_mb(k_ra
     &nge+h11b-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_y_tr1_14_3_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+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,p8b,p3b,h2b_2,h7b_2,p8b_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+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_y_tr1_14_3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsd_y_tr1_14_3_1',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_y_tr1_14_3_1',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsd_y_tr1_14_3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsd_y_tr1_14_3_1',5,MA_ERR)
      IF ((h7b .lt. h2b) .and. (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 * (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+p8b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h7b .lt. h2b) .and. (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 * (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+p8b-1),int_mb(k_range+p3b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF ((h2b .le. h7b) .and. (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 * (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+p8b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h2b .le. h7b) .and. (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 * (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+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_y_tr1_14_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_y_tr1_14_3_1',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsd_y_tr1_14_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_y_tr1_14_3_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p8b-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),(p8b -
     & noab - 1 + nvab * (h11b - 1 + noab * (h7b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsd_y_tr1_14_3_1',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsd_y_tr1_14_3_1',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsd_y_tr1_14_3_1(l_a_offset,k_a_offset,size)
C     $Id: ccsd_y_tr1.F 25300 2014-02-27 20:25:27Z jhammond $
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 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 h2b
      INTEGER h7b
      INTEGER h11b
      INTEGER p8b
      length = 0
      DO h2b = 1,noab
      DO h7b = 1,noab
      DO h11b = 1,noab
      DO p8b = noab+1,noab+nvab
      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+p8b-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+p8b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      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+p8b-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_y_tr1_14_3_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 p8b = noab+1,noab+nvab
      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+p8b-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+p8b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      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+p8b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p8b - noab - 1 + nvab * (h11b - 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+h11b-1) * int_mb(k_range+p8b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
